diff --git a/examples/analytic/analytic.py b/examples/analytic/analytic.py index 631e14b44f8f8e36b9752f6786f7be6440dab4dc..39f15a551b0fcdc4590db33d33fc0fd9aa642030 100755 --- a/examples/analytic/analytic.py +++ b/examples/analytic/analytic.py @@ -1,63 +1,64 @@ #!/usr/bin/env python2 import numpy as np import sympy as sm - + + def compute(args): ''' HySoP Analytic Example: Initialize a field with a space and time dependent analytic formula. ''' from hysop import Field, Box, IOParams, MPIParams, \ - Simulation, Problem, ScalarParameter + Simulation, Problem, ScalarParameter from hysop.constants import Implementation from hysop.operators import AnalyticField, HDF_Writer - + # Define domain npts = args.npts - box = Box(origin=args.box_origin, length=args.box_length, dim=args.ndim) - + box = Box(origin=args.box_origin, length=args.box_length, dim=args.ndim) + # Define parameters and field (time and analytic field) - t = ScalarParameter('t', dtype=args.dtype) + t = ScalarParameter('t', dtype=args.dtype) scalar = Field(domain=box, name='S0', dtype=args.dtype) - + # We need to first get default MPI parameters (even for non MPI jobs) # so we use default domain communicator and task. mpi_params = MPIParams(comm=box.task_comm, task_id=box.current_task()) - + # Setup implementation specific variables impl = args.impl op_kwds = {'mpi_params': mpi_params} if (impl is Implementation.PYTHON): # Setup python specific extra operator keyword arguments # (mapping: variable name => variable value) - op_kwds['extra_input_kwds'] = {'t': t} + op_kwds['extra_input_kwds'] = {'t': t} elif (impl is Implementation.OPENCL): # For the OpenCL implementation we need to setup the compute device # and configure how the code is generated and compiled at runtime. - + # Create an explicit OpenCL context from user parameters from hysop.backend.device.opencl.opencl_tools import get_or_create_opencl_env, get_device_number cl_env = get_or_create_opencl_env( mpi_params=mpi_params, - platform_id=args.cl_platform_id, - device_id=box.machine_rank%get_device_number() if args.cl_device_id is None else None) + platform_id=args.cl_platform_id, + device_id=box.machine_rank % get_device_number() if args.cl_device_id is None else None) # Configure OpenCL kernel generation and tuning (already done by HysopArgParser) from hysop.methods import OpenClKernelConfig method = {OpenClKernelConfig: args.opencl_kernel_config} - + # Setup opencl specific extra operator keyword arguments - op_kwds['cl_env'] = cl_env - op_kwds['method'] = method + op_kwds['cl_env'] = cl_env + op_kwds['method'] = method else: - msg='Unknown implementation \'{}\'.'.format(impl) + msg = 'Unknown implementation \'{}\'.'.format(impl) raise ValueError(msg) - + # Analytic initialization method depends on chosen implementation if (impl is Implementation.PYTHON): # With the python implementation we can directly use a python method # (using numpy arrays). Here each field component is stored in the - # tuple 'data'. Coordinates will be passed as a tuple as a second + # tuple 'data'. Coordinates will be passed as a tuple as a second # argument. Finally extra arguments (here t) are passed last. # Note that t is a ScalarParameter, so we evaluate it to get its value. def compute_scalar(data, coords, component, t): @@ -77,21 +78,21 @@ def compute(args): for xi in xs: compute_scalar *= sm.cos(xi-ts) else: - msg='Unknown implementation {}.'.format(impl) - + msg = 'Unknown implementation {}.'.format(impl) + # Finally build the operator - analytic = AnalyticField(name='analytic', - field=scalar, formula=compute_scalar, - variables = {scalar: npts}, implementation=impl, - **op_kwds) + analytic = AnalyticField(name='analytic', + field=scalar, formula=compute_scalar, + variables={scalar: npts}, implementation=impl, + **op_kwds) # Write output field at given frequency io_params = IOParams(filename='analytic', frequency=args.dump_freq) df = HDF_Writer(name='S', - io_params=io_params, - variables={scalar: npts}, - **op_kwds) - + io_params=io_params, + variables={scalar: npts}, + **op_kwds) + # Create the problem we want to solve and insert our operator problem = Problem() problem.insert(analytic, df) @@ -102,36 +103,36 @@ def compute(args): if args.display_graph: problem.display(args.visu_rank) - # Create a simulation and solve the problem + # Create a simulation and solve the problem # (do not forget to specify the time parameter here) - simu = Simulation(start=args.tstart, end=args.tend, - nb_iter=args.nb_iter, dt0=args.dt, - max_iter=args.max_iter, + simu = Simulation(start=args.tstart, end=args.tend, + nb_iter=args.nb_iter, dt0=args.dt, + max_iter=args.max_iter, times_of_interest=args.dump_times, t=t) - - # Finally solve the problem + + # Finally solve the problem problem.solve(simu, dry_run=args.dry_run) - + # Finalize problem.finalize() -if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors - +if __name__ == '__main__': + from hysop.examples.example_utils import HysopArgParser, colors + prog_name = 'analytic' default_dump_dir = '{}/hysop_examples/{}'.format(HysopArgParser.tmp_dir(), prog_name) - description=colors.color('HySoP Analytic Example: ', fg='blue', style='bold') - description+='Initialize a field with a space and time dependent analytic formula.' + description = colors.color('HySoP Analytic Example: ', fg='blue', style='bold') + description += 'Initialize a field with a space and time dependent analytic formula.' parser = HysopArgParser(prog_name=prog_name, - description=description, - default_dump_dir=default_dump_dir) + description=description, + default_dump_dir=default_dump_dir) - parser.set_defaults(box_start=(0.0,), box_length=(2*np.pi,), - tstart=0.0, tend=10.0, nb_iter=100, - dump_freq=5) + parser.set_defaults(box_start=(0.0,), box_length=(2*np.pi,), + tstart=0.0, tend=10.0, nb_iter=100, + dump_freq=5) parser.run(compute) diff --git a/examples/bubble/periodic_bubble.py b/examples/bubble/periodic_bubble.py index af738c800b67e56f6653af9c5a652238dd4a9d76..5de7e1e0e894438edd8a1847b74f221498f83b35 100644 --- a/examples/bubble/periodic_bubble.py +++ b/examples/bubble/periodic_bubble.py @@ -302,7 +302,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class PeriodicBubbleArgParser(HysopArgParser): def __init__(self): diff --git a/examples/bubble/periodic_bubble_levelset.py b/examples/bubble/periodic_bubble_levelset.py index 810a926e963a76e365ee9bd4a85ef3e90951b4f4..237bf8f67da57cbc7201148d8745e97bc17e3c4d 100644 --- a/examples/bubble/periodic_bubble_levelset.py +++ b/examples/bubble/periodic_bubble_levelset.py @@ -300,7 +300,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class PeriodicBubbleArgParser(HysopArgParser): def __init__(self): diff --git a/examples/bubble/periodic_bubble_levelset_penalization.py b/examples/bubble/periodic_bubble_levelset_penalization.py index 05a3ef5d5763c25bfc0396b2a224d31b1faa3f8f..7cf865cca6289c92a78ff471171c812476bafdd6 100644 --- a/examples/bubble/periodic_bubble_levelset_penalization.py +++ b/examples/bubble/periodic_bubble_levelset_penalization.py @@ -342,7 +342,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class PeriodicBubbleArgParser(HysopArgParser): def __init__(self): diff --git a/examples/bubble/periodic_jet_levelset.py b/examples/bubble/periodic_jet_levelset.py index ac99a865cfba414847367fbdf70957f0faf134e1..9607f8fde2e3ecd12d081d30888496cc46cb58d9 100644 --- a/examples/bubble/periodic_jet_levelset.py +++ b/examples/bubble/periodic_jet_levelset.py @@ -287,7 +287,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class PeriodicJetArgParser(HysopArgParser): def __init__(self): diff --git a/examples/cylinder/oscillating_cylinder.py b/examples/cylinder/oscillating_cylinder.py index 73f3e41df6bbdac3ff9ea2bdeaeacf9872797974..b51b858819bb400e551d141773a27cae4f77313d 100644 --- a/examples/cylinder/oscillating_cylinder.py +++ b/examples/cylinder/oscillating_cylinder.py @@ -260,7 +260,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class OscillatingCylinderArgParser(HysopArgParser): def __init__(self): diff --git a/examples/fixed_point/heat_equation.py b/examples/fixed_point/heat_equation.py index 518a773813524c64f33b4f973e1ddfeca2a0cecd..d54e802acb102d1ae11864752f7ab31dfa04e91b 100644 --- a/examples/fixed_point/heat_equation.py +++ b/examples/fixed_point/heat_equation.py @@ -197,7 +197,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class IMArgParser(HysopArgParser): def __init__(self): diff --git a/examples/flow_around_sphere/flow_around_sphere.py b/examples/flow_around_sphere/flow_around_sphere.py index 807d0d26c20d2b8278d0fbced56498d3d18fcb2c..f01e5f9ef41c2abccfbf9951a96222ecaf7e9611 100644 --- a/examples/flow_around_sphere/flow_around_sphere.py +++ b/examples/flow_around_sphere/flow_around_sphere.py @@ -327,7 +327,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors parser = HysopArgParser(prog_name="FlowAroundSphere", description="""HySoP flow around a sphere.\n""", default_dump_dir='{}/hysop_examples/FlowAroundSphere'.format( diff --git a/examples/multiresolution/scalar_advection.py b/examples/multiresolution/scalar_advection.py index 82e805e2b91c43f20e59fa2ae97522377c65aa29..98b763292636f9d93457308e4466e423ed4a6d8b 100644 --- a/examples/multiresolution/scalar_advection.py +++ b/examples/multiresolution/scalar_advection.py @@ -189,7 +189,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class MultiResolutionScalarAdvectionArgParser(HysopArgParser): def __init__(self): diff --git a/examples/particles_above_salt/particles_above_salt_bc.py b/examples/particles_above_salt/particles_above_salt_bc.py index ce823f8c30da311706dc48e207ad71466d90c092..807120e6b91b04dbc1cda2fb48ee055b970569cb 100644 --- a/examples/particles_above_salt/particles_above_salt_bc.py +++ b/examples/particles_above_salt/particles_above_salt_bc.py @@ -323,7 +323,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ParticleAboveSaltArgParser(HysopArgParser): def __init__(self): diff --git a/examples/particles_above_salt/particles_above_salt_bc_3d.py b/examples/particles_above_salt/particles_above_salt_bc_3d.py index afcdbf826ab17ca8d6803a86b0329e250c41c7e8..3bd83aeb8ac50be9fe9d89a7d3f23de31bc11fb3 100644 --- a/examples/particles_above_salt/particles_above_salt_bc_3d.py +++ b/examples/particles_above_salt/particles_above_salt_bc_3d.py @@ -338,7 +338,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ParticleAboveSaltArgParser(HysopArgParser): def __init__(self): diff --git a/examples/particles_above_salt/particles_above_salt_periodic.py b/examples/particles_above_salt/particles_above_salt_periodic.py index 8a6fcb237de981178f9c79e32bb6239d9d67380c..8eaac49a29d3f76553a35e4de668e5f84bd5caba 100644 --- a/examples/particles_above_salt/particles_above_salt_periodic.py +++ b/examples/particles_above_salt/particles_above_salt_periodic.py @@ -333,7 +333,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ParticleAboveSaltArgParser(HysopArgParser): def __init__(self): diff --git a/examples/particles_above_salt/particles_above_salt_symmetrized.py b/examples/particles_above_salt/particles_above_salt_symmetrized.py index 904de36a616854db2c187128c198d33954f93ba9..f7a393327fd98c6af407c0735f24185aa9c342f9 100644 --- a/examples/particles_above_salt/particles_above_salt_symmetrized.py +++ b/examples/particles_above_salt/particles_above_salt_symmetrized.py @@ -320,7 +320,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ParticleAboveSaltArgParser(HysopArgParser): def __init__(self): diff --git a/examples/scalar_advection/levelset.py b/examples/scalar_advection/levelset.py index 045bb3330086091ad52e75f5f70bd646c2d6a6bb..8e8dbe82c9fe96572097611f87375fdb7bcf86e1 100644 --- a/examples/scalar_advection/levelset.py +++ b/examples/scalar_advection/levelset.py @@ -215,7 +215,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class LevelsetArgParser(HysopArgParser): def __init__(self): diff --git a/examples/scalar_advection/scalar_advection.py b/examples/scalar_advection/scalar_advection.py index 7b133555eaf2fd9759bded5a4b3c4cfd5aed4a43..0e061844a910454eefe79b3e126c898ae3c131e4 100644 --- a/examples/scalar_advection/scalar_advection.py +++ b/examples/scalar_advection/scalar_advection.py @@ -142,7 +142,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ScalarAdvectionArgParser(HysopArgParser): def __init__(self): diff --git a/examples/scalar_diffusion/scalar_diffusion.py b/examples/scalar_diffusion/scalar_diffusion.py index 170359e4181a670c6c324018f24bc6f0e6f583ae..085664f096eb19369944a2d59f18d46b33fb3503 100755 --- a/examples/scalar_diffusion/scalar_diffusion.py +++ b/examples/scalar_diffusion/scalar_diffusion.py @@ -118,7 +118,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ScalarDiffusionArgParser(HysopArgParser): def __init__(self): diff --git a/examples/sediment_deposit/sediment_deposit.py b/examples/sediment_deposit/sediment_deposit.py index 3041c495b42494cd0d85ac6d65d2b07e00708a80..ea0b53c941f56b311bc48154f31ab12d43a4642c 100644 --- a/examples/sediment_deposit/sediment_deposit.py +++ b/examples/sediment_deposit/sediment_deposit.py @@ -334,7 +334,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ParticleAboveSaltArgParser(HysopArgParser): def __init__(self): diff --git a/examples/sediment_deposit/sediment_deposit_levelset.py b/examples/sediment_deposit/sediment_deposit_levelset.py index 5f5beda14f0bdca5d2c8e26daf973ce379981210..bb566be49c3d933f086a9d17493ac068cdf24ce8 100644 --- a/examples/sediment_deposit/sediment_deposit_levelset.py +++ b/examples/sediment_deposit/sediment_deposit_levelset.py @@ -395,7 +395,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ParticleAboveSaltArgParser(HysopArgParser): def __init__(self): diff --git a/examples/shear_layer/shear_layer.py b/examples/shear_layer/shear_layer.py index 520d42899942b7a3868b3961a7a9279df2dc4433..29a14fad5ae6c7614e93fe31d179e42a52d82706 100644 --- a/examples/shear_layer/shear_layer.py +++ b/examples/shear_layer/shear_layer.py @@ -205,7 +205,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class ShearLayerArgParser(HysopArgParser): def __init__(self): diff --git a/examples/taylor_green/taylor_green.py b/examples/taylor_green/taylor_green.py index a8d07d76fa12605817c88997ce6bb65daedb8239..1d544f4d7933ccceacec954a264ef95669a0c16e 100644 --- a/examples/taylor_green/taylor_green.py +++ b/examples/taylor_green/taylor_green.py @@ -315,7 +315,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class TaylorGreenArgParser(HysopArgParser): def __init__(self): diff --git a/examples/taylor_green/taylor_green_cpuFortran.py b/examples/taylor_green/taylor_green_cpuFortran.py index cc575e98a1fdea7e88dcf2663be590595a0a749c..d89e280f7bd936f267674de167cba101191cb8a8 100644 --- a/examples/taylor_green/taylor_green_cpuFortran.py +++ b/examples/taylor_green/taylor_green_cpuFortran.py @@ -232,7 +232,7 @@ def compute(args): if __name__=='__main__': - from examples.example_utils import HysopArgParser, colors + from hysop.examples.example_utils import HysopArgParser, colors class TaylorGreenArgParser(HysopArgParser): def __init__(self): diff --git a/examples/__init__.py b/hysop/examples/__init__.py similarity index 100% rename from examples/__init__.py rename to hysop/examples/__init__.py diff --git a/examples/example_utils.py b/hysop/examples/example_utils.py similarity index 100% rename from examples/example_utils.py rename to hysop/examples/example_utils.py