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