|
[Sponsors] |
July 26, 2005, 11:32 |
Hi,
How can I create an arra
|
#1 |
Member
Radu Mustata
Join Date: Mar 2009
Location: Zaragoza, Spain
Posts: 99
Rep Power: 17 |
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 |
|
July 26, 2005, 11:38 |
Try creating a ptrList of them
|
#2 |
Senior Member
Join Date: Mar 2009
Posts: 854
Rep Power: 22 |
Try creating a ptrList of them.
|
|
July 26, 2005, 12:17 |
Thanks for the message, Henry.
|
#3 |
Member
Radu Mustata
Join Date: Mar 2009
Location: Zaragoza, Spain
Posts: 99
Rep Power: 17 |
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 |
|
July 26, 2005, 15:08 |
Try something like
ptrList<
|
#4 |
Senior Member
Mattijs Janssens
Join Date: Mar 2009
Posts: 1,419
Rep Power: 26 |
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) |
|
July 27, 2005, 09:52 |
OK, thanks. I did the followin
|
#5 |
Member
Radu Mustata
Join Date: Mar 2009
Location: Zaragoza, Spain
Posts: 99
Rep Power: 17 |
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 |
|
July 27, 2005, 09:58 |
you should loop over the field
|
#6 |
Senior Member
Join Date: Mar 2009
Posts: 854
Rep Power: 22 |
you should loop over the fields and use fields[i] rather than fields(i).
|
|
September 12, 2005, 08:48 |
Hi again, I´m back with my lit
|
#7 |
Member
Radu Mustata
Join Date: Mar 2009
Location: Zaragoza, Spain
Posts: 99
Rep Power: 17 |
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 |
|
September 12, 2005, 14:47 |
doesn't it compile? Where? Fai
|
#8 |
Senior Member
Mattijs Janssens
Join Date: Mar 2009
Posts: 1,419
Rep Power: 26 |
doesn't it compile? Where? Fail during running? Where?
You will need to define your volScalarField properly (so with an IOobject and mesh etc.). |
|
January 31, 2007, 17:50 |
Hi everybody,
is it possibl
|
#9 |
New Member
diego n.
Join Date: Mar 2009
Posts: 17
Rep Power: 17 |
Hi everybody,
is it possible to use PtrList with Matrix<scalar>? Thanks in advance Diego |
|
January 29, 2008, 15:28 |
Sorry for the stupid question,
|
#10 |
New Member
C.E.M.
Join Date: Mar 2009
Posts: 16
Rep Power: 17 |
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 |
|
January 29, 2008, 15:46 |
Eeeeasy! http://www.cfd-online
|
#11 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
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 |
|
January 30, 2008, 13:40 |
Neat. Thanks Hrv! I hope you
|
#12 |
New Member
C.E.M.
Join Date: Mar 2009
Posts: 16
Rep Power: 17 |
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 |
|
|
|
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 |