forked from jan/opencl_fdtd
Revert "lookup tables"
(accidental commit)
This reverts commit 7bf7a3d80c
.
This commit is contained in:
parent
7bf7a3d80c
commit
cd72219d0b
@ -121,27 +121,15 @@ def cpml(direction: int,
|
||||
p0e, p1e = par(xe)
|
||||
p0h, p1h = par(xh)
|
||||
|
||||
def create_table(name, xs, type='float'):
|
||||
s = type + ''' {name}(int x) {{
|
||||
switch (x) {{
|
||||
'''.format(name=name)
|
||||
for i, x in enumerate(xs):
|
||||
s += ''' case {i}: return {x};
|
||||
'''.format(i=i, x=x)
|
||||
s += '''
|
||||
}
|
||||
}'''
|
||||
return s
|
||||
|
||||
vals = {'r': r,
|
||||
'u': uv[0],
|
||||
'v': uv[1],
|
||||
'np': np,
|
||||
'th': thickness,
|
||||
#'p0e': ', '.join((str(x) for x in p0e)),
|
||||
#'p1e': ', '.join((str(x) for x in p1e)),
|
||||
#'p0h': ', '.join((str(x) for x in p0h)),
|
||||
#'p1h': ', '.join((str(x) for x in p1h)),
|
||||
'p0e': ', '.join((str(x) for x in p0e)),
|
||||
'p1e': ', '.join((str(x) for x in p1e)),
|
||||
'p0h': ', '.join((str(x) for x in p0h)),
|
||||
'p1h': ', '.join((str(x) for x in p1h)),
|
||||
'se': '-+'[direction % 2],
|
||||
'sh': '+-'[direction % 2]}
|
||||
|
||||
@ -161,16 +149,24 @@ if ( (s{r} - 1) > {r} && {r} > (s{r} - 1) - ({th} + 1) ) {{
|
||||
raise Exception('Bad polarity (=0)')
|
||||
|
||||
code_e = """
|
||||
Psi_{r}{np}_E{u}[ip] = p0e(ir) * Psi_{r}{np}_E{u}[ip] + p1e(ir) * (H{v}[i] - H{v}[i-di{r}]);
|
||||
Psi_{r}{np}_E{v}[ip] = p0e(ir) * Psi_{r}{np}_E{v}[ip] + p1e(ir) * (H{u}[i] - H{u}[i-di{r}]);
|
||||
// pml parameters:
|
||||
const float p0[{th}] = {{ {p0e} }};
|
||||
const float p1[{th}] = {{ {p1e} }};
|
||||
|
||||
Psi_{r}{np}_E{u}[ip] = p0[ir] * Psi_{r}{np}_E{u}[ip] + p1[ir] * (H{v}[i] - H{v}[i-di{r}]);
|
||||
Psi_{r}{np}_E{v}[ip] = p0[ir] * Psi_{r}{np}_E{v}[ip] + p1[ir] * (H{u}[i] - H{u}[i-di{r}]);
|
||||
|
||||
E{u}[i] {se}= dt / eps{u}[i] * Psi_{r}{np}_E{u}[ip];
|
||||
E{v}[i] {sh}= dt / eps{v}[i] * Psi_{r}{np}_E{v}[ip];
|
||||
}}
|
||||
"""
|
||||
code_h = """
|
||||
Psi_{r}{np}_H{u}[ip] = p0h(ir) * Psi_{r}{np}_H{u}[ip] + p1h(ir) * (E{v}[i+di{r}] - E{v}[i]);
|
||||
Psi_{r}{np}_H{v}[ip] = p0h(ir) * Psi_{r}{np}_H{v}[ip] + p1h(ir) * (E{u}[i+di{r}] - E{u}[i]);
|
||||
// pml parameters:
|
||||
const float p0[{th}] = {{ {p0h} }};
|
||||
const float p1[{th}] = {{ {p1h} }};
|
||||
|
||||
Psi_{r}{np}_H{u}[ip] = p0[ir] * Psi_{r}{np}_H{u}[ip] + p1[ir] * (E{v}[i+di{r}] - E{v}[i]);
|
||||
Psi_{r}{np}_H{v}[ip] = p0[ir] * Psi_{r}{np}_H{v}[ip] + p1[ir] * (E{u}[i+di{r}] - E{u}[i]);
|
||||
|
||||
H{u}[i] {sh}= dt * Psi_{r}{np}_H{u}[ip];
|
||||
H{v}[i] {se}= dt * Psi_{r}{np}_H{v}[ip];
|
||||
@ -184,11 +180,6 @@ if ( (s{r} - 1) > {r} && {r} > (s{r} - 1) - ({th} + 1) ) {{
|
||||
'Psi_{r}{np}_E{v}'.format(**vals)],
|
||||
'psi_H': ['Psi_{r}{np}_H{u}'.format(**vals),
|
||||
'Psi_{r}{np}_H{v}'.format(**vals)],
|
||||
'tables': create_table('p0e', p0e) + \
|
||||
create_table('p1e', p1e) + \
|
||||
create_table('p0h', p0h) + \
|
||||
create_table('p1h', p1h)
|
||||
|
||||
}
|
||||
|
||||
return pml_data
|
||||
|
@ -174,8 +174,8 @@ class Simulation(object):
|
||||
pml_E_args = ', '.join(E_args + H_args + dt_arg + eps_args + arglist_E)
|
||||
pml_H_args = ', '.join(E_args + H_args + dt_arg + arglist_H)
|
||||
|
||||
pml_E = ElementwiseKernel(self.context, preamble=pml_data['tables'], arguments=pml_E_args, operation=pml_E_source)
|
||||
pml_H = ElementwiseKernel(self.context, preamble=pml_data['tables'], arguments=pml_H_args, operation=pml_H_source)
|
||||
pml_E = ElementwiseKernel(self.context, arguments=pml_E_args, operation=pml_E_source)
|
||||
pml_H = ElementwiseKernel(self.context, arguments=pml_H_args, operation=pml_H_source)
|
||||
|
||||
self.cpml_E = lambda e: pml_E(*self.E, *self.H, self.dt, *self.eps, *psi_E, wait_for=e)
|
||||
self.cpml_H = lambda e: pml_H(*self.E, *self.H, self.dt, *psi_H, wait_for=e)
|
||||
|
Loading…
Reference in New Issue
Block a user