|
[Sponsors] |
Calculate a new filed from variables in the controldict |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 28, 2020, 05:38 |
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 |
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... |
|
September 29, 2020, 05:52 |
|
#2 | |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8 |
Quote:
{ 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(); #}; } } |
||
September 29, 2020, 06:11 |
|
#3 |
Senior Member
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8 |
Uhm..thanks a lot!
I will try soon. Can I ask you what does it means: codeInclude #{ #include "OFstream.H" #}; ? Thanks a lot! |
|
September 29, 2020, 06:40 |
|
#4 |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8 |
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. |
|
September 30, 2020, 09:27 |
|
#5 |
Senior Member
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8 |
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? |
|
September 30, 2020, 09:56 |
|
#6 |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8 |
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? |
|
September 30, 2020, 10:25 |
|
#7 |
Senior Member
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8 |
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! |
|
October 1, 2020, 03:02 |
|
#8 |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8 |
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. |
|
October 1, 2020, 03:36 |
|
#9 |
Senior Member
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8 |
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! |
|
October 2, 2020, 04:42 |
|
#10 |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8 |
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. |
|
January 12, 2021, 03:49 |
|
#11 | |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8 |
Quote:
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(); #}; } } Last edited by geth03; January 12, 2021 at 07:21. Reason: updated for version 8 |
||
June 27, 2022, 04:24 |
controlDict
|
#12 | |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 |
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:
|
||
June 29, 2022, 23:19 |
|
#13 |
New Member
Join Date: May 2020
Posts: 14
Rep Power: 6 |
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); |
|
June 30, 2022, 03:53 |
|
#14 |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 |
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 |
|
July 23, 2022, 05:31 |
|
#15 |
New Member
Join Date: May 2020
Posts: 14
Rep Power: 6 |
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 |
|
Tags |
#static(p), controldict., field for p, pressure area |
|
|
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 |