CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Help with this line of code : (https://www.cfd-online.com/Forums/openfoam/114480-help-line-code.html)

atmcfd March 11, 2013 21:42

Help with this line of code :
 
Hi all.

I dont quite understand what these lines of code mean in the file nuSgsUSpaldingWallFunctionFvPatchScalarField.C , which is the Spalding Wall Function for LES. I use OpenFOAM 2.1.1

U has been defined as
Code:

const fvPatchVectorField& U = lesModel.U().boundaryField()[patchi];
Then, later in the code,

Code:

const scalarField magUp(mag(U.patchInternalField() - U));
Why is the U for boundary field subtracted from that of internal field? I'm not sure how these 2 arrays can be of the same size if one contains all the boundary elements and the other all the internal elements. What is the resullting array size then?

I am confused as to why this is being done. Any help will be appreciated.

Also, I CANNOT find the nuSgsUSpaldingWallFunction folder in the Github for OpenFOAM 2.1.x https://github.com/OpenFOAM/OpenFOAM-2.1.x
whereas its there in OpenFOAM-2.1.1 / src / turbulenceModels / incompressible / LES / derivedFvPatchFields / wallFunctions / nuSgsWallFunctions / nuSgsUSpaldingWallFunction /nuSgsUSpaldingWallFunctionFvPatchScalarField.C

in my install directory of OpenFOAM 2.1.1 in my machine!!! Why is this? :confused:

Thank you all for your time.

Regards

A.T.M

ybapat March 12, 2013 00:12

U.patchInternalField() will only give U field in neighboring cells to the patch and not complete internal field.

Regards,
-Yogesh

atmcfd March 12, 2013 07:58

Quote:

Originally Posted by ybapat (Post 413286)
U.patchInternalField() will only give U field in neighboring cells to the patch and not complete internal field.

Regards,
-Yogesh

Yogesh,

Thank you.

Just to make sure I understand right,
lesModel.U().boundaryField()[patchi] has the patchID mentioned here, whereas the
U.patchInternalField() doesnt have anything like that. Which patch does it refer to by default? Also, the "boundaryField" refers to the cells which are adjacent to the boundary, and the "internalField" refers to the cells adjacent to the boundaryField cells? is this correct?

Regards,
ATM

chegdan March 12, 2013 10:27

Greetings!

Just some more info for you. The line

Code:

const fvPatchVectorField& U = lesModel.U().boundaryField()[patchi];
is a const reference to the boundary field values of U for a specific patch. This means you can only "look" at the values and not adjust them through the reference. Doing something line U = 2*U won't do anythign and will giv eyou an error. its a way to save on overhead and also to prevent the user from accidentally overwriting something that needs to stay untouched at this point in the code. next, the line

Code:

const scalarField magUp(mag(U.patchInternalField() - U));
is a scalar field of the magnitude of the patch velocity relative to the velocity of the patch. U being the value of velocity of the patch faces and U.internalField() being the velocity at the cell centers adjacent to the patch faces. The size of U and U.patchInternalField() are the same because every boundary face has one patchInternal cell. lastly, no need for patchInternalField to know what patch it is pointing to since it is already in there from our reference in the first line of code.

atmcfd March 12, 2013 10:49

Dan,

Thank you very much! That was helpful.

On a similar note, can I just call pressure (press) in the code as

Code:

const volScalarField& press = db().lookupObject<volScalarField>("p")
and then say

Code:

const fvPatchScalarField& P = press().boundaryField()[patchi];
To get the values of Pressure in the boundary patch? (In this case, the wall boundary)

Sorry if this seems very rudimentary....I am not very comfortable with the way OF is coded. Thanks again.

chegdan March 12, 2013 10:59

The compiler should tell you if it is a redefinition of the variable names or if it is a reserved word....since its job is to keep track of that. These variables have local scope so you can name them what you have suggested unless they are defined in another part of the code you are altering.

Quote:

Sorry if this seems very rudimentary....I am not very comfortable with the way OF is coded.
No worries, this is how you learn...by asking these questions :)

atmcfd March 15, 2013 00:59

Dan,

Thats right....Thank you :D.

I am pretty sure that the variable names I am using here are unique in the code and not used anywhere else. I just want to include the local \frac{\partial p}{\partial x}
term at the near wall cells in my code (which is a new wall function - I am coding it by seeing the nuSgsUSpaldingWallFunctionFvPatchScalarField.C , and reusing the code I want from it)

So, I do :
Code:

const volScalarField& pr = db().lookupObject<volScalarField>("p")[patchi]; // (Line 130) Read "Pressure" from the database structure

const volScalarField& bpr = pr().boundaryField()[patchi]; //  Defining new variable to the boundary field values of 'p' read from the previous line
const volVectorField Gbpr = Foam::fvc::grad(bpr); // (Line 138) Defining new variable for gradient of the pressure boundary field 'bpr'
const scalarField GradP = Gbpr.component(0); // Defining new variable for X-component of the gradient

After which I could use the local pressure gradient for the cell in my code as GradP[facei]

Compiling would give me this error:
Code:

NewWallFunctionFvPatchScalarField.C: In member function ‘virtual void Foam::incompressible::LESModels::NewWallFunctionFvPatchScalarField::evaluate(Foam::UPstream::commsTypes)’:
NewWallFunctionFvPatchScalarField.C:130: error: invalid initialization  of reference of type ‘const Foam::volScalarField&’ from expression  of type ‘const double’
NewWallFunctionFvPatchScalarField.C:138: error: no match for call to ‘(const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>) ()’

I guess the problem is in the call pr(), which is not associated with any function. But since I have read the "p" field using lookup, shouldn't it work?

the nuSgsUSpaldingWallFunctionFvPatchScalarField.C does a similar operation with "U" field, which was defined in LESModel.C. I'm wondering how I can fix my code to do the operation I want - I assume it should be somewhat simple for a C++ programmer, but I couldn't figure out myself.

Regards,
atm

atmcfd March 17, 2013 16:00

Some additional info:

The above code compiles fine if i do not make the pr().boundaryField call , remove [patchi] from Line 130, and use the 'pr' field as itself. Looks like If I just find out the function to use to create a boundaryField from a complete volScalarField, I will be done.

Thanks,

atm

chegdan March 20, 2013 21:41

If you want access to your boundary field from your volScalarField, look at your first post on how you originally accessed the boundary field

Code:

const fvPatchVectorField& U = lesModel.U().boundaryField()[patchi];
Look at the type. Look for fvPatchScalarField for some inspiration.

atmcfd March 24, 2013 22:33

Dan,

Thanks for responding. I will look into it more.....

Regards

Atm

Giancarlo_IngChimico April 11, 2013 18:50

Hi guys,
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?


Best


Giancarlo


All times are GMT -4. The time now is 15:55.