Module application¶
-
class
pysph.solver.application.
Application
(fname=None, output_dir=None, domain=None)[source]¶ Bases:
object
Subclass this to run any SPH simulation. There are several important methods that this class provides. The application is typically used as follows:
class EllipticalDrop(Application): def create_particles(self): # ... def create_scheme(self): # ... ... app = EllipticalDrop() app.run() app.post_process(app.info_filename)
The
post_process()
method is entirely optional and typically performs the post-processing. It is important to understand the correct sequence of the method calls. When theApplication
instance is created, the following methods are invoked by the__init__()
method:initialize()
: use this to setup any constants etc.create_scheme()
: this needs to be overridden if one wishes to use apysph.sph.scheme.Scheme
. If one does not want to use a scheme, thecreate_equations()
andcreate_solver()
methods must be overridden.self.scheme.add_user_options()
: i.e. the scheme’s command line options are added, if there is a scheme.add_user_options()
: add any user specified command line options.
When
app.run()
is called, the following methods are called in order:_parse_command_line()
: this is a private method but it is important to note that the command line arguments are first parsed.consume_user_options()
: this is called right after the command line args are parsed.configure_scheme()
: This is where one may configure the scheme according to the passed command line arguments.create_solver()
: Create the solver, note that this is needed only if one has not used a scheme, otherwise, this will by default return the solver created by the scheme chosen.create_equations()
: Create any equations. Defaults to letting the scheme generate and return the desired equations.create_particles()
create_inlet_outlet()
create_domain()
: Not needed for non-periodic domains.create_nnps()
: Not needed unless one wishes to override the default NNPS.create_tools()
: Add anypysph.solver.tools.Tool
instances.customize_output()
: Customize the output visualization.
Additionally, as the application runs there are several convenient optional callbacks setup:
pre_step()
: Called before each time step.post_stage()
: Called after every stage of the integration.post_step()
: Called after each time step.
Finally, it is a good idea to overload the
post_process()
method to perform any post processing for the generated data.The application instance also has several important attributes, some of these are as follows:
args
: command line arguments, typicallysys.argv[1:]
.domain
: optionalpysph.base.nnps_base.DomainManager
instance.fname
: filename pattern to use when dumping output.inlet_outlet
: list of inlet/outlets.nnps
: instance ofpysph.base.nnps_base.NNPS
.num_procs
: total number of processes running.output_dir
: Output directory.parallel_manager
: in parallel, an instance ofpysph.parallel.parallel_manager.ParallelManager
.particles
: list ofpysph.base.particle_array.ParticleArray
.rank
: Rank of this process.scheme
: the optionalpysph.sph.scheme.Scheme
instance.solver
: the solver instance,pysph.solver.solver.Solver
.tools
: a list of possiblepysph.solver.tools.Tool
.
Constructor
Parameters: - fname (str) – file name to use for the output files.
- output_dir (str) – output directory name.
- domain (pysph.base.nnps_base.DomainManager) – A domain manager to use. This is used for periodic domains etc.
-
add_tool
(tool)[source]¶ Add a
pysph.solver.tools.Tool
instance to the application.
-
add_user_options
(group)[source]¶ Add any user-defined options to the given option group.
Note
This uses the argparse module.
-
configure_scheme
()[source]¶ This is called after
consume_user_options()
is called. One can configure the SPH scheme here as at this point all the command line options are known.
-
consume_user_options
()[source]¶ This is called right after the command line arguments are parsed.
All the parsed options are available in
self.options
and can be used in this method.This is meant to be overridden by users to setup any internal variables etc. that depend on the command line arguments passed. Note that this method is called well before the solver or particles are created.
-
create_domain
()[source]¶ Create a pysph.base.nnps_base.DomainManager and return it if needed.
This is used for periodic domains etc. Note that if the domain is passed to
__init__()
, then this method is not called.
-
create_inlet_outlet
(particle_arrays)[source]¶ Create inlet and outlet objects and return them as a list.
The method is passed a dictionary of particle arrays keyed on the name of the particle array.
-
create_nnps
()[source]¶ Create any NNPS if desired and return it, else a default NNPS will be created automatically.
-
create_scheme
()[source]¶ Create a suitable SPH scheme and return it.
Note that this method is called after the arguments are all processed and after
consume_user_options()
is called.
-
create_tools
()[source]¶ Create any tools and return a sequence of them. This method is called after particles/inlets etc. are all setup, configured etc.
-
customize_output
()[source]¶ Customize the output file visualization by adding any files.
For example, the pysph view command will look for a
mayavi_config.py
file that can be used to script the viewer. You can use self._mayavi_config(‘code’) to add a default customization here.Note that this is executed before the simulation starts.
-
post_process
(info_fname_or_directory)[source]¶ Given an info filename or a directory containing the info file, read the information and do any post-processing of the results. Please overload the method to perform any processing.
The info file has a few useful attributes and can be read using the
read_info()
method.The output_files property should provide the output files generated.
-
post_stage
(current_time, dt, stage)[source]¶ If overloaded, this is called automatically after each integrator stage, i.e. if the integrator is a two stage integrator it will be called after the first and second stages.
The method is passed (current_time, dt, stage). See the the
pysph.sph.integrator.Integrator.one_timestep()
methods for examples of how this is called.
-
post_step
(solver)[source]¶ If overloaded, this is called automatically after each integrator step. The method is passed the solver instance.
-
pre_step
(solver)[source]¶ If overloaded, this is called automatically before each integrator step. The method is passed the solver instance.
-
read_info
(fname_or_dir)[source]¶ Read the information from the given info file (or directory containing the info file, the first found info file will be used).
-
run
(argv=None)[source]¶ Run the application.
This basically calls
setup()
and thensolve()
.Parameters: argv (list) – Optional command line arguments. Handy when running interactively.
-
setup
(argv=None)[source]¶ Setup the application.
This may be used to setup the various pieces of infrastructure to run an SPH simulation, for example, this will parse the command line arguments passed, setup the scheme, solver, equations etc. It will not call the solver’s solve method though. This can be useful if you wish to manually run the solver.
Parameters: argv (list) – Optional command line arguments. Handy when running interactively.