Nektar++
Domain.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Domain.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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description:
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 #include <string>
35 #include <sstream>
36 
37 #include <SpatialDomains/Domain.h>
38 
39 // Use the stl version, primarily for string.
40 #ifndef TIXML_USE_STL
41 #define TIXML_USE_STL
42 #endif
43 
44 #include <tinyxml/tinyxml.h>
45 
46 namespace Nektar
47 {
48  namespace SpatialDomains
49  {
51  m_meshGraph(meshGraph)
52  {
53  }
54 
56  {
57  }
58 
59  void Domain::Read(std::string &infilename)
60  {
61  SetFileName(infilename);
62  TiXmlDocument doc(infilename);
63  bool loadOkay = doc.LoadFile();
64 
65  ASSERTL0(loadOkay, (std::string("Unable to load file: ") + infilename).c_str());
66 
67  Read(doc);
68  }
69 
70  // \brief Read will read the meshgraph vertices given a TiXmlDocument.
71  void Domain::Read(TiXmlDocument &doc)
72  {
73  TiXmlElement* master = NULL; // Master tag within which all data is contained.
74  TiXmlElement* domain = NULL;
75  TiXmlElement* boundary = NULL;
76 
77  master = doc.FirstChildElement("NEKTAR");
78  ASSERTL0(master, "Unable to find NEKTAR tag in file");
79 
80  domain = master->FirstChildElement("DOMAIN");
81 
82  ASSERTL0(domain, "Unable to find DOMAIN tag in file.");
83 
84  TiXmlNode *node = domain->FirstChild();
85  std::string components(node->ValueStr());
86  std::istringstream domainStrm(components);
87  std::string entry;
88 
89  // May have multiple composites defined.
90  if(domainStrm)
91  {
92  domainStrm >> entry;
93 
94  if (entry.length())
95  {
96  ASSERTL0(entry[0] == 'C', "Only composites are allowed in a definition of a domain.");
97 
98  // Determine the index associated with the C. Allow range syntax.
99 
100  std::string::size_type indxBeg = entry.find_first_of('[') + 1;
101  std::string::size_type indxEnd = entry.find_last_of(']') - 1;
102 
103  ASSERTL0(indxBeg <= indxEnd, (std::string("Error reading DOMAIN definition:") + entry).c_str());
104 
105  std::string indxStr = entry.substr(indxBeg, indxEnd - indxBeg + 1);
106 
107  std::istringstream indexStrm(indxStr);
108  int indx1=-1, indx2=-1;
109  if (indexStrm)
110  {
111  // Should read either [a] where a is a nonnegative integer, or
112  // [a-b] where a and b are nonnegative integers, b>a.
113  // Easiest way to know is if a '-' is present we have the latter
114  // case.
115 
116  indexStrm >> indx1;
117  ASSERTL0(indx1 >= 0, (std::string("Error reading collection range: ") + indxStr).c_str());
118  indx2 = indx1;
119 
120  std::string::size_type dashLoc=indxStr.find('-');
121  if (dashLoc != std::string::npos)
122  {
123  // Skip up to and including the '-' character, then read
124  // the other index. We are safe in doing this because we
125  // already know it is there...somewhere.
126  indexStrm.seekg(dashLoc+1);
127  indexStrm >> indx2;
128 
129  ASSERTL0(indx1 < indx2 && indx2 >= 0,
130  (std::string("Error reading collection range: ") + indxStr).c_str());
131  }
132 
133  for (int i=indx1; i<=indx2; ++i)
134  {
135  Composite composite = m_meshGraph->GetComposite(i);
136  m_domain.push_back(composite);
137  }
138  }
139  }
140  }
141 
142  boundary = master->FirstChildElement("BOUNDARY");
143  ASSERTL0(boundary, "Unable to find BOUNDARY tag in file.");
144 
145  TiXmlElement *bc = boundary->FirstChildElement();
146 
147  // Boundary will have type and composite list.
148  while(bc)
149  {
150  std::string bcType(bc->ValueStr());
151 
152  TiXmlNode *node = bc->FirstChild();
153  std::string components(node->ValueStr());
154  std::istringstream boundaryStrm(components);
155  std::string entry;
156 
157  // Index of the tag letter into the type enum.
158  const char *beginName = BoundaryTypeNameMap;
159  // std::find needs the end to be one past the last element.
160  const char *endName = BoundaryTypeNameMap+eBoundaryTypeLastElement + 1;
161  const char* indx = std::find(beginName, endName, bcType[0]);
162 
163  // Not found if the index (ptr) is past the last element.
164  ASSERTL0(indx != endName, (std::string("Unable to read boundary type tag: ") + bcType).c_str());
165 
166  BoundarySharedPtr boundary(new BoundaryEntry);
167  boundary->m_BoundaryType = BoundaryType(indx - BoundaryTypeNameMap);
168  m_boundaries.push_back(boundary);
169 
170  // May have multiple composites defined.
171  if(boundaryStrm)
172  {
173  domainStrm >> entry;
174 
175  if (entry.length())
176  {
177  ASSERTL0(entry[0] == 'C', "Only composites are allowed in a definition of a boundary condition.");
178 
179  // Determine the index associated with the C. Allow range syntax.
180 
181  std::string::size_type indxBeg = entry.find_first_of('[') + 1;
182  std::string::size_type indxEnd = entry.find_last_of(']') - 1;
183 
184  ASSERTL0(indxBeg <= indxEnd, (std::string("Error reading BOUNDARY definition:") + entry).c_str());
185 
186  // Read between the brackets.
187  std::string indxStr = entry.substr(indxBeg, indxEnd - indxBeg + 1);
188 
189  std::istringstream indexStrm(indxStr);
190  int indx1=-1, indx2=-1;
191  if(indexStrm)
192  {
193  // Should read either [a] where a is a nonnegative integer, or
194  // [a-b] where a and b are nonnegative integers, b>a.
195  // Easiest way to know is if a '-' is present we have the latter
196  // case.
197 
198  indexStrm >> indx1;
199  ASSERTL0(indx1 >= 0, (std::string("Error reading collection range: ") + indxStr).c_str());
200 
201  std::string::size_type dashLoc=indxStr.find('-');
202  if (dashLoc != std::string::npos)
203  {
204  // Skip up to and including the '-' character, then read
205  // the other index. We are safe in doing this because we
206  // already know it is there...somewhere.
207  while(indexStrm.get() != '-');
208  indexStrm >> indx2;
209 
210  ASSERTL0(indx1 < indx2 && indx2 >= 0,
211  (std::string("Error reading collection range: ") + indxStr).c_str());
212  }
213 
214  for (int i=indx1; i<=indx2; ++i)
215  {
216  Composite composite = m_meshGraph->GetComposite(i);
217  boundary->m_BoundaryComposites.push_back(composite);
218  }
219  }
220  }
221  }
222 
223  bc = bc->NextSiblingElement();
224  }
225  }
226 
227  void Domain::Write(std::string &outfilename)
228  {
229  }
230  }
231 };
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
void SetFileName(const std::string &inString)
Definition: Domain.h:94
void Write(std::string &outfilename)
Definition: Domain.cpp:227
void Read(std::string &infilename)
Definition: Domain.cpp:59
BoundaryVector m_boundaries
Definition: Domain.h:104
CompositeVector m_domain
Definition: Domain.h:103
Base class for a spectral/hp element mesh.
Definition: MeshGraph.h:179
CompositeSharedPtr GetComposite(int whichComposite)
Definition: MeshGraph.h:240
std::shared_ptr< BoundaryEntry > BoundarySharedPtr
Definition: Domain.h:75
const char BoundaryTypeNameMap[]
Definition: Domain.h:60
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:362
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
Definition: Domain.h:70