CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Conditional Operation on a Geometric Field

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 15, 2010, 17:52
Default Conditional Operation on a Geometric Field
  #1
New Member
 
Sachin Shanbhag
Join Date: Nov 2009
Posts: 3
Rep Power: 17
shane5ul is on a distinguished road
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&) [...]
shane5ul is offline   Reply With Quote

Old   July 15, 2010, 18:55
Default
  #2
Senior Member
 
mturcios777's Avatar
 
Marco A. Turcios
Join Date: Mar 2009
Location: Vancouver, BC, Canada
Posts: 740
Rep Power: 28
mturcios777 will become famous soon enough
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.
mturcios777 is offline   Reply With Quote

Old   July 16, 2010, 13:02
Default
  #3
New Member
 
Sachin Shanbhag
Join Date: Nov 2009
Posts: 3
Rep Power: 17
shane5ul is on a distinguished road
Thanks mturcios.
shane5ul is offline   Reply With Quote

Reply

Tags
conditional, field

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 16:11.