|
[Sponsors] |
June 20, 2013, 18:15 |
Define an array of "volVectroField" type
|
#1 |
New Member
reza
Join Date: Apr 2013
Posts: 16
Rep Power: 13 |
Hi all,
When I define a variable "Uold" as: volVectorField Uold("Uold", U); Uold = U; it works. However, I would like to define an array of Uold. I mean, I want to have Uold1, Uold2, ..... So When I define the above expression inside a loop it does not work I.e. for (int i=1; i < 100; i++) { volVectorField Uold[i] ("Uold", U); Uold[i] = U; } Could anybody please help me how to define an array of the object "volVectroField" type? Thanks |
|
June 21, 2013, 02:55 |
|
#2 |
Senior Member
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18 |
Hi!
You can be inspired by what is done for multicomponent mass transfer where there is a table of volScalarField Y. You first have to reserve the memory with a list of pointer : Code:
PtrList <volScalarField> Y(speciesNames.size()); Code:
wordList speciesNames ( transportProperties.lookup("speciesNames") ); Code:
forAll(speciesNames, s) { Y.set ( s, new volScalarField ( IOobject ( speciesNames[s], runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); } Cyp |
|
June 24, 2013, 19:53 |
Loop over volVectorField
|
#3 |
New Member
reza
Join Date: Apr 2013
Posts: 16
Rep Power: 13 |
Thanks a lot Cyp.
Your information was pretty helpful to me. Regards Reza |
|
June 3, 2018, 21:02 |
|
#4 |
New Member
Anshul
Join Date: Dec 2017
Location: India
Posts: 25
Rep Power: 8 |
what does wordList specieName contain?
is it used to input size of the array? and how do I define it in transportProperties? Thank You i would hiGhly appreciate any sort of help/feedback |
|
June 4, 2018, 03:34 |
|
#5 | |
Senior Member
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 11 |
Quote:
Code:
Z ( 0 0.5 1 ); Code:
speciesNames ( H2 O2 H2O );
__________________
https://openfoam.top |
||
May 9, 2020, 15:37 |
|
#6 |
Senior Member
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12 |
What about the same procedure but for several regions?
for example: Code:
forAll(regions, i) { forAll(speciesNames, s) { Y[i].set ( s, new volScalarField ( IOobject ( speciesNames[s], runTime.timeName(), mesh_region[i], IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh_region[i] ); } } |
|
May 9, 2020, 15:54 |
|
#7 | |
Senior Member
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 11 |
Quote:
Code:
PtrList<PtrList<volScalarField>> Y(regions.size()); forAll(regions, i) { Y.set ( i, new PtrList<volScalarField>(mesh_region.size()) ); forAll(speciesNames, s) { Y[nsf].set ( s, new volScalarField ( IOobject ( speciesNames[s],, runTime.timeName(), mesh_region[i], IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh_region[i] ) ); } }
__________________
https://openfoam.top |
||
May 10, 2020, 21:09 |
|
#8 | |
Senior Member
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12 |
Quote:
It compiles well and it works great when I have 1 species (speciesNames.size() = 1, s = 0) However, when I run the code with 2 species (speciesNames.size() = 2, s = 0,1 ), I got the following error for s = 1: Code:
#0 Foam::error::printStack(Foam::Ostream&) at ??:? #1 Foam::sigSegv::sigHandler(int) at ??:? #2 ? in "/lib/x86_64-linux-gnu/libc.so.6" #3 ? in "/home/user/OpenFOAM/user-6/platforms/linux64GccDPInt32Opt/bin/solver" #4 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6" #5 ? in "/home/user/OpenFOAM/user-6/platforms/linux64GccDPInt32Opt/bin/solver" Segmentation fault (core dumped) Code:
Y[s].set ( s, new volScalarField ( IOobject ( speciesNames[s], runTime.timeName(), mesh_region[i], IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh_region[i] ) ); |
||
May 10, 2020, 21:45 |
|
#9 | |
Senior Member
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12 |
Quote:
the following lines: Code:
Y.set ( i, new PtrList<volScalarField>(mesh_region.size()) ); forAll(speciesNames, s) { Y[s].set ( s, new volScalarField ( IOobject ( speciesNames[s], runTime.timeName(), mesh_region[i], IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh_region[i] ) ); } Code:
Y.set ( i, new PtrList<volScalarField>(speciesNames.size()) ); forAll(speciesNames, s) { Y[i].set ( s, new volScalarField ( IOobject ( speciesNames[s], runTime.timeName(), mesh_region[i], IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh_region[i] ) ); } |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
rhoSimpleFoam | claco | OpenFOAM | 7 | April 20, 2010 04:32 |
buoyantSimpleRadiationFoam | msarkar | OpenFOAM | 0 | February 15, 2010 06:22 |
Flow Around a Cylinder | ronaldo | OpenFOAM | 5 | September 18, 2009 08:13 |
Missing math.h header | Travis | FLUENT | 4 | January 15, 2009 11:48 |
UDF FOR UNSTEADY TIME STEP | mayur | FLUENT | 3 | August 9, 2006 10:19 |