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