MeshStructure.h 6.33 KB
 Peter Gottschling committed Feb 15, 2008 1 2 // ============================================================================ // == ==  Thomas Witkowski committed Dec 08, 2009 3 // == Amdis - Adaptive multidimensional simulations ==  Peter Gottschling committed Feb 15, 2008 4 // == ==  Thomas Witkowski committed Dec 16, 2010 5 // == http://www.amdis-fem.org ==  Peter Gottschling committed Feb 15, 2008 6 7 // == == // ============================================================================  Thomas Witkowski committed Dec 16, 2010 8 9 10 11 12 13 14 15 16 17 18 19 // // Software License for AMDiS // // Copyright (c) 2010 Dresden University of Technology // All rights reserved. // Authors: Simon Vey, Thomas Witkowski et al. // // This file is part of AMDiS // // See also license.opensource.txt in the distribution.  Peter Gottschling committed Feb 15, 2008 20 21 22  /** \file MeshStructure.h */  Thomas Witkowski committed Jun 08, 2010 23 24 #ifndef AMDIS_MESH_STRUCTURE_H #define AMDIS_MESH_STRUCTURE_H  Peter Gottschling committed Feb 15, 2008 25 26  #include  Thomas Witkowski committed Nov 25, 2010 27 28 #include  Thomas Witkowski committed May 12, 2009 29 #include "AMDiS_fwd.h"  Thomas Witkowski committed Jun 12, 2009 30 #include "Global.h"  Thomas Witkowski committed Apr 18, 2012 31 #include "BoundaryObject.h"  Thomas Witkowski committed Jun 12, 2009 32   Peter Gottschling committed Feb 15, 2008 33 34 35 36 37 38 namespace AMDiS { class MeshStructure { public: MeshStructure()  Thomas Witkowski committed Dec 08, 2009 39 40 41 42  : currentIndex(0), currentCode(0), pos(0), currentElement(0),  Thomas Witkowski committed Jan 19, 2010 43 44  nElements(0), debugMode(false)  Thomas Witkowski committed May 12, 2009 45  {}  Peter Gottschling committed Feb 15, 2008 46 47 48  void clear();  Thomas Witkowski committed Apr 18, 2012 49   Thomas Witkowski committed Nov 25, 2010 50 51 52 53 54 55 56 57 58 59  /** \brief * Creates a mesh structure code from a mesh object by traversing it in * preorder. * * \param[in] mesh Mesh that is used to create the structure code. * \param[in] macroElIndex If the value is set to -1, the structure code is * created for the whole mesh. Otherwise, it is done * only for the macro element with this index. */ void init(Mesh *mesh, int macroElIndex = -1);  Thomas Witkowski committed May 21, 2010 60   Thomas Witkowski committed Jan 19, 2010 61 62  void init(BoundaryObject &bound);  Thomas Witkowski committed Nov 19, 2010 63  void init(const std::vector& initCode, int n)  Thomas Witkowski committed Jun 12, 2009 64  {  Thomas Witkowski committed Dec 08, 2009 65 66  code = initCode; nElements = n;  Peter Gottschling committed Feb 15, 2008 67  reset();  Thomas Witkowski committed May 12, 2009 68  }  Peter Gottschling committed Feb 15, 2008 69   Thomas Witkowski committed Feb 08, 2012 70 71  /// Sets all position counters, that are used to traverse the code, to the /// starting position. The code itself is not changed.  Peter Gottschling committed Feb 15, 2008 72 73  void reset();  Thomas Witkowski committed Jan 19, 2010 74 75 76 77 78 79  /// Returns whether the code is empty or not. inline bool empty() { return (nElements == 0); }  Thomas Witkowski committed Jun 12, 2009 80 81  inline void commit() {  Thomas Witkowski committed Dec 08, 2009 82 83  if (pos > 0) code.push_back(currentCode);  Peter Gottschling committed Feb 15, 2008 84  reset();  Thomas Witkowski committed May 12, 2009 85  }  Peter Gottschling committed Feb 15, 2008 86 87 88 89 90 91 92  bool skipBranch(MeshStructure *insert = NULL); ElInfo *skipBranch(ElInfo *elInfo, TraverseStack *stack); bool nextElement(MeshStructure *insert = NULL);  Thomas Witkowski committed Apr 13, 2011 93 94  int lookAhead(unsigned int n = 1);  Thomas Witkowski committed Jun 12, 2009 95 96  inline bool isLeafElement() {  Thomas Witkowski committed Dec 08, 2009 97  return (currentCode & 1) == 0;  Thomas Witkowski committed May 12, 2009 98  }  Peter Gottschling committed Feb 15, 2008 99   Thomas Witkowski committed Apr 18, 2012 100 101  /// Merges a mesh structure code with its own mesh structure code. The result /// overwrites the own mesh structure code.  Thomas Witkowski committed Dec 08, 2009 102  void merge(MeshStructure *struc)  Thomas Witkowski committed Jun 12, 2009 103  {  Peter Gottschling committed Feb 15, 2008 104  MeshStructure temp(*this);  Thomas Witkowski committed Dec 08, 2009 105  merge(&temp, struc, this);  Thomas Witkowski committed May 12, 2009 106  }  Peter Gottschling committed Feb 15, 2008 107   Thomas Witkowski committed Aug 04, 2008 108 109 110  /** \brief * Fits a given mesh to the mesh structure code. *  Thomas Witkowski committed Apr 18, 2012 111 112 113  * \param debugMode In debugMode, the whole mesh is fitted to the mesh * structure code. Otherwise, the mesh is fitted only on * the partition of the current process.  Thomas Witkowski committed Jul 06, 2010 114 115  * \param macroElIndex If the mesh structure code represents only one macro * element, this can be denoted here by its index. In this  Thomas Witkowski committed Apr 18, 2012 116 117 118  * case, only the corresponding macro element will be * fitted to the code. Otherwise, this variable is * negative and the whole mesh will be adapted.  Thomas Witkowski committed Aug 04, 2008 119  */  Peter Gottschling committed Feb 15, 2008 120 121  void fitMeshToStructure(Mesh *mesh, RefinementManager *manager,  Thomas Witkowski committed Jul 06, 2010 122  bool debugMode = false,  Thomas Witkowski committed Nov 09, 2010 123 124  int macroElIndex = -1, bool ignoreFinerMesh = false);  Peter Gottschling committed Feb 15, 2008 125   Thomas Witkowski committed Jan 13, 2012 126 127 128  /// Converts the mesh structure code to a string (for debugging). string toStr(bool resetCode = true);  Thomas Witkowski committed Jun 12, 2009 129  /// Prints the mesh structure code.  Thomas Witkowski committed Jul 30, 2010 130  void print(bool resetCode = true);  Peter Gottschling committed Feb 15, 2008 131   Thomas Witkowski committed Jun 12, 2009 132  /// Returns the mesh structure code.  Thomas Witkowski committed Nov 19, 2010 133  inline const std::vector& getCode()  Thomas Witkowski committed Jun 12, 2009 134  {  Thomas Witkowski committed Dec 08, 2009 135  return code;  Thomas Witkowski committed May 12, 2009 136  }  Peter Gottschling committed Feb 15, 2008 137   Thomas Witkowski committed Jun 12, 2009 138 139  inline int getNumElements() {  Thomas Witkowski committed Dec 08, 2009 140  return nElements;  Thomas Witkowski committed May 12, 2009 141  }  Peter Gottschling committed Feb 15, 2008 142   Thomas Witkowski committed Jun 12, 2009 143 144  inline int getCurrentElement() {  Thomas Witkowski committed Dec 08, 2009 145  return currentElement;  Thomas Witkowski committed May 12, 2009 146  }  Peter Gottschling committed Feb 15, 2008 147   Thomas Witkowski committed Jan 19, 2010 148 149 150 151 152 153 154 155  void setDebugMode(bool b) { debugMode = b; } /// Returns true, if the given mesh structure code is equal to this one. bool compare(MeshStructure &other);  Thomas Witkowski committed Feb 09, 2012 156 157 158 159 160 161 162 163 164 165 166 167 168  /** \brief * Creates a value array of a given DOFVector. This value array corresponds * to the mesh structure code of the element and thus can easily be used * to reconstruct the values of the DOFVector on the same element (e.g., after * the mesh and the value array has been redistributed in parallel * computations). * * \param[in] macroElIndex Index of the macro element for which the value * structure code must be created. * \param[in] vec DOFVector to be used for creating the value code. * \param[out] values Resulting value structure code. */ void getMeshStructureValues(int macroElIndex,  Thomas Witkowski committed Nov 30, 2010 169 170 171 172  const DOFVector* vec, std::vector& values);  Thomas Witkowski committed Feb 09, 2012 173 174 175 176 177 178 179 180 181  /** \brief * Uses a value structure code, e.g. created by \ref getMeshStructureValues, * to reconstruct the data of a DOFVector on a given macro element. * * \param[in] macroElIndex Macro element index the code is related to. * \param[out] vec DOFVector that should be reconstructed. * \param[in] values Value structure code. */ void setMeshStructureValues(int macroElIndex,  Thomas Witkowski committed Nov 30, 2010 182 183 184  DOFVector* vec, const std::vector& values);  Thomas Witkowski committed Aug 04, 2008 185  protected:  Thomas Witkowski committed Dec 08, 2009 186  /// Insert a new element to the structure code. Is used by the init function.  Thomas Witkowski committed Aug 04, 2008 187 188  void insertElement(bool isLeaf);  Thomas Witkowski committed Apr 18, 2012 189 190 191 192 193  void addAlongSide(Element *el, GeoIndex subObj, int ithObj, int elType, bool reverseOrder);  Thomas Witkowski committed Dec 09, 2009 194   Thomas Witkowski committed Jun 12, 2009 195  /// Merges two mesh structure codes to one structure code.  Thomas Witkowski committed Aug 04, 2008 196 197 198 199  void merge(MeshStructure *structure1, MeshStructure *structure2, MeshStructure *result);  Peter Gottschling committed Feb 15, 2008 200  protected:  Thomas Witkowski committed Jun 08, 2010 201  /// Mesh structure code.  Thomas Witkowski committed Nov 19, 2010 202  std::vector code;  Peter Gottschling committed Feb 15, 2008 203   Thomas Witkowski committed Dec 08, 2009 204  int currentIndex;  Peter Gottschling committed Feb 15, 2008 205   Thomas Witkowski committed Nov 19, 2010 206  uint64_t currentCode;  Peter Gottschling committed Feb 15, 2008 207   Thomas Witkowski committed Dec 08, 2009 208  int pos;  Peter Gottschling committed Feb 15, 2008 209   Thomas Witkowski committed Dec 08, 2009 210  int currentElement;  Peter Gottschling committed Feb 15, 2008 211   Thomas Witkowski committed Dec 08, 2009 212  int nElements;  Peter Gottschling committed Feb 15, 2008 213   Thomas Witkowski committed Apr 18, 2012 214 215  /// If true, some output is printed to screen during mesh structure /// code generation.  Thomas Witkowski committed Jan 19, 2010 216 217  bool debugMode;  Thomas Witkowski committed Nov 19, 2010 218  static const int structureSize;  Thomas Witkowski committed Nov 09, 2010 219 220  friend class ArhWriter;  Peter Gottschling committed Feb 15, 2008 221 222 223 224 225  }; } #endif