Commit d433ed35 authored by Kilian Lackhove's avatar Kilian Lackhove

Enable timedependent file function type.

This adds a TIMEDEPENDENT argument to Function type File and enables the use of
a time depenmdent file name for boundary conditions, auxiliary fields etc.

The implementation relies on boost::format, where the given filename is
used as format string and the step time as argument. The full boost::format
syntax is supported. An error is thown when the corresponding file is not
found, so in order to only supply a new file every Nth timespep, one might
use appropriately named symlinks.

Example:

The function
<FUNCTION NAME="Baseflow">
    <F VAR="U0" TIMEDEPENDENT="1" FILE="U0_%14.8R.fld"/>
</FUNCTION>

will look for files named U0_basegrid_1.00000000E-05.fld,
U0_basegrid_2.00000000E-05.fld and so on.
parent b51a7a20
......@@ -214,7 +214,21 @@ the field data is specified. The expansion order used to generate the .rst file
must be the same as that for the simulation. The filename must be specified
relative to the location of the .xml file.
Other examples of this input features can be the insertion of a forcing term,
With the additional argument \inltt{TIMEDEPENDENT="1"}, different files can be
loaded for each timestep. The filenames are defined using
\href{http://www.boost.org/doc/libs/1_56_0/libs/format/doc/format.html#syntax}{boost::format syntax}
where the step time is used as variable. For example, the function
\inltt{Baseflow} would load the files \inltt{U0V0\_1.00000000E-05.fld},
\inltt{U0V0\_2.00000000E-05.fld} and so on.
\begin{lstlisting}[style=XMLStyle]
<FUNCTION NAME="Baseflow">
<F VAR="U0,V0" TIMEDEPENDENT="1"FILE="U0V0_%14.8R.fld"/>
</FUNCTION>
\end{lstlisting}
Other examples of this input feature can be the insertion of a forcing term,
\begin{lstlisting}[style=XMLStyle]
<FUNCTION NAME="BodyForce">
......
......@@ -2278,7 +2278,15 @@ namespace Nektar
// Files are denoted by F
else if (conditionType == "F")
{
funcDef.m_type = eFunctionTypeFile;
if (variable->Attribute("TIMEDEPENDENT") &&
boost::lexical_cast<bool>(variable->Attribute("TIMEDEPENDENT")))
{
funcDef.m_type = eFunctionTypeTransientFile;
}
else
{
funcDef.m_type = eFunctionTypeFile;
}
// File must have a FILE.
ASSERTL0(variable->Attribute("FILE"),
......
......@@ -87,7 +87,8 @@ namespace Nektar
{
eFunctionTypeExpression,
eFunctionTypeFile,
eSIZE_FunctionType
eFunctionTypeTransientFile,
eSIZE_FunctionType,
};
const char* const FunctionTypeMap[] =
{
......
......@@ -52,6 +52,8 @@
#include <SolverUtils/Advection/Advection.h>
#include <SolverUtils/Diffusion/Diffusion.h>
#include <boost/format.hpp>
#include <iostream>
#include <string>
......@@ -771,7 +773,7 @@ namespace Nektar
ffunc->Evaluate(x0,x1,x2,pTime,pArray);
}
else if (vType == LibUtilities::eFunctionTypeFile)
else if (vType == LibUtilities::eFunctionTypeFile || vType == LibUtilities::eFunctionTypeTransientFile)
{
std::string filename
= m_session->GetFunctionFilename(pFunctionName, pFieldName,domain);
......@@ -790,6 +792,18 @@ namespace Nektar
ElementGIDs[i] = m_fields[0]->GetExp(i)->GetGeom()->GetGlobalID();
}
if (vType == LibUtilities::eFunctionTypeTransientFile)
{
try
{
filename = boost::str(boost::format(filename) % m_time);
}
catch (...)
{
ASSERTL0(false, "Invalid Filename in function \""
+ pFunctionName + "\", variable \"" + pFieldName + "\"")
}
}
m_fld->Import(filename,FieldDef,FieldData,
LibUtilities::NullFieldMetaDataMap,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment