42#include <boost/format.hpp>
61 : m_session(session), m_field(
field), m_name(functionName),
65 "Function '" +
m_name +
"' does not exist.");
79 std::vector<std::string> vFieldNames =
m_session->GetVariables();
81 for (
int i = 0; i < vFieldNames.size(); i++)
83 Evaluate(vFieldNames[i], pArray[i], pTime, domain);
100 ASSERTL1(pFieldNames.size() == pArray.size(),
102 "' variable list size mismatch with array storage.");
104 for (
int i = 0; i < pFieldNames.size(); i++)
106 Evaluate(pFieldNames[i], pArray[i], pTime, domain);
120 std::vector<std::string> pFieldNames,
122 const NekDouble &pTime,
const int domain)
124 ASSERTL0(pFieldNames.size() == pFields.size(),
125 "Field list / name list size mismatch.");
127 for (
int i = 0; i < pFieldNames.size(); i++)
129 Evaluate(pFieldNames[i], pFields[i]->UpdatePhys(), pTime, domain);
130 if (pFields[i]->GetWaveSpace())
132 pFields[i]->HomogeneousFwdTrans(pFields[i]->GetTotPoints(),
133 pFields[i]->GetPhys(),
134 pFields[i]->UpdatePhys());
136 pFields[i]->FwdTransLocalElmt(pFields[i]->GetPhys(),
137 pFields[i]->UpdateCoeffs());
152 const NekDouble &pTime,
const int domain)
157 unsigned int nq =
m_field->GetNpoints();
159 std::pair<std::string, int> key(pFieldName, domain);
167 if (pArray.size() < nq)
183 std::string filename =
186 if (fs::path(filename).extension() ==
".pts" ||
187 fs::path(filename).extension() ==
".csv")
198 ASSERTL0(
false,
"unknown eFunctionType");
226 retVal = ffunc->GetExpression();
231 std::string filename =
233 retVal =
"from file " + filename;
237 ASSERTL0(
false,
"unknown eFunctionType");
253 const NekDouble &pTime,
const int domain)
255 unsigned int nq =
m_field->GetNpoints();
256 if (pArray.size() < nq)
267 m_field->GetCoords(x0, x1, x2);
271 ffunc->Evaluate(x0, x1, x2, pTime, pArray);
284 const NekDouble &pTime,
const int domain)
286 unsigned int nq =
m_field->GetNpoints();
287 if (pArray.size() < nq)
292 std::string filename =
294 std::string fileVar =
297 if (fileVar.length() == 0)
299 fileVar = pFieldName;
310#if (defined _WIN32 && _MSC_VER < 1900)
313 unsigned int old_exponent_format;
314 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
316 _set_output_format(old_exponent_format);
324 "\", variable \"" + fileVar +
"\"")
329 int numexp =
m_field->GetExpSize();
331 for (
int i = 0; i < numexp; ++i)
333 ElementGIDs[i] =
m_field->GetExp(i)->GetGeom()->GetGlobalID();
336 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
337 std::vector<std::vector<NekDouble>> FieldData;
340 fldIO->Import(filename, FieldDef, FieldData,
346 for (
int i = 0; i < FieldDef.size(); ++i)
350 for (
int j = 0; j < FieldDef[i]->m_fields.size(); ++j)
352 if (FieldDef[i]->m_fields[j] == fileVar)
360 m_field->ExtractDataToCoeffs(FieldDef[i], FieldData[i],
361 FieldDef[i]->m_fields[idx], vCoeffs);
365 cout <<
"Field " + fileVar +
" not found." << endl;
369 bool wavespace =
m_field->GetWaveSpace();
371 m_field->BwdTrans(vCoeffs, pArray);
372 m_field->SetWaveSpace(wavespace);
385 const NekDouble &pTime,
const int domain)
387 unsigned int nq =
m_field->GetNpoints();
388 if (pArray.size() < nq)
393 std::string filename =
395 std::string fileVar =
398 if (fileVar.length() == 0)
400 fileVar = pFieldName;
411#if (defined _WIN32 && _MSC_VER < 1900)
414 unsigned int old_exponent_format;
415 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
417 _set_output_format(old_exponent_format);
425 "\", variable \"" + fileVar +
"\"")
433 std::string funcFilename =
437 if (fs::path(filename).extension() ==
".pts")
440 ptsIO.
Import(filename, inPts);
442 else if (fs::path(filename).extension() ==
".csv")
445 csvIO.
Import(filename, inPts);
449 ASSERTL1(
false,
"Unsupported file type");
453 inPts->GetNFields());
454 for (
int i = 0; i < inPts->GetDim() + inPts->GetNFields(); ++i)
458 if (inPts->GetDim() == 1)
462 else if (inPts->GetDim() == 2)
464 m_field->GetCoords(pts[0], pts[1]);
466 else if (inPts->GetDim() == 3)
468 m_field->GetCoords(pts[0], pts[1], pts[2]);
471 inPts->GetDim(), inPts->GetFieldNames(), pts);
482 std::vector<MultiRegions::ExpListSharedPtr>>(
484 if (
m_session->GetComm()->GetRank() == 0)
490 if (
m_session->GetComm()->GetRank() == 0)
493 if (
m_session->DefinesCmdLineArgument(
"verbose"))
509 vector<string> fieldNames = outPts->GetFieldNames();
510 for (fieldInd = 0; fieldInd < fieldNames.size(); ++fieldInd)
512 if (outPts->GetFieldName(fieldInd) == fileVar)
517 ASSERTL0(fieldInd != fieldNames.size(),
"field not found");
519 pArray = outPts->GetPts(fieldInd + outPts->GetDim());
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
A class that contains algorithms for interpolation between pts fields, expansions and different meshe...
FIELD_UTILS_EXPORT void Interpolate(const T expInField, T &expOutField, NekDouble def_value=0., NekDouble tolerance=NekConstants::kFindDistanceMin)
Interpolate from an expansion to an expansion.
static std::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
void PrintStatistics()
Returns if the weights have already been computed.
void SetProgressCallback(FuncPointerT func, ObjectPointerT obj)
sets a callback funtion which gets called every time the interpolation progresses
void CalcWeights(const LibUtilities::PtsFieldSharedPtr ptsInField, LibUtilities::PtsFieldSharedPtr &ptsOutField, bool reuseTree=false)
Compute interpolation weights without doing any interpolation.
void Import(const std::string &inFile, PtsFieldSharedPtr &ptsField, FieldMetaDataMap &fieldmetadatamap=NullFieldMetaDataMap, DomainRangeShPtr &Range=NullDomainRangeShPtr)
Import a pts field from file.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::map< std::string, FieldUtils::Interpolator< std::vector< MultiRegions::ExpListSharedPtr > > > m_interpolators
Interpolator for pts file input for a variable & domain combination.
MultiRegions::ExpListSharedPtr m_field
The expansion we want to evaluate this function for.
bool m_toCache
Store resulting arrays (and interpolators)
std::map< std::pair< std::string, int >, Array< OneD, NekDouble > > m_arrays
Cached result arrays.
SOLVER_UTILS_EXPORT void EvaluateFld(std::string pFieldName, Array< OneD, NekDouble > &pArray, const NekDouble &pTime=0.0, const int domain=0)
SOLVER_UTILS_EXPORT void Evaluate(Array< OneD, Array< OneD, NekDouble > > &pArray, const NekDouble pTime=0.0, const int domain=0)
Evaluates a function defined in the xml session file at each quadrature point.
SOLVER_UTILS_EXPORT void EvaluatePts(std::string pFieldName, Array< OneD, NekDouble > &pArray, const NekDouble &pTime=0.0, const int domain=0)
Evaluates a function from pts file.
SOLVER_UTILS_EXPORT SessionFunction(const LibUtilities::SessionReaderSharedPtr &session, const MultiRegions::ExpListSharedPtr &field, std::string functionName, bool toCache=false)
Representation of a FUNCTION defined in the session xml file.
SOLVER_UTILS_EXPORT void PrintProgressbar(const int position, const int goal) const
std::map< std::pair< std::string, int >, NekDouble > m_lastCached
Last time the cache for this variable & domain combo was updated.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
SOLVER_UTILS_EXPORT std::string Describe(std::string pFieldName, const int domain=0)
Provide a description of a function for a given field name.
SOLVER_UTILS_EXPORT void EvaluateExp(std::string pFieldName, Array< OneD, NekDouble > &pArray, const NekDouble &pTime=0.0, const int domain=0)
std::shared_ptr< FieldIO > FieldIOSharedPtr
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
static FieldMetaDataMap NullFieldMetaDataMap
std::shared_ptr< PtsField > PtsFieldSharedPtr
@ eFunctionTypeExpression
@ eFunctionTypeTransientFile
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
static const NekDouble kNekZeroTol
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)