CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Getting internalField values from a patchField (http://www.cfd-online.com/Forums/openfoam-programming-development/112602-getting-internalfield-values-patchfield.html)

aabbasi59 January 31, 2013 13:50

Getting internalField values from a patchField
 
Dear Foamers,

I am trying to develop a 1-D heat transfer model. I have a source term in Laplacian Equation. This term is a function of time. I have defined a volscalarField(R) in createFields. For each run time I need to put the internalField values of this volscalarField(R) equal to the its values in one of the boundary patch. I mean R values in the whole domain are equal to its value on the specific boundary patch.

I am looking forward hearing your advice.
Your advice is appreciated in advance.

Ali

fumiya February 1, 2013 21:55

Hi Ali,

You can use the following code if the boundary value of R is constant
on your specific boundary patch.

Code:

// find the patch label
label PatchID = mesh.boundaryMesh().findPatchID("your patch name");
label FaceID = 0;

forAll(R, cellI)
{
    R[cellI] = R.boundaryField()[PatchID][FaceID];
}

If the boundaryField of R on your patch is nonuniform, you need to
change the FaceID.

Hope that helps,
Fumiya

aabbasi59 February 8, 2013 11:58

Dear fumiya,
Thank you so much for your post. It was very helpul.
But there is a problem:
I used the specfied code in my code. It works only for the first time step and It doesn't work for remaining time steps. I have put it in the time loop but unfortunately it works only for the first time step. It should be mentioned that there isn't any errors in compiling the code.
Any advice is appreciated.
Thanks,
Ali

kmooney February 15, 2013 10:20

Hi Ali,

Do you have any more information other than 'it didn't work'? Is the internal field not updating? Is it crashing?

aabbasi59 February 22, 2013 12:48

This problem has been solved!!
 
Dear kmooney,
Thanks for your post.
I solved this problem. I needed to read a variable from a text file(for example R) and then calculate a parameter in the domain in each point and in each time step. My model is a 1-D model and I thought the best way was to create a "volScalarField" and then put it equal to "R" in each time step because I wanted to calculate another parameter(for instance Rn) that is a function of "R". I have understood that this method hasn't been good and using the "interpolationTable" for time steps would be better. So I have used "interpolationTable" in my code and the mentioned problem was solved.:)

Regards,
Ali

Giancarlo_IngChimico April 12, 2013 16:02

Hi all,
I have a similar problem.

I have a patch named "fluid_to solid" in my mesh. In order to copy the values of a field in correspondence to this specific patch I have written the following code:

Code:


    forAll( TFluid[j].boundaryField(), patchi)
    {
        label patchID = fluidRegions[j].boundaryMesh().findPatchID("fluid_to_solid");
        forAll( TFluid[j].boundaryField()[patchID], facei)
            {
                Tf[facei+1] = TFluid[j].boundaryField()[patchID][facei];
            }
                   
    }

Now I have to copy the values of TFluid[j].internalField() at the same patch "fluid_to_solid".

Can anyone help me?


Regards


Giancarlo

kmooney April 13, 2013 11:00

Hi Giancarlo,

.internalField() returns cell centered values for any volume field. You might be mistaken if you are attempting to copy cell centered values to patch faces.


Quote:

Originally Posted by Giancarlo_IngChimico (Post 420209)
Hi all,
I have a similar problem.

I have a patch named "fluid_to solid" in my mesh. In order to copy the values of a field in correspondence to this specific patch I have written the following code:

Code:


    forAll( TFluid[j].boundaryField(), patchi)
    {
        label patchID = fluidRegions[j].boundaryMesh().findPatchID("fluid_to_solid");
        forAll( TFluid[j].boundaryField()[patchID], facei)
            {
                Tf[facei+1] = TFluid[j].boundaryField()[patchID][facei];
            }
                   
    }

Now I have to copy the values of TFluid[j].internalField() at the same patch "fluid_to_solid".

Can anyone help me?


Regards


Giancarlo


Giancarlo_IngChimico April 13, 2013 13:42

I kmooney I haven't been quite clear. I have a multi region mesh ( fluid and solid). The interface between these regions in named "fluid_to_solid".
I want to know the internalField value not for all cells in the fluid region, but only the value of cells located at interface. With the code that I post first I get the boundary value of a generic field for the cells of interest but my problem is the internal field.

I hope that I was more clear now.

Regards

Giancarlo

immortality April 13, 2013 14:13

hi where should add your first code?

hz283 November 30, 2013 17:22

Dear fumiya,

I would like to store the wall heat flux from the wall boundary faces into the cell centers (the cell is the one the wall face belongs to) because I will use the wall heat flux as a source term in another governing equations. So the goal is to store the wall heat flux originally in the boundary Fields of the heat flux (volScalarField) to the internal Fields. In this case, non-zero heat flux should exist for those cells neighboring to solid walls but the internal cells should still be zero. Following the suggestions from you in the post, I get the following code. But using it I found that my goal is still not reached because I do not know why all the cell centers have the non-zero heat flux, which is not correct I think. Could you please me to have a look at the following lines, Thank you very much.


// calculate the wall heat flux
const surfaceScalarField::GeometricBoundaryField& patchHeatFlux =
heatFlux.boundaryField();

forAll(wallHeatFlux.boundaryField(), patchi)
{
if(patchi == mesh.boundary().findPatchID("WALL"))
{
wallHeatFlux.boundaryField()[patchi] = patchHeatFlux[patchi];

label FaceID = 0;
forAll(wallHeatFlux, cellI)
{
forAll(wallHeatFlux.boundaryField()[patchi], FaceID)
{
wallHeatFlux[cellI] = wallHeatFlux.boundaryField()[patchi][FaceID];
}
}
}
}


Quote:

Originally Posted by fumiya (Post 405574)
Hi Ali,

You can use the following code if the boundary value of R is constant
on your specific boundary patch.

Code:

// find the patch label
label PatchID = mesh.boundaryMesh().findPatchID("your patch name");
label FaceID = 0;

forAll(R, cellI)
{
    R[cellI] = R.boundaryField()[PatchID][FaceID];
}

If the boundaryField of R on your patch is nonuniform, you need to
change the FaceID.

Hope that helps,
Fumiya


fumiya December 1, 2013 02:45

Hi hz283,

You might want to try the following code:

Code:

forAll(mesh.boundary(), patchI) // patch loop
{
    if(mesh.boundary()[patchI].name()=="WALL")
    {
        wallHeatFlux.boundaryField()[patchI] = patchHeatFlux[patchI];

        forAll(mesh.boundary()[patchI], faceI)
        {
            wallHeatFlux[mesh.boundary()[patchI].faceCells()[faceI]] =
                wallHeatFlux.boundaryField()[patchI][faceI];
        }
    }
}

You can use the "faceCells" function to get the cell label adjacent to a patch.

Hope this helps,
fumiya


All times are GMT -4. The time now is 10:41.