Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::InputXml:
Collaboration graph
[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 ()
 
- Public Member Functions inherited from Nektar::FieldUtils::InputModule
 InputModule (FieldSharedPtr p_m)
 
FIELD_UTILS_EXPORT void AddFile (string fileType, string fileName)
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
FIELD_UTILS_EXPORT void RegisterConfig (string key, 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 bool GetRequireEquiSpaced (void)
 
FIELD_UTILS_EXPORT void SetRequireEquiSpaced (bool pVal)
 
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 Attributes

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

Additional Inherited Members

- Protected Member Functions inherited from Nektar::FieldUtils::InputModule
void PrintSummary ()
 Print summary of elements. More...
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
- Protected Attributes inherited from Nektar::FieldUtils::InputModule
set< string > m_allowedFiles
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 

Detailed Description

Input module for Xml files.

Definition at line 49 of file InputXml.h.

Constructor & Destructor Documentation

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

Set up InputXml object.

Definition at line 65 of file InputXml.cpp.

References Nektar::FieldUtils::InputModule::m_allowedFiles.

65  : InputModule(f)
66 {
67  m_allowedFiles.insert("xml");
68  m_allowedFiles.insert("xml.gz");
69  m_allowedFiles.insert("fld"); // these files could be allowed with xml files
70  m_allowedFiles.insert("chk");
71  m_allowedFiles.insert("rst");
72 }
Nektar::FieldUtils::InputXml::~InputXml ( )
virtual

Definition at line 77 of file InputXml.cpp.

78 {
79 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 57 of file InputXml.h.

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

58  {
60  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual std::string Nektar::FieldUtils::InputXml::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 64 of file InputXml.h.

65  {
66  return "InputXml";
67  }
void Nektar::FieldUtils::InputXml::Process ( po::variables_map &  vm)
virtual

Implements Nektar::FieldUtils::Module.

Definition at line 84 of file InputXml.cpp.

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

85 {
86  Timer timerpart;
87 
88  // check for multiple calls to inputXml due to split xml
89  // files. If so just return
90  int expsize = m_f->m_exp.size();
91  m_f->m_comm->AllReduce(expsize, LibUtilities::ReduceMax);
92 
93  if (expsize != 0)
94  {
95  return;
96  }
97 
98  if (m_f->m_verbose)
99  {
100  if (m_f->m_comm->TreatAsRankZero())
101  {
102  cout << "Processing input xml file" << endl;
103  timerpart.Start();
104  }
105  }
106 
107  // check to see if fld file defined so can use in
108  // expansion defintion if required
109  string fldending;
110  bool fldfilegiven = true;
111 
112  // Determine appropriate field input
113  if (m_f->m_inputfiles.count("fld") != 0)
114  {
115  fldending = "fld";
116  }
117  else if (m_f->m_inputfiles.count("chk") != 0)
118  {
119  fldending = "chk";
120  }
121  else if (m_f->m_inputfiles.count("rst") != 0)
122  {
123  fldending = "rst";
124  }
125  else
126  {
127  fldfilegiven = false;
128  }
129 
130  string xml_ending = "xml";
131  string xml_gz_ending = "xml.gz";
132 
133  std::vector<std::string> files;
134  // load .xml ending
135  for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
136  {
137  files.push_back(m_f->m_inputfiles[xml_ending][i]);
138  }
139 
140  // load any .xml.gz endings
141  for (int j = 0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
142  {
143  files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
144  }
145 
147 
148  // define range to process output
149  if (vm.count("range"))
150  {
151  vector<NekDouble> values;
153  vm["range"].as<string>().c_str(), values),
154  "Failed to interpret range string");
155 
156  ASSERTL0(values.size() > 1, "Do not have minimum values of xmin,xmax");
157  ASSERTL0(values.size() % 2 == 0,
158  "Do not have an even number of range values");
159 
160  int nvalues = values.size() / 2;
162 
163  rng->m_doZrange = false;
164  rng->m_doYrange = false;
165  rng->m_checkShape = false;
166 
167  switch (nvalues)
168  {
169  case 3:
170  rng->m_doZrange = true;
171  rng->m_zmin = values[4];
172  rng->m_zmax = values[5];
173  case 2:
174  rng->m_doYrange = true;
175  rng->m_ymin = values[2];
176  rng->m_ymax = values[3];
177  case 1:
178  rng->m_doXrange = true;
179  rng->m_xmin = values[0];
180  rng->m_xmax = values[1];
181  break;
182  default:
183  ASSERTL0(false, "too many values specfied in range");
184  }
185  }
186 
187  // define range to only take a single shape.
188  if (vm.count("onlyshape"))
189  {
191  {
192  rng =
194  rng->m_doXrange = false;
195  rng->m_doYrange = false;
196  rng->m_doZrange = false;
197  }
198 
199  rng->m_checkShape = true;
200 
201  string shapematch = boost::to_upper_copy(vm["onlyshape"].as<string>());
202  int i;
203  for (i = 0; i < LibUtilities::SIZE_ShapeType; ++i)
204  {
205  string shapeval = LibUtilities::ShapeTypeMap[i];
206  boost::to_upper(shapeval);
207  if (shapematch.compare(shapeval) == 0)
208  {
209  rng->m_shapeType = (LibUtilities::ShapeType)i;
210  break;
211  }
212  }
213  ASSERTL0(i != LibUtilities::SIZE_ShapeType,
214  "Failed to find shape type in -onlyshape command line "
215  "argument");
216  }
217 
218  // Set up command lines options that will be passed through to SessionReader
219  vector<string> cmdArgs;
220  cmdArgs.push_back("FieldConvert");
221 
222  if (m_f->m_verbose)
223  {
224  cmdArgs.push_back("--verbose");
225  }
226 
227  if (vm.count("part-only"))
228  {
229  cmdArgs.push_back("--part-only");
230  cmdArgs.push_back(
231  boost::lexical_cast<string>(vm["part-only"].as<int>()));
232  }
233 
234  if (vm.count("part-only-overlapping"))
235  {
236  cmdArgs.push_back("--part-only-overlapping");
237  cmdArgs.push_back(
238  boost::lexical_cast<string>(vm["part-only-overlapping"].as<int>()));
239  }
240 
241  if (vm.count("npz"))
242  {
243  cmdArgs.push_back("--npz");
244  cmdArgs.push_back(boost::lexical_cast<string>(vm["npz"].as<int>()));
245  }
246 
247  int argc = cmdArgs.size();
248  const char **argv = new const char *[argc];
249  for (int i = 0; i < argc; ++i)
250  {
251  argv[i] = cmdArgs[i].c_str();
252  }
253 
255  argc, (char **)argv, files, m_f->m_comm);
256 
257  // Free up memory.
258  delete[] argv;
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 session reader CPU Time: " << setw(8) << left
270  << ss.str() << endl;
271  timerpart.Start();
272  }
273  }
274 
275  m_f->m_graph = SpatialDomains::MeshGraph::Read(m_f->m_session, rng);
276 
277  if (m_f->m_verbose)
278  {
279  if (m_f->m_comm->TreatAsRankZero())
280  {
281  timerpart.Stop();
282  NekDouble cpuTime = timerpart.TimePerTest(1);
283 
284  stringstream ss;
285  ss << cpuTime << "s";
286  cout << "\t InputXml mesh graph setup CPU Time: " << setw(8)
287  << left << ss.str() << endl;
288  timerpart.Start();
289  }
290  }
291 
292  // currently load all field (possibly could read data from
293  // expansion list but it is re-arranged in expansion)
294  const SpatialDomains::ExpansionMap &expansions =
295  m_f->m_graph->GetExpansions();
296 
297  // if Range has been speficied it is possible to have a
298  // partition which is empty so ccheck this and return if
299  // no elements present.
300  if (!expansions.size())
301  {
302  return;
303  }
304 
305  m_f->m_exp.resize(1);
306 
307  // load fielddef header if fld file is defined. This gives
308  // precedence to Homogeneous definition in fld file
309  int NumHomogeneousDir = 0;
310  if (fldfilegiven)
311  {
312  // use original expansion to identify which elements are in
313  // this partition/subrange
314 
315  Array<OneD, int> ElementGIDs(expansions.size());
316  SpatialDomains::ExpansionMap::const_iterator expIt;
317 
318  int i = 0;
319  for (expIt = expansions.begin(); expIt != expansions.end(); ++expIt)
320  {
321  ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
322  }
323 
324  m_f->m_fielddef.clear();
325  m_f->m_data.clear();
326 
327  m_f->FieldIOForFile(m_f->m_inputfiles[fldending][0])->Import(
328  m_f->m_inputfiles[fldending][0], m_f->m_fielddef, m_f->m_data,
329  m_f->m_fieldMetaDataMap, ElementGIDs);
330  NumHomogeneousDir = m_f->m_fielddef[0]->m_numHomogeneousDir;
331 
332  //----------------------------------------------
333  // Set up Expansion information to use mode order from field
334  m_f->m_graph->SetExpansions(m_f->m_fielddef);
335  }
336  else
337  {
338  if (m_f->m_session->DefinesSolverInfo("HOMOGENEOUS"))
339  {
340  std::string HomoStr = m_f->m_session->GetSolverInfo("HOMOGENEOUS");
341 
342  if ((HomoStr == "HOMOGENEOUS1D") || (HomoStr == "Homogeneous1D") ||
343  (HomoStr == "1D") || (HomoStr == "Homo1D"))
344  {
345  NumHomogeneousDir = 1;
346  }
347  if ((HomoStr == "HOMOGENEOUS2D") || (HomoStr == "Homogeneous2D") ||
348  (HomoStr == "2D") || (HomoStr == "Homo2D"))
349  {
350  NumHomogeneousDir = 2;
351  }
352  }
353  }
354 
355  // reset expansion defintion to use equispaced points if required.
357  {
358  int nPointsNew = 0;
359 
360  if (vm.count("output-points"))
361  {
362  nPointsNew = vm["output-points"].as<int>();
363  }
364 
365  m_f->m_graph->SetExpansionsToEvenlySpacedPoints(nPointsNew);
366  }
367  else
368  {
369  if (vm.count("output-points"))
370  {
371  int nPointsNew = vm["output-points"].as<int>();
372  m_f->m_graph->SetExpansionsToPointOrder(nPointsNew);
373  }
374  }
375 
376  if (m_f->m_verbose)
377  {
378  if (m_f->m_comm->TreatAsRankZero())
379  {
380  timerpart.Stop();
381  NekDouble cpuTime = timerpart.TimePerTest(1);
382 
383  stringstream ss;
384  ss << cpuTime << "s";
385  cout << "\t InputXml setexpansion CPU Time: " << setw(8) << left
386  << ss.str() << endl;
387  timerpart.Start();
388  }
389  }
390 
391  // Override number of planes with value from cmd line
392  if (NumHomogeneousDir == 1 && vm.count("output-points-hom-z"))
393  {
394  int expdim = m_f->m_graph->GetMeshDimension();
395  m_f->m_fielddef[0]->m_numModes[expdim] =
396  vm["output-points-hom-z"].as<int>();
397  }
398 
399  m_f->m_exp[0] = m_f->SetUpFirstExpList(NumHomogeneousDir, fldfilegiven);
400 
401  if (m_f->m_verbose)
402  {
403  if (m_f->m_comm->TreatAsRankZero())
404  {
405  timerpart.Stop();
406  NekDouble cpuTime = timerpart.TimePerTest(1);
407 
408  stringstream ss1;
409 
410  ss1 << cpuTime << "s";
411  cout << "\t InputXml set first exp CPU Time: " << setw(8) << left
412  << ss1.str() << endl;
413  }
414  }
415 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
Definition: MeshGraph.cpp:124
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp:66
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
void Stop()
Definition: Timer.cpp:62
boost::shared_ptr< DomainRange > DomainRangeShPtr
Definition: MeshGraph.h:157
double NekDouble
static DomainRangeShPtr NullDomainRangeShPtr
Definition: MeshGraph.h:158
void Start()
Definition: Timer.cpp:51
static bool GenerateUnOrderedVector(const char *const str, std::vector< NekDouble > &vec)
Definition: ParseUtils.hpp:128
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
Definition: Timer.cpp:108
std::map< int, ExpansionShPtr > ExpansionMap
Definition: MeshGraph.h:174
FieldSharedPtr m_f
Field object.

Member Data Documentation

ModuleKey Nektar::FieldUtils::InputXml::m_className
static
Initial value:

ModuleKey for class.

Definition at line 62 of file InputXml.h.