Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Nektar::FieldUtils::InputXml Class Reference

#include <InputXml.h>

Inheritance diagram for Nektar::FieldUtils::InputXml:
[legend]

Public Member Functions

 InputXml (FieldSharedPtr f)
 Set up InputXml object. More...
 
virtual ~InputXml ()
 
- Public Member Functions inherited from Nektar::FieldUtils::InputModule
 InputModule (FieldSharedPtr p_m)
 
void PrintSummary ()
 Print a brief summary of information. More...
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::string value="")
 Register a configuration option with a module. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
FIELD_UTILS_EXPORT void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static ModuleSharedPtr create (FieldSharedPtr f)
 Creates an instance of this class. More...
 
- Static Public Member Functions inherited from Nektar::FieldUtils::InputModule
static FIELD_UTILS_EXPORT std::string GuessFormat (std::string fileName)
 Tries to guess the format of the input file. More...
 

Static Public Attributes

static ModuleKey m_className []
 ModuleKey for class. More...
 

Protected Member Functions

virtual void v_Process (po::variables_map &vm) override
 
virtual std::string v_GetModuleName () override
 
virtual std::string v_GetModuleDescription () override
 
virtual ModulePriority v_GetModulePriority () override
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

Input module for Xml files.

Definition at line 48 of file InputXml.h.

Constructor & Destructor Documentation

◆ InputXml()

Nektar::FieldUtils::InputXml::InputXml ( FieldSharedPtr  f)

Set up InputXml object.

Definition at line 62 of file InputXml.cpp.

62  : InputModule(f)
63 {
64  m_allowedFiles.insert("xml");
65  m_allowedFiles.insert("xml.gz");
66 }
InputModule(FieldSharedPtr p_m)
Definition: Module.cpp:63
std::set< std::string > m_allowedFiles
List of allowed file formats.
Definition: Module.h:265

References Nektar::FieldUtils::Module::m_allowedFiles.

◆ ~InputXml()

Nektar::FieldUtils::InputXml::~InputXml ( )
virtual

Definition at line 71 of file InputXml.cpp.

72 {
73 }

Member Function Documentation

◆ create()

static ModuleSharedPtr Nektar::FieldUtils::InputXml::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 54 of file InputXml.h.

