41 #include <boost/format.hpp>
58 SessionFunction::SessionFunction(
62 : m_session(session), m_field(field), m_name(functionName),
66 "Function '" +
m_name +
"' does not exist.");
80 std::vector<std::string> vFieldNames =
m_session->GetVariables();
82 for (
int i = 0; i < vFieldNames.size(); i++)
84 Evaluate(vFieldNames[i], pArray[i], pTime, domain);
101 ASSERTL1(pFieldNames.size() == pArray.size(),
103 "' variable list size mismatch with array storage.");
105 for (
int i = 0; i < pFieldNames.size(); i++)
107 Evaluate(pFieldNames[i], pArray[i], pTime, domain);
121 std::vector<std::string> pFieldNames,
123 const NekDouble &pTime,
const int domain)
125 ASSERTL0(pFieldNames.size() == pFields.size(),
126 "Field list / name list size mismatch.");
128 for (
int i = 0; i < pFieldNames.size(); i++)
130 Evaluate(pFieldNames[i], pFields[i]->UpdatePhys(), pTime, domain);
131 pFields[i]->FwdTransLocalElmt(pFields[i]->GetPhys(),
132 pFields[i]->UpdateCoeffs());
147 const NekDouble &pTime,
const int domain)
152 unsigned int nq =
m_field->GetNpoints();
154 std::pair<std::string, int> key(pFieldName, domain);
162 if (pArray.size() < nq)
178 std::string filename =
181 if (boost::filesystem::path(filename).extension() ==
".pts" ||
182 boost::filesystem::path(filename).extension() ==
".csv")
193 ASSERTL0(
false,
"unknown eFunctionType");
221 retVal = ffunc->GetExpression();
226 std::string filename =
228 retVal =
"from file " + filename;
232 ASSERTL0(
false,
"unknown eFunctionType");
248 const NekDouble &pTime,
const int domain)
250 unsigned int nq =
m_field->GetNpoints();
251 if (pArray.size() < nq)
262 m_field->GetCoords(x0, x1, x2);
266 ffunc->Evaluate(x0, x1, x2, pTime, pArray);
279 const NekDouble &pTime,
const int domain)
281 unsigned int nq =
m_field->GetNpoints();
282 if (pArray.size() < nq)
287 std::string filename =
289 std::string fileVar =
292 if (fileVar.length() == 0)
294 fileVar = pFieldName;
305 #if (defined _WIN32 && _MSC_VER < 1900)
308 unsigned int old_exponent_format;
309 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
311 _set_output_format(old_exponent_format);
319 "\", variable \"" + fileVar +
"\"")
324 int numexp =
m_field->GetExpSize();
326 for (
int i = 0; i < numexp; ++i)
328 ElementGIDs[i] =
m_field->GetExp(i)->GetGeom()->GetGlobalID();
331 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
332 std::vector<std::vector<NekDouble>> FieldData;
335 fldIO->Import(filename, FieldDef, FieldData,
341 for (
int i = 0; i < FieldDef.size(); ++i)
345 for (
int j = 0; j < FieldDef[i]->m_fields.size(); ++j)
347 if (FieldDef[i]->m_fields[j] == fileVar)
355 m_field->ExtractDataToCoeffs(FieldDef[i], FieldData[i],
356 FieldDef[i]->m_fields[idx], vCoeffs);
360 cout <<
"Field " + fileVar +
" not found." << endl;
364 m_field->BwdTrans(vCoeffs, pArray);
377 const NekDouble &pTime,
const int domain)
379 unsigned int nq =
m_field->GetNpoints();
380 if (pArray.size() < nq)
385 std::string filename =
387 std::string fileVar =
390 if (fileVar.length() == 0)
392 fileVar = pFieldName;
403 #if (defined _WIN32 && _MSC_VER < 1900)
406 unsigned int old_exponent_format;
407 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
409 _set_output_format(old_exponent_format);
417 "\", variable \"" + fileVar +
"\"")
425 std::string funcFilename =
429 if (boost::filesystem::path(filename).extension() ==
".pts")
432 ptsIO.
Import(filename, inPts);
434 else if (boost::filesystem::path(filename).extension() ==
".csv")
437 csvIO.
Import(filename, inPts);
441 ASSERTL1(
false,
"Unsupported file type");
445 inPts->GetNFields());
446 for (
int i = 0; i < inPts->GetDim() + inPts->GetNFields(); ++i)
450 if (inPts->GetDim() == 1)
454 else if (inPts->GetDim() == 2)
456 m_field->GetCoords(pts[0], pts[1]);
458 else if (inPts->GetDim() == 3)
460 m_field->GetCoords(pts[0], pts[1], pts[2]);
463 inPts->GetDim(), inPts->GetFieldNames(), pts);
473 if (
m_session->GetComm()->GetRank() == 0)
479 if (
m_session->GetComm()->GetRank() == 0)
482 if (
m_session->DefinesCmdLineArgument(
"verbose"))
498 vector<string> fieldNames = outPts->GetFieldNames();
499 for (fieldInd = 0; fieldInd < fieldNames.size(); ++fieldInd)
501 if (outPts->GetFieldName(fieldInd) == fileVar)
506 ASSERTL0(fieldInd != fieldNames.size(),
"field not found");
508 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 std::vector< MultiRegions::ExpListSharedPtr > expInField, std::vector< MultiRegions::ExpListSharedPtr > &expOutField, NekDouble def_value=0.0)
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.
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 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 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 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.
std::map< std::string, FieldUtils::Interpolator > m_interpolators
Interpolator for pts file input for a variable & domain combination.
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
The above copyright notice and this permission notice shall be included.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)