Skip to content
Snippets Groups Projects
Commit 31605122 authored by EXT Jean-Matthieu Etancelin's avatar EXT Jean-Matthieu Etancelin
Browse files

fix python flowrate correction

parent 8e95d031
No related branches found
No related tags found
1 merge request!16MPI operators
Pipeline #39993 failed
...@@ -44,7 +44,7 @@ class PythonFlowRateCorrection(HostOperator): ...@@ -44,7 +44,7 @@ class PythonFlowRateCorrection(HostOperator):
self.absorption_start = absorption_start self.absorption_start = absorption_start
if self.absorption_start is None: if self.absorption_start is None:
self.absorption_start = velocity.domain.end[-1] self.absorption_start = velocity.domain.end[-1]
## TODO: Correction is taking an absorption start (see absorption operator) only in X dir. # TODO: Correction is taking an absorption start (see absorption operator) only in X dir.
super(PythonFlowRateCorrection, self).__init__( super(PythonFlowRateCorrection, self).__init__(
input_fields=input_fields, output_fields=output_fields, input_fields=input_fields, output_fields=output_fields,
input_params=input_params, **kwds) input_params=input_params, **kwds)
...@@ -63,35 +63,38 @@ class PythonFlowRateCorrection(HostOperator): ...@@ -63,35 +63,38 @@ class PythonFlowRateCorrection(HostOperator):
super(PythonFlowRateCorrection, self).discretize() super(PythonFlowRateCorrection, self).discretize()
self.dvelocity = self.input_discrete_tensor_fields[self.velocity] self.dvelocity = self.input_discrete_tensor_fields[self.velocity]
self.dvorticity = self.input_discrete_tensor_fields[self.vorticity] self.dvorticity = self.input_discrete_tensor_fields[self.vorticity]
topo = self.dvelocity[0].topology vtopo = self.dvelocity[0].topology
mesh = topo.mesh wtopo = self.dvorticity[0].topology
vmesh = vtopo.mesh
wmesh = wtopo.mesh
# Compute volume and surface integration coefficients # Compute volume and surface integration coefficients
spaceStep = mesh.space_step spaceStep = vmesh.space_step
lengths = topo.domain.length lengths = vtopo.domain.length
self._inv_ds = 1. / np.prod(lengths[:-1]) self._inv_ds = 1. / np.prod(lengths[:-1])
self._inv_dvol = 1. / (lengths[0]*lengths[1]*(self.absorption_start-topo.domain.origin[-1])) self._inv_dvol = 1. / (lengths[0]*lengths[1] *
(self.absorption_start-vtopo.domain.origin[-1]))
self.coeff_mean = np.prod(spaceStep) / np.prod(lengths) self.coeff_mean = np.prod(spaceStep) / np.prod(lengths)
# Compute space coordinates from domain origin # Compute space coordinates from domain origin
x0 = mesh.global_origin[-1] x0 = vmesh.global_origin[-1]
self.x_coord = mesh.local_mesh_coords[0] - x0 self.x_coord = vmesh.local_mesh_coords[0] - x0
# Compute slices for volume and surface integration # Compute slices for volume and surface integration
gstart = mesh.local_origin.copy() gstart = vmesh.local_origin.copy()
gstart[-1] = mesh.global_origin[-1] gstart[-1] = vmesh.global_origin[-1]
if mesh.is_inside_local_domain(gstart): if vmesh.is_inside_local_domain(gstart):
ind4integ_v = [_ for _ in mesh.local_compute_slices] ind4integ_v = [_ for _ in vmesh.local_compute_slices]
ind4integ_v[-1] = mesh.point_local_indices(gstart)[-1] ind4integ_v[-1] = vmesh.point_local_indices(gstart)[-1]
self._ind4integ_v = tuple(ind4integ_v) self._ind4integ_v = tuple(ind4integ_v)
else: else:
self._ind4integ_v = None self._ind4integ_v = None
self._ds_in = np.prod(spaceStep[0:2]) self._ds_in = np.prod(spaceStep[0:2])
ind4integ_w = [_ for _ in mesh.local_compute_slices] ind4integ_w = [_ for _ in wmesh.local_compute_slices]
box_end = mesh.local_origin.copy() box_end = wmesh.local_origin.copy()
box_end[-1] = self.absorption_start box_end[-1] = self.absorption_start
ind4integ_w[-1] = slice(ind4integ_w[-1].start, ind4integ_w[-1] = slice(ind4integ_w[-1].start,
mesh.point_local_indices(box_end)[-1], wmesh.point_local_indices(box_end)[-1],
ind4integ_w[-1].step) ind4integ_w[-1].step)
self._ind4integ_w = tuple(ind4integ_w) self._ind4integ_w = tuple(ind4integ_w)
self._ds_box = np.prod(spaceStep) self._ds_box = np.prod(spaceStep)
...@@ -134,13 +137,13 @@ class PythonFlowRateCorrection(HostOperator): ...@@ -134,13 +137,13 @@ class PythonFlowRateCorrection(HostOperator):
flowrate_req = self.flowrate() * self._inv_ds flowrate_req = self.flowrate() * self._inv_ds
velo_shift = np.zeros((dv.dim, )) velo_shift = np.zeros((dv.dim, ))
velo_shift = flowrate_req - self.rates[0:dv.dim] velo_shift = flowrate_req - self.rates[dv.dim-1::-1]
# Shift velocity Vx # Shift velocity Vx
dv.data[0][...] += velo_shift[2] dv.data[0][...] += velo_shift[2]
# Update Vy and Vz with mean vorticity # Update Vy and Vz with mean vorticity
dv.data[1][...] += velo_shift[1] + self.rates[dv.dim]*self.x_coord dv.data[1][...] += velo_shift[1] + self.rates[dv.dim+2]*self.x_coord
dv.data[2][...] += velo_shift[0] + self.rates[dv.dim+1]*self.x_coord dv.data[2][...] += velo_shift[0] + self.rates[dv.dim+1]*self.x_coord
if (self.ghost_exchanger is not None): if (self.ghost_exchanger is not None):
self.ghost_exchanger() self.ghost_exchanger()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment