|
[Sponsors] |
July 25, 2023, 09:45 |
coded function in openFOAM 11
|
#1 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
In openFOAM v10, I have a function that calculates the volume-averaged flowspeed everywhere in my models. Inside ./system/controlDict, I have
Code:
functions { #includeFunc volAvU } Code:
volAvU { functionObjectLibs ( "libutilityFunctionObjects.so" ); type coded; codeOptions #{ -I$(LIB_SRC)/meshTools/lnInclude #}; codeExecute #{ const volVectorField& U ( mesh().lookupObject<volVectorField>("U") ); volScalarField magU(mag(U)); volScalarField scalar(mag(U)); dimensionedScalar totVol("totVol",dimensionSet(0,3,0,0,0,0,0),gSum(mesh().V())); dimensionedScalar avU("avU",dimensionSet(0,1,-1,0,0,0,0),0.0); scalar = mag(U); avU = fvc::domainIntegrate(scalar)/totVol; Info << "Time=," << mesh().time().value() << ", "; Info << "volAvMagU=" << avU.value() << endl; #}; } This now fails in openFOAM v11 -- I'll describe the errors in a follow-up post, because it's a bit messy. My questions are: -- what has changed? -- where can I find documentation of how this should work? Actually, I also look at some more complicated measures as well -- for example, what volume fraction of the fluid has a speed above 5m/s, etc -- so I think I want the "coded" type, rather than a one-liner of type "volFieldValue". (However I would be interested to see if a one-liner can apply mag() to vector U.) |
|
July 25, 2023, 10:08 |
|
#2 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
If I try the coded function mentioned in the OP in openFOAM v11, I initially get an error:
Code:
[6] [6] [6] --> FOAM FATAL ERROR: [6] Unknown function type coded Valid functions are : 7 ( fvModel massFractions moleFractions patchProbes probes sets surfaces ) Code:
Code:
/home/username/example/system/controlDict/functions/volAvU/volAvU: In member function ‘virtual bool Foam::volAvUFunctionObject::execute()’: /home/username/example/system/controlDict/functions/volAvU/volAvU:35:15: error: ‘fvc’ has not been declared |
|
July 25, 2023, 10:27 |
|
#3 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
None of the files in the tutorials mention "fvc", so I presume that this set of commands has been moved somewhere. Do I need to go and wrestle with the source code to find where?
Only one file in the tutorials mentions "integrate" (case-insensitive): it is /opt/openfoam11/tutorials/compressibleVoF/ballValve/system/controlDict in a function of type "volFieldValue", which seems limited. (Where should I look for documentation of volFieldValue? -- I tried the User Guide.) Only one file in the tutorials mentions "gSum": it is /opt/openfoam11/tutorials/multiphaseEuler/bubbleColumnEvaporating/system/continuityFunctions in a function of type "coded". I am not sure whether different functions are allowed in continuityFunctions compared to controlDict, and I am not sure how to find out. (As you can tell, my knowledge of openFOAM is very patchy indeed. I presume that the code in continuityFunctions takes effect somehow, but it is not mentioned elsewhere in the tutorial files. Maybe continuityFunctions is a reserved filename with an automatic effect?) I think my best chance of guessing how to proceed would be to investigate the coded function in /opt/openfoam11/tutorials/potentialFoam/cylinder/system/controlDict but I would prefer to learn properly, rather than cutting and pasting code at random. Can anyone advise me how to learn, please? |
|
July 25, 2023, 10:59 |
|
#4 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,200
Rep Power: 28 |
Hello,
I don't know why your coded function object does not work anymore with OpenFOAM 11. However, about documentation for volFieldValue, you can use the (very handy) foamInto utility: Code:
foamInfo volFieldValue Code:
File /opt/openfoam11/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H Description Provides a 'fvCellSet' specialisation of the fieldValue function object. Given a list of user-specified fields and a 'fvCellSet', a number of operations can be performed, such as sums, averages and integrations. Example of function object specification: \verbatim volFieldValue1 { type volFieldValue; libs ("libfieldFunctionObjects.so"); log true; writeControl writeTime; writeFields true; select cellZone; cellZone c0; operation volAverage; weightField alpha1; fields ( p U ); } \endverbatim Usage \table Property | Description | Required | Default value type | Type name: volFieldValue | yes | log | Write data to standard output | no | no writeFields | Write the region field values | yes | writeLocation| Write the location (if available) | no | no select | fvCellSet type: see below | yes | name | Name of fvCellSet if required | no | operation | Operation to perform | yes | weightField | Name of field to apply weighting | no | weightFields | Names of fields to apply weighting | no | fields | List of fields to operate on | yes | \endtable Where \c select options are: \plaintable cellZone | requires a 'name' entry to specify the cellZone all | all cells \endplaintable The \c operation is one of: \plaintable none | No operation sum | Sum sumMag | Sum of component magnitudes average | Ensemble average volAverage | Volume weighted average volIntegrate | Volume integral min | Minimum max | Maximum minMag | Minimum magnitude maxMag | Maximum magnitude CoV | Coefficient of variation: standard deviation/mean \endplaintable Model This appears to be the 'volFieldValue' model of the 'fieldValues' family. The models in the 'fieldValues' family are: + fieldValueDelta + surfaceFieldValue + volFieldValue Examples using "volFieldValue" /opt/openfoam11/tutorials/compressibleVoF/ballValve On a side note, few others productivity-oriented tips here: https://cfd.direct/openfoam/v11-productive-cfd/ I hope this helps, Yann |
|
July 25, 2023, 13:07 |
|
#5 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Hi Yann,
Thanks, foamInfo is helpful -- but only for the commands that it covers. -- gSum and domainIntegrate are not covered, for example. I think gSum is still valid, because it is in one of the tutorials. I am unsure about fvc::domainIntegrate. (Of course, it could be difficult to find it if it no longer exists in OF11 -- but it is not recognised by OF10's foamInfo.) If I wanted to know (for example) the list of acceptable values for writeControl in volFieldValue, how would I find it? -- foamInfo gives one example, writeTime -- and I know (from trying it) that this is not what I want. -- foamInfo links to the source code volFieldValue.H, but that does not lead me to a list. Nor does https://cpp.openfoam.org/v11/volFieldValue_8H.html. It could be useful to know that the info from foamInfo (for example the list of options) is not complete. -- For example, tutorials/compressibleVoF/ballValve/system/controlDict shows that a function of "type volFieldValue;" can have "writeControl timeStep; writeInterval 1;". I think this is probably what I want, and I can guess what writeInterval does. |
|
July 26, 2023, 05:17 |
|
#6 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,200
Rep Power: 28 |
Hello obscureed,
foamInfo gives information about applications, models, function objects, boundary conditions... implemented in OpenFOAM. gSum is none of that, only a C++ function. This is why you won't get anything about it with foamInfo. (foamInfo can only give you generic documentation of the coded function object) The only way I can think of to get C++ related information/documentation would be to use the C++ source guide (https://cpp.openfoam.org/v11/) but it does not seem very handy to me and I fail to find what I'm looking for most of the time (maybe because I'm not a developer) About writeControl: this is a general entry available for all function objects. foamInfo volFieldValue will only return documentation specific to this function object (basically it just retrieves the header of the source file for this function) and that's why you don't get anything about writeControl, which is not specific to volFieldValue but inherited from the functionObject base-class. However, you can get information about writeControl with foamInfo functionObject. (Or you can also use the good old banana trick to know what are your options for a specific entry, but it won't help you to learn about all existing entries) Hope this helps, Yann |
|
July 26, 2023, 08:48 |
|
#7 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Yes, that is helpful, thank you.
I agree that it is difficult to make progress by looking at the source code documentation, even if it is theoretically very thorough. My experience of all openFOAM documentation is that it is OK when you already have a good idea of what you are looking for, but frankly unhelpful when you do not. (The examples we have already discussed show this. What would lead me to type "foamInfo functionObject" for information about volFieldValue? If gSum is a standard C++ function, where is it defined? -- I went looking at https://cpp.hotexamples.com/examples...-examples.html, and all the examples were CFD- and openFOAM-related.) The banana trick is good for taking a single step, but it feels like exploring in the dark sometimes. So, thanks for your pointers to the help and foamInfo, Yann. If anyone has any specific information for the original coded function that I posted, it could save me some considerable time. |
|
October 26, 2023, 03:40 |
Use libs(...)
|
#8 |
New Member
Join Date: Jan 2021
Posts: 1
Rep Power: 0 |
Not sure if it's still relevant, but as far as understand in OF11 you should replace:
Code:
functionObjectLibs ( "libutilityFunctionObjects.so" ); Code:
libs ( "libutilityFunctionObjects.so" ); Hope this helps. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Frequently Asked Questions about Installing OpenFOAM | wyldckat | OpenFOAM Installation | 3 | November 14, 2023 12:58 |
Map of the OpenFOAM Forum - Understanding where to post your questions! | wyldckat | OpenFOAM | 10 | September 2, 2021 06:29 |
whats the cause of error? | immortality | OpenFOAM Running, Solving & CFD | 13 | March 24, 2021 08:15 |
[blockMesh] Errors during blockMesh meshing | Madeleine P. Vincent | OpenFOAM Meshing & Mesh Conversion | 51 | May 30, 2016 11:51 |
New OpenFOAM Forum Structure | jola | OpenFOAM | 2 | October 19, 2011 07:55 |