Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : #ifndef LIBMESH_PERIODIC_BOUNDARY_BASE_H 19 : #define LIBMESH_PERIODIC_BOUNDARY_BASE_H 20 : 21 : // Local Includes 22 : #include "libmesh/libmesh_config.h" 23 : 24 : #ifdef LIBMESH_ENABLE_PERIODIC 25 : 26 : // Local Includes 27 : #include "libmesh/point.h" 28 : #include "libmesh/dense_matrix.h" 29 : 30 : // C++ Includes 31 : #include <set> 32 : #include <memory> 33 : 34 : namespace libMesh 35 : { 36 : 37 : // Forward Declarations 38 : class Elem; 39 : class MeshBase; 40 : 41 : /** 42 : * The base class for defining periodic boundaries. 43 : * 44 : * \author Roy Stogner 45 : * \date 2010 46 : * \brief Base class for all PeriodicBoundary implementations. 47 : */ 48 : class PeriodicBoundaryBase 49 : { 50 : public: 51 : enum TransformationType 52 : { FORWARD=0, 53 : INVERSE=1 }; 54 : 55 : /** 56 : * The boundary ID of this boundary and its counterpart 57 : */ 58 : boundary_id_type myboundary, pairedboundary; 59 : 60 : /** 61 : * Constructor 62 : */ 63 : PeriodicBoundaryBase(); 64 : 65 : /** 66 : * Copy constructor 67 : */ 68 : PeriodicBoundaryBase(const PeriodicBoundaryBase & other); 69 : 70 : /** 71 : * Destructor 72 : */ 73 54 : virtual ~PeriodicBoundaryBase() = default; 74 : 75 : /** 76 : * This function should be overridden by derived classes to 77 : * define how one finds corresponding nodes on the periodic 78 : * boundary pair. 79 : */ 80 : virtual Point get_corresponding_pos(const Point & pt) const = 0; 81 : 82 : /** 83 : * If we want the DofMap to be able to make copies of references and 84 : * store them in the underlying map, this class must be clone'able, 85 : * i.e. have a kind of virtual construction mechanism. The user can 86 : * also pass a flag to enable an 'inverse transformation' to be 87 : * cloned from a forward transformation. The simplest way to 88 : * implement a clone function like this is in terms of a copy 89 : * constructor, see periodic_boundary.h. 90 : * 91 : * \note Not every transformation needs to provide an automatic way 92 : * to clone an inverse: you can simply add a pair of 93 : * PeriodicBoundaryBase objects using the appropriate DofMap 94 : * interface instead. 95 : */ 96 : virtual std::unique_ptr<PeriodicBoundaryBase> clone(TransformationType t = FORWARD) const = 0; 97 : 98 : void set_variable(unsigned int var); 99 : 100 : void merge(const PeriodicBoundaryBase & pb); 101 : 102 : bool is_my_variable(unsigned int var_num) const; 103 : 104 : /** 105 : * @return true if _transformation_matrix is not null. 106 : */ 107 : bool has_transformation_matrix() const; 108 : 109 : /** 110 : * Get the transformation matrix, if it is defined. 111 : * Throw an error if it is not defined. 112 : */ 113 : const DenseMatrix<Real> & get_transformation_matrix() const; 114 : 115 : /** 116 : * Set the transformation matrix. When calling this method we 117 : * require the following conditions: 118 : * 1) \p matrix is square with size that matches this->variables.size() 119 : * 2) the list of variables in this->variables set must all have the same FE type 120 : * Both of these conditions are asserted in DBG mode. 121 : */ 122 : void set_transformation_matrix(const DenseMatrix<Real> & matrix); 123 : 124 : /** 125 : * Get the set of variables for this periodic boundary condition. 126 : */ 127 : const std::set<unsigned int> & get_variables() const; 128 : 129 : protected: 130 : 131 : /** 132 : * Set of variables for this periodic boundary, empty means all variables possible 133 : */ 134 : std::set<unsigned int> variables; 135 : 136 : /** 137 : * A DenseMatrix that defines the mapping of variables on this 138 : * boundary and the counterpart boundary. This is necessary for 139 : * periodic-boundaries with vector-valued quantities (e.g. 140 : * velocity or displacement) on a sector of a circular domain, 141 : * for example, since in that case we must map each variable 142 : * to a corresponding linear combination of all the variables. 143 : * We store the DenseMatrix via a unique_ptr, and an uninitialized 144 : * pointer is treated as equivalent to the identity matrix. 145 : */ 146 : std::unique_ptr<DenseMatrix<Real>> _transformation_matrix; 147 : 148 : }; 149 : 150 : } // namespace libmesh 151 : 152 : #endif // LIBMESH_ENABLE_PERIODIC 153 : 154 : #endif // LIBMESH_PERIODIC_BOUNDARY_BASE_H