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  // define range to process output
129  if(vm.count("range"))
130  {
131  vector<NekDouble> values;
133  vm["range"].as<string>().c_str(), values),
134  "Failed to interpret range string");
135 
136  ASSERTL0(values.size() > 1,
137  "Do not have minimum values of xmin,xmax");
138  ASSERTL0(values.size() % 2 == 0,
139  "Do not have an even number of range values");
140 
141  int nvalues = values.size()/2;
143 
144  rng->doZrange = false;
145  rng->doYrange = false;
146 
147  switch(nvalues)
148  {
149  case 3:
150  rng->doZrange = true;
151  rng->zmin = values[4];
152  rng->zmax = values[5];
153  case 2:
154  rng->doYrange = true;
155  rng->ymin = values[2];
156  rng->ymax = values[3];
157  case 1:
158  rng->doXrange = true;
159  rng->xmin = values[0];
160  rng->xmax = values[1];
161  break;
162  default:
163  ASSERTL0(false,"too many values specfied in range");
164  }
165  }
166 
167  if(m_f->m_verbose)
168  {
169  string firstarg = "FieldConvert";
170  string verbose = "-v";
171  char **argv;
172  argv = (char**)malloc(2*sizeof(char*));
173  argv[0] = (char *)malloc(firstarg.size()*sizeof(char));
174  argv[1] = (char *)malloc(verbose.size()*sizeof(char));
175 
176  sprintf(argv[0],"%s",firstarg.c_str());
177  sprintf(argv[1],"%s",verbose.c_str());
178 
180  CreateInstance(2, (char **)argv, files, m_f->m_comm);
181  }
182  else
183  {
185  CreateInstance(0, 0, files, m_f->m_comm);
186  }
187 
188 
189 
190 
191  m_f->m_graph = SpatialDomains::MeshGraph::Read(m_f->m_session,rng);
193  ::AllocateSharedPtr(m_f->m_session->GetComm());
194 
195  // currently load all field (possibly could read data from
196  // expansion list but it is re-arranged in expansion)
197  const SpatialDomains::ExpansionMap &expansions = m_f->m_graph->GetExpansions();
198 
199  // if Range has been speficied it is possible to have a
200  // partition which is empty so ccheck this and return if
201  // no elements present.
202  if(!expansions.size())
203  {
204  return;
205  }
206 
207  m_f->m_exp.resize(1);
208 
209  // load fielddef if fld file is defined This gives
210  // precedence to Homogeneous definition in fld file
211  int NumHomogeneousDir = 0;
212  if(fldfilegiven)
213  {
214  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],m_f->m_fielddef);
215  NumHomogeneousDir = m_f->m_fielddef[0]->m_numHomogeneousDir;
216 
217  //----------------------------------------------
218  // Set up Expansion information to use mode order from field
219  m_f->m_graph->SetExpansions(m_f->m_fielddef);
220  }
221  else
222  {
223  if(m_f->m_session->DefinesSolverInfo("HOMOGENEOUS"))
224  {
225  std::string HomoStr = m_f->m_session->GetSolverInfo("HOMOGENEOUS");
226 
227  if((HomoStr == "HOMOGENEOUS1D") || (HomoStr == "Homogeneous1D")
228  || (HomoStr == "1D") || (HomoStr == "Homo1D"))
229  {
230  NumHomogeneousDir = 1;
231  }
232  if((HomoStr == "HOMOGENEOUS2D") || (HomoStr == "Homogeneous2D")
233  || (HomoStr == "2D") || (HomoStr == "Homo2D"))
234  {
235  NumHomogeneousDir = 2;
236  }
237  }
238  }
239 
240  // reset expansion defintion to use equispaced points if required.
241  if(m_requireEquiSpaced) // set up points to be equispaced
242  {
243  int nPointsNew = 0;
244 
245  if(vm.count("output-points"))
246  {
247  nPointsNew = vm["output-points"].as<int>();
248  }
249 
250 
251  m_f->m_graph->SetExpansionsToEvenlySpacedPoints(nPointsNew);
252  }
253 
254  m_f->m_exp[0] = m_f->SetUpFirstExpList(NumHomogeneousDir,fldfilegiven);
255  }
256  }
257 }