Skip to content

Commit

Permalink
Updated pyrandaRANSBox.py to work with current version of RANSBox. Ma…
Browse files Browse the repository at this point in the history
…de changes to account for addition of TurbVars data structure in RANSBox. Added TurbVars to EvaluateModel call and created dictionary for variable mappings to avoid potential overwrite of Pyranda variables by RANSBox Outputs.
  • Loading branch information
Dana Lynn Ona-Lansigan Lavacot authored and flow-phys committed Jul 3, 2024
1 parent e02ac5e commit 278f7ad
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions pyranda/pyrandaRANSBOX.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,30 @@ def __init__(self,pysim):
self.ny = pysim.PyMPI.ay
self.nz = pysim.PyMPI.az
self.shape = (self.nx, self.ny, self.nz)
self.input_maps = {}
self.turbvar_maps = {}
self.output_maps = {}

# Inputs - auto from ransbox api
inputs = ransbox.RANSBoxInputs()
self.inputList = [i for i in dir(inputs) if "__" not in i]
for ii in self.inputList:
exec("self.%s = None" % ii)
# exec(f"self.input_maps.%s = None" % ii)
self.input_maps[ii] = None

# Turbulence variables
turbvars = ransbox.RANSBoxTurbVars()
self.turbvarList = [i for i in dir(turbvars) if "__" not in i]
for ii in self.turbvarList:
# exec(f"self.turbvar_maps.%s = None" % ii)
self.turbvar_maps[ii] = None

# Outputs - auto from ransbox api
outputs = ransbox.RANSBoxOutputs()
self.outputList = [i for i in dir(outputs) if "__" not in i]
for ii in self.outputList:
exec("self.%s = None" % ii)
# exec(f"self.output_maps.%s = None" % ii)
self.output_maps[ii] = None

# Available Models
self.modPrefix = "RANSBox_ModelType_"
Expand All @@ -56,6 +68,7 @@ def __init__(self,pysim):


self.inputs = inputs
self.turbvars = turbvars
self.outputs = outputs
self.allocated = False

Expand Down Expand Up @@ -154,7 +167,7 @@ def allocate(self):
# Allocate some space for RANSBox outputs
npts = self.nx * self.ny * self.nz
for ii in self.outputList:
#exec("val = self.%s" % ii )
# exec("val = self.%s" % ii )
#if val:
exec("self.outputs.%s = numpy.zeros(npts)" % ii )

Expand Down Expand Up @@ -183,36 +196,42 @@ def toF(self, val ):

def evaluate(self):

if not self.allocated:
self.allocate()

# Setup inputs (if direct pointer, only do once?)
#inputs = self.inputs

for ii in self.inputList:
exec("val = self.%s" % ii )
# exec(f"val = self.%s" % ii)
# val = getattr(self.input_maps,ii)
val = self.input_maps[ii]
if val:
#exec("self.inputs.%s = self.toC( self.pysim.variables[ self.%s ].data )" % (ii,ii) )
exec("self.inputs.%s = self.pysim.variables[ self.%s ].data " % (ii,ii) )

exec("self.inputs.%s = self.pysim.variables[ val ].data " % ii )

for ii in self.turbvarList:
# exec(f"val = self.%s" % ii)
# val = getattr(self.turbvar_maps,ii)
val = self.turbvar_maps[ii]
if val:
exec("self.turbvars.%s = self.pysim.variables[ val ].data " % ii )

if not self.allocated:
self.allocate()

# Evaluate model
npts = self.nx * self.ny * self.nz
RANSBox_EvaluateModel(self.model, self.inputs, self.outputs, npts, "cpu")
RANSBox_EvaluateModel(self.model, self.inputs, self.turbvars, self.outputs, npts, "cpu")


#import pdb
#pdb.set_trace()


for ii in self.outputList:
exec("val = self.%s" % ii )
if val:
#exec("self.pysim.variables[ self.%s ].data = self.toF( self.outputs.%s )" % (ii,ii) )
exec("self.pysim.variables[ self.%s ].data = self.outputs.%s.reshape(self.shape)" % (ii,ii) )







# Update outputs

for ii in self.outputList:
# exec(f"val = self.%s" % ii )
# val = getattr(self.output_maps,ii)
val = self.output_maps[ii]
if val:
exec("self.pysim.variables[ val ].data = self.outputs.%s.reshape(self.shape)" % ii )

0 comments on commit 278f7ad

Please sign in to comment.