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

Reading parameters for ignition source from a dictionary

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By Delcraft

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 18, 2015, 07:17
Default Reading parameters for ignition source from a dictionary
  #1
New Member
 
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14
Delcraft is on a distinguished road
Hello,

I would like to define an energy source (gaussian distribution in time and space) for the solver "reactingFoam" with parameters taken from a dictionary file. I created a file reading the source properties:
Code:
IOdictionary ignitionProperties
(
    IOobject
	(
    	    "ignitionProperties",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
     )
);
    const wordList spotNames(ignitionProperties.toc());

    forAll(spotNames, i)
    {
        const word& spotName = spotNames[i];
        Info<< "Creating settings for ignition spot: " << spotName << endl;

        const dictionary& subDict = IgnitionProperties.subDict(spotName);
        dimensionedScalar eps_("eps", dimensionSet(1,2,-2,0,0,0,0), scalar(0.0));
        dimensionedScalar sigmas_("sigmas", dimensionSet(0,1,0,0,0,0,0), scalar(1.0));
        dimensionedScalar sigmat_("sigmat", dimensionSet(0,0,1,0,0,0,0), scalar(1.0));
        dimensionedScalar tmax_("tmax", dimensionSet(0,0,1,0,0,0,0), scalar(0.0));
        dimensionedVector location_("location", dimensionSet(0,1,0,0,0,0,0), vector(0.0 0.0 0.0));
        eps_ = subDict.lookup("eps");
        sigmas_ = subDict.lookup("sigmas");
        sigmat_ = subDict.lookup("sigmat");
        tmax_ = subDict.lookup("tmax");
        location_ = subdict.lookup("location");
        Info<< "eps = " << eps_ << endl;
        Info<< "sigmas = " << sigmas_ << endl;
        Info<< "sigmat = " << sigmat_ << endl;
        Info<< "tmax = " << tmax_ << endl;
        Info<< "location = " << location_ << endl;
    }
And after that I added such code for energy source in "EEqn.H":
Code:
#include "readIgnitionProps.H"
    volScalarField& xCoord = mesh.C().component(vector::X);
    volScalarField& yCoord = mesh.C().component(vector::Y);
    volScalarField& zCoord = mesh.C().component(vector::Z);
    volScalarField& dist;
    const scalar& PI = 3.1415926535;
    volScalarField& ST;
    volScalarField& he = thermo.he();

    fvScalarMatrix EEqn
    (
        fvm::ddt(rho, he) + mvConvection->fvmDiv(phi, he)
      + fvc::ddt(rho, K) + fvc::div(phi, K)
      + (
            he.name() == "e"
          ? fvc::div
            (
                fvc::absolute(phi/fvc::interpolate(rho), U),
                p,
                "div(phiv,p)"
            )
          : -dpdt
        )
      - fvm::laplacian(turbulence->alphaEff(), he)
     ==
        reaction->Sh()
      + fvOptions(rho, he)
      + ST
    );

    forAll(mesh.cells(), celli)
    {
        forAll(spotNames, i)
        {
            dist = sqrt(sqr(xCoord - location_.value().x())
                     + sqr(yCoord - location_.value().y())
                     + sqr(zCoord - location_.value().z()));
            ST += eps_/4/sqr(PI)/pow(sigmas_,3)/sigmat_
                    *exp(-0.5*sqr(dist/sigmas_))
                    *exp(-0.5*sqr((runTime.value() - tmax_)/sigmat_));
        }
    }
Unfortunately, I get an error when I compile the solver:
Code:
Making dependency list for source file ignitionFoam.C
SOURCE=ignitionFoam.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam230/src/finiteVolume/lnInclude -I/opt/openfoam230/src/fvOptions/lnInclude -I/opt/openfoam230/src/meshTools/lnInclude -I/opt/openfoam230/src/sampling/lnInclude -I/opt/openfoam230/src/turbulenceModels/compressible/turbulenceModel -I/opt/openfoam230/src/thermophysicalModels/specie/lnInclude -I/opt/openfoam230/src/thermophysicalModels/reactionThermo/lnInclude -I/opt/openfoam230/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam230/src/thermophysicalModels/chemistryModel/lnInclude -I/opt/openfoam230/src/ODE/lnInclude -I/opt/openfoam230/src/combustionModels/lnInclude -IlnInclude -I. -I/opt/openfoam230/src/OpenFOAM/lnInclude -I/opt/openfoam230/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/ignitionFoam.o
In file included from EEqn.H:2:0,
                 from ignitionFoam.C:76:
