|
[Sponsors] |
OpenFOAM construct for conditional field modification |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 23, 2019, 12:12 |
OpenFOAM construct for conditional field modification
|
#1 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22 |
I would like to ask if there is a standard OpenFOAM construction/macro/??? to write the following algorithm in a more concise way:
Code:
forAll(TPatch, faceI) { if (TPatch[faceI] > whatever) { xPatch[faceI] = get_something(TPatch[faceI] ); } else { xPatch[faceI] = get_something_else(TPatch[faceI]); } } Code:
xPatch = (TPach > watever ? get_something(TPatch) : get_something_else(TPatch)) |
|
May 25, 2019, 13:34 |
|
#2 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
I do not know precisely, but when construction the pressure contribution in the energy equation of of compressible flow it is done something similar:
Code:
fvScalarMatrix EEqn ( fvm::ddt(rho, he) + fvm::div(phi, he) + fvc::ddt(rho, K) + fvc::div(phi, K) + ( he.name() == "e" ? fvc::div ( fvc::absolute(phi/fvc::interpolate(rho), U), p, "div(phiv,p)" ) : -dpdt ) - fvm::laplacian(turbulence.alphaEff(), he) == rho*(U&g) + rad.Sh(thermo, he) + Qdot + fvOptions(rho, he) ); |
|
May 25, 2019, 18:04 |
|
#3 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22 |
Thank you for your answer. But this is only testing the name of the energy field and selected on of two possible ways for the calculation.
What I look for is a way to calcuate a field differently for each cell based on a condition. |
|
May 27, 2019, 08:06 |
|
#4 |
Senior Member
|
Hi,
@jherb There are neg and pos functions for fields, so your code could look like: Code:
xPatch = pos(TPach - watever)*get_something(TPatch) + neg(TPach - watever)*get_something_else(TPatch)) |
|
May 30, 2019, 08:38 |
|
#5 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22 |
@alexeym: Thank you for your answer. This will work (if using neg0 to also catch all cells with value 0). But it would require to two both calculations/function calls for each cell. Also I am not sure it this would not require some temporary fields. So for large meshes this might be significantly slower than a cell-by-cell decision.
|
|
May 30, 2019, 18:43 |
|
#6 |
Senior Member
|
@jherb, well, surely it won't be faster (for any size of the mesh), since it requires creation of temporary fields and (at least) double evaluation of TPach - watever. Yet there is "vectorisation" mantra. Which is usually supported (or imposed) by certain prof.
Also your code is a candidate for either transforming into macro or a template. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] dynamicTopoFVMesh and pointDisplacement | RandomUser | OpenFOAM Meshing & Mesh Conversion | 6 | April 26, 2018 08:30 |
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology | wyldckat | OpenFOAM | 17 | November 10, 2017 16:54 |
Suggestion for a new sub-forum at OpenFOAM's Forum | wyldckat | Site Help, Feedback & Discussions | 20 | October 28, 2014 10:04 |
Moving mesh | Niklas Wikstrom (Wikstrom) | OpenFOAM Running, Solving & CFD | 122 | June 15, 2014 07:20 |
Problem with rhoSimpleFoam | matteo_gautero | OpenFOAM Running, Solving & CFD | 0 | February 28, 2008 07:51 |