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 : 19 : 20 : #ifndef LIBMESH_SYSTEM_SUBSET_BY_SUBDOMAIN_H 21 : #define LIBMESH_SYSTEM_SUBSET_BY_SUBDOMAIN_H 22 : 23 : // Local Includes 24 : #include "libmesh/system_subset.h" 25 : #include "libmesh/id_types.h" 26 : #include "libmesh/parallel_object.h" 27 : 28 : // C++ includes 29 : #include <cstddef> 30 : #include <set> 31 : 32 : namespace libMesh 33 : { 34 : 35 : // Forward Declarations 36 : 37 : /** 38 : * This class represents a subset of the dofs of a \p System, selected 39 : * by the \p subdomain_id and possible the variable numbers. The dofs 40 : * in the subset will be sorted. 41 : * 42 : * \author Tim Kroeger 43 : * \date 2010 44 : */ 45 18 : class SystemSubsetBySubdomain : public SystemSubset, 46 : public ParallelObject 47 : { 48 : public: 49 : 50 : /** 51 : * Subclass for user-specified selection of subdomain ids to be 52 : * included in a \p SystemSubset. 53 : */ 54 24 : class SubdomainSelection : public ReferenceCountedObject<SubdomainSelection> 55 : { 56 : public: 57 : 58 : /** 59 : * Constructor. 60 : */ 61 : SubdomainSelection (); 62 : 63 : /** 64 : * Destructor. 65 : */ 66 : virtual ~SubdomainSelection (); 67 : 68 : /** 69 : * Method that decides whether a given subdomain id is included in 70 : * the subset or nor. 71 : */ 72 : virtual bool operator() (const subdomain_id_type & subdomain_id) const = 0; 73 : 74 : private: 75 : /** 76 : * This isn't a copyable object, so let's make sure nobody tries. 77 : * 78 : * We won't even bother implementing this; we'll just make sure 79 : * that the compiler doesn't implement a default. 80 : */ 81 : SubdomainSelection (const SubdomainSelection &); 82 : 83 : /** 84 : * This isn't a copyable object, so let's make sure nobody tries. 85 : * 86 : * We won't even bother implementing this; we'll just make sure 87 : * that the compiler doesn't implement a default. 88 : */ 89 : SubdomainSelection & operator = (const SubdomainSelection &); 90 : }; // subclass \p SubdomainSelection 91 : 92 : 93 : 94 : /** 95 : * Selection of subdomain ids by a list. 96 : */ 97 0 : class SubdomainSelectionByList : public SubdomainSelection 98 : { 99 : public: 100 : /** 101 : * Constructor. Does not take a copy of the \p list, so make sure 102 : * that the \p list does not go out of scope before \p *this does. 103 : */ 104 : explicit 105 : SubdomainSelectionByList (const std::set<subdomain_id_type> & list); 106 : 107 : /** 108 : * Method that decides whether a given subdomain id is included in 109 : * the subset or nor. 110 : */ 111 : virtual bool operator() (const subdomain_id_type & subdomain_id) const override; 112 : 113 : protected: 114 : /** 115 : * The actual list. 116 : */ 117 : const std::set<subdomain_id_type> & _list; 118 : }; 119 : 120 : /** 121 : * Constructor. The subset will consist of those dofs which are 122 : * associated to at least one mesh element that has a subdomain id 123 : * contained in the \p subdomain_selection. If \p var_nums is not a 124 : * \p nullptr, dofs that are associated to a variable number 125 : * that is not contained in \p var_nums will not contain to the 126 : * subset, no matter what elements they belong to. 127 : */ 128 : SystemSubsetBySubdomain (const System & system, 129 : const SubdomainSelection & subdomain_selection, 130 : const std::set<unsigned int> * const var_nums = nullptr); 131 : 132 : /** 133 : * Constructor. The subset will consist of those dofs which are 134 : * associated to at least one mesh element that has a subdomain id 135 : * contained in the set \p subdomain_ids. If \p var_nums is not a 136 : * \p nullptr, dofs that are associated to a variable number 137 : * that is not contained in \p var_nums will not contain to the 138 : * subset, no matter what elements they belong to. 139 : */ 140 : SystemSubsetBySubdomain (const System & system, 141 : const std::set<subdomain_id_type> & subdomain_ids, 142 : const std::set<unsigned int> * const var_nums = nullptr); 143 : 144 : /** 145 : * Destructor. 146 : */ 147 : virtual ~SystemSubsetBySubdomain (); 148 : 149 : /** 150 : * \returns The actual set of dofs that the subset consists of. 151 : * 152 : * The result will contain local dofs on each processor only and 153 : * will not contain duplicates. 154 : */ 155 : virtual const std::vector<unsigned int> & dof_ids () const override; 156 : 157 : /** 158 : * Initializes the class. Will be called by the constructors. Can 159 : * also be called manually to update the subset. This is required 160 : * if (a) the subdomain ids of some elements have changed in the 161 : * meantime and you want these changes to take effect, or (b) you 162 : * want to use a different \p SubdomainSelection object now. 163 : */ 164 : void init (const SubdomainSelection & subdomain_selection); 165 : 166 : /** 167 : * Initializes the class. Will be called by the constructors. Can 168 : * also be called manually to update the subset. This is required 169 : * if (a) the subdomain ids of some elements have changed in the 170 : * meantime and you want these changes to take effect, or (b) you 171 : * want to use a different list of subdomain ids now. 172 : */ 173 : void init (const std::set<subdomain_id_type> & subdomain_ids); 174 : 175 : protected: 176 : 177 : /** 178 : * Sets \p _var_nums to either a copy of \p var_nums or, if that is 179 : * \p nullptr, a set of all variable numbers that occur in the system. 180 : */ 181 : void set_var_nums (const std::set<unsigned int> * const var_nums); 182 : 183 : /** 184 : * The set of all variable numbers that are contained in the subset. 185 : * This will be set by the constructor to either a copy of its \p 186 : * var_nums argument or, if that is \p nullptr, a set of all variable 187 : * numbers that occur in the system. 188 : */ 189 : std::set<unsigned int> _var_nums; 190 : 191 : /** 192 : * The actual set of the dof ids. 193 : */ 194 : std::vector<unsigned int> _dof_ids; 195 : 196 : }; // class SystemSubset 197 : 198 : } // namespace libMesh 199 : 200 : #endif // LIBMESH_SYSTEM_SUBSET_BY_SUBDOMAIN_H