37 #include <boost/algorithm/string/classification.hpp>
38 #include <boost/algorithm/string/predicate.hpp>
39 #include <boost/algorithm/string/split.hpp>
40 #include <boost/core/ignore_unused.hpp>
41 #include <boost/program_options.hpp>
53 const std::weak_ptr<EquationSystem> &pEquation,
const ParamMap &pParams)
54 :
Filter(pSession, pEquation)
59 auto it = pParams.find(
"OutputFile");
60 if (it == pParams.end())
62 std::stringstream outname;
63 outname <<
m_session->GetSessionName() <<
".fld";
68 ASSERTL0(it->second.length() > 0,
"Missing parameter 'OutputFile'.");
69 if (it->second.find_last_of(
'.') != std::string::npos)
75 std::stringstream outname;
76 outname << it->second <<
".fld";
82 it = pParams.find(
"RestartFile");
83 if (it == pParams.end())
89 ASSERTL0(it->second.length() > 0,
"Missing parameter 'RestartFile'.");
90 if (it->second.find_last_of(
'.') != std::string::npos)
96 std::stringstream outname;
97 outname << it->second <<
".fld";
103 it = pParams.find(
"OutputFrequency");
104 if (it == pParams.end())
119 it = pParams.find(
"PhaseAverage");
120 if (it == pParams.end())
126 std::string sOption = it->second.c_str();
128 (boost::iequals(sOption,
"yes"));
133 auto itPeriod = pParams.find(
"PhaseAveragePeriod");
134 auto itPhase = pParams.find(
"PhaseAveragePhase");
138 (itPeriod != pParams.end() && itPhase != pParams.end()),
139 "The phase sampling feature requires both 'PhaseAveragePeriod' and "
140 "'PhaseAveragePhase' to be set.");
152 "PhaseAveragePeriod must be greater than 0.");
154 "PhaseAveragePhase must be between 0 and 1.");
157 it = pParams.find(
"SampleFrequency");
158 if (it == pParams.end())
173 if (
m_session->GetComm()->GetRank() == 0 &&
174 m_session->DefinesCmdLineArgument(
"verbose"))
176 std::cout <<
"Phase sampling activated with period "
179 <<
"Sampling within a tolerance of "
192 m_f = std::shared_ptr<Field>(
new Field());
193 std::vector<std::string> modcmds;
195 std::stringstream moduleStream;
196 it = pParams.find(
"Modules");
197 if (it != pParams.end())
199 moduleStream.str(it->second);
201 while (!moduleStream.fail())
204 moduleStream >> sMod;
205 if (!moduleStream.fail())
207 modcmds.push_back(sMod);
215 std::vector<std::string> tmp;
220 it = pParams.find(
"options");
221 if (it != pParams.end())
225 std::vector<char *> argv;
227 strargv =
"dummy " + it->second;
228 strargv.push_back((
char)0);
230 for (
size_t i = 0; strargv[i]; ++i)
232 if (strargv[i] !=
' ' && flag)
234 argv.push_back(&strargv[i]);
238 if (strargv[i] ==
' ')
245 po::options_description desc(
"Available options");
250 "Produce this help message.")
252 "Print the list of available modules.")
253 (
"output-points,n", po::value<int>(),
254 "Output at n equipspaced points along the "
255 "collapsed coordinates (for .dat, .vtu).")
256 (
"output-points-hom-z", po::value<int>(),
257 "Number of planes in the z-direction for output of "
258 "Homogeneous 1D expansion(for .dat, .vtu).")
260 "Write error of fields for regression checking")
262 "Force the output to be written without any checks")
263 (
"range,r", po::value<std::string>(),
264 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
265 "in which any vertex is contained.")
267 "Do not use equispaced output.")
268 (
"nparts", po::value<int>(),
269 "Define nparts if running serial problem to mimic "
270 "parallel run with many partitions.")
271 (
"npz", po::value<int>(),
272 "Used to define number of partitions in z for Homogeneous1D "
273 "expansions for parallel runs.")
274 (
"onlyshape", po::value<std::string>(),
275 "Only use element with defined shape type i.e. -onlyshape "
277 (
"part-only", po::value<int>(),
278 "Partition into specified npart partitions and exit")
279 (
"part-only-overlapping", po::value<int>(),
280 "Partition into specified npart overlapping partitions and exit")
281 (
"modules-opt,p", po::value<std::string>(),
282 "Print options for a module.")
283 (
"module,m", po::value<std::vector<std::string> >(),
284 "Specify modules which are to be used.")
285 (
"useSessionVariables",
286 "Use variables defined in session for output")
287 (
"useSessionExpansion",
288 "Use expansion defined in session.")
290 "Enable verbose mode.");
293 po::options_description hidden(
"Hidden options");
297 (
"input-file", po::value<std::vector<std::string> >(),
301 po::options_description cmdline_options;
302 cmdline_options.add(hidden).add(desc);
304 po::options_description visible(
"Allowed options");
307 po::positional_options_description
p;
308 p.add(
"input-file", -1);
312 po::store(po::command_line_parser(argc, &(argv[0]))
313 .options(cmdline_options)
319 catch (
const std::exception &e)
321 std::cerr << e.what() << std::endl;
325 m_vm.insert(std::make_pair(
"forceoutput", po::variable_value()));
345 nfield = (n < pFields.size()) ? n : 0;
351 m_fieldMetaData[
"InitialTime"] = boost::lexical_cast<std::string>(time);
357 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
358 std::vector<std::vector<NekDouble>> fieldData;
362 fld->Import(
m_restartFile, fieldDef, fieldData, fieldMetaData);
370 for (k = 0; k < pFields.size(); ++k)
372 if (pFields[k]->GetSession()->GetVariable(k) ==
m_variables[j])
383 for (
int i = 0; i < fieldData.size(); ++i)
385 pFields[nfield]->ExtractDataToCoeffs(
391 if (fieldMetaData.count(
"NumberOfFieldDumps"))
393 m_numSamples = atoi(fieldMetaData[
"NumberOfFieldDumps"].c_str());
400 if (fieldMetaData.count(
"InitialTime"))
406 if (fieldMetaData.count(
"FilterFileNum"))
408 m_outputIndex = atoi(fieldMetaData[
"FilterFileNum"].c_str());
424 int nfield = pFields.size();
426 for (
int n = 0; n < nfield; ++n)
428 m_variables[n] = pFields[n]->GetSession()->GetVariable(n);
432 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
433 for (
int n = 0; n < nfield; ++n)
435 coeffs[n] = pFields[n]->GetCoeffs();
438 auto equ =
m_equ.lock();
439 ASSERTL0(equ,
"Weak pointer expired");
454 int nfield = pFields.size();
455 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
456 for (
int n = 0; n < nfield; ++n)
458 coeffs[n] = pFields[n]->GetCoeffs();
461 auto equ =
m_equ.lock();
462 ASSERTL0(equ,
"Weak pointer expired");
463 equ->ExtraFldOutput(coeffs, variables);
485 if (
m_session->GetComm()->GetRank() == 0 &&
486 m_session->DefinesCmdLineArgument(
"verbose"))
488 std::cout <<
"Sample: " << std::setw(8) << std::left
490 << std::left << currentPhase << std::endl;
523 boost::ignore_unused(pFields, time);
545 std::stringstream outname;
552 outname <<
name << suffix << ext;
556 outname <<
name <<
"_" << dump << suffix << ext;
564 for (
int i = 0; i <
m_modules.size(); ++i)
566 if (
m_modules[i]->GetModulePriority() == priority)
593 for (
int i = 0; i < modcmds.size(); ++i)
596 std::vector<std::string> tmp1;
600 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
602 if (i == modcmds.size() - 1)
613 if (tmp1.size() == 1)
615 int dot = tmp1[0].find_last_of(
'.') + 1;
616 std::string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
618 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
622 module.second = tmp1[1];
623 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
630 module.second = tmp1[0];
639 for (
int j = offset; j < tmp1.size(); ++j)
641 std::vector<std::string> tmp2;
642 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
644 if (tmp2.size() == 1)
646 mod->RegisterConfig(tmp2[0]);
648 else if (tmp2.size() == 2)
650 mod->RegisterConfig(tmp2[0], tmp2[1]);
654 std::cerr <<
"ERROR: Invalid module configuration: format is "
655 <<
"either :arg or :arg=val" << std::endl;
666 for (
int i = 0; i <
m_modules.size(); ++i)
668 ++modulesCount[
m_modules[i]->GetModulePriority()];
676 module.second = std::string(
"equispacedoutput");
691 m_f->m_graph = pFields[0]->GetGraph();
692 m_f->m_comm =
m_f->m_session->GetComm();
696 m_f->m_numHomogeneousDir = 0;
699 m_f->m_numHomogeneousDir = 1;
703 m_f->m_numHomogeneousDir = 2;
707 m_f->m_exp[0] = pFields[0];
712 nfield = (n < pFields.size()) ? n : 0;
716 m_f->m_exp[n]->SetWaveSpace(
false);
719 "pFields[nfield] does not have the "
720 "same number of coefficients as m_outFields[n]");
722 m_f->m_exp[n]->ExtractCoeffsToCoeffs(pFields[nfield],
m_outFields[n],
723 m_f->m_exp[n]->UpdateCoeffs());
725 m_f->m_exp[n]->BwdTrans(
m_f->m_exp[n]->GetCoeffs(),
726 m_f->m_exp[n]->UpdatePhys());
736 for (
int i = 0; i < modules.size(); ++i)
738 ++modulesCount[modules[i]->GetModulePriority()];
748 std::stringstream ss;
750 for (
int i = 0; i < modules.size(); ++i)
755 modules[i]->GetModulePriority() ==
eCreateExp ||
756 modules[i]->GetModulePriority() ==
eFillExp ||
757 modules[i]->GetModulePriority() ==
eCreatePts)
759 ss << modules[i]->GetModuleName() <<
" ";
762 ss <<
"not compatible with FilterFieldConvert.";
770 std::stringstream ss;
772 for (
int i = 0; i < modules.size(); ++i)
776 ss << modules[i]->GetModuleName() <<
" ";
779 ss <<
"is not compatible with module(s): ";
780 for (
int i = 0; i < modules.size(); ++i)
784 ss << modules[i]->GetModuleName() <<
" ";
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
NekDouble Evaluate() const
static std::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
virtual SOLVER_UTILS_EXPORT void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
std::string m_restartFile
virtual SOLVER_UTILS_EXPORT void v_ProcessSample(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, std::vector< Array< OneD, NekDouble >> &fieldcoeffs, const NekDouble &time)
virtual SOLVER_UTILS_EXPORT ~FilterFieldConvert()
static std::string className
Name of the class.
void CreateFields(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields)
unsigned int m_outputFrequency
unsigned int m_sampleFrequency
virtual SOLVER_UTILS_EXPORT void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
std::vector< std::string > m_variables
void CheckModules(std::vector< ModuleSharedPtr > &modules)
virtual SOLVER_UTILS_EXPORT bool v_IsTimeDependent()
NekDouble m_phaseTolerance
unsigned int m_numSamples
virtual SOLVER_UTILS_EXPORT void v_FillVariablesName(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields)
virtual SOLVER_UTILS_EXPORT void v_PrepareOutput(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const std::map< std::string, std::string > &pParams)
Creates an instance of this class.
SOLVER_UTILS_EXPORT FilterFieldConvert(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
void CreateModules(std::vector< std::string > &modcmds)
void OutputField(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, int dump=-1)
LibUtilities::FieldMetaDataMap m_fieldMetaData
NekDouble m_phaseSamplePeriod
std::vector< Array< OneD, NekDouble > > m_outFields
virtual SOLVER_UTILS_EXPORT NekDouble v_GetScale()
unsigned int m_outputIndex
virtual SOLVER_UTILS_EXPORT std::string v_GetFileSuffix()
virtual SOLVER_UTILS_EXPORT void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
NekDouble m_phaseSamplePhase
std::vector< ModuleSharedPtr > m_modules
LibUtilities::SessionReaderSharedPtr m_session
const std::weak_ptr< EquationSystem > m_equ
std::map< std::string, std::string > ParamMap
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< Module > ModuleSharedPtr
ModuleFactory & GetModuleFactory()
std::shared_ptr< FieldIO > FieldIOSharedPtr
std::map< std::string, std::string > FieldMetaDataMap
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static PtsFieldSharedPtr NullPtsField
FilterFactory & GetFilterFactory()
The above copyright notice and this permission notice shall be included.
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)