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

Declration and calculating volScalarField

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 25, 2020, 07:19
Default Declration and calculating volScalarField
  #1
New Member
 
Elol
Join Date: Feb 2020
Posts: 16
Rep Power: 6
Elol is on a distinguished road
Hi everybody,

I have a problem understanding this issue, I declared volScalarField as follow;
Code:
volScalarField klim
(
    IOobject
    (
        "klim",
        runTime.timeName(),
        mesh_
       // IOobject::MUST_READ,
       // IOobject::AUTO_WRITE
    ),
    mesh_
   //deltaX[i] *deltaX[i]/runTime.deltaT() 
//totalDeltaX1/runTime.deltaT()

);

and calculated it as follows;

Code:
scalarField deltaX = cbrt(mesh_.V());
forAll (deltaX, i)
{
//deltaX[i] = mag(deltaX[i]);
klim = deltaX[i] * deltaX[i]/runTime.deltaT();

}
But then I have this error;
Code:
--> FOAM FATAL ERROR: 
cannot find file "/home/Elol/OpenFOAM/Elol-v1712/run/tests_1/0.011976/klim"
I am using klim in a transport equation.

Anybody knows why this is happening ?

Thanks in advance.
Elol is offline   Reply With Quote

Old   November 25, 2020, 07:44
Default
  #2
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
so klim is a volScalarField and is accessed incorrectly in the loop?

klim = deltaX[i] * deltaX[i]/runTime.deltaT(); //klim[i] is correct access
geth03 is offline   Reply With Quote

Old   November 25, 2020, 08:11
Default
  #3
New Member
 
Elol
Join Date: Feb 2020
Posts: 16
Rep Power: 6
Elol is on a distinguished road
Thanks for you reply,

Yes klim is volScalarField,

when I tried klim[i] it gives me a compilation error as follow

Code:
error: cannot convert ‘Foam::dimensionedScalar {aka Foam::dimensioned<double>}’ to ‘double’ in assignment
 klim[i] = deltaX[i] * deltaX[i]/runTime.deltaT();
Elol is offline   Reply With Quote

Old   November 25, 2020, 08:30
Default
  #4
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
Quote:
Originally Posted by Elol View Post

Code:
error: cannot convert ‘Foam::dimensionedScalar {aka Foam::dimensioned<double>}’ to ‘double’ in assignment
 klim[i] = deltaX[i] * deltaX[i]/runTime.deltaT();
obviously you didn't define the dimension of klim, so openfoam checks if dimensions match before doing calculations. so when declaring klim, also define the dimension!
geth03 is offline   Reply With Quote

Old   November 25, 2020, 09:02
Default
  #5
New Member
 
Elol
Join Date: Feb 2020
Posts: 16
Rep Power: 6
Elol is on a distinguished road
Thanks.

It worked, it needed also to change the runTime.deltaT() to runTime.deltaT().value()

Have a nice day.

Best Regards
Elol
Elol is offline   Reply With Quote

Reply

Tags
openfoam, volscalafield


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



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