Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GlobalOptimizationParameters.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File GlobalOptimizationParameters.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: Source file of global optimisation parameters class
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef TIXML_USE_STL
37 #define TIXML_USE_STL
38 #endif
39 #include <tinyxml.h>
41 
42 namespace Nektar
43 {
44  namespace NekOptimize
45  {
46  /**
47  * @class GlobalOptParam
48  *
49  * Global optimisation parameters determines how the various matrices
50  * in the spectral/hp element formulation are evaluated. For details
51  * see the page on \ref optimisation Optimisation.
52  */
53 
54  /**
55  * No global optimisation parameters present.
56  */
58  m_doGlobalMatOp(SIZE_OptimizeOperationType,false),
59  m_shapeList(1,LibUtilities::eNoShapeType),
60  m_shapeNumElements(1,nel)
61  {
62  Array<OneD, bool> set_false(1,false);
63  m_doBlockMatOp = Array<OneD, Array<OneD, bool > >
64  (SIZE_OptimizeOperationType,set_false);
65  }
66 
67  /**
68  * Read global optimisation parameters from a file and set up flags.
69  * @param fileName File to read parameters from.
70  */
72  const Array<OneD, const int> &NumShapeElements):
73  m_doGlobalMatOp(SIZE_OptimizeOperationType,false)
74  {
75  int i;
76  int numShapes = 0;
77  TiXmlDocument& doc = pSession->GetDocument();
78 
79  m_shapeNumElements = NumShapeElements;
80 
81  switch (dim)
82  {
83  case 1:
84  numShapes = 1;
85  ASSERTL0(false,"Needs setting up for dimension 1");
86  break;
87  case 2:
88  numShapes = 2;
89  m_shapeList = Array<OneD, LibUtilities::ShapeType>(numShapes);
91  m_shapeList[1] = LibUtilities::eQuadrilateral;
92  break;
93  case 3:
94  numShapes = 4;
95  m_shapeList = Array<OneD, LibUtilities::ShapeType>(numShapes);
96  m_shapeList[0] = LibUtilities::eTetrahedron;
97  m_shapeList[1] = LibUtilities::ePyramid;
98  m_shapeList[2] = LibUtilities::ePrism;
99  m_shapeList[3] = LibUtilities::eHexahedron;
100  break;
101  }
102 
103  m_doBlockMatOp = Array<OneD, Array<OneD,bool> > (SIZE_OptimizeOperationType);
104  for(i = 0; i < SIZE_OptimizeOperationType; ++i)
105  {
106  m_doBlockMatOp[i] = Array<OneD, bool> (numShapes,false);
107  }
108 
109  TiXmlHandle docHandle(&doc);
110  TiXmlElement* master
111  = docHandle.FirstChildElement("NEKTAR").Element();
112  ASSERTL0(master , "Unable to find NEKTAR tag in file.");
113 
114  TiXmlElement* paramList
115  = docHandle.FirstChildElement("NEKTAR")
116  .FirstChildElement("GLOBALOPTIMIZATIONPARAMETERS")
117  .Element();
118 
119  // If no global optimisation parameters set, we're done
120  if (!paramList)
121  {
122  return;
123  }
124 
125  // Check if there is a reference an external file and if so, load it
126  TiXmlElement* source
127  = paramList->FirstChildElement("SOURCE");
128  if (source)
129  {
130  std::string sourceFile = source->Attribute("FILE");
131  TiXmlDocument docSource;
132  bool loadOkay = docSource.LoadFile(sourceFile);
133  ASSERTL0(loadOkay, (std::string("Unable to load file: ") +
134  sourceFile).c_str());
135  TiXmlHandle docSourceHandle(&docSource);
136  master = docHandle.FirstChildElement("NEKTAR").Element();
137  ASSERTL0(master , "Unable to find NEKTAR tag in file.");
138 
139  paramList = docHandle.FirstChildElement("NEKTAR")
140  .FirstChildElement("GLOBALOPTIMIZATIONPARAMETERS")
141  .Element();
142  ASSERTL0(paramList, std::string("Specified source file '"
143  + sourceFile + "' is missing an "
144  "GLOBALOPTIMIZATIONPARAMETERS tag.").c_str());
145  }
146 
147  int n;
148  for(n = 0; n < SIZE_OptimizeOperationType; n++)
149  {
150  TiXmlElement* operationType = paramList->FirstChildElement(
152 
153  if(operationType)
154  {
155  TiXmlElement* arrayElement = operationType
156  ->FirstChildElement("DO_GLOBAL_MAT_OP");
157  if(arrayElement)
158  {
159  int value;
160  int err;
161 
162  err = arrayElement->QueryIntAttribute("VALUE", &value);
163  ASSERTL0(err == TIXML_SUCCESS,(
164  std::string("Unable to read DO_GLOBAL_MAT_OP "
165  "attribute VALUE for ")
166  + std::string(OptimizationOperationTypeMap[n])
167  + std::string(".")
168  ));
169 
170  m_doGlobalMatOp[n] = (bool) value;
171  }
172 
173  arrayElement
174  = operationType->FirstChildElement("DO_BLOCK_MAT_OP");
175  if(arrayElement)
176  {
177  int value;
178  int err;
179 
180  switch (dim)
181  {
182  case 1:
183  break;
184  case 2:
185  err = arrayElement->QueryIntAttribute("TRI", &value);
186  ASSERTL0(err == TIXML_SUCCESS, (
187  std::string("Unable to read DO_BLOCK_MAT_OP "
188  "attribute TRI for ")
189  + std::string(OptimizationOperationTypeMap[n])
190  + std::string(".")));
191 
192  m_doBlockMatOp[n][0] = (bool) value;
193 
194  err = arrayElement->QueryIntAttribute("QUAD", &value);
195  ASSERTL0(err == TIXML_SUCCESS, (
196  std::string("Unable to read DO_BLOCK_MAT_OP "
197  "attribute QUAD for ")
198  + std::string(OptimizationOperationTypeMap[n])
199  + std::string(".")));
200 
201  m_doBlockMatOp[n][1] = (bool) value;
202  break;
203  case 3:
204  err = arrayElement->QueryIntAttribute("TET", &value);
205  ASSERTL0(err == TIXML_SUCCESS, (
206  std::string("Unable to read DO_BLOCK_MAT_OP "
207  "attribute TET for ")
208  + std::string(OptimizationOperationTypeMap[n])
209  + std::string(".")));
210 
211  m_doBlockMatOp[n][0] = (bool) value;
212 
213  err = arrayElement->QueryIntAttribute("PYR", &value);
214  ASSERTL0(err == TIXML_SUCCESS, (
215  std::string("Unable to read DO_BLOCK_MAT_OP "
216  "attribute PYR for ")
217  + std::string(OptimizationOperationTypeMap[n])
218  + std::string(".")));
219 
220  m_doBlockMatOp[n][1] = (bool) value;
221 
222  err = arrayElement->QueryIntAttribute("PRISM", &value);
223  ASSERTL0(err == TIXML_SUCCESS, (
224  std::string("Unable to read DO_BLOCK_MAT_OP "
225  "attribute PRISM for ")
226  + std::string(OptimizationOperationTypeMap[n])
227  + std::string(".")));
228 
229  m_doBlockMatOp[n][2] = (bool) value;
230 
231  err = arrayElement->QueryIntAttribute("HEX", &value);
232  ASSERTL0(err == TIXML_SUCCESS, (
233  std::string("Unable to read DO_BLOCK_MAT_OP "
234  "attribute HEX for ")
235  + std::string(OptimizationOperationTypeMap[n])
236  + std::string(".")));
237 
238  m_doBlockMatOp[n][3] = (bool) value;
239  break;
240 
241  break;
242 
243  }
244  }
245  }
246  }
247  }
248 
249 
250  } // end of namespace
251 } // end of namespace