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/)
-   -   volScalarField (https://www.cfd-online.com/Forums/openfoam-programming-development/82129-volscalarfield.html)

DiegoNaval November 17, 2010 15:57

volScalarField
 
HI all,
I have a little problem with a volScalarField, I have create that field in a class where is not defined the runTime object, but I want create a volScalarField that than I fill in that way:
__________________________________________________ ______
volScalarField alfa
(
IOobject
(
"alfa",
fileName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_
);

forAll(cells, i)
{
label lab=cells[i];
if(IntCell_[lab])
alfa.internalField()[lab]=1;
else
alfa.internalField()[lab]=0;
}
__________________________________________________ ______
All can be compiled but when I run the solver that use that class I have that error:
__________________________________________________ ______
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.7.x |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 1.7.x-a654f2c8b4fb
Exec : MYMRFSimpleFoam
Date : Nov 17 2010
Time : 15:30:43
Host : salaria
PID : 11695
Case : /home/diego/OpenFOAM/diego-1.7.x/run/VerificaMRF/SimplePropeller
nProcs : 1
SigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading field p

Reading field U

Reading/calculating face flux field phi

Selecting incompressible transport model Newtonian
Selecting RAS turbulence model kOmegaSST
kOmegaSSTCoeffs
{
alphaK1 0.85034;
alphaK2 1;
alphaOmega1 0.5;
alphaOmega2 0.85616;
gamma1 0.5532;
gamma2 0.4403;
beta1 0.075;
beta2 0.0828;
betaStar 0.09;
a1 0.31;
c1 10;
}


Starting time loop

Time = 1



--> FOAM FATAL ERROR:
NO_READ specified for read-constructor of object alfa of class IOobject

From function regIOobject::readStream()
in file db/regIOobject/regIOobjectRead.C at line 46.

FOAM aborting

#0 Foam::error::printStack(Foam::Ostream&) in "/home/diego/OpenFOAM/OpenFOAM-1.7.x/lib/linux64GccDPOpt/libOpenFOAM.so"
#1 Foam::error::abort() in "/home/diego/OpenFOAM/OpenFOAM-1.7.x/lib/linux64GccDPOpt/libOpenFOAM.so"
#2 Foam::regIOobject::readStream() in "/home/diego/OpenFOAM/OpenFOAM-1.7.x/lib/linux64GccDPOpt/libOpenFOAM.so"
#3 Foam::regIOobject::readStream(Foam::word const&) in "/home/diego/OpenFOAM/OpenFOAM-1.7.x/lib/linux64GccDPOpt/libOpenFOAM.so"
#4 Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject const&, Foam::fvMesh const&) in "/home/diego/OpenFOAM/diego-1.7.x/applications/bin/linux64GccDPOpt/MYMRFSimpleFoam"
#5 Foam::MRFZone::correctVelocityEquation(Foam::fvMat rix<Foam::Vector<double> >&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh>&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh>&) const in "/home/diego/OpenFOAM/diego-1.7.x/applications/bin/linux64GccDPOpt/MYMRFSimpleFoam"
#6 Foam::regIOobject::writeObject(Foam::IOstream::str eamFormat, Foam::IOstream::versionNumber, Foam::IOstream::compressionType) const in "/home/diego/OpenFOAM/diego-1.7.x/applications/bin/linux64GccDPOpt/MYMRFSimpleFoam"
#7 main in "/home/diego/OpenFOAM/diego-1.7.x/applications/bin/linux64GccDPOpt/MYMRFSimpleFoam"
#8 __libc_start_main in "/lib/libc.so.6"
#9 Foam::regIOobject::writeObject(Foam::IOstream::str eamFormat, Foam::IOstream::versionNumber, Foam::IOstream::compressionType) const in "/home/diego/OpenFOAM/diego-1.7.x/applications/bin/linux64GccDPOpt/MYMRFSimpleFoam"
Aborted
__________________________________________________ ______

Someone have an idea on which is the problem?

nimasam November 18, 2010 03:49

ur ioDic difinition is ill, use something like this:
volScalarField alfa
(
IOobject
(
"alfa",
fileName(),
mesh_,
IOobject::NO_READ, // when u use no read u should initialize ur variable
IOobject::NO_WRITE
),
mesh_,
dimensionScalar ("alfa",dimensionSet (0,0,....), 0) // this is just for initializing
);

ok? ;)

DiegoNaval November 18, 2010 11:30

Thank you very much nima,
Now it's work well.

linch January 30, 2012 09:06

Hi all,

I have another question to this topic. In createField.H I create a volScalarField
Code:

volScalarField kappa
    (
        IOobject
        ( 
            "kappa",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        twoPhaseProperties.kappa()
    );

The class twoPhaseProperties is of the type compressibleTwoPhaseMixture, which I implemented analog to the twoPhaseMixture class. In the implementation of the class I have following lines:
Code:

tmp<volScalarField> compressibleTwoPhaseMixture::kappa() const
{
    return tmp<volScalarField>
    (
        new volScalarField
        (
            "kappa",
            limitedAlpha1*kappaModel1_->kappa()
            + (scalar(1) - limitedAlpha1)*kappaModel2_->kappa()
        )
    );
}

Such implementation can be found in the original twoPhaseProperties.C. Because new volScalarField has the same name "kappa" it somehow overwrites the option IOobject::AUTO_WRITE, and the volScalarField is not written. This does'n happen if I implement it in the following way.
Code:

tmp<volScalarField> compressibleTwoPhaseMixture::kappa() const
{
    return tmp<volScalarField>
    (
        limitedAlpha1*kappaModel1_->kappa()
        + (scalar(1) - limitedAlpha1)*kappaModel2_->kappa()
    );
}

So my questions are:
1) Does the first implementation allocate a new memory block for the whole volScalarField, even if the volScalarField kappa already exists? I would waste memory if so.
2) Where and why the IOobject::AUTO_WRITE is being overwritten?
3) Is the second implementation write? Does it have any drawbacks?

