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

Array of fields

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 26, 2005, 11:32
Default Hi, How can I create an arra
  #1
Member
 
Radu Mustata
Join Date: Mar 2009
Location: Zaragoza, Spain
Posts: 99
Rep Power: 17
r2d2 is on a distinguished road
Hi,
How can I create an array of volScalFields in one CreatFields.H, say of oodles? Say field[i], i = 0,10...Is there an example somewhere?
Cheers,
Radu
r2d2 is offline   Reply With Quote

Old   July 26, 2005, 11:38
Default Try creating a ptrList of them
  #2
Senior Member
 
Join Date: Mar 2009
Posts: 854
Rep Power: 22
henry is on a distinguished road
Try creating a ptrList of them.
henry is offline   Reply With Quote

Old   July 26, 2005, 12:17
Default Thanks for the message, Henry.
  #3
Member
 
Radu Mustata
Join Date: Mar 2009
Location: Zaragoza, Spain
Posts: 99
Rep Power: 17
r2d2 is on a distinguished road
Thanks for the message, Henry.
I thought of something like this in CreateFields.H.

const int nVarmax = 10;
for (int i =0; i<nVarmax; i++)
{

word fieldName = "name_of_field"[i]

volScalarField field[i]
(
IOobject
(
fieldName,
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
}
Still have to sort out the "name_of_field"[i] and field[i] bits...
Cheers,
Radu
r2d2 is offline   Reply With Quote

Old   July 26, 2005, 15:08
Default Try something like ptrList<
  #4
Senior Member
 
Mattijs Janssens
Join Date: Mar 2009
Posts: 1,419
Rep Power: 26
mattijs is on a distinguished road
Try something like

ptrList<volscalarfield> fields(10);

for (i=0 ...)
{
word fieldName = "field_" + Foam::name(i);

fields.hook(new volScalarField(IOobject(...))
}

See e.g foamToVTK.C, call to readFields (though is templated)
mattijs is offline   Reply With Quote

Old   July 27, 2005, 09:52
Default OK, thanks. I did the followin
  #5
Member
 
Radu Mustata
Join Date: Mar 2009
Location: Zaragoza, Spain
Posts: 99
Rep Power: 17
r2d2 is on a distinguished road
OK, thanks. I did the following:

ptrList<volscalarfield> fields(10);
for (int i =0; i<10; i++)
{
word fieldName = "field_" + Foam::name(i);
Info<< "Reading field " << fieldName<< endl;
fields.hook(
volScalarField
(
IOobject
(
fieldName,
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
)
);

}
So now if I want to solve an, say, convection diffusion eq + source term with one such field (actually all of them) what do I refer to in the ddt, div and laplacian operators? This is kind of what I want:

solve
(
fvm::ddt(fields(i))
+ fvm::div(phi,fields(i))
- fvm::laplacian(sgsModel->nuEff(),fields(i))
);

Many thanks,
Radu
r2d2 is offline   Reply With Quote

Old   July 27, 2005, 09:58
Default you should loop over the field
  #6
Senior Member
 
Join Date: Mar 2009
Posts: 854
Rep Power: 22
henry is on a distinguished road
you should loop over the fields and use fields[i] rather than fields(i).
henry is offline   Reply With Quote

Old   September 12, 2005, 08:48
Default Hi again, I´m back with my lit
  #7
Member
 
Radu Mustata
Join Date: Mar 2009
Location: Zaragoza, Spain
Posts: 99
Rep Power: 17
r2d2 is on a distinguished road
Hi again, I´m back with my little problems.
Having done what I was taught to do above, and the things work fine with no source term I would like now to add some source for each field and then to calculate at run time a "mean field" (mean wrt the number of fields) and write it out.
Thought of doing in the body of oodles.C:
volScalarField meanFields;
for (int i =0; i<10; i++){

meanFields +=fields[i];


}
meanFields /=10;

...but doesn´t seem to work. Should I do something like in createAverages.H and calculateAverages.H?
Thanks,
Radu
r2d2 is offline   Reply With Quote

Old   September 12, 2005, 14:47
Default doesn't it compile? Where? Fai
  #8
Senior Member
 
Mattijs Janssens
Join Date: Mar 2009
Posts: 1,419
Rep Power: 26
mattijs is on a distinguished road
doesn't it compile? Where? Fail during running? Where?

You will need to define your volScalarField properly (so with an IOobject and mesh etc.).
mattijs is offline   Reply With Quote

Old   January 31, 2007, 17:50
Default Hi everybody, is it possibl
  #9
New Member
 
diego n.
Join Date: Mar 2009
Posts: 17
Rep Power: 17
diegon is on a distinguished road
Hi everybody,

is it possible to use PtrList with Matrix<scalar>?

Thanks in advance

Diego
diegon is offline   Reply With Quote

Old   January 29, 2008, 15:28
Default Sorry for the stupid question,
  #10
New Member
 
C.E.M.
Join Date: Mar 2009
Posts: 16
Rep Power: 17
evan is on a distinguished road
Sorry for the stupid question, but I am trying to use a ptrlist (parameter list?) in createfields.H. I have:

PtrList<volscalarfield> nu(Y);
for (int i=0, i<Y.size(); i++)
{
word nui = "nu_" + Foam::name(i);
Info << "Reading Field << nui << endl;
nu.set
(
volScalarField
(
IOobject
(
nui,
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
)
);
}

And when I compile I get:

error: no matching function for call to "Foam::PtrList< ... etc ..."

Would somebody mind explaining to me what I'm doing wrong here?

Evan
evan is offline   Reply With Quote

Old   January 29, 2008, 15:46
Default Eeeeasy! http://www.cfd-online
  #11
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Eeeeasy! Do:

nu.set
(
i,
new volScalarField
(
...
);


See it - you need and index and a new in front of volScalarField.

Enjoy,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   January 30, 2008, 13:40
Default Neat. Thanks Hrv! I hope you
  #12
New Member
 
C.E.M.
Join Date: Mar 2009
Posts: 16
Rep Power: 17
evan is on a distinguished road
Neat. Thanks Hrv! I hope you can forgive my programming ignorance ... you should have seen me a year ago ! Seems I spend a lot of time enjoying your text, most recently Numerical Solution Algorithms ..., and am excited to take a closer look at this new coupledFvScalarMatrix class!

I posted the below question yesterday in "Running / Solving / CFD: Pollutant dispersion in the environment" too, though it seems related to this thread, and maybe this is a more appropriate venue for the question, so let me copy it here, and sorry for double posting.

----------------------
Hi all,

So to revisit the question raised by Alberto, does anyone know (or be
willing to discuss) how to make an indexed list of constants that is
read from a dictionary. So, the diffusivity example Alberto brought up
would work great. That is, say you have n diffusion constants listed
in your constants dictionary as:

dimensionedScalar D1 (dictionary.lookup("D1")); . . . dimensionedScalar Dn (dictionary.lookup("DY"));

but you want to index them in your solver (along with other indexed
fields) as:

for(label i=0; i<n; i++)
{
volScalarField& Yi = Y[i];

// call D[i] list here

solve
(
fvm::ddt(Yi)
+ fvm::D[i]*fvm::laplacian(Yi)

);

etc.

Or is there a better way about going about this? Mattijs' suggestion
from before is currently over my head .

Best,
Evan
evan 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
array in UDF Kamal FLUENT 1 November 7, 2013 02:15
can we initialize an array in UDF? blueberry Fluent UDF and Scheme Programming 2 April 14, 2009 13:00
CFD for photovoltaic array Achmadi Main CFD Forum 1 May 21, 2007 05:42
??cfx5.6 array name?? Erica CFX 0 December 28, 2004 08:28
array initialization Ossi Siemens 1 February 20, 2004 12:07


All times are GMT -4. The time now is 08:38.