readIgnitionProps.H: In function ‘int main(int, char**)’:
readIgnitionProps.H:19:37: error: ‘IgnitionProperties’ was not declared in this scope
readIgnitionProps.H:29:21: error: ‘subdict’ was not declared in this scope
In file included from ignitionFoam.C:76:0:
EEqn.H:3:58: error: invalid initialization of non-const reference of type ‘Foam::volScalarField& {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&}’ from an rvalue of type ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’
EEqn.H:4:58: error: invalid initialization of non-const reference of type ‘Foam::volScalarField& {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&}’ from an rvalue of type ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’
EEqn.H:5:58: error: invalid initialization of non-const reference of type ‘Foam::volScalarField& {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&}’ from an rvalue of type ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’
EEqn.H:6:21: error: ‘dist’ declared as reference but not initialized
EEqn.H:8:21: error: ‘ST’ declared as reference but not initialized
EEqn.H:36:38: error: ‘location_’ was not declared in this scope
EEqn.H:39:19: error: ‘eps_’ was not declared in this scope
EEqn.H:39:38: error: ‘sigmas_’ was not declared in this scope
EEqn.H:39:49: error: ‘sigmat_’ was not declared in this scope
EEqn.H:41:58: error: ‘tmax_’ was not declared in this scope
/opt/openfoam230/src/finiteVolume/lnInclude/readTimeControls.H:38:8: warning: unused variable ‘maxDeltaT’ [-Wunused-variable]
make: *** [Make/linux64GccDPOpt/ignitionFoam.o] Error 1
Could anyone tell me where should I place the link to the file "readIgnitionProps.H" to obtain the correct compilation of the code? Or maybe I made a principal mistake in other place?
Thanks for any help,

Delcraft
Delcraft is offline   Reply With Quote

Old   January 18, 2015, 08:39
Default
  #2
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12
ssss is on a distinguished road
Code:
const dictionary& subDict = IgnitionProperties.subDict(spotName);
Code:
location_ = subdict.lookup("location");
Should be

Code:
const dictionary& subDict = ignitionProperties.subDict(spotName);
Code:
location_ = subDict.lookup("location");
After that you should be careful, you are initializing variables inside a for loop
Code:
 forAll(spotNames, i)
so when you exit the for loop the variables will be destroyed and thus you get the EEqn.H:39:19: error: ‘eps_’ was not declared in this scope error, try to create them before the for loop
ssss is offline   Reply With Quote

Old   January 18, 2015, 10:00
Default
  #3
New Member
 
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14
Delcraft is on a distinguished road
Thank you ssss,

I've corrected these errors and now I have only problems with EEqn.H:

Code:
EEqn.H: In function ‘int main(int, char**)’:
EEqn.H:6:21: error: ‘dist’ declared as reference but not initialized
EEqn.H:8:21: error: ‘ST’ declared as reference but not initialized
EEqn.H:36:56: error: request for member ‘x’ in ‘location_.Foam::dimensioned<Type>::value [with Type = double]()’, which is of non-class type ‘double’
EEqn.H:37:55: error: request for member ‘y’ in ‘location_.Foam::dimensioned<Type>::value [with Type = double]()’, which is of non-class type ‘double’
EEqn.H:38:55: error: request for member ‘z’ in ‘location_.Foam::dimensioned<Type>::value [with Type = double]()’, which is of non-class type ‘double’
so consequently I have two questions:
1) How should I initialize variables "dist" and "ST", because the initialization like this:
Code:
    volScalarField& dist = 0.0;
    volScalarField& ST = 0.0;
doesn't work - in this case I have an error
Code:
error: invalid initialization of non-const reference of type ‘Foam::volScalarField& {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&}’ from an rvalue of type ‘double'
2) How to get a component from a vector? I'm trying to get it, for example, the component x as "location_.value().x()" but obviously I do it wrong.
Delcraft is offline   Reply With Quote

Old   January 18, 2015, 10:26
Default
  #4
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12
ssss is on a distinguished road
For 2) try:

Code:
location_.x()
For 1) try (the same with dist):

Code:
volScalarField ST=xCoord-xCoord;
It is a bit of a hack, but I'm not an expert of C++. Let me know if it works
ssss is offline   Reply With Quote

Old   January 18, 2015, 11:32
Default
  #5
New Member
 
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14
Delcraft is on a distinguished road
No, it doesn't. I think the main problem is I don't understand to which type of variable I should associate the values "dist" ( the distance from a mesh cell to the ignition point) and ST ( the source term itself) ☺
Delcraft is offline   Reply With Quote

