CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM

Help with this line of code :

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   March 11, 2013, 22:42
Default Help with this line of code :
  #1
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
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?

Thank you all for your time.

Regards

A.T.M
atmcfd is offline   Reply With Quote

Old   March 12, 2013, 01:12
Default
  #2
Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 41
Rep Power: 6
ybapat is on a distinguished road
U.patchInternalField() will only give U field in neighboring cells to the patch and not complete internal field.

Regards,
-Yogesh
ybapat is offline   Reply With Quote

Old   March 12, 2013, 08:58
Default
  #3
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
Quote:
Originally Posted by ybapat View Post
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
atmcfd is offline   Reply With Quote

Old   March 12, 2013, 11:27
Default
  #4
Senior Member
 
chegdan's Avatar
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 543
Rep Power: 18
chegdan will become famous soon enough
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.
__________________
Dan

Find me on twitter @dancombest and LinkedIn
chegdan is offline   Reply With Quote

Old   March 12, 2013, 11:49
Default
  #5
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
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.
atmcfd is offline   Reply With Quote

Old   March 12, 2013, 11:59
Default
  #6
Senior Member
 
chegdan's Avatar
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 543
Rep Power: 18
chegdan will become famous soon enough
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
__________________
Dan

Find me on twitter @dancombest and LinkedIn

Last edited by chegdan; March 12, 2013 at 12:45.
chegdan is offline   Reply With Quote

Old   March 15, 2013, 01:59
Default
  #7
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
Dan,

Thats right....Thank you .

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

Last edited by atmcfd; March 18, 2013 at 23:02. Reason: edit
atmcfd is offline   Reply With Quote

Old   March 17, 2013, 17:00
Default
  #8
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
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

Last edited by atmcfd; March 18, 2013 at 23:03.
atmcfd is offline   Reply With Quote

Old   March 20, 2013, 22:41
Default
  #9
Senior Member
 
chegdan's Avatar
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 543
Rep Power: 18
chegdan will become famous soon enough
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.
__________________
Dan

Find me on twitter @dancombest and LinkedIn
chegdan is offline   Reply With Quote

Old   March 24, 2013, 23:33
Default
  #10
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
Dan,

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

Regards

Atm
atmcfd is offline   Reply With Quote

Old   April 11, 2013, 18:50
Post
  #11
New Member
 
Giancarlo
Join Date: Apr 2013
Location: Milan
Posts: 18
Rep Power: 4
Giancarlo_IngChimico is on a distinguished road
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
Giancarlo_IngChimico is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenFOAM 1.7.1 installation problem on OpenSUSE 11.3 flakid OpenFOAM Installation 16 December 28, 2010 09:48
OpenFOAM15 installables are incomplete problem with paraFoam tryingof OpenFOAM Bugs 17 December 7, 2008 05:41
OpenFOAM with IBM AIX matthias OpenFOAM Installation 20 March 25, 2008 03:36
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 15:56
What is the Better Way to Do CFD? John C. Chien Main CFD Forum 54 April 23, 2001 08:10


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