|
[Sponsors] |
Reading parameters for ignition source from a dictionary |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 18, 2015, 08:17 |
Reading parameters for ignition source from a dictionary
|
#1 |
New Member
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14 |
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; } 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_)); } } 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 Thanks for any help, Delcraft |
|
January 18, 2015, 09:39 |
|
#2 |
Senior Member
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 13 |
Code:
const dictionary& subDict = IgnitionProperties.subDict(spotName); Code:
location_ = subdict.lookup("location"); Code:
const dictionary& subDict = ignitionProperties.subDict(spotName); Code:
location_ = subDict.lookup("location"); Code:
forAll(spotNames, i) |
|
January 18, 2015, 11:00 |
|
#3 |
New Member
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14 |
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’ 1) How should I initialize variables "dist" and "ST", because the initialization like this: Code:
volScalarField& dist = 0.0; volScalarField& ST = 0.0; 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' |
|
January 18, 2015, 11:26 |
|
#4 |
Senior Member
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 13 |
For 2) try:
Code:
location_.x() Code:
volScalarField ST=xCoord-xCoord; |
|
January 18, 2015, 12:32 |
|
#5 |
New Member
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14 |
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) ☺
|
|
January 18, 2015, 13:45 |
|
#6 |
Senior Member
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 13 |
Try then:
Code:
const volVectorField& centres = U.mesh.C().internalField(); volScalarField dist=mag(centres-location_); |
|
January 21, 2015, 16:40 |
|
#7 |
New Member
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14 |
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_)); } Delcraft |
|
January 21, 2015, 18:01 |
|
#8 |
New Member
Paul
Join Date: Apr 2012
Posts: 27
Rep Power: 14 |
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")) ); } 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])); } |
|
Tags |
dictionary, energy source, reactingfoam |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] difficulties installing swak4foam | newbie29 | OpenFOAM Community Contributions | 120 | October 21, 2022 05:01 |
Trouble compiling utilities using source-built OpenFOAM | Artur | OpenFOAM Programming & Development | 14 | October 29, 2013 11:59 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 13:41 |
[swak4Foam] build problem swak4Foam OF 2.2.0 | mcathela | OpenFOAM Community Contributions | 14 | April 23, 2013 14:59 |
Version 15 on Mac OS X | gschaider | OpenFOAM Installation | 113 | December 2, 2009 11:23 |