Best regards,
Ilya

marupio January 30, 2012 11:58

1) Yes. Not only that, it creates a totally independent object that contains only the initial values of kappa. These values will never change throughout your simulation.
2) Probably gets overwritten in the GeometricField constructor. You can look through the list of constructors and choose one that suits you.
3) ?

What are you trying to achieve? Do you want kappa written out at every timestep, when it normally doesn't? I don't know how the mixture models work. You could use your first implementation, except change the constructor you use. Maybe give it a dimensioned scalar instead of the whole field.

Code:

    ...
    IOobject
    (
        ...
    ),
    mesh,
    dimensionedScalar
    (
        "kappa",
        twoPhaseProperties.kappa().dimensions(),
        0.0
    )
);

Then, just before runTime.write(), update your output field by setting kappa equal to twoPhaseProperties.kappa().

linch February 1, 2012 13:42

Thank you David for the reply!
Quote:

Originally Posted by marupio (Post 341951)
Yes. Not only that, it creates a totally independent object that contains only the initial values of kappa. These values will never change throughout your simulation.

Really? I thought the values will be updated each time I call twoPhaseProperties.kappa()
Quote:

Originally Posted by marupio (Post 341951)
What are you trying to achieve? Do you want kappa written out at every timestep, when it normally doesn't?

Exactly.
Quote:

Originally Posted by marupio (Post 341951)
Maybe give it a dimensioned scalar instead of the whole field.

Well, kappa is different in each cell (e.g. it could be pressure or temperature dependent), thus volScalarField is ok. My goal is to make my two phase properties library, which is generally usable. One could either use the properties directly (e.g. fvm::laplacian(twoPhaseProperties.kappaf(),T) ) or to update an already existing field (e.g. kappa = twoPhaseProperties.kappa()). In the last case I want to prevent the double usage of memory. But I'm not sure if my second variant is right:
Code:

tmp<volScalarField> compressibleTwoPhaseMixture::kappa() const
{
    return tmp<volScalarField>
    (
        new volScalarField
        (
            "kappa",
            limitedAlpha1*kappaModel1_->kappa()
            + (scalar(1) - limitedAlpha1)*kappaModel2_->kappa()
        )
    );
}

Best regards,
Ilya

marupio February 1, 2012 13:49

Quote:

Originally Posted by linch (Post 342328)
Well, kappa is different in each cell (e.g. it could be pressure or temperature dependent), thus volScalarField is ok.

You are still creating a volScalarField, just using a different constructor that doesn't read from a file. The dimensionedScalar you define is the initial value throughout. This is a good constructor to use.

I'm sorry I didn't notice this: your kappa() function returns tmp<>. It is a temporary object. There is no permanent storage for kappa, therefore you aren't being wasteful by keeping a copy at the solver level. But you need to keep it up to date at every timestep before runTime.write() by setting it equal to the result of the function call as I suggested above.

linch February 2, 2012 03:04

Thanks once again David.
Quote:

Originally Posted by marupio (Post 342329)
The dimensionedScalar you define is the initial value throughout. This is a good constructor to use.

Could you please tell why?
Quote:

Originally Posted by marupio (Post 342329)
But you need to keep it up to date at every timestep before runTime.write() by setting it equal to the result of the function call as I suggested above.

That's clear.


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