From 914aa2a4ff23ab31a5d577328c4b6875111a6651 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Keck <Jean-Baptiste.Keck@imag.fr>
Date: Fri, 29 Jun 2018 11:39:18 +0200
Subject: [PATCH] merge

---
 .../particles_above_salt_periodic.py          | 19 +++++++++++++++----
 hysop/operator/directional/diffusion_dir.py   |  2 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/examples/particles_above_salt/particles_above_salt_periodic.py b/examples/particles_above_salt/particles_above_salt_periodic.py
index 6364e61d5..f521f5141 100644
--- a/examples/particles_above_salt/particles_above_salt_periodic.py
+++ b/examples/particles_above_salt/particles_above_salt_periodic.py
@@ -34,7 +34,7 @@ def init_salinity(data, coords, l0):
 
 
 def compute(args):
-    from hysop import Field, Box, Simulation, Problem, MPIParams, IOParams
+    from hysop import Field, Box, Simulation, Problem, MPIParams, IOParams, vprint
     from hysop.defaults import VelocityField, VorticityField, \
                                DensityField, ViscosityField, \
                                LevelSetField, \
@@ -58,6 +58,7 @@ def compute(args):
     from hysop.symbolic.relational import Assignment, LogicalGT, LogicalLT
     from hysop.symbolic.misc import Select
     from hysop.symbolic.tmp import TmpScalar
+    from hysop.tools.string_utils import framed_str
 
     # Constants
     l0 = 1.5 #initial thickness of the profile
@@ -209,7 +210,17 @@ def compute(args):
                                         S: npts})
 
     ### Adaptive timestep operator
-    adapt_dt = AdaptiveTimeStep(dt, equivalent_CFL=True, max_dt=1e-3,
+    dx = np.min(np.divide(box.length, np.asarray(args.npts)-1))
+    S_dt = 0.5*(dx**2)/nu_S
+    C_dt = 0.5*(dx**2)/nu_C
+    W_dt = 0.5*(dx**2)/1.0
+    msg = 'S_dt={}, C_dt={}, W_dt={}'
+    msg = msg.format(S_dt, C_dt, W_dt)
+    msg = '\n'+framed_str(' DIFFUSION STABILITY CRITERIA ', msg)
+    vprint(msg)
+    max_dt = min(S_dt, C_dt, W_dt)
+
+    adapt_dt = AdaptiveTimeStep(dt, equivalent_CFL=True, max_dt=max_dt,
                                     name='merge_dt', pretty_name='dt', )
     dt_cfl   = adapt_dt.push_cfl_criteria(cfl=args.cfl, Finf=min_max_U.Finf,
                                             equivalent_CFL=True, 
@@ -264,7 +275,7 @@ def compute(args):
     problem.initialize_field(field=S,     formula=init_salinity, l0=l0)
     
     # Finally solve the problem 
-    problem.solve(simu)
+    problem.solve(simu, dry_run=args.dry_run)
     
     # Finalize
     problem.finalize()
@@ -300,7 +311,7 @@ if __name__=='__main__':
 
     parser = ParticleAboveSaltArgParser()
 
-    parser.set_defaults(impl='cl', ndim=2, npts=(257,),
+    parser.set_defaults(impl='cl', ndim=2, npts=(65,),
                         box_origin=(0.0,), box_length=(1.0,), 
                         tstart=0.0, tend=0.51, 
                         dt=1e-6, cfl=0.5, lcfl=0.125,
diff --git a/hysop/operator/directional/diffusion_dir.py b/hysop/operator/directional/diffusion_dir.py
index 31329a3ba..a7666dbe2 100644
--- a/hysop/operator/directional/diffusion_dir.py
+++ b/hysop/operator/directional/diffusion_dir.py
@@ -139,6 +139,8 @@ class DirectionalDiffusion(DirectionalSymbolic):
             msg=msg.format(self._operator, CustomSymbolicOperatorBase)
             raise TypeError(msg)
         
+        self.coeffs = coeffs
+        
     def _gen_expressions(self, fields, coeffs, laplacian_formulation):
         from hysop.symbolic.field import div, grad, laplacian
         exprs = ()
-- 
GitLab