libMesh
Loading...
Searching...
No Matches
hdg_problem.h
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#ifndef HDG_PROBLEM_H
19#define HDG_PROBLEM_H
20
21#include "libmesh/libmesh_config.h"
22
23#include "libmesh/nonlinear_implicit_system.h"
24#include "libmesh/fe.h"
25#include "exact_soln.h"
26
27namespace libMesh
28{
29class MeshBase;
30class DofMap;
31class StaticCondensation;
32class QBase;
33
36{
37public:
38 HDGProblem(const Real nu_in, const bool cavity_in);
40
41 // Global data structures
43 const MeshBase * mesh;
44 const DofMap * dof_map;
46
47 // FE objects
48 std::unique_ptr<FEVectorBase> vector_fe;
49 std::unique_ptr<FEBase> scalar_fe;
50 std::unique_ptr<QBase> qrule;
51 std::unique_ptr<FEVectorBase> vector_fe_face;
52 std::unique_ptr<FEBase> scalar_fe_face;
53 std::unique_ptr<FEBase> lm_fe_face;
54 std::unique_ptr<QBase> qface;
55
56 // boundary information
61
62 // The kinematic viscosity
64
65 // Whether we performing a cavity simulation
66 bool cavity;
67
68 // The true solutions
72
73 // Whether we are performing an MMS study
74 bool mms;
75
76 void init();
77
78 virtual void residual(const NumericVector<Number> & X,
80 NonlinearImplicitSystem & S) override;
81
82 virtual void jacobian(const NumericVector<Number> & X,
84 NonlinearImplicitSystem & S) override;
85
86private:
88 const unsigned int ivar_num,
89 const unsigned int jvar_num,
90 const DenseMatrix<Number> & elem_mat);
91
92 void create_identity_residual(const QBase & quadrature,
93 const std::vector<Real> & JxW_local,
94 const std::vector<std::vector<Real>> & phi,
95 const std::vector<Number> & sol,
96 const std::size_t n_dofs,
98
99 void create_identity_jacobian(const QBase & quadrature,
100 const std::vector<Real> & JxW_local,
101 const std::vector<std::vector<Real>> & phi,
102 const std::size_t n_dofs,
104
105 void compute_stress(const std::vector<Gradient> & vel_gradient,
106 const unsigned int vel_component,
107 std::vector<Gradient> & sigma);
108
109 void vector_volume_residual(const std::vector<Gradient> & vector_sol,
110 const std::vector<Number> & scalar_sol,
112
114
115 NumberVectorValue vel_cross_vel_residual(const std::vector<Number> & u_sol_local,
116 const std::vector<Number> & v_sol_local,
117 const unsigned int qp,
118 const unsigned int vel_component) const;
119
120 NumberVectorValue vel_cross_vel_jacobian(const std::vector<Number> & u_sol_local,
121 const std::vector<Number> & v_sol_local,
122 const unsigned int qp,
123 const unsigned int vel_component,
124 const unsigned int vel_j_component,
125 const std::vector<std::vector<Real>> & phi,
126 const unsigned int j) const;
127
128 void scalar_volume_residual(const std::vector<Gradient> & vel_gradient,
129 const unsigned int vel_component,
130 std::vector<Gradient> & sigma,
132
133 void scalar_volume_jacobian(const unsigned int vel_component,
137 DenseMatrix<Number> & Jsv);
138
140
143 DenseMatrix<Number> & Jpglm,
144 DenseMatrix<Number> & Jglmp);
145
147
149
150 RealVectorValue get_dirichlet_velocity(const unsigned int qp) const;
151
153
154 void vector_dirichlet_residual(const unsigned int vel_component, DenseVector<Number> & R);
155
156 void vector_face_residual(const std::vector<Number> & lm_sol, DenseVector<Number> & R);
157
159
160 void scalar_dirichlet_residual(const std::vector<Gradient> & vector_sol,
161 const std::vector<Number> & scalar_sol,
162 const unsigned int vel_component,
164
165 void scalar_dirichlet_jacobian(const unsigned int vel_component,
168 DenseMatrix<Number> & Jss);
169
170 void scalar_face_residual(const std::vector<Gradient> & vector_sol,
171 const std::vector<Number> & scalar_sol,
172 const std::vector<Number> & lm_sol,
173 const unsigned int vel_component,
175
176 void scalar_face_jacobian(const unsigned int vel_component,
180 DenseMatrix<Number> & Jslm,
181 DenseMatrix<Number> & Js_lmu,
182 DenseMatrix<Number> & Js_lmv);
183
184 void lm_face_residual(const std::vector<Gradient> & vector_sol,
185 const std::vector<Number> & scalar_sol,
186 const std::vector<Number> & lm_sol,
187 const unsigned int vel_component,
189
190 void lm_face_jacobian(const unsigned int vel_component,
191 DenseMatrix<Number> & Jlmq,
192 DenseMatrix<Number> & Jlmp,
193 DenseMatrix<Number> & Jlms,
194 DenseMatrix<Number> & Jlmlm,
195 DenseMatrix<Number> & Jlm_lmu,
196 DenseMatrix<Number> & Jlm_lmv);
197
198 // volume
199 const std::vector<Real> * JxW;
200 const std::vector<Point> * q_point;
201 const std::vector<std::vector<RealVectorValue>> * vector_phi;
202 const std::vector<std::vector<Real>> * scalar_phi;
203 const std::vector<std::vector<RealVectorValue>> * grad_scalar_phi;
204 const std::vector<std::vector<Real>> * div_vector_phi;
205
206 // face
207 const std::vector<Real> * JxW_face;
208 const std::vector<Point> * qface_point;
209 const std::vector<std::vector<RealVectorValue>> * vector_phi_face;
210 const std::vector<std::vector<Real>> * scalar_phi_face;
211 const std::vector<std::vector<Real>> * lm_phi_face;
212 const std::vector<Point> * normals;
213
214 // dof indices
215 std::unordered_map<unsigned int, std::vector<dof_id_type>> dof_indices;
216
217 // local solutions at quadrature points
218 std::vector<Gradient> qu_sol;
219 std::vector<Number> u_sol;
220 std::vector<Number> lm_u_sol;
221 std::vector<Gradient> qv_sol;
222 std::vector<Number> v_sol;
223 std::vector<Number> lm_v_sol;
224 std::vector<Number> p_sol;
225
226 // stresses at quadrature points
227 std::vector<Gradient> sigma_u;
228 std::vector<Gradient> sigma_v;
229
230 // local degree of freedom values
231 std::vector<Number> qu_dof_values;
232 std::vector<Number> u_dof_values;
233 std::vector<Number> lm_u_dof_values;
234 std::vector<Number> qv_dof_values;
235 std::vector<Number> v_dof_values;
236 std::vector<Number> lm_v_dof_values;
237 std::vector<Number> p_dof_values;
239
240 // Number of dofs on elem
241 std::size_t vector_n_dofs;
242 std::size_t scalar_n_dofs;
243 std::size_t lm_n_dofs;
244 std::size_t p_n_dofs;
245 std::size_t global_lm_n_dofs;
246
247 // Our stabilization coefficient
248 static constexpr Real tau = 1;
249
250 // The current boundary ID
252
253 // The current element neighbor
254 const Elem * neigh;
255
256 // Computed via the formula: \bar{q} = \frac{1}{|\partial K|} \int_{\partial K} q
257 std::vector<Number> qbar;
258};
259
260} // namespace libMesh
261
262#endif // HDG_PROBLEM_H
Defines a dense matrix for use in Finite Element-type computations.
Defines a dense vector for use in Finite Element-type computations.
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
This is the base class from which all geometric element types are derived.
Definition elem.h:96
StaticCondensation * sc
Definition hdg_problem.h:45
const USoln u_true_soln
Definition hdg_problem.h:69
boundary_id_type bottom_bnd
Definition hdg_problem.h:60
void scalar_volume_residual(const std::vector< Gradient > &vel_gradient, const unsigned int vel_component, std::vector< Gradient > &sigma, DenseVector< Number > &R)
std::vector< Number > qv_dof_values
boundary_id_type right_bnd
Definition hdg_problem.h:59
std::vector< Number > qu_dof_values
std::vector< Number > v_dof_values
std::vector< Gradient > sigma_u
std::vector< Number > p_dof_values
const std::vector< std::vector< Real > > * scalar_phi_face
std::vector< Gradient > sigma_v
const std::vector< std::vector< RealVectorValue > > * vector_phi
const std::vector< Real > * JxW
void vector_dirichlet_residual(const unsigned int vel_component, DenseVector< Number > &R)
std::unique_ptr< FEVectorBase > vector_fe_face
Definition hdg_problem.h:51
const std::vector< std::vector< Real > > * div_vector_phi
void create_identity_jacobian(const QBase &quadrature, const std::vector< Real > &JxW_local, const std::vector< std::vector< Real > > &phi, const std::size_t n_dofs, DenseMatrix< Number > &J)
const std::vector< Point > * q_point
std::vector< Number > lm_v_sol
const PSoln p_true_soln
Definition hdg_problem.h:71
void pressure_dirichlet_residual(DenseVector< Number > &R)
const std::vector< Real > * JxW_face
const std::vector< std::vector< Real > > * scalar_phi
void pressure_face_residual(DenseVector< Number > &R)
const MeshBase * mesh
Definition hdg_problem.h:43
std::vector< Number > p_sol
void scalar_dirichlet_residual(const std::vector< Gradient > &vector_sol, const std::vector< Number > &scalar_sol, const unsigned int vel_component, DenseVector< Number > &R)
void vector_face_residual(const std::vector< Number > &lm_sol, DenseVector< Number > &R)
virtual void jacobian(const NumericVector< Number > &X, SparseMatrix< Number > &, NonlinearImplicitSystem &S) override
Jacobian function.
std::unique_ptr< FEBase > scalar_fe
Definition hdg_problem.h:49
const std::vector< Point > * normals
void scalar_face_jacobian(const unsigned int vel_component, DenseMatrix< Number > &Jsq, DenseMatrix< Number > &Jsp, DenseMatrix< Number > &Jss, DenseMatrix< Number > &Jslm, DenseMatrix< Number > &Js_lmu, DenseMatrix< Number > &Js_lmv)
const DofMap * dof_map
Definition hdg_problem.h:44
void scalar_volume_jacobian(const unsigned int vel_component, DenseMatrix< Number > &Jsq, DenseMatrix< Number > &Jsp, DenseMatrix< Number > &Jsu, DenseMatrix< Number > &Jsv)
const Elem * neigh
std::unique_ptr< QBase > qrule
Definition hdg_problem.h:50
std::unordered_map< unsigned int, std::vector< dof_id_type > > dof_indices
std::size_t scalar_n_dofs
std::vector< Number > v_sol
NumberVectorValue vel_cross_vel_residual(const std::vector< Number > &u_sol_local, const std::vector< Number > &v_sol_local, const unsigned int qp, const unsigned int vel_component) const
std::vector< Gradient > qv_sol
std::vector< Number > lm_u_sol
const std::vector< std::vector< RealVectorValue > > * vector_phi_face
boundary_id_type left_bnd
Definition hdg_problem.h:57
std::vector< Number > qbar
NumberVectorValue vel_cross_vel_jacobian(const std::vector< Number > &u_sol_local, const std::vector< Number > &v_sol_local, const unsigned int qp, const unsigned int vel_component, const unsigned int vel_j_component, const std::vector< std::vector< Real > > &phi, const unsigned int j) const
RealVectorValue get_dirichlet_velocity(const unsigned int qp) const
boundary_id_type top_bnd
Definition hdg_problem.h:58
void create_identity_residual(const QBase &quadrature, const std::vector< Real > &JxW_local, const std::vector< std::vector< Real > > &phi, const std::vector< Number > &sol, const std::size_t n_dofs, DenseVector< Number > &R)
std::unique_ptr< QBase > qface
Definition hdg_problem.h:54
std::vector< Number > u_sol
const std::vector< std::vector< RealVectorValue > > * grad_scalar_phi
std::size_t global_lm_n_dofs
boundary_id_type current_bnd
void scalar_face_residual(const std::vector< Gradient > &vector_sol, const std::vector< Number > &scalar_sol, const std::vector< Number > &lm_sol, const unsigned int vel_component, DenseVector< Number > &R)
std::vector< Number > lm_u_dof_values
void pressure_volume_jacobian(DenseMatrix< Number > &Jpu, DenseMatrix< Number > &Jpv, DenseMatrix< Number > &Jpglm, DenseMatrix< Number > &Jglmp)
const VSoln v_true_soln
Definition hdg_problem.h:70
static constexpr Real tau
std::vector< Number > u_dof_values
std::size_t lm_n_dofs
const std::vector< std::vector< Real > > * lm_phi_face
void lm_face_residual(const std::vector< Gradient > &vector_sol, const std::vector< Number > &scalar_sol, const std::vector< Number > &lm_sol, const unsigned int vel_component, DenseVector< Number > &R)
void vector_face_jacobian(DenseMatrix< Number > &Jqlm)
void lm_face_jacobian(const unsigned int vel_component, DenseMatrix< Number > &Jlmq, DenseMatrix< Number > &Jlmp, DenseMatrix< Number > &Jlms, DenseMatrix< Number > &Jlmlm, DenseMatrix< Number > &Jlm_lmu, DenseMatrix< Number > &Jlm_lmv)
std::size_t vector_n_dofs
virtual void residual(const NumericVector< Number > &X, NumericVector< Number > &R, NonlinearImplicitSystem &S) override
Residual function.
void scalar_dirichlet_jacobian(const unsigned int vel_component, DenseMatrix< Number > &Jsq, DenseMatrix< Number > &Jsp, DenseMatrix< Number > &Jss)
std::vector< Gradient > qu_sol
const std::vector< Point > * qface_point
void compute_stress(const std::vector< Gradient > &vel_gradient, const unsigned int vel_component, std::vector< Gradient > &sigma)
std::unique_ptr< FEBase > scalar_fe_face
Definition hdg_problem.h:52
void vector_volume_jacobian(DenseMatrix< Number > &Jqq, DenseMatrix< Number > &Jqs)
void add_matrix(NonlinearImplicitSystem &sys, const unsigned int ivar_num, const unsigned int jvar_num, const DenseMatrix< Number > &elem_mat)
std::vector< Number > lm_v_dof_values
std::unique_ptr< FEVectorBase > vector_fe
Definition hdg_problem.h:48
void vector_volume_residual(const std::vector< Gradient > &vector_sol, const std::vector< Number > &scalar_sol, DenseVector< Number > &R)
std::unique_ptr< FEBase > lm_fe_face
Definition hdg_problem.h:53
void pressure_face_jacobian(DenseMatrix< Number > &Jplm_u, DenseMatrix< Number > &Jplm_v)
void pressure_volume_residual(DenseVector< Number > &Rp, DenseVector< Number > &Rglm)
std::size_t p_n_dofs
This is the MeshBase class.
Definition mesh_base.h:81
Abstract base class to be used to calculate the Jacobian of a nonlinear system.
Abstract base class to be used to calculate the residual of a nonlinear system.
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
The QBase class provides the basic functionality from which various quadrature rules can be derived.
Definition quadrature.h:62
Generic sparse matrix.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
int8_t boundary_id_type
Definition id_types.h:51
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real