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

Assigning volVectorField components from three different volScalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes
  • 5 Post By Jerryfan
  • 2 Post By Zeppo

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 15, 2016, 12:33
Default Assigning volVectorField components from three different volScalarField
  #1
New Member
 
Aldo Muņoz
Join Date: Feb 2016
Posts: 4
Rep Power: 10
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, 02:28
Default
  #2
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 13
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];
}
}
Jerryfan is offline   Reply With Quote

Old   August 16, 2016, 10:41
Default
  #3
New Member
 
Aldo Muņoz
Join Date: Feb 2016
Posts: 4
Rep Power: 10
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, 12:37
Default
  #4
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22
Zeppo will become famous soon enough
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.
victorious_BIG and daron like this.
Zeppo is offline   Reply With Quote

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

Reply

Tags
components, volvectorfield


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
volScalarField to volVectorField syavash OpenFOAM Programming & Development 16 September 28, 2018 14:23
Compressible 2D airfoil rhoSimpleFoam fatal error volScalarField none jfournier OpenFOAM Running, Solving & CFD 4 September 28, 2017 07:28
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
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 07:16


All times are GMT -4. The time now is 17:37.