CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Define an array of "volVectroField" type (http://www.cfd-online.com/Forums/openfoam-programming-development/119642-define-array-volvectrofield-type.html)

haghgoo_reza June 20, 2013 18:15

Define an array of "volVectroField" type
 
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

Cyp June 21, 2013 02:55

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());
where speciesNames is a list of word defined elsewhere. For example,
Code:

wordList speciesNames
(
    transportProperties.lookup("speciesNames")
);

Then you create your speciesNames.size() objects on the heap:

Code:

forAll(speciesNames, s)
{
  Y.set
  (
        s,
        new volScalarField
        (
            IOobject
            (
                speciesNames[s],
                runTime.timeName(),
                mesh,
                IOobject::MUST_READ,
                IOobject::AUTO_WRITE
        ),
        mesh
  );
}

Best,
Cyp

haghgoo_reza June 24, 2013 19:53

Loop over volVectorField
 
Thanks a lot Cyp.
Your information was pretty helpful to me.:)

Regards
Reza


All times are GMT -4. The time now is 01:25.