# Conditional Operation on a Geometric Field

 Register Blogs Members List Search Today's Posts Mark Forums Read

 July 15, 2010, 16:52 Conditional Operation on a Geometric Field #1 New Member   Sachin Shanbhag Join Date: Nov 2009 Posts: 3 Rep Power: 9 Sponsored Links 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&, const Foam::scalar&) [...]

 July 15, 2010, 17:55 #2 Senior Member     Marco A. Turcios Join Date: Mar 2009 Location: Vancouver, BC, Canada Posts: 734 Rep Power: 21 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, 12:02 #3 New Member   Sachin Shanbhag Join Date: Nov 2009 Posts: 3 Rep Power: 9 Thanks mturcios.

 Tags conditional, field

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20 sega OpenFOAM Programming & Development 6 February 15, 2011 10:57 sega OpenFOAM Programming & Development 12 October 21, 2009 06:20 matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51 liu OpenFOAM Running, Solving & CFD 6 December 30, 2005 18:27