55  {
57  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ v_GetModuleDescription()

virtual std::string Nektar::FieldUtils::InputXml::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 69 of file InputXml.h.

70  {
71  return "Processing input xml file";
72  }

◆ v_GetModuleName()

virtual std::string Nektar::FieldUtils::InputXml::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 64 of file InputXml.h.

65  {
66  return "InputXml";
67  }

◆ v_GetModulePriority()

virtual ModulePriority Nektar::FieldUtils::InputXml::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 74 of file InputXml.h.

75  {
76  return eCreateGraph;
77  }

References Nektar::FieldUtils::eCreateGraph.

◆ v_Process()

void Nektar::FieldUtils::InputXml::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 78 of file InputXml.cpp.

79 {
80  LibUtilities::Timer timerpart;
81  if (m_f->m_verbose)
82  {
83  if (m_f->m_comm->TreatAsRankZero())
84  {
85  timerpart.Start();
86  }
87  }
88 
89  // check for multiple calls to inputXml due to split xml
90  // files. If so just return
91  if (m_f->m_graph)
92  {
93  return;
94  }
95 
96  string xml_ending = "xml";
97  string xml_gz_ending = "xml.gz";
98 
99  std::vector<std::string> files;
100  // load .xml ending
101  for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
102  {
103  files.push_back(m_f->m_inputfiles[xml_ending][i]);
104  }
105 
106  // load any .xml.gz endings
107  for (int j = 0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
108  {
109  files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
110  }
111 
113 
114  // define range to process output
115  if (vm.count("range"))
116  {
117  vector<NekDouble> values;
118  ASSERTL0(ParseUtils::GenerateVector(vm["range"].as<string>(), values),
119  "Failed to interpret range string");
120 
121  ASSERTL0(values.size() > 1, "Do not have minimum values of xmin,xmax");
122  ASSERTL0(values.size() % 2 == 0,
123  "Do not have an even number of range values");
124 
125  int nvalues = values.size() / 2;
127 
128  rng->m_doZrange = false;
129  rng->m_doYrange = false;
130  rng->m_checkShape = false;
131 
132  switch (nvalues)
133  {
134  case 3:
135  rng->m_doZrange = true;
136  rng->m_zmin = values[4];
137  rng->m_zmax = values[5];
138  /* Falls through. */
139  case 2:
140  rng->m_doYrange = true;
141  rng->m_ymin = values[2];
142  rng->m_ymax = values[3];
143  /* Falls through. */
144  case 1:
145  rng->m_doXrange = true;
146  rng->m_xmin = values[0];
147  rng->m_xmax = values[1];
148  break;
149  default:
151  "too many values specfied in range");
152  }
153  }
154 
155  // define range to only take a single shape.
156  if (vm.count("onlyshape"))
157  {
159  {
161  rng->m_doXrange = false;
162  rng->m_doYrange = false;
163  rng->m_doZrange = false;
164  }
165 
166  rng->m_checkShape = true;
167 
168  string shapematch = boost::to_upper_copy(vm["onlyshape"].as<string>());
169  int i;
170  for (i = 0; i < LibUtilities::SIZE_ShapeType; ++i)
171  {
172  string shapeval = LibUtilities::ShapeTypeMap[i];
173  boost::to_upper(shapeval);
174  if (shapematch.compare(shapeval) == 0)
175  {
176  rng->m_shapeType = (LibUtilities::ShapeType)i;
177  break;
178  }
179  }
181  "Failed to find shape type in -onlyshape command line "
182  "argument");
183  }
184 
185  // Set up command lines options that will be passed through to SessionReader
186  vector<string> cmdArgs;
187  cmdArgs.push_back("FieldConvert");
188 
189  if (m_f->m_verbose)
190  {
191  cmdArgs.push_back("--verbose");
192  }
193 
194  if (vm.count("part-only"))
195  {
196  cmdArgs.push_back("--part-only");
197  cmdArgs.push_back(
198  boost::lexical_cast<string>(vm["part-only"].as<int>()));
199  }
200 
201  if (vm.count("part-only-overlapping"))
202  {
203  cmdArgs.push_back("--part-only-overlapping");
204  cmdArgs.push_back(
205  boost::lexical_cast<string>(vm["part-only-overlapping"].as<int>()));
206  }
207 
208  if (vm.count("npz"))
209  {
210  cmdArgs.push_back("--npz");
211  cmdArgs.push_back(boost::lexical_cast<string>(vm["npz"].as<int>()));
212  }
213 
214  // Parallel-in-time
215  if (vm.count("npt"))
216  {
217  cmdArgs.push_back("--npt");
218  cmdArgs.push_back(boost::lexical_cast<string>(vm["npt"].as<int>()));
219  }
220 
221  int argc = cmdArgs.size();
222  const char **argv = new const char *[argc];
223  for (int i = 0; i < argc; ++i)
224  {
225  argv[i] = cmdArgs[i].c_str();
226  }
227 
229  argc, (char **)argv, files, m_f->m_comm);
230 
231  if (vm.count("nparts"))
232  {
233  // make sure have pre-partitioned mesh for nparts option
234  ASSERTL0(boost::icontains(files[0], "_xml"),
235  "Expect the mesh to have been pre-partitioned when "
236  " using the \"--nparts\" option. Please use \"--part-only\" "
237  "option to prepartition xml file.");
238  }
239 
240  // Free up memory.
241  delete[] argv;
242 
243  if (m_f->m_verbose)
244  {
245  if (m_f->m_comm->TreatAsRankZero())
246  {
247  timerpart.Stop();
248  NekDouble cpuTime = timerpart.TimePerTest(1);
249 
250  stringstream ss;
251  ss << cpuTime << "s";
252  cout << "\t InputXml session reader CPU Time: " << setw(8) << left
253  << ss.str() << endl;
254  timerpart.Start();
255  }
256  }
257 
258  m_f->m_graph = SpatialDomains::MeshGraph::Read(m_f->m_session, rng);
259 
260  if (m_f->m_verbose)
261  {
262  if (m_f->m_comm->TreatAsRankZero())
263  {
264  timerpart.Stop();
265  NekDouble cpuTime = timerpart.TimePerTest(1);
266 
267  stringstream ss;
268  ss << cpuTime << "s";
269  cout << "\t InputXml mesh graph setup CPU Time: " << setw(8)
270  << left << ss.str() << endl;
271  timerpart.Start();
272  }
273  }
274 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
Definition: Timer.cpp:68
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:131
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true)
Definition: MeshGraph.cpp:111
const char *const ShapeTypeMap[SIZE_ShapeType]
Definition: ShapeType.hpp:79
std::shared_ptr< DomainRange > DomainRangeShPtr
Definition: DomainRange.h:66
static DomainRangeShPtr NullDomainRangeShPtr
Definition: DomainRange.h:67
double NekDouble

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::ErrorUtil::efatal, Nektar::ParseUtils::GenerateVector(), Nektar::FieldUtils::Module::m_f, NEKERROR, Nektar::LibUtilities::NullDomainRangeShPtr, Nektar::SpatialDomains::MeshGraph::Read(), Nektar::LibUtilities::ShapeTypeMap, Nektar::LibUtilities::SIZE_ShapeType, Nektar::LibUtilities::Timer::Start(), Nektar::LibUtilities::Timer::Stop(), and Nektar::LibUtilities::Timer::TimePerTest().

Member Data Documentation

◆ m_className

ModuleKey Nektar::FieldUtils::InputXml::m_className
static
Initial value:
= {
ModuleKey(eInputModule, "xml"), InputXml::create, "Reads Xml file."),
ModuleKey(eInputModule, "xml.gz"), InputXml::create, "Reads Xml file."),
}
static ModuleSharedPtr create(FieldSharedPtr f)
Creates an instance of this class.
Definition: InputXml.h:54
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

ModuleKey for class.

Definition at line 59 of file InputXml.h.