BoundaryManager.h 5.33 KB
Newer Older
1 2 3 4 5 6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9 10 11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12 13 14 15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17 18 19 20 21 22 23 24 25 26
// ==                                                                        ==
// ============================================================================

/** \file BoundaryManager.h */

#ifndef AMDIS_BOUNDARYMANAGER_H
#define AMDIS_BOUNDARYMANAGER_H

#include <map>

27
#include "AMDiS_fwd.h"
28 29 30 31 32
#include "Boundary.h"
#include "BoundaryCondition.h"

namespace AMDiS {

33 34
  typedef std::map<BoundaryType, BoundaryCondition*> BoundaryIndexMap;

35 36 37 38 39 40 41 42 43 44 45
  /**
   * \ingroup Assembler
   *
   * \brief
   * A BoundaryManager handles a set of boundary conditions and applies
   * this conditions to DOFVectorBase and DOFMatrix objects. Each DOFVectorBase
   * and each DOFMatrix has its own BoundaryManager.
   */
  class BoundaryManager
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
46 47 48 49 50 51
    BoundaryManager(const FiniteElemSpace *feSpace);

    BoundaryManager(BoundaryManager &bm);

    ~BoundaryManager();

52
    /// Adds a local boundary condition to the list of managed conditions.
53 54
    void addBoundaryCondition(BoundaryCondition *localBC) 
    {
55 56
      FUNCNAME("BoundaryManager::addBoundaryCondition()");

57
      BoundaryType type = localBC->getBoundaryType();
58 59
      TEST_EXIT(localBCs[type] == NULL)
	("There is already a condition for this type.\n");
60
      localBCs[type] = localBC;
61 62 63

      std::vector<BoundaryCondition*>& boundMap = globalBoundaryMap[type];
      boundMap.push_back(localBC);
64
    }
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

    void initMatrix(DOFMatrix *matrix);

    void exitMatrix(DOFMatrix *matrix);

    void initVector(DOFVectorBase<double> *vector);

    void exitVector(DOFVectorBase<double> *vector);

    /** \brief
     * Calls DOFVectorBase::fillBoundaryCondition() for each local boundary condition
     * in \ref localBCs.
     */
    void fillBoundaryConditions(ElInfo *elInfo, DOFVectorBase<double> *vec);

    /** \brief
     * Calls DOFMatrix::fillBoundaryCondition() for each local boundary condition
     * in \ref localBCs.
     */
    void fillBoundaryConditions(ElInfo *elInfo, DOFMatrix *mat);

    /** \brief
     * Calls BoundaryCondition::boundResidual() for each boundary condition in 
     * \ref localBCs.
     */
90
    double boundResidual(ElInfo *elInfo, DOFMatrix *matrix, 
91 92
			 const DOFVectorBase<double> *dv);

93 94
    inline BoundaryCondition *getBoundaryCondition(BoundaryType type) 
    {
95
      return localBCs[type];
96
    }
97

98
    const BoundaryIndexMap& getBoundaryConditionMap() 
99
    {
100
      return localBCs;
101
    }
102

103
    void setBoundaryConditionMap(const BoundaryIndexMap& bcs) 
104
    {
105
      localBCs = bcs;
106
    }
107 108 109 110 111 112 113 114 115 116 117 118 119
    
    /** \brief
     * Returns true, if there is at least one boundary object with the given boundary
     * id, which implements a periodic boundary.
     */
    static bool isBoundaryPeriodic(BoundaryType b)
    {
      for (int i = 0; i < static_cast<int>(globalBoundaryMap[b].size()); i++)
	if (globalBoundaryMap[b][i]->isPeriodic())
	  return true;

      return false;
    }
120 121

  protected:
122
    /// Map of managed local boundary conditions.
123
    BoundaryIndexMap localBCs;
Thomas Witkowski's avatar
Thomas Witkowski committed
124

125
    /// Temporary thread-safe variable for functions fillBoundaryconditions.
Thomas Witkowski's avatar
Thomas Witkowski committed
126 127
    std::vector<BoundaryType*> localBounds;

128 129 130
    /// Temporary thread-safe variable for functions fillBoundaryconditions.
    std::vector<Vector<DegreeOfFreedom> > dofIndices;

Thomas Witkowski's avatar
Thomas Witkowski committed
131 132 133 134 135
    /** \brief
     * Stores the number of byte that were allocated in the constructor for
     * each localBounds value. Is used to free the memory in the destructor.
     */
    int allocatedMemoryLocalBounds;
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

    /** \brief
     * For every boundary id we store here all possible boundary object (although
     * it's not clear if it is meaningful to have different boundary conditions on the
     * same boundary id). 
     *
     * We have to use this global variable, because the mesh traverse interface does 
     * not provide more information about traversed boundaries at elements than the
     * boundary id.
     *
     * TODO: Change interface such that mesh traverse returns the boundary objects
     * directly and we can remove this global variable. The biggest problem will be
     * than serialization and deserialization of the mesh.
     */
    static std::map<BoundaryType, std::vector<BoundaryCondition*> > globalBoundaryMap;
151 152 153 154 155
  };

}

#endif