Skip to content
Snippets Groups Projects
Commit 20cbd81f authored by Christophe Picard's avatar Christophe Picard
Browse files

Destroy old BC

parent c91291dd
No related branches found
No related tags found
1 merge request!3Resolve "Sine and cosine transforms to solve homogeneous Neumann and Dirichlet problems"
Pipeline #16726 failed
"""Operator to kill the vorticity at the outlet boundary
(i.e. removal of the periodic BC in the flow direction
by vorticity absorption in order to set the far field
velocity to u_inf at the inlet)
See :ref:`absorption_bc`.
"""
from hysop.constants import debug
from hysop.operator.discrete.absorption_bc import AbsorptionBC as Dab
from hysop.operator.computational import Computational
from hysop.operator.continuous import opsetup
from hysop.domain.subsets import SubBox
import numpy as np
class AbsorptionBC(Computational):
"""
The periodic boundary condition is modified at the outlet
in the flow direction in order to discard
in the dowstream region the eddies coming
periodically from the outlet.
The far field velocity is set to u_inf at the inlet.
"""
@debug
def __init__(self, velocity, vorticity, req_flowrate,
x_range, filter_func=None, **kwds):
"""
Parameters
----------
velocity, vorticity : :class:`~hysop.fields.continuous_field.Field`
req_flowrate : double
required value for the flow rate
(used to set the u_inf velocity value at the inlet)
x_range : list or numpy array
x-coordinates delimitating the absorption domain
like [x_beginning, x_end]
filter_func: list of python functions, optional
functions used to compute the filter and its differential.
**kwds : extra parameters for base class
Notes
-----
* if set, filter_func[0] and filter_func[1] must be python function
returning a numpy array. For example to apply a sine inside
the absorption area use :
.. code::
def func(x):
return np.sin(x)
"""
assert 'variables' not in kwds, 'variables parameter is useless.'
super(AbsorptionBC, self).__init__(variables=[velocity,
vorticity], **kwds)
# velocity variable
self.velocity = velocity
# vorticity variable
self.vorticity = vorticity
self.input = [self.velocity, self.vorticity]
self.output = [self.vorticity]
# Expected value for the flow rate through input surface
self.req_flowrate = req_flowrate
# x-coordinates delimitating the absorption band at the outlet
self._filter_func = filter_func
self.absorption_box = self.build_absorption_box(x_range)
# on_proc[topo] = True if this operator has to work on the
# current process, i.e. if absorption_box has points
# on the current process.
self.on_proc = {}
def discretize(self):
super(AbsorptionBC, self)._standard_discretize()
assert self._single_topo, 'Multi-resolution case is not allowed.'
topo = self.discrete_fields[self.vorticity].topology
self.absorption_box.discretize(topo)
self.on_proc[topo] = self.absorption_box.on_proc[topo]
def build_absorption_box(self, x_range):
"""Build a box to define the area where the absorption
filter will be applied
Parameters
----------
x_range : list or numpy array
x right and left positions of the box.
"""
# setup for the absorption filter definition
dom = self.vorticity.domain
borig = dom.origin.copy()
borig[0] = x_range[0]
blength = dom.length.copy()
blength[0] = x_range[1] - x_range[0]
return SubBox(parent=dom, origin=borig, length=blength)
def get_work_properties(self):
super(AbsorptionBC, self).get_work_properties()
wd = self.discrete_fields[self.vorticity]
subshape = self.absorption_box.mesh[wd.topology].resolution
subsize = np.prod(subshape)
return {'rwork': (subsize, ), 'iwork': None}
@debug
@opsetup
def setup(self, rwork=None, iwork=None):
if not self._is_uptodate:
# if self.on_proc[self.discrete_fields[self.vorticity].topology]:
self.discrete_op =\
Dab(velocity=self.discrete_fields[self.velocity],
vorticity=self.discrete_fields[self.vorticity],
req_flowrate=self.req_flowrate,
absorption_box=self.absorption_box,
rwork=rwork, iwork=iwork,
filter_func=self._filter_func)
# Output setup
self._set_io('absorption_BC', (1, 2 + self.domain.dim))
self.discrete_op.set_writer(self._writer)
self._is_uptodate = True
def wait(self):
print "TEMP WAIT FOR TEST"
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