Difference between revisions of "TrackError Custom Task"

From OSUPDOCS
Jump to navigation Jump to search
 
(25 intermediate revisions by the same user not shown)
Line 7: Line 7:
== Simulation Error Metrics ==
== Simulation Error Metrics ==


Imagine a generic distance from particle value to a theoretical expectation for that value equal to <math>|x_p|</math>. For example, the distance could be difference between particle stress in the <tt>x</tt> directions and expected stress:
Imagine a generic distance from particle value to a theoretical expectation for that value equal to <math>|x_p|</math>. For example, the distance could be scalar difference between particle stress in the <tt>x</tt> direction and expected stress:


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<math>|x_p| = |\sigma_{p,xx} - \sigma_{xx}({\rm theory})|</math>
<math>|x_p| = |\sigma_{p,xx} - \sigma_{xx}({\rm theory})|</math>


If the particle value is a vector, the distance would be a vector distance. For example, velocity distance would be:
If the particle value is a vector, the distance would be a vector distance between value and expection. For example, a velocity distance would be:


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<math>|x_p| = \sqrt{\bigl(\vec V_p-\vec V({\rm theory})\bigr)\cdot\bigl(\vec V_p-\vec V({\rm theory})\bigr)}</math>
<math>|x_p| = \sqrt{\bigl(\vec V_p-\vec V({\rm theory})\bigr)\cdot\bigl(\vec V_p-\vec V({\rm theory})\bigr)}</math>


The P-norm for a given distance is defined as:
The P-norm for a given distance definition and for <math>N_p</math> particles is defined as:


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<math>||x||_P = \left( \sum_{p=1}^{N_p} |x_p|^P\right)^{1/P}</math>
<math>||x||_P = \left( \sum_{p=1}^{N_p} |x_p|^P\right)^{1/P}</math>


where <math>N_p</math> is the number of particles. The root-mean-squared distance is defined as:
The same distance can also define a root-mean-squared distance defined as:


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<math>{\rm RMS} = \sqrt{{1\over N_p} \sum_{p=1}^{N_p} |x_p|^2}</math>
<math>{\rm RMS} = \sqrt{{1\over N_p} \sum_{p=1}^{N_p} |x_p|^2}</math>


This task can archive mean P-norm values and RMS distances for any entered function for <math>|x_p|</math>. These mean values can be for each time step or cumulatively averaged over all time steps.
This task can archive mean P-norm values and RMS distances for any entered function for <math>|x_p|</math>. The archived values can be for each time step or cumulatively averaged over all time step calculations.
 
== Task Output ==
 
The <tt>TrackError</tt> calculations will be written to a tab-delimited text file.


== Task Scheduling ==
== Task Scheduling ==
Line 45: Line 41:
     . . .
     . . .


In <tt>XML</tt> files, this tasks is scheduled using a <tt>Schedule</tt> element, which must be within the single <tt><CustomTasks></tt> block:
In <tt>XML</tt> files, this task is scheduled using a <tt>Schedule</tt> element, which must be within the single <tt><CustomTasks></tt> block:


  <Schedule name='TrackError'>
  <Schedule name='TrackError'>
