CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Foam::FixedList accepts only static data members? (https://www.cfd-online.com/Forums/openfoam-programming-development/99494-foam-fixedlist-accepts-only-static-data-members.html)

Hagen April 4, 2012 11:11

Foam::FixedList accepts only static data members?
 
Dear Foamers,

I need to define a new vector type with a fixed length. For that purpose I used:
typedef FixedList<scalar, n_> newType_;
This appears to work with n being defined as a "static const int" only. In my case, however, n is an integer, which is initialized in another class and passed on. Trying to compile produces the following error:
error: invalid use of non-static data member ‘Foam::specie::n_
Any help on this issue is greatly appreciated!

Hagen

olesen April 5, 2012 02:51

Quote:

Originally Posted by Hagen (Post 353154)
Dear Foamers,

I need to define a new vector type with a fixed length. For that purpose I used:
typedef FixedList<scalar, n_> newType_;
This appears to work with n being defined as a "static const int" only. In my case, however, n is an integer, which is initialized in another class and passed on. Trying to compile produces the following error:
error: invalid use of non-static data member ‘Foam::specie::n_
Any help on this issue is greatly appreciated!

Hagen

The FixedList is a template class, you need to specify the type and dimension at compile time. If indeed you specify the "n" in the other class, you could also provide a typedef for the FixedList there too. It's hard to say without knowing what exactly you are trying to attempt.

Hagen April 5, 2012 03:08

I would like to define the new type to store species properties, e.g. the critical temperature, in a multi-component solver. Thus the size of the vector depends on the number of species involved. In order to have a flexible code, suitable for changing number of species, I want to read the vector size from the "thermophysicalProperties" dictionary.
Do I get it right that this is not possible with the FixedList class since the size of it is fixed during compilation?
Any suggestions how to define a vector type with flexible size?

Thank you!

olesen April 5, 2012 03:29

Quote:

Originally Posted by Hagen (Post 353236)
I would like to define the new type to store species properties, e.g. the critical temperature, in a multi-component solver. Thus the size of the vector depends on the number of species involved. In order to have a flexible code, suitable for changing number of species, I want to read the vector size from the "thermophysicalProperties" dictionary.
Do I get it right that this is not possible with the FixedList class since the size of it is fixed during compilation?
Any suggestions how to define a vector type with flexible size?

Thank you!

From your description: just use the List template class. You'll find lots of examples throughout OPENFOAM ... it's one of the most commonly used classes.


All times are GMT -4. The time now is 15:44.