HArD::Core3D
Hybrid Arbitrary Degree::Core 3D - Library to implement 3D schemes with vertex, edge, face and cell polynomials as unknowns
Loading...
Searching...
No Matches
ddr-magnetostatics.hpp
Go to the documentation of this file.
1// Implementation of the discrete de Rham sequence for the magnetostatic problem.
2//
3// Author: Daniele Di Pietro (daniele.di-pietro@umontpellier.fr)
4//
5
6/*
7 * The DDR scheme is described in
8 *
9 * An arbitrary-order method for magnetostatics on polyhedral meshes based on a discrete de Rham
10 sequence.
11 * D. A. Di Pietro and J. Droniou, 31p, 2020. url: https://arxiv.org/abs/2005.06890.
12 *
13 * If you use this code in a scientific publication, please mention the above article.
14 *
15 */
16
17#ifndef MAGNETOSTATICS_HPP
18#define MAGNETOSTATICS_HPP
19
20#include <iostream>
21
22#include <boost/math/constants/constants.hpp>
23
24#include <Eigen/Sparse>
25#include <unsupported/Eigen/SparseExtra>
26
27#include <mesh.hpp>
28#include <mesh_builder.hpp>
30#include <linearsolver.hpp>
31
32#include <xdiv.hpp>
33#include <xcurl.hpp>
34
40namespace HArDCore3D
41{
42
50 {
51 typedef Eigen::SparseMatrix<double> SystemMatrixType;
52
53 typedef std::function<Eigen::Vector3d(const Eigen::Vector3d &)> ForcingTermType;
54 typedef std::function<Eigen::Vector3d(const Eigen::Vector3d &)> SolutionPotentialType;
55 typedef std::function<Eigen::Vector3d(const Eigen::Vector3d &)> SolutionCurlType;
57
60 const DDRCore & ddrcore,
61 bool use_threads,
62 std::ostream & output = std::cout
63 );
64
67 const ForcingTermType & f,
68 const PermeabilityType & mu,
69 const SolutionPotentialType & u
70 );
71
72
74 inline size_t dimensionSpace() const
75 {
76 return m_xcurl.dimension() + m_xdiv.dimension();
77 }
78
80 inline size_t nbSCDOFs() const
81 {
82 return m_ddrcore.mesh().n_cells() * m_nloc_sc_H;
83 }
84
86 inline size_t sizeSystem() const
87 {
88 return dimensionSpace() - nbSCDOFs();
89 }
90
92 inline const XCurl & xCurl() const
93 {
94 return m_xcurl;
95 }
96
98 inline const XDiv & xDiv() const
99 {
100 return m_xdiv;
101 }
102
104 inline const SystemMatrixType & systemMatrix() const {
105 return m_A;
106 }
107
110 return m_A;
111 }
112
114 inline const Eigen::VectorXd & systemVector() const {
115 return m_b;
116 }
117
119 inline Eigen::VectorXd & systemVector() {
120 return m_b;
121 }
122
124 inline const double & stabilizationParameter() const {
125 return m_stab_par;
126 }
127
129 inline double & stabilizationParameter() {
130 return m_stab_par;
131 }
132
134 inline const SystemMatrixType & scMatrix() const {
135 return m_sc_A;
136 }
137
139 inline Eigen::VectorXd & scVector() {
140 return m_sc_b;
141 }
142
144 std::vector<double> computeNorms(
145 const std::vector<Eigen::VectorXd> & list_dofs
146 ) const;
147
148 private:
150 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
151 _compute_local_contribution(
152 size_t iT,
153 const ForcingTermType & f,
154 const PermeabilityType & mu
155 );
156
158 LocalStaticCondensation _compute_static_condensation(const size_t & iT) const;
159
161 void _assemble_local_contribution(
162 size_t iT,
163 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
164 std::list<Eigen::Triplet<double> > & A1,
165 Eigen::VectorXd & b1,
166 std::list<Eigen::Triplet<double> > & A2,
167 Eigen::VectorXd & b2
168 );
169
170 const DDRCore & m_ddrcore;
171 bool m_use_threads;
172 std::ostream & m_output;
173 XCurl m_xcurl;
174 XDiv m_xdiv;
175 const size_t m_nloc_sc_H; // Number of statically condensed DOFs of H in each cell
176 SystemMatrixType m_A; // Matrix and RHS of statically condensed system
177 Eigen::VectorXd m_b;
178 SystemMatrixType m_sc_A; // Static condensation operator and RHS (to recover statically condensed DOFs)
179 Eigen::VectorXd m_sc_b;
180 double m_stab_par;
181 };
182
183 //------------------------------------------------------------------------------
184 // Exact solutions
185 //------------------------------------------------------------------------------
186
187 static const double PI = boost::math::constants::pi<double>();
188 using std::sin;
189 using std::cos;
190
191 //------------------------------------------------------------------------------
192
194 constant_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
195 return Eigen::Vector3d(1., 2., 3.);
196 };
197
199 constant_sigma = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
200 return Eigen::Vector3d::Zero();
201 };
202
204 constant_f = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
205 return Eigen::Vector3d::Zero();
206 };
207
210
211 //------------------------------------------------------------------------------
212
214 linear_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
215 return Eigen::Vector3d(
216 x(0) + x(1) + x(2),
217 2.*(x(0)-x(1)+x(2)),
218 -x(0) - x(1) + x(2)
219 );
220 };
221
223 linear_sigma = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
224 return Eigen::Vector3d(-3., 2., 1.);
225 };
226
228 linear_f = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
229 return Eigen::Vector3d::Zero();
230 };
231
234
235 //------------------------------------------------------------------------------
236
238 trigonometric_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
239 return Eigen::Vector3d(
240 cos(PI*x(0)) * sin(PI*x(1)) * sin(PI*x(2)),
241 -2. * sin(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2)),
242 sin(PI*x(0)) * sin(PI*x(1)) * cos(PI*x(2))
243 );
244 };
245
247 trigonometric_sigma = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
248 return 3. * PI * Eigen::Vector3d(
249 sin(PI*x(0)) * cos(PI*x(1)) * cos(PI*x(2)),
250 0.,
251 -cos(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2))
252 );
253 };
254
256 trigonometric_f = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
257 return 3. * std::pow(PI, 2) * Eigen::Vector3d(
258 cos(PI*x(0)) * sin(PI*x(1)) * sin(PI*x(2)),
259 -2. * sin(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2)),
260 sin(PI*x(0)) * sin(PI*x(1)) * cos(PI*x(2))
261 );
262 };
263
266
267 //------------------------------------------------------------------------------
268
269
271 variable_permeability_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
272 return Eigen::Vector3d(
273 cos(PI*x(0)) * sin(PI*x(1)) * sin(PI*x(2)),
274 -2. * sin(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2)),
275 sin(PI*x(0)) * sin(PI*x(1)) * cos(PI*x(2))
276 );
277 };
278
280 variable_permeability_sigma = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
281 return 3 * PI / (1. + x(0) + x(1) + x(2))
282 * Eigen::Vector3d(
283 sin(PI*x(0)) * cos(PI*x(1)) * cos(PI*x(2)),
284 0.,
285 -cos(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2))
286 );
287 };
288
290 variable_permeability_f = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
291 double a = 3 * PI / std::pow(1. + x(0) + x(1) + x(2), 2);
292 double b = 3 * std::pow(PI, 2) / (1. + x(0) + x(1) + x(2));
293 double dy_sigmax = -a * sin(PI*x(0)) * cos(PI*x(1)) * cos(PI*x(2))
294 - b * sin(PI*x(0)) * sin(PI*x(1)) * cos(PI*x(2));
295 double dz_sigmax = -a * sin(PI*x(0)) * cos(PI*x(1)) * cos(PI*x(2))
296 - b * sin(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2));
297 ;
298 double dx_sigmaz = a * cos(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2))
299 + b * sin(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2));
300
301 double dy_sigmaz = a * cos(PI*x(0)) * cos(PI*x(1)) * sin(PI*x(2))
302 + b * cos(PI*x(0)) * sin(PI*x(1)) * sin(PI*x(2));
303
304 return Eigen::Vector3d(
305 dy_sigmaz,
307 -dy_sigmax
308 );
309 };
310
313 [](const Cell & T, const Eigen::Vector3d & x) -> double { return 1. + x(0) + x(1) + x(2); },
314 [](const Cell & T) -> size_t { return 1; }
315 );
316
317} // end of namespace HArDCore3D
318
319#endif
Construct all polynomial spaces for the DDR sequence.
Definition ddrcore.hpp:62
Discrete Hcurl space: local operators, L2 product and global interpolator.
Definition xcurl.hpp:19
Discrete Hdiv space: local operators, L2 product and global interpolator.
Definition xdiv.hpp:20
@ Matrix
Definition basis.hpp:67
size_t dimension() const
Returns the dimension of the global space (all DOFs for all geometric entities)
Definition localdofspace.hpp:80
const Mesh & mesh() const
Return a const reference to the mesh.
Definition ddrcore.hpp:134
static const double PI
Definition ddr-magnetostatics.hpp:187
Eigen::VectorXd & scVector()
Returns the static condensation rhs.
Definition ddr-magnetostatics.hpp:139
static Magnetostatics::SolutionPotentialType linear_u
Definition ddr-magnetostatics.hpp:214
static Magnetostatics::SolutionCurlType linear_sigma
Definition ddr-magnetostatics.hpp:223
double & stabilizationParameter()
Returns the stabilization parameter.
Definition ddr-magnetostatics.hpp:129
const double & stabilizationParameter() const
Returns the stabilization parameter.
Definition ddr-magnetostatics.hpp:124
static Magnetostatics::SolutionCurlType trigonometric_sigma
Definition ddr-magnetostatics.hpp:247
Eigen::SparseMatrix< double > SystemMatrixType
Definition ddr-magnetostatics.hpp:51
SystemMatrixType & systemMatrix()
Returns the linear system matrix.
Definition ddr-magnetostatics.hpp:109
static Magnetostatics::PermeabilityType constant_mu
Definition ddr-magnetostatics.hpp:209
static Magnetostatics::PermeabilityType linear_mu
Definition ddr-magnetostatics.hpp:233
size_t nbSCDOFs() const
Returns the number of statically condensed DOFs (here, the cell magnetic field DOFs)
Definition ddr-magnetostatics.hpp:80
static Magnetostatics::SolutionPotentialType constant_u
Definition ddr-magnetostatics.hpp:194
const XDiv & xDiv() const
Returns the space XDiv.
Definition ddr-magnetostatics.hpp:98
static Magnetostatics::SolutionPotentialType trigonometric_u
Definition ddr-magnetostatics.hpp:238
static Magnetostatics::PermeabilityType variable_permeability_mu
Definition ddr-magnetostatics.hpp:312
static Magnetostatics::ForcingTermType constant_f
Definition ddr-magnetostatics.hpp:204
const SystemMatrixType & systemMatrix() const
Returns the linear system matrix.
Definition ddr-magnetostatics.hpp:104
size_t dimensionSpace() const
Returns the dimension of the magnetic field + potential space.
Definition ddr-magnetostatics.hpp:74
static Magnetostatics::SolutionCurlType constant_sigma
Definition ddr-magnetostatics.hpp:199
std::vector< double > computeNorms(const std::vector< Eigen::VectorXd > &list_dofs) const
Compute the discrete Hcurl \times Hdiv norm of a family of vectors representing the dofs.
Definition ddr-magnetostatics.cpp:410
static Magnetostatics::PermeabilityType trigonometric_mu
Definition ddr-magnetostatics.hpp:265
std::function< Eigen::Vector3d(const Eigen::Vector3d &)> SolutionCurlType
Definition ddr-magnetostatics.hpp:55
IntegralWeight PermeabilityType
Definition ddr-magnetostatics.hpp:56
size_t sizeSystem() const
Returns the size of the statically condensed system.
Definition ddr-magnetostatics.hpp:86
static Magnetostatics::SolutionCurlType variable_permeability_sigma
Definition ddr-magnetostatics.hpp:280
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition ddr-magnetostatics.hpp:114
const XCurl & xCurl() const
Returns the space XCurl.
Definition ddr-magnetostatics.hpp:92
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition ddr-magnetostatics.hpp:119
void assembleLinearSystem(const ForcingTermType &f, const PermeabilityType &mu, const SolutionPotentialType &u)
Assemble the global system
Definition ddr-magnetostatics.cpp:230
std::function< Eigen::Vector3d(const Eigen::Vector3d &)> SolutionPotentialType
Definition ddr-magnetostatics.hpp:54
const SystemMatrixType & scMatrix() const
Returns the static condensation recovery operator.
Definition ddr-magnetostatics.hpp:134
std::function< Eigen::Vector3d(const Eigen::Vector3d &)> ForcingTermType
Definition ddr-magnetostatics.hpp:53
static Magnetostatics::SolutionPotentialType variable_permeability_u
Definition ddr-magnetostatics.hpp:271
static Magnetostatics::ForcingTermType trigonometric_f
Definition ddr-magnetostatics.hpp:256
static Magnetostatics::ForcingTermType linear_f
Definition ddr-magnetostatics.hpp:228
static Magnetostatics::ForcingTermType variable_permeability_f
Definition ddr-magnetostatics.hpp:290
bool use_threads
Definition HHO_DiffAdvecReac.hpp:47
std::size_t n_cells() const
number of cells in the mesh.
Definition MeshND.hpp:60
Definition ddr-magnetostatics.hpp:41
Structure for weights (scalar, at the moment) in integral.
Definition integralweight.hpp:36
Structure to store information for, and perform, local static condensation.
Definition local_static_condensation.hpp:25
Assemble a magnetostatic problem.
Definition ddr-magnetostatics.hpp:50