Line 61: Line 57:
* <tt>(firstTime)</tt> - Enter the time to start error metric calculations (in [[ConsistentUnits Command#Legacy and Consistent Units|alt time units]]). After this time is reached, subsequent calculations will be spaced by the entered <tt>(timeInterval)</tt>. This parameter is ignored unless the <tt>(timeInterval)</tt> parameter is set as well.
* <tt>(firstTime)</tt> - Enter the time to start error metric calculations (in [[ConsistentUnits Command#Legacy and Consistent Units|alt time units]]). After this time is reached, subsequent calculations will be spaced by the entered <tt>(timeInterval)</tt>. This parameter is ignored unless the <tt>(timeInterval)</tt> parameter is set as well.


Next, you enter up to 10 <tt>(xpexpr)</tt><math>=|x_p|</math> expressions for evaluating error metrics. The expressions are written in the style of [[User Defined Functions|user-defined functions]], but can contain different variables:
Next, you enter up to 10 <tt>(xpexpr)</tt><math>=|x_p|</math> expressions for evaluating a "distance." The expressions are written in the style of [[User Defined Functions|user-defined functions]], but can contain different variables:


* <tt>t</tt> for simulation time (in [[ConsistentUnits Command#Legacy and Consistent Units|alt time units]])
* <tt>t</tt> for simulation time (in [[ConsistentUnits Command#Legacy and Consistent Units|alt time units]])
Line 69: Line 65:
* <tt>sxx</tt>, <tt>syy</tt>, <tt>szz</tt>, <tt>sxy</tt>, <tt>sxz</tt>, and <tt>syz</tt> for particle stress (in [[ConsistentUnits Command#Legacy and Consistent Units|pressure units]])
* <tt>sxx</tt>, <tt>syy</tt>, <tt>szz</tt>, <tt>sxy</tt>, <tt>sxz</tt>, and <tt>syz</tt> for particle stress (in [[ConsistentUnits Command#Legacy and Consistent Units|pressure units]])


To determine the type of error metric, enter <tt>(cumulative)</tt> and <tt>(Pvalue)</tt> options ''before'' entering the <tt>(xpexpr)</tt> expressions. Once these parameters are set, they apply to all subsequent <tt>(xpexpr)</tt> expressions unless changed to new values with new <tt>Parameter</tt> commands. Their functions are
To determine the type of error metric that is calculated, enter <tt>(cumulative)</tt> and <tt>(Pvalue)</tt> options ''before'' entering the <tt>(xpexpr)</tt> expressions. Once these parameters are set, they apply to all subsequent <tt>(xpexpr)</tt> expressions unless changed to new values with new <tt>Parameter</tt> commands. Their functions are
 
*<tt>(cumulative)</tt> - set to 0 or 1. If 0, the error metric is found for each time step. If 1, the error metric is averaged over all time steps with calculations. The default is 0 (if never entered).
*<tt>(Pvalue)</tt> - determines the error metric that is calculated. The default is 2 (if never entered).


<ul>
Equations for the calculated error metrics for each combination of <tt>(cumulative)</tt> and <tt>(Pvalue)</tt> are in the following table (and <math>N_s</math> is the number of calculation time steps).
<li><tt>(cumulative)</tt> - set to 0 or 1. If 0, the error metric is found for each time step. If 1, the error metric averaged over all time steps with calculations.</li>
 
<li><tt>(Pvalue)</tt> - determines the error metric that is calculated. If <tt>(Pvalue)=P&gt;0</tt> and <tt>(cumulative)=0</tt>, the error metric calculated is:<br>
{| class="wikitable"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|-
<math>({\rm metric}) = {1\over N_p}\left( \sum_{p=1}^{N_p} ({\rm xpexpr})^P\right)^{1/P}</math>
! (Pvalue) !! (cumulative)=0 !! (cumulative)=1
<br>If <tt>(cumulative)=1</tt>, the error metric calculated changes to:<br>
|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
| 0 (RMS error) || <math>\sqrt{{1\over N_p} \sum_{p=1}^{N_p} ({\rm xpexpr})^2}</math> || <math>{1\over N_s}\sum_{i=1}^{N_s} \sqrt{{1\over N_p} \sum_{p=1}^{N_p} ({\rm xpexpr})^2}</math>
<math>({\rm metric}) = {1\over N_sN_p}\left( \sum_{s=1}^{N_s}\sum_{p=1}^{N_p} ({\rm xpexpr})^P\right)^{1/P}</math>
|-
<br>where <math>N_s</math> is the number of time steps with error calculations. If <tt>(Pvalue)=0</tt> and <tt>(cumulative)=0</tt>, the error metric is an RMS calculation:<br>
| P&gt;0 (mean P-norm) || <math>{1\over N_p}\left( \sum_{p=1}^{N_p} ({\rm xpexpr})^P\right)^{1/P}</math> || <math>{1\over N_s}\sum_{s=1}^{N_s}\left({1\over N_p} \sum_{p=1}^{N_p} ({\rm xpexpr})^P\right)^{1/P}</math>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|}
<math>{\rm RMS} = \sqrt{{1\over N_p} \sum_{p=1}^{N_p} ({\rm xpexpr})^2}</math>
 
<br>If <tt>(cumulative)=1</tt>, the error metric changes to averaged RMS over calculation time steps:<br>
=== TrackError Output ===
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
<math>\left\langle{\rm RMS}\right\rangle = {1\over N_s}\sum_{i=1}^{N_s} \sqrt{{1\over N_p} \sum_{p=1}^{N_p} ({\rm xpexpr})^2}</math>
The <tt>TrackError</tt> calculations will be written to a tab-delimited text file with name
</li>
 
</ul>
(path)_Error(num).txt
 
where <tt>(path)</tt> is the path name used to [[MPM Archiving Options|archive results]] and <tt>(num)</tt> is the <tt>TrackError</tt> task number. A single <tt>TrackError</tt> task can track up to 10 error functions. An MPM simulation can use any number of <tt>TrackError</tt> tasks if it needs more than 10 error function or if you prefer the error metrics to be in separate files.
 
Note that calculations in files written by a <tt>TrackError</tt> task can be plotted in [[NairnFEAMPM]] or [[NairnFEAMPMViz]] by using the "Import..." options for any 2D plots.


== Notes ==
== Notes ==


# Note the <tt>(Pvalue)=1</tt> is ordinary mean value of the <tt>(xpexpr)</tt> expression. This setting can be used to extend [[MPM Global Archiving Options|global archiving options]] to include arbitrary functions of particle properties.
# Note the <tt>(Pvalue)=1</tt> is ordinary mean value of the <tt>(xpexpr)</tt> expression. This setting can be used to extend [[MPM Global Archiving Options|global archiving options]] to include arbitrary functions of particle properties or the average of that property over all time steps (by using <tt>(cumulative)=1</tt>.

Latest revision as of 12:21, 11 December 2023

A custom task to archive simulations results compared to theoretical predictions

Introduction

This tasks can compare particle values to a theoretical model and archive some metric for accuracy of the simulation. It is useful for tracking convergence of MPM simulations.

Simulation Error Metrics

Imagine a generic distance from particle value to a theoretical expectation for that value equal to [math]\displaystyle{ |x_p| }[/math]. For example, the distance could be scalar difference between particle stress in the x direction and expected stress:

      [math]\displaystyle{ |x_p| = |\sigma_{p,xx} - \sigma_{xx}({\rm theory})| }[/math]

If the particle value is a vector, the distance would be a vector distance between value and expection. For example, a velocity distance would be:

      [math]\displaystyle{ |x_p| = \sqrt{\bigl(\vec V_p-\vec V({\rm theory})\bigr)\cdot\bigl(\vec V_p-\vec V({\rm theory})\bigr)} }[/math]

The P-norm for a given distance definition and for [math]\displaystyle{ N_p }[/math] particles is defined as:

      [math]\displaystyle{ ||x||_P = \left( \sum_{p=1}^{N_p} |x_p|^P\right)^{1/P} }[/math]

The same distance can also define a root-mean-squared distance defined as:

      [math]\displaystyle{ {\rm RMS} = \sqrt{{1\over N_p} \sum_{p=1}^{N_p} |x_p|^2} }[/math]

This task can archive mean P-norm values and RMS distances for any entered function for [math]\displaystyle{ |x_p| }[/math]. The archived values can be for each time step or cumulatively averaged over all time step calculations.

Task Scheduling

In scripted files, a TrackError custom task is scheduled using

CustomTask TrackError
Parameter archiveTime,(timeInterval)
Parameter firstArchiveTime,(firstTime)
Parameter cumulative,(cumulative)
Parameter P,(Pvalue)
Parameter function,(xpexpr)
   . . .

In XML files, this task is scheduled using a Schedule element, which must be within the single <CustomTasks> block:

<Schedule name='TrackError'>
   <Parameter name='archiveTime'>(timeInterval)</Parameter>
   <Parameter name='firstArchiveTime'>(firstTime)</Parameter>
   <Parameter name='cumulative'>(cumulative)</Parameter>
   <Parameter name='P'>(Pvalue)</Parameter>
   <Parameter name='function'>(xpexpr)</Parameter>
        . . .
</Schedule>

where the first two parameters, both of which are optional, are

  • (timeInterval) - Enter the time interval (in alt time units) between calculations of error metrics. If this parameter is omitted, the calculations are done on the same steps as the particle archives.
  • (firstTime) - Enter the time to start error metric calculations (in alt time units). After this time is reached, subsequent calculations will be spaced by the entered (timeInterval). This parameter is ignored unless the (timeInterval) parameter is set as well.

Next, you enter up to 10 (xpexpr)[math]\displaystyle{ =|x_p| }[/math] expressions for evaluating a "distance." The expressions are written in the style of user-defined functions, but can contain different variables:

To determine the type of error metric that is calculated, enter (cumulative) and (Pvalue) options before entering the (xpexpr) expressions. Once these parameters are set, they apply to all subsequent (xpexpr) expressions unless changed to new values with new Parameter commands. Their functions are

  • (cumulative) - set to 0 or 1. If 0, the error metric is found for each time step. If 1, the error metric is averaged over all time steps with calculations. The default is 0 (if never entered).
  • (Pvalue) - determines the error metric that is calculated. The default is 2 (if never entered).

Equations for the calculated error metrics for each combination of (cumulative) and (Pvalue) are in the following table (and [math]\displaystyle{ N_s }[/math] is the number of calculation time steps).

(Pvalue) (cumulative)=0 (cumulative)=1
0 (RMS error) [math]\displaystyle{ \sqrt{{1\over N_p} \sum_{p=1}^{N_p} ({\rm xpexpr})^2} }[/math] [math]\displaystyle{ {1\over N_s}\sum_{i=1}^{N_s} \sqrt{{1\over N_p} \sum_{p=1}^{N_p} ({\rm xpexpr})^2} }[/math]
P>0 (mean P-norm) [math]\displaystyle{ {1\over N_p}\left( \sum_{p=1}^{N_p} ({\rm xpexpr})^P\right)^{1/P} }[/math] [math]\displaystyle{ {1\over N_s}\sum_{s=1}^{N_s}\left({1\over N_p} \sum_{p=1}^{N_p} ({\rm xpexpr})^P\right)^{1/P} }[/math]

TrackError Output

The TrackError calculations will be written to a tab-delimited text file with name

(path)_Error(num).txt

where (path) is the path name used to archive results and (num) is the TrackError task number. A single TrackError task can track up to 10 error functions. An MPM simulation can use any number of TrackError tasks if it needs more than 10 error function or if you prefer the error metrics to be in separate files.

Note that calculations in files written by a TrackError task can be plotted in NairnFEAMPM or NairnFEAMPMViz by using the "Import..." options for any 2D plots.

Notes

  1. Note the (Pvalue)=1 is ordinary mean value of the (xpexpr) expression. This setting can be used to extend global archiving options to include arbitrary functions of particle properties or the average of that property over all time steps (by using (cumulative)=1.