CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   How to access mesh information to define a boundar condition (https://www.cfd-online.com/Forums/openfoam-solving/246240-how-access-mesh-information-define-boundar-condition.html)

Vader92 November 21, 2022 17:10

How to access mesh information to define a boundar condition
 
Hi, I'm new to OpenFoam. I'm looking to develop an adjoint optimization solver in OpenFOAM. I have a mesh size of (20,20,1) .I added a new volScalarField vf which i defined in my 0 folder.

internalField nonuniform List<scalar>
400

I want to implement a coded boundary condition such that for each element on the boundary, if vf=1 , U=(5, 0 0) and if vf=0, U=(0,0,0). My implementation looks something like

inlet
{
type codedMixed;
refValue uniform (0 0 0);
refGradient uniform (0 0 0);
valueFraction uniform 1;

name inletBC;

code
{
const fvPatch& boundaryPatch = patch();
vectorField& field = *this;
vectorField vf= vf;

forAll(boundaryPatch, faceI)
{
field[faceI] = vector((1-vf[faceI])*0 + vf[faceI]*5,0,0);
}

}
}

I believe the bolded line is causing some errors as I don't think that's the correct way to get the volScalarField vf. I am unsure as to how I could access vf and use it in this BC. Any help will be appreciated.


All times are GMT -4. The time now is 08:00.