libMesh
Loading...
Searching...
No Matches
dirichlet_boundary.C
Go to the documentation of this file.
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
32namespace libMesh
33{
34
36DirichletBoundary(std::set<boundary_id_type> b_in,
37 std::vector<unsigned int> variables_in,
38 const FunctionBase<Number> * f_in,
39 const FunctionBase<Gradient> * g_in) :
40 b(std::move(b_in)),
41 variables(std::move(variables_in)),
42 f(f_in ? f_in->clone() : nullptr),
43 g(g_in ? g_in->clone() : nullptr),
44 f_system(nullptr),
45 jacobian_tolerance(0.)
46{
48 f->init();
49 if (g)
50 g->init();
51}
52
53
55DirichletBoundary(std::set<boundary_id_type> b_in,
56 std::vector<unsigned int> variables_in,
57 const FunctionBase<Number> & f_in,
58 VariableIndexing type) :
59 b(std::move(b_in)),
60 variables(std::move(variables_in)),
61 f_system(nullptr),
62 jacobian_tolerance(0.)
63{
64 if (type == LOCAL_VARIABLE_ORDER)
65 {
66 auto c = std::make_unique<CompositeFunction<Number>>();
67 c->attach_subfunction(f_in, variables);
68 f = std::move(c);
69 }
70 else
71 f = f_in.clone();
72
73 f->init();
74}
75
76
78DirichletBoundary(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 VariableIndexing type) :
83 b(std::move(b_in)),
84 variables(std::move(variables_in)),
85 f_system(nullptr),
86 jacobian_tolerance(0.)
87{
88 if (type == LOCAL_VARIABLE_ORDER)
89 {
90 auto cf = std::make_unique<CompositeFunction<Number>>();
91 cf->attach_subfunction(f_in, variables);
92 f = std::move(cf);
93
94 auto cg = std::make_unique<CompositeFunction<Gradient>>();
95 cg->attach_subfunction(g_in, variables);
96 g = std::move(cg);
97 }
98 else
99 {
100 f = f_in.clone();
101 g = g_in.clone();
102 }
103
104 f->init();
105 g->init();
106}
107
108
110DirichletBoundary(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 const FEMFunctionBase<Gradient> * g_in) :
115 b(std::move(b_in)),
116 variables(std::move(variables_in)),
117 f_fem(f_in ? f_in->clone() : nullptr),
118 g_fem(g_in ? g_in->clone() : nullptr),
119 f_system(&f_sys_in),
120 jacobian_tolerance(0.)
121{
123}
124
125
127DirichletBoundary(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 VariableIndexing type) :
132 b(std::move(b_in)),
133 variables(std::move(variables_in)),
134 f_system(&f_sys_in),
135 jacobian_tolerance(0.)
136{
137 if (type == LOCAL_VARIABLE_ORDER)
138 {
139 auto c = std::make_unique<CompositeFEMFunction<Number>>();
140 c->attach_subfunction(f_in, variables);
141 f_fem = std::move(c);
142 }
143 else
144 f_fem = f_in.clone();
145}
146
147
149DirichletBoundary(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 VariableIndexing type) :
155 b(std::move(b_in)),
156 variables(std::move(variables_in)),
157 f_system(&f_sys_in),
158 jacobian_tolerance(0.)
159{
160 if (type == LOCAL_VARIABLE_ORDER)
161 {
162 auto cf = std::make_unique<CompositeFEMFunction<Number>>();
163 cf->attach_subfunction(f_in, variables);
164 f_fem = std::move(cf);
165
166 auto cg = std::make_unique<CompositeFEMFunction<Gradient>>();
167 cg->attach_subfunction(g_in, variables);
168 g_fem = std::move(cg);
169 }
170 else
171 {
172 f_fem = f_in.clone();
173 g_fem = g_in.clone();
174 }
175}
176
177
180 b(d_in.b),
181 variables(d_in.variables),
182 f(d_in.f ? d_in.f->clone() : nullptr),
183 g(d_in.g ? d_in.g->clone() : nullptr),
184 f_fem(d_in.f_fem ? d_in.f_fem->clone() : nullptr),
185 g_fem(d_in.g_fem ? d_in.g_fem->clone() : nullptr),
186 f_system(d_in.f_system),
187 jacobian_tolerance(d_in.jacobian_tolerance)
188{
190 libmesh_assert(!(f && f_fem));
191 libmesh_assert(!(f && g_fem));
192 libmesh_assert(!(f_fem && g));
194 if (f)
195 f->init();
196 if (g)
197 g->init();
198}
199
200
202{
203 // Implementation in terms of the copy constructor to avoid code duplication.
204 DirichletBoundary tmp(rhs);
205 std::swap(tmp, *this); // class must be "MoveAssignable" and "MoveConstructible" for std::swap to work.
206 return *this;
207}
208
209
211
212} // namespace libMesh
213
214#endif // LIBMESH_ENABLE_DIRICHLET
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
std::vector< unsigned int > variables
DirichletBoundary(std::set< boundary_id_type > b_in, std::vector< unsigned int > variables_in, const FunctionBase< Number > *f_in, const FunctionBase< Gradient > *g_in=nullptr)
Constructor for a system-variable-order boundary using pointers-to-functors.
~DirichletBoundary()
Standard destructor.
DirichletBoundary & operator=(const DirichletBoundary &)
std::unique_ptr< FunctionBase< Number > > f
std::unique_ptr< FunctionBase< Gradient > > g
std::unique_ptr< FEMFunctionBase< Number > > f_fem
std::unique_ptr< FEMFunctionBase< Gradient > > g_fem
FEMFunctionBase is a base class from which users can derive in order to define "function-like" object...
virtual std::unique_ptr< FEMFunctionBase< Output > > clone() const =0
Base class for functors that can be evaluated at a point and (optionally) time.
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
static const Real b
The libMesh namespace provides an interface to certain functionality in the library.
VariableIndexing
Dirichlet functions may be indexed either by "system variable order" or "local variable order",...
libmesh_assert(ctx)