|
[Sponsors] |
May 11, 2010, 10:39 |
Vector field from scalars
|
#1 |
New Member
Vadims Geza
Join Date: Apr 2010
Location: Latvia
Posts: 9
Rep Power: 16 |
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! |
|
May 11, 2010, 13:51 |
|
#2 |
New Member
Valerio Novaresio
Join Date: Mar 2009
Location: Polonghera, Cuneo, Italy
Posts: 27
Rep Power: 17 |
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... |
|
May 21, 2017, 17:14 |
Error
|
#3 |
Member
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 52
Rep Power: 14 |
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]; ^ " |
|
May 22, 2017, 04:24 |
|
#4 |
Senior Member
|
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); 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. |
|
May 22, 2017, 18:16 |
|
#5 |
Member
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 52
Rep Power: 14 |
Thank you Alexey. It works!
|
|
|
|
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 | Siemens | 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 | Siemens | 0 | March 11, 2004 11:37 |
The Field Scalars in Tascflow | Darcy | CFX | 0 | November 19, 2003 22:14 |