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 // 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:
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 #include <string>
36 #include <sstream>
37 
38 #include <SpatialDomains/Domain.h>
39 
40 // Use the stl version, primarily for string.
41 #ifndef TIXML_USE_STL
42 #define TIXML_USE_STL
43 #endif
44 
45 #include <tinyxml/tinyxml.h>
46 
47 namespace Nektar
48 {
49  namespace SpatialDomains
50  {
52  m_meshGraph(meshGraph)
53  {
54  }
55 
57  {
58  }
59 
60  void Domain::Read(std::string &infilename)
61  {
62  SetFileName(infilename);
63  TiXmlDocument doc(infilename);
64  bool loadOkay = doc.LoadFile();
65 
66  ASSERTL0(loadOkay, (std::string("Unable to load file: ") + infilename).c_str());
67 
68  Read(doc);
69  }
70 
71  // \brief Read will read the meshgraph vertices given a TiXmlDocument.
72  void Domain::Read(TiXmlDocument &doc)
73  {
74  TiXmlElement* master = 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(entry[0] == 'C', "Only composites are allowed in a definition of a domain.");
98 
99  // Determine the index associated with the C. Allow range syntax.
100 
101  std::string::size_type indxBeg = entry.find_first_of('[') + 1;
102  std::string::size_type indxEnd = entry.find_last_of(']') - 1;
103 
104  ASSERTL0(indxBeg <= indxEnd, (std::string("Error reading DOMAIN definition:") + entry).c_str());
105 
106  std::string indxStr = entry.substr(indxBeg, indxEnd - indxBeg + 1);
107 
108  std::istringstream indexStrm(indxStr);
109  int indx1=-1, indx2=-1;
110  if (indexStrm)
111  {
112  // Should read either [a] where a is a nonnegative integer, or
113  // [a-b] where a and b are nonnegative integers, b>a.
114  // Easiest way to know is if a '-' is present we have the latter
115  // case.
116 
117  indexStrm >> indx1;
118  ASSERTL0(indx1 >= 0, (std::string("Error reading collection range: ") + indxStr).c_str());
119  indx2 = indx1;
120 
121  std::string::size_type dashLoc=indxStr.find('-');
122  if (dashLoc != std::string::npos)
123  {
124  // Skip up to and including the '-' character, then read
125  // the other index. We are safe in doing this because we
126  // already know it is there...somewhere.
127  indexStrm.seekg(dashLoc+1);
128  indexStrm >> indx2;
129 
130  ASSERTL0(indx1 < indx2 && indx2 >= 0,
131  (std::string("Error reading collection range: ") + indxStr).c_str());
132  }
133 
134  for (int i=indx1; i<=indx2; ++i)
135  {
136  Composite composite = m_meshGraph->GetComposite(i);
137  m_domain.push_back(composite);
138  }
139  }
140  }
141  }
142 
143  boundary = master->FirstChildElement("BOUNDARY");
144  ASSERTL0(boundary, "Unable to find BOUNDARY tag in file.");
145 
146  TiXmlElement *bc = boundary->FirstChildElement();
147 
148  // Boundary will have type and composite list.
149  while(bc)
150  {
151  std::string bcType(bc->ValueStr());
152 
153  TiXmlNode *node = bc->FirstChild();
154  std::string components(node->ValueStr());
155  std::istringstream boundaryStrm(components);
156  std::string entry;
157 
158  // Index of the tag letter into the type enum.
159  const char *beginName = BoundaryTypeNameMap;
160  // std::find needs the end to be one past the last element.
161  const char *endName = BoundaryTypeNameMap+eBoundaryTypeLastElement + 1;
162  const char* indx = std::find(beginName, endName, bcType[0]);
163 
164  // Not found if the index (ptr) is past the last element.
165  ASSERTL0(indx != endName, (std::string("Unable to read boundary type tag: ") + bcType).c_str());
166 
167  BoundarySharedPtr boundary(new BoundaryEntry);
168  boundary->m_BoundaryType = BoundaryType(indx - BoundaryTypeNameMap);
169  m_boundaries.push_back(boundary);
170 
171  // May have multiple composites defined.
172  if(boundaryStrm)
173  {
174  domainStrm >> entry;
175 
176  if (entry.length())
177  {
178  ASSERTL0(entry[0] == 'C', "Only composites are allowed in a definition of a boundary condition.");
179 
180  // Determine the index associated with the C. Allow range syntax.
181 
182  std::string::size_type indxBeg = entry.find_first_of('[') + 1;
183  std::string::size_type indxEnd = entry.find_last_of(']') - 1;
184 
185  ASSERTL0(indxBeg <= indxEnd, (std::string("Error reading BOUNDARY definition:") + entry).c_str());
186 
187  // Read between the brackets.
188  std::string indxStr = entry.substr(indxBeg, indxEnd - indxBeg + 1);
189 
190  std::istringstream indexStrm(indxStr);
191  int indx1=-1, indx2=-1;
192  if(indexStrm)
193  {
194  // Should read either [a] where a is a nonnegative integer, or
195  // [a-b] where a and b are nonnegative integers, b>a.
196  // Easiest way to know is if a '-' is present we have the latter
197  // case.
198 
199  indexStrm >> indx1;
200  ASSERTL0(indx1 >= 0, (std::string("Error reading collection range: ") + indxStr).c_str());
201 
202  std::string::size_type dashLoc=indxStr.find('-');
203  if (dashLoc != std::string::npos)
204  {
205  // Skip up to and including the '-' character, then read
206  // the other index. We are safe in doing this because we
207  // already know it is there...somewhere.
208  while(indexStrm.get() != '-');
209  indexStrm >> indx2;
210 
211  ASSERTL0(indx1 < indx2 && indx2 >= 0,
212  (std::string("Error reading collection range: ") + indxStr).c_str());
213  }
214 
215  for (int i=indx1; i<=indx2; ++i)
216  {
217  Composite composite = m_meshGraph->GetComposite(i);
218  boundary->m_BoundaryComposites.push_back(composite);
219  }
220  }
221  }
222  }
223 
224  bc = bc->NextSiblingElement();
225  }
226  }
227 
228  void Domain::Write(std::string &outfilename)
229  {
230  }
231  }
232 };
void SetFileName(const std::string &inString)
Definition: Domain.h:97
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
const char BoundaryTypeNameMap[]
Definition: Domain.h:61
Definition: Domain.h:70
void Write(std::string &outfilename)
Definition: Domain.cpp:228
CompositeVector m_domain
Definition: Domain.h:106
Composite GetComposite(int whichComposite) const
Definition: MeshGraph.h:456
BoundaryVector m_boundaries
Definition: Domain.h:107
boost::shared_ptr< GeometryVector > Composite
Definition: MeshGraph.h:111
void Read(std::string &infilename)
Definition: Domain.cpp:60
Base class for a spectral/hp element mesh.
Definition: MeshGraph.h:183
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:312
boost::shared_ptr< BoundaryEntry > BoundarySharedPtr
Definition: Domain.h:76