Difference between revisions of "Writing a Custom Task"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
This page explains how to create a new [[MPM Calculations | This page explains how to create a new [[MPM Calculations]] and integrate it into [[NairnMPM]]. Custom tasks can be used to add many new features to the code, including now ways to export results for visualization. | ||
== Basic Steps == | == Basic Steps == | ||
The first steps create the task and allow it to be used in calculations | |||
* Create a new source code class that inherits from the <tt>CustomTask</tt> class (or a subclass of that class). | |||
* Create instance of this new task in <tt>MPMReadHandler::myStartElement()</tt>when an input file wants to use the new task: | |||
** See section for tag <tt>Schedule</tt> | ** See section for tag <tt>Schedule</tt> | ||
** New instance created as determined by the <tt>name</tt> attribute of the tag | ** New instance created as determined by the <tt>name</tt> attribute of the tag | ||
** This change should be the only change done to the core code. | ** This change should be the only change done to the core code. | ||
* Support methods listed below (as needed) in the new custom task. Most methods return the <tt>nextTask</tt> because the calling code uses it when it loops over all custom tasks. Any that are not needed can be omitted because the <tt>CustomTask</tt> class provides methods that simply returns the <tt>nextTask</tt>. Custom tasks are done at the end of the time step in the <tt>MPMStep()</tt> code. | |||
== Task Parameters == | == Task Parameters == |
Revision as of 10:39, 9 February 2014
This page explains how to create a new MPM Calculations and integrate it into NairnMPM. Custom tasks can be used to add many new features to the code, including now ways to export results for visualization.
Basic Steps
The first steps create the task and allow it to be used in calculations
- Create a new source code class that inherits from the CustomTask class (or a subclass of that class).
- Create instance of this new task in MPMReadHandler::myStartElement()when an input file wants to use the new task:
- See section for tag Schedule
- New instance created as determined by the name attribute of the tag
- This change should be the only change done to the core code.
- Support methods listed below (as needed) in the new custom task. Most methods return the nextTask because the calling code uses it when it loops over all custom tasks. Any that are not needed can be omitted because the CustomTask class provides methods that simply returns the nextTask. Custom tasks are done at the end of the time step in the MPMStep() code.
Task Parameters
If the custom task has parameters, implement them by reading them with:
- char *CustomTask::InputParam(char *pName,int &input) - Check the parameter name in pName. If it matches a defined task parameter name set input to the kind of pointer needed and return the actual pointer to the class variable for that parameter. If no match return NULL. This is the only method that does not return nextTask.
Initialize
- CustomTask *CustomTask::Initialize() - This method is called once at beginning of the entire MPM analysis. Do any initialization and print info about the task using cout. Anything printed will by in the custom tasks section of the results file.
Step Tasks
In each time step, the custom tasks is called through various methods. Your new tasks can implement those that are needed.
Prepare Custom Task
- CustomTask *MyTask::PrepareForStep(bool &doExtraps) - This method is called in MPMStep() just before custom tasks are done. You can use it to initialize variables. If the task needs extrapolations to the grids or summations over particles, set doExtraps to TRUE.
Custom Extrapolatlions
The following methods are in a loop which allows a custom task to extrapolate some property to the grid or do some other calculation requiring a loop over all particles:
- `CustomTask *MyTask::BeginExtrapolations(void)` - Called once before extrapolation loop begins. Initialize any required variables.
- `CustomTask *MyTask::NodalExtrapolation(NodalPoint *ndmi,MPMBase *mpnt,short vfld,int matfld,double wt)` - Called repeatedly in the loop for each particle/node pair. `vfld` is the velocity field, `matfld` is material valocity filed (when in multimaterial mode), and `wt` is the weight (or mass times shape function). Can use to extrapolate particle data to the grid.
- `CustomTask *CustomTask::ParticleCalculation(NodalPoint *ndmi,MPMBase *mpnt,short vfld,int matfld, double fn,double xDeriv,double yDeriv,double zDeriv)` - Called repeatedly in the loop for each particle/node pair. `vfld` is the velocity field, `matfld` is material valocity filed (when in multimaterial mode), and `wt` is the weight (or mass times shape function). Can use to extrapolate nodal values to the particles.
- `CustomTask *MyTask::ParticleExtrapolation(MPMBase *mpnt)` - Called once for each particle. Can use to sum any quantity over the particles.
- `CustomTask *MyTask::EndExtrapolations(void)` - Called once when extrapolations are over. Use to free anything allocated during the extrapolations or to do some calculations.
Custom Task Calculations
- `CustomTask *MyTask::StepCalculation(void)` - This method is the usually the main part of any custom task. Do the desired calculations. The code will have access to all global variables.
Step 7d: Custom Finish
- `CustomTask *MyTask::FinishForStep(void)` - Called once when all custom tasks are done. Use to free up any memory still allocated by the task.