41 #include <boost/format.hpp> 60 std::string functionName,
62 : m_session(session), m_field(field), m_name(functionName), m_toCache(toCache)
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.num_elements(),
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);
119 std::vector<std::string> pFieldNames,
124 ASSERTL0(pFieldNames.size() == pFields.num_elements(),
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 pFields[i]->FwdTrans_IterPerExp(pFields[i]->GetPhys(),
131 pFields[i]->UpdateCoeffs());
151 unsigned int nq =
m_field->GetNpoints();
153 std::pair<std::string, int> key(pFieldName, domain);
161 if (pArray.num_elements() < nq)
177 std::string filename =
180 if (boost::filesystem::path(filename).extension() ==
".pts" ||
181 boost::filesystem::path(filename).extension() ==
".csv")
192 ASSERTL0(
false,
"unknown eFunctionType");
220 retVal = ffunc->GetExpression();
225 std::string filename =
227 retVal =
"from file " + filename;
231 ASSERTL0(
false,
"unknown eFunctionType");
250 unsigned int nq =
m_field->GetNpoints();
251 if (pArray.num_elements() < nq)
262 m_field->GetCoords(x0, x1, x2);
266 ffunc->Evaluate(x0, x1, x2, pTime, pArray);
282 unsigned int nq =
m_field->GetNpoints();
283 if (pArray.num_elements() < nq)
288 std::string filename =
290 std::string fileVar =
293 if (fileVar.length() == 0)
295 fileVar = pFieldName;
306 #if (defined _WIN32 && _MSC_VER < 1900) 309 unsigned int old_exponent_format;
310 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
312 _set_output_format(old_exponent_format);
320 "Invalid Filename in function \"" +
m_name +
321 "\", variable \"" + fileVar +
"\"")
326 int numexp =
m_field->GetExpSize();
328 for (
int i = 0; i < numexp; ++i)
330 ElementGIDs[i] =
m_field->GetExp(i)->GetGeom()->GetGlobalID();
333 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
334 std::vector<std::vector<NekDouble> > FieldData;
337 fldIO->Import(filename,
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)
361 FieldDef[i], FieldData[i], FieldDef[i]->m_fields[idx], vCoeffs);
365 cout <<
"Field " + fileVar +
" not found." << endl;
369 m_field->BwdTrans_IterPerExp(vCoeffs, pArray);
385 unsigned int nq =
m_field->GetNpoints();
386 if (pArray.num_elements() < nq)
391 std::string filename =
393 std::string fileVar =
396 if (fileVar.length() == 0)
398 fileVar = pFieldName;
409 #if (defined _WIN32 && _MSC_VER < 1900) 412 unsigned int old_exponent_format;
413 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
415 _set_output_format(old_exponent_format);
423 "Invalid Filename in function \"" +
m_name +
424 "\", variable \"" + fileVar +
"\"")
432 std::string funcFilename =
436 if (boost::filesystem::path(filename).extension() ==
".pts")
439 ptsIO.
Import(filename, inPts);
441 else if (boost::filesystem::path(filename).extension() ==
".csv")
444 csvIO.
Import(filename, inPts);
448 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);
481 if (
m_session->GetComm()->GetRank() == 0)
486 interp.CalcWeights(inPts, outPts);
487 if (
m_session->GetComm()->GetRank() == 0)
490 if (
m_session->DefinesCmdLineArgument(
"verbose"))
492 interp.PrintStatistics();
503 interp.Interpolate(inPts, outPts);
506 vector<string> fieldNames = outPts->GetFieldNames();
507 for (fieldInd = 0; fieldInd < fieldNames.size(); ++fieldInd)
509 if (outPts->GetFieldName(fieldInd) == fileVar)
514 ASSERTL0(fieldInd != fieldNames.size(),
"field not found");
516 pArray = outPts->GetPts(fieldInd + outPts->GetDim());
bool m_toCache
Store resulting arrays (and interpolators)
#define ASSERTL0(condition, msg)
A class that contains algorithms for interpolation between pts fields, expansions and different meshe...
std::map< std::pair< std::string, int >, NekDouble > m_lastCached
Last time the cache for this variable & domain combo was updated.
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
SOLVER_UTILS_EXPORT void EvaluateExp(std::string pFieldName, Array< OneD, NekDouble > &pArray, const NekDouble &pTime=0.0, const int domain=0)
SOLVER_UTILS_EXPORT void PrintProgressbar(const int position, const int goal) const
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
void Import(const std::string &inFile, PtsFieldSharedPtr &ptsField, FieldMetaDataMap &fieldmetadatamap=NullFieldMetaDataMap)
Import a pts field from file.
std::map< std::pair< std::string, int >, Array< OneD, NekDouble > > m_arrays
Cached result arrays.
std::shared_ptr< PtsField > PtsFieldSharedPtr
static const NekDouble kNekZeroTol
SOLVER_UTILS_EXPORT std::string Describe(std::string pFieldName, const int domain=0)
Provide a description of a function for a given field name.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
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.
std::shared_ptr< Equation > EquationSharedPtr
static std::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
std::map< std::string, FieldUtils::Interpolator > m_interpolators
Interpolator for pts file input for a variable & domain combination.
SOLVER_UTILS_EXPORT void EvaluateFld(std::string pFieldName, Array< OneD, NekDouble > &pArray, const NekDouble &pTime=0.0, const int domain=0)
MultiRegions::ExpListSharedPtr m_field
The expansion we want to evaluate this function for.
std::shared_ptr< FieldIO > FieldIOSharedPtr
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
static FieldMetaDataMap NullFieldMetaDataMap
std::shared_ptr< SessionReader > SessionReaderSharedPtr