Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  ModuleKey InputXml::m_className[5] = {
51  ModuleKey(eInputModule, "xml"), InputXml::create,
52  "Reads Xml file."),
54  ModuleKey(eInputModule, "xml.gz"), InputXml::create,
55  "Reads Xml file."),
56  };
57 
58  /**
59  * @brief Set up InputXml object.
60  *
61  */
62  InputXml::InputXml(FieldSharedPtr f) : InputModule(f)
63  {
64  m_allowedFiles.insert("xml");
65  m_allowedFiles.insert("xml.gz");
66  m_allowedFiles.insert("fld"); // these files could be allowed with xml files
67  m_allowedFiles.insert("chk");
68  m_allowedFiles.insert("rst");
69  }
70 
72  {
73  }
74 
75  /**
76  *
77  */
78  void InputXml::Process(po::variables_map &vm)
79  {
80 
81  if(m_f->m_verbose)
82  {
83  cout << "Processing input xml file" << endl;
84  }
85  // check to see if fld file defined so can use in
86  // expansion defintion if required
87  string fldending;
88  bool fldfilegiven = true;
89 
90  //Determine appropriate field input
91  if(m_f->m_inputfiles.count("fld") != 0)
92  {
93  fldending = "fld";
94  }
95  else if(m_f->m_inputfiles.count("chk") != 0)
96  {
97  fldending = "chk";
98  }
99  else if (m_f->m_inputfiles.count("rst") != 0)
100  {
101  fldending = "rst";
102  }
103  else
104  {
105  fldfilegiven = false;
106  }
107 
108  string xml_ending = "xml";
109  string xml_gz_ending = "xml.gz";
110 
111 
112  std::vector<std::string> files;
113  // load .xml ending
114  for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
115  {
116  files.push_back(m_f->m_inputfiles[xml_ending][i]);
117  }
118 
119  // load any .xml.gz endings
120  for (int j =0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
121  {
122  files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
123  }
124 
127 
128 
129  // define range to process output
130  if(vm.count("range"))
131  {
132  vector<NekDouble> values;
134  vm["range"].as<string>().c_str(), values),
135  "Failed to interpret range string");
136 
137  ASSERTL0(values.size() > 1,
138  "Do not have minimum values of xmin,xmax");
139  ASSERTL0(values.size() % 2 == 0,
140  "Do not have an even number of range values");
141 
142  int nvalues = values.size()/2;
145 
146  rng->m_doZrange = false;
147  rng->m_doYrange = false;
148  rng->m_checkShape = false;
149 
150  switch(nvalues)
151  {
152  case 3:
153  rng->m_doZrange = true;
154  rng->m_zmin = values[4];
155  rng->m_zmax = values[5];
156  case 2:
157  rng->m_doYrange = true;
158  rng->m_ymin = values[2];
159  rng->m_ymax = values[3];
160  case 1:
161  rng->m_doXrange = true;
162  rng->m_xmin = values[0];
163  rng->m_xmax = values[1];
164  break;
165  default:
166  ASSERTL0(false,"too many values specfied in range");
167  }
168  }
169 
170  // define range to only take a single shape.
171  if(vm.count("onlyshape"))
172  {
174  {
177  rng->m_doXrange = false;
178  rng->m_doYrange = false;
179  rng->m_doZrange = false;
180  }
181 
182  rng->m_checkShape = true;
183 
184  string shapematch =
185  boost::to_upper_copy(vm["onlyshape"].as<string>());
186  int i;
187  for(i = 0; i < LibUtilities::SIZE_ShapeType; ++i)
188  {
189  string shapeval = LibUtilities::ShapeTypeMap[i];
190  boost::to_upper(shapeval);
191  if(shapematch.compare(shapeval) == 0)
192  {
193  rng->m_shapeType = (LibUtilities::ShapeType)i;
194  break;
195  }
196  }
197  ASSERTL0(i != LibUtilities::SIZE_ShapeType,
198  "Failed to find shape type in -onlyshape command line "
199  "argument");
200  }
201 
202 
203  if(m_f->m_verbose)
204  {
205  string firstarg = "FieldConvert";
206  string verbose = "-v";
207  char **argv;
208  argv = (char**)malloc(2*sizeof(char*));
209  argv[0] = (char *)malloc(firstarg.size()*sizeof(char));
210  argv[1] = (char *)malloc(verbose.size()*sizeof(char));
211 
212  sprintf(argv[0],"%s",firstarg.c_str());
213  sprintf(argv[1],"%s",verbose.c_str());
214 
216  CreateInstance(2, (char **)argv, files, m_f->m_comm);
217  }
218  else
219  {
221  CreateInstance(0, 0, files, m_f->m_comm);
222  }
223 
224 
225 
226 
227  m_f->m_graph = SpatialDomains::MeshGraph::Read(m_f->m_session,rng);
229  ::AllocateSharedPtr(m_f->m_session->GetComm());
230 
231  // currently load all field (possibly could read data from
232  // expansion list but it is re-arranged in expansion)
233  const SpatialDomains::ExpansionMap &expansions = m_f->m_graph->GetExpansions();
234 
235  // if Range has been speficied it is possible to have a
236  // partition which is empty so ccheck this and return if
237  // no elements present.
238  if(!expansions.size())
239  {
240  return;
241  }
242 
243  m_f->m_exp.resize(1);
244 
245  // load fielddef if fld file is defined This gives
246  // precedence to Homogeneous definition in fld file
247  int NumHomogeneousDir = 0;
248  if(fldfilegiven)
249  {
250  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],m_f->m_fielddef);
251  NumHomogeneousDir = m_f->m_fielddef[0]->m_numHomogeneousDir;
252 
253  //----------------------------------------------
254  // Set up Expansion information to use mode order from field
255  m_f->m_graph->SetExpansions(m_f->m_fielddef);
256  }
257  else
258  {
259  if(m_f->m_session->DefinesSolverInfo("HOMOGENEOUS"))
260  {
261  std::string HomoStr = m_f->m_session->GetSolverInfo("HOMOGENEOUS");
262 
263  if((HomoStr == "HOMOGENEOUS1D") || (HomoStr == "Homogeneous1D")
264  || (HomoStr == "1D") || (HomoStr == "Homo1D"))
265  {
266  NumHomogeneousDir = 1;
267  }
268  if((HomoStr == "HOMOGENEOUS2D") || (HomoStr == "Homogeneous2D")
269  || (HomoStr == "2D") || (HomoStr == "Homo2D"))
270  {
271  NumHomogeneousDir = 2;
272  }
273  }
274  }
275 
276  // reset expansion defintion to use equispaced points if required.
277  if(m_requireEquiSpaced) // set up points to be equispaced
278  {
279  int nPointsNew = 0;
280 
281  if(vm.count("output-points"))
282  {
283  nPointsNew = vm["output-points"].as<int>();
284  }
285 
286 
287  m_f->m_graph->SetExpansionsToEvenlySpacedPoints(nPointsNew);
288  }
289 
290  m_f->m_exp[0] = m_f->SetUpFirstExpList(NumHomogeneousDir,fldfilegiven);
291  }
292  }
293 }