CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Conditional Operation on a Geometric Field (http://www.cfd-online.com/Forums/openfoam/78236-conditional-operation-geometric-field.html)

shane5ul July 15, 2010 16:52

Conditional Operation on a Geometric Field
 
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::operator*(const Foam::GeometricField<Type, PatchField, GeoMesh>&, const Foam::scalar&) [...]

mturcios777 July 15, 2010 17:55

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.

shane5ul July 16, 2010 12:02

Thanks mturcios.


All times are GMT -4. The time now is 00:42.