Modified laplacian solver
Dear all,
I tried to modify laplacianFoam to - be able to use temperature dependent material properties and - obtain the generated heat flux at the boundaries. I'm sure there already exist many solutions, function objects etc. to get this done, but for exercise I wanted to try that by my own. My code compiles and the solver in principle works. But during coding some questiosn came up I wanted to ask. But to start with the codes of the three modified files: laplacianFoam.C - modified Code:
#include "fvCFD.H" Code:
Info<< "Reading field T\n" << endl; Code:
if (runTime.writeTime()) Now to ask some specific questions: 1) How do I implement and read a new boolean statement in the controlDict and/or the transportProperties? I tried both and my trials are coloured in red in the code snippets (laplacian.C & createFields.H). Unfortunately none of them work. 2) I would like to create an output file with a list of the heat fluxes of all boundary cells for each patch. Unfortunately this partt of the code doesn't compile, the problem is the registryObject and I don't get what I have to put there to make it work (coloured in blue in write.H). Could somebody briefly explain what I have to put in there? 3) For me the two upper lines to obtain the cell center temperatures coloured in green (write.H) are identical with the single (commented) line below. However, if I use the single line command, the results differ (and are obviously wrong). Does anyone know why that is? Thank you very much in advance, stockzahn |
Hi stockzahn,
Quote:
If you use a bool type, - you can use only “true” or “false”, not “yes|no|on|off”, - there is no need to use an equal-to operator (==) because the bool variable itself will be the answer (true or false). The function of a dictionary class returns ITstream, not bool. https://github.com/OpenFOAM/OpenFOAM...tionary.H#L320 It is impossible - to compare different class and type, and - to assign a type to another class. If you prefer to use a bool type, lookupOrDefault function with a bool argument returns bool. (what you give will be returned as a template class) The following line will work as what you want (I did NOT tested it , sorry…) Code:
bool varProps = runTime.controlDict().lookupOrDefault(”variable", false) https://github.com/OpenFOAM/OpenFOAM...witch/Switch.H “runTimeModifiable” entry in controlDict is declared as Swith. “adjustTimeStep” entry is dealt as Swith by explicitly specifying it. Code:
lookupOrDefault<Switch>("adjustTimeStep", false) The code of Time class will be a good example of dictionary handling. |
Thanks for your response snak,
unfortunately I don't quite understand your explanation. I tried to get the code in the links you send me, but I wasn't able to correct my mistake. Quote:
Thanks for these clarifications, but to which equal-to operator (==) you are referring to? In my code Code:
if (runTime.controlDict().lookup("variable") == "yes" || runTime.controlDict().lookup("variable") == "true") Quote:
So the comparison of the return value of "lookup"-function with a word/string ("yes", "true") seems to be a problem? What kind of types are possible to return with the "lookup"-function? Quote:
Actually I don't need to return a bool, I just want to make a new entry into the dictionary, like I did for the polynomial coefficients, and dependent on the value/word next to it (preferably a word like "yes" or "true" or "on" instead of numbers 1 or 0), the solver should decide, if variable thermal properties are used or not. If a certain keyword is found, then the bool "varProp" is switched to "true". Since you pointed out that in the controlDict the option "runTimeModifiable" is defined as Switch: Do all the possible option in the controlDict have to be defined (like in Time.H)? In the transportDict that obviously is not necessary, therefore there should be a possibilty to define keywords. I suppose. Thanks, stockzahn |
I've just got a hint from Mowgli, for all of you who calculate polynoms like I do it in the first code snippet of my post #1: Have a look to the Horner scheme! Decreased the calculation time distinctly.
|
Hi, stockzahn
Quote:
Quote:
If there is no entry, the value is false. lookupOrDefault function can read the entry or can set the default value even if there is no entry. lookup function will cause an error with message when the entry does not exist. https://github.com/OpenFOAM/OpenFOAM...emplates.C#L32 --- The other example (not tested) Code:
Switch varProps = runTime.controlDict().lookupOrDefault<Switch>(”variable", false) Quote:
https://github.com/OpenFOAM/OpenFOAM...tionary.H#L320 --- lookup-func can be used (not tested) Code:
bool varProps = false; |
Thanks again snak,
that one: Code:
bool varProps = runTime.controlDict().lookupOrDefault(”variable", false) worked perefctly - as I wanted it. I put it in the transportProperties though: Code:
bool varProps = transportProperties.lookupOrDefault(”variable", false); Thanks a lot again! stockzahn |
Congrats on your success, stockzahn.
bool can only handle yes or no. Using Switch class will improve the usability with on/off and yes/no. If you have any chance, could you test the Switch version? Code:
Switch varProps = transportProperties.lookupOrDefault<Switch>("variable", false); |
Dear snak,
Both versions (bool and Switch) work with all keyword pairs (on/off, true/false, yes/no). Switch: Code:
Switch varProps = transportProperties.lookupOrDefault<Switch>("variable", false); bool: Code:
bool varProps = transportProperties.lookupOrDefault("variable", false); |
All times are GMT -4. The time now is 09:37. |