Line data Source code
1 : // The libMesh Finite Element Library.
2 : // Copyright (C) 2002-2026 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 : #include "libmesh/dirichlet_boundaries.h"
21 :
22 : #ifdef LIBMESH_ENABLE_DIRICHLET
23 :
24 : // Local Includes
25 : #include "libmesh/composite_fem_function.h"
26 : #include "libmesh/composite_function.h"
27 : #include "libmesh/vector_value.h"
28 :
29 : // C++ Includes
30 : #include <memory>
31 :
32 : namespace libMesh
33 : {
34 :
35 480 : DirichletBoundary::
36 : DirichletBoundary(std::set<boundary_id_type> b_in,
37 : std::vector<unsigned int> variables_in,
38 : const FunctionBase<Number> * f_in,
39 480 : const FunctionBase<Gradient> * g_in) :
40 154 : b(std::move(b_in)),
41 154 : variables(std::move(variables_in)),
42 480 : f(f_in ? f_in->clone() : nullptr),
43 172 : g(g_in ? g_in->clone() : nullptr),
44 172 : f_system(nullptr),
45 788 : jacobian_tolerance(0.)
46 : {
47 154 : libmesh_assert(f);
48 480 : f->init();
49 480 : if (g)
50 0 : g->init();
51 480 : }
52 :
53 :
54 604 : DirichletBoundary::
55 : DirichletBoundary(std::set<boundary_id_type> b_in,
56 : std::vector<unsigned int> variables_in,
57 : const FunctionBase<Number> & f_in,
58 604 : VariableIndexing type) :
59 178 : b(std::move(b_in)),
60 426 : variables(std::move(variables_in)),
61 248 : f_system(nullptr),
62 604 : jacobian_tolerance(0.)
63 : {
64 604 : if (type == LOCAL_VARIABLE_ORDER)
65 : {
66 503 : auto c = std::make_unique<CompositeFunction<Number>>();
67 503 : c->attach_subfunction(f_in, variables);
68 271 : f = std::move(c);
69 155 : }
70 : else
71 372 : f = f_in.clone();
72 :
73 604 : f->init();
74 604 : }
75 :
76 :
77 161 : DirichletBoundary::
78 : DirichletBoundary(std::set<boundary_id_type> b_in,
79 : std::vector<unsigned int> variables_in,
80 : const FunctionBase<Number> & f_in,
81 : const FunctionBase<Gradient> & g_in,
82 161 : VariableIndexing type) :
83 46 : b(std::move(b_in)),
84 115 : variables(std::move(variables_in)),
85 69 : f_system(nullptr),
86 161 : jacobian_tolerance(0.)
87 : {
88 161 : if (type == LOCAL_VARIABLE_ORDER)
89 : {
90 0 : auto cf = std::make_unique<CompositeFunction<Number>>();
91 0 : cf->attach_subfunction(f_in, variables);
92 0 : f = std::move(cf);
93 :
94 0 : auto cg = std::make_unique<CompositeFunction<Gradient>>();
95 0 : cg->attach_subfunction(g_in, variables);
96 0 : g = std::move(cg);
97 0 : }
98 : else
99 : {
100 230 : f = f_in.clone();
101 276 : g = g_in.clone();
102 : }
103 :
104 161 : f->init();
105 161 : g->init();
106 161 : }
107 :
108 :
109 0 : DirichletBoundary::
110 : DirichletBoundary(std::set<boundary_id_type> b_in,
111 : std::vector<unsigned int> variables_in,
112 : const System & f_sys_in,
113 : const FEMFunctionBase<Number> * f_in,
114 0 : const FEMFunctionBase<Gradient> * g_in) :
115 0 : b(std::move(b_in)),
116 0 : variables(std::move(variables_in)),
117 0 : f_fem(f_in ? f_in->clone() : nullptr),
118 0 : g_fem(g_in ? g_in->clone() : nullptr),
119 0 : f_system(&f_sys_in),
120 0 : jacobian_tolerance(0.)
121 : {
122 0 : libmesh_assert(f_fem);
123 0 : }
124 :
125 :
126 0 : DirichletBoundary::
127 : DirichletBoundary(std::set<boundary_id_type> b_in,
128 : std::vector<unsigned int> variables_in,
129 : const System & f_sys_in,
130 : const FEMFunctionBase<Number> & f_in,
131 0 : VariableIndexing type) :
132 0 : b(std::move(b_in)),
133 0 : variables(std::move(variables_in)),
134 0 : f_system(&f_sys_in),
135 0 : jacobian_tolerance(0.)
136 : {
137 0 : if (type == LOCAL_VARIABLE_ORDER)
138 : {
139 0 : auto c = std::make_unique<CompositeFEMFunction<Number>>();
140 0 : c->attach_subfunction(f_in, variables);
141 0 : f_fem = std::move(c);
142 0 : }
143 : else
144 0 : f_fem = f_in.clone();
145 0 : }
146 :
147 :
148 0 : DirichletBoundary::
149 : DirichletBoundary(std::set<boundary_id_type> b_in,
150 : std::vector<unsigned int> variables_in,
151 : const System & f_sys_in,
152 : const FEMFunctionBase<Number> & f_in,
153 : const FEMFunctionBase<Gradient> & g_in,
154 0 : VariableIndexing type) :
155 0 : b(std::move(b_in)),
156 0 : variables(std::move(variables_in)),
157 0 : f_system(&f_sys_in),
158 0 : jacobian_tolerance(0.)
159 : {
160 0 : if (type == LOCAL_VARIABLE_ORDER)
161 : {
162 0 : auto cf = std::make_unique<CompositeFEMFunction<Number>>();
163 0 : cf->attach_subfunction(f_in, variables);
164 0 : f_fem = std::move(cf);
165 :
166 0 : auto cg = std::make_unique<CompositeFEMFunction<Gradient>>();
167 0 : cg->attach_subfunction(g_in, variables);
168 0 : g_fem = std::move(cg);
169 0 : }
170 : else
171 : {
172 0 : f_fem = f_in.clone();
173 0 : g_fem = g_in.clone();
174 : }
175 0 : }
176 :
177 :
178 1245 : DirichletBoundary::
179 1245 : DirichletBoundary(const DirichletBoundary & d_in) :
180 378 : b(d_in.b),
181 1245 : variables(d_in.variables),
182 1623 : f(d_in.f ? d_in.f->clone() : nullptr),
183 959 : g(d_in.g ? d_in.g->clone() : nullptr),
184 867 : f_fem(d_in.f_fem ? d_in.f_fem->clone() : nullptr),
185 867 : g_fem(d_in.g_fem ? d_in.g_fem->clone() : nullptr),
186 1245 : f_system(d_in.f_system),
187 4269 : jacobian_tolerance(d_in.jacobian_tolerance)
188 : {
189 378 : libmesh_assert(f || f_fem);
190 378 : libmesh_assert(!(f && f_fem));
191 378 : libmesh_assert(!(f && g_fem));
192 378 : libmesh_assert(!(f_fem && g));
193 378 : libmesh_assert(!(f_fem && !f_system));
194 1245 : if (f)
195 1245 : f->init();
196 1245 : if (g)
197 161 : g->init();
198 1245 : }
199 :
200 :
201 0 : DirichletBoundary & DirichletBoundary::operator= (const DirichletBoundary & rhs)
202 : {
203 : // Implementation in terms of the copy constructor to avoid code duplication.
204 0 : DirichletBoundary tmp(rhs);
205 0 : std::swap(tmp, *this); // class must be "MoveAssignable" and "MoveConstructible" for std::swap to work.
206 0 : return *this;
207 0 : }
208 :
209 :
210 990 : DirichletBoundary::~DirichletBoundary () = default;
211 :
212 : } // namespace libMesh
213 :
214 : #endif // LIBMESH_ENABLE_DIRICHLET
|