CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Boundary condition. How to get the normal gradient of the patchField U (https://www.cfd-online.com/Forums/openfoam-programming-development/151984-boundary-condition-how-get-normal-gradient-patchfield-u.html)

Sylv April 21, 2015 07:57

Boundary condition. How to get the normal gradient of the patchField U
 
Dear Foam,

I have a home-made solver, which has the volVectorField named Vs aside the classic U and p field. In a custom inlet boundary condition of U (named "customBC"), I need to access Vs, which is quite easy with a lookupObject. I also need the normal gradient of Vs on my inlet BC. I have implemented several possibilities, which work fine, but they are either costly or not flexible.

  1. First possibility: get snGard(Vs) in the BC and extract the right patchField from snGard(Vs) with such code:
    Code:

    // in the custom boundary condition of U
    const volVectorField& Vs = this->db().lookupObject<volVectorField>("Vs");
    const surfaceVectorField snGradVs = fvc::snGrad(Vs);
    const label& patchIndex(this->patch().index());
    const vectorField& patchSnGradVs = snGradVs.boundaryField()[patchIndex];

    This works well, but if I have N "customBC", snGrad(Vs) is calculated N time, which is costly. It is also not very efficient to calculate snGrad on the entire field and keeping only the patch field...
  2. Second possibility: calculate snGrad(Vs) in the solver directly. The calculation is done only one, even with multiple "customBC". But it is not very flexible. If I don't need "customBC", snGradVs is calculated for nothing...
Is there a why to calculate the snGrad of a boundary field more efficiently?

Cheers,
Marcel

schröder April 21, 2015 08:29

From a boundary field you have access to the face value ("psif"), the value at the cell center ("psic") and the delta coeffient ("delta"), which is 1/(distance from center to face).
From these values you can calculate the normal gradient sngrad=delta*(psif-psic).

I don't remember the functions to access psif,psic and delta, but you'll find them if you browse the fvPatchField documentation.

Martin


All times are GMT -4. The time now is 06:47.