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 <sstream>
35 #include <string>
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 {
50 Domain::Domain(MeshGraph *meshGraph) : m_meshGraph(meshGraph)
51 {
52 }
53 
55 {
56 }
57 
58 void Domain::Read(std::string &infilename)
59 {
60  SetFileName(infilename);
61  TiXmlDocument doc(infilename);
62  bool loadOkay = doc.LoadFile();
63 
64  ASSERTL0(loadOkay,
65  (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 =
74  NULL; // Master tag within which all data is contained.
75  TiXmlElement *domain = NULL;
76  TiXmlElement *boundary = NULL;
77 
78  master = doc.FirstChildElement("NEKTAR");
79  ASSERTL0(master, "Unable to find NEKTAR tag in file");
80 
81  domain = master->FirstChildElement("DOMAIN");
82 
83  ASSERTL0(domain, "Unable to find DOMAIN tag in file.");
84 
85  TiXmlNode *node = domain->FirstChild();
86  std::string components(node->ValueStr());
87  std::istringstream domainStrm(components);
88  std::string entry;
89 
90  // May have multiple composites defined.
91  if (domainStrm)
92  {
93  domainStrm >> entry;
94 
95  if (entry.length())
96  {
97  ASSERTL0(
98  entry[0] == 'C',
99  "Only composites are allowed in a definition of a domain.");
100 
101  // Determine the index associated with the C. Allow range syntax.
102 
103  std::string::size_type indxBeg = entry.find_first_of('[') + 1;
104  std::string::size_type indxEnd = entry.find_last_of(']') - 1;
105 
106  ASSERTL0(indxBeg <= indxEnd,
107  (std::string("Error reading DOMAIN definition:") + entry)
108  .c_str());
109 
110  std::string indxStr = entry.substr(indxBeg, indxEnd - indxBeg + 1);
111 
112  std::istringstream indexStrm(indxStr);
113  int indx1 = -1, indx2 = -1;
114  if (indexStrm)
115  {
116  // Should read either [a] where a is a nonnegative integer, or
117  // [a-b] where a and b are nonnegative integers, b>a.
118  // Easiest way to know is if a '-' is present we have the latter
119  // case.
120 
121  indexStrm >> indx1;
122  ASSERTL0(
123  indx1 >= 0,
124  (std::string("Error reading collection range: ") + indxStr)
125  .c_str());
126  indx2 = indx1;
127 
128  std::string::size_type dashLoc = indxStr.find('-');
129  if (dashLoc != std::string::npos)
130  {
131  // Skip up to and including the '-' character, then read
132  // the other index. We are safe in doing this because we
133  // already know it is there...somewhere.
134  indexStrm.seekg(dashLoc + 1);
135  indexStrm >> indx2;
136 
137  ASSERTL0(indx1 < indx2 && indx2 >= 0,
138  (std::string("Error reading collection range: ") +
139  indxStr)
140  .c_str());
141  }
142 
143  for (int i = indx1; i <= indx2; ++i)
144  {
145  Composite composite = m_meshGraph->GetComposite(i);
146  m_domain.push_back(composite);
147  }
148  }
149  }
150  }
151 
152  boundary = master->FirstChildElement("BOUNDARY");
153  ASSERTL0(boundary, "Unable to find BOUNDARY tag in file.");
154 
155  TiXmlElement *bc = boundary->FirstChildElement();
156 
157  // Boundary will have type and composite list.
158  while (bc)
159  {
160  std::string bcType(bc->ValueStr());
161 
162  TiXmlNode *node = bc->FirstChild();
163  std::string components(node->ValueStr());
164  std::istringstream boundaryStrm(components);
165  std::string entry;
166 
167  // Index of the tag letter into the type enum.
168  const char *beginName = BoundaryTypeNameMap;
169  // std::find needs the end to be one past the last element.
170  const char *endName =
172  const char *indx = std::find(beginName, endName, bcType[0]);
173 
174  // Not found if the index (ptr) is past the last element.
175  ASSERTL0(indx != endName,
176  (std::string("Unable to read boundary type tag: ") + bcType)
177  .c_str());
178 
179  BoundarySharedPtr boundary(new BoundaryEntry);
180  boundary->m_BoundaryType = BoundaryType(indx - BoundaryTypeNameMap);
181  m_boundaries.push_back(boundary);
182 
183  // May have multiple composites defined.
184  if (boundaryStrm)
185  {
186  domainStrm >> entry;
187 
188  if (entry.length())
189  {
190  ASSERTL0(entry[0] == 'C',
191  "Only composites are allowed in a definition of a "
192  "boundary condition.");
193 
194  // Determine the index associated with the C. Allow range
195  // syntax.
196 
197  std::string::size_type indxBeg = entry.find_first_of('[') + 1;
198  std::string::size_type indxEnd = entry.find_last_of(']') - 1;
199 
200  ASSERTL0(
201  indxBeg <= indxEnd,
202  (std::string("Error reading BOUNDARY definition:") + entry)
203  .c_str());
204 
205  // Read between the brackets.
206  std::string indxStr =
207  entry.substr(indxBeg, indxEnd - indxBeg + 1);
208 
209  std::istringstream indexStrm(indxStr);
210  int indx1 = -1, indx2 = -1;
211  if (indexStrm)
212  {
213  // Should read either [a] where a is a nonnegative integer,
214  // or [a-b] where a and b are nonnegative integers, b>a.
215  // Easiest way to know is if a '-' is present we have the
216  // latter case.
217 
218  indexStrm >> indx1;
219  ASSERTL0(indx1 >= 0,
220  (std::string("Error reading collection range: ") +
221  indxStr)
222  .c_str());
223 
224  std::string::size_type dashLoc = indxStr.find('-');
225  if (dashLoc != std::string::npos)
226  {
227  // Skip up to and including the '-' character, then read
228  // the other index. We are safe in doing this because
229  // we already know it is there...somewhere.
230  while (indexStrm.get() != '-')
231  ;
232  indexStrm >> indx2;
233 
234  ASSERTL0(
235  indx1 < indx2 && indx2 >= 0,
236  (std::string("Error reading collection range: ") +
237  indxStr)
238  .c_str());
239  }
240 
241  for (int i = indx1; i <= indx2; ++i)
242  {
243  Composite composite = m_meshGraph->GetComposite(i);
244  boundary->m_BoundaryComposites.push_back(composite);
245  }
246  }
247  }
248  }
249 
250  bc = bc->NextSiblingElement();
251  }
252 }
253 
254 void Domain::Write(std::string &outfilename)
255 {
256 }
257 } // namespace SpatialDomains
258 }; // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
void SetFileName(const std::string &inString)
Definition: Domain.h:95
void Write(std::string &outfilename)
Definition: Domain.cpp:254
void Read(std::string &infilename)
Definition: Domain.cpp:58
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:180
CompositeSharedPtr GetComposite(int whichComposite)
Definition: MeshGraph.h:240
std::shared_ptr< BoundaryEntry > BoundarySharedPtr
Definition: Domain.h:70
const char BoundaryTypeNameMap[]
Definition: Domain.h:60
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:444
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
Definition: Domain.h:65