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

Initializing constants

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 21, 2010, 09:59
Default Initializing constants
  #1
New Member
 
Michael Gruber
Join Date: Oct 2009
Location: Graz
Posts: 13
Rep Power: 16
gruber is on a distinguished road
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);
The class looks like this:

HTML Code:
# include "IOdictionary.H"
class A
{
  const IOdictionary transportProperties_;
  const dimensionedScalar Sct_;
  const dimensionedScalar g_;
public:
  A;
}
The constructor looks like this:

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") ) )
{}
The compiler doesn't report any bugs, but when I try to run a testcase the following error is displayed during the constructor call

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
Can someone please tell me the error in my program?

Thank you very much.
gruber is offline   Reply With Quote

Old   April 21, 2010, 10:35
Default
  #2
Member
 
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 16
CedricVH is on a distinguished road
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.
CedricVH is offline   Reply With Quote

Old   April 21, 2010, 10:52
Default
  #3
New Member
 
Michael Gruber
Join Date: Oct 2009
Location: Graz
Posts: 13
Rep Power: 16
gruber is on a distinguished road
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();
}
I modified a working solver like I wrote above to initialize a transportProperty parameter and it failed. So there should be something wrong with my initializing algorithm.
gruber is offline   Reply With Quote

Old   April 21, 2010, 12:34
Default
  #4
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
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.
niklas is offline   Reply With Quote

Old   April 22, 2010, 05:40
Default
  #5
New Member
 
Michael Gruber
Join Date: Oct 2009
Location: Graz
Posts: 13
Rep Power: 16
gruber is on a distinguished road
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);
for the class

HTML Code:
# include "IOdictionary.H"
class A
{
  const dimensionedScalar& Sct_;
  const dimensionedVector& g_;
public:
  A(Sct, g);
}
with the constructor

HTML Code:
A::A(Sct, g) : Sct_( Sct ), g_( g ) {}
gruber is offline   Reply With Quote

Reply

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
Initializing constants gruber Main CFD Forum 0 April 21, 2010 09:57
what constants to choose for std k-e model daniel.struwig FLUENT 0 April 18, 2009 06:51
query regarding role of initializing in a solving Kishore FLUENT 2 July 4, 2007 23:23
Switches and Real Constants for Diesel Combustion Tony Siemens 0 July 30, 2006 20:15
Modelling a turbulent jet and k-epsilon constants Ant Siemens 3 January 24, 2005 15:56


All times are GMT -4. The time now is 23:53.