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

Viscosity model - error: object is not allocated - C++ beginner

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 23, 2016, 11:48
Default Viscosity model - error: object is not allocated - C++ beginner
  #1
Member
 
Vinícius da Costa Ávila
Join Date: Jul 2015
Location: Porto Alegre, Brazil
Posts: 62
Rep Power: 11
avila.vc is on a distinguished road
Hi,

I am trying to implement viscosity models in twoPhaseEulerFoam, but I am a beginner with C++.

It compiles ok, but when I try to run with bubbleColumn tutorial, I get this error message:

Code:
--> FOAM FATAL ERROR: 
object of type N4Foam14transportModelE is not allocated

    From function Foam::autoPtr<T>::operator->()
    in file /opt/OpenFOAM-3.0.x/src/OpenFOAM/lnInclude/autoPtrI.H at line 176.

FOAM aborting
I have modified phaseModel.H as follows:
Code:
    
    // Private data   
...
      //- Thermophysical properties
        autoPtr<rhoThermo> thermo_;

       //- Viscosity model properties
        autoPtr<transportModel> transport_; // I have included this line
...
    // Member Functions
// I have modified the lines below, the original code is commented right after each line
...
        //- Return the laminar viscosity
        tmp<volScalarField> nu() const
        {
            return transport_->nu(); //return thermo_->nu();
        }

        //- Return the laminar viscosity for patch
        tmp<scalarField> nu(const label patchi) const
        {
            return transport_->nu(patchi); //return thermo_->nu(patchi);
        }

        //- Return the laminar dynamic viscosity
        tmp<volScalarField> mu() const
        {
            return transport_->nu()*rho(); //return thermo_->mu();
        }

        //- Return the laminar dynamic viscosity for patch
        tmp<scalarField> mu(const label patchi) const
        {
            return transport_->nu(patchi)*rho(); //return thermo_->mu(patchi);
        }
...
What have I done wrong?
__________________
Vinícius dC.A.
avila.vc is offline   Reply With Quote

Old   March 23, 2016, 15:38
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
autoPtr is just a pointer. It needs to point to something. You need to set it. That is, you need to give it a transportModel. Either in the constructor initialisation list, or with a call to set().
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   February 10, 2022, 00:32
Default
  #3
Member
 
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 97
Rep Power: 5
saicharan662000@gmail.com is on a distinguished road
hello avila,
Have you solved the problem?
saicharan662000@gmail.com is offline   Reply With Quote

Old   February 10, 2022, 11:04
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by saicharan662000@gmail.com View Post
hello avila,
Have you solved the problem?

A common problem you need to watch out for: the autoPtr behaves somewhat like auto_ptr (obsolete) as well as unique_ptr. Specifically, this means there is a misfeature that the copy constructor actually behaves like a move constructor and "steals" the pointer. If you have code using autoPtr for internal storage, you need to decide which behaviour you want:
  1. allow copy to 'steal' the pointer (default behaviour)
  2. initialize the new version to nullptr and have a lazy creation later in the class
  3. clone the autoPtr if non-null, or initialize as nullptr
The third option may be what you want. In this case, the autoPtr provides its own 'clone()' method that forwards to the clone method on the underlying pointer, or returns a nullptr if the original autoPtr was itself a nullptr.
olesen is offline   Reply With Quote

Old   February 10, 2022, 11:18
Default Error:Object not allocated.
  #5
Member
 
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 97
Rep Power: 5
saicharan662000@gmail.com is on a distinguished road
Hello olesen,
Thanks for reply. Can you explain it in more detail.

I am developing the evaporation solver. I am using compressible Interfoam solver. I am modelling my physics in twoPhaseMixtureThermo files. I have calculated mDotAlphal which is evaporation rate. And it is declared as private member. As it is a private member I used following code in twoPhaseMixtureThermo. H as
Code:
 tmp<volScalarField> mDotE = this-> mDotAlphal
. And I used mDotE in pEqn. H and alpha Equation.
Code for pEqn is
Code:
tmp<volScalarField> mDotE = mixture.mDotE();
fvScalarMatrix p_rghEqnIncomp
        (
            fvc::div(phiHbyA)
          - fvm::laplacian(rAUf, p_rgh)
          - mDotE()*(1/rho1 - 1/rho2)
        );
Solver compiled well but got the error Object not allocated when test case was setup.

Thanks in advance
saicharan662000@gmail.com is offline   Reply With Quote

Old   February 14, 2022, 02:00
Default
  #6
Member
 
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 97
Rep Power: 5
saicharan662000@gmail.com is on a distinguished road
Quote:
Originally Posted by olesen View Post
A common problem you need to watch out for: the autoPtr behaves somewhat like auto_ptr (obsolete) as well as unique_ptr. Specifically, this means there is a misfeature that the copy constructor actually behaves like a move constructor and "steals" the pointer. If you have code using autoPtr for internal storage, you need to decide which behaviour you want:
  1. allow copy to 'steal' the pointer (default behaviour)
  2. initialize the new version to nullptr and have a lazy creation later in the class
  3. clone the autoPtr if non-null, or initialize as nullptr
The third option may be what you want. In this case, the autoPtr provides its own 'clone()' method that forwards to the clone method on the underlying pointer, or returns a nullptr if the original autoPtr was itself a nullptr.

@olesen,
this is how I declared the fields.
twoPhaseMixtureThermo.H


