CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Define an array of "volVectroField" type

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 3 Post By Cyp
  • 1 Post By zhangyan
  • 1 Post By ancolli

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 20, 2013, 18:15
Default Define an array of "volVectroField" type
  #1
New Member
 
reza
Join Date: Apr 2013
Posts: 16
Rep Power: 13
haghgoo_reza is on a distinguished road
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
haghgoo_reza is offline   Reply With Quote

Old   June 21, 2013, 02:55
Default
  #2
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18
Cyp is on a distinguished road
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
fedvasu, sonGoku and HPE like this.
Cyp is offline   Reply With Quote

Old   June 24, 2013, 19:53
Default Loop over volVectorField
  #3
New Member
 
reza
Join Date: Apr 2013
Posts: 16
Rep Power: 13
haghgoo_reza is on a distinguished road
Thanks a lot Cyp.
Your information was pretty helpful to me.

Regards
Reza
haghgoo_reza is offline   Reply With Quote

Old   June 3, 2018, 21:02
Default
  #4
New Member
 
Anshul
Join Date: Dec 2017
Location: India
Posts: 25
Rep Power: 8
sonGoku is on a distinguished road
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
sonGoku is offline   Reply With Quote

Old   June 4, 2018, 03:34
Default
  #5
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 11
zhangyan is on a distinguished road
Quote:
Originally Posted by sonGoku View Post
what does wordList specieName contain?
is it used to input size of the array?
and how do I define it in transportProperties?
For a scalarList, it can be read in a Dict like this:
Code:
Z
(
0
0.5
1
);
Similarly, a wordList should be like this:
Code:
speciesNames
(
H2
O2
H2O
);
__________________
https://openfoam.top
zhangyan is offline   Reply With Quote

Old   May 9, 2020, 15:37
Default
  #6
Senior Member
 
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12
ancolli is on a distinguished road
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]
   );
 }
}
how to declare the pointer?
ancolli is offline   Reply With Quote

Old   May 9, 2020, 15:54
Default
  #7
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 11
zhangyan is on a distinguished road
Quote:
Originally Posted by ancolli View Post
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]
   );
 }
}
how to declare the pointer?

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]
            )
        );
    }
}
ancolli likes this.
__________________
https://openfoam.top
zhangyan is offline   Reply With Quote

Old   May 10, 2020, 21:09
Default
  #8
Senior Member
 
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12
ancolli is on a distinguished road
Quote:
Originally Posted by zhangyan View Post
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]
            )
        );
    }
}
Thanks a lot zhangyan

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)
due to the following piece of code:

Code:
        Y[s].set
        (
            s,
            new volScalarField
            (
                IOobject
                (
                    speciesNames[s],
                    runTime.timeName(),
                    mesh_region[i],
                    IOobject::MUST_READ,
                    IOobject::AUTO_WRITE
                ),
                mesh_region[i]
            )
        );
Do you know what can it be?
ancolli is offline   Reply With Quote

Old   May 10, 2020, 21:45
Default
  #9
Senior Member
 
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12
ancolli is on a distinguished road
Quote:
Originally Posted by ancolli View Post
Thanks a lot zhangyan

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)
due to the following piece of code:

Code:
        Y[s].set
        (
            s,
            new volScalarField
            (
                IOobject
                (
                    speciesNames[s],
                    runTime.timeName(),
                    mesh_region[i],
                    IOobject::MUST_READ,
                    IOobject::AUTO_WRITE
                ),
                mesh_region[i]
            )
        );
Do you know what can it be?
I found the mistake, sorry!

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]
            )
        );
    }
should be:

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]
            )
        );
    }
HPE likes this.
ancolli is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


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


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