Difference between revisions of "Creating MPM Materials"

From OSUPDOCS
Jump to navigation Jump to search
Line 3: Line 3:
== Getting Started ==
== Getting Started ==


The first steps are to add a new class to NairnMPM and to allow input command files to use that material. These steps involve creating the source code and some editing of the core code to add the new material class.
The first steps are to create source files for the new material class, to give the material a unique name, and to allow the main [[NairnMPM]] code to instantiate the material class when it is needed for a particle.


== Class Source Code ==
=== Class Source Code ===


The best way to create the source code is to duplicate the <tt>NewMaterial.cpp</tt> and <tt>NewMaterial.hpp</tt> files, which are templates for a new material class. Edit the files and change <tt>NewMaterial</tt> to the new material's class name. This template is a subclass of <tt>MaterialBase</tt>. Normally the new material will be a subclass of another class. If so, change <tt>MaterialBase</tt> references, as needed, to the actual parent class. These changes are needed whenever a method in the new material class needs to pass control to its immediate super class.
The best way to create the source code is to duplicate the <tt>NewMaterial.cpp</tt> and <tt>NewMaterial.hpp</tt> files, which are templates for a new material class. Edit the files and change <tt>NewMaterial</tt> to the new material's class name. This template is a subclass of <tt>MaterialBase</tt>. Normally the new material will be a subclass of another class. If so, change <tt>MaterialBase</tt> references, as needed, to the actual parent class. These changes are needed whenever a method in the new material class needs to pass control to its immediate super class.
Line 17: Line 17:
All documented materials use low numbers (starting with 1). To avoid conflicts, those working on custom materials should use large number (>100).
All documented materials use low numbers (starting with 1). To avoid conflicts, those working on custom materials should use large number (>100).


== Editing Required in Core Code ==
=== Editing Required in Core Code ===


Almost all coding will be done in the new material class files, but for that material to be recognized as an option in NairnMPM, a few places in the core code have to be edited first. Theses should be the only changes needed outside the new material class files.
Almost all coding will be done in the new material class files, but for that material to be recognized as an option in [[NairnMPM]] , a few places in the core code have to be edited first. Theses should be the only changes needed outside the new material class files.


# In MaterialController::AddMaterial(int matID,char *matName)- - add a new case in the switch(matID) section to call the default constructor of the new material when matID matches the new material constant defined in the previous section.
<ol>
# Include the new material's header file at the top of Common/Read_XML/MaterialController.cpp
<li>In <tt>MaterialController::AddMaterial(int matID,char *matName)</tt> add a new case in the <tt>switch(matID)<tt> section to call the default constructor of the new material when <tt>matID</tt> matches the new material's constant defined in the previous section.
<pre>
case TAITLIQUID:
newMaterial=new TaitLiquid(matName);
break;
</pre>
<li>Include the new material's header file at the top of <tt>Common/Read_XML/MaterialController.cpp</tt>.
</ol>

Revision as of 12:03, 4 December 2013

This section explains how to write C++ code create a new material class for use in NairnMPM.

Getting Started

The first steps are to create source files for the new material class, to give the material a unique name, and to allow the main NairnMPM code to instantiate the material class when it is needed for a particle.

Class Source Code

The best way to create the source code is to duplicate the NewMaterial.cpp and NewMaterial.hpp files, which are templates for a new material class. Edit the files and change NewMaterial to the new material's class name. This template is a subclass of MaterialBase. Normally the new material will be a subclass of another class. If so, change MaterialBase references, as needed, to the actual parent class. These changes are needed whenever a method in the new material class needs to pass control to its immediate super class.

Material Class Hierarchy

The new material should be inserted into the NairnMPM material class hierarchy with a unique name is ID. In the new materials header files, replace NEWMATERIAL with the material name (which by convention is in UPPERCASE) and replace the number in the new constant's definition with the new material's ID:

#define MYMATERIAL 102

All documented materials use low numbers (starting with 1). To avoid conflicts, those working on custom materials should use large number (>100).

Editing Required in Core Code

Almost all coding will be done in the new material class files, but for that material to be recognized as an option in NairnMPM , a few places in the core code have to be edited first. Theses should be the only changes needed outside the new material class files.

  1. In MaterialController::AddMaterial(int matID,char *matName) add a new case in the switch(matID) section to call the default constructor of the new material when matID matches the new material's constant defined in the previous section.
    		case TAITLIQUID:
    			newMaterial=new TaitLiquid(matName);
    			break;
    
  2. Include the new material's header file at the top of Common/Read_XML/MaterialController.cpp.