Code:
class twoPhaseMixtureThermo
:
    public psiThermo,
    public twoPhaseMixture,
    public interfaceProperties
{
    // Private Data

        //- Thermo-package of phase 1
        autoPtr<rhoThermo> thermo1_;

        //- Thermo-package of phase 2
        autoPtr<rhoThermo> thermo2_;
        //ADDED
        dimensionedScalar lambdaF_; // thermal conductivity [kg*m/s3/K]
        dimensionedScalar Tsat_; // saturation temp [K]
        dimensionedScalar Tinf_; // bulk temperature of the water [K]
        dimensionedScalar ifg_; // latent heat for for fluid [m2/s2]
        dimensionedScalar charLength_; //characteristic length
        dimensionedScalar g_; // gravity
        dimensionedScalar mcCoeff_; // mass condensation coefficient for better view
        // interface area function //ADDED
        tmp<volScalarField>interfaceArea() const;
        // heat transfer coefficient
        tmp<volScalarField> hCoeff() const;
         tmp<volScalarField> mDotAlphal() const;

twoPhaseMixtureThermo.C


Code:
Foam::twoPhaseMixtureThermo::twoPhaseMixtureThermo
(
    const volVectorField& U,
    const surfaceScalarField& phi
    
    
)
:
    psiThermo(U.mesh(), word::null),
    twoPhaseMixture(U.mesh(), *this),
    interfaceProperties(alpha1(), U, *this),
    thermo1_(nullptr),
    thermo2_(nullptr),
    //ADDED
    lambdaF_("lambdaF", dimMass*dimLength/(dimTime*dimTime*dimTime*dimTemperature) , lookup("lambdaF")),
    Tsat_("Tsat",dimTemperature, lookup("Tsat")),
    Tinf_("Tinf",dimTemperature, lookup("Tinf")),
    ifg_("ifg", dimLength*dimLength/(dimTime*dimTime),lookup("ifg")),
    charLength_("charLength", dimLength, lookup("charLength")),
    g_("gravity", dimLength/(dimTime*dimTime) ,lookup("gravity")),
    mcCoeff_( (Tsat_-Tinf_) / ifg_ )
{
    {
        volScalarField T1
        (
            IOobject
            (
                IOobject::groupName("T", phase1Name()),
                U.mesh().time().timeName(),
                U.mesh()
            ),
            T_,
            calculatedFvPatchScalarField::typeName
        );
        T1.write();
    }

    {
        volScalarField T2
        (
            IOobject
            (
                IOobject::groupName("T", phase2Name()),
                U.mesh().time().timeName(),
                U.mesh()
            ),
            T_,
            calculatedFvPatchScalarField::typeName
        );
        T2.write();
    }


    // Note: we're writing files to be read in immediately afterwards.
    //       Avoid any thread-writing problems.
    fileHandler().flush();

    thermo1_ = rhoThermo::New(U.mesh(), phase1Name());
    thermo2_ = rhoThermo::New(U.mesh(), phase2Name());

    // thermo1_->validate(phase1Name(), "e");
    // thermo2_->validate(phase2Name(), "e");

    correct();
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::twoPhaseMixtureThermo::~twoPhaseMixtureThermo()
{}


// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //


void Foam::twoPhaseMixtureThermo::correctThermo()
{
    thermo1_->T() = T_;
    thermo1_->he() = thermo1_->he(p_, T_);
    thermo1_->correct();

    thermo2_->T() = T_;
    thermo2_->he() = thermo2_->he(p_, T_);
    thermo2_->correct();
}

//ADDED
Foam::tmp<Foam::volScalarField>
Foam::twoPhaseMixtureThermo::interfaceArea() const
{
    // return the interfacial area based on model for interfacial area
    // returns dimensions Area

    // model based on regular volume cells, taking the largest cut area
    // as maximum for area, linear increase and decrease with alpha
    const volScalarField& cellVolume =
        alpha1().db().lookupObject<volScalarField>("cellVolu");
    volScalarField limitedAlpha1 = min(max(alpha1(), scalar(0)), scalar(1));

    const dimensionedScalar
                areaFactor("areaFactor",dimensionSet(0,2,0,0,0,0,0), 0.0);

    volScalarField interfaceArea = alpha1() * areaFactor;
    volScalarField maxArea = alpha1() * areaFactor;

    maxArea = sqrt(3.0)*pow(cellVolume,(2.0/3.0));
    return tmp<volScalarField>
    (
      (neg(limitedAlpha1-0.5)*maxArea*2.0*limitedAlpha1) +
                  (pos(limitedAlpha1-0.5)*maxArea*(-2.0*( limitedAlpha1 - 1.0)))
    );

}
//ADDED
Foam::tmp<Foam::volScalarField>
Foam::twoPhaseMixtureThermo::hCoeff() const
{
// from [Bejan, Convection heat transfer, 1995]
const volScalarField& rho1 = thermo1_->rho();
const volScalarField& rho2 = thermo2_->rho();
    return tmp<volScalarField>
    (
        1.079 * (lambdaF_ / charLength_ ) * pow(
         (pow3(charLength_) * ifg_ * g_ * (rho1-rho2) ) /
          (lambdaF_ * nu() * (Tsat_ - Tinf_) ) , 0.2 )
    );
}

Can I know where the error is?
saicharan662000@gmail.com is offline   Reply With Quote

Reply

Tags
allocated, beginner, c++, error, viscosity model

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
Problem with divergence TDK FLUENT 13 December 14, 2018 06:00
Viscosity model - Compressible flow Aurelien Thinat OpenFOAM Programming & Development 3 March 6, 2018 07:08
Validity of Sutherland's viscosity model for high-T gases tatu Main CFD Forum 1 March 6, 2013 12:00
How to modify the viscosity model mpml OpenFOAM Running, Solving & CFD 4 October 13, 2010 07:44
Frictional viscosity in granular model Hp FLUENT 4 June 1, 2004 20:42


All times are GMT -4. The time now is 04:54.