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

volScalarField

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 17, 2010, 16:57
Default volScalarField
  #1
Member
 
Diego Villa
Join Date: Mar 2010
Location: Genova Italy
Posts: 37
Rep Power: 16
DiegoNaval is on a distinguished road
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:rintStack(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?
DiegoNaval is offline   Reply With Quote

Old   November 18, 2010, 04:49
Default
  #2
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
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?
nimasam is offline   Reply With Quote

Old   November 18, 2010, 12:30
Default
  #3
Member
 
Diego Villa
Join Date: Mar 2010
Location: Genova Italy
Posts: 37
Rep Power: 16
DiegoNaval is on a distinguished road
Thank you very much nima,
Now it's work well.
DiegoNaval is offline   Reply With Quote

Old   January 30, 2012, 10:06
Default
  #4
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
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
linch is offline   Reply With Quote

Old   January 30, 2012, 12:58
Default
  #5
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
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().
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   February 1, 2012, 14:42
Default
  #6
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
Thank you David for the reply!
Quote:
Originally Posted by marupio View Post
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 View Post
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 View Post
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
linch is offline   Reply With Quote

Old   February 1, 2012, 14:49
Default
  #7
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
Quote:
Originally Posted by linch View Post
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.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   February 2, 2012, 04:04
Default
  #8
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
Thanks once again David.
Quote:
Originally Posted by marupio View Post
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 View Post
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.
linch is offline   Reply With Quote

Reply


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
How to create initiate a volScalarField p without reading from disk NO_READ does not seem to work dbxmcf OpenFOAM Running, Solving & CFD 14 March 25, 2022 07:08
if-loop, volScalarField comparison volker OpenFOAM 7 March 6, 2020 21:03
Problems with creating a volScalarField georlade OpenFOAM Programming & Development 4 December 4, 2016 13:31
Fill a volScalarField DiegoNaval OpenFOAM Programming & Development 6 November 19, 2010 10:26
dimensioned volScalarField lions85 OpenFOAM 1 November 12, 2009 03:41


All times are GMT -4. The time now is 19:03.