Old   January 18, 2015, 12:45
Default
  #6
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12
ssss is on a distinguished road
Try then:

Code:
const volVectorField& centres = U.mesh.C().internalField();
volScalarField dist=mag(centres-location_);
It's a bit difficult to know what fails without the solver in hand.
ssss is offline   Reply With Quote

Old   January 21, 2015, 15:40
Default
  #7
New Member
 
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14
Delcraft is on a distinguished road
Hello,

I found a solution for my problem. It was necessary to create two scalar fields for the distance from mesh cell to ignition point and for the energy source and locate it in the file CreateFields.H. After that I created additional file with the source formulation and included it into EEqn.H (all necessary files are attached).

My second step is to permit to create several ignition sources in the domain, and at this step I can't understand how can I set the loop over all sources points for the mesh cells. I tried to do this by this way (in the file included to EEqn.H):

Code:
forAll(spotNames,i)
{
    ST += eps_/pow(sigmas_,3)/sigmat_/4/sqr(PI)*exp(-0.5*sqr(dist/sigmas_))
            *exp(-0.5*sqr((t - tmax_)/sigmat_));
}
where the energy source is summarized over all locations (spotNames, in my test there are two), but finally I got that all the energy is released in the second location.

Delcraft
Attached Files
File Type: h createFields.H (2.1 KB, 22 views)
File Type: h EEqn.H (767 Bytes, 25 views)
File Type: h readIgnitionProps.H (1.4 KB, 14 views)
File Type: h sourceTerm.H (349 Bytes, 15 views)
Delcraft is offline   Reply With Quote

Old   January 21, 2015, 17:01
Default
  #8
New Member
 
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14
Delcraft is on a distinguished road
I've solved this problem too, just slightly modifying the code of the dictionary input (creating a pointer list instead of single variable, as in this thread - http://www.cfd-online.com/Forums/ope...ictionary.html):

Code:
const wordList spotNames(ignitionProperties.toc());
 
    PtrList<dimensionedScalar> eps_(spotNames.size());
    PtrList<dimensionedScalar> sigmas_(spotNames.size());
    PtrList<dimensionedScalar> sigmat_(spotNames.size());
    PtrList<dimensionedScalar> tmax_(spotNames.size());
    PtrList<dimensionedVector> location_(spotNames.size());
 
    forAll(spotNames, i)
    {
        const word& spotName = spotNames[i];
        const dictionary& subDict = ignitionProperties.subDict(spotName);
 
        eps_.set
        (
             i,
             new dimensionedScalar(subDict.lookup("eps"))
        );
        sigmas_.set
        (
             i,
             new dimensionedScalar(subDict.lookup("sigmas"))
        );
        sigmat_.set
        (
             i,
             new dimensionedScalar(subDict.lookup("sigmat"))
        );
        tmax_.set
        (
             i,
             new dimensionedScalar(subDict.lookup("tmax"))
        );
        location_.set
        (
             i,
             new dimensionedVector(subDict.lookup("location"))
        );
    }
and setting the loop over every source location:
Code:
forAll(spotNames,i)
{
        dist = mag(mesh.C() - location_[i]);
        ST += eps_[i]/pow(sigmas_[i],3)/sigmat_[i]/4/sqr(PI)*exp(-0.5*sqr(dist/sigmas_[i]))
                    *exp(-0.5*sqr((t - tmax_[i])/sigmat_[i]));
}
All is resolved, excuse me for so many words ))
Attached Files
File Type: h createFields.H (2.3 KB, 27 views)
File Type: h readIgnitionProps.H (2.4 KB, 27 views)
File Type: h sourceTerm.H (334 Bytes, 20 views)
panachristos likes this.
Delcraft is offline   Reply With Quote

Reply

Tags
dictionary, energy source, reactingfoam

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[swak4Foam] difficulties installing swak4foam newbie29 OpenFOAM Community Contributions 120 October 21, 2022 04:01
Trouble compiling utilities using source-built OpenFOAM Artur OpenFOAM Programming & Development 14 October 29, 2013 10:59
[swak4Foam] Error bulding swak4Foam sfigato OpenFOAM Community Contributions 18 August 22, 2013 12:41
[swak4Foam] build problem swak4Foam OF 2.2.0 mcathela OpenFOAM Community Contributions 14 April 23, 2013 13:59
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 10:23


All times are GMT -4. The time now is 01:05.