From 06db3ab069a788ddb4ac0d71ae142caa786e8ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franck=20P=C3=A9rignon?= <franck.perignon@imag.fr> Date: Fri, 20 May 2016 17:35:28 +0200 Subject: [PATCH] Fix tests, examples + pep8 things --- examples/FlowAroundHemisphere.py | 10 +- examples/FlowAroundSphere_DNS.py | 8 +- examples/FlowAroundSphere_linearized.py | 12 +- examples/FlowAroundSphere_pressure.py | 10 +- examples/LevelSet2D/levelSet2D.py | 8 +- examples/LevelSet3D/levelSet3D.py | 8 +- examples/LevelSet3D/levelSet3D_Scales.py | 6 +- .../levelSet3D_Scales_MultiScale.py | 6 +- examples/LevelSet3D/levelSet3D_gpu.py | 8 +- .../LevelSet3D/levelSet3D_gpu_MultiScale.py | 8 +- examples/LevelSet3D/levelSet3D_only_gpu.py | 8 +- .../levelSet3D_only_gpu_MultiScale.py | 8 +- examples/LevelSet3D/levelSet3D_python.py | 8 +- .../Multiphase/NS_planeJet_hybrid_MS_MP.py | 4 +- examples/Multiphase/RTI.py | 4 +- examples/NSDebug_faux2D.py | 4 +- examples/NS_Richtmyer_Meshkov.py | 6 +- examples/NS_bluff_bodies.py | 6 +- examples/PassiveControl_Hemisphere.py | 10 +- examples/Plane_jet/NS_planeJet_hybrid_MS.py | 4 +- examples/RMI/RMI_hybrid.py | 4 +- examples/TaylorGreen/TaylorGreen3D.py | 12 +- examples/TaylorGreen/TaylorGreen3D_GPU.py | 6 +- examples/TaylorGreen/TaylorGreen3D_debug.py | 10 +- .../TaylorGreen/TaylorGreen3D_debug_filter.py | 10 +- examples/demo_2D_real-time.py | 6 +- examples/demo_hybrid.py | 2 +- examples/howto_integrators.py | 28 +- examples/mainJM.py | 4 +- examples/testDiffusion.py | 10 +- examples/testPoisson.py | 4 +- examples/testScales.py | 6 +- examples/testVisu.py | 2 +- hysop/fields/tests/test_field.py | 2 +- hysop/fields/tests/test_variable.py | 57 ++-- hysop/fields/variable_parameter.py | 131 +++------ hysop/gpu/QtRendering.py | 10 +- hysop/gpu/gpu_diffusion.py | 8 +- hysop/gpu/gpu_particle_advection.py | 12 +- hysop/gpu/gpu_transfer.py | 2 +- hysop/gpu/multi_gpu_particle_advection.py | 10 +- .../gpu/tests/test_advection_nullVelocity.py | 28 +- .../tests/test_advection_randomVelocity.py | 24 +- .../tests/test_gpu_multiresolution_filter.py | 2 +- hysop/gpu/tests/test_multiphase_baroclinic.py | 2 +- hysop/numerics/tests/test_integrators.py | 12 +- hysop/operator/adapt_timestep.py | 6 +- hysop/operator/discrete/adapt_timestep.py | 6 +- hysop/operator/discrete/baroclinic.py | 2 +- .../operator/discrete/baroclinic_from_rhs.py | 2 +- hysop/operator/discrete/custom.py | 2 +- hysop/operator/discrete/diffusion_fft.py | 2 +- hysop/operator/discrete/drag_and_lift.py | 4 +- hysop/operator/discrete/energy_enstrophy.py | 2 +- hysop/operator/discrete/forcing.py | 2 +- hysop/operator/discrete/low_pass_filt.py | 2 +- hysop/operator/discrete/monitoringPoints.py | 6 +- hysop/operator/discrete/multiphase_gradp.py | 2 +- hysop/operator/discrete/particle_advection.py | 2 +- hysop/operator/discrete/penalization.py | 2 +- hysop/operator/discrete/poisson_fft.py | 4 +- hysop/operator/discrete/profiles.py | 38 +-- hysop/operator/discrete/reprojection.py | 2 +- hysop/operator/discrete/residual.py | 6 +- hysop/operator/discrete/scales_advection.py | 2 +- hysop/operator/discrete/spectrum.py | 2 +- hysop/operator/discrete/stretching.py | 4 +- .../operator/discrete/velocity_correction.py | 2 +- hysop/operator/hdf_io.py | 4 +- hysop/operator/tests/test_Stretching.py | 12 +- .../operator/tests/test_adaptive_time_step.py | 14 +- hysop/operator/tests/test_advec_scales.py | 44 +-- hysop/operator/tests/test_analytic.py | 2 +- hysop/operator/tests/test_density.py | 2 +- hysop/operator/tests/test_diff_poisson_3D.py | 4 +- hysop/operator/tests/test_diffusion.py | 6 +- hysop/operator/tests/test_drag_and_lift.py | 12 +- hysop/operator/tests/test_energy_enstrophy.py | 2 +- hysop/operator/tests/test_hdf5_io.py | 26 +- hysop/operator/tests/test_multiphase_gradp.py | 2 +- .../tests/test_multiresolution_filter.py | 2 +- .../operator/tests/test_particle_advection.py | 8 +- hysop/operator/tests/test_penalization.py | 4 +- hysop/operator/tests/test_poisson.py | 12 +- hysop/operator/tests/test_redistribute.py | 4 +- hysop/operator/tests/test_reprojection.py | 4 +- hysop/operator/tests/test_spectrum.py | 2 +- .../tests/test_velocity_correction.py | 4 +- hysop/problem/problem.py | 6 +- hysop/problem/problem_tasks.py | 6 +- hysop/problem/simulation.py | 278 ++++++++++++------ hysop/problem/tests/test_simulation.py | 36 +-- hysop/problem/tests/test_transport.py | 32 +- 93 files changed, 596 insertions(+), 584 deletions(-) diff --git a/examples/FlowAroundHemisphere.py b/examples/FlowAroundHemisphere.py index 5b983bf98..5f47c02a9 100644 --- a/examples/FlowAroundHemisphere.py +++ b/examples/FlowAroundHemisphere.py @@ -115,7 +115,7 @@ vorti = Field(domain=box, formula=computeVort, name='Vorticity', is_vector=True) # ========= Simulation setup ========= -simu = Simulation(tinit=0.0, tend=75.0, timeStep=0.0125, iterMax=10000000) +simu = Simulation(start=0.0, end=75.0, time_step=0.0125, max_iter=10000000) # Adaptative timestep method : dt = min(values(dtCrit)) @@ -365,10 +365,10 @@ def restart(filename): filedump = filename + '_rk_' + str(main_rank) db = open(filedump, 'r') simu = cPickle.load(db) - simu.start = simu.time - simu.timeStep - ite = simu.currentIteration + simu.start = simu.time - simu.time_step + ite = simu.current_iteration simu.initialize() - simu.currentIteration = ite + simu.current_iteration = ite print 'simu', simu print ("load ...", filename) return simu @@ -401,7 +401,7 @@ while not simu.isOver: simu.printState() run(seq) simu.advance() - testdump = simu.currentIteration % dumpFreq is 0 + testdump = simu.current_iteration % dumpFreq is 0 if doDump and testdump: print 'dump ...' dump(dump_filename) diff --git a/examples/FlowAroundSphere_DNS.py b/examples/FlowAroundSphere_DNS.py index ea8ba078b..69808ec09 100644 --- a/examples/FlowAroundSphere_DNS.py +++ b/examples/FlowAroundSphere_DNS.py @@ -121,7 +121,7 @@ vorti = Field(domain=box, formula=computeVort, name='Vorticity', is_vector=True) # ========= Simulation setup ========= -simu = Simulation(tinit=0.0, tend=300.0, timeStep=0.0125, iterMax=100) +simu = Simulation(start=0.0, end=300.0, time_step=0.0125, max_iter=100) # Adaptative timestep method : dt = min(values(dtCrit)) @@ -279,10 +279,10 @@ def restart(filename): filedump = filename + '_rk_' + str(main_rank) db = open(filedump, 'r') simu = cPickle.load(db) - simu.start = simu.time - simu.timeStep - ite = simu.currentIteration + simu.start = simu.time - simu.time_step + ite = simu.current_iteration simu.initialize() - simu.currentIteration = ite + simu.current_iteration = ite print 'simu', simu print ("load ...", filename) return simu diff --git a/examples/FlowAroundSphere_linearized.py b/examples/FlowAroundSphere_linearized.py index d2bc313bd..26d0004e2 100644 --- a/examples/FlowAroundSphere_linearized.py +++ b/examples/FlowAroundSphere_linearized.py @@ -124,7 +124,7 @@ vorti = Field(domain=box, formula=setZeroVort, name='Vorticity_fluc', is_vector=True) # ========= Simulation setup ========= -simu = Simulation(tinit=0.0, tend=2000.0, timeStep=0.005, iterMax=10000000) +simu = Simulation(start=0.0, end=2000.0, time_step=0.005, max_iter=10000000) # Adaptative timestep method : dt = min(values(dtCrit)) @@ -414,12 +414,12 @@ def restart(filename): filedump = filename + '_rk_' + str(main_rank) db = open(filedump, 'r') simu = cPickle.load(db) -# simu.start = simu.time - simu.timeStep -# ite = simu.currentIteration +# simu.start = simu.time - simu.time_step +# ite = simu.current_iteration simu.start = 0.0 - simu.timeStep = 0.005 + simu.time_step = 0.005 simu.initialize() -# simu.currentIteration = ite +# simu.current_iteration = ite print 'simu', simu print ("load ...", filename) return simu @@ -485,7 +485,7 @@ while not simu.isOver: simu.printState() run(seq) simu.advance() - testdump = simu.currentIteration % dumpFreq is 0 + testdump = simu.current_iteration % dumpFreq is 0 if doDump and testdump: print 'dump ...' dump(dump_filename) diff --git a/examples/FlowAroundSphere_pressure.py b/examples/FlowAroundSphere_pressure.py index 31b3dc801..4bc967849 100644 --- a/examples/FlowAroundSphere_pressure.py +++ b/examples/FlowAroundSphere_pressure.py @@ -118,7 +118,7 @@ pressure = Field(domain=box, formula=computePressure, name='Pressure') # ========= Simulation setup ========= -simu = Simulation(tinit=0.0, tend=80.0, timeStep=0.0125, iterMax=10000000) +simu = Simulation(start=0.0, end=80.0, time_step=0.0125, max_iter=10000000) # Adaptative timestep method : dt = min(values(dtCrit)) @@ -387,10 +387,10 @@ def run(sequence): # filedump = filename + '_rk_' + str(main_rank) # db = parmesPickle(filedump, mode='load') # simu = db.load('simulation')[0] -# simu.start = simu.time - simu.timeStep -# ite = simu.currentIteration +# simu.start = simu.time - simu.time_step +# ite = simu.current_iteration # simu.initialize() -# simu.currentIteration = ite +# simu.current_iteration = ite # print 'simu', simu # print ("load ...", filename) # velo.load(filename) @@ -421,7 +421,7 @@ while not simu.isOver: simu.printState() run(seq) simu.advance() -# # testdump = simu.currentIteration % dumpFreq is 0 +# # testdump = simu.current_iteration % dumpFreq is 0 # # if doDump and testdump: # # dump(dump_filename) print '[', main_rank, '] total time for run :', MPI.Wtime() - time_run diff --git a/examples/LevelSet2D/levelSet2D.py b/examples/LevelSet2D/levelSet2D.py index e9323589b..12ca3ecdb 100644 --- a/examples/LevelSet2D/levelSet2D.py +++ b/examples/LevelSet2D/levelSet2D.py @@ -47,11 +47,11 @@ nbElem_s = [1025] * dim dv = Discretization(nbElem_v) ds = Discretization(nbElem_s) -timeStep = 0.35 / (2. * np.pi) -finalTime = 12. - timeStep +time_step = 0.35 / (2. * np.pi) +finalTime = 12. - time_step outputModulo = 20 -simu = hysop.Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=100000) +simu = hysop.Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=100000) # Domain box = hysop.Box(length=boxLength, origin=boxMin) diff --git a/examples/LevelSet3D/levelSet3D.py b/examples/LevelSet3D/levelSet3D.py index 214289833..2ee37c145 100644 --- a/examples/LevelSet3D/levelSet3D.py +++ b/examples/LevelSet3D/levelSet3D.py @@ -53,11 +53,11 @@ else: dv = Discretization(nbElem_v, ghosts=[1, ] * dim) ds = Discretization(nbElem_s) -timeStep = 0.35 / (4. * np.pi) +time_step = 0.35 / (4. * np.pi) finalTime = 3. outputModulo = 10 -simu = Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=120) +simu = Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=120) # Domain box = hysop.Box(length=boxLength, origin=boxMin) @@ -80,7 +80,7 @@ else: # compute communication buffers advec_method[ExtraArgs] = {'user_src': ['./levelSet3D.cl'], 'device_id': main_rank % 2, - 'max_dt': simu.timeStep, + 'max_dt': simu.time_step, 'max_velocity': [2, 1, 1]} advec = Advection(velo, diff --git a/examples/LevelSet3D/levelSet3D_Scales.py b/examples/LevelSet3D/levelSet3D_Scales.py index 1d92c3841..251b45a43 100644 --- a/examples/LevelSet3D/levelSet3D_Scales.py +++ b/examples/LevelSet3D/levelSet3D_Scales.py @@ -42,11 +42,11 @@ nbElem_s = [65] * dim dv = Discretization(nbElem_v) ds = Discretization(nbElem_s) -timeStep = 0.35 / (4. * np.pi) +time_step = 0.35 / (4. * np.pi) finalTime = 3. outputModulo = 10 -simu = Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=120) +simu = Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=120) # Domain box = hysop.Box(length=boxLength, origin=boxMin) diff --git a/examples/LevelSet3D/levelSet3D_Scales_MultiScale.py b/examples/LevelSet3D/levelSet3D_Scales_MultiScale.py index 637430464..b50c7baed 100644 --- a/examples/LevelSet3D/levelSet3D_Scales_MultiScale.py +++ b/examples/LevelSet3D/levelSet3D_Scales_MultiScale.py @@ -42,11 +42,11 @@ nbElem_s = [129] * dim dv = Discretization(nbElem_v) ds = Discretization(nbElem_s) -timeStep = 0.35 / (4. * np.pi) +time_step = 0.35 / (4. * np.pi) finalTime = 3. outputModulo = 10 -simu = Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=120) +simu = Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=120) # Domain box = hysop.Box(length=boxLength, origin=boxMin) diff --git a/examples/LevelSet3D/levelSet3D_gpu.py b/examples/LevelSet3D/levelSet3D_gpu.py index ff0d9ff50..b12d157da 100755 --- a/examples/LevelSet3D/levelSet3D_gpu.py +++ b/examples/LevelSet3D/levelSet3D_gpu.py @@ -49,11 +49,11 @@ nbElem_s = [129] * dim dv = Discretization(nbElem_v) ds = Discretization(nbElem_s) -timeStep = 0.35 / (4. * np.pi) +time_step = 0.35 / (4. * np.pi) finalTime = 3. outputModulo = 10 -simu = Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=120) +simu = Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=120) # Domain box = hysop.Box(length=boxLength, origin=boxMin) @@ -73,7 +73,7 @@ if main_size > 1: # Multi-GPU advection must know a max dt and velocity to # compute communication buffers advec_method[ExtraArgs] = {'device_id': main_rank % 2, - 'max_dt': simu.timeStep, + 'max_dt': simu.time_step, 'max_velocity': [2, 1, 1]} advec = Advection(velo, diff --git a/examples/LevelSet3D/levelSet3D_gpu_MultiScale.py b/examples/LevelSet3D/levelSet3D_gpu_MultiScale.py index cacac2ac3..2bfef8a41 100644 --- a/examples/LevelSet3D/levelSet3D_gpu_MultiScale.py +++ b/examples/LevelSet3D/levelSet3D_gpu_MultiScale.py @@ -50,11 +50,11 @@ nbElem_s = [129] * dim dv = Discretization(nbElem_v, ghosts=[1, ] * dim) ds = Discretization(nbElem_s) -timeStep = 0.35 / (4. * np.pi) +time_step = 0.35 / (4. * np.pi) finalTime = 3. outputModulo = 10 -simu = Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=120) +simu = Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=120) # Domain box = hysop.Box(length=boxLength, origin=boxMin) @@ -74,7 +74,7 @@ if main_size > 1: # Multi-GPU advection must know a max dt and velocity to # compute communication buffers advec_method[ExtraArgs] = {'device_id': main_rank % 2, - 'max_dt': simu.timeStep, + 'max_dt': simu.time_step, 'max_velocity': [2, 1, 1]} advec = Advection(velo, diff --git a/examples/LevelSet3D/levelSet3D_only_gpu.py b/examples/LevelSet3D/levelSet3D_only_gpu.py index 5dc258c2d..5a87c8e07 100644 --- a/examples/LevelSet3D/levelSet3D_only_gpu.py +++ b/examples/LevelSet3D/levelSet3D_only_gpu.py @@ -35,11 +35,11 @@ nbElem_s = [129] * dim dv = Discretization(nbElem_v) ds = Discretization(nbElem_s) -timeStep = 0.35 / (4. * np.pi) +time_step = 0.35 / (4. * np.pi) finalTime = 3. outputModulo = 10 -simu = Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=120) +simu = Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=120) # Domain box = hysop.Box(length=boxLength, origin=boxMin) @@ -61,7 +61,7 @@ else: # compute communication buffers advec_method[ExtraArgs] = {'user_src': ['./levelSet3D.cl'], 'device_id': main_rank % 2, - 'max_dt': simu.timeStep, + 'max_dt': simu.time_step, 'max_velocity': [2, 1, 1], 'velocity_only_on_device': True} diff --git a/examples/LevelSet3D/levelSet3D_only_gpu_MultiScale.py b/examples/LevelSet3D/levelSet3D_only_gpu_MultiScale.py index 4970ca107..5a689da0c 100644 --- a/examples/LevelSet3D/levelSet3D_only_gpu_MultiScale.py +++ b/examples/LevelSet3D/levelSet3D_only_gpu_MultiScale.py @@ -36,11 +36,11 @@ nbElem_s = [129] * dim dv = Discretization(nbElem_v, ghosts=[1, ] * dim) ds = Discretization(nbElem_s) -timeStep = 0.35 / (4. * np.pi) +time_step = 0.35 / (4. * np.pi) finalTime = 3. outputModulo = 10 -simu = Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=120) +simu = Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=120) # Domain box = hysop.Box(length=boxLength, origin=boxMin) @@ -63,7 +63,7 @@ else: # compute communication buffers advec_method[ExtraArgs] = {'user_src': ['./levelSet3D.cl'], 'device_id': main_rank % 2, - 'max_dt': simu.timeStep, + 'max_dt': simu.time_step, 'max_velocity': [2, 1, 1], 'velocity_only_on_device': True} diff --git a/examples/LevelSet3D/levelSet3D_python.py b/examples/LevelSet3D/levelSet3D_python.py index 9c19ac27a..fc845ee45 100644 --- a/examples/LevelSet3D/levelSet3D_python.py +++ b/examples/LevelSet3D/levelSet3D_python.py @@ -53,11 +53,11 @@ else: dv = Discretization(nbElem_v, ghosts=[1, ] * dim) ds = Discretization(nbElem_s) -timeStep = 0.35 / (4. * np.pi) +time_step = 0.35 / (4. * np.pi) finalTime = 3. outputModulo = 10 -simu = Simulation(tinit=0.0, tend=finalTime, - timeStep=timeStep, iterMax=120) +simu = Simulation(start=0.0, end=finalTime, + time_step=time_step, max_iter=120) # Domain box = hysop.Box(length=boxLength, origin=boxMin) @@ -89,7 +89,7 @@ advec = Advection(velo, # method=advec_method, # user_src=['./levelSet3D.cl'], # device_id=main_rank % 2, - # max_dt=simu.timeStep, + # max_dt=simu.time_step, # max_velocity=[2, 1, 1]) advec.discretize() diff --git a/examples/Multiphase/NS_planeJet_hybrid_MS_MP.py b/examples/Multiphase/NS_planeJet_hybrid_MS_MP.py index 912aa6cf9..0529eebf6 100644 --- a/examples/Multiphase/NS_planeJet_hybrid_MS_MP.py +++ b/examples/Multiphase/NS_planeJet_hybrid_MS_MP.py @@ -160,7 +160,7 @@ baroclinic_rhs = hysop.Field(domain=box, data = {'dt': 0.01} dt = VariableParameter(data) -simu = Simulation(tinit=0.0, tend=5., timeStep=0.01, iterMax=1000) +simu = Simulation(start=0.0, end=5., time_step=0.01, max_iter=1000) # Flow discretizations: d_F_0g = Discretization(USER_NB_ELEM_UW) @@ -556,7 +556,7 @@ while not simu.isOver: simu.advance() main_comm.Barrier() -nb_ite = simu.currentIteration +nb_ite = simu.current_iteration total_time += MPI.Wtime() - cttime simu.finalize() diff --git a/examples/Multiphase/RTI.py b/examples/Multiphase/RTI.py index 9df0bb972..4534e86e6 100644 --- a/examples/Multiphase/RTI.py +++ b/examples/Multiphase/RTI.py @@ -157,7 +157,7 @@ baroclinic_rhs = hysop.Field(domain=box, data = {'dt': 0.001} dt = VariableParameter(data) -simu = Simulation(tinit=0.0, tend=2.5, timeStep=0.001, iterMax=10000) +simu = Simulation(start=0.0, end=2.5, time_step=0.001, max_iter=10000) # Flow discretizations: d_C = Discretization(USER_NB_ELEM_UW) @@ -515,7 +515,7 @@ while not simu.isOver: U_CPU_to_GPU.wait() main_comm.Barrier() -nb_ite = simu.currentIteration +nb_ite = simu.current_iteration simu.finalize() diff --git a/examples/NSDebug_faux2D.py b/examples/NSDebug_faux2D.py index 16902a658..d69c4a7a9 100755 --- a/examples/NSDebug_faux2D.py +++ b/examples/NSDebug_faux2D.py @@ -284,8 +284,8 @@ for monit in monitors.values(): allops = dict(op.items() + distr.items() + monitors.items()) # ========= Simulation setup ========= -simu = Simulation(tinit=0.0, tend=100., timeStep=0.0125, iterMax=1000000) -#simu = Simulation(tinit=0.0, tend=75., timeStep=dt['dt'], iterMax=6) +simu = Simulation(start=0.0, end=100., time_step=0.0125, max_iter=1000000) +#simu = Simulation(start=0.0, end=75., time_step=dt['dt'], max_iter=6) ind = sphere.discretize(topofft) vdfft = velo.discreteFields[topofft].data diff --git a/examples/NS_Richtmyer_Meshkov.py b/examples/NS_Richtmyer_Meshkov.py index bf7c92422..e6fa38c76 100755 --- a/examples/NS_Richtmyer_Meshkov.py +++ b/examples/NS_Richtmyer_Meshkov.py @@ -269,9 +269,9 @@ distrDiffBaro = Redistribute([vorti], diffusion, baroclinic) distrBaroPoiss = Redistribute([vorti], baroclinic, poisson) ## Simulation -simu = Simulation(tinit=0.0, - tend=250., timeStep=0.005, - iterMax=1000000) +simu = Simulation(start=0.0, + end=250., time_step=0.005, + max_iter=1000000) # Define the problem to solve pb = NSProblem(operators=[distrPoiStr_velo, diff --git a/examples/NS_bluff_bodies.py b/examples/NS_bluff_bodies.py index 1a3459f1c..9b74f4cfe 100755 --- a/examples/NS_bluff_bodies.py +++ b/examples/NS_bluff_bodies.py @@ -177,9 +177,9 @@ distrPoissCurl = Redistribute([vorti, velo], poisson, curl) distrCurlAdv = Redistribute([vorti, velo], curl, advec) ## Simulation with fixed time step -simu = Simulation(tinit=0.0, - tend=10., timeStep=0.005, - iterMax=1000000) +simu = Simulation(start=0.0, + end=10., time_step=0.005, + max_iter=1000000) ## Define the problem to solve diff --git a/examples/PassiveControl_Hemisphere.py b/examples/PassiveControl_Hemisphere.py index 8ab1dd167..1480dfa4c 100644 --- a/examples/PassiveControl_Hemisphere.py +++ b/examples/PassiveControl_Hemisphere.py @@ -113,7 +113,7 @@ vorti = Field(domain=box, formula=computeVort, # ========= Simulation setup ========= -simu = Simulation(tinit=0.0, tend=80.0, timeStep=0.0125, iterMax=10000000) +simu = Simulation(start=0.0, end=80.0, time_step=0.0125, max_iter=10000000) # Adaptative timestep method : dt = min(values(dtCrit)) @@ -360,10 +360,10 @@ def run(sequence): # filedump = filename + '_rk_' + str(main_rank) # db = parmesPickle(filedump, mode='load') # simu = db.load('simulation')[0] -# simu.start = simu.time - simu.timeStep -# ite = simu.currentIteration +# simu.start = simu.time - simu.time_step +# ite = simu.current_iteration # simu.initialize() -# simu.currentIteration = ite +# simu.current_iteration = ite # print 'simu', simu # print ("load ...", filename) # velo.load(filename) @@ -394,7 +394,7 @@ while not simu.isOver: simu.printState() run(seq) simu.advance() -# # testdump = simu.currentIteration % dumpFreq is 0 +# # testdump = simu.current_iteration % dumpFreq is 0 # # if doDump and testdump: # # dump(dump_filename) print '[', main_rank, '] total time for run :', MPI.Wtime() - time_run diff --git a/examples/Plane_jet/NS_planeJet_hybrid_MS.py b/examples/Plane_jet/NS_planeJet_hybrid_MS.py index c8954d628..bee1729fe 100644 --- a/examples/Plane_jet/NS_planeJet_hybrid_MS.py +++ b/examples/Plane_jet/NS_planeJet_hybrid_MS.py @@ -139,7 +139,7 @@ scal = hysop.Field(domain=box, formula=initScal, data = {'dt': 0.001} dt = VariableParameter(data) -simu = Simulation(tinit=0.0, tend=5., timeStep=0.001, iterMax=10000) +simu = Simulation(start=0.0, end=5., time_step=0.001, max_iter=10000) # Flow discretizations: d_uw = Discretization(USER_NB_ELEM_UW) @@ -437,7 +437,7 @@ while not simu.isOver: simu.advance() main_comm.Barrier() -nb_ite = simu.currentIteration +nb_ite = simu.current_iteration simu.finalize() diff --git a/examples/RMI/RMI_hybrid.py b/examples/RMI/RMI_hybrid.py index 887ca9459..7f2076058 100644 --- a/examples/RMI/RMI_hybrid.py +++ b/examples/RMI/RMI_hybrid.py @@ -164,7 +164,7 @@ rho = hysop.Field(domain=box, formula=initRho, data = {'dt': 0.001} dt = VariableParameter(data) -simu = Simulation(tinit=0.0, tend=100., timeStep=0.001, iterMax=1000000) +simu = Simulation(start=0.0, end=100., time_step=0.001, max_iter=1000000) # Flow discretizations: d_uw = Discretization(USER_NB_ELEM_UW) @@ -463,7 +463,7 @@ while not simu.isOver: simu.advance() main_comm.Barrier() -nb_ite = simu.currentIteration +nb_ite = simu.current_iteration simu.finalize() diff --git a/examples/TaylorGreen/TaylorGreen3D.py b/examples/TaylorGreen/TaylorGreen3D.py index 89688d793..93684a350 100755 --- a/examples/TaylorGreen/TaylorGreen3D.py +++ b/examples/TaylorGreen/TaylorGreen3D.py @@ -156,10 +156,10 @@ distrStrDiff = Redistribute([vorti], stretch, diffusion) distrPoissTimeStep = Redistribute([velo, vorti], poisson, dtAdapt) ## Simulation -simu = Simulation(tinit=0.0, - tend=10.0, - timeStep=dt_adapt['dt'], - iterMax=1000000) +simu = Simulation(start=0.0, + end=10.0, + time_step=dt_adapt['dt'], + max_iter=1000000) # Define the problem to solve ## With adaptative time step @@ -227,8 +227,8 @@ def run(): # simu.initialize() # while not simu.isOver: # distrPoiStr_velo.apply(simu) -# subSimu = Simulation(tinit=simu.tk, tend=10., timeStep=simu.timeStep/2.0, -# iterMax=2) +# subSimu = Simulation(start=simu.tk, end=10., time_step=simu.time_step/2.0, +# max_iter=2) # subSimu.initialize() # print '==============' # simu.printState() diff --git a/examples/TaylorGreen/TaylorGreen3D_GPU.py b/examples/TaylorGreen/TaylorGreen3D_GPU.py index 997ad5f8a..d10a69eb5 100644 --- a/examples/TaylorGreen/TaylorGreen3D_GPU.py +++ b/examples/TaylorGreen/TaylorGreen3D_GPU.py @@ -186,9 +186,9 @@ velo_diff_advec_Z = Redistribute([velo], poisson, advec.advecDir[2], distrPoissTimeStep = Redistribute([velo, vorti], poisson, dtAdapt) ## Simulation -simu = Simulation(tinit=0.0, - tend=10., timeStep=dt_adapt, - iterMax=1000000) +simu = Simulation(start=0.0, + end=10., time_step=dt_adapt, + max_iter=1000000) ## Define the problem to solve pb = NSProblem(operators=[velo_poisson_stretch, advec, diff --git a/examples/TaylorGreen/TaylorGreen3D_debug.py b/examples/TaylorGreen/TaylorGreen3D_debug.py index 203a4a12f..70152cb8e 100644 --- a/examples/TaylorGreen/TaylorGreen3D_debug.py +++ b/examples/TaylorGreen/TaylorGreen3D_debug.py @@ -70,7 +70,7 @@ vorti = Field(domain=box, formula=computeVort, # ========= Simulation setup ========= -simu = Simulation(tinit=0.0, tend=10.0, timeStep=0.0125, iterMax=10000000) +simu = Simulation(start=0.0, end=10.0, time_step=0.0125, max_iter=10000000) # Adaptative timestep method : dt = min(values(dtCrit)) # where dtCrit is a list of criterions on which the computation @@ -230,10 +230,10 @@ def run(sequence): # filedump = filename + '_rk_' + str(main_rank) # db = parmesPickle(filedump, mode='load') # simu = db.load('simulation')[0] -# simu.start = simu.time - simu.timeStep -# ite = simu.currentIteration +# simu.start = simu.time - simu.time_step +# ite = simu.current_iteration # simu.initialize() -# simu.currentIteration = ite +# simu.current_iteration = ite # print 'simu', simu # print ("load ...", filename) # velo.load(filename) @@ -264,7 +264,7 @@ while not simu.isOver: simu.printState() run(seq) simu.advance() -# # testdump = simu.currentIteration % dumpFreq is 0 +# # testdump = simu.current_iteration % dumpFreq is 0 # # if doDump and testdump: # # dump(dump_filename) print '[', main_rank, '] total time for run :', MPI.Wtime() - time_run diff --git a/examples/TaylorGreen/TaylorGreen3D_debug_filter.py b/examples/TaylorGreen/TaylorGreen3D_debug_filter.py index bac8348fa..723db975e 100644 --- a/examples/TaylorGreen/TaylorGreen3D_debug_filter.py +++ b/examples/TaylorGreen/TaylorGreen3D_debug_filter.py @@ -80,7 +80,7 @@ vortiFiltered = Field(domain=box, formula=computeVortFilt, # ========= Simulation setup ========= -simu = Simulation(tinit=0.0, tend=10.0, timeStep=0.0125, iterMax=10000000) +simu = Simulation(start=0.0, end=10.0, time_step=0.0125, max_iter=10000000) # Adaptative timestep method : dt = min(values(dtCrit)) # where dtCrit is a list of criterions on which the computation @@ -251,10 +251,10 @@ def run(sequence): # filedump = filename + '_rk_' + str(main_rank) # db = parmesPickle(filedump, mode='load') # simu = db.load('simulation')[0] -# simu.start = simu.time - simu.timeStep -# ite = simu.currentIteration +# simu.start = simu.time - simu.time_step +# ite = simu.current_iteration # simu.initialize() -# simu.currentIteration = ite +# simu.current_iteration = ite # print 'simu', simu # print ("load ...", filename) # velo.load(filename) @@ -285,7 +285,7 @@ while not simu.isOver: simu.printState() run(seq) simu.advance() -# # testdump = simu.currentIteration % dumpFreq is 0 +# # testdump = simu.current_iteration % dumpFreq is 0 # # if doDump and testdump: # # dump(dump_filename) print '[', main_rank, '] total time for run :', MPI.Wtime() - time_run diff --git a/examples/demo_2D_real-time.py b/examples/demo_2D_real-time.py index f50c52435..504fa2177 100755 --- a/examples/demo_2D_real-time.py +++ b/examples/demo_2D_real-time.py @@ -49,9 +49,9 @@ boxLength = [1., 1.] boxMin = [0., 0.] nbElem = [513, 513] -timeStep = 0.075 -finalTime = 3.0 + timeStep -simu = Simulation(tinit=0.0, tend=finalTime, timeStep=timeStep) +time_step = 0.075 +finalTime = 3.0 + time_step +simu = Simulation(start=0.0, end=finalTime, time_step=time_step) ## Domain box = Box(dim, length=boxLength, origin=boxMin) diff --git a/examples/demo_hybrid.py b/examples/demo_hybrid.py index e68787d2c..004ecbea9 100644 --- a/examples/demo_hybrid.py +++ b/examples/demo_hybrid.py @@ -58,7 +58,7 @@ p = Printer(variables=[field], red = RedistributeIntercomm(field, topo, op, p, proc_tasks, main_comm, component=None) -simu = Simulation(tinit=0.0, tend=3., timeStep=0.15, iterMax=200) +simu = Simulation(start=0.0, end=3., time_step=0.15, max_iter=200) pb = ProblemTasks([op, red, p], simu, proc_tasks) diff --git a/examples/howto_integrators.py b/examples/howto_integrators.py index 73a53ba8f..b082f18e6 100644 --- a/examples/howto_integrators.py +++ b/examples/howto_integrators.py @@ -22,13 +22,13 @@ from parmepy.mpi.topology import Cartesian # Grid resolution for tests nb = 5 # Initial time -tinit = 0. +start = 0. # Final time -tend = 0.5 +end = 0.5 # Time step #dt = 1e-3 # time sequence -#time = npu.seq(tinit, tend, dt) +#time = npu.seq(start, end, dt) #nbSteps = time.size import math as m import parmepy as pp @@ -425,7 +425,7 @@ def odespy1D(solver, nbSteps): """ Integration with odespy """ - time_points = np.linspace(tinit, tend, nbSteps) + time_points = np.linspace(start, end, nbSteps) dtt = time_points[1] - time_points[0] u, t = solver.solve(time_points) err = 0 @@ -437,7 +437,7 @@ def odespy2D(solver, nbSteps): """ Integration with odespy for solver.neq > 1 """ - time_points = np.linspace(tinit, tend, nbSteps) + time_points = np.linspace(start, end, nbSteps) dtt = time_points[1] - time_points[0] u, t = solver.solve(time_points) neq = solver.neq @@ -453,10 +453,10 @@ def integrate(integ, nbSteps): """ Integration with parmepy """ - t = tinit - time_points = np.linspace(tinit, tend, nbSteps) + t = start + time_points = np.linspace(start, end, nbSteps) dtt = time_points[1] - time_points[0] - y = [npw.ones(nb) * math.exp(-tinit)] + y = [npw.ones(nb) * math.exp(-start)] #res = [npw.zeros(nb)] # work = None i = 1 @@ -498,22 +498,22 @@ def test_1D_0(): # Euler dtE[i], errE[i] = integrate(Euler(1, func1D), nbSteps) solver = ode.Euler(funcODESPY) - solver.set_initial_condition([math.exp(-tinit)]) + solver.set_initial_condition([math.exp(-start)]) dtodespy[i], errodespy[i] = odespy1D(solver, nbSteps) # RK2 dt2[i], err2[i] = integrate(RK2(1, func1D), nbSteps) solver = ode.RK2(funcODESPY) - solver.set_initial_condition([math.exp(-tinit)]) + solver.set_initial_condition([math.exp(-start)]) dt2odespy[i], err2odespy[i] = odespy1D(solver, nbSteps) # RK3 dt3[i], err3[i] = integrate(RK3(1, func1D), nbSteps) solver = ode.RK3(funcODESPY) - solver.set_initial_condition([math.exp(-tinit)]) + solver.set_initial_condition([math.exp(-start)]) dt3odespy[i], err3odespy[i] = odespy1D(solver, nbSteps) # RK4 dt4[i], err4[i] = integrate(RK4(1, func1D), nbSteps) solver = ode.RK4(funcODESPY) - solver.set_initial_condition([math.exp(-tinit)]) + solver.set_initial_condition([math.exp(-start)]) dt4odespy[i], err4odespy[i] = odespy1D(solver, nbSteps) nbSteps += 10 @@ -570,8 +570,8 @@ def integrate2D(integ, nbSteps): """ Integration with parmepy """ - t = tinit - time_points = np.linspace(tinit, tend, nbSteps) + t = start + time_points = np.linspace(start, end, nbSteps) dtt = time_points[1] - time_points[0] y = [npw.ones((nb, nb)), npw.zeros((nb, nb))] # res = [npw.zeros((nb, nb)), npw.zeros((nb, nb))] diff --git a/examples/mainJM.py b/examples/mainJM.py index 0e08df232..0c9c48522 100755 --- a/examples/mainJM.py +++ b/examples/mainJM.py @@ -26,7 +26,7 @@ def run(): # Parameters nb = 65 nbElem = (nb, nb, nb) - timeStep = 0.02 + time_step = 0.02 finalTime = 1. outputFilePrefix = './res/RK2_' outputModulo = 0 @@ -62,7 +62,7 @@ def run(): pb = TransportProblem([advec]) ## Setting solver to Problem - pb.setUp(finalTime, timeStep) + pb.setUp(finalTime, time_step) t1 = time.time() ## Solve problem diff --git a/examples/testDiffusion.py b/examples/testDiffusion.py index b3e5e316f..5e485e004 100755 --- a/examples/testDiffusion.py +++ b/examples/testDiffusion.py @@ -75,7 +75,7 @@ monitor = Energy_enstrophy(velocity, vorticity, ## Definition of simulation parameters tini = restartTime niter = (finalTime - tini) / dt -simu = Simulation(tinit=tini, tend=finalTime, nbiter=niter) +simu = Simulation(start=tini, end=finalTime, nbiter=niter) diffusion.setUp() poisson.setUp() @@ -88,8 +88,8 @@ velocity.load('dump_velo_T=_0.5') vorticity.load('dump_vort_T=_0.5') while simu.time <= finalTime: - print 'time, niter : ', simu.time, simu.currentIteration -# if (simu.currentIteration == 50): + print 'time, niter : ', simu.time, simu.current_iteration +# if (simu.current_iteration == 50): # print 'dump fields ...' # velocity.dump(filenameVel) # vorticity.dump(filenameVort) @@ -97,8 +97,8 @@ while simu.time <= finalTime: diffusion.apply(simu) poisson.apply(simu) monitor.apply(simu) - simu.time += simu.timeStep - simu.currentIteration += 1 + simu.time += simu.time_step + simu.current_iteration += 1 print "post ", vorticity.norm() diff --git a/examples/testPoisson.py b/examples/testPoisson.py index 7614da9e9..4dc58b34b 100755 --- a/examples/testPoisson.py +++ b/examples/testPoisson.py @@ -66,9 +66,9 @@ ref = pp.Field(domain=dom, name='reference', is_vector=True) refOp = Analytic(ref, formula=computeRef, resolutions={ref: resol}) -timeStep = 0.25 +time_step = 0.25 simu = Simulation() -#simu.iterMax = simu.iterMax - 2 +#simu.max_iter = simu.max_iter - 2 refOp.discretize() poisson.discretize() refOp.setUp() diff --git a/examples/testScales.py b/examples/testScales.py index 0c1f953bf..34b47da96 100755 --- a/examples/testScales.py +++ b/examples/testScales.py @@ -69,7 +69,7 @@ for k in range(localres[2]): goodScal = scal3D.copy() goodVelo = vx.copy() -timeStep = 0.01 +time_step = 0.01 finalTime = 2. * period currentTime = 0.0 @@ -82,11 +82,11 @@ if(rank == 0): # Simulation t0 = MPI.Wtime() -scal3D = scales.solve_advection(timeStep, vx, vy, vz, scal3D) +scal3D = scales.solve_advection(time_step, vx, vy, vz, scal3D) print "elapsed time on processus ", rank, ": ", MPI.Wtime() - t0 -currentTime += timeStep +currentTime += time_step diff --git a/examples/testVisu.py b/examples/testVisu.py index a7b10a5e1..579efe813 100755 --- a/examples/testVisu.py +++ b/examples/testVisu.py @@ -60,7 +60,7 @@ op = Analytic(scal3D, resolutions={scal3D: resolution3D}, topo=topo) op.discretize() op.setUp() -simu = Simulation(tinit=0.0, tend=2., nbIter=100, iterMax=1000000) +simu = Simulation(start=0.0, end=2., nbIter=100, max_iter=1000000) op.apply(simu) sc3D = scal3D.discretization(topo) diff --git a/hysop/fields/tests/test_field.py b/hysop/fields/tests/test_field.py index 31c62dd14..dc119c8ca 100755 --- a/hysop/fields/tests/test_field.py +++ b/hysop/fields/tests/test_field.py @@ -379,7 +379,7 @@ def hdf_dump_load(discretisation, formula): fname = 'f1_' + str(dimension) ff = Field(box, name=fname, is_vector=True, formula=formula) iop = IOParams(ff.name) - simu = Simulation(nbIter=4) + simu = Simulation(nb_iter=4) simu.initialize() ff.initialize(time=simu.time, topo=topo) ff.hdf_dump(topo, simu) diff --git a/hysop/fields/tests/test_variable.py b/hysop/fields/tests/test_variable.py index 40e66eafd..8068ecd51 100755 --- a/hysop/fields/tests/test_variable.py +++ b/hysop/fields/tests/test_variable.py @@ -1,6 +1,6 @@ +"""Test simulation dependent parameters. """ -Testing hysop.field.variable_parameter.Variable_parameter -""" + from hysop.fields.variable_parameter import VariableParameter from hysop.problem.simulation import Simulation from math import sin, cos @@ -9,41 +9,28 @@ import numpy as np def test_constant_var(): uinf = 1. - var = VariableParameter(data=uinf, name='uinf') - assert var['uinf'] == 1. - var['uinf'] *= 3 - assert var['uinf'] == 3. - - v2 = VariableParameter({'uinf': uinf}) - assert v2['uinf'] == 1. - - -def func(simu): - time = simu.tk + var = VariableParameter(data=uinf) + var.data *= 3 + assert var.data == 3. + simu = Simulation(nb_iter=5) + simu.initialize() + while not simu.is_over: + var.update(simu) + assert var.data == 3. + simu.advance() + + +def func(s): + time = s.time return np.asarray((sin(time), cos(time))) def test_time_var(): var = VariableParameter(formula=func) - simu = Simulation(tinit=0., tend=1., timeStep=0.1) - var.update(simu) - assert np.allclose(var['func'], [0., 1.]) - assert var.name == 'func' - simu.advance() - var.update(simu) - assert np.allclose(var['func'], [sin(0.1), cos(0.1)]) - var = VariableParameter(formula=func, name='nn') - assert var.name == 'nn' - assert var.formula is not None - - -def test_time_var2(): - var = VariableParameter(formula=func, name='toto', data={'alpha': 1.}) - simu = Simulation(tinit=0., tend=1., timeStep=0.1) - assert var.name == 'alpha' - assert np.allclose(var['alpha'], [1.]) - var.update(simu) - assert np.allclose(var['alpha'], [sin(0.), cos(0.)]) - simu.advance() - var.update(simu) - assert np.allclose(var['alpha'], [sin(0.1), cos(0.1)]) + simu = Simulation(start=0., end=1., time_step=0.1) + simu.initialize() + while not simu.is_over: + var.update(simu) + assert np.allclose(var.data, [sin(simu.time), cos(simu.time)]) + simu.advance() + diff --git a/hysop/fields/variable_parameter.py b/hysop/fields/variable_parameter.py index 2d17a2803..d4f1b788c 100644 --- a/hysop/fields/variable_parameter.py +++ b/hysop/fields/variable_parameter.py @@ -1,120 +1,63 @@ -# -# Definition of the adaptative time step (for example) on the 3D domain: -# \code -# dt_adapt = Variable(dom3D, name="adaptative_timestep, data=[0.1]") -# ... -# \endcode -# -# -""" -@file variable_parameter.py - -Tools to define parameters that do not depend on space but may -be used as input-output parameter during simulation. - -Example : the time step. - -\code -data = {'timestep': 0.1 } -dt = VariableParameter(data) - -## An operator that can change dt -op = Adaptative_timestep(..., dt) -simu = Simulation(..., dt, ...) - -op.apply(simu) ===> change simu.time_step - -\endcode - -A python function may be set to compute the parameter. -Example : if you want to define a time-dependent parameter -alpha, such that alpha = [sin(t), cos(t)], do : +"""Tools to define parameters that do not depend on space but may +depend on simulation parameters. -\code -def myfunc(simu): - return sin(simu.time), cos(simu.time) +Example : the flow rate through the inlet +.. code:: -alpha = VariableParameter(formula=myfunc, name='alpha') + def frate(simu): + res = np.zeros(problem.dimension) + res[...] = np.sin(simu.time) + return res -simu = Simulation(tstart = 0., tend=1., timeStep=0.1) + # define the parameter ... + rate = VariableParameter(formula=frate) + ... + # compute its value for the current simulation state + rate.update(simu) -print alpha -# --> return {'alpha': None} +Notes +----- -alpha.update(simu) -print alpha -# --> return {'alpha': (0., 1.)} - -simu.advance() -alpha.update(simu) -print alpha -# --> return {'alpha': (0.19866933079506122, 0.9800665778412416)} +* frate must be a python function with a simulation object as input. +* update function is usually called during operator apply + (for instance adaptive time step or absorption_BC). """ class VariableParameter(object): - """ - Class to embed a user-defined parameter (a dictionnary indeed). + """User-defined parameter (a dictionnary indeed) + that may depend on simulation parameters values and so + needs some update during simulation process. - VariableParameter has a member data which is mutable. """ - def __init__(self, data=None, name=None, formula=None): + def __init__(self, data=0., formula=None): """ - Creates a dictionnary with data - @param data: the data used as parameter - @param name : optional name, used if data is not a dict. - - If data is a dictionnary, self.data = data, that's it. - Else data will be added into self.data dict, with name as a key. + Parameters + ---------- + data: real or integer, optional + default or initial value of the parameter + formula : python function, optional + how to compute the variable """ - ## name of the variable - self.name = name - if self.name is None and formula is not None: - self.name = formula.__name__ - ## Formula used to compute data (a python function) + self.data = data + # Formula used to compute data (a python function) + if formula is None: + formula = lambda simu: self.data self.formula = formula - if self.formula is None: - self.formula = self._constant - ## data values - if isinstance(data, dict): - msg = 'A dictionnary is used to initialize the variable.' - msg += 'Name parameter will be ignored.' - print (msg) - self.data = data - self.name = data.keys()[0] - else: - if self.name is None: - msg = "Name arg is required when data is not a dict." - raise AttributeError(msg) - self.data = {self.name: data} - - def _constant(self, simu=None): - return self.data[self.name] def update(self, simu=None): - """ - Apply formula to compute data for - a given simulation (current time ...) - @param simu : a hysop.problem.simulation.Simulation - """ - self.data[self.name] = self.formula(simu) + """Update parameter value for the current simulation - def __getitem__(self, key): - """ Access to the content of the data[key] - @param key : requested key. - @return component 'key' of the dict - """ - return self.data[key] + Parameter + --------- + simu : `:class::~hysop.problem.simulation.Simulation` - def __setitem__(self, key, value): - """ - Set the data[key] = value """ - self.data[key] = value + self.data = self.formula(simu) def __str__(self): return str(self.data) diff --git a/hysop/gpu/QtRendering.py b/hysop/gpu/QtRendering.py index 1791a48b9..305d42d2b 100644 --- a/hysop/gpu/QtRendering.py +++ b/hysop/gpu/QtRendering.py @@ -162,14 +162,14 @@ class QtOpenGLRendering(Computational): Update the color GLBuffer and redraw the QGLWidget. """ t = simulation.time - dt = simulation.timeStep + dt = simulation.time_step if main_rank == 0: - simulation.printState() + simulation.print_state() # OpenCL update self.numMethod(self.gpu_field.gpu_data[self.component], self.color) self.window.widget.updateGL() - if simulation.currentIteration > 1: + if simulation.current_iteration > 1: self.window.label.setText( self.labelText + "t={0:6.2f}, fps={1:6.2f}".format( t + dt, @@ -209,8 +209,8 @@ class QtOpenGLRendering(Computational): @param problem : Problem to set the Qt main loop. """ def problem_step(): - if not problem.simulation.isOver: - problem.simulation.printState() + if not problem.simulation.is_over: + problem.simulation.print_state() for op in problem.operators: op.apply(problem.simulation) problem.simulation.advance() diff --git a/hysop/gpu/gpu_diffusion.py b/hysop/gpu/gpu_diffusion.py index 207fc2fd3..7496ea541 100644 --- a/hysop/gpu/gpu_diffusion.py +++ b/hysop/gpu/gpu_diffusion.py @@ -170,7 +170,7 @@ class GPUDiffusion(DiscreteOperator, GPUOperator): d_evt = self.num_diffusion( self.field.gpu_data[0], self.field_tmp, - self.gpu_precision(self.viscosity * simulation.timeStep), + self.gpu_precision(self.viscosity * simulation.time_step), self._mesh_size, wait_for=wait_evt) c_evt = self.copy.launch_sizes_in_args( @@ -256,7 +256,7 @@ class GPUDiffusion(DiscreteOperator, GPUOperator): self.field.gpu_data[0], self._to_recv_buf[self._cutdir_list[0]], self.field_tmp, - self.gpu_precision(self.viscosity * simulation.timeStep), + self.gpu_precision(self.viscosity * simulation.time_step), self._mesh_size, wait_for=wait_evt) if len(self._cutdir_list) == 2: @@ -265,7 +265,7 @@ class GPUDiffusion(DiscreteOperator, GPUOperator): self._to_recv_buf[self._cutdir_list[0]], self._to_recv_buf[self._cutdir_list[1]], self.field_tmp, - self.gpu_precision(self.viscosity * simulation.timeStep), + self.gpu_precision(self.viscosity * simulation.time_step), self._mesh_size, wait_for=wait_evt) if len(self._cutdir_list) == 3: @@ -275,7 +275,7 @@ class GPUDiffusion(DiscreteOperator, GPUOperator): self._to_recv_buf[self._cutdir_list[1]], self._to_recv_buf[self._cutdir_list[2]], self.field_tmp, - self.gpu_precision(self.viscosity * simulation.timeStep), + self.gpu_precision(self.viscosity * simulation.time_step), self._mesh_size, wait_for=wait_evt) #c_evt = cl.enqueue_copy(self.cl_env.queue, self.field.gpu_data[0], diff --git a/hysop/gpu/gpu_particle_advection.py b/hysop/gpu/gpu_particle_advection.py index a0f2be00d..9a09a6767 100644 --- a/hysop/gpu/gpu_particle_advection.py +++ b/hysop/gpu/gpu_particle_advection.py @@ -640,7 +640,7 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): # self._init_events[self.fields_on_grid[0]].append(evt) def _compute_advec_euler_simpleechelle(self, simulation, dtCoeff, split_id, old_dir): - dt = simulation.timeStep * dtCoeff + dt = simulation.time_step * dtCoeff wait_evts = self.velocity.events + \ self._init_events[self.fields_on_grid[0]] # Advection @@ -653,7 +653,7 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): self._init_events[self.fields_on_grid[0]].append(evt) def _compute_advec_simpleechelle(self, simulation, dtCoeff, split_id, old_dir): - dt = simulation.timeStep * dtCoeff + dt = simulation.time_step * dtCoeff wait_evts = self.velocity.events + \ self._init_events[self.fields_on_grid[0]] # Advection @@ -666,7 +666,7 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): self._init_events[self.fields_on_grid[0]].append(evt) def _compute_advec_multiechelle(self, simulation, dtCoeff, split_id, old_dir): - dt = simulation.timeStep * dtCoeff + dt = simulation.time_step * dtCoeff wait_evts = self.velocity.events + \ self._init_events[self.fields_on_grid[0]] # Advection @@ -699,7 +699,7 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): if split_id==0 and self._synchronize is not None: self._synchronize(self.velocity.data) self.velocity.toDevice() - dt = simulation.timeStep * dtCoeff + dt = simulation.time_step * dtCoeff wait_evts = self.velocity.events + \ self._init_events[self.fields_on_grid[0]] + \ self.fields_on_grid[0].events @@ -718,7 +718,7 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): self._init_events[self.fields_on_grid[0]] = [] def _compute_1k_simpleechelle(self, simulation, dtCoeff, split_id, old_dir): - dt = simulation.timeStep * dtCoeff + dt = simulation.time_step * dtCoeff wait_evts = self.velocity.events + \ self._init_events[self.fields_on_grid[0]] + \ self.fields_on_grid[0].events @@ -735,7 +735,7 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): def _compute_1k_euler_simpleechelle(self, simulation, dtCoeff, split_id, old_dir): - dt = simulation.timeStep * dtCoeff + dt = simulation.time_step * dtCoeff wait_evts = self.velocity.events + \ self._init_events[self.fields_on_grid[0]] + \ self.fields_on_grid[0].events diff --git a/hysop/gpu/gpu_transfer.py b/hysop/gpu/gpu_transfer.py index 16da3a216..b915bff18 100644 --- a/hysop/gpu/gpu_transfer.py +++ b/hysop/gpu/gpu_transfer.py @@ -115,7 +115,7 @@ class DataTransfer(Computational): @opapply def apply(self, simulation=None): - ite = simulation.currentIteration + ite = simulation.current_iteration if ite % self.freq == 0: self._transfer() diff --git a/hysop/gpu/multi_gpu_particle_advection.py b/hysop/gpu/multi_gpu_particle_advection.py index 3a7c68c77..6febad7ff 100644 --- a/hysop/gpu/multi_gpu_particle_advection.py +++ b/hysop/gpu/multi_gpu_particle_advection.py @@ -680,7 +680,7 @@ class MultiGPUParticleAdvection(GPUParticleAdvection): self.profiler['comm_gpu_advec_set'] += advec_gpu_time def _init_copy(self, simulation, dtCoeff, split_id, old_dir): - self._exchange_velocity_buffers(simulation.timeStep * dtCoeff) + self._exchange_velocity_buffers(simulation.time_step * dtCoeff) wait_evt = self.fields_on_grid[0].events for g, p in zip(self.fields_on_grid[0].gpu_data, self.fields_on_part[self.fields_on_grid[0]]): @@ -689,7 +689,7 @@ class MultiGPUParticleAdvection(GPUParticleAdvection): self._init_events[self.fields_on_grid[0]].append(evt) def _init_transpose_xy(self, simulation, dtCoeff, split_id, old_dir): - self._exchange_velocity_buffers(simulation.timeStep * dtCoeff) + self._exchange_velocity_buffers(simulation.time_step * dtCoeff) wait_evt = self.fields_on_grid[0].events for g, p in zip(self.fields_on_grid[0].gpu_data, self.fields_on_part[self.fields_on_grid[0]]): @@ -697,7 +697,7 @@ class MultiGPUParticleAdvection(GPUParticleAdvection): self._init_events[self.fields_on_grid[0]].append(evt) def _init_transpose_xz(self, simulation, dtCoeff, split_id, old_dir): - self._exchange_velocity_buffers(simulation.timeStep * dtCoeff) + self._exchange_velocity_buffers(simulation.time_step * dtCoeff) wait_evt = self.fields_on_grid[0].events for g, p in zip(self.fields_on_grid[0].gpu_data, self.fields_on_part[self.fields_on_grid[0]]): @@ -705,7 +705,7 @@ class MultiGPUParticleAdvection(GPUParticleAdvection): self._init_events[self.fields_on_grid[0]].append(evt) def _compute_advec_comm(self, simulation, dtCoeff, split_id, old_dir): - dt = simulation.timeStep * dtCoeff + dt = simulation.time_step * dtCoeff self._todevice_velocity_buffers() wait_evts = self.velocity.events + self._evt_l_v + self._evt_r_v + \ self._init_events[self.fields_on_grid[0]] @@ -830,7 +830,7 @@ class MultiGPUParticleAdvection(GPUParticleAdvection): wait_for=wait_list) def _compute_1c_comm(self, simulation, dtCoeff, split_id, old_dir): - dt = simulation.timeStep * dtCoeff + dt = simulation.time_step * dtCoeff if self._is2kernel: self._compute_advec_comm(simulation, dtCoeff, split_id, old_dir) else: diff --git a/hysop/gpu/tests/test_advection_nullVelocity.py b/hysop/gpu/tests/test_advection_nullVelocity.py index 213b38c36..5a26b98c2 100644 --- a/hysop/gpu/tests/test_advection_nullVelocity.py +++ b/hysop/gpu/tests/test_advection_nullVelocity.py @@ -45,7 +45,7 @@ def assertion_2D(scal, velo, advec): scal_d.wait() velo_d.wait() - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) scal_d.toHost() scal_d.wait() @@ -70,8 +70,8 @@ def assertion_2D_withPython(scal, velo, advec, advec_py): scal_d.wait() velo_d.wait() - advec_py.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec_py.apply(Simulation(start=0., end=0.01, nb_iter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) py_res = scal_d.data[0].copy() scal_d.toHost() @@ -99,7 +99,7 @@ def assertion_3D(scal, velo, advec): scal_d.wait() velo_d.wait() - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) scal_d.toHost() scal_d.wait() @@ -125,8 +125,8 @@ def assertion_3D_withPython(scal, velo, advec, advec_py): scal_d.wait() velo_d.wait() - advec_py.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec_py.apply(Simulation(start=0., end=0.01, nb_iter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) py_res = scal_d.data[0].copy() scal_d.toHost() @@ -832,8 +832,8 @@ def test_rectangular_domain2D(): scal_d.toDevice() velo_d.toDevice() - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.01, nb_iter=1)) scal_py_res = scal_d.data[0].copy() scal_d.toHost() @@ -877,8 +877,8 @@ def test_rectangular_domain3D(): scal_d.toDevice() velo_d.toDevice() - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.01, nb_iter=1)) scal_py_res = scal_d.data[0].copy() scal_d.toHost() @@ -923,8 +923,8 @@ def test_2D_vector(): scal_d.toDevice() velo_d.toDevice() - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.01, nb_iter=1)) scal_py_res_X = scal_d.data[0].copy() scal_py_res_Y = scal_d.data[1].copy() @@ -975,8 +975,8 @@ def test_3D_vector(): scal_d.toDevice() velo_d.toDevice() - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.01, nb_iter=1)) scal_py_res_X = scal_d.data[0].copy() scal_py_res_Y = scal_d.data[1].copy() scal_py_res_Z = scal_d.data[2].copy() diff --git a/hysop/gpu/tests/test_advection_randomVelocity.py b/hysop/gpu/tests/test_advection_randomVelocity.py index c151b8f3f..64f0e2740 100644 --- a/hysop/gpu/tests/test_advection_randomVelocity.py +++ b/hysop/gpu/tests/test_advection_randomVelocity.py @@ -47,8 +47,8 @@ def assertion_2D_withPython(scal, velo, advec, advec_py): scal_d.toDevice() velo_d.toDevice() - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) py_res = scal_d.data[0].copy() scal_d.toHost() @@ -77,8 +77,8 @@ def assertion_3D_withPython(scal, velo, advec, advec_py): scal_d.toDevice() velo_d.toDevice() - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) py_res = scal_d.data[0].copy() scal_d.toHost() @@ -703,8 +703,8 @@ def test_rectangular_domain2D(): scal_d.toDevice() velo_d.toDevice() - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) py_res = scal_d.data[0].copy() scal_d.toHost() @@ -750,8 +750,8 @@ def test_rectangular_domain3D(): scal_d.toDevice() velo_d.toDevice() - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) py_res = scal_d.data[0].copy() scal_d.toHost() @@ -797,8 +797,8 @@ def test_vector_2D(): scal_d.toDevice() velo_d.toDevice() - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) py_res_X = scal_d.data[0].copy() py_res_Y = scal_d.data[1].copy() @@ -854,8 +854,8 @@ def test_vector_3D(): scal_d.toDevice() velo_d.toDevice() - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) py_res_X = scal_d.data[0].copy() py_res_Y = scal_d.data[1].copy() diff --git a/hysop/gpu/tests/test_gpu_multiresolution_filter.py b/hysop/gpu/tests/test_gpu_multiresolution_filter.py index 111b4e919..cf1ffe130 100755 --- a/hysop/gpu/tests/test_gpu_multiresolution_filter.py +++ b/hysop/gpu/tests/test_gpu_multiresolution_filter.py @@ -19,7 +19,7 @@ if main_rank < n_gpu: L = [1., 1., 1.] O = [0., 0., 0.] -simu = Simulation(tinit=0., tend=0.1, nbIter=1) +simu = Simulation(start=0., end=0.1, nb_iter=1) PY_COMPARE = True diff --git a/hysop/gpu/tests/test_multiphase_baroclinic.py b/hysop/gpu/tests/test_multiphase_baroclinic.py index 742ba3629..e4d45594a 100755 --- a/hysop/gpu/tests/test_multiphase_baroclinic.py +++ b/hysop/gpu/tests/test_multiphase_baroclinic.py @@ -76,7 +76,7 @@ def test_baroclinic_rhs_nonperiodic(): def call_operator(func, grad_func, vfunc): """Call the baroclinic rhs operator from given initialization functions""" - simu = Simulation(tinit=0.0, tend=1.0, timeStep=0.1, iterMax=1) + simu = Simulation(start=0.0, end=1.0, time_step=0.1, max_iter=1) box = Box() rhs = Field(box, is_vector=True, name='rhs') gradp = Field(box, is_vector=True, formula=vfunc, name='gradp') diff --git a/hysop/numerics/tests/test_integrators.py b/hysop/numerics/tests/test_integrators.py index c90c46bcb..3c421b13e 100755 --- a/hysop/numerics/tests/test_integrators.py +++ b/hysop/numerics/tests/test_integrators.py @@ -11,13 +11,13 @@ cos = np.cos # Grid resolution for tests nb = 9 # Initial time -tinit = 0. +start = 0. # Final time -tend = 0.2 +end = 0.2 # Time step #dt = 1e-3 # time sequence -#time = npu.seq(tinit, tend, dt) +#time = npu.seq(start, end, dt) #nbSteps = time.size import hysop as pp d1 = Discretization([nb + 1]) @@ -66,10 +66,10 @@ def integrate(integ, nbSteps): """ Integration with hysop """ - t = tinit - time_points = np.linspace(tinit, tend, nbSteps) + t = start + time_points = np.linspace(start, end, nbSteps) dtt = time_points[1] - time_points[0] - y = [npw.ones(nb) * math.exp(-tinit)] + y = [npw.ones(nb) * math.exp(-start)] res = [npw.zeros(nb)] # work = None i = 1 diff --git a/hysop/operator/adapt_timestep.py b/hysop/operator/adapt_timestep.py index 6a60e1ef2..93ba310d0 100755 --- a/hysop/operator/adapt_timestep.py +++ b/hysop/operator/adapt_timestep.py @@ -28,7 +28,7 @@ class AdaptTimeStep(Computational): time_range=None, lcfl=0.125, cfl=0.5, maxdt=9999., **kwds): """ - Create a timeStep-evaluation operator from given + Create a time_step-evaluation operator from given velocity and vorticity variables. Note : If cfl is None, the computation of the adaptative time step @@ -129,7 +129,7 @@ class AdaptTimeStep(Computational): def wait(self): task_is_source = self._mpis.task_id == self.domain.current_task() rank = self._mpis.rank - dt = self.simulation.timeStep + dt = self.simulation.time_step for rk in self._intercomms: if task_is_source: # Local 0 broadcast current_indices to remote comm @@ -139,4 +139,4 @@ class AdaptTimeStep(Computational): self._intercomms[rk].bcast(dt, root=MPI.PROC_NULL) else: dt = self._intercomms[rk].bcast(dt, root=0) - self.simulation.updateTimeStep(dt) + self.simulation.update_time_step(dt) diff --git a/hysop/operator/discrete/adapt_timestep.py b/hysop/operator/discrete/adapt_timestep.py index ccbc65d7e..85e1ade95 100755 --- a/hysop/operator/discrete/adapt_timestep.py +++ b/hysop/operator/discrete/adapt_timestep.py @@ -230,8 +230,8 @@ class AdaptTimeStep_D(DiscreteOperator): # current time time = self.simulation.time - iteration = self.simulation.currentIteration - Nmax = min(self.simulation.iterMax, self.time_range[1]) + iteration = self.simulation.current_iteration + Nmax = min(self.simulation.max_iter, self.time_range[1]) self.diagnostics[0] = time if iteration >= self.time_range[0] and iteration <= Nmax: if self._is_gradU_needed: @@ -254,6 +254,6 @@ class AdaptTimeStep_D(DiscreteOperator): self._writer.write() # Update simulation time step with the new dt - self.simulation.updateTimeStep(dt) + self.simulation.update_time_step(dt) # Warning this update is done only for the current MPI task! # See wait function in base class. diff --git a/hysop/operator/discrete/baroclinic.py b/hysop/operator/discrete/baroclinic.py index 607fa5597..cacdd39f7 100644 --- a/hysop/operator/discrete/baroclinic.py +++ b/hysop/operator/discrete/baroclinic.py @@ -87,7 +87,7 @@ class Baroclinic(DiscreteOperator): if simulation is None: raise ValueError("Missing simulation value for computation.") - dt = simulation.timeStep + dt = simulation.time_step if self._old_dt is None: self._old_dt = dt # Synchronize ghost points of velocity and density diff --git a/hysop/operator/discrete/baroclinic_from_rhs.py b/hysop/operator/discrete/baroclinic_from_rhs.py index 1434833bc..4f7d6355d 100644 --- a/hysop/operator/discrete/baroclinic_from_rhs.py +++ b/hysop/operator/discrete/baroclinic_from_rhs.py @@ -49,7 +49,7 @@ class BaroclinicFromRHS(DiscreteOperator): if simulation is None: raise ValueError("Missing simulation value for computation.") - dt = simulation.timeStep + dt = simulation.time_step # Synchronize ghost points of velocity and density #self._synchronizeRHS(self.rhs.data) diff --git a/hysop/operator/discrete/custom.py b/hysop/operator/discrete/custom.py index 3f02d612e..20b6aa4da 100644 --- a/hysop/operator/discrete/custom.py +++ b/hysop/operator/discrete/custom.py @@ -19,7 +19,7 @@ class CustomMonitor(DiscreteOperator): self.res_shape = res_shape def apply(self, simulation=None): - ite = simulation.currentIteration + ite = simulation.current_iteration values = self.function(simulation, self.variables) if self._writer is not None and self._writer.do_write(ite): diff --git a/hysop/operator/discrete/diffusion_fft.py b/hysop/operator/discrete/diffusion_fft.py index 21401ea3a..daa409eeb 100644 --- a/hysop/operator/discrete/diffusion_fft.py +++ b/hysop/operator/discrete/diffusion_fft.py @@ -44,7 +44,7 @@ class DiffusionFFT(DiscreteOperator): def apply(self, simulation=None): assert simulation is not None, \ "Missing dt value for diffusion computation." - dt = simulation.timeStep + dt = simulation.time_step ghosts = self.vorticity.topology.ghosts() if self.vorticity.dimension == 2: diff --git a/hysop/operator/discrete/drag_and_lift.py b/hysop/operator/discrete/drag_and_lift.py index 21f3fb77e..875b9ee3b 100644 --- a/hysop/operator/discrete/drag_and_lift.py +++ b/hysop/operator/discrete/drag_and_lift.py @@ -133,7 +133,7 @@ class Forces(DiscreteOperator): # Synchro of ghost points is required for fd schemes self._synchronize(self._datalist) # Compute forces locally - dt = simulation.timeStep + dt = simulation.time_step if not self._on_proc: self._buffer[...] = 0.0 self.force[...] = 0.0 @@ -145,7 +145,7 @@ class Forces(DiscreteOperator): # normalization of the forces --> cD, cL, cZ self.force *= self._normalization # Print results, if required - ite = simulation.currentIteration + ite = simulation.current_iteration if self._writer is not None and self._writer.do_write(ite): self._writer.buffer[0, 0] = simulation.time self._writer.buffer[0, 1:] = self.force diff --git a/hysop/operator/discrete/energy_enstrophy.py b/hysop/operator/discrete/energy_enstrophy.py index e22512fca..974cf1665 100644 --- a/hysop/operator/discrete/energy_enstrophy.py +++ b/hysop/operator/discrete/energy_enstrophy.py @@ -132,7 +132,7 @@ class EnergyEnstrophy(DiscreteOperator): self.enstrophy = recvbuff[1] * self.coeff['Enstrophy'] # Print results, if required - ite = simulation.currentIteration + ite = simulation.current_iteration if self._writer is not None and self._writer.do_write(ite): self._writer.buffer[0, 0] = simulation.time self._writer.buffer[0, 1] = self.energy diff --git a/hysop/operator/discrete/forcing.py b/hysop/operator/discrete/forcing.py index 7d9121db5..683a20c87 100644 --- a/hysop/operator/discrete/forcing.py +++ b/hysop/operator/discrete/forcing.py @@ -54,7 +54,7 @@ class Forcing(DiscreteOperator): def apply(self, simulation=None): assert simulation is not None, \ "Simulation parameter is required." - dt = simulation.timeStep + dt = simulation.time_step self._apply(dt) diff --git a/hysop/operator/discrete/low_pass_filt.py b/hysop/operator/discrete/low_pass_filt.py index 45104de99..02267ba85 100644 --- a/hysop/operator/discrete/low_pass_filt.py +++ b/hysop/operator/discrete/low_pass_filt.py @@ -55,7 +55,7 @@ class LowPassFilt(DiscreteOperator): def apply(self, simulation=None): assert simulation is not None, \ "Simulation parameter is required." - dt = simulation.timeStep + dt = simulation.time_step self._apply(dt) diff --git a/hysop/operator/discrete/monitoringPoints.py b/hysop/operator/discrete/monitoringPoints.py index de8ae0e8b..46fa8cd6b 100644 --- a/hysop/operator/discrete/monitoringPoints.py +++ b/hysop/operator/discrete/monitoringPoints.py @@ -40,7 +40,7 @@ class MonitoringPoints(DiscreteOperator): self.length = topo_v.domain.length self.origin = topo_v.domain.origin self.coords = topo_v.mesh.coords - self.nbIter = 0 + self.nb_iter = 0 ## Normalized flow values at monitoring position (velNorm, vortNorm) self.velNorm = 0.0 self.vortNorm = 0.0 @@ -94,11 +94,11 @@ class MonitoringPoints(DiscreteOperator): "Missing simulation value for computation." time = simulation.time - ite = simulation.currentIteration + ite = simulation.current_iteration filename = self._writer.filename #+ '_ite' + format(ite) if self.is_rk_computing : - self.nbIter += 1 + self.nb_iter += 1 vd = self.velocity.data vortd = self.vorticity.data nbc = self.velocity.nb_components diff --git a/hysop/operator/discrete/multiphase_gradp.py b/hysop/operator/discrete/multiphase_gradp.py index b15e780f5..91ab67e12 100644 --- a/hysop/operator/discrete/multiphase_gradp.py +++ b/hysop/operator/discrete/multiphase_gradp.py @@ -82,7 +82,7 @@ class GradP(DiscreteOperator): if simulation is None: raise ValueError("Missing simulation value for computation.") - dt = simulation.timeStep + dt = simulation.time_step if self._old_dt is None: self._old_dt = dt # Synchronize ghost points of velocity and density diff --git a/hysop/operator/discrete/particle_advection.py b/hysop/operator/discrete/particle_advection.py index 8740979b8..14053b0dc 100644 --- a/hysop/operator/discrete/particle_advection.py +++ b/hysop/operator/discrete/particle_advection.py @@ -175,7 +175,7 @@ class ParticleAdvection(DiscreteOperator): assert simulation is not None, \ 'Simulation parameter is missing.' - t, dt = simulation.time, simulation.timeStep * dt_coeff + t, dt = simulation.time, simulation.time_step * dt_coeff # Initialize fields on particles with fields on grid values. for fg in self.fields_on_grid: for d in xrange(fg.nb_components): diff --git a/hysop/operator/discrete/penalization.py b/hysop/operator/discrete/penalization.py index b8113bb13..46b6bc4bd 100644 --- a/hysop/operator/discrete/penalization.py +++ b/hysop/operator/discrete/penalization.py @@ -108,7 +108,7 @@ class Penalization(DiscreteOperator): def apply(self, simulation=None): assert simulation is not None, \ "Simulation parameter is required." - dt = simulation.timeStep + dt = simulation.time_step self._apply(dt) diff --git a/hysop/operator/discrete/poisson_fft.py b/hysop/operator/discrete/poisson_fft.py index 7aeb18b22..1cd215f14 100644 --- a/hysop/operator/discrete/poisson_fft.py +++ b/hysop/operator/discrete/poisson_fft.py @@ -112,11 +112,11 @@ class PoissonFFT(DiscreteOperator): def do_projection_with_op(self, simu): self.projection.apply(simu) - ite = simu.currentIteration + ite = simu.current_iteration return self.projection.do_projection(ite) def do_projection_no_op(self, simu): - ite = simu.currentIteration + ite = simu.current_iteration return ite % self.projection == 0 def _solve2D(self, simu=None): diff --git a/hysop/operator/discrete/profiles.py b/hysop/operator/discrete/profiles.py index 74ca03e4f..97e1a3682 100644 --- a/hysop/operator/discrete/profiles.py +++ b/hysop/operator/discrete/profiles.py @@ -46,7 +46,7 @@ class Profiles(DiscreteOperator): self.length = topo_v.domain.length self.origin = topo_v.domain.origin self.coords = topo_v.mesh.coords - self.nbIter = 0 + self.nb_iter = 0 ## Mean quantities (meanVelNorm, meanVortNorm, meanVelX, ## meanVelY, meanVelY, meanVortX, meanVortY, meanVortZ) self.mean_qtities = None @@ -105,11 +105,11 @@ class Profiles(DiscreteOperator): "Missing simulation value for computation." time = simulation.time - ite = simulation.currentIteration + ite = simulation.current_iteration filename = self._writer.filename + '_ite' + format(ite) if time >= self.beginMeanComput and self.is_rk_computing : - self.nbIter += 1 + self.nb_iter += 1 vd = self.velocity.data vortd = self.vorticity.data nbc = self.velocity.nb_components @@ -162,26 +162,26 @@ class Profiles(DiscreteOperator): if self.direction==0 : for i in xrange (self.shape_v[0]): self._writer.buffer[0, 0] = self.coords[0][i,0,0] - self._writer.buffer[0, 1] = self.mean_qtities[0][i] / self.nbIter - self._writer.buffer[0, 2] = self.mean_qtities[1][i] / self.nbIter - self._writer.buffer[0, 3] = self.mean_qtities[2][i] / self.nbIter - self._writer.buffer[0, 4] = self.mean_qtities[3][i] / self.nbIter - self._writer.buffer[0, 5] = self.mean_qtities[4][i] / self.nbIter - self._writer.buffer[0, 6] = self.mean_qtities[5][i] / self.nbIter - self._writer.buffer[0, 7] = self.mean_qtities[6][i] / self.nbIter - self._writer.buffer[0, 8] = self.mean_qtities[7][i] / self.nbIter + self._writer.buffer[0, 1] = self.mean_qtities[0][i] / self.nb_iter + self._writer.buffer[0, 2] = self.mean_qtities[1][i] / self.nb_iter + self._writer.buffer[0, 3] = self.mean_qtities[2][i] / self.nb_iter + self._writer.buffer[0, 4] = self.mean_qtities[3][i] / self.nb_iter + self._writer.buffer[0, 5] = self.mean_qtities[4][i] / self.nb_iter + self._writer.buffer[0, 6] = self.mean_qtities[5][i] / self.nb_iter + self._writer.buffer[0, 7] = self.mean_qtities[6][i] / self.nb_iter + self._writer.buffer[0, 8] = self.mean_qtities[7][i] / self.nb_iter ft.write(f, self._writer.buffer) elif self.direction==1 : for j in xrange (self.shape_v[1]): self._writer.buffer[0, 0] = self.coords[1][0,j,0] - self._writer.buffer[0, 1] = self.mean_qtities[0][j] / self.nbIter - self._writer.buffer[0, 2] = self.mean_qtities[1][j] / self.nbIter - self._writer.buffer[0, 3] = self.mean_qtities[2][j] / self.nbIter - self._writer.buffer[0, 4] = self.mean_qtities[3][j] / self.nbIter - self._writer.buffer[0, 5] = self.mean_qtities[4][j] / self.nbIter - self._writer.buffer[0, 6] = self.mean_qtities[5][j] / self.nbIter - self._writer.buffer[0, 7] = self.mean_qtities[6][j] / self.nbIter - self._writer.buffer[0, 8] = self.mean_qtities[7][j] / self.nbIter + self._writer.buffer[0, 1] = self.mean_qtities[0][j] / self.nb_iter + self._writer.buffer[0, 2] = self.mean_qtities[1][j] / self.nb_iter + self._writer.buffer[0, 3] = self.mean_qtities[2][j] / self.nb_iter + self._writer.buffer[0, 4] = self.mean_qtities[3][j] / self.nb_iter + self._writer.buffer[0, 5] = self.mean_qtities[4][j] / self.nb_iter + self._writer.buffer[0, 6] = self.mean_qtities[5][j] / self.nb_iter + self._writer.buffer[0, 7] = self.mean_qtities[6][j] / self.nb_iter + self._writer.buffer[0, 8] = self.mean_qtities[7][j] / self.nb_iter ft.write(f, self._writer.buffer) else : raise ValueError("Only profiles in the X or Y direction.") diff --git a/hysop/operator/discrete/reprojection.py b/hysop/operator/discrete/reprojection.py index 76a1ba3e4..a883d293c 100644 --- a/hysop/operator/discrete/reprojection.py +++ b/hysop/operator/discrete/reprojection.py @@ -83,7 +83,7 @@ class Reprojection(DiscreteOperator): def apply(self, simulation=None): assert simulation is not None, \ 'Simulation parameter is missing.' - ite = simulation.currentIteration + ite = simulation.current_iteration # Reset reprojection frequency to default self.frequency = self._default_frequency diff --git a/hysop/operator/discrete/residual.py b/hysop/operator/discrete/residual.py index 2fa568b12..f221ac09d 100644 --- a/hysop/operator/discrete/residual.py +++ b/hysop/operator/discrete/residual.py @@ -31,7 +31,7 @@ class Residual(DiscreteOperator): self.length = topo_w.domain.length self.origin = topo_w.domain.origin self.coords = topo_w.mesh.coords - self.nbIter = 0 + self.nb_iter = 0 ## Global residual self.residual = 0.0 # Time stem of the previous iteration @@ -73,8 +73,8 @@ class Residual(DiscreteOperator): "Missing simulation value for computation." time = simulation.time - ite = simulation.currentIteration - dt = simulation.timeStep + ite = simulation.current_iteration + dt = simulation.time_step if self._old_dt is None: self._old_dt = dt diff --git a/hysop/operator/discrete/scales_advection.py b/hysop/operator/discrete/scales_advection.py index 04b47c09d..79064cecc 100644 --- a/hysop/operator/discrete/scales_advection.py +++ b/hysop/operator/discrete/scales_advection.py @@ -73,7 +73,7 @@ class ScalesAdvection(DiscreteOperator): assert simulation is not None, \ "Missing simulation value for computation." - dt = simulation.timeStep + dt = simulation.time_step # Call scales advection for adF, fun in zip(self.advected_fields, self._scales_func): adF = fun(dt, self.velocity.data[0], diff --git a/hysop/operator/discrete/spectrum.py b/hysop/operator/discrete/spectrum.py index 9b1bdb056..defda6370 100755 --- a/hysop/operator/discrete/spectrum.py +++ b/hysop/operator/discrete/spectrum.py @@ -50,7 +50,7 @@ class FFTSpectrum(DiscreteOperator): def apply(self, simulation=None): assert simulation is not None, \ "Missing dt value for diffusion computation." - ite = simulation.currentIteration + ite = simulation.current_iteration ghosts = self.field.topology.ghosts() if self.field.dimension == 3: fftw2py.spectrum_3d(self.field.data[0], diff --git a/hysop/operator/discrete/stretching.py b/hysop/operator/discrete/stretching.py index e000205b8..4f1527605 100755 --- a/hysop/operator/discrete/stretching.py +++ b/hysop/operator/discrete/stretching.py @@ -137,7 +137,7 @@ class Stretching(DiscreteOperator): # current time t = simulation.time # time step - dt = simulation.timeStep + dt = simulation.time_step self._apply(t, dt) # def apply(self, simulation=None): @@ -147,7 +147,7 @@ class Stretching(DiscreteOperator): # "Missing simulation value for computation." # # # time step -# dt = simulation.timeStep +# dt = simulation.time_step # # current time # t = simulation.time # diff --git a/hysop/operator/discrete/velocity_correction.py b/hysop/operator/discrete/velocity_correction.py index 0053ecd9b..ffd41bf71 100755 --- a/hysop/operator/discrete/velocity_correction.py +++ b/hysop/operator/discrete/velocity_correction.py @@ -140,7 +140,7 @@ class VelocityCorrection_D(DiscreteOperator): # vort_mean[X], vort_mean[Y], vort_mean[Z]] # or (in 2D) [vx_shift, flowrates[Y], vort_mean] vort_mean = self.rates[start:] - ite = simulation.currentIteration + ite = simulation.current_iteration if self._writer is not None and self._writer.do_write(ite): self._writer.buffer[0, 0] = simulation.time self._writer.buffer[0, 1] = ite diff --git a/hysop/operator/hdf_io.py b/hysop/operator/hdf_io.py index 5653b0aa3..6936a3370 100755 --- a/hysop/operator/hdf_io.py +++ b/hysop/operator/hdf_io.py @@ -219,7 +219,7 @@ class HDF_Writer(HDF_IO): def apply(self, simulation=None): if simulation is None: raise ValueError("Missing simulation value for monitoring.") - ite = simulation.currentIteration + ite = simulation.current_iteration if ite == -1 or ite % self.io_params.frequency == 0: self.step(simulation) self._count += 1 @@ -260,7 +260,7 @@ class HDF_Writer(HDF_IO): # Get 'current' filename. It depends on the number # of the current output (count) and on the current process # rank. - self._count = simu.currentIteration + self._count = simu.current_iteration compression = self.open_hdf(self._count, mode='w') # Get the names of output variables and create the corresponding # datasets diff --git a/hysop/operator/tests/test_Stretching.py b/hysop/operator/tests/test_Stretching.py index 4b6baa5b0..159d50635 100755 --- a/hysop/operator/tests/test_Stretching.py +++ b/hysop/operator/tests/test_Stretching.py @@ -101,7 +101,7 @@ def test_stretching(): boxLength = [1., 1., 1.] boxMin = [0., 0., 0.] nbElem = Discretization([nb, nb, nb], [2, 2, 2]) - timeStep = 0.05 + time_step = 0.05 # Domain box = pp.Box(length=boxLength, origin=boxMin) @@ -123,7 +123,7 @@ def test_stretching(): velo.initialize(topo=topo) vorti.initialize(topo=topo) stretch.setup() - simulation = Simulation(tinit=0, tend=1., timeStep=timeStep) + simulation = Simulation(start=0, end=1., time_step=time_step) stretch.apply(simulation) def test_stretchingLinearized(): @@ -133,7 +133,7 @@ def test_stretchingLinearized(): boxLength = [1., 1., 1.] boxMin = [0., 0., 0.] nbElem = Discretization([nb, nb, nb], [2, 2, 2]) - timeStep = 0.05 + time_step = 0.05 # Domain box = pp.Box(length=boxLength, origin=boxMin) @@ -170,7 +170,7 @@ def test_stretchingLinearized(): vortiBF.initialize(topo=topo) stretch1.setup() stretch2.setup() - simulation = Simulation(tinit=0, tend=1., timeStep=timeStep) + simulation = Simulation(start=0, end=1., time_step=time_step) stretch1.apply(simulation) print 'norm vorti (usual):', vorti.norm(topo) @@ -184,7 +184,7 @@ def test_stretching_external_work(): boxLength = [1., 1., 1.] boxMin = [0., 0., 0.] nbElem = Discretization([nb, nb, nb], [2, 2, 2]) - timeStep = 0.05 + time_step = 0.05 # Domain box = pp.Box(length=boxLength, origin=boxMin) @@ -213,5 +213,5 @@ def test_stretching_external_work(): velo.initialize(topo=topo) vorti.initialize(topo=topo) stretch.setup(rwork=rwork) - simulation = Simulation(tinit=0, tend=1., timeStep=timeStep) + simulation = Simulation(start=0, end=1., time_step=time_step) stretch.apply(simulation) diff --git a/hysop/operator/tests/test_adaptive_time_step.py b/hysop/operator/tests/test_adaptive_time_step.py index f1a7eef40..81e1016e2 100755 --- a/hysop/operator/tests/test_adaptive_time_step.py +++ b/hysop/operator/tests/test_adaptive_time_step.py @@ -42,7 +42,7 @@ def test_adapt(): Here we just check if discr/setup/apply process goes well. """ velo, vorti = init() - simu = Simulation(nbIter=2) + simu = Simulation(nb_iter=2) op = AdaptTimeStep(velo, vorti, simulation=simu, discretization=d3d, lcfl=0.125, cfl=0.5) op.discretize() @@ -56,7 +56,7 @@ def test_adapt_2(): The same but with file output """ velo, vorti = init() - simu = Simulation(nbIter=2) + simu = Simulation(nb_iter=2) op = AdaptTimeStep(velo, vorti, simulation=simu, io_params=True, discretization=d3d, lcfl=0.125, cfl=0.5) op.discretize() @@ -72,7 +72,7 @@ def test_adapt_3(): The same but with external work vector """ velo, vorti = init() - simu = Simulation(nbIter=2) + simu = Simulation(nb_iter=2) op = AdaptTimeStep(velo, vorti, simulation=simu, io_params=True, discretization=d3d, lcfl=0.125, cfl=0.5) op.discretize() @@ -114,7 +114,7 @@ def test_adapt_4(): from hysop.tools.parameters import MPIParams cpu_task = MPIParams(comm=dom.comm_task, task_id=CPU) - simu = Simulation(nbIter=4) + simu = Simulation(nb_iter=4) op = AdaptTimeStep(velo, vorti, simulation=simu, io_params=True, discretization=d3d, lcfl=0.125, cfl=0.5, mpi_params=cpu_task) @@ -124,13 +124,13 @@ def test_adapt_4(): op.setup() vorti.initialize() - while not simu.isOver: + while not simu.is_over: if dom.is_on_task(CPU): op.apply() op.wait() simu.advance() refval = 0 if dom.is_on_task(CPU): - refval = simu.timeStep + refval = simu.time_step refval = main_comm.bcast(refval, root=0) - assert refval == simu.timeStep + assert refval == simu.time_step diff --git a/hysop/operator/tests/test_advec_scales.py b/hysop/operator/tests/test_advec_scales.py index c5e1c5213..c81900e7e 100755 --- a/hysop/operator/tests/test_advec_scales.py +++ b/hysop/operator/tests/test_advec_scales.py @@ -43,8 +43,8 @@ def test_nullVelocity_m4(): scal_ref_d.data[0][...] = scal_d.data[0][...] topo = scal_d.topology assert (velo.norm(topo) == 0).all() - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) print (np.max(np.abs(scal_ref_d.data[0] - scal_d.data[0]))) assert np.allclose(scal_ref_d.data[0], scal_d.data[0]) @@ -83,8 +83,8 @@ def test_nullVelocity_vec_m4(): scal_ref_d.data[1][...] = scal_d.data[1][...] scal_ref_d.data[2][...] = scal_d.data[2][...] - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_ref_d.data[0], scal_d.data[0]) assert np.allclose(scal_ref_d.data[1], scal_d.data[1]) @@ -107,7 +107,7 @@ def test_nullVelocity_m6(): scal_d.data[0][...] = np.asarray(np.random.random(scal_d.data[0].shape)) scal_init = npw.copy(scal_d.data[0]) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_init, scal_d.data[0]) @@ -135,7 +135,7 @@ def test_nullVelocity_vec_m6(): scal_init1 = npw.copy(scal_d.data[1]) scal_init2 = npw.copy(scal_d.data[2]) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_init0, scal_d.data[0]) assert np.allclose(scal_init1, scal_d.data[1]) @@ -170,8 +170,8 @@ def test_nullVelocity_m8(): np.random.random(scal_d.data[0].shape)) scal_ref_d.data[0][...] = scal_d.data[0] - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_ref_d.data[0], scal_d.data[0]) @@ -205,8 +205,8 @@ def test_nullVelocity_vec_m8(): npw.asrealarray(np.random.random(scal_d.data[i].shape)) scal_ref_d.data[i][...] = scal_d.data[i][...] - advec.apply(Simulation(tinit=0., tend=0.075, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.075, nbIter=1)) + advec.apply(Simulation(start=0., end=0.075, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.075, nb_iter=1)) for i in xrange(box.dimension): assert np.allclose(scal_ref_d.data[i], scal_d.data[i]) @@ -245,8 +245,8 @@ def _randomVelocity_m4(): velo_d.data[2][...] = npw.asrealarray( np.random.random(scal_d.data[0].shape)) / (2. * scal_d.resolution[1]) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_ref_d.data[0], scal_d.data[0]) @@ -290,8 +290,8 @@ def _randomVelocity_vec_m4(): velo_d.data[2][...] = npw.asrealarray( np.random.random(scal_d.data[2].shape)) / (2. * scal_d.resolution[1]) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_ref_d.data[0], scal_d.data[0]) assert np.allclose(scal_ref_d.data[1], scal_d.data[1]) @@ -331,8 +331,8 @@ def test_randomVelocity_m6(): velo_d.data[2][...] = npw.asrealarray( np.random.random(scal_d.data[0].shape)) / (2. * scal_d.resolution[1]) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_ref_d.data[0], scal_d.data[0]) @@ -376,8 +376,8 @@ def test_randomVelocity_vec_m6(): velo_d.data[2][...] = npw.asrealarray( np.random.random(scal_d.data[2].shape)) / (2. * scal_d.resolution[1]) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_ref_d.data[0], scal_d.data[0]) assert np.allclose(scal_ref_d.data[1], scal_d.data[1]) @@ -418,8 +418,8 @@ def test_randomVelocity_m8(): velo_d.data[2][...] = npw.asrealarray( np.random.random(scal_d.data[0].shape)) / (2. * scal_d.resolution[1]) - advec.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.1, nbIter=1)) + advec.apply(Simulation(start=0., end=0.1, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.1, nb_iter=1)) assert np.allclose(scal_ref_d.data[0], scal_d.data[0], atol=1e-07) @@ -464,8 +464,8 @@ def test_randomVelocity_vec_m8(): velo_d.data[2][...] = npw.asrealarray( np.random.random(scal_d.data[2].shape)) / (2. * scal_d.resolution[1]) - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) - advec_py.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) + advec_py.apply(Simulation(start=0., end=0.01, nb_iter=1)) assert np.allclose(scal_ref_d.data[0], scal_d.data[0], atol=1e-07) assert np.allclose(scal_ref_d.data[1], scal_d.data[1], atol=1e-07) diff --git a/hysop/operator/tests/test_analytic.py b/hysop/operator/tests/test_analytic.py index b9d8a032c..6d9678e6a 100755 --- a/hysop/operator/tests/test_analytic.py +++ b/hysop/operator/tests/test_analytic.py @@ -13,7 +13,7 @@ d2D = Discretization([33, 33]) L2D = [1., 1.] origin2D = [0., 0.] nbc = 4 -simu = Simulation(tinit=0., tend=0.1, nbIter=1) +simu = Simulation(start=0., end=0.1, nb_iter=1) # Non-Vectorized and vectorized formulas for a scalar diff --git a/hysop/operator/tests/test_density.py b/hysop/operator/tests/test_density.py index 0016e6eed..55aee581b 100755 --- a/hysop/operator/tests/test_density.py +++ b/hysop/operator/tests/test_density.py @@ -26,5 +26,5 @@ def test_density(): op.setup() topo = op.variables[viscosity] viscosity.initialize(topo=topo) - # simu = Simulation(nbIter=2) + # simu = Simulation(nb_iter=2) # op.apply(simu) ## --> need to be reviewed diff --git a/hysop/operator/tests/test_diff_poisson_3D.py b/hysop/operator/tests/test_diff_poisson_3D.py index d4c9186d1..9dbea2deb 100755 --- a/hysop/operator/tests/test_diff_poisson_3D.py +++ b/hysop/operator/tests/test_diff_poisson_3D.py @@ -63,7 +63,7 @@ def test_Diff_Poisson(): diffusion.setup() poisson.setup() - simu = Simulation(tinit=0.0, tend=10., timeStep=0.002, - iterMax=1000000) + simu = Simulation(start=0.0, end=10., time_step=0.002, + max_iter=1000000) diffusion.apply(simu) poisson.apply(simu) diff --git a/hysop/operator/tests/test_diffusion.py b/hysop/operator/tests/test_diffusion.py index 9a493a7b4..6473a8b5d 100755 --- a/hysop/operator/tests/test_diffusion.py +++ b/hysop/operator/tests/test_diffusion.py @@ -44,7 +44,7 @@ def test_Diffusion3D(): diff.discretize() diff.setup() topo = diff.discreteFields[vorticity].topology - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) vorticity.initialize(topo=topo) diff.apply(simu) diff.finalize() @@ -62,7 +62,7 @@ def test_Diffusion3D_2(): diff.discretize() diff.setup() topo = diff.discreteFields[vorticity].topology - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) vorticity.initialize(topo=topo) diff.apply(simu) diff.finalize() @@ -79,7 +79,7 @@ def test_Diffusion2D(): diff.discretize() diff.setup() topo = diff.discreteFields[vorticity].topology - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) vorticity.initialize(topo=topo) diff.apply(simu) diff.finalize() diff --git a/hysop/operator/tests/test_drag_and_lift.py b/hysop/operator/tests/test_drag_and_lift.py index 06fd9fef8..aba51c89c 100755 --- a/hysop/operator/tests/test_drag_and_lift.py +++ b/hysop/operator/tests/test_drag_and_lift.py @@ -107,7 +107,7 @@ def test_momentum_forces_3d(): obstacles=obst, penalisation_coeff=[1e8]) dg.discretize() dg.setup() - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.apply(simu) dg.apply(simu) @@ -131,21 +131,21 @@ def build_noca(formulation): def test_noca1(): dg, op = build_noca(1) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.apply(simu) dg.apply(simu) def test_noca2(): dg, op = build_noca(2) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.apply(simu) dg.apply(simu) def test_noca3(): dg, op = build_noca(3) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.apply(simu) dg.apply(simu) @@ -180,13 +180,13 @@ def test_all_drags(): drag.discretize() drag.setup() - simu = Simulation(timeStep=1e-4, tend=1e-2) + simu = Simulation(time_step=1e-4, end=1e-2) op.apply(simu) for drag in dg: dg[drag].apply(simu) simu.initialize() - while not simu.isOver: + while not simu.is_over: velo.initialize(simu.time, topo) vorti.initialize(simu.time, topo) for drag in dg: diff --git a/hysop/operator/tests/test_energy_enstrophy.py b/hysop/operator/tests/test_energy_enstrophy.py index 87505acb6..6e624ce33 100755 --- a/hysop/operator/tests/test_energy_enstrophy.py +++ b/hysop/operator/tests/test_energy_enstrophy.py @@ -65,7 +65,7 @@ def test_energy_enstrophy(): topo = op.variables[velo] velo.initialize(topo=topo) vorti.initialize(topo=topo) - simu = Simulation(nbIter=2) + simu = Simulation(nb_iter=2) op.apply(simu) intrange = [] box = topo.domain diff --git a/hysop/operator/tests/test_hdf5_io.py b/hysop/operator/tests/test_hdf5_io.py index 3e338fbae..199ee817b 100755 --- a/hysop/operator/tests/test_hdf5_io.py +++ b/hysop/operator/tests/test_hdf5_io.py @@ -70,7 +70,7 @@ def test_write_read_scalar_3D(): filename = working_dir + '/testIO_scal' iop = IOParams(filename, fileformat=IO.HDF5) op = HDF_Writer(variables={scalRef: topo}, io_params=iop) - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) op.discretize() op.setup() simu.initialize() @@ -118,13 +118,13 @@ def test_write_read_scalar_3D_defaults(): # Write a scalar field, using default configuration for output # names and location op = HDF_Writer(variables={scalRef: topo}) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.discretize() op.setup() scal3D.discretize(topo=topo) scalRef.initialize(simu.time, topo=topo) simu.initialize() - while not simu.isOver: + while not simu.is_over: op.apply(simu) simu.advance() @@ -147,7 +147,7 @@ def test_write_read_scalar_3D_defaults(): # Read a scalar field, using default configuration for output # names and location, with a given iteration number. reader = HDF_Reader(variables={scalRef: topo}, - restart=simu.currentIteration - 1) + restart=simu.current_iteration - 1) reader.discretize() reader.setup() for d in xrange(scal3D.nb_components): @@ -167,13 +167,13 @@ def test_write_read_vectors_3D_defaults(): # Write a vector field, using default configuration for output # names and location op = HDF_Writer(variables={velo: topo, vorti: topo}) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.discretize() op.setup() velo.initialize(simu.time, topo=topo) vorti.initialize(simu.time, topo=topo) simu.initialize() - while not simu.isOver: + while not simu.is_over: op.apply(simu) simu.advance() @@ -215,7 +215,7 @@ def test_write_read_vectors_3D_defaults(): # the writer above. reader = HDF_Reader(variables={velo: topo, vorti: topo}, io_params=IOParams(filename), - restart=simu.currentIteration - 1) + restart=simu.current_iteration - 1) reader.discretize() reader.setup() for d in xrange(v3d.nb_components): @@ -242,14 +242,14 @@ def test_write_read_vectors_3D(): iop = IOParams(filename, fileformat=IO.HDF5) op = HDF_Writer(variables={velo: topo, vorti: topo}, var_names={velo: 'io_1', vorti: 'io_2'}, io_params=iop) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.discretize() op.setup() velo.initialize(simu.time, topo=topo) vorti.initialize(simu.time, topo=topo) simu.initialize() - while not simu.isOver: + while not simu.is_over: op.apply(simu) simu.advance() @@ -301,12 +301,12 @@ def test_write_read_subset_1(): # but with fixed names for datasets op = HDF_Writer(variables={velo: topo}, var_names={velo: 'io_1'}, subset=mybox) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.discretize() op.setup() velo.initialize(simu.time, topo=topo) simu.initialize() - while not simu.isOver: + while not simu.is_over: op.apply(simu) simu.advance() op.finalize() @@ -356,12 +356,12 @@ def test_write_read_subset_2(): # but with fixed names for datasets op = HDF_Writer(variables={velo: topo}, var_names={velo: 'io_1'}, subset=mybox) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) op.discretize() op.setup() velo.initialize(simu.time, topo=topo) simu.initialize() - while not simu.isOver: + while not simu.is_over: op.apply(simu) simu.advance() op.finalize() diff --git a/hysop/operator/tests/test_multiphase_gradp.py b/hysop/operator/tests/test_multiphase_gradp.py index f9a3a000c..1f8fc2e1f 100755 --- a/hysop/operator/tests/test_multiphase_gradp.py +++ b/hysop/operator/tests/test_multiphase_gradp.py @@ -48,7 +48,7 @@ def res_func(res, x, y, z, t): def test_gradp(): """Testing gradp operator against analytical result""" - simu = Simulation(tinit=0.0, tend=1.0, timeStep=0.1, iterMax=1) + simu = Simulation(start=0.0, end=1.0, time_step=0.1, max_iter=1) box = Box() velo = Field(box, is_vector=True, formula=velo_func, name='v0') res = Field(box, is_vector=True, name='res') diff --git a/hysop/operator/tests/test_multiresolution_filter.py b/hysop/operator/tests/test_multiresolution_filter.py index fbda089f3..04c5b0514 100755 --- a/hysop/operator/tests/test_multiresolution_filter.py +++ b/hysop/operator/tests/test_multiresolution_filter.py @@ -12,7 +12,7 @@ from hysop.mpi.main_var import main_size L = [1., 1., 1.] O = [0., 0., 0.] -simu = Simulation(tinit=0., tend=0.1, nbIter=1) +simu = Simulation(start=0., end=0.1, nb_iter=1) # Warning : values too large for tests n_middle = 513 diff --git a/hysop/operator/tests/test_particle_advection.py b/hysop/operator/tests/test_particle_advection.py index ad6fc2ef0..f753e4d4c 100755 --- a/hysop/operator/tests/test_particle_advection.py +++ b/hysop/operator/tests/test_particle_advection.py @@ -84,7 +84,7 @@ def assertion(scal, advec): np.random.random(scal_d.data[0].shape)) scal_init = npw.copy(scal_d.data[0]) - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) return np.allclose(scal_init, scal_d.data[0]) @@ -100,7 +100,7 @@ def assertion_vector2D(scal, advec): scal1_init = npw.copy(scal_d.data[0]) scal2_init = npw.copy(scal_d.data[1]) - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) print (np.max(np.abs((scal1_init - scal_d.data[0])))) print (np.max(np.abs((scal2_init - scal_d.data[1])))) return np.allclose(scal1_init, scal_d.data[0]) and \ @@ -122,7 +122,7 @@ def assertion_vector3D(scal, advec): scal2_init = npw.copy(scal_d.data[1]) scal3_init = npw.copy(scal_d.data[2]) - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) return np.allclose(scal1_init, scal_d.data[0]) and \ np.allclose(scal2_init, scal_d.data[1]) and \ np.allclose(scal3_init, scal_d.data[2]) @@ -141,7 +141,7 @@ def assertion_list(scal, advec): scal1_init = npw.copy(scal1_d.data[0]) scal2_init = npw.copy(scal2_d.data[0]) - advec.apply(Simulation(tinit=0., tend=0.01, nbIter=1)) + advec.apply(Simulation(start=0., end=0.01, nb_iter=1)) print (scal1_init, scal1_d.data[0]) print (scal2_init, scal2_d.data[0]) return np.allclose(scal1_init, scal1_d.data[0]) and \ diff --git a/hysop/operator/tests/test_penalization.py b/hysop/operator/tests/test_penalization.py index 75bd69718..4aef8703b 100755 --- a/hysop/operator/tests/test_penalization.py +++ b/hysop/operator/tests/test_penalization.py @@ -98,7 +98,7 @@ def check_penal(penal, sref, vref, scal, velo): velo.initialize(topo=topo) vd = velo.discretize(topo) sd = scal.discretize(topo) - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) penal.apply(simu) ind = topo.mesh.compute_index assert np.allclose(sd.data[0][ind], sref.data[0][ind]) @@ -284,7 +284,7 @@ def check_penal_vort(penal, wref, vref, vorti, velo): wd = vorti.discretize(topo) ind = topo.mesh.compute_index - simu = Simulation(nbIter=200) + simu = Simulation(nb_iter=200) penal.apply(simu) for d in xrange(vd.nb_components): assert np.allclose(vd.data[d][ind], vref.data[d][ind]) diff --git a/hysop/operator/tests/test_poisson.py b/hysop/operator/tests/test_poisson.py index 57de254e0..3cc2fb039 100755 --- a/hysop/operator/tests/test_poisson.py +++ b/hysop/operator/tests/test_poisson.py @@ -112,7 +112,7 @@ def test_Poisson_Pressure_3D(): topo = poisson.discreteFields[pressure].topology # Analytic operator to compute the reference field refOp = Analytic(variables={ref: topo}, formula=computeRefPressure) - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) refOp.discretize() refOp.setup() pressure.initialize(topo=topo) @@ -142,7 +142,7 @@ def test_Poisson3D(): # Analytic operator to compute the reference field ref = pp.Field(domain=dom, name='reference', is_vector=True) refOp = Analytic(variables={ref: topo}, formula=computeRef) - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) refOp.discretize() refOp.setup() vorticity.initialize(topo=topo) @@ -172,7 +172,7 @@ def test_Poisson2D(): # Analytic operator to compute the reference field ref = pp.Field(domain=dom, name='reference', is_vector=True) refOp = Analytic(variables={ref: topo}, formula=computeRef2D) - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) refOp.discretize() refOp.setup() vorticity.initialize(topo=topo) @@ -209,7 +209,7 @@ def test_Poisson3D_correction(): # Analytic operator to compute the reference field ref = pp.Field(domain=dom, name='reference', is_vector=True) refOp = Analytic(variables={ref: topo}, formula=computeRef_with_correction) - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) refOp.discretize() refOp.setup() vorticity.initialize(topo=topo) @@ -245,7 +245,7 @@ def test_Poisson3D_projection_1(): # Analytic operator to compute the reference field ref = pp.Field(domain=dom, name='reference', is_vector=True) refOp = Analytic(variables={ref: topo}, formula=computeRef) - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) refOp.discretize() refOp.setup() vorticity.initialize(topo=topo) @@ -284,7 +284,7 @@ def test_Poisson3D_projection_2(): # Analytic operator to compute the reference field ref = pp.Field(domain=dom, name='reference', is_vector=True) refOp = Analytic(variables={ref: topo}, formula=computeRef) - simu = Simulation(nbIter=10) + simu = Simulation(nb_iter=10) refOp.discretize() refOp.setup() vorticity.initialize(topo=topo) diff --git a/hysop/operator/tests/test_redistribute.py b/hysop/operator/tests/test_redistribute.py index f5450b9a1..917df64a1 100755 --- a/hysop/operator/tests/test_redistribute.py +++ b/hysop/operator/tests/test_redistribute.py @@ -38,7 +38,7 @@ def init_3d(domain): fields['vorticity'] = pp.Field(domain=domain, name='vorticity', is_vector=True, formula=v3d) fields['scal'] = pp.Field(domain=domain, name='scal') - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) simu.initialize() return fields, simu @@ -636,7 +636,7 @@ def test_distribute_inter_2d(): velocity = pp.Field(domain=domtasks, name='velocity', is_vector=True, formula=v2d) vort = pp.Field(domain=domtasks, name='vort') - simu = Simulation(nbIter=3) + simu = Simulation(nb_iter=3) reference = pp.Field(domain=domtasks, name='ref', is_vector=True, formula=v2d) r_2d = Discretization([33, ] * 2) diff --git a/hysop/operator/tests/test_reprojection.py b/hysop/operator/tests/test_reprojection.py index 7baaa624e..d1d11efee 100644 --- a/hysop/operator/tests/test_reprojection.py +++ b/hysop/operator/tests/test_reprojection.py @@ -47,11 +47,11 @@ def test_reprojection(): op.discretize() op.setup() # === Simulation setup === - simu = Simulation(nbIter=8) + simu = Simulation(nb_iter=8) # init fields vorti.initialize(topo=topo) # Apply correction simu.initialize() - while not simu.isOver: + while not simu.is_over: op.apply(simu) simu.advance() diff --git a/hysop/operator/tests/test_spectrum.py b/hysop/operator/tests/test_spectrum.py index 4acc7264c..7152e3f65 100755 --- a/hysop/operator/tests/test_spectrum.py +++ b/hysop/operator/tests/test_spectrum.py @@ -27,7 +27,7 @@ def test_spectrum(): op.setup() topo = op.discreteFields[field].topology field.initialize(topo=topo) - simu = Simulation(nbIter=1) + simu = Simulation(nb_iter=1) simu.initialize() op.apply(simu) diff --git a/hysop/operator/tests/test_velocity_correction.py b/hysop/operator/tests/test_velocity_correction.py index 34f962929..a24cbb315 100755 --- a/hysop/operator/tests/test_velocity_correction.py +++ b/hysop/operator/tests/test_velocity_correction.py @@ -68,7 +68,7 @@ def test_velocity_correction_3D(): op.discretize() op.setup() # === Simulation setup === - simu = Simulation(tinit=0.0, tend=5., timeStep=0.005, iterMax=1000000) + simu = Simulation(start=0.0, end=5., time_step=0.005, max_iter=1000000) # init fields velo.initialize(topo=topo) vorti.initialize(topo=topo) @@ -101,7 +101,7 @@ def test_velocity_correction_2D(): op.discretize() op.setup() # === Simulation setup === - simu = Simulation(tinit=0.0, tend=5., timeStep=0.005, iterMax=1000000) + simu = Simulation(start=0.0, end=5., time_step=0.005, max_iter=1000000) # init fields velo.initialize(topo=topo) vorti.initialize(topo=topo) diff --git a/hysop/problem/problem.py b/hysop/problem/problem.py index df77cac6e..9cb16aaba 100644 --- a/hysop/problem/problem.py +++ b/hysop/problem/problem.py @@ -168,9 +168,9 @@ class Problem(object): self.simulation.initialize() if main_rank == 0: print ("\n\n Start solving ...") - while not self.simulation.isOver: + while not self.simulation.is_over: if main_rank == 0: - self.simulation.printState() + self.simulation.print_state() for op in self.operators: if __VERBOSE__: @@ -178,7 +178,7 @@ class Problem(object): op.apply(self.simulation) testdump = \ - self.simulation.currentIteration % self.dumpFreq is 0 + self.simulation.current_iteration % self.dumpFreq is 0 self.simulation.advance() if self._doDump and testdump: self.dump() diff --git a/hysop/problem/problem_tasks.py b/hysop/problem/problem_tasks.py index 3d9efb4cc..aaab86c4e 100644 --- a/hysop/problem/problem_tasks.py +++ b/hysop/problem/problem_tasks.py @@ -155,9 +155,9 @@ class ProblemTasks(Problem): self.main_comm.Barrier() if self._main_rank == 0: print ("\n\n Start solving ...") - while not self.simulation.isOver: + while not self.simulation.is_over: if self._main_rank == 0: - self.simulation.printState() + self.simulation.print_state() for op in self.operators: if op.task_id() == self.my_task: op.apply(self.simulation) @@ -165,7 +165,7 @@ class ProblemTasks(Problem): if op._source_id == self.my_task: op.wait() testdump = \ - self.simulation.currentIteration % self.dumpFreq is 0 + self.simulation.current_iteration % self.dumpFreq is 0 self.simulation.advance() if self._doDump and testdump: self.dump() diff --git a/hysop/problem/simulation.py b/hysop/problem/simulation.py index 1a6f5d8f4..dea2196c1 100644 --- a/hysop/problem/simulation.py +++ b/hysop/problem/simulation.py @@ -1,138 +1,220 @@ -""" -@file simulation.py +"""Description of the simulation parameters (time, iteration ...) + +Usage +----- + +.. code:: + + # Initialize the simulation + s = Simulation(start=0.2, end=1., time_step=0.1) + # do some initialisation stuff with operators, + # print initial state ... + + # time loop + s.initialize() # --> ready to start + while not s.is_over: + # operators work + op.apply(s) + io.apply(s) + ... + # update time step (optional) + adapt_time.apply(s) + + # Prepare next step + s.advance() + + # end simulation (optional) to prepare io + s.finalize() + io.apply(s) -Description of the simulation parameters (time, iteration ...) """ import sys +from abc import ABCMeta, abstractmethod + eps = sys.float_info.epsilon +"""Machine epsilon, used to compare times.""" class Simulation(object): - """ - Setup for simulation parameters. + """Time-Simulation process description (time step, iteration ...) """ - def __init__(self, tinit=0.0, tend=1.0, nbIter=None, timeStep=None, - iterMax=1000): + def __init__(self, start=0.0, end=1.0, nb_iter=None, time_step=None, + max_iter=1000): """ - Creates a Timer. - @param tinit : Simulation starting time. - @param tend : Simulation final time. - @param nbIter : number of required iterations - @param timeStep : default time step - @param iterMax : maximum number of iterations (useful - only if timeStep is modified. See adaptativeTimeStep operator). - - If both timeStep and nbIter are given, timeStep is not used. - - Notation: - iteration number 'currentIteration' - between tk and tkp1 = tk + timeStep + Parameters + ---------- + start, end: real, optional + initial and final time for simulation + nb_iter : int, optional + number of iterations required + time_step : real, optional + max_iter : int, optional + maximum number of iterations allowed. + + Attributes + ---------- + time : real + current time (value at the end of the time step) + current_iteration : int + start at 0. See notes below. + is_over : bool + true if end or max_iter or nb_iter has been reached. + + Notes + ----- + * all parameters are optional but either time_step or nb_iter + must be set. + * If both time_step and nb_iter are given, time_step is not used. + * current_iteration = -1 means simulation has not started, and + self.time = self.start + * current_iteration = 0 after a call to initialize, + self.time = self.start + self.time_step, i.e. targeted time. + * self.current_iteration = k, runs between self.tk and self.tkp1. + with self.tkp1 == self.time + """ - ## Simulation final time - self.end = tend - ## Starting time - self.start = tinit - ## Simulation current time - self.time = tinit - ## Is simulation is terminated - self.isOver = False - ## Iteration counter - self.currentIteration = -1 - ## Number of iterations - if nbIter is not None: - self.nbIter = nbIter - if nbIter is not None and timeStep is not None: - print ('Warning : both nbIter and timeStep are given.\ - timeStep is ignored') - self.timeStep = (self.end - self.start) / self.nbIter - elif timeStep is not None: - ## Simulation time step - self.timeStep = timeStep + # Simulation final time + self.end = end + # Starting time + self.start = start + # Simulation current time + self.time = start + # Is simulation is terminated + self.is_over = False + # Iteration counter + self.current_iteration = -1 + # Number of iterations + if nb_iter is not None: + self.nb_iter = nb_iter + msg = '------------------------------------------------\n' + msg += 'Simulation warning : both nb_iter and time_step\n' + msg += ' are given, time step input will be ignored.\n' + msg += '------------------------------------------------\n' + + if nb_iter is not None and time_step is not None: + print (msg) + self.time_step = (self.end - self.start) / self.nb_iter + elif time_step is not None: + # Simulation time step + self.time_step = time_step else: - raise ValueError('You must set nbIter or timeStep value.') - self.iterMax = iterMax - assert iterMax >= nbIter - ## Starting time for the current iteration - self.tk = tinit - ## tk + dt - self.tkp1 = tinit + self.timeStep - self._lastStep = False + raise ValueError('You must set nb_iter or time_step value.') + # backup initial time step, required to reset simulation. + self._dt0 = self.time_step + self.max_iter = max_iter + assert max_iter >= nb_iter + # Starting time for the current iteration + self.tk = start + # tk + dt + self.tkp1 = start + self.time_step assert self.end > self.start, \ 'Final time must be greater than initial time' - assert (self.start + self.timeStep) <= self.end,\ + assert (self.start + self.time_step) <= self.end,\ 'start + step is bigger than end.' - ## Internal tolerance for timer + # Internal tolerance for timer self.tol = eps + # True if initialize has been called. + self._is_ready = False + self._next_is_last = False + + # splitting parameters, if set. Optional + self.split_id = None + self.current_dir = 0 + self.old_dir = 0 + self.sub_step = self.time_step def advance(self): + """Proceed to next time. + + * Advance time and iteration number. + * Compute the new timestep + * check if simulation is over. """ - Proceed to next time. - Advance time and iteration number. - Compute a timestep for the incoming iteration (from a vairable and - to reach the end of simulation) - """ - # Increment iteration counter - self.currentIteration += 1 - if self._lastStep: - # The timestep was adjusted to reach end in the previous call - # So now the simulation is over - self.isOver = True - else: - if self.currentIteration < self.iterMax: - # Advance time for the iteration just ended - self.tk = self.tkp1 - self.tkp1 = self.tk + self.timeStep - - # Adjust last timestep to reach self.end - if self.tkp1 > self.end: - self.timeStep = self.end - self.tk - if self.timeStep <= self.tol: - self.isOver = True - else: - self.tkp1 = self.end - self._lastStep = True - else: - # iteration number is reached - self.isOver = True + msg = 'simu.initialize() must be called before' + msg += ' the time simulation loop.' + assert self._is_ready, msg + if self.is_over: + return + if self._next_is_last: + self.is_over = True + return + self.tk = self.tkp1 + self.tkp1 = self.tk + self.time_step + if abs(self.tkp1 - self.end) <= self.tol: + self._next_is_last = True + elif self.tkp1 > self.end: + # resize ... + self._next_is_last = True + self.tkp1 = self.end + self.time_step = self.end - self.tk + self.current_iteration += 1 self.time = self.tkp1 - def updateTimeStep(self, newDt): - """ - Update current time step. - This function is usually called from Adapt_timestep operator. - """ - self.timeStep = newDt + if self.current_iteration + 2 > self.max_iter: + self._next_is_last = True + + def update_time_step(self, dt): + """Update time step for the next iteration + + Parameters + ----------- + dt: double + the new time step + + Notes + ----- + Warning : since it does not update tkp1 and time, + it must be called at the end of the time loop, just + before 'advance'. - def printState(self): """ - print current state + self.time_step = dt + + def print_state(self): + """Print current simulation parameters """ msg = "== Iteration : {0:3d}, from t = {1:6.5} to t = {2:6.5f} ==" - print (msg.format(self.currentIteration, self.tk, self.time)) + print (msg.format(self.current_iteration, self.tk, self.time)) def __str__(self): s = "Simulation parameters : " s += "from " + str(self.start) + ' to ' + str(self.end) - s += ', time step : ' + str(self.timeStep) + s += ', time step : ' + str(self.time_step) s += ', current time : ' + str(self.time) + ', iteration number : ' - s += str(self.currentIteration) + ', max number of iterations : ' - s += str(self.iterMax) + s += str(self.current_iteration) + ', max number of iterations : ' + s += str(self.max_iter) return s def initialize(self): + """(Re)set simulation to initial values + --> back to iteration 0 and ready to run. + """ self.tk = self.start - self.tkp1 = self.start + self.timeStep + self.time_step = self._dt0 + self.tkp1 = self.start + self.time_step + assert self.tkp1 <= self.end self.time = self.tkp1 - self.isOver = False - self.currentIteration = 0 - self._lastStep = False + self.is_over = False + self.current_iteration = 0 + self._is_ready = True + self._next_is_last = False + + def set_split(self, split_id, split): + self.split_id = split_id + self.sub_step = split[1] * self.time_step + self.current_dir = split[0] + + def next_split(self): + self.old_dir = self.current_dir def finalize(self): + """Use this function when you need to call an hdf i/o operator + after the end of the time-loop. """ - Useful for printers if printer.frequency is not 1 - """ - self.isOver = True - self.currentIteration = -1 + self.is_over = True + self.current_iteration = -1 + + diff --git a/hysop/problem/tests/test_simulation.py b/hysop/problem/tests/test_simulation.py index 8a7ae1264..beb982de0 100755 --- a/hysop/problem/tests/test_simulation.py +++ b/hysop/problem/tests/test_simulation.py @@ -5,52 +5,52 @@ tests simulation incr and io_utils writer from hysop.problem.simulation import Simulation from hysop.tools.io_utils import Writer, IOParams, IO -simu = Simulation(tinit=0.0, tend=1.0, nbIter=10) +simu = Simulation(start=0.0, end=1.0, nb_iter=10) def test_simu_incr(): io_params = IOParams(filename='temp_test', frequency=2, fileformat=IO.ASCII) wr = Writer(io_params) - assert wr.do_write(simu.currentIteration) + assert wr.do_write(simu.current_iteration) simu.initialize() - assert not wr.do_write(simu.currentIteration) + assert not wr.do_write(simu.current_iteration) count = 1 - while not simu.isOver: + while not simu.is_over: if count % 2 == 0: - assert wr.do_write(simu.currentIteration) + assert wr.do_write(simu.current_iteration) else: - assert not wr.do_write(simu.currentIteration) - simu.printState() + assert not wr.do_write(simu.current_iteration) + simu.print_state() simu.advance() count += 1 - assert simu.currentIteration == 10 + assert simu.current_iteration == 10 simu.finalize() - assert wr.do_write(simu.currentIteration) + assert wr.do_write(simu.current_iteration) def test_simu_incr2(): io_params = IOParams(filename='temp_test', frequency=3, fileformat=IO.ASCII) wr = Writer(io_params) - assert wr.do_write(simu.currentIteration) - simu.timeStep = 0.10000000001 + assert wr.do_write(simu.current_iteration) + simu.time_step = 0.10000000001 simu.initialize() - assert not wr.do_write(simu.currentIteration) + assert not wr.do_write(simu.current_iteration) count = 1 - while not simu.isOver: + while not simu.is_over: if count % 3 == 0: - assert wr.do_write(simu.currentIteration) + assert wr.do_write(simu.current_iteration) else: - assert not wr.do_write(simu.currentIteration) - simu.printState() + assert not wr.do_write(simu.current_iteration) + simu.print_state() simu.advance() count += 1 - assert simu.currentIteration == 10 + assert simu.current_iteration == 10 simu.finalize() - assert wr.do_write(simu.currentIteration) + assert wr.do_write(simu.current_iteration) diff --git a/hysop/problem/tests/test_transport.py b/hysop/problem/tests/test_transport.py index a96d98a19..3b4fbe77b 100644 --- a/hysop/problem/tests/test_transport.py +++ b/hysop/problem/tests/test_transport.py @@ -48,7 +48,7 @@ def rotating_velocity_2D(x, y, t): return -c * y, c * x -def assertion(dim, boxLength, boxMin, nbElem, finalTime, timeStep, +def assertion(dim, boxLength, boxMin, nbElem, finalTime, time_step, s, v, rtol=1e-05, atol=1e-08): box = Box(length=boxLength, origin=boxMin) print "domain init ...", id(box) @@ -56,7 +56,7 @@ def assertion(dim, boxLength, boxMin, nbElem, finalTime, timeStep, velo = Field(domain=box, formula=v, vectorize_formula=True, name='Velocity', is_vector=True) advec = Advection(velo, scal, discretization=Discretization(nbElem)) - simu = Simulation(tinit=0.0, tend=finalTime, timeStep=timeStep, iterMax=1) + simu = Simulation(start=0.0, end=finalTime, time_step=time_step, max_iter=1) print "velo dom ...", id(velo.domain) print "scal dom ...", id(scal.domain) pb = TransportProblem([advec], simu) @@ -73,10 +73,10 @@ def test_nullVelocity_2D(): boxLength = [1., 1.] boxMin = [0., 0.] nbElem = [nb, nb] - timeStep = 0.01 - finalTime = timeStep + time_step = 0.01 + finalTime = time_step assert assertion(dim, boxLength, boxMin, - nbElem, finalTime, timeStep, + nbElem, finalTime, time_step, lambda x, y, t: np.random.random(), lambda x, y, t: (0., 0.)) @@ -87,10 +87,10 @@ def test_nullVelocity_3D(): boxLength = [1., 1., 1.] boxMin = [0., 0., 0.] nbElem = [nb, nb, nb] - timeStep = 0.01 - finalTime = timeStep + time_step = 0.01 + finalTime = time_step assert assertion(dim, boxLength, boxMin, - nbElem, finalTime, timeStep, + nbElem, finalTime, time_step, lambda x, y, z, t: np.random.random(), lambda x, y, z, t: (0., 0., 0.)) @@ -101,10 +101,10 @@ def test_gaussian_2D(): boxLength = [2., 2.] boxMin = [-1., -1.] nbElem = [nb, nb] - timeStep = 0.001 - finalTime = timeStep + time_step = 0.001 + finalTime = time_step assert assertion(dim, boxLength, boxMin, - nbElem, finalTime, timeStep, + nbElem, finalTime, time_step, gaussian_scalar_2D, rotating_velocity_2D, rtol=1e-04, atol=1e-05) @@ -115,10 +115,10 @@ def test_cosinus_translation_2D(): boxLength = [2., 2.] boxMin = [-1., -1.] nbElem = [nb, nb] - timeStep = 1. + time_step = 1. finalTime = 1. assert assertion(dim, boxLength, boxMin, - nbElem, finalTime, timeStep, + nbElem, finalTime, time_step, cosinus_product_2D, lambda x, y, t: (1., 2.)) @@ -129,9 +129,9 @@ def test_cosinus_translation_3D(): boxLength = [2., 2., 2.] boxMin = [-1., -1., -1.] nbElem = [nb, nb, nb] - timeStep = 1. - finalTime = timeStep + time_step = 1. + finalTime = time_step assert assertion(dim, boxLength, boxMin, - nbElem, finalTime, timeStep, + nbElem, finalTime, time_step, cosinus_product_3D, lambda x, y, z, t: (1., 2., 0.5)) -- GitLab