libMesh
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 
27 namespace libMesh
28 {
29 class MeshBase;
30 class DofMap;
31 class StaticCondensation;
32 class QBase;
33 
36 {
37 public:
38  HDGProblem(const Real nu_in, const bool cavity_in);
39  ~HDGProblem();
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,
83  SparseMatrix<Number> & /*J*/,
84  NonlinearImplicitSystem & S) override;
85 
86 private:
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,
103  DenseMatrix<Number> & J);
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,
111  DenseVector<Number> & R);
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,
131  DenseVector<Number> & R);
132 
133  void scalar_volume_jacobian(const unsigned int vel_component,
134  DenseMatrix<Number> & Jsq,
135  DenseMatrix<Number> & Jsp,
136  DenseMatrix<Number> & Jsu,
137  DenseMatrix<Number> & Jsv);
138 
140 
142  DenseMatrix<Number> & Jpv,
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,
163  DenseVector<Number> & R);
164 
165  void scalar_dirichlet_jacobian(const unsigned int vel_component,
166  DenseMatrix<Number> & Jsq,
167  DenseMatrix<Number> & Jsp,
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,
174  DenseVector<Number> & R);
175 
176  void scalar_face_jacobian(const unsigned int vel_component,
177  DenseMatrix<Number> & Jsq,
178  DenseMatrix<Number> & Jsp,
179  DenseMatrix<Number> & Jss,
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,
188  DenseVector<Number> & R);
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
const std::vector< std::vector< Real > > * scalar_phi_face
Definition: hdg_problem.h:210
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:549
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:177
boundary_id_type bottom_bnd
Definition: hdg_problem.h:60
std::unique_ptr< QBase > qface
Definition: hdg_problem.h:54
HDGProblem(const Real nu_in, const bool cavity_in)
Definition: hdg_problem.C:53
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:118
const std::vector< std::vector< Real > > * scalar_phi
Definition: hdg_problem.h:202
void vector_face_residual(const std::vector< Number > &lm_sol, DenseVector< Number > &R)
Definition: hdg_problem.C:421
const std::vector< std::vector< RealVectorValue > > * vector_phi_face
Definition: hdg_problem.h:209
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:655
void pressure_face_residual(DenseVector< Number > &R)
Definition: hdg_problem.C:341
std::vector< Gradient > sigma_u
Definition: hdg_problem.h:227
const std::vector< std::vector< RealVectorValue > > * vector_phi
Definition: hdg_problem.h:201
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:506
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)
Definition: hdg_problem.C:145
boundary_id_type current_bnd
Definition: hdg_problem.h:251
std::unique_ptr< FEBase > lm_fe_face
Definition: hdg_problem.h:53
std::vector< Number > v_sol
Definition: hdg_problem.h:222
std::vector< Number > p_sol
Definition: hdg_problem.h:224
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:131
const DofMap * dof_map
Definition: hdg_problem.h:44
std::unique_ptr< FEBase > scalar_fe
Definition: hdg_problem.h:49
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:205
std::vector< Number > v_dof_values
Definition: hdg_problem.h:235
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:238
void pressure_volume_residual(DenseVector< Number > &Rp, DenseVector< Number > &Rglm)
Definition: hdg_problem.C:279
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
const Elem * neigh
Definition: hdg_problem.h:254
The libMesh namespace provides an interface to certain functionality in the library.
const std::vector< Real > * JxW_face
Definition: hdg_problem.h:207
This is the MeshBase class.
Definition: mesh_base.h:80
const std::vector< Real > * JxW
Definition: hdg_problem.h:199
const VSoln v_true_soln
Definition: hdg_problem.h:70
const std::vector< std::vector< Real > > * div_vector_phi
Definition: hdg_problem.h:204
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:200
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:105
virtual void residual(const NumericVector< Number > &X, NumericVector< Number > &R, NonlinearImplicitSystem &S) override
Definition: hdg_problem.C:712
std::size_t lm_n_dofs
Definition: hdg_problem.h:243
int8_t boundary_id_type
Definition: id_types.h:51
boundary_id_type top_bnd
Definition: hdg_problem.h:58
std::vector< Number > lm_u_sol
Definition: hdg_problem.h:220
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:215
std::vector< Number > qv_dof_values
Definition: hdg_problem.h:234
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98
std::size_t global_lm_n_dofs
Definition: hdg_problem.h:245
std::vector< Number > p_dof_values
Definition: hdg_problem.h:237
static constexpr Real tau
Definition: hdg_problem.h:248
std::unique_ptr< QBase > qrule
Definition: hdg_problem.h:50
const PSoln p_true_soln
Definition: hdg_problem.h:71
std::vector< Number > lm_v_sol
Definition: hdg_problem.h:223
const std::vector< std::vector< Real > > * lm_phi_face
Definition: hdg_problem.h:211
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:613
std::vector< Number > u_sol
Definition: hdg_problem.h:219
std::unique_ptr< FEBase > scalar_fe_face
Definition: hdg_problem.h:52
void add_matrix(NonlinearImplicitSystem &sys, const unsigned int ivar_num, const unsigned int jvar_num, const DenseMatrix< Number > &elem_mat)
Definition: hdg_problem.C:886
std::vector< Number > u_dof_values
Definition: hdg_problem.h:232
virtual void jacobian(const NumericVector< Number > &X, SparseMatrix< Number > &, NonlinearImplicitSystem &S) override
Definition: hdg_problem.C:896
void pressure_dirichlet_residual(DenseVector< Number > &R)
Definition: hdg_problem.C:396
RealVectorValue get_dirichlet_velocity(const unsigned int qp) const
Definition: hdg_problem.C:371
void scalar_dirichlet_jacobian(const unsigned int vel_component, DenseMatrix< Number > &Jsq, DenseMatrix< Number > &Jsp, DenseMatrix< Number > &Jss)
Definition: hdg_problem.C:479
std::vector< Gradient > qu_sol
Definition: hdg_problem.h:218
const std::vector< Point > * normals
Definition: hdg_problem.h:212
std::vector< Gradient > qv_sol
Definition: hdg_problem.h:221
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Number > qu_dof_values
Definition: hdg_problem.h:231
StaticCondensation * sc
Definition: hdg_problem.h:45
void vector_volume_jacobian(DenseMatrix< Number > &Jqq, DenseMatrix< Number > &Jqs)
Definition: hdg_problem.C:161
const MeshBase * mesh
Definition: hdg_problem.h:43
void pressure_face_jacobian(DenseMatrix< Number > &Jplm_u, DenseMatrix< Number > &Jplm_v)
Definition: hdg_problem.C:353
boundary_id_type left_bnd
Definition: hdg_problem.h:57
std::vector< Number > lm_u_dof_values
Definition: hdg_problem.h:233
const std::vector< Point > * qface_point
Definition: hdg_problem.h:208
Number global_lm_dof_value
Definition: hdg_problem.h:238
void pressure_volume_jacobian(DenseMatrix< Number > &Jpu, DenseMatrix< Number > &Jpv, DenseMatrix< Number > &Jpglm, DenseMatrix< Number > &Jglmp)
Definition: hdg_problem.C:307
const USoln u_true_soln
Definition: hdg_problem.h:69
std::size_t p_n_dofs
Definition: hdg_problem.h:244
void vector_face_jacobian(DenseMatrix< Number > &Jqlm)
Definition: hdg_problem.C:430
std::vector< Number > lm_v_dof_values
Definition: hdg_problem.h:236
const std::vector< std::vector< RealVectorValue > > * grad_scalar_phi
Definition: hdg_problem.h:203
std::size_t scalar_n_dofs
Definition: hdg_problem.h:242
std::size_t vector_n_dofs
Definition: hdg_problem.h:241
void vector_dirichlet_residual(const unsigned int vel_component, DenseVector< Number > &R)
Definition: hdg_problem.C:408
std::vector< Gradient > sigma_v
Definition: hdg_problem.h:228
boundary_id_type right_bnd
Definition: hdg_problem.h:59
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:51
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:441
std::vector< Number > qbar
Definition: hdg_problem.h:257
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:187