Implementation of "source" fields (J)
This commit is contained in:
parent
cb471df182
commit
d8dc024626
32
opencl_fdtd/kernels/update_j.cl
Normal file
32
opencl_fdtd/kernels/update_j.cl
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Update E-field from J field
|
||||||
|
*
|
||||||
|
* Template parameters:
|
||||||
|
* common_header: Rendered contents of common.cl
|
||||||
|
*
|
||||||
|
* OpenCL args:
|
||||||
|
* E, Jr, Ji, c, s, xmin, xmax, ymin, ymax, zmin, zmax
|
||||||
|
*/
|
||||||
|
|
||||||
|
{{common_header}}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
__global ftype *Jrx = Jr + XX;
|
||||||
|
__global ftype *Jry = Jr + YY;
|
||||||
|
__global ftype *Jrz = Jr + ZZ;
|
||||||
|
__global ftype *Jix = Ji + XX;
|
||||||
|
__global ftype *Jiy = Ji + YY;
|
||||||
|
__global ftype *Jiz = Ji + ZZ;
|
||||||
|
|
||||||
|
|
||||||
|
if (x < xmin || y < ymin || z < zmin) {
|
||||||
|
PYOPENCL_ELWISE_CONTINUE;
|
||||||
|
}
|
||||||
|
if (x >= xmax || y >= ymax || z >= zmax) {
|
||||||
|
PYOPENCL_ELWISE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ex[i] += c * Jrx[i] + s * Jix[i];
|
||||||
|
Ey[i] += c * Jry[i] + s * Jiy[i];
|
||||||
|
Ez[i] += c * Jrz[i] + s * Jiz[i];
|
@ -70,6 +70,7 @@ class Simulation(object):
|
|||||||
update_E = None # type: Callable[[List[pyopencl.Event]], pyopencl.Event]
|
update_E = None # type: Callable[[List[pyopencl.Event]], pyopencl.Event]
|
||||||
update_H = None # type: Callable[[List[pyopencl.Event]], pyopencl.Event]
|
update_H = None # type: Callable[[List[pyopencl.Event]], pyopencl.Event]
|
||||||
update_S = None # type: Callable[[List[pyopencl.Event]], pyopencl.Event]
|
update_S = None # type: Callable[[List[pyopencl.Event]], pyopencl.Event]
|
||||||
|
update_J = None # type: Callable[[List[pyopencl.Event]], pyopencl.Event]
|
||||||
sources = None # type: Dict[str, str]
|
sources = None # type: Dict[str, str]
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
@ -80,7 +81,8 @@ class Simulation(object):
|
|||||||
context: pyopencl.Context = None,
|
context: pyopencl.Context = None,
|
||||||
queue: pyopencl.CommandQueue = None,
|
queue: pyopencl.CommandQueue = None,
|
||||||
float_type: numpy.float32 or numpy.float64 = numpy.float32,
|
float_type: numpy.float32 or numpy.float64 = numpy.float32,
|
||||||
do_poynting: bool = True):
|
do_poynting: bool = True,
|
||||||
|
do_fieldsrc: bool = False):
|
||||||
"""
|
"""
|
||||||
Initialize the simulation.
|
Initialize the simulation.
|
||||||
|
|
||||||
@ -179,6 +181,17 @@ class Simulation(object):
|
|||||||
S_fields[ptr('oS')] = self.oS
|
S_fields[ptr('oS')] = self.oS
|
||||||
S_fields[ptr('S')] = self.S
|
S_fields[ptr('S')] = self.S
|
||||||
|
|
||||||
|
J_fields = OrderedDict()
|
||||||
|
if do_fieldsrc:
|
||||||
|
J_source = jinja_env.get_template('update_j.cl').render(**jinja_args)
|
||||||
|
self.sources['J'] = J_source
|
||||||
|
|
||||||
|
self.Ji = pyopencl.array.zeros_like(self.E)
|
||||||
|
self.Jr = pyopencl.array.zeros_like(self.E)
|
||||||
|
J_fields[ptr('Jr')] = self.Jr
|
||||||
|
J_fields[ptr('Ji')] = self.Ji
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
PML
|
PML
|
||||||
'''
|
'''
|
||||||
@ -191,6 +204,15 @@ class Simulation(object):
|
|||||||
self.update_H = self._create_operation(H_source, (base_fields, pml_h_fields, S_fields))
|
self.update_H = self._create_operation(H_source, (base_fields, pml_h_fields, S_fields))
|
||||||
if do_poynting:
|
if do_poynting:
|
||||||
self.update_S = self._create_operation(S_source, (base_fields, S_fields))
|
self.update_S = self._create_operation(S_source, (base_fields, S_fields))
|
||||||
|
if do_fieldsrc:
|
||||||
|
args = OrderedDict()
|
||||||
|
[args.update(d) for d in (base_fields, J_fields)]
|
||||||
|
var_args = [ctype + ' ' + v for v in 'cs'] + ['uint ' + r + m for r in 'xyz' for m in ('min', 'max')]
|
||||||
|
print(var_args)
|
||||||
|
update = ElementwiseKernel(self.context, operation=J_source,
|
||||||
|
arguments=', '.join(list(args.keys()) + var_args))
|
||||||
|
#print(len(args.values()),'\n\n', args.values(), args.keys())
|
||||||
|
self.update_J = lambda e, *a: update(*args.values(), *a, wait_for=e)
|
||||||
|
|
||||||
|
|
||||||
def _create_pmls(self, pmls):
|
def _create_pmls(self, pmls):
|
||||||
|
Loading…
Reference in New Issue
Block a user