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/)
-   -   Assigning volVectorField components from three different volScalarField (https://www.cfd-online.com/Forums/openfoam-programming-development/176305-assigning-volvectorfield-components-three-different-volscalarfield.html)

aldoMunoz August 15, 2016 11:33

Assigning volVectorField components from three different volScalarField
 
Hi foamers,
I need to assign values from three volScalarField to the components of a volVectorFIeld.

Is there any direct way to do this operation? Otherwise, they have a tip for this.

thanks in advance to anyone who can help me.

Jerryfan August 16, 2016 01:28

Hi,


It might look like this:
supposing you have:
Quote:

volVectorField v;
volScalarField s1;
volScalarField s2;
volScalarField s3;

forAll(v, cellI)
{
v[cellI].x()=s1[cellI];
v[cellI].y()=s2[cellI];
v[cellI].z()=s3[cellI];
}
Also, for the boundary conditions:

Quote:

forAll(v.boundaryField(), patchI)
{
fvPatchField<vector>& pv = v.boundaryField()[patchI];
const fvPatchField<scalar>& ps1 = s1.boundaryField()[patchI];
const fvPatchField<scalar>& ps2 = s2.boundaryField()[patchI];
const fvPatchField<scalar>& ps3 = s3.boundaryField()[patchI];

forAll(pv, faceI)
{
pv[faceI].x() = ps1[faceI];
pv[faceI].y() = ps2[faceI];
pv[faceI].z() = ps3[faceI];
}
}

aldoMunoz August 16, 2016 09:41

Thanks for your reply,

I used your code in this way:

Quote:

volScalarField Rex("Rex" , "equation" );
volScalarField Rey("Rey" , "equation");

forAll(Re , celli)
{
Re[celli].x() = Rex[celli];
Re[celli].y() = Rey[celli];
}

label patchIDempty = mesh.boundaryMesh().findPatchID("defaultFaces");
forAll(Re.boundaryField() , patchID)
{
if(patchID != patchIDempty)
{
fvPatchField<vector> &pv = Re.boundaryField()[patchID];
const fvPatchField<scalar> &ps1 = Rex.boundaryField()[patchID];
const fvPatchField<scalar> &ps2 = Rey.boundaryField()[patchID];

forAll(pv, faceI)
{
pv[faceI].x() = ps1[faceI];
pv[faceI].y() = ps2[faceI];

}
}
}
and the volVectorFIeld Re is created in createFields.H:

Quote:

volVectorField Re
(
IOobject
(
"Re",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedVector("Re", dimless, Foam::vector(0,0,0))
);
when i tried to compile i have this error:
Quote:

calcTau0.H:18:56: error: binding ‘const Foam::fvPatchField<Foam::Vector<double> >’ to reference of type ‘Foam::fvPatchField<Foam::Vector<double> >&’ discards qualifiers
fvPatchField<vector> &pv = Re.boundaryField()[patchID];
What am I doing wrong? I have tried several changes to the code but can not find the right way.

I appreciate your help,

Zeppo August 16, 2016 11:37

You should change
Code:

fvPatchField<vector> &pv = Re.boundaryField()[patchID];
to
Code:

fvPatchField<vector> &pv = Re.boundaryFieldRef()[patchID];
The interface has been changed all over the sources. Non-ref version returns const-access, ref version returns non-const access.

aldoMunoz August 16, 2016 11:43

Now it works.
Thanks a lot!


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