CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

Assigning volVectorField components from three different volScalarField

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

Like Tree1Likes
  • 1 Post By Jerryfan

Reply
 
LinkBack Thread Tools Display Modes
Old   August 15, 2016, 11:33
Default Assigning volVectorField components from three different volScalarField
  #1
New Member
 
Aldo Muņoz
Join Date: Feb 2016
Posts: 3
Rep Power: 2
aldoMunoz is on a distinguished road
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.
aldoMunoz is offline   Reply With Quote

Old   August 16, 2016, 01:28
Default
  #2
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 47
Rep Power: 4
Jerryfan is on a distinguished road
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 likes this.
Jerryfan is offline   Reply With Quote

Old   August 16, 2016, 09:41
Default
  #3
New Member
 
Aldo Muņoz
Join Date: Feb 2016
Posts: 3
Rep Power: 2
aldoMunoz is on a distinguished road
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,
aldoMunoz is offline   Reply With Quote

Old   August 16, 2016, 11:37
Default
  #4
Member
 
Sergei
Join Date: Dec 2009
Posts: 77
Rep Power: 8
Zeppo is on a distinguished road
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.
Zeppo is offline   Reply With Quote

Old   August 16, 2016, 11:43
Default
  #5
New Member
 
Aldo Muņoz
Join Date: Feb 2016
Posts: 3
Rep Power: 2
aldoMunoz is on a distinguished road
Now it works.
Thanks a lot!
aldoMunoz is offline   Reply With Quote

Reply

Tags
components, volvectorfield

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compressible 2D airfoil rhoSimpleFoam fatal error volScalarField none jfournier OpenFOAM Running, Solving & CFD 2 August 20, 2016 18:18
execFlowFunctionObjects - unknown field problem Toorop OpenFOAM Post-Processing 16 March 14, 2016 04:25
using chemkin JMDag2004 OpenFOAM Pre-Processing 2 March 8, 2016 23:38
volScalarField to volVectorField syavash OpenFOAM Programming & Development 7 July 30, 2015 09:09
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 06:16


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