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

Calculate a new filed from variables in the controldict

Register Blogs Community New Posts Updated Threads Search

Like Tree11Likes
  • 1 Post By Carlo_P
  • 4 Post By geth03
  • 1 Post By Carlo_P
  • 2 Post By geth03
  • 3 Post By geth03

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 28, 2020, 05:38
Default Calculate a new filed from variables in the controldict
  #1
Senior Member
 
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8
Carlo_P is on a distinguished road
Hey guys,
I would like to ask you how should be possible to calculate a new field in the controlDict.


The idea is to calculate the absolute pressure also in simpleFoam simulation.


I have to create a new field that should be


pAb=static(p)*1.2+101325.


How can I write this formula in the controlDict?






Furthemore, I would like to calculate the difference from the massFlow ingoing and outgoing, in different patches.


How can be possible?


massDiff=flowRatePatch(name=inlet1)+flowRatePatch( name=inlet2)+flowRatePatch(name=inlet3), etc...
tariq likes this.
Carlo_P is offline   Reply With Quote

Old   September 29, 2020, 05:52
Default
  #2
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
Quote:
Originally Posted by Carlo_P View Post
Hey guys,
I would like to ask you how should be possible to calculate a new field in the controlDict.


The idea is to calculate the absolute pressure also in simpleFoam simulation.


I have to create a new field that should be


pAb=static(p)*1.2+101325.


How can I write this formula in the controlDict?






Furthemore, I would like to calculate the difference from the massFlow ingoing and outgoing, in different patches.


How can be possible?


massDiff=flowRatePatch(name=inlet1)+flowRatePatch( name=inlet2)+flowRatePatch(name=inlet3), etc...
functions
{
absPressure
{
type coded;
libs ("libutilityFunctionObjects.so");
writeControl adjustableRunTime;
writeInterval 1;

name writePressure;

codeInclude
#{
#include "OFstream.H"
#};

codeWrite
#{
volScalarField absPressure
(
IOobject
(
"absolutePressure",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
static(p)*1.2+101325 //here is your equation for absolute pressure
);
absPressure.write();

#};

}

}
tariq, Carlo_P, hhu_lulu and 1 others like this.
geth03 is offline   Reply With Quote

Old   September 29, 2020, 06:11
Default
  #3
Senior Member
 
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8
Carlo_P is on a distinguished road
Uhm..thanks a lot!
I will try soon.


Can I ask you what does it means:


codeInclude
#{
#include "OFstream.H"
#};


?


Thanks a lot!
tariq likes this.
Carlo_P is offline   Reply With Quote

Old   September 29, 2020, 06:40
Default
  #4
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
i previously had a similar task, so i output my volScalarField in a txt-file.
the include file is needed for that task, it is from the c++ standard lib,
you don't need it, i forgot to take it out.
tariq and Carlo_P like this.
geth03 is offline   Reply With Quote

Old   September 30, 2020, 09:27
Default
  #5
Senior Member
 
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8
Carlo_P is on a distinguished road
Uhm....it doesn't work..


Using dynamicCode for functionObject writePressure at line 167 in "/home/system/controlDict/functions/absPressure"
Creating new library in "dynamicCode/writePressure/platforms/linux64GccDPInt32Opt/lib/libwritePressure_abd1dcb55d05af47405a492c28b8bf83c 3604585.so"
Invoking "wmake -s libso /home/testPressure/dynamicCode/writePressure"
wmake libso /home/testPressure/dynamicCode/writePressure
ln: ./lnInclude
wmkdep: functionObjectTemplate.C
Ctoo: functionObjectTemplate.C
/home***testPressure/system/controlDict/functions/absPressure: In member function ‘virtual bool Foam::writePressureFunctionObject::write()’:
/home/***testPressure/system/controlDict/functions/absPressure:186:1: error: ‘p’ was not declared in this scope
make: *** [/home/*****/openFoam/openFoam8/OpenFOAM-dev/wmake/rules/General/transform:26: Make/linux64GccDPInt32Opt/functionObjectTemplate.o] Error 1

--> FOAM FATAL IO ERROR:
Failed wmake "dynamicCode/writePressure/platforms/linux64GccDPInt32Opt/lib/libwritePressure_abd1dcb55d05af47405a492c28b8bf83c 3604585.so"


file: /home/****/testPressure/system/controlDict/functions/absPressure from line 167 to line 175.

From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
in file db/dynamicLibrary/codedBase/codedBase.C at line 206.









Any idea?
Carlo_P is offline   Reply With Quote

Old   September 30, 2020, 09:56
Default
  #6
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
the error message says 'p' was not declared in this scope,
how do you access p, what did you write where i wrote here comes your equation?
geth03 is offline   Reply With Quote

Old   September 30, 2020, 10:25
Default
  #7
Senior Member
 
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8
Carlo_P is on a distinguished road
I only removed the code in excess and wite p instead of static(p), since I did an error.
The correct formula is p*1.2+101325


