CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   ‘mesh’ was not declared in this scope (https://www.cfd-online.com/Forums/openfoam-programming-development/132931-mesh-not-declared-scope.html)

sharonyue April 8, 2014 03:04

‘mesh’ was not declared in this scope
 
Hi guys,

I wanna change d0 as a dimensionedScalar to a volScalarField. So I revise the code:

in solvers/compressibleTwoPhaseEulerFoam/phaseModel/diameterModels/isothermalDiameter.C

Code:

class isothermal
:
    public diameterModel
{
    // Private data

        //- Reference diameter for the isothermal expansion
        //dimensionedScalar d0_; This is original
        volScalarField d0_;
   

        //- Reference pressure for the isothermal expansion
        dimensionedScalar p0_;
       
        //- Reference pressure for the isothermal expansion
        dimensionedScalar n0_;


public:
.....................

in solvers/compressibleTwoPhaseEulerFoam/phaseModel/diameterModels/isothermalDiameter.H
Code:


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::diameterModels::isothermal::isothermal
(
    const dictionary& dict,
    const phaseModel& phase
)
:
    diameterModel(dict, phase),
    d0_
    (
        IOobject
        (
            "d0",
            mesh.time().timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    ), 
    //d0_("d0", dimLength, dict.lookup("d0")), This is original
    p0_("p0", dimPressure, dict.lookup("p0")),
    n0_("n0", dimDensity, dict.lookup("n0"))
{}


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

When I wmake libso, it said:
Code:

SOURCE=diameterModels/isothermalDiameter/isothermalDiameter.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam222/src/finiteVolume/lnInclude -I/opt/openfoam222/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam222/src/transportModels/incompressible/lnInclude -IlnInclude -I. -I/opt/openfoam222/src/OpenFOAM/lnInclude -I/opt/openfoam222/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/isothermalDiameter.o
diameterModels/isothermalDiameter/isothermalDiameter.C: In constructor ‘Foam::diameterModels::isothermal::isothermal(const Foam::dictionary&, const Foam::phaseModel&)’:
diameterModels/isothermalDiameter/isothermalDiameter.C:63:13: error: ‘mesh’ was not declared in this scope

make: *** [Make/linux64GccDPOpt/isothermalDiameter.o] Error 1
a@a:~/OpenFOAM/myCase/solvers/compressibleTwoPhaseEulerFoam/phaseModel$

So how should I handle this? Thanks in advance.

alexeym April 8, 2014 03:28

Hi,

as phase is a child class of volScalarField it has mesh() method which will return constant reference to the mesh. So the code can be:

Code:

    d0_
    (
        IOobject
        (
            "d0",
            phase.mesh().time().timeName(),
            phase.mesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        phase.mesh()
    ),

or

Code:

    d0_
    (
        IOobject
        (
            "d0",
            phase.time().timeName(),
            phase.db(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        phase.mesh()
    ),


sharonyue April 8, 2014 03:33

@Alexey Matveichev

Solved! so quick! Thanks very much.!!

Alee reza August 25, 2017 14:43

error: ‘constrainP1’ was not declared in this scope constrainP1(p1, U1,rAU1)
 
Hi guys,
I wanna solve some new equation with icoFoam so i added my new equation in icoFaom .When I wmake , it said:[icoOTDFoam.C:139:70: error: ‘constrainHbyA1’ was not declared in this scope
volVectorField HbyA1(constrainHbyA1(rAU1*U1Eqn.H(), U1, p1));][]
and this is my solver .C

[/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

Application
icoFoam

Description
Transient solver for incompressible, laminar flow of Newtonian fluids.

\*---------------------------------------------------------------------------*/

#include "fvCFD.H"
#include "pisoControl.H"

#include "pisoControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"

pisoControl piso(mesh);

#include "createFields.H"
#include "initContinuityErrs.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Info<< "\nStarting time loop\n" << endl;

while (runTime.loop())
{
Info<< "Time = " << runTime.timeName() << nl << endl;

#include "CourantNo.H"

// Momentum predictor

fvVectorMatrix UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
- fvm::laplacian(nu, U)
);

if (piso.momentumPredictor())
{
solve(UEqn == -fvc::grad(p));
}

// --- PISO loop
while (piso.correct())
{
volScalarField rAU(1.0/UEqn.A());

volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p));
///H/ap that is equal to U in old version
surfaceScalarField phiHbyA
(
"phiHbyA",
fvc::flux(HbyA)
+ fvc::interpolate(rAU)*fvc::ddtCorr(U, phi)
);
///phiHbyA is like new phi
adjustPhi(phiHbyA, U, p);

// Update the pressure BCs to ensure flux consistency
constrainPressure(p, U, phiHbyA, rAU);

// Non-orthogonal pressure corrector loop
while (piso.correctNonOrthogonal())
{
// Pressure corrector

fvScalarMatrix pEqn
(
fvm::laplacian(rAU, p) == fvc::div(phiHbyA)
);

pEqn.setReference(pRefCell, pRefValue);

pEqn.solve(mesh.solver(p.select(piso.finalInnerIte r())));

if (piso.finalNonOrthogonalIter())
{
phi = phiHbyA - pEqn.flux();
}
}

#include "continuityErrs.H"

U = HbyA - rAU*fvc::grad(p);
U.correctBoundaryConditions();
}
/////////////////////////////////////////////////////////%%%******
// first mode predictor

fvVectorMatrix U1Eqn
(
fvm::ddt(U1)
+ fvm::div(phi, U1)
+ fvm::div(phi1,U)
- fvm::laplacian(nu, U1)

);

if (piso.momentumPredictor())
{
solve(U1Eqn == -fvc::grad(p1));
}

// --- PISO loop
while (piso.correct())
{
volScalarField rAU1(1.0/U1Eqn.A());

volVectorField HbyA1(constrainHbyA1(rAU1*U1Eqn.H(), U1, p1));

surfaceScalarField phiHbyA1
(
"phiHbyA1",
fvc::flux(HbyA1)
+ fvc::interpolate(rAU1)*fvc::ddtCorr(U1, phi1)
);
///phiHbyA is like new phi
adjustPhi1(phiHbyA1, U1, p1);///Think

constrainP1(p1, U1, phiHbyA1, rAU1);

// Non-orthogonal pressure corrector loop
while (piso.correctNonOrthogonal())
{
// Pressure corrector

fvScalarMatrix p1Eqn
(
fvm::laplacian(rAU1, p1) == fvc::div(phiHbyA1)
);

p1Eqn.setReference(pRefCell, pRefValue);

p1Eqn.solve(mesh.solver(p1.select(piso.finalInnerI ter())));

if (piso.finalNonOrthogonalIter())
{
phi1 = phiHbyA1 - p1Eqn.flux();
}
}

#include "continuityErrs.H"

U1 = HbyA1 - rAU1*fvc::grad(p1);
U1.correctBoundaryConditions();
}



runTime.write();




Info<< "End\n" << endl;

return 0;
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
}

}


// ************************************************** *********************** //][/QUOTE]
what should I do? Thanks in advance.

tooran February 27, 2020 12:48

error: ‘mesh’ was not declared in this scope
 
Hi all,
I am trying to change a HerschelBulkley in a viscosity model of openfoam.


I want to add a if-condition as follows:


if y<2m then calculate strain rate ....


so I write following loop in the HerschelBulkley.C:


forAll ( mesh.C(), celli) //loop through cell centres
{
if mesh.C().component(vector::y)< scalar (2.0)

{
return
(
min
(
nu0_,
(tau0_ + k_*rtone*pow(tone*sr(), n_))
/(max(sr(), dimensionedScalar ("vSmall", dimless/dimTime, vSmall)))
)
);
}

else {.....


But it shows me error :


error: ‘mesh’ was not declared in this scope
forAll ( mesh.C(), celli) //loop through cell centres



could you please help me?

tooran March 5, 2020 14:44

undefined symbol: _ZN4Foam
 
I solved my problem by adding the following sentences at HerschelBulkley.C

const objectRegistry& db();
const volVectorField& U = db().lookupObject<volVectorField>("U");
const fvMesh & mesh = U.mesh();


It is compiled without error but when I run my case it shows me error :




undefined symbol: _ZN4Foam15viscosityModels2dbEv


Now I found that I should change my option file in MAKE Folder. But I do not know how I should change my option !.


Could anyone help me?
Thanks

tooran March 6, 2020 20:08

I declare the mesh in the scope by adding:
const fvMesh& mesh = U_.mesh();




It compiles with out error and I run it with solver, it works fine.


All times are GMT -4. The time now is 16:48.