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

Solving N (Non-Coupled) Scalar Transport Equations

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By marc.immer

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 8, 2011, 04:20
Default Solving N (Non-Coupled) Scalar Transport Equations
  #1
New Member
 
Joel Lehikoinen
Join Date: Jun 2011
Posts: 26
Rep Power: 15
joel.lehikoinen is on a distinguished road
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
joel.lehikoinen is offline   Reply With Quote

Old   July 8, 2011, 05:00
Default
  #2
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
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()
            )
        );
    }
Then use a for loop to solve the equations, as done in, for example, YEqn.H in solvers/combustion/chemFoam
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   July 12, 2011, 03:41
Default
  #3
New Member
 
Joel Lehikoinen
Join Date: Jun 2011
Posts: 26
Rep Power: 15
joel.lehikoinen is on a distinguished road
Thank you very much for your help, I managed to create the solver I will need.
joel.lehikoinen is offline   Reply With Quote

Old   February 19, 2013, 03:56
Default
  #4
New Member
 
AD
Join Date: Aug 2012
Location: Japan
Posts: 4
Rep Power: 14
dinksy is on a distinguished road
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
dinksy is offline   Reply With Quote

Old   October 1, 2013, 06:47
Default
  #5
New Member
 
Marc
Join Date: Sep 2012
Posts: 17
Rep Power: 14
marc.immer is on a distinguished road
Hi,
I'm asking myself the same question (how to initialize the array in the 0 folder).
Did you make any progress?

Marc
marc.immer is offline   Reply With Quote

Old   October 1, 2013, 09:36
Default
  #6
Senior Member
 
Olivier
Join Date: Jun 2009
Location: France, grenoble
Posts: 272
Rep Power: 18
olivierG is on a distinguished road
hello,

Why you don't use reactingFoam or rhoReacting(Buoyant)Foam ?
At least take a look at this solver.

regards,
olivier
olivierG is offline   Reply With Quote

Old   October 1, 2013, 09:44
Default
  #7
New Member
 
Marc
Join Date: Sep 2012
Posts: 17
Rep Power: 14
marc.immer is on a distinguished road
Thanks, reactingFoam is helpful. But I guess there is no easier way than duplicating/renaming the files in the 0 Folder for each species. But this at least can be automated with a script.

Cheers
Marc
marc.immer is offline   Reply With Quote

Old   October 1, 2013, 09:50
Default
  #8
Senior Member
 
Olivier
Join Date: Jun 2009
Location: France, grenoble
Posts: 272
Rep Power: 18
olivierG is on a distinguished road
yes and no

If you take a look at reactingFoam tutorial, for product of reaction, you have a "Ydefault" file, in which you specify the defaut boundary conditions for the species. So you may try to use this.

regards,
olivier
olivierG is offline   Reply With Quote

Old   October 1, 2013, 11:16
Default
  #9
New Member
 
Marc
Join Date: Sep 2012
Posts: 17
Rep Power: 14
marc.immer is on a distinguished road
I took a look at the reactingFoam solver. Since I'm only interested in a passive scalar transport, having a whole thermodynamic model might be a bit overkill... I'm not sure how I could only extract the classes I need, since it all seems to dependend on the classes basicMultiComponentMixture and chemistryReader.

Regards
Marc
marc.immer is offline   Reply With Quote

Old   October 3, 2013, 09:00
Default
  #10
New Member
 
Marc
Join Date: Sep 2012
Posts: 17
Rep Power: 14
marc.immer is on a distinguished road
Hi,

I managed to get it to work. I used parts of the reactingFoam for the loop structure,

Code:
tmp<fv::convectionScheme<scalar> > mvConvection
	(
	    fv::convectionScheme<scalar>::New
	    (
		mesh,
		fields,
		phi,
		mesh.divScheme("div(phi,si_h)")
	    )
	);
	volScalarField kappaEff
	(
	    "kappaEff",
	    turbulence->nu()/Pr + turbulence->nut()/Prt
	);

	forAll(s, i)
    	{
	    volScalarField& si = s[i];

	    tmp<fvScalarMatrix> siEqn
	    (
		    fvm::ddt(si)
		  + mvConvection->fvmDiv(phi, si)
		  - fvm::laplacian(kappaEff, si)
	    );

	    sources.constrain(siEqn());
            solve(siEqn() == sources(si),mesh.solver("si"));
        }
and copy pasted parts of the chemistryReader to get the initial files.
To define the species, I added a list into the transportProperties dict. (makes it easier to read in the createFields.H

Code:
wordList names(transportProperties.lookup("scalars"));
    PtrList<volScalarField> s(names.size());

    forAll(s, i)
    {
        IOobject header
        (
            names[i],
            mesh.time().timeName(),
            mesh,
            IOobject::NO_READ
        );

        // check if field exists and can be read
        if (header.headerOk())
        {
            s.set
            (
                i,
                new volScalarField
                (
                    IOobject
                    (
                        names[i],
                        mesh.time().timeName(),
                        mesh,
                        IOobject::MUST_READ,
                        IOobject::AUTO_WRITE
                    ),
                    mesh
                )
            );
        }
        else
        {
            volScalarField sdefault
            (
                IOobject
                (
                    "sdefault",
                    mesh.time().timeName(),
                    mesh,
                    IOobject::MUST_READ,
                    IOobject::NO_WRITE
                ),
                mesh
            );

            s.set
            (
                i,
                new volScalarField
                (
                    IOobject
                    (
                        names[i],
                        mesh.time().timeName(),
                        mesh,
                        IOobject::NO_READ,
                        IOobject::AUTO_WRITE
                    ),
                    sdefault
                )
            );
        }
    }
    multivariateSurfaceInterpolationScheme<scalar>::fieldTable fields;

    forAll(s, i)
	{
	    fields.add(s[i]);
	}
olivierG and reza2031 like this.
marc.immer is offline   Reply With Quote

Reply

Tags
scalar transport


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
GAMG solver causes troubles colinB OpenFOAM Running, Solving & CFD 5 June 13, 2013 08:48
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 05:35
Differences between serial and parallel runs carsten OpenFOAM Bugs 11 September 12, 2008 12:16
Convergence moving mesh lr103476 OpenFOAM Running, Solving & CFD 30 November 19, 2007 15:09


All times are GMT -4. The time now is 16:13.