functions
{
absPressure
{
type coded;
libs ("libutilityFunctionObjects.so");
writeControl adjustableRunTime;
writeInterval 1;

name writePressure;


codeWrite
#{
volScalarField absPressure
(
IOobject
(
"absolutePressure",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
p*1.2+101325 //here is your equation for absolute pressure
);
absPressure.write();

#};

}

}





Are the # in the correct position?
How can I include p?


Thanks a lot!
Carlo_P is offline   Reply With Quote

Old   October 1, 2020, 03:02
Default
  #8
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
i will look into that in detail when i find some time.

meanwhile, if you don't already know it:
you can use the calculator in paraview and create your new pressure
based on the 'p' and your equation and visualize it that way.
geth03 is offline   Reply With Quote

Old   October 1, 2020, 03:36
Default
  #9
Senior Member
 
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8
Carlo_P is on a distinguished road
Thanks a lot,
yes, I know the paraview way, but later would be not possible to export as faom format.


I know that it is possible to export the data as csv file, but how can be export as foam format?


Thanks a lot!
Carlo_P is offline   Reply With Quote

Old   October 2, 2020, 04:42
Default
  #10
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
i don't know if it is possible to export such a file

but if you use the same methods for all geometries and simulations
you can save your template under file -> save state,
that way you can just load the state the next time and just
change the .foam-file path,
that way it is more convenient.

there is also a paraview forum from the developers,
you could also ask paraview related questions there
if you can't find a solution here.
geth03 is offline   Reply With Quote

Old   January 12, 2021, 03:49
Default
  #11
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
Quote:
Originally Posted by Carlo_P View Post
I only removed the code in excess and wite p instead of static(p), since I did an error.
The correct formula is p*1.2+101325


functions
{
absPressure
{
type coded;
libs ("libutilityFunctionObjects.so");
writeControl adjustableRunTime;
writeInterval 1;

name writePressure;


codeWrite
#{
volScalarField absPressure
(
IOobject
(
"absolutePressure",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
p*1.2+101325 //here is your equation for absolute pressure
);
absPressure.write();

#};

}

}





Are the # in the correct position?
How can I include p?


Thanks a lot!
hey, sorry for the very late response.

if you want to acces a field you need you will have to tell it first!
i.e.:
const volScalarField& p_ =mesh().lookupObject<volScalarField>("p");
//now your code has acces to p, but we call it p_ from now on.

functions
{
absPressure
{
type coded;
libs ("libutilityFunctionObjects.so");
writeControl adjustableRunTime;
writeInterval 1;

name writePressure;

codeWrite
#{
const volScalarField& p_ =mesh().lookupObject<volScalarField>("p");
volScalarField absPressure
(
IOobject
(
"absolutePressure",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
p_*1.2+101325
);
absPressure.write();

#};

}

}
tariq, altinel and hhu_lulu like this.

Last edited by geth03; January 12, 2021 at 07:21. Reason: updated for version 8
geth03 is offline   Reply With Quote

Old   June 27, 2022, 04:24
Smile controlDict
  #12
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Hello,

I would have a problem with the same thing and I would be appreciative if you let me know your opinion.
I am simulating a single bubble with "interFoam" in a solution of water and sugar. In the "controlDict", I am using a functionObject to solve the concentration of sugar (C distribution) in the water. Everything goes well now actually but, I would need to modify the solver and use the C profile in the solver to calculate a new force. I am now unable to use the profile which is calculated in the "controlDict" in the main body of solver. Do you know how is it possible?

Thanks alot

Best regards,
Sadra


Quote:
Originally Posted by geth03 View Post
functions
{
absPressure
{
type coded;
libs ("libutilityFunctionObjects.so");
writeControl adjustableRunTime;
writeInterval 1;

name writePressure;

codeInclude
#{
#include "OFstream.H"
#};

codeWrite
#{
volScalarField absPressure
(
IOobject
(
"absolutePressure",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
static(p)*1.2+101325 //here is your equation for absolute pressure
);
absPressure.write();

#};

}

}
sadra2003 is offline   Reply With Quote

Old   June 29, 2022, 23:19
Default
  #13
New Member
 
Join Date: May 2020
Posts: 14
Rep Power: 6
ruanyg968tf is on a distinguished road
Hi sadra, you should store it at the variable at the end of your code if you still need to access to it like this:
store(variableName, variablePointer);
ruanyg968tf is offline   Reply With Quote

Old   June 30, 2022, 03:53
Smile
  #14
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Hi ruany,

Thanks a lot for your guidance. I am completely stuck in this part of my simulation actually. I wpuld be really thankful if you help me to address the problem.
You mean that I need to add:

store(variableName, variablePointer);

in my controlDict? and How can I access it in my solver?

Best regards,
Sadra

Quote:
Originally Posted by ruanyg968tf View Post
Hi sadra, you should store it at the variable at the end of your code if you still need to access to it like this:
store(variableName, variablePointer);
sadra2003 is offline   Reply With Quote

Old   July 23, 2022, 05:31
Default
  #15
New Member
 
Join Date: May 2020
Posts: 14
Rep Power: 6
ruanyg968tf is on a distinguished road
Hi Sadra,
Sorry for my late reply. I think I have misunderstood your demanding. If you would like to access a new variable in the main body of your solver, you can make changes to the solver and recompile the source code directly. For example, you can define the variable you need in "createFields.H" and access it directly after your definition.
Best regards,
Ruanyg
ruanyg968tf is offline   Reply With Quote

Reply

Tags
#static(p), controldict., field for p, pressure area


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 define and calculate LES variables rhoPisoFoam Jotazeld OpenFOAM 1 April 3, 2020 05:12
OpenFOAM - Control and Editing of Lagrangian Output Variables gmag OpenFOAM Programming & Development 1 June 25, 2019 13:29
Sensitivity information for custom design variables dghate SU2 0 March 20, 2017 07:39
Need of Help: HowTo designate explicitely unknown variables of a question? Democritus OpenFOAM Programming & Development 6 April 12, 2016 09:38
how to calculate the averaged mass flow along a line over time ? iampolaris OpenFOAM Post-Processing 0 March 10, 2011 23:03


All times are GMT -4. The time now is 07:34.