Skip to content
Snippets Groups Projects
Commit 880d668c authored by Jean-Baptiste Keck's avatar Jean-Baptiste Keck
Browse files

added hyperbolic function

parent ef43a7e0
No related branches found
No related tags found
1 merge request!3Resolve "Sine and cosine transforms to solve homogeneous Neumann and Dirichlet problems"
......@@ -8,7 +8,10 @@ TANK_RATIO = 1
FILL_PCT = 0.25
SEDIMENT_RADIUS = 5e-3
SEDIMENT_COUNT = int(1.15*(FILL_PCT*TANK_RATIO / (np.pi*SEDIMENT_RADIUS**2)))
DISCRETIZATION = 4096
DISCRETIZATION = 2048
BLOB_INIT = False
NB = 5
# initialize vorticity
def init_vorticity(data, coords, component=None):
......@@ -32,18 +35,21 @@ def init_phi(data, coords, nblobs, rblob):
R2 = rblob * rblob
cache_file='/tmp/C_init_ls_{}_{}'.format('_'.join(str(x) for x in data.shape),
str(abs(hash((TANK_RATIO,nblobs,rblob)))))
str(abs(hash((BLOB_INIT, NB, TANK_RATIO, nblobs, rblob)))))
try:
D = np.load(file=cache_file+'.npz')
vprint(' *Initializing sediments from cache: "{}.npz".'.format(cache_file))
data[...] = D['data']
except:
vprint(' *Initializing sediments of radius {} with {} random blobs.'.format(rblob, nblobs))
nb = 5
data[...] = np.sin(2*np.pi*nb*X)*np.sin(2*np.pi*nb*Y)
return
if not BLOB_INIT:
vprint(' *Initializing sediments with sines...')
data[...] = np.sin(2*np.pi*NB*X)*np.sin(2*np.pi*NB*Y)
data[...] = np.abs(data)
return
# we cache initialization
vprint(' *Initializing sediments of radius {} with {} random blobs.'.format(rblob, nblobs))
np.savez_compressed(file=cache_file, data=data)
vprint(' *Caching data to "{}.npz".'.format(cache_file))
......@@ -230,7 +236,11 @@ def compute(args):
#e3 = Assignment(H, H_eps)
#e4 = Assignment(Ss, S1 + (S2-S1)*H)
#exprs = (e0,e1,e2,e3,e4)
e = Assignment(Ss, 0.5*LogicalLE(phis, 0))
if BLOB_INIT:
e = Assignment(Ss, 0.5*LogicalLE(phis, 0))
else:
e = Assignment(Ss, 0.5*LogicalGT(phis, 0.5))
#e = Assignment(Ss, 0.5*LogicalLE(phis, 0))
exprs = (e,)
eval_fields = DirectionalSymbolic(name='eval_fields',
pretty_name=u'{}({})'.format(
......@@ -305,8 +315,8 @@ def compute(args):
dump_fields = HDF_Writer(name='dump',
io_params=io_params,
force_backend=Backend.OPENCL,
variables={velo: npts,
vorti: npts,
variables={#velo: npts,
#vorti: npts,
phi: npts,
S: npts},
**extra_op_kwds)
......@@ -324,7 +334,7 @@ def compute(args):
### Adaptive timestep operator
adapt_dt = AdaptiveTimeStep(dt, equivalent_CFL=True,
name='merge_dt', pretty_name='dt',
max_dt=1e-1)
max_dt=1)
dt_cfl = adapt_dt.push_cfl_criteria(cfl=args.cfl,
Finf=min_max_U.Finf,
equivalent_CFL=True,
......@@ -376,7 +386,8 @@ def compute(args):
# Initialize vorticity, velocity, S on all topologies
problem.initialize_field(field=velo, formula=init_velocity)
problem.initialize_field(field=vorti, formula=init_vorticity)
problem.initialize_field(field=phi, formula=init_phi, nblobs=nblobs, rblob=rblob, without_ghosts=True)
problem.initialize_field(field=phi, formula=init_phi, nblobs=nblobs, rblob=rblob,
without_ghosts=BLOB_INIT)
# Finally solve the problem
problem.solve(simu, dry_run=args.dry_run)
......@@ -418,9 +429,9 @@ if __name__=='__main__':
parser.set_defaults(impl='cl', ndim=2,
npts=(TANK_RATIO*DISCRETIZATION+1,DISCRETIZATION+1),
box_origin=(0.0,), box_length=(1.0,),
tstart=0.0, tend=10000.1,
dt=1e-6, cfl=0.50, lcfl=0.50,
dump_times=tuple(float(100*x) for x in range(100)),
tstart=0.0, tend=100.1,
dt=1e-6, cfl=8.00, lcfl=0.50,
dump_times=tuple(float(5*x) for x in range(20)),
dump_freq=0)
parser.run(compute)
......
......@@ -39,7 +39,8 @@ def map_expression(csc, expr, args, reqs):
def _map_ctypes(expr, args):
if isinstance(expr, sm.functions.elementary.trigonometric.TrigonometricFunction):
if isinstance(expr, (sm.functions.elementary.trigonometric.TrigonometricFunction,
sm.functions.elementary.hyperbolic.HyperbolicFunction)):
(args, ctype) = OpenClCastUtils.promote_expressions_to_required_signature(args,
'ftype', ret=0)
elif isinstance(expr, Select):
......@@ -133,7 +134,10 @@ _func_mappings = {
Select: OpenClSelect,
BroadCast: OpenClBroadCast,
Expand: OpenClExpand,
sm.cos: BuiltinFunction('cos'),
sm.sin: BuiltinFunction('sin'),
sm.tan: BuiltinFunction('tan'),
sm.cos: BuiltinFunction('cos'),
sm.sin: BuiltinFunction('sin'),
sm.tan: BuiltinFunction('tan'),
sm.cosh: BuiltinFunction('cosh'),
sm.sinh: BuiltinFunction('sinh'),
sm.tanh: BuiltinFunction('tanh'),
}
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