<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://imechanica.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>iMechanica - The factory idiom and material models - Comments</title>
 <link>http://imechanica.org/node/2586</link>
 <description>Comments for &quot;The factory idiom and material models&quot;</description>
 <language>en</language>
<item>
 <title>Library for design patterns/idioms</title>
 <link>http://imechanica.org/node/2586#comment-6381</link>
 <description>&lt;p&gt;Good luck, Biswajit. A C++ library that contains implementations of design patterns and idioms is &lt;a href=&quot;http://loki-lib.sourceforge.net/&quot; target=&quot;_blank&quot; title=&quot;Loki&quot;&gt;Loki. &lt;/a&gt;&lt;/p&gt;
&lt;br class=&quot;clear&quot; /&gt;</description>
 <pubDate>Sat, 19 Jan 2008 00:41:09 -0500</pubDate>
 <dc:creator>N. Sukumar</dc:creator>
 <guid isPermaLink="false">comment 6381 at http://imechanica.org</guid>
</item>
<item>
 <title>Dear Biswajit, 


Wish you</title>
 <link>http://imechanica.org/node/2586#comment-6377</link>
 <description>&lt;p&gt;
Dear Biswajit,&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Wish you the best in your new post, and we look forward to your coming back to iMechanica.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
-Teng&amp;nbsp;
&lt;/p&gt;
&lt;br class=&quot;clear&quot; /&gt;</description>
 <pubDate>Fri, 18 Jan 2008 10:25:43 -0500</pubDate>
 <dc:creator>Teng Li</dc:creator>
 <guid isPermaLink="false">comment 6377 at http://imechanica.org</guid>
</item>
<item>
 <title>C++ Idioms and Design Patterns...</title>
 <link>http://imechanica.org/node/2586#comment-6374</link>
 <description>&lt;p&gt;
