|
[Sponsors] |
July 15, 2010, 17:52 |
Conditional Operation on a Geometric Field
|
#1 |
New Member
Sachin Shanbhag
Join Date: Nov 2009
Posts: 3
Rep Power: 17 |
This may be a relatively simple question. I am simplifying the actual problem, for clarity.
Say variable X is of type volScalarField, and takes values between 0 and 1.0. I want to define a dependent variable Y (type volScalarField) whose definition depends on the local value of X. Something like if(X>0.5) { Y = exp(-X); } else { Y = 2*X; } I tried to do this literally, and it said something like error: no match for 'operator>' in 'Foam:perator*(const Foam::GeometricField<Type, PatchField, GeoMesh>&, const Foam::scalar&) [...] |
|
July 15, 2010, 18:55 |
|
#2 |
Senior Member
Marco A. Turcios
Join Date: Mar 2009
Location: Vancouver, BC, Canada
Posts: 740
Rep Power: 28 |
Because this operation has to be done cell by cell, you need to use something like:
forAll (X, celli) { if(X[celli]>0.5) { Y[celli] = exp(-X[celli]);} else { Y[celli] = 2*X[celli];} } If the field has dimensions, then you're going to have to make sure you deal with them properly, but other than that I think that's how it goes down. |
|
July 16, 2010, 13:02 |
|
#3 |
New Member
Sachin Shanbhag
Join Date: Nov 2009
Posts: 3
Rep Power: 17 |
Thanks mturcios.
|
|
Tags |
conditional, field |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Perfoming operation if field is present | sega | OpenFOAM Programming & Development | 13 | August 16, 2023 06:08 |
Moving mesh | Niklas Wikstrom (Wikstrom) | OpenFOAM Running, Solving & CFD | 122 | June 15, 2014 07:20 |
Operation to READ_IF_PRESENT field | sega | OpenFOAM Programming & Development | 6 | February 15, 2011 10:57 |
Problem with rhoSimpleFoam | matteo_gautero | OpenFOAM Running, Solving & CFD | 0 | February 28, 2008 07:51 |
How to update polyPatchbs localPoints | liu | OpenFOAM Running, Solving & CFD | 6 | December 30, 2005 18:27 |