CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Vector field from scalars (http://www.cfd-online.com/Forums/openfoam/76002-vector-field-scalars.html)

Vadims.geza May 11, 2010 10:39

Vector field from scalars
 
Hello all!

I need to create vector field from three scalars. It can not be done by using vector operations in this case. I have got all scalar components VsX, VsY and VsZ.

volVectorField Vs
IOobject
(
"Vs",
runTime.timeName(),
mesh,
IOobject::NO_READ
),
mesh,
dimenstionedVector("variableName", dimensionSet(0,0,0,0,0,0,0), Foam::vector(VsX,VsY,VsZ))

it says
error: no matching function for call to 'Foam::Vector<double>::Vector(Foam::volScalarField &, Foam::volScalarField&, Foam::volScalarField&)'

So, please give me some advice how to do this, if it is possible!
Many thanks in advance!

novyno May 11, 2010 13:51

Hi,

you can read the vectorField initialized with dummy values (i.e zero value):

volVectorField Vs
(
IOobject
(
"Vs",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

do the same with the scalarField(s):

volScalarField VsX
(
IOobject
(
"VsX",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

etc...

and finanlly:

forAll( Vs.internalField(), i)
{
Vs.internalField()[i].component(vector::X) = Vsx.internalField()[i];
Vs.internalField()[i].component(vector::Y) = Vsy.internalField()[i];
Vs.internalField()[i].component(vector::Z) = Vsz.internalField()[i];
}
forAll( Vs.boundaryField(), boundaryI)
{
forAll( Vs.boundaryField()[boundaryI], i)
{
Vs.boundaryField()[boundaryI][i].component(vector::X) = Vsx.boundaryField()[boundaryI][i];
Vs.boundaryField()[boundaryI][i].component(vector::Y) = Vsy.boundaryField()[boundaryI][i];
Vs.boundaryField()[boundaryI][i].component(vector::Z) = Vsz.boundaryField()[boundaryI][i];
}
}

Of course if you already have the fields you don't have to read them! :-)


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