Nektar++
InputXml.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: InputXml.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Read xml file and set up expansions
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "InputXml.h"
41 
42 static std::string npts = LibUtilities::SessionReader::RegisterCmdLineArgument(
43  "NumberOfPoints","n","Define number of points to dump output");
44 
45 namespace Nektar
46 {
47 namespace Utilities
48 {
49 
50 ModuleKey InputXml::m_className[5] = {
52  ModuleKey(eInputModule, "xml"), InputXml::create,
53  "Reads Xml file."),
55  ModuleKey(eInputModule, "xml.gz"), InputXml::create,
56  "Reads Xml file."),
57 };
58 
59 
60 /**
61  * @brief Set up InputXml object.
62  *
63  */
64 InputXml::InputXml(FieldSharedPtr f) : InputModule(f)
65 {
66  m_allowedFiles.insert("xml");
67  m_allowedFiles.insert("xml.gz");
68  m_allowedFiles.insert("fld"); // these files could be allowed with xml files
69  m_allowedFiles.insert("chk");
70  m_allowedFiles.insert("rst");
71 }
72 
73 
74 /**
75  *
76  */
78 {
79 }
80 
81 
82 /**
83  *
84  */
85 void InputXml::Process(po::variables_map &vm)
86 {
87 
88  if(m_f->m_verbose)
89  {
90  cout << "Processing input xml file" << endl;
91  }
92  // check to see if fld file defined so can use in
93  // expansion defintion if required
94  string fldending;
95  bool fldfilegiven = true;
96 
97  //Determine appropriate field input
98  if(m_f->m_inputfiles.count("fld") != 0)
99  {
100  fldending = "fld";
101  }
102  else if(m_f->m_inputfiles.count("chk") != 0)
103  {
104  fldending = "chk";
105  }
106  else if (m_f->m_inputfiles.count("rst") != 0)
107  {
108  fldending = "rst";
109  }
110  else
111  {
112  fldfilegiven = false;
113  }
114 
115  string xml_ending = "xml";
116  string xml_gz_ending = "xml.gz";
117 
118 
119  std::vector<std::string> files;
120  // load .xml ending
121  for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
122  {
123  files.push_back(m_f->m_inputfiles[xml_ending][i]);
124  }
125 
126  // load any .xml.gz endings
127  for (int j =0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
128  {
129  files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
130  }
131 
134 
135 
136  // define range to process output
137  if(vm.count("range"))
138  {
139  vector<NekDouble> values;
141  vm["range"].as<string>().c_str(), values),
142  "Failed to interpret range string");
143 
144  ASSERTL0(values.size() > 1,
145  "Do not have minimum values of xmin,xmax");
146  ASSERTL0(values.size() % 2 == 0,
147  "Do not have an even number of range values");
148 
149  int nvalues = values.size()/2;
152 
153  rng->m_doZrange = false;
154  rng->m_doYrange = false;
155  rng->m_checkShape = false;
156 
157  switch(nvalues)
158  {
159  case 3:
160  rng->m_doZrange = true;
161  rng->m_zmin = values[4];
162  rng->m_zmax = values[5];
163  case 2:
164  rng->m_doYrange = true;
165  rng->m_ymin = values[2];
166  rng->m_ymax = values[3];
167  case 1:
168  rng->m_doXrange = true;
169  rng->m_xmin = values[0];
170  rng->m_xmax = values[1];
171  break;
172  default:
173  ASSERTL0(false,"too many values specfied in range");
174  }
175  }
176 
177  // define range to only take a single shape.
178  if(vm.count("onlyshape"))
179  {
181  {
184  rng->m_doXrange = false;
185  rng->m_doYrange = false;
186  rng->m_doZrange = false;
187  }
188 
189  rng->m_checkShape = true;
190 
191  string shapematch =
192  boost::to_upper_copy(vm["onlyshape"].as<string>());
193  int i;
194  for(i = 0; i < LibUtilities::SIZE_ShapeType; ++i)
195  {
196  string shapeval = LibUtilities::ShapeTypeMap[i];
197  boost::to_upper(shapeval);
198  if(shapematch.compare(shapeval) == 0)
199  {
200  rng->m_shapeType = (LibUtilities::ShapeType)i;
201  break;
202  }
203  }
204  ASSERTL0(i != LibUtilities::SIZE_ShapeType,
205  "Failed to find shape type in -onlyshape command line "
206  "argument");
207  }
208 
209 
210  if(m_f->m_verbose)
211  {
212  string firstarg = "FieldConvert";
213  string verbose = "-v";
214  char **argv;
215  argv = (char**)malloc(2*sizeof(char*));
216  argv[0] = (char *)malloc(firstarg.size()*sizeof(char));
217  argv[1] = (char *)malloc(verbose.size()*sizeof(char));
218 
219  sprintf(argv[0],"%s",firstarg.c_str());
220  sprintf(argv[1],"%s",verbose.c_str());
221 
223  CreateInstance(2, (char **)argv, files, m_f->m_comm);
224  }
225  else
226  {
228  CreateInstance(0, 0, files, m_f->m_comm);
229  }
230 
231  m_f->m_graph = SpatialDomains::MeshGraph::Read(m_f->m_session,rng);
233  ::AllocateSharedPtr(m_f->m_session->GetComm());
234 
235  // currently load all field (possibly could read data from
236  // expansion list but it is re-arranged in expansion)
237  const SpatialDomains::ExpansionMap &expansions = m_f->m_graph->GetExpansions();
238 
239  // if Range has been speficied it is possible to have a
240  // partition which is empty so ccheck this and return if
241  // no elements present.
242  if(!expansions.size())
243  {
244  return;
245  }
246 
247  m_f->m_exp.resize(1);
248 
249  // load fielddef if fld file is defined This gives
250  // precedence to Homogeneous definition in fld file
251  int NumHomogeneousDir = 0;
252  if(fldfilegiven)
253  {
254  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],m_f->m_fielddef);
255  NumHomogeneousDir = m_f->m_fielddef[0]->m_numHomogeneousDir;
256 
257  //----------------------------------------------
258  // Set up Expansion information to use mode order from field
259  m_f->m_graph->SetExpansions(m_f->m_fielddef);
260  }
261  else
262  {
263  if(m_f->m_session->DefinesSolverInfo("HOMOGENEOUS"))
264  {
265  std::string HomoStr = m_f->m_session->GetSolverInfo("HOMOGENEOUS");
266 
267  if((HomoStr == "HOMOGENEOUS1D") || (HomoStr == "Homogeneous1D")
268  || (HomoStr == "1D") || (HomoStr == "Homo1D"))
269  {
270  NumHomogeneousDir = 1;
271  }
272  if((HomoStr == "HOMOGENEOUS2D") || (HomoStr == "Homogeneous2D")
273  || (HomoStr == "2D") || (HomoStr == "Homo2D"))
274  {
275  NumHomogeneousDir = 2;
276  }
277  }
278  }
279 
280  // reset expansion defintion to use equispaced points if required.
281  if(m_requireEquiSpaced) // set up points to be equispaced
282  {
283  int nPointsNew = 0;
284 
285  if(vm.count("output-points"))
286  {
287  nPointsNew = vm["output-points"].as<int>();
288  }
289 
290 
291  m_f->m_graph->SetExpansionsToEvenlySpacedPoints(nPointsNew);
292  }
293 
294  m_f->m_exp[0] = m_f->SetUpFirstExpList(NumHomogeneousDir,fldfilegiven);
295 }
296 
297 }
298 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
pair< ModuleType, string > ModuleKey
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
Definition: MeshGraph.cpp:119
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual void Process()=0
STL namespace.
FieldSharedPtr m_f
Field object.
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp:66
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::string npts
Definition: InputXml.cpp:42
boost::shared_ptr< DomainRange > DomainRangeShPtr
Definition: MeshGraph.h:154
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:677
static DomainRangeShPtr NullDomainRangeShPtr
Definition: MeshGraph.h:155
static bool GenerateUnOrderedVector(const char *const str, std::vector< NekDouble > &vec)
Definition: ParseUtils.hpp:127
std::map< int, ExpansionShPtr > ExpansionMap
Definition: MeshGraph.h:171
ModuleFactory & GetModuleFactory()
Abstract base class for input modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215