Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | 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 ()
 
virtual void Process (po::variables_map &vm)
 
virtual std::string GetModuleName ()
 
virtual std::string GetModuleDescription ()
 
virtual ModulePriority GetModulePriority ()
 
- 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
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
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...
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
- 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:238

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 56 of file InputXml.h.

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

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

◆ GetModuleDescription()

virtual std::string Nektar::FieldUtils::InputXml::GetModuleDescription ( )
inlinevirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 68 of file InputXml.h.

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

◆ GetModuleName()

virtual std::string Nektar::FieldUtils::InputXml::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 63 of file InputXml.h.

64  {
65  return "InputXml";
66  }

◆ GetModulePriority()

virtual ModulePriority Nektar::FieldUtils::InputXml::GetModulePriority ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 73 of file InputXml.h.

74  {
75  return eCreateGraph;
76  }

References Nektar::FieldUtils::eCreateGraph.

◆ Process()

void Nektar::FieldUtils::InputXml::Process ( po::variables_map &  vm)
virtual

Implements 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:
150  NEKERROR(ErrorUtil::efatal, "too many values specfied in range");
151  }
152  }
153 
154  // define range to only take a single shape.
155  if (vm.count("onlyshape"))
156  {
158  {
159  rng =
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  int argc = cmdArgs.size();
215  const char **argv = new const char *[argc];
216  for (int i = 0; i < argc; ++i)
217  {
218  argv[i] = cmdArgs[i].c_str();
219  }
220 
222  argc, (char **)argv, files, m_f->m_comm);
223 
224  if (vm.count("nparts"))
225  {
226  // make sure have pre-partitioned mesh for nparts option
227  ASSERTL0(boost::icontains(files[0],"_xml"),
228  "Expect the mesh to have been pre-partitioned when "
229  " using the\"--nparts\" option. Please use \"--part-only\" "
230  "option to prepartition xml file.");
231  }
232 
233  // Free up memory.
234  delete[] argv;
235 
236  if (m_f->m_verbose)
237  {
238  if (m_f->m_comm->TreatAsRankZero())
239  {
240  timerpart.Stop();
241  NekDouble cpuTime = timerpart.TimePerTest(1);
242 
243  stringstream ss;
244  ss << cpuTime << "s";
245  cout << "\t InputXml session reader CPU Time: " << setw(8) << left
246  << ss.str() << endl;
247  timerpart.Start();
248  }
249  }
250 
251  m_f->m_graph = SpatialDomains::MeshGraph::Read(m_f->m_session, rng);
252 
253  if (m_f->m_verbose)
254  {
255  if (m_f->m_comm->TreatAsRankZero())
256  {
257  timerpart.Stop();
258  NekDouble cpuTime = timerpart.TimePerTest(1);
259 
260  stringstream ss;
261  ss << cpuTime << "s";
262  cout << "\t InputXml mesh graph setup CPU Time: " << setw(8)
263  << left << ss.str() << endl;
264  timerpart.Start();
265  }
266  }
267 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#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:230
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:62
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:135
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true)
Definition: MeshGraph.cpp:113
std::shared_ptr< DomainRange > DomainRangeShPtr
Definition: DomainRange.h:61
static DomainRangeShPtr NullDomainRangeShPtr
Definition: DomainRange.h:62
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp: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:56
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

ModuleKey for class.

Definition at line 61 of file InputXml.h.