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

Declare new volScalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By adhiraj
  • 1 Post By The Mad Scientist

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 5, 2019, 12:00
Default Declare new volScalarField
  #1
Member
 
Farshad
Join Date: Sep 2010
Posts: 36
Rep Power: 15
farshadexp is on a distinguished road
Hi FOAMers...
I'm trying to declare a new volScalarField based on an existing volScalarField, as followong:


Code:
volScalarField rhohe
(
    IOobject
    (
        "rhohe",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    rho*thermo.he()
);
No compile error.
But during run, following error is being shown:


Code:
--> FOAM FATAL ERROR: 
cannot be called for a calculatedFvPatchField
    on patch base of field rhohe in file "/home/farshad/OpenFOAM/farshad-v1812/run/fireFoam/LES/smallPoolFire2D/0/rhohe"
    You are probably trying to solve for a field with a default boundary condition.

    From function Foam::tmp<Foam::Field<Type> > Foam::calculatedFvPatchField<Type>::gradientInternalCoeffs() const [with Type = double]
    in file fields/fvPatchFields/basic/calculated/calculatedFvPatchField.C at line 186.
Your helps are appreciated, in advance.
farshadexp is offline   Reply With Quote

Old   July 8, 2019, 03:11
Default
  #2
New Member
 
Adam
Join Date: Jan 2019
Posts: 21
Rep Power: 7
boundary93 is on a distinguished road
I think you should do the calculaton not where you create the field but Im not sure
boundary93 is offline   Reply With Quote

Old   July 8, 2019, 14:43
Default
  #3
Member
 
Farshad
Join Date: Sep 2010
Posts: 36
Rep Power: 15
farshadexp is on a distinguished road
Thanks boundary93 for your response...
I declare that in Createfields.H and also YEEqn.H. But in both cases the result is same, runtime error.
farshadexp is offline   Reply With Quote

Old   July 9, 2019, 15:00
Default
  #4
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15
adhiraj is on a distinguished road
Are you creating a field rhohe and then also trying to solve an equation for it?

If so, you will need to explicitly set boundary conditions for rhohe. As far as I recall, when you multiply two fields to produce a new field, you get "calculated" boundary conditions for the new field. Solvers don't know what to do with the "calculated" boundary condition.

Hope this helps.
adhiraj is offline   Reply With Quote

Old   July 9, 2019, 15:33
Default
  #5
Member
 
Farshad
Join Date: Sep 2010
Posts: 36
Rep Power: 15
farshadexp is on a distinguished road
Dear Adhiraj
You are right, that's the point.

But, I am trying to solve "rhohe" instead of "he" in the same manner. For "he" we need no BC, and also for rho, so why we need to specify BC for new "rhohe"??
And, what's the solution
farshadexp is offline   Reply With Quote

Old   July 9, 2019, 16:28
Default
  #6
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15
adhiraj is on a distinguished road
Keep in mind that he is a 'special' variable, in that it is generated internally, and is not provided by the user. This variable also comes with special boundary conditions, and it is taken care of by the code internally.

The variable rho does not seem to be so special, and so I am not 100% sure of what is happening. I think this is what happens with rho (someone more familiar with the code can explain more? ):

If you look at the rho equation, it does not seem to directly use boundary values of rho.
So maybe that is why the function gradientInternalCoeffs is not called for rho?
adhiraj is offline   Reply With Quote

Old   July 12, 2019, 02:00
Default
  #7
Member
 
Farshad
Join Date: Sep 2010
Posts: 36
Rep Power: 15
farshadexp is on a distinguished road
Thanks for explanation Adhiraj, right!
I'm looking for a solution to declare a volSacalarField based on "he", which do not need a boundary condition, because I think it's hard to specify a BC.
What is the solution? do you have any idea?!
farshadexp is offline   Reply With Quote

Old   July 12, 2019, 17:15
Default
  #8
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15
adhiraj is on a distinguished road
I guess there are two options here:

1. Implement the new variable as rhohe = rho*he. For the boundary conditions, have a look at what is done for he, and maybe you can use that as a guide. Here your goal is to come up with a boundary condition that is consistent with the corresponding temperature boundary condition.

2. Reformulate the problem so that you know what boundary conditions to use, and simply read them in during simulation. So you will need to provide a rhohe file in the initial time directory.
adhiraj is offline   Reply With Quote

Old   July 13, 2019, 11:06
Default
  #9
Member
 
Farshad
Join Date: Sep 2010
Posts: 36
Rep Power: 15
farshadexp is on a distinguished road
appreciated Adhiraj...
for the first option, declaring rhohe=rho*he leads to compile error.
Declaring in YEEqn.H:
Code:
YEEqn.H:58:32: error: invalid user-defined conversion from ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ to ‘Foam::volScalarField& {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&}’ [-fpermissive]
     volScalarField& rhohe = rho*he;
Declaring in createFields.H:


Code:
createFields.H:177:29: error: conversion from ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’ to ‘Foam::volScalarField& {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&}’ discards qualifiers [-fpermissive]
 volScalarField& rhohe = rho*he;
farshadexp is offline   Reply With Quote

Old   July 15, 2019, 13:16
Default
  #10
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15
adhiraj is on a distinguished road
Sorry if my last reply was not clear, my bad

When I wrote

Quote:
Implement the new variable as rhohe = rho*he.
I did not mean that the line should be directly used in code, since that would not work. I was suggesting a thought process. You will need to figure out how to implement that thought into meaningful code. Unfortunately I have not studied the code part where he is defined and boundaries set, so I cannot help you with the implementation.
farshadexp likes this.
adhiraj is offline   Reply With Quote

Old   July 26, 2019, 13:18
Default
  #11
New Member
 
Join Date: Jun 2017
Posts: 9
Rep Power: 0
The Mad Scientist is on a distinguished road
Farshad,

In case you have some simple boundary condition then you can use this format but this only works very few boundary types.


Info<< "Reading field h\n" << endl;
volScalarField h
(
IOobject
(
"h",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
Cp*T + fl*L,
T.boundaryField().types(),
fl.boundaryField().types()
);


If this doesn't help then you can either define your field in normal ways and calculate your boundary values somewhere in the solver.


or you can predefine your varible in you 0 directory then modify the internal field in the code given you have simple BC.
farshadexp likes this.
The Mad Scientist is offline   Reply With Quote

Old   July 26, 2019, 13:22
Default
  #12
Member
 
Farshad
Join Date: Sep 2010
Posts: 36
Rep Power: 15
farshadexp is on a distinguished road
Hi Adhiraj
that was my fault. thanks for your guidance. I will try and hopefully find a solution...
Quote:
Originally Posted by adhiraj View Post
Sorry if my last reply was not clear, my bad

When I wrote



I did not mean that the line should be directly used in code, since that would not work. I was suggesting a thought process. You will need to figure out how to implement that thought into meaningful code. Unfortunately I have not studied the code part where he is defined and boundaries set, so I cannot help you with the implementation.
farshadexp is offline   Reply With Quote

Old   July 26, 2019, 13:29
Default
  #13
Member
 
Farshad
Join Date: Sep 2010
Posts: 36
Rep Power: 15
farshadexp is on a distinguished road
Hi Scientist
Based on your explanations, I will define variable. It need some manipilations (I guess). I will tell you the results.
Quote:
Originally Posted by The Mad Scientist View Post
Farshad,

In case you have some simple boundary condition then you can use this format but this only works very few boundary types.


Info<< "Reading field h\n" << endl;
volScalarField h
(
IOobject
(
"h",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
Cp*T + fl*L,
T.boundaryField().types(),
fl.boundaryField().types()
);


If this doesn't help then you can either define your field in normal ways and calculate your boundary values somewhere in the solver.


or you can predefine your varible in you 0 directory then modify the internal field in the code given you have simple BC.
farshadexp is offline   Reply With Quote

Old   July 28, 2019, 15:57
Default
  #14
Member
 
Farshad
Join Date: Sep 2010
Posts: 36
Rep Power: 15
farshadexp is on a distinguished road
Quote:
Originally Posted by The Mad Scientist View Post
Farshad,

In case you have some simple boundary condition then you can use this format but this only works very few boundary types.


Info<< "Reading field h\n" << endl;
volScalarField h
(
IOobject
(
"h",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
Cp*T + fl*L,
T.boundaryField().types(),
fl.boundaryField().types()
);


If this doesn't help then you can either define your field in normal ways and calculate your boundary values somewhere in the solver.


or you can predefine your varible in you 0 directory then modify the internal field in the code given you have simple BC.

Hi,
I tried your solution and declared a field as followings:


Code:
volScalarField rhohe
(
    IOobject
    (
        "rhohe",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ, //NO_READ,
        IOobject::AUTO_WRITE
    ),
    rho*he,
    rho.boundaryField().types(),
    he.boundaryField().types()
);
moreover, after encountering the same problem, I define a "rhohe" file based on "T" in "0" folder (obviously it's not a correct BC but I do this to check the response of the solver):


Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "0";
    object      rhohe;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [2 -1 -2 0 0 0 0];

internalField   uniform 300;

boundaryField
{
    "(outlet|sides)"
    {
        type            inletOutlet;
        inletValue      $internalField;
        value           $internalField;
    }

    base
    {
        type            zeroGradient; //calculated;
        //value           $internalField;
    }

    inlet
    {
        type            fixedValue;
        value           uniform 300;
    }

    frontAndBack
    {
        type            empty;
    }
}
But again, nothing is changed.


Code:
--> FOAM FATAL ERROR: 
cannot be called for a calculatedFvPatchField
    on patch base of field rhohe in file "/home/farshad/OpenFOAM/farshad-v1812/run/fireFoam/LES/smallPoolFire2D/0.00144928/rhohe"
    You are probably trying to solve for a field with a default boundary condition.

    From function Foam::tmp<Foam::Field<Type> > Foam::calculatedFvPatchField<Type>::gradientInternalCoeffs() const [with Type = double]
    in file fields/fvPatchFields/basic/calculated/calculatedFvPatchField.C at line 186.
farshadexp is offline   Reply With Quote

Old   July 28, 2019, 18:23
Default
  #15
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
try this:

1- Declare your variable to be read from 0 directory:

Code:
volScalarField rhohe
(
    IOobject
    (
        "rhohe",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);
2- Then update it somewhere in your code before solving for it:
Code:
rhohe = rho * he;
rhohe.correctBoundaryConditions();
Note: with this method you have to set correct boundary conditions for rhohe in 0 directory.
Daniel_Khazaei is offline   Reply With Quote

Reply

Tags
openfoam


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
[OpenFOAM.org] OpenFOAM 2.3.1 installation on SUSE Linux Enterprise 12 harsha_kulkarni OpenFOAM Installation 17 November 16, 2015 03:06
[OpenFOAM.org] Installation problem 2.4.0 on Centos 6.6 luke_skywalker OpenFOAM Installation 8 November 13, 2015 08:15
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 06:16
Sgimpi pere OpenFOAM 27 September 24, 2011 07:57
Ld_library_path scottneh OpenFOAM 9 November 21, 2009 09:15


All times are GMT -4. The time now is 08:01.