|
[Sponsors] |
Viscosity model - error: object is not allocated - C++ beginner |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 23, 2016, 11:48 |
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 |
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 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); } ...
__________________
Vinícius dC.A. |
|
March 23, 2016, 15:38 |
|
#2 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
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 |
|
February 10, 2022, 00:32 |
|
#3 |
Member
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 97
Rep Power: 5 |
hello avila,
Have you solved the problem? |
|
February 10, 2022, 11:04 |
|
#4 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
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:
|
|
February 10, 2022, 11:18 |
Error:Object not allocated.
|
#5 |
Member
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 97
Rep Power: 5 |
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 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) ); Thanks in advance |
|
February 14, 2022, 02:00 |
|
#6 | |
Member
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 97
Rep Power: 5 |
Quote:
@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? |
||
Tags |
allocated, beginner, c++, error, viscosity model |
Thread Tools | Search this Thread |
Display Modes | |
|
|
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 |