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

Is there a similar function to numpy.where in OpenFOAM?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 3, 2021, 09:13
Question Is there a similar function to numpy.where in OpenFOAM?
  #1
Senior Member
 
NotOverUnderated's Avatar
 
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5
NotOverUnderated is on a distinguished road
Hello,

OpenFOAM makes it very easy to assign values to fields thanks to operator overloading which makes it more natural and avoids explicit looping over all mesh cells, e.g:

Code:
// assuming p is volScalarField, we can use
p = 5.0
// Now every mesh cell has a value p=5
Now comes the question that arise naturally. Does this flexibility extends to conditional assignment, i.e. is it possible to assign values to fields conditionally without using an explicit looping (which in Python with numpy can be achieved using the where function), e.g:

Code:
# Assuming t and p are two 1D arrays and have the same size
p = numpy.where(t<2.0, 7.0, 0.0)

# That means if t <2.0 assign the value 7.0 to p, otherwise 0.0
My question: is there a similar functionality in OpenFOAM that allows that without explicit looping?

Thank you
NotOverUnderated is offline   Reply With Quote

Reply

Tags
openfoam, python


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
Map of the OpenFOAM Forum - Understanding where to post your questions! wyldckat OpenFOAM 10 September 2, 2021 06:29
OpenFOAM Training, London, Chicago, Munich, Houston 2016-2017 cfd.direct OpenFOAM Announcements from Other Sources 0 September 14, 2016 04:19
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27
Compilation errors in ThirdPartymallochoard feng_w OpenFOAM Installation 1 January 25, 2009 07:59
Droplet Evaporation Christian Main CFD Forum 2 February 27, 2007 07:27


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