|
[Sponsors] | |||||
|
|
|
#1 |
|
New Member
Joel Lehikoinen
Join Date: Jun 2011
Posts: 26
Rep Power: 3 ![]() |
Hi,
I need to create a solver based on buoyantPimpleFoam which solves an arbitrary (around 10) scalar transport equations. I have written a solver which solves one passive scalar transport equation. I could just copy-paste that code enough many times, but I would like to know if a more elegant solution is possible: Namely, how easy it would be to implement a for-loop that solves N scalar transport equations, where N is specified by the user? The problem is, I don't know C++ and I'm not too familiar with the classes present in OpenFOAM. As far as I know, the vectors in OpenFOAM are always 3-dimensional. But could I use a tensor of rank (1,N) or (N,1) to store the scalars? Or is using a tensor a bad idea, if I want to have different BCs for the scalars? Tensor would be nice because then I wouldn't have to worry about how to get OF to read/write files with indices in their names (scalar1, scalar2, etc.). This is not a critical problem, as I said I can just copy-paste the code snippet that solves one scalar transport equation N times, but if I want to change the number of scalars later it becomes cumbersome to recompile the solver every time. I was just wondering if anyone with more knowledge of C++ and OF source code knows these things. Regards, Joel |
|
|
|
|
|
|
|
|
#2 |
|
Senior Member
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 345
Rep Power: 12 ![]() |
Sure, you can use a PtrList. Here's how you initialise them:
Code:
// Create a list of pointers to the mass fraction field of each species.
PtrList<volScalarField> chemicalSpecies(numberOfSpecies);
for (label i=0; i<numberOfSpecies; ++i)
{
Info << "Creating Species " << namesOfSpecies[i] << endl;
chemicalSpecies.set
(
i,
new volScalarField
(
IOobject
(
namesOfSpecies[i],
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("zero", dimless, 0.0),
mixtureFraction.boundaryField().types()
)
);
}
__________________
Laurence R. McGlashan :: Website |
|
|
|
|
|
|
|
|
#3 |
|
New Member
Joel Lehikoinen
Join Date: Jun 2011
Posts: 26
Rep Power: 3 ![]() |
Thank you very much for your help, I managed to create the solver I will need.
|
|
|
|
|
|
|
|
|
#4 |
|
New Member
AD
Join Date: Aug 2012
Location: Japan
Posts: 4
Rep Power: 2 ![]() |
I am also trying to solve a similar problem of solving transport equation of n scalars, say c, and would like to define them as an array, such as c[n] instead of defining n separate scalarfields. The above thread was of some help but if you can tell me which solver it is a part of then I could look into it to clarify my doubts. The main problem I face is with the definition of c as an array in the initial time folder [0].
Regards |
|
|
|
|
|
![]() |
| Tags |
| scalar transport |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| GAMG solver causes troubles | colinB | OpenFOAM Running, Solving & CFD | 3 | January 26, 2013 15:57 |
| Full pipe 3D using icoFoam | cyberbrain | OpenFOAM | 4 | March 16, 2011 10:20 |
| calculation diverge after continue to run | zhajingjing | OpenFOAM | 0 | April 28, 2010 04:35 |
| Differences between serial and parallel runs | carsten | OpenFOAM Bugs | 11 | September 12, 2008 11:16 |
| Convergence moving mesh | lr103476 | OpenFOAM Running, Solving & CFD | 30 | November 19, 2007 14:09 |