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

Vector field from scalars

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

Reply
 
LinkBack Thread Tools Display Modes
Old   May 11, 2010, 10:39
Default Vector field from scalars
  #1
New Member
 
Vadims Geza
Join Date: Apr 2010
Location: Latvia
Posts: 9
Rep Power: 9
Vadims.geza is on a distinguished road
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!
Vadims.geza is offline   Reply With Quote

Old   May 11, 2010, 13:51
Default
  #2
New Member
 
Valerio Novaresio
Join Date: Mar 2009
Location: Polonghera, Cuneo, Italy
Posts: 27
Rep Power: 10
novyno is on a distinguished road
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! :-)
__________________
...The best way to acquire new knowledge is to share it...
novyno is offline   Reply With Quote

Old   May 21, 2017, 17:14
Default Error
  #3
New Member
 
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 29
Rep Power: 7
Sugajen is on a distinguished road
I did as you had suggested, but it throws an error saying "error: assignment of read-only location (&(& Ulu.Foam::GeometricField<Type, PatchField, GeoMesh>::internalField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>())->Foam:imensionedField<Foam::Vector<double>, Foam::volMesh>::<anonymous>.Foam::Field<Foam::Vect or<double> >::<anonymous>.Foam::List<Foam::Vector<double> >::<anonymous>.Foam::UList<T>:perator[]<Foam::Vector<double> >(i))->Foam::Vector<double>::<anonymous>.Foam::VectorSpa ce<Form, Cmpt, Ncmpts>::component<Foam::Vector<double>, double, 3u>(0)
Ulu.internalField()[i].component(vector::X) = 0;"

also,

" error: assignment of read-only location (&(& Ulu.Foam::GeometricField<Type, PatchField, GeoMesh>::internalField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>())->Foam:imensionedField<Foam::Vector<double>, Foam::volMesh>::<anonymous>.Foam::Field<Foam::Vect or<double> >::<anonymous>.Foam::List<Foam::Vector<double> >::<anonymous>.Foam::UList<T>:perator[]<Foam::Vector<double> >(i))->Foam::Vector<double>::<anonymous>.Foam::VectorSpa ce<Form, Cmpt, Ncmpts>::component<Foam::Vector<double>, double, 3u>(2)
Ulu.internalField()[i].component(vector::Z) = Jw.internalField()[i];
^
"
Sugajen is offline   Reply With Quote

Old   May 22, 2017, 04:24
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,653
Rep Power: 27
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
Hi all,

@Sugajen

In your initial attempt you tried to create vector from scalarFields. it is not easy.

Since you need volVectorField with default (calculated) boundary conditions, why not use something like:

Code:
const vector i(1, 0, 0);
const vector j(0, 1, 0);
const vector k(0, 0, 1);

volVectorField Vs("Vs", i*VsX + j*VsY + k*VsZ);
It seems that you even do not need AUTO_WRITE capability for the field (otherwise, you can use constructor from IOobject and volVectorField).

novyno's answer is correct for versions below 3.0.x. In 3 and 4 internalField is read-only, yet there is ref, which returns non-const reference.
alexeym is offline   Reply With Quote

Old   May 22, 2017, 18:16
Default
  #5
New Member
 
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 29
Rep Power: 7
Sugajen is on a distinguished road
Thank you Alexey. It works!
Sugajen is offline   Reply With Quote

Reply

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
generic scalars in star manuutin STAR-CD 0 August 7, 2009 06:05
Passive scalars and Star-CCM+ Tim CD-adapco 1 May 19, 2008 11:04
Flux functions for User-Defined Scalars Zhengcai Ye FLUENT 0 October 8, 2004 10:34
about .run file and information of scalars isidro CD-adapco 0 March 11, 2004 12:37
The Field Scalars in Tascflow Darcy CFX 0 November 19, 2003 23:14


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