Dear Biswajit,
&lt;/p&gt;
&lt;p&gt;
Good that you broached this topic up... I was wondering if discussions related to programming would be appropriate here at iMechanica---especially, discussions at a somewhat more abstract level (i.e. not concerned with the syntax of languages etc.)... Also, the more serious amongst tutorial codes in C++... I was already wondering if I should be posting some of my code &lt;a href=&quot;http://ajitjadhav.wordpress.com&quot;&gt;my general blog site&lt;/a&gt;... So, I was really delighted to see your above post here...
&lt;/p&gt;
&lt;p&gt;
About C++ idioms. A very closely related topic is &lt;strong&gt;Design Patterns&lt;/strong&gt;. For example, see &lt;a href=&quot;http://en.wikipedia.org/wiki/Design_pattern_(computer_science)&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Design_Patterns&quot;&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
With that said, I have a word of caution, though. IMO it is best *NOT* to try to use design patterns right in the first iteration of a major version of your software--v 1.0 or v 2.0 or whatever....
&lt;/p&gt;
&lt;p&gt;
I know I am sounding like an unenthusiastic fool who has no respect whatsoever for the abstract or high-level design here... But the way I loook at it, there has been sometimes too much of a good thing w.r.t. the high-level abstract design too... Just for example, notice that issues and factors such as data locality (cache and virtual memory), ease of IPC and of parallelization, etc. ought to enter software&amp;nbsp;design... Yet, as a matter of fact, a lot of issues of this nature cannot become as clear as they should be, until the first cut is already over. (We don&amp;#39;t have to wait until the profiling stage, but at least a major chunk of the code ought to first exist before people can really get such parts right.) Hence, it is sometimes better to go ahead with a simple scheme involving a minimal number of very loosely coupled classes, and then put them all together into a better framework... A real bottom-up design&amp;nbsp;exercise, in a sense....
&lt;/p&gt;
&lt;p&gt;
Of course, my above comment does not apply to your above post of C++ idioms (or your example of the Factory idiom)... I just wanted to qualify my recommendation of design patterns, that&amp;#39;s all...
&lt;/p&gt;
&lt;p&gt;
-----
&lt;/p&gt;
&lt;p&gt;
Biswajit, on a personal note: If you want to quit USA, that&amp;#39;s good (ask me why (!)) but you don&amp;#39;t want to therefore return to India, do you?
&lt;/p&gt;
&lt;p&gt;
One way or the other, I enjoyed your answers over a range of issues here... Let me wish you the very best in your new environment, and, as Zhigang said, do let us know once you are ready to chat here at iMechanica again... I look forward to&amp;nbsp;interacting with you&amp;nbsp;soon again...
&lt;/p&gt;
&lt;p&gt;
--Ajit
&lt;/p&gt;
&lt;br class=&quot;clear&quot; /&gt;</description>
 <pubDate>Thu, 17 Jan 2008 22:59:28 -0500</pubDate>
 <dc:creator>Ajit R. Jadhav</dc:creator>
 <guid isPermaLink="false">comment 6374 at http://imechanica.org</guid>
</item>
<item>
 <title>Best wishes for Biswajit</title>
 <link>http://imechanica.org/node/2586#comment-6370</link>
 <description>&lt;p&gt;Dear Biswajit:&amp;nbsp; Thank you so much for &lt;a href=&quot;/user/1095/track&quot;&gt;your contributions to iMechanica&lt;/a&gt;.&amp;nbsp; I have learned much from you.&amp;nbsp; Please let us know when you are settled in your new environment.&amp;nbsp; Good Luck and best wishes, Zhigang&lt;/p&gt;
&lt;br class=&quot;clear&quot; /&gt;</description>
 <pubDate>Thu, 17 Jan 2008 21:07:33 -0500</pubDate>
 <dc:creator>Zhigang Suo</dc:creator>
 <guid isPermaLink="false">comment 6370 at http://imechanica.org</guid>
</item>
<item>
 <title>The factory idiom and material models</title>
 <link>http://imechanica.org/node/2586</link>
 <description>&lt;p&gt;
I&amp;#39;m leaving the US in a couple of days and will probably take a hiatus of a few months from iMechanica.&amp;nbsp; Before I leave, I want to tell you about a &lt;a href=&quot;http://everything2.com/index.pl?node_id=1116186&quot;&gt;C++ idiom&lt;/a&gt;  that eases the implementation and use of multiple material models in a computational mechanics code.
&lt;/p&gt;
&lt;p&gt;
The first book on C++ idioms was by &lt;a href=&quot;http://users.rcn.com/jcoplien/&quot; target=&quot;_blank&quot;&gt;Jim Copilien&lt;/a&gt; sometime in the late 1990s called &amp;quot;Advanced C++: Programming Styles and Idioms&amp;quot;.&amp;nbsp; The idea of such idioms has become considerably widespread since then - so much so that there is a &lt;a href=&quot;http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms&quot; target=&quot;_blank&quot;&gt;Wikibook on the subject&lt;/a&gt; .
&lt;/p&gt;
&lt;p&gt;
The idiom I am going to talk about is the &lt;strong&gt;Factory idiom&lt;/strong&gt;.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
My need to use the factory idiom arose when I was trying to compare a number of plasticity models.&amp;nbsp; I wanted to avoid complicating the code by using &lt;em&gt;if statements &lt;/em&gt;or other manual control mechanisms to deal with models specified in the input.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Let me show you how it&amp;#39;s done - step by step.&amp;nbsp; For simplicity, let us assume that only the flow stress model varies and everything else remains the same.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Step 1:&lt;/strong&gt;&amp;nbsp; We create a abstract base class called &lt;font face=&quot;courier new,courier&quot; color=&quot;#3366ff&quot;&gt;FlowStressModel.h&lt;/font&gt;&lt;font color=&quot;#3366ff&quot;&gt;.&amp;nbsp;&amp;nbsp;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The contents of the file are of the form:
&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;class FlowStressModel {&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; private:&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; public:&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FlowStressModel();&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~FlowStressModel();&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual double computeFlowStress(const PlasticityState* state, ...) = 0;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual double computeDsigDep(const PlasticityState* state, ...) = 0;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;};&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
In the corresponding &lt;font color=&quot;#008080&quot;&gt;FlowStressModel.cc &lt;/font&gt;file we have
&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;FlowStressModel.h&amp;quot;&lt;/font&gt;&amp;nbsp;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;FlowStressModel::FlowStressModel() {}&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;FlowStressModel::~FlowStressModel() {}&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Step 2:&amp;nbsp; &lt;/strong&gt;Next we create a factory for flow stress models called &lt;font color=&quot;#008080&quot;&gt;FlowStressModelFactory.h&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
This file contains something like
&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;class FlowStressModel;&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;	&lt;font color=&quot;#339966&quot;&gt;class FlowStressModelFactory&lt;br /&gt;
	{&lt;br /&gt;
	&amp;nbsp; public:&lt;br /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static PlasticityModel* create(ProblemSpecP&amp;amp; ps);&lt;br /&gt;
	};&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;
Here the problem specification (ProblemSpec) is a pointer to the input XML file or any other input format that you may have.
&lt;/p&gt;
&lt;p&gt;
The implementation of the factory in the file &lt;font color=&quot;#008080&quot;&gt;FlowStressModelFactory.cc&lt;/font&gt; has the following form
&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;FlowStressModelFactory.h&amp;quot; &lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;LinearHardeningPlasticity.h&amp;quot;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;JohnsonCookPlasticity.h&amp;quot; &lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;....&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;FlowStressModel* FlowStressModelFactory::create(ProblemSpecP&amp;amp; ps)&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; // First read the problem specification (however you want)&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; // and get the material_type (mat_type)&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; if (mat_type == &amp;quot;linear hardening&amp;quot;) {&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (new LinearHardeningPlasticity(ps));&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; } else if (mat_type == &amp;quot;johnson_cook&amp;quot;) {&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (new JohnsonCookPlasticity(ps));&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; }&amp;nbsp; &lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Step 3&lt;/strong&gt;:&amp;nbsp; Now we can implement the LinearHardeningPlasticity and JohnsonCookPlasticity models by deriving them from the FlowStressModel class and making them concrete.&amp;nbsp; For instance, for the JohnsonCookPlasticity model we have a &lt;font color=&quot;#008080&quot;&gt;JohnsonCookPlasticity.h&lt;/font&gt; file which contains
&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;FlowStressModel.h&amp;quot;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;class JohnsonCookPlasticity : public FlowStressModel &lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; private:&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LocalModelData d_data;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; public:&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; JohsonCookPlasticity(ProblemSpecP&amp;amp; ps);&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp; virtual ~JohnsonCookPlasticity();&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color=&quot;#339966&quot;&gt;double computeFlowStress(const PlasticityState* state, ...);&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color=&quot;#339966&quot;&gt;double computeDsigDep(const PlasticityState* state, ...);&amp;nbsp;&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
The implementation of the model is in &lt;font color=&quot;#008080&quot;&gt;JohnsonCookPlasticity.cc&lt;/font&gt; which contains something like
&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;JohnsonCookPlasticity.h&amp;quot;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;JohnsonCookPlasticity::JohnsonCookPlasticity(ProblemSpecP&amp;amp; ps)&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp; // Read stuff from the input file and create object&amp;nbsp; &lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&lt;br /&gt;
	JohnsonCookPlasticity::~JohnsonCookPlasticity()&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp; // delete anything that you need to&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;double&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;JohnsonCookPlasticity::computeFlowStress(const PlasticityState* state, ...)&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp; // do tha actual flow stress computation here&amp;nbsp; &lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;double&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;JohnsonCookPlasticity:: computeDsigDep(const PlasticityState* state, ...)&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; // Calculate the derivative of the flow stress with respect to the plastic strain&lt;br /&gt;
	&amp;nbsp; &lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
Adding other flow stress models follows the same pattern.&amp;nbsp; All you have to do is create the code for the model and add a line to the factory.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Step 4: &lt;/strong&gt;The final step is to add this information to your elastic-plastic stress update code.&amp;nbsp; Let us suppose that the class is called ElasticPlastic.&amp;nbsp; Then the file &lt;font color=&quot;#008080&quot;&gt;ElasticPlastic.h&lt;/font&gt; will have the form&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;FlowStressModel.h&amp;quot;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;.....&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;class ElasticPlastic {&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; public:&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .....&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; protected:&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FlowStressModel* d_flowStress;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .....&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; public:&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElasticPlastic(ProblemSpecP&amp;amp; ps);&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~ElasticPlastic();&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void computeStress(Matrix&amp;amp; stress);&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ......&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;};&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
In the actual implementation of ElasticPlastic (i.e., in the &lt;font color=&quot;#008080&quot;&gt;ElasticPlastic.cc&lt;/font&gt; file) you will have
&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;ElasticPlastic.h&amp;quot;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;#include &amp;quot;FlowStressModelFactory.h&amp;quot;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;...&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;ElasticPlastic::ElasticPlastic(ProblemSpecP&amp;amp; ps)&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; // Read all the other stuff that you need for the ElasticPlastic model&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; // Create the flow stress model&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; d_flowStress = FlowStressModelFactory::create(ps);&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;ElasticPlastic::~ElasticPlastic()&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; // Delete all the other stuff that you need to delete&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; // Delete the flow stres model&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; delete d_flowStress;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;void&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;ElasticPlastic::compute stress(Matrix&amp;amp; stress)&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;{&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp; // Do whatever is needed before you can compute the flow stress&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp;&amp;nbsp; // set up the plasticity state&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; PlasticityState* state = new PlasticityState();&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; // compute the flow stress&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;&amp;nbsp; double flowStress = d_flowStress-&amp;gt;computeFlowStress(state, ....);&lt;br /&gt;
	&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
	&lt;font color=&quot;#339966&quot;&gt;}&amp;nbsp;&lt;/font&gt;
	&lt;/p&gt;
&lt;p&gt;
So you have made the code much more cleaner than otherwise possible and more intuitive.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
That&amp;#39;s the basic idea which we use extensively in Uintah.&amp;nbsp; Our inputs files are in XML and hundreds of material models can be easily switched in and out without the user or the coder having to bother at all with whether the if statements are correctly done.&amp;nbsp; For instance if the original input file contained something like
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&lt;font color=&quot;#ff00ff&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;flow_stress_model type = &amp;quot;johnson_cook&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;A&amp;gt; 90.0e6&amp;nbsp; &amp;lt;/A&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;B&amp;gt; 292.0e6 &amp;lt;/B&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;C&amp;gt; 0.025&amp;nbsp;&amp;nbsp; &amp;lt;/C&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;n&amp;gt; 0.31&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/n&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;m&amp;gt; 1.09&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/m&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/flow_stress_model&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
then all the user needs to do to switch to a linear hardening model is write instead
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color=&quot;#ff00ff&quot;&gt;&amp;lt;flow_stress_model type = &amp;quot;linear_hardening&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sig_0&amp;gt; 90.0e6&amp;nbsp; &amp;lt;/sig_0&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;H&amp;gt; 292.0e5 &amp;lt;/H&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plasticity_model&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
and everything exactly as before - but with a new model.
&lt;/p&gt;
&lt;p&gt;
Hope that helps some of you out there.
&lt;/p&gt;
&lt;p&gt;
-- Biswajit&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;br class=&quot;clear&quot; /&gt;</description>
 <comments>http://imechanica.org/node/2586#comments</comments>
 <category domain="http://imechanica.org/taxonomy/term/1355">C++</category>
 <category domain="http://imechanica.org/taxonomy/term/162">computational mechanics</category>
 <category domain="http://imechanica.org/taxonomy/term/169">Plasticity</category>
 <pubDate>Thu, 17 Jan 2008 20:14:00 -0500</pubDate>
 <dc:creator>Biswajit Banerjee</dc:creator>
 <guid isPermaLink="false">2586 at http://imechanica.org</guid>
</item>
</channel>
</rss>
