|
[Sponsors] |
April 21, 2010, 10:59 |
Initializing constants
|
#1 |
New Member
Michael Gruber
Join Date: Oct 2009
Location: Graz
Posts: 13
Rep Power: 17 |
Hello,
I'm looking for a solution of my problem. I have defined constant dimensioned scalars and vectors in the transportProperties dictionary, eg: HTML Code:
Sct Sct [0 2 -1 0 0 0 0] 2.0e-09; g g [ 0 1 -2 0 0 0 0] (0 0 9.81); HTML Code:
# include "IOdictionary.H" class A { const IOdictionary transportProperties_; const dimensionedScalar Sct_; const dimensionedScalar g_; public: A; } HTML Code:
A::A : transportProperties_( IOobject( "transportProperties", U.time().constant(), U.db(), IOobject::MUST_READ, IOobject::NO_WRITE)), Sct_ ( dimensionedScalar( transportProperties_.lookup("Sct") ) ), g_ ( dimensionedVector( transportProperties_.lookup("g") ) ) {} HTML Code:
#0 Foam::error::printStack(Foam::Ostream&) in "/home/of/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/libOpenFOAM.so" #1 Foam::sigSegv::sigSegvHandler(int) in "/home/of/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/libOpenFOAM.so" #2 ?? in "/lib64/libc.so.6" #3 std::string::assign(std::string const&) in "/home/of/OpenFOAM/ThirdParty/gcc-4.3.1/platforms/linux64/lib64/libstdc++.so.6" #4 Foam::IOerror::operator()(char const*, char const*, int, Foam::string const&, int, int) in "/home/of/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/libOpenFOAM.so" #5 Foam::IOerror::operator()(char const*, char const*, int, Foam::dictionary const&) in "/home/of/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/libOpenFOAM.so" #6 Foam::dictionary::lookupEntry(Foam::word const&, bool) const in "/home/of/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/libOpenFOAM.so" #7 Foam::dictionary::lookup(Foam::word const&, bool) const in "/home/of/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/libOpenFOAM.so" #8 Foam::IncompressibleCloud::IncompressibleCloud(Foam::volPointInterpolation const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) in "/home/of/OpenFOAM/of-1.5/applications/bin/linux64GccDPOpt/icoRLF" #9 main in "/home/of/OpenFOAM/of-1.5/applications/bin/linux64GccDPOpt/icoRLF" #10 __libc_start_main in "/lib64/libc.so.6" #11 Foam::regIOobject::readIfModified() in "/home/of/OpenFOAM/of-1.5/applications/bin/linux64GccDPOpt/icoRLF" Segmentation fault Thank you very much. |
|
April 21, 2010, 11:35 |
|
#2 |
Member
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 17 |
A segmentation error usually has to something to do with an array being out of bounds.
In your class, you have defined const dimensionedScalar g_; instead of const dimensionedVector g_; which is different from your constructor. |
|
April 21, 2010, 11:52 |
|
#3 |
New Member
Michael Gruber
Join Date: Oct 2009
Location: Graz
Posts: 13
Rep Power: 17 |
Thank you for your answer.
You are right. I have posted it wrongly. Certainly it should mean: HTML Code:
# include "IOdictionary.H" class A { const IOdictionary transportProperties_; const dimensionedScalar Sct_; const dimensionedVector g_; public: A(); } |
|
April 21, 2010, 13:34 |
|
#4 |
Super Moderator
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29 |
How can that compile?
How does class A know about U when it has no arguments in the constructor? and you dont need to do the typecast Sct_ (transportProperties_.lookup("Sct")) is sufficient for dimensionedScalars. |
|
April 22, 2010, 06:40 |
|
#5 |
New Member
Michael Gruber
Join Date: Oct 2009
Location: Graz
Posts: 13
Rep Power: 17 |
I found a workaround for my problem:
I read in the parameters from the dictionary transportProperties as global parameters and assign them to the class by the constructor call: HTML Code:
transportProperties_( IOobject( "transportProperties", U.time().constant(), U.db(), IOobject::MUST_READ, IOobject::NO_WRITE)); dimensionedScalar Sct ( transportProperties_.lookup("Sct") ); dimensionedVector g ( transportProperties_.lookup("g") ) A(Sct, g); HTML Code:
# include "IOdictionary.H" class A { const dimensionedScalar& Sct_; const dimensionedVector& g_; public: A(Sct, g); } HTML Code:
A::A(Sct, g) : Sct_( Sct ), g_( g ) {} |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Initializing constants | gruber | Main CFD Forum | 0 | April 21, 2010 10:57 |
what constants to choose for std k-e model | daniel.struwig | FLUENT | 0 | April 18, 2009 07:51 |
query regarding role of initializing in a solving | Kishore | FLUENT | 2 | July 5, 2007 00:23 |
Switches and Real Constants for Diesel Combustion | Tony | Siemens | 0 | July 30, 2006 21:15 |
Modelling a turbulent jet and k-epsilon constants | Ant | Siemens | 3 | January 24, 2005 16:56 |