Assigning volVectorField components from three different volScalarField

 Register Blogs Members List Search Today's Posts Mark Forums Read

 August 15, 2016, 11:33 Assigning volVectorField components from three different volScalarField #1 New Member   Aldo Muņoz Join Date: Feb 2016 Posts: 3 Rep Power: 2 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.

August 16, 2016, 01:28
#2
Member

Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 47
Rep Power: 4
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& pv = v.boundaryField()[patchI]； const fvPatchField& ps1 = s1.boundaryField()[patchI]； const fvPatchField& ps2 = s2.boundaryField()[patchI]； const fvPatchField& ps3 = s3.boundaryField()[patchI]； forAll(pv, faceI) { pv[faceI].x() = ps1[faceI]; pv[faceI].y() = ps2[faceI]; pv[faceI].z() = ps3[faceI]; } }

August 16, 2016, 09:41
#3
New Member

Aldo Muņoz
Join Date: Feb 2016
Posts: 3
Rep Power: 2

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 &pv = Re.boundaryField()[patchID]; const fvPatchField &ps1 = Rex.boundaryField()[patchID]; const fvPatchField &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 >’ to reference of type ‘Foam::fvPatchField >&’ discards qualifiers fvPatchField &pv = Re.boundaryField()[patchID];
What am I doing wrong? I have tried several changes to the code but can not find the right way.

 August 16, 2016, 11:37 #4 Member   Sergei Join Date: Dec 2009 Posts: 77 Rep Power: 8 You should change Code: `fvPatchField &pv = Re.boundaryField()[patchID];` to Code: `fvPatchField &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.

 August 16, 2016, 11:43 #5 New Member   Aldo Muņoz Join Date: Feb 2016 Posts: 3 Rep Power: 2 Now it works. Thanks a lot!

 Tags components, volvectorfield

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post jfournier OpenFOAM Running, Solving & CFD 2 August 20, 2016 18:18 Toorop OpenFOAM Post-Processing 16 March 14, 2016 04:25 JMDag2004 OpenFOAM Pre-Processing 2 March 8, 2016 23:38 syavash OpenFOAM Programming & Development 7 July 30, 2015 09:09 immortality OpenFOAM Post-Processing 30 September 15, 2013 06:16

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