An implementation of a general solver base class
Bases: object
Base class for all PySPH Solvers
Constructor
Any additional keyword args are used to set the values of any of the attributes.
>>> integrator = PECIntegrator(fluid=WCSPHStep())
>>> kernel = CubicSpline(dim=2)
>>> solver = Solver(dim=2, integrator=integrator, kernel=kernel,
... n_damp=50, tf=1.0, dt=1e-3, adaptive_timestep=True,
... pfreq=100, cfl=0.5, output_at_times=[1e-1, 1.0])
These callbacks are called after each integrator stage.
The callbacks are passed (current_time, dt, stage). See the the Integrator.one_timestep methods for examples of how this is called.
>>> def post_stage_callback_function(t, dt, stage):
>>> # This function is called after every stage of integrator.
>>> print t, dt, stage
>>> # Do something
>>> solver.add_post_stage_callback(post_stage_callback_function)
These callbacks are called after each timestep is performed.
The callbacks are passed the solver instance (i.e. self).
>>> def post_step_callback_function(solver):
>>> # This function is called after every time step.
>>> print solver.t, solver.dt
>>> # Do something
>>> solver.add_post_step_callback(post_step_callback_function)
These callbacks are called before each timestep is performed.
The callbacks are passed the solver instance (i.e. self).
>>> def pre_step_callback_function(solver):
>>> # This function is called before every time step.
>>> print solver.t, solver.dt
>>> # Do something
>>> solver.add_pre_step_callback(pre_step_callback_function)
Dump the simulation results to file
The arrays used for printing are determined by the particle array’s output_property_arrays data attribute. For debugging it is sometimes nice to have all the arrays (including accelerations) saved. This can be chosen from using the command line option –detailed-output
Output data Format:
A single file named as: <fname>_<rank>_<iteration_count>.npz
The data is saved as a Python dictionary with two keys:
solver_data : Solver meta data like time, dt and iteration number
particle properties as value.
Example:
You can load the data output by PySPH like so:
>>> from pysph.solver.utils import load
>>> data = load('output_directory/filename_x_xxx.npz')
>>> solver_data = data['solver_data']
>>> arrays = data['arrays']
>>> fluid = arrays['fluid']
>>> ...
In the above example, it is assumed that the output file contained an array named fluid.
Load particle data from dumped output file.
Data is loaded from the output_directory using the same format as stored by the dump_output() method. Proper functioning required that all the relevant properties of arrays be dumped.
Set it to True to use adaptive timestepping based on cfl, viscous and force factor.
Look at pysph.sph.integrator.compute_time_step for more details.
set the callable to be called at every command_interval iteration
the callable is called with the solver instance as an argument
Set the default solver dump mode in parallel.
The available modes are:
distributed : Each processor dumps a file locally.
Setup the solver.
The solver’s processor id is set if the in_parallel flag is set to true.
The order of the integrating calcs is determined by the solver’s order attribute.
This is usually called at the start of a PySPH simulation.
Implement the basic solvers here
All subclasses of Solver may implement this function to add the necessary operations for the problem at hand.
Look at solver/fluid_solver.py for an example.