ReactionDiffusionSolver Plugin
Related: ReactionDiffusionSolverFVM (finite volume) Plugin
The reaction diffusion solver solves the following system of N reaction diffusion equations:
where W
denotes cell type
Let’s consider a simple example of such system:
It can be coded as follows:
<Steppable Type="ReactionDiffusionSolverFE">
<AutoscaleDiffusion/>
<DiffusionField Name="F">
<DiffusionData>
<FieldName>F</FieldName>
<DiffusionConstant>0.010</DiffusionConstant>
<ConcentrationFileName>
Demos/diffusion/diffusion_2D.pulse.txt
</ConcentrationFileName>
<AdditionalTerm>-0.01*H</AdditionalTerm>
</DiffusionData>
</DiffusionField>
<DiffusionField Name="H">
<DiffusionData>
<FieldName>H</FieldName>
<DiffusionConstant>0.0</DiffusionConstant>
<AdditionalTerm>0.01*F</AdditionalTerm>
</DiffusionData>
</DiffusionField>
</Steppable>
Notice how we implement functions f
from the general system of
reaction diffusion equations. We simply use <AdditionalTerm>
tag and
there we type an arithmetic expression involving field names (tags
<FieldName>
). In addition to this, we may include in those expressions the
word CellType
. For example:
<AdditionalTerm>0.01*F*CellType</AdditionalTerm>
This means that function f
will depend also on CellType
. CellType
holds the value of the type of the cell at a particular location - x
, y
, z
- of the lattice. The inclusion of the cell type might be useful if you
want to use additional terms which may change depending on the cell
type. Then all you have to do is to either use if statements inside
<AdditionalTerm>
or form equivalent mathematical expression using
functions allowed by muParser
: http://muparser.sourceforge.net/mup_features.html#idDef2
For example, let’s assume that the additional term for the second equation is the following:
In such a case, additional terms would be coded as follows:
<AdditionalTerm>CellType==1 ? 0.01*F : 0.15*F</AdditionalTerm>
We used a ternary operator, which functions the same as an `` if-then-else`` statement, to decide which expression to use based on whether or not the CellType is 1. (The syntax is similar to programming languages like C or C++)
The syntax of the ternary (aka if-then-else
statement) is as follows:
condition ? expression if condition is true : expression if condition false
Warning
Important: If change the above expression to
we will get an XML parsing error. Why? This i because XML parser will think
that <1
is the beginning of the new XML element. To fix this you could
use two approaches:
Present your expression as
CDATA
<AdditionalTerm>
<![CDATA[
CellType<1 ? 0.01*F : 0.15*F
]]>
</AdditionalTerm>
In this case, the XML parser will correctly interpret the expression enclosed
between <![CDATA[
and ]]>
.
2. Replace XML using equivalent Python syntax - see (http://pythonscriptingmanual.readthedocs.io/en/latest/replacing_cc3dml_with_equivalent_python_syntax.html) in which case you would code the above XML element as the following Python statement:
DiffusionDataElmnt.ElementCC3D('AdditionalTerm', {}, 'CellType<1 ? 0.01*F : 0.15*F')
In summary, if you would like to use muParser for more flexibility in your XML, make sure to use this general syntax:
<AdditionalTerm>
<![CDATA[
YOUR EXPRESSION
]]>
</AdditionalTerm>
One thing to remember is that the computing time of the additional term depends on the level of complexity of this term. Thus, you might get some performance degradation for very complex expressions coded in muParser.
Similarly as in the case of FlexibleDiffusionSolverFE
, we may use the
<AutoscaleDiffusion>
tag, which tells CC3D to automatically rescale the diffusion constant.
See section FlexibleDiffusionSolver or the Appendix for more
information.