42#include <boost/format.hpp>
59 : m_session(session), m_field(
field), m_name(functionName),
63 "Function '" +
m_name +
"' does not exist.");
77 std::vector<std::string> vFieldNames =
m_session->GetVariables();
79 for (
int i = 0; i < vFieldNames.size(); i++)
81 Evaluate(vFieldNames[i], pArray[i], pTime, domain);
98 ASSERTL1(pFieldNames.size() == pArray.size(),
100 "' variable list size mismatch with array storage.");
102 for (
int i = 0; i < pFieldNames.size(); i++)
104 Evaluate(pFieldNames[i], pArray[i], pTime, domain);
118 std::vector<std::string> pFieldNames,
120 const NekDouble &pTime,
const int domain)
122 ASSERTL0(pFieldNames.size() == pFields.size(),
123 "Field list / name list size mismatch.");
125 for (
int i = 0; i < pFieldNames.size(); i++)
127 Evaluate(pFieldNames[i], pFields[i]->UpdatePhys(), pTime, domain);
128 if (pFields[i]->GetWaveSpace())
130 pFields[i]->HomogeneousFwdTrans(pFields[i]->GetTotPoints(),
131 pFields[i]->GetPhys(),
132 pFields[i]->UpdatePhys());
134 pFields[i]->FwdTransLocalElmt(pFields[i]->GetPhys(),
135 pFields[i]->UpdateCoeffs());
150 const NekDouble &pTime,
const int domain)
155 unsigned int nq =
m_field->GetNpoints();
157 std::pair<std::string, int> key(pFieldName, domain);
165 if (pArray.size() < nq)
181 std::string filename =
184 if (fs::path(filename).extension() ==
".pts" ||
185 fs::path(filename).extension() ==
".csv")
196 ASSERTL0(
false,
"unknown eFunctionType");
224 retVal = ffunc->GetExpression();
229 std::string filename =
231 retVal =
"from file " + filename;
235 ASSERTL0(
false,
"unknown eFunctionType");
251 const NekDouble &pTime,
const int domain)
253 unsigned int nq =
m_field->GetNpoints();
254 if (pArray.size() < nq)
265 m_field->GetCoords(x0, x1, x2);
269 ffunc->Evaluate(x0, x1, x2, pTime, pArray);
282 const NekDouble &pTime,
const int domain)
284 unsigned int nq =
m_field->GetNpoints();
285 if (pArray.size() < nq)
290 std::string filename =
292 std::string fileVar =
295 if (fileVar.length() == 0)
297 fileVar = pFieldName;
308#if (defined _WIN32 && _MSC_VER < 1900)
311 unsigned int old_exponent_format;
312 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
314 _set_output_format(old_exponent_format);
322 "\", variable \"" + fileVar +
"\"")
327 int numexp =
m_field->GetExpSize();
329 for (
int i = 0; i < numexp; ++i)
331 ElementGIDs[i] =
m_field->GetExp(i)->GetGeom()->GetGlobalID();
334 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
335 std::vector<std::vector<NekDouble>> FieldData;
338 fldIO->Import(filename, FieldDef, FieldData,
344 for (
int i = 0; i < FieldDef.size(); ++i)
348 for (
int j = 0; j < FieldDef[i]->m_fields.size(); ++j)
350 if (FieldDef[i]->m_fields[j] == fileVar)
358 m_field->ExtractDataToCoeffs(FieldDef[i], FieldData[i],
359 FieldDef[i]->m_fields[idx], vCoeffs);
363 std::cout <<
"Field " + fileVar +
" not found." << std::endl;
367 bool wavespace =
m_field->GetWaveSpace();
369 m_field->BwdTrans(vCoeffs, pArray);
370 m_field->SetWaveSpace(wavespace);
383 const NekDouble &pTime,
const int domain)
385 unsigned int nq =
m_field->GetNpoints();
386 if (pArray.size() < 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 "\", variable \"" + fileVar +
"\"")
431 std::string funcFilename =
435 if (fs::path(filename).extension() ==
".pts")
438 ptsIO.
Import(filename, inPts);
440 else if (fs::path(filename).extension() ==
".csv")
443 csvIO.
Import(filename, inPts);
447 ASSERTL1(
false,
"Unsupported file type");
451 inPts->GetNFields());
452 for (
int i = 0; i < inPts->GetDim() + inPts->GetNFields(); ++i)
456 if (inPts->GetDim() == 1)
460 else if (inPts->GetDim() == 2)
462 m_field->GetCoords(pts[0], pts[1]);
464 else if (inPts->GetDim() == 3)
466 m_field->GetCoords(pts[0], pts[1], pts[2]);
469 inPts->GetDim(), inPts->GetFieldNames(), pts);
480 std::vector<MultiRegions::ExpListSharedPtr>>(
482 if (
m_session->GetComm()->GetRank() == 0)
488 if (
m_session->GetComm()->GetRank() == 0)
490 std::cout << std::endl;
491 if (
m_session->DefinesCmdLineArgument(
"verbose"))
507 std::vector<std::string> fieldNames = outPts->GetFieldNames();
508 for (fieldInd = 0; fieldInd < fieldNames.size(); ++fieldInd)
510 if (outPts->GetFieldName(fieldInd) == fileVar)
515 ASSERTL0(fieldInd != fieldNames.size(),
"field not found");
517 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)