CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Field of arrays (https://www.cfd-online.com/Forums/openfoam-solving/59180-field-arrays.html)

alberto January 31, 2008 22:10

I have to store and manipulate
 
I have to store and manipulate an array of 15 scalars in each cell. These scalars should be passed to other functions and saved to file.

Is there a fast or pre-defined way to do something similar in OF?

With kind regards,
Alberto

alberto February 1, 2008 00:19

While trying to solving this i
 
While trying to solving this issue, I was thinking to use an IOPtrList, but I meet issues when I try to create a function which returns it.

In other words a function like:

tmp<ioptrlist<volscalarfield> > myFunc()

which returns an IOPtrList. Is this doable?

Regards,
Alberto

olesen February 1, 2008 03:10

Hi Alberto, In reply to you
 
Hi Alberto,

In reply to your first post:
if you want 15 scalars for each cell, why not define the corresponding class - eg, AlbertoScalars and pass that through?

Instead of using volScalarField, which is acually GeometricField<scalar,>, you could have a volAlbertoField:
GeometricField<albertoscalars,>.

In reply to your second post:
I don't think there are any restriction on what the tmp class can handle, but I would think you might be better having a PtrList instead of an IOPtrList and hook in the IOPtrList elsewhere from your tmp.

/mark

alberto February 1, 2008 12:35

Hello Mark, I thought of us
 
Hello Mark,

I thought of using volScalarFields because at a certain point I've to solve for them.

I will try your suggestion to use PtrList instead of IOPtrList, and if it doesn't work I'll reconsider your idea of the class for my scalars.

Thanks a lot,
Alberto

alberto February 1, 2008 12:55

Using PtrList I get the same i
 
Using PtrList I get the same issue I get with IOPtrList.

The compiler outputs the following:

/home/alberto/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/PtrList.C: In copy constructor 'Foam::PtrList<t>::PtrList(const Foam::PtrList<t>&) [with T = Foam::GeometricField<double,>]':
collisionModel/BGK/bgkCollision.C:123: instantiated from here
/home/alberto/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/PtrList.C:61: error: invalid conversion from 'Foam::DimensionedField<double,>*' to 'Foam::GeometricField<double,>*'
/home/alberto/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/tmpI.H: In destructor 'Foam::tmp<t>::~tmp() [with T = Foam::PtrList<foam::geometricfield<double,> >]':
collisionModel/BGK/bgkCollision.C:123: instantiated from here
/home/alberto/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/tmpI.H:82: error: 'class Foam::PtrList<foam::geometricfield<double,> >' has no member named 'okToDelete'
/home/alberto/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/tmpI.H:89: error: 'class Foam::PtrList<foam::geometricfield<double,> >' has no member named 'operator--'
/home/alberto/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/tmpI.H: In copy constructor 'Foam::tmp<t>::tmp(const Foam::tmp<t>&) [with T = Foam::PtrList<foam::geometricfield<double,> >]':
collisionModel/BGK/bgkCollision.C:123: instantiated from here
/home/alberto/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/tmpI.H:65: error: 'class Foam::PtrList<foam::geometricfield<double,> >' has no member named 'operator++'

when I declare:
tmp<ptrlist<volscalarfield> > myFunc
(
const PtrList<volscalarfield>& m,
const scalar& timeStep,
const scalar& p
) const;

and then define it as:

Foam::tmp<foam::ptrlist<foam::volscalarfield> > Foam::myModel::myFunc
(
const PtrList<volscalarfield>& m,
const scalar& timeStep,
const scalar& p
) const
{
/* cut code */

PtrList<volscalarfield> myList = m;

/* Other code here */

return myList;
}

(Sorry if caps are not right, I copy and pasted, and it seems they went lost somewhere).

Any ideas? :-)

Thanks in advance,
Alberto

alberto February 1, 2008 13:16

Just a bit more feedback. If I
 
Just a bit more feedback. If I remove tmp<...>, I just get the invalid conversion error in the copy constructor:

/home/alberto/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/PtrList.C:61: error: invalid conversion from 'Foam::DimensionedField<double,>*' to 'Foam::GeometricField<double,>*'

Looks strange to me, because both are PtrList<volscalarfield>.

Regards,
Alberto

olesen February 1, 2008 14:21

I can't really see what has go
 
I can't really see what has gone wrong here (still being very at C++), but since GeometricField is derived from DimensionedField, it looks like you are getting close.

Until you get it figured out, you might try cheating and just pass about Field\<scalar\> instead.

alberto February 1, 2008 14:29

What's funny is that it _must_
 
What's funny is that it _must_ be something under my eyes, because something similar to what I need is done in the sources of the code for example for species transport.

I just can't find an example of how a PtrList is passed as argument to a function, and then returned in some way.

However I'll investigate it furtherly, because using a PtrList makes the code a lot more clean and readable, and keeps it consistent with the algorithm I want to implement.

I'll make you know what I find.

Alberto

alberto February 1, 2008 15:04

It seems there's something not
 
It seems there's something not working properly to me. For example, if you write the simple lines:

PtrList<volscalarfield> a(10);
PtrList<volscalarfield> b = a;

you get exactly the same error when you compile.

A.

alberto February 3, 2008 13:38

Well, I was trying to do somet
 
Well, I was trying to do something meaningless I guess.

I just need to pass the PtrList by reference, and then use it directly in the method.

Regards,
A.

yashar.afarin September 25, 2011 09:10

I want to define an array
 
Hi Alberto,

I need exactly the same. Indeed I want to compute species mole fraction and also species diffusion coefficient and use them in YEqn. I read you post and it was very interesting but there is one question, did you solve your problem? how did you define an array with specific variables in each cell?
I really appreciate if you could help me!

alberto September 28, 2011 00:23

Hi,

it has been a while. I re-thought the implementation in order to use a PtrList of fields.

Best,
Alberto

Omarspace October 4, 2017 05:14

Stuck at same point
 
Hello all,

I am stuck at the same point. could you kindly elaborate how you managed to pass this problem ? :confused:


All times are GMT -4. The time now is 23:37.