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/)
-   -   Access a volScalarField from BC code (http://www.cfd-online.com/Forums/openfoam-programming-development/94752-access-volscalarfield-bc-code.html)

Hisham November 24, 2011 08:10

Access a volScalarField from BC code
 
Dear Foamers,

I am trying to access a volScalarField values at cells next to a patch from the BC code. I tried the following:
Code:

const fvPatchField<scalar>& Mu =
      patch().lookupPatchField<volScalarField, scalar>("solidShearMod");

The code compiles fine but does not work properly ... The value passed is different from what the solver outputs. I have tried that with a uniform value for the volScalarField. Nevertheless, the solver should have nonuniform values in practice.

I would appreciate any hint on what may be wrong. I did not provide more data because I frankly do not know what may cause this.

Best regards,
Hisham

marupio November 24, 2011 10:44

Hi Hisham,

I just did this myself. Are you trying to access its own values, or another volScalarField? If you are in... say... T's boundary condition, and you want T's values *next* to the boundary patch, then I can tell you what to do. Otherwise, you need to use the object registry to look up the other volScalarField.

This gives you a list of cell indices that correspond to the internal field cells next to the patch:

Code:

    labelList cellNeighbours(patch().faceCells());
Then it's one to one:

Code:

    internalField()[cellNeighbours[faceIndex]]
corresponds with:
Code:

    gradient()[faceIndex]
or whatever you are using.

Hisham November 24, 2011 11:27

Hi David,

Thanks a lot for the quick feedback. The volScalarField I am trying to access is not the one for the BC. The approach I posted is used in the tractionDisplacementFvPatchVectorField.C BC line 173 to access the sigmaD volSymmTensorField from the BC that is used for displacement volVectorField in the solidDisplacementFoam solver.

With regard to what you posted, I understand that in my case I should pass the whole volField from the registry then find cells with faces on patch and extract values individually ... Is that well understood?

Best regards,
Hisham

marupio November 24, 2011 11:29

Yes, use the object registry to gain a const reference to the field in question. The cellNeighbours list should be the same for the local GeometricField as it is for the volScalarField you look up.

Hisham November 25, 2011 15:27

Hi David,

I found a reference to internal field in the fvPatchField class (similar to the patch() reference). I will try to use it then if still not successful I will try the objectRegistry.

Thanks a lot for you help!

Best regards,
Hisham

marupio November 25, 2011 15:54

The internalField() reference or dimensionedInternalField() will give you direct access to the data in the GeometricField your boundary condition applies to, not any others. To access others, I think you have to use lookupObject in the objectRegistry.

Hisham November 25, 2011 16:33

OK ... Thanks again!


All times are GMT -4. The time now is 12:11.