CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   setFieldsDict for spatially varying field (https://www.cfd-online.com/Forums/openfoam/194034-setfieldsdict-spatially-varying-field.html)

Joanne October 9, 2017 10:17

setFieldsDict for spatially varying field
 
Hi all, I was hoping someone could shed some light.

I am looking to create a scalar field that varies linearly as a function of space and would like to know if there's a way to do it through setFieldsDict.

I am using OF v4.1 on ubuntu 16.06 so unfortunately swak4foam isn't available for me without a complete overhaul.

Any help would be deeply appreciated.

JFM November 15, 2017 22:11

Hi Joanne

Not sure if this is what you are looking for but this post may assist:
https://www.cfd-online.com/Forums/op...ed-volume.html

Regards
JFM

Taataa November 16, 2017 15:18

A while ago I used this snippet for setting a parabolic boundary condition for U at the inlet:

Code:

inlet
    {
        type            codedFixedValue;
        value          uniform (0 0 0);
        redirectType    parabolaProfile; 

        code
        #{
            const fvPatch& boundaryPatch = patch();
            const vectorField& Cf = boundaryPatch.Cf();

            vectorField& field = *this;
            scalar uave = 10;
            scalar h = 5e-3;
           
            scalar vel;

            forAll(Cf, faceI)
            {
                vel = 6 * uave / (h*h) * (h * Cf[faceI].y() - Cf[faceI].y() * Cf[faceI].y());
                field[faceI] = vector(vel, 0, 0);
            }
        #};
    }

You can use a similar approach.


All times are GMT -4. The time now is 04:21.