libMesh
hdg_problem.C
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 #include "hdg_problem.h"
19 
20 #if defined(LIBMESH_HAVE_EIGEN_DENSE) && defined(LIBMESH_HAVE_PETSC)
21 
22 #include "libmesh/mesh_base.h"
23 #include "libmesh/dof_map.h"
24 #include "libmesh/static_condensation.h"
25 #include "libmesh/quadrature.h"
26 #include "libmesh/boundary_info.h"
27 #include "libmesh/numeric_vector.h"
28 #include "libmesh/sparse_matrix.h"
29 
30 namespace libMesh
31 {
32 // compute a solution indexable at quadrature points composed from the local degree of freedom
33 // solution vector and associated basis functions
34 template <typename SolnType, typename PhiType>
35 void
36 compute_qp_soln(std::vector<SolnType> & qp_vec,
37  const unsigned int n_qps,
38  const std::vector<std::vector<PhiType>> & phi,
39  const std::vector<Number> & dof_values)
40 {
41  libmesh_assert(dof_values.size() == phi.size());
42  qp_vec.resize(n_qps);
43  for (auto & val : qp_vec)
44  val = {};
45  for (const auto i : index_range(phi))
46  {
47  const auto & qp_phis = phi[i];
48  libmesh_assert(qp_phis.size() == n_qps);
49  const auto sol = dof_values[i];
50  for (const auto qp : make_range(n_qps))
51  qp_vec[qp] += qp_phis[qp] * sol;
52  }
53 }
54 
55 HDGProblem::HDGProblem(const Real nu_in, const bool cavity_in)
56  : nu(nu_in),
57  cavity(cavity_in),
58  u_true_soln(nu, cavity),
59  v_true_soln(nu, cavity),
60  p_true_soln(cavity)
61 {
62 }
63 
64 HDGProblem::~HDGProblem() = default;
65 
66 void
68 {
69  // Attach quadrature rules for the FE objects that we will reinit within the element "volume"
70  vector_fe->attach_quadrature_rule(qrule.get());
71  scalar_fe->attach_quadrature_rule(qrule.get());
72 
73  // Attach quadrature rules for the FE objects that we will reinit on the element faces
74  vector_fe_face->attach_quadrature_rule(qface.get());
75  scalar_fe_face->attach_quadrature_rule(qface.get());
76  lm_fe_face->attach_quadrature_rule(qface.get());
77 
78  // pre-request our required volumetric data
79  JxW = &vector_fe->get_JxW();
80  q_point = &vector_fe->get_xyz();
81  vector_phi = &vector_fe->get_phi();
82  scalar_phi = &scalar_fe->get_phi();
83  grad_scalar_phi = &scalar_fe->get_dphi();
84  div_vector_phi = &vector_fe->get_div_phi();
85 
86  // pre-request our required element face data
87  vector_phi_face = &vector_fe_face->get_phi();
88  scalar_phi_face = &scalar_fe_face->get_phi();
89  lm_phi_face = &lm_fe_face->get_phi();
90  JxW_face = &vector_fe_face->get_JxW();
91  qface_point = &vector_fe_face->get_xyz();
92  normals = &vector_fe_face->get_normals();
93 
94  const auto & bnd_info = mesh->get_boundary_info();
95  left_bnd = bnd_info.get_id_by_name("left");
96  top_bnd = bnd_info.get_id_by_name("top");
97  right_bnd = bnd_info.get_id_by_name("right");
98  bottom_bnd = bnd_info.get_id_by_name("bottom");
103  global_lm_n_dofs = cavity ? 1 : 0;
104 }
105 
106 void
108  const std::vector<Real> & JxW_local,
109  const std::vector<std::vector<Real>> & phi,
110  const std::vector<Number> & sol,
111  const std::size_t n_dofs,
113 {
114  for (const auto qp : make_range(quadrature.n_points()))
115  for (const auto i : make_range(n_dofs))
116  R(i) -= JxW_local[qp] * phi[i][qp] * sol[qp];
117 }
118 
119 void
121  const std::vector<Real> & JxW_local,
122  const std::vector<std::vector<Real>> & phi,
123  const std::size_t n_dofs,
125 {
126  for (const auto qp : make_range(quadrature.n_points()))
127  for (const auto i : make_range(n_dofs))
128  for (const auto j : make_range(n_dofs))
129  J(i, j) -= JxW_local[qp] * phi[i][qp] * phi[j][qp];
130 }
131 
132 void
133 HDGProblem::compute_stress(const std::vector<Gradient> & vel_gradient,
134  const unsigned int vel_component,
135  std::vector<Gradient> & sigma)
136 {
137  sigma.resize(qrule->n_points());
138  for (const auto qp : make_range(qrule->n_points()))
139  {
140  Gradient qp_p;
141  qp_p(vel_component) = p_sol[qp];
142  sigma[qp] = nu * vel_gradient[qp] - qp_p;
143  }
144 }
145 
146 void
147 HDGProblem::vector_volume_residual(const std::vector<Gradient> & vector_sol,
148  const std::vector<Number> & scalar_sol,
150 {
151  for (const auto qp : make_range(qrule->n_points()))
152  for (const auto i : make_range(vector_n_dofs))
153  {
154  // Vector equation dependence on vector dofs
155  R(i) += (*JxW)[qp] * ((*vector_phi)[i][qp] * vector_sol[qp]);
156 
157  // Vector equation dependence on scalar dofs
158  R(i) += (*JxW)[qp] * ((*div_vector_phi)[i][qp] * scalar_sol[qp]);
159  }
160 }
161 
162 void
164 {
165  for (const auto qp : make_range(qrule->n_points()))
166  for (const auto i : make_range(vector_n_dofs))
167  {
168  // Vector equation dependence on vector dofs
169  for (const auto j : make_range(vector_n_dofs))
170  Jqq(i, j) += (*JxW)[qp] * ((*vector_phi)[i][qp] * (*vector_phi)[j][qp]);
171 
172  // Vector equation dependence on scalar dofs
173  for (const auto j : make_range(scalar_n_dofs))
174  Jqs(i, j) += (*JxW)[qp] * ((*div_vector_phi)[i][qp] * (*scalar_phi)[j][qp]);
175  }
176 }
177 
179 HDGProblem::vel_cross_vel_residual(const std::vector<Number> & u_sol_local,
180  const std::vector<Number> & v_sol_local,
181  const unsigned int qp,
182  const unsigned int vel_component) const
183 {
184  const NumberVectorValue U(u_sol_local[qp], v_sol_local[qp]);
185  return U * U(vel_component);
186 }
187 
189 HDGProblem::vel_cross_vel_jacobian(const std::vector<Number> & u_sol_local,
190  const std::vector<Number> & v_sol_local,
191  const unsigned int qp,
192  const unsigned int vel_component,
193  const unsigned int vel_j_component,
194  const std::vector<std::vector<Real>> & phi,
195  const unsigned int j) const
196 {
197  const NumberVectorValue U(u_sol_local[qp], v_sol_local[qp]);
198  NumberVectorValue vector_phi_local;
199  vector_phi_local(vel_j_component) = phi[j][qp];
200  auto ret = vector_phi_local * U(vel_component);
201  if (vel_component == vel_j_component)
202  ret += U * phi[j][qp];
203  return ret;
204 }
205 
206 void
207 HDGProblem::scalar_volume_residual(const std::vector<Gradient> & vel_gradient,
208  const unsigned int vel_component,
209  std::vector<Gradient> & sigma,
211 {
212  compute_stress(vel_gradient, vel_component, sigma);
213  const auto & mms_info = vel_component == 0 ? static_cast<const ExactSoln &>(u_true_soln)
214  : static_cast<const ExactSoln &>(v_true_soln);
215  for (const auto qp : make_range(qrule->n_points()))
216  {
217  const auto vel_cross_vel = vel_cross_vel_residual(u_sol, v_sol, qp, vel_component);
218 
219  // Prepare forcing function
220  Real f = 0;
221  if (mms)
222  f = mms_info.forcing((*q_point)[qp]);
223 
224  for (const auto i : make_range(scalar_n_dofs))
225  {
226  // Scalar equation dependence on vector and pressure dofs
227  R(i) += (*JxW)[qp] * ((*grad_scalar_phi)[i][qp] * sigma[qp]);
228 
229  // Scalar equation dependence on scalar dofs
230  R(i) -= (*JxW)[qp] * ((*grad_scalar_phi)[i][qp] * vel_cross_vel);
231 
232  if (mms)
233  // Scalar equation RHS
234  R(i) -= (*JxW)[qp] * (*scalar_phi)[i][qp] * f;
235  }
236  }
237 }
238 
239 void
240 HDGProblem::scalar_volume_jacobian(const unsigned int vel_component,
241  DenseMatrix<Number> & Jsq,
242  DenseMatrix<Number> & Jsp,
243  DenseMatrix<Number> & Jsu,
244  DenseMatrix<Number> & Jsv)
245 {
246  for (const auto qp : make_range(qrule->n_points()))
247  for (const auto i : make_range(scalar_n_dofs))
248  {
249  // Scalar equation dependence on vector dofs
250  for (const auto j : make_range(vector_n_dofs))
251  Jsq(i, j) += (*JxW)[qp] * nu * ((*grad_scalar_phi)[i][qp] * (*vector_phi)[j][qp]);
252 
253  // Scalar equation dependence on pressure dofs
254  for (const auto j : make_range(p_n_dofs))
255  {
256  Gradient p_phi;
257  p_phi(vel_component) = (*scalar_phi)[j][qp];
258  Jsp(i, j) -= (*JxW)[qp] * ((*grad_scalar_phi)[i][qp] * p_phi);
259  }
260 
261  // Scalar equation dependence on scalar dofs
262  for (const auto j : make_range(scalar_n_dofs))
263  {
264  // derivatives wrt 0th component
265  {
266  const auto vel_cross_vel =
267  vel_cross_vel_jacobian(u_sol, v_sol, qp, vel_component, 0, (*scalar_phi), j);
268  Jsu(i, j) -= (*JxW)[qp] * ((*grad_scalar_phi)[i][qp] * vel_cross_vel);
269  }
270  // derivatives wrt 1th component
271  {
272  const auto vel_cross_vel =
273  vel_cross_vel_jacobian(u_sol, v_sol, qp, vel_component, 1, (*scalar_phi), j);
274  Jsv(i, j) -= (*JxW)[qp] * ((*grad_scalar_phi)[i][qp] * vel_cross_vel);
275  }
276  }
277  }
278 }
279 
280 void
282 {
283  for (const auto qp : make_range(qrule->n_points()))
284  {
285  // Prepare forcing function
286  Real f = 0;
287  if (mms)
288  f = p_true_soln.forcing((*q_point)[qp]);
289 
290  const Gradient vel(u_sol[qp], v_sol[qp]);
291  for (const auto i : make_range(p_n_dofs))
292  {
293  Rp(i) -= (*JxW)[qp] * ((*grad_scalar_phi)[i][qp] * vel);
294 
295  if (mms)
296  // Pressure equation RHS
297  Rp(i) -= (*JxW)[qp] * (*scalar_phi)[i][qp] * f;
298 
299  if (cavity)
300  Rp(i) -= (*JxW)[qp] * (*scalar_phi)[i][qp] * global_lm_dof_value;
301  }
302 
303  if (cavity)
304  Rglm(0) -= (*JxW)[qp] * p_sol[qp];
305  }
306 }
307 
308 void
310  DenseMatrix<Number> & Jpv,
311  DenseMatrix<Number> & Jpglm,
312  DenseMatrix<Number> & Jglmp)
313 {
314  for (const auto qp : make_range(qrule->n_points()))
315  {
316  for (const auto i : make_range(p_n_dofs))
317  {
318  for (const auto j : make_range(scalar_n_dofs))
319  {
320  {
321  const Gradient phi((*scalar_phi)[j][qp], Number(0));
322  Jpu(i, j) -= (*JxW)[qp] * ((*grad_scalar_phi)[i][qp] * phi);
323  }
324  {
325  const Gradient phi(Number(0), (*scalar_phi)[j][qp]);
326  Jpv(i, j) -= (*JxW)[qp] * ((*grad_scalar_phi)[i][qp] * phi);
327  }
328  }
329  if (cavity)
330  Jpglm(i, 0) -= (*JxW)[qp] * (*scalar_phi)[i][qp];
331  }
332 
333  if (cavity)
334  {
336  for (const auto j : make_range(p_n_dofs))
337  Jglmp(0, j) -= (*JxW)[qp] * (*scalar_phi)[j][qp];
338  }
339  }
340 }
341 
342 void
344 {
345  for (const auto qp : make_range(qface->n_points()))
346  {
347  const Gradient vel(lm_u_sol[qp], lm_v_sol[qp]);
348  const auto vdotn = vel * (*normals)[qp];
349  for (const auto i : make_range(p_n_dofs))
350  R(i) += (*JxW_face)[qp] * vdotn * (*scalar_phi_face)[i][qp];
351  }
352 }
353 
354 void
356 {
357  for (const auto qp : make_range(qface->n_points()))
358  for (const auto i : make_range(p_n_dofs))
359  for (const auto j : make_range(lm_n_dofs))
360  {
361  {
362  const Gradient phi((*lm_phi_face)[j][qp], Number(0));
363  Jplm_u(i, j) += (*JxW_face)[qp] * phi * (*normals)[qp] * (*scalar_phi_face)[i][qp];
364  }
365  {
366  const Gradient phi(Number(0), (*lm_phi_face)[j][qp]);
367  Jplm_v(i, j) += (*JxW_face)[qp] * phi * (*normals)[qp] * (*scalar_phi_face)[i][qp];
368  }
369  }
370 }
371 
373 HDGProblem::get_dirichlet_velocity(const unsigned int qp) const
374 {
375  if (mms)
377 
378  if (cavity)
379  {
380  if (current_bnd == top_bnd)
381  return RealVectorValue(1, 0);
382  else
383  return RealVectorValue(0, 0);
384  }
385  else // channel flow case
386  {
388 
389  if (current_bnd == left_bnd)
390  return RealVectorValue(1, 0);
391 
392  else
393  return RealVectorValue(0, 0);
394  }
395 }
396 
397 void
399 {
400  for (const auto qp : make_range(qface->n_points()))
401  {
402  const auto dirichlet_velocity = get_dirichlet_velocity(qp);
403  const auto vdotn = dirichlet_velocity * (*normals)[qp];
404  for (const auto i : make_range(p_n_dofs))
405  R(i) += (*JxW_face)[qp] * vdotn * (*scalar_phi_face)[i][qp];
406  }
407 }
408 
409 void
410 HDGProblem::vector_dirichlet_residual(const unsigned int vel_component, DenseVector<Number> & R)
411 {
412  for (const auto qp : make_range(qface->n_points()))
413  {
414  const auto scalar_value = get_dirichlet_velocity(qp)(vel_component);
415 
416  // External boundary -> Dirichlet faces -> Vector equation RHS
417  for (const auto i : make_range(vector_n_dofs))
418  R(i) -= (*JxW_face)[qp] * ((*vector_phi_face)[i][qp] * (*normals)[qp]) * scalar_value;
419  }
420 }
421 
422 void
423 HDGProblem::vector_face_residual(const std::vector<Number> & lm_sol, DenseVector<Number> & R)
424 {
425  for (const auto qp : make_range(qface->n_points()))
426  // Vector equation dependence on LM dofs
427  for (const auto i : make_range(vector_n_dofs))
428  R(i) -= (*JxW_face)[qp] * ((*vector_phi_face)[i][qp] * (*normals)[qp]) * lm_sol[qp];
429 }
430 
431 void
433 {
434  for (const auto qp : make_range(qface->n_points()))
435  // Vector equation dependence on LM dofs
436  for (const auto i : make_range(vector_n_dofs))
437  for (const auto j : make_range(lm_n_dofs))
438  Jqlm(i, j) -=
439  (*JxW_face)[qp] * ((*vector_phi_face)[i][qp] * (*normals)[qp]) * (*lm_phi_face)[j][qp];
440 }
441 
442 void
443 HDGProblem::scalar_dirichlet_residual(const std::vector<Gradient> & vector_sol,
444  const std::vector<Number> & scalar_sol,
445  const unsigned int vel_component,
447 {
448  for (const auto qp : make_range(qface->n_points()))
449  {
450  Gradient qp_p;
451  qp_p(vel_component) = p_sol[qp];
452 
453  const auto dirichlet_velocity = get_dirichlet_velocity(qp);
454  const auto scalar_value = dirichlet_velocity(vel_component);
455  ;
456 
457  for (const auto i : make_range(scalar_n_dofs))
458  {
459  // vector
460  R(i) -= (*JxW_face)[qp] * nu * (*scalar_phi_face)[i][qp] * (vector_sol[qp] * (*normals)[qp]);
461 
462  // pressure
463  R(i) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * (qp_p * (*normals)[qp]);
464 
465  // scalar from stabilization term
466  R(i) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * tau * scalar_sol[qp] * (*normals)[qp] *
467  (*normals)[qp];
468 
469  // dirichlet lm from stabilization term
470  R(i) -= (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * tau * scalar_value * (*normals)[qp] *
471  (*normals)[qp];
472 
473  // dirichlet lm from advection term
474  R(i) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * (dirichlet_velocity * (*normals)[qp]) *
475  scalar_value;
476  }
477  }
478 }
479 
480 void
481 HDGProblem::scalar_dirichlet_jacobian(const unsigned int vel_component,
482  DenseMatrix<Number> & Jsq,
483  DenseMatrix<Number> & Jsp,
484  DenseMatrix<Number> & Jss)
485 {
486  for (const auto qp : make_range(qface->n_points()))
487  for (const auto i : make_range(scalar_n_dofs))
488  {
489  for (const auto j : make_range(vector_n_dofs))
490  Jsq(i, j) -= (*JxW_face)[qp] * nu * (*scalar_phi_face)[i][qp] *
491  ((*vector_phi_face)[j][qp] * (*normals)[qp]);
492 
493  for (const auto j : make_range(p_n_dofs))
494  {
495  Gradient p_phi;
496  p_phi(vel_component) = (*scalar_phi_face)[j][qp];
497  // pressure
498  Jsp(i, j) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * (p_phi * (*normals)[qp]);
499  }
500 
501  for (const auto j : make_range(scalar_n_dofs))
502  Jss(i, j) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * tau * (*scalar_phi_face)[j][qp] *
503  (*normals)[qp] * (*normals)[qp];
504  }
505 }
506 
507 void
508 HDGProblem::scalar_face_residual(const std::vector<Gradient> & vector_sol,
509  const std::vector<Number> & scalar_sol,
510  const std::vector<Number> & lm_sol,
511  const unsigned int vel_component,
513 {
514  for (const auto qp : make_range(qface->n_points()))
515  {
516  Gradient qp_p;
517  qp_p(vel_component) = p_sol[qp];
518  const auto vel_cross_vel = vel_cross_vel_residual(lm_u_sol, lm_v_sol, qp, vel_component);
519 
520  for (const auto i : make_range(scalar_n_dofs))
521  {
522  if (neigh)
523  {
524  // vector
525  R(i) -=
526  (*JxW_face)[qp] * nu * (*scalar_phi_face)[i][qp] * (vector_sol[qp] * (*normals)[qp]);
527 
528  // pressure
529  R(i) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * (qp_p * (*normals)[qp]);
530 
531  // scalar from stabilization term
532  R(i) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * tau * scalar_sol[qp] *
533  (*normals)[qp] * (*normals)[qp];
534 
535  // lm from stabilization term
536  R(i) -= (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * tau * lm_sol[qp] * (*normals)[qp] *
537  (*normals)[qp];
538  }
539  else
540  libmesh_assert_msg(current_bnd == right_bnd,
541  "This method should only be called with an outflow boundary. "
542  "Dirichlet boundaries should call a different routine");
543 
544  // lm from convection term
545  R(i) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * vel_cross_vel * (*normals)[qp];
546  }
547  }
548 }
549 
550 void
551 HDGProblem::scalar_face_jacobian(const unsigned int vel_component,
552  DenseMatrix<Number> & Jsq,
553  DenseMatrix<Number> & Jsp,
554  DenseMatrix<Number> & Jss,
555  DenseMatrix<Number> & Jslm,
556  DenseMatrix<Number> & Js_lmu,
557  DenseMatrix<Number> & Js_lmv)
558 {
559  for (const auto qp : make_range(qface->n_points()))
560  for (const auto i : make_range(scalar_n_dofs))
561  {
562  if (neigh)
563  {
564  for (const auto j : make_range(vector_n_dofs))
565  Jsq(i, j) -= (*JxW_face)[qp] * nu * (*scalar_phi_face)[i][qp] *
566  ((*vector_phi_face)[j][qp] * (*normals)[qp]);
567 
568  for (const auto j : make_range(p_n_dofs))
569  {
570  Gradient p_phi;
571  p_phi(vel_component) = (*scalar_phi_face)[j][qp];
572  // pressure
573  Jsp(i, j) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * (p_phi * (*normals)[qp]);
574  }
575 
576  for (const auto j : make_range(scalar_n_dofs))
577  Jss(i, j) += (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * tau *
578  (*scalar_phi_face)[j][qp] * (*normals)[qp] * (*normals)[qp];
579  }
580  else
581  libmesh_assert_msg(current_bnd == right_bnd,
582  "This method should only be called with an outflow boundary. "
583  "Dirichlet boundaries should call a different routine");
584 
585  for (const auto j : make_range(lm_n_dofs))
586  {
587  if (neigh)
588  // from stabilization term
589  Jslm(i, j) -= (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * tau * (*lm_phi_face)[j][qp] *
590  (*normals)[qp] * (*normals)[qp];
591 
592  //
593  // from convection term
594  //
595 
596  // derivatives wrt 0th component
597  {
598  const auto vel_cross_vel =
599  vel_cross_vel_jacobian(lm_u_sol, lm_v_sol, qp, vel_component, 0, (*lm_phi_face), j);
600  Js_lmu(i, j) +=
601  (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * vel_cross_vel * (*normals)[qp];
602  }
603  // derivatives wrt 1th component
604  {
605  const auto vel_cross_vel =
606  vel_cross_vel_jacobian(lm_u_sol, lm_v_sol, qp, vel_component, 1, (*lm_phi_face), j);
607  Js_lmv(i, j) +=
608  (*JxW_face)[qp] * (*scalar_phi_face)[i][qp] * vel_cross_vel * (*normals)[qp];
609  }
610  }
611  }
612 }
613 
614 void
615 HDGProblem::lm_face_residual(const std::vector<Gradient> & vector_sol,
616  const std::vector<Number> & scalar_sol,
617  const std::vector<Number> & lm_sol,
618  const unsigned int vel_component,
620 {
621  for (const auto qp : make_range(qface->n_points()))
622  {
623  Gradient qp_p;
624  qp_p(vel_component) = p_sol[qp];
625  const auto vel_cross_vel = vel_cross_vel_residual(lm_u_sol, lm_v_sol, qp, vel_component);
626 
627  for (const auto i : make_range(lm_n_dofs))
628  {
629  // vector
630  R(i) -= (*JxW_face)[qp] * nu * (*lm_phi_face)[i][qp] * (vector_sol[qp] * (*normals)[qp]);
631 
632  // pressure
633  R(i) += (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * (qp_p * (*normals)[qp]);
634 
635  // scalar from stabilization term
636  R(i) += (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * tau * scalar_sol[qp] * (*normals)[qp] *
637  (*normals)[qp];
638 
639  // lm from stabilization term
640  R(i) -= (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * tau * lm_sol[qp] * (*normals)[qp] *
641  (*normals)[qp];
642 
643  // If we are an internal face we add the convective term. On the outflow boundary we do not
644  // zero out the convection term, e.g. we are going to set q + p + tau * (u - u_hat) to zero
645  if (neigh)
646  // lm from convection term
647  R(i) += (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * vel_cross_vel * (*normals)[qp];
648  else
649  libmesh_assert_msg(current_bnd == right_bnd,
650  "This method should only be called with an outflow boundary. "
651  "Dirichlet boundaries should call a different routine");
652  }
653  }
654 }
655 
656 void
657 HDGProblem::lm_face_jacobian(const unsigned int vel_component,
658  DenseMatrix<Number> & Jlmq,
659  DenseMatrix<Number> & Jlmp,
660  DenseMatrix<Number> & Jlms,
661  DenseMatrix<Number> & Jlmlm,
662  DenseMatrix<Number> & Jlm_lmu,
663  DenseMatrix<Number> & Jlm_lmv)
664 {
665  for (const auto qp : make_range(qface->n_points()))
666  for (const auto i : make_range(lm_n_dofs))
667  {
668  for (const auto j : make_range(vector_n_dofs))
669  Jlmq(i, j) -= (*JxW_face)[qp] * nu * (*lm_phi_face)[i][qp] *
670  ((*vector_phi_face)[j][qp] * (*normals)[qp]);
671 
672  for (const auto j : make_range(p_n_dofs))
673  {
674  Gradient p_phi;
675  p_phi(vel_component) = (*scalar_phi_face)[j][qp];
676  Jlmp(i, j) += (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * (p_phi * (*normals)[qp]);
677  }
678 
679  for (const auto j : make_range(scalar_n_dofs))
680  Jlms(i, j) += (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * tau * (*scalar_phi_face)[j][qp] *
681  (*normals)[qp] * (*normals)[qp];
682 
683  for (const auto j : make_range(lm_n_dofs))
684  {
685  // from stabilization term
686  Jlmlm(i, j) -= (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * tau * (*lm_phi_face)[j][qp] *
687  (*normals)[qp] * (*normals)[qp];
688  if (neigh)
689  {
690  // derivatives wrt 0th component
691  {
692  const auto vel_cross_vel =
693  vel_cross_vel_jacobian(lm_u_sol, lm_v_sol, qp, vel_component, 0, (*lm_phi_face), j);
694  Jlm_lmu(i, j) +=
695  (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * vel_cross_vel * (*normals)[qp];
696  }
697  // derivatives wrt 1th component
698  {
699  const auto vel_cross_vel =
700  vel_cross_vel_jacobian(lm_u_sol, lm_v_sol, qp, vel_component, 1, (*lm_phi_face), j);
701  Jlm_lmv(i, j) +=
702  (*JxW_face)[qp] * (*lm_phi_face)[i][qp] * vel_cross_vel * (*normals)[qp];
703  }
704  }
705  else
706  libmesh_assert_msg(current_bnd == right_bnd,
707  "This method should only be called with an outflow boundary. "
708  "Dirichlet boundaries should call a different routine");
709  }
710  }
711 }
712 
713 void
717 {
718  R.zero();
719 
720  const auto u_num = S.variable_number("vel_x");
721  const auto v_num = S.variable_number("vel_y");
722  const auto qu_num = S.variable_number("qu");
723  const auto qv_num = S.variable_number("qv");
724  const auto lm_u_num = S.variable_number("lm_u");
725  const auto lm_v_num = S.variable_number("lm_v");
726  const auto p_num = S.variable_number("pressure");
727  const auto global_lm_num = cavity ? S.variable_number("global_lm") : invalid_uint;
728 
729  auto & qu_dof_indices = dof_indices[qu_num];
730  auto & u_dof_indices = dof_indices[u_num];
731  auto & lm_u_dof_indices = dof_indices[lm_u_num];
732  auto & qv_dof_indices = dof_indices[qv_num];
733  auto & v_dof_indices = dof_indices[v_num];
734  auto & lm_v_dof_indices = dof_indices[lm_v_num];
735  auto & p_dof_indices = dof_indices[p_num];
736  static std::vector<dof_id_type> dummy_indices;
737  auto & global_lm_dof_indices = cavity ? dof_indices[global_lm_num] : dummy_indices;
738 
739  std::vector<boundary_id_type> boundary_ids;
740  const auto & boundary_info = mesh->get_boundary_info();
741  DenseVector<Number> Rqu, Rqv, Ru, Rv, Rlm_u, Rlm_v, Rp, Rglm;
742 
743  for (const auto & elem : mesh->active_local_element_ptr_range())
744  {
745  // Retrive our dof indices for all fields
746  dof_map->dof_indices(elem, qu_dof_indices, qu_num);
747  dof_map->dof_indices(elem, u_dof_indices, u_num);
748  dof_map->dof_indices(elem, lm_u_dof_indices, lm_u_num);
749  dof_map->dof_indices(elem, qv_dof_indices, qv_num);
750  dof_map->dof_indices(elem, v_dof_indices, v_num);
751  dof_map->dof_indices(elem, lm_v_dof_indices, lm_v_num);
752  dof_map->dof_indices(elem, p_dof_indices, p_num);
753  if (cavity)
754  {
755  dof_map->dof_indices(elem, global_lm_dof_indices, global_lm_num);
756  libmesh_assert(global_lm_dof_indices.size() == 1);
757  }
758 
759  vector_n_dofs = qu_dof_indices.size();
760  scalar_n_dofs = u_dof_indices.size();
761  lm_n_dofs = lm_u_dof_indices.size();
762  p_n_dofs = p_dof_indices.size();
764  Rqu.resize(vector_n_dofs);
765  Rqv.resize(vector_n_dofs);
766  Ru.resize(scalar_n_dofs);
767  Rv.resize(scalar_n_dofs);
768  Rlm_u.resize(lm_n_dofs);
769  Rlm_v.resize(lm_n_dofs);
770  Rp.resize(p_n_dofs);
771  Rglm.resize(global_lm_dof_indices.size());
772 
773  // Reinit our volume FE objects
774  vector_fe->reinit(elem);
775  scalar_fe->reinit(elem);
776 
777  libmesh_assert_equal_to(vector_n_dofs, vector_phi->size());
778  libmesh_assert_equal_to(scalar_n_dofs, scalar_phi->size());
779 
780  // Get our local element dof values
781  X.get(qu_dof_indices, qu_dof_values);
782  X.get(u_dof_indices, u_dof_values);
783  X.get(lm_u_dof_indices, lm_u_dof_values);
784  X.get(qv_dof_indices, qv_dof_values);
785  X.get(v_dof_indices, v_dof_values);
786  X.get(lm_v_dof_indices, lm_v_dof_values);
787  X.get(p_dof_indices, p_dof_values);
788  if (cavity)
789  global_lm_dof_value = X(global_lm_dof_indices[0]);
790 
791  // Compute volumetric local qp solutions
797 
798  //
799  // compute volumetric residuals and Jacobians
800  //
801 
802  // qu and u
805 
806  // qv and v
809 
810  // p
811  pressure_volume_residual(Rp, Rglm);
812 
813  for (auto side : elem->side_index_range())
814  {
815  neigh = elem->neighbor_ptr(side);
816 
817  // Reinit our face FE objects
818  vector_fe_face->reinit(elem, side);
819  scalar_fe_face->reinit(elem, side);
820  lm_fe_face->reinit(elem, side);
821 
822  // Compute face local qp solutions
830 
831  if (neigh == nullptr)
832  {
833  boundary_info.boundary_ids(elem, side, boundary_ids);
834  libmesh_assert(boundary_ids.size() == 1);
835  current_bnd = boundary_ids[0];
836  if (cavity || (current_bnd != right_bnd))
837  {
838  // qu, u
841 
842  // qv, v
845 
846  // p
848 
849  // Set the LMs on these Dirichlet boundary faces to 0
852 
853  continue;
854  }
855  }
856 
857  //
858  // if we got here, then we are on an internal face or an outlet face
859  //
860 
861  // qu, u, lm_u
864  lm_face_residual(qu_sol, u_sol, lm_u_sol, 0, Rlm_u);
865 
866  // qv, v, lm_v
869  lm_face_residual(qv_sol, v_sol, lm_v_sol, 1, Rlm_v);
870 
871  // p
873  }
874 
875  R.add_vector(Rqu, qu_dof_indices);
876  R.add_vector(Rqv, qv_dof_indices);
877  R.add_vector(Ru, u_dof_indices);
878  R.add_vector(Rv, v_dof_indices);
879  R.add_vector(Rlm_u, lm_u_dof_indices);
880  R.add_vector(Rlm_v, lm_v_dof_indices);
881  R.add_vector(Rp, p_dof_indices);
882  if (cavity)
883  R.add_vector(Rglm, global_lm_dof_indices);
884  }
885 }
886 
887 void
889  const unsigned int ivar_num,
890  const unsigned int jvar_num,
891  const DenseMatrix<Number> & elem_mat)
892 {
894  elem_mat, libmesh_map_find(dof_indices, ivar_num), libmesh_map_find(dof_indices, jvar_num));
895 }
896 
897 void
901 {
902  auto * J = &S.get_system_matrix();
903 
904  if (!sc)
905  // PETSc requires that the Jacobian matrix have a diagonal for some types of preconditioners
906  for (const auto i : make_range(J->row_start(), J->row_stop()))
907  J->add(i, i, 0);
908 
909  const auto u_num = S.variable_number("vel_x");
910  const auto v_num = S.variable_number("vel_y");
911  const auto qu_num = S.variable_number("qu");
912  const auto qv_num = S.variable_number("qv");
913  const auto lm_u_num = S.variable_number("lm_u");
914  const auto lm_v_num = S.variable_number("lm_v");
915  const auto p_num = S.variable_number("pressure");
916  const auto global_lm_num = cavity ? S.variable_number("global_lm") : invalid_uint;
917 
918  auto & qu_dof_indices = dof_indices[qu_num];
919  auto & u_dof_indices = dof_indices[u_num];
920  auto & lm_u_dof_indices = dof_indices[lm_u_num];
921  auto & qv_dof_indices = dof_indices[qv_num];
922  auto & v_dof_indices = dof_indices[v_num];
923  auto & lm_v_dof_indices = dof_indices[lm_v_num];
924  auto & p_dof_indices = dof_indices[p_num];
925  static std::vector<dof_id_type> dummy_indices;
926  auto & global_lm_dof_indices = cavity ? dof_indices[global_lm_num] : dummy_indices;
927 
928  std::vector<boundary_id_type> boundary_ids;
929  const auto & boundary_info = mesh->get_boundary_info();
930 
931  DenseMatrix<Number> Jqu_qu, Jqv_qv, Jqu_u, Jqv_v, Ju_qu, Jv_qv, Ju_p, Jv_p, Ju_u, Jv_u, Ju_v,
932  Jv_v, Jp_u, Jp_v, Jp_glm, Jglm_p, Jp_lmu, Jp_lmv, Jqu_lmu, Jqv_lmv, Ju_lmu, Jv_lmv, Jv_lmu,
933  Ju_lmv, Jlmu_qu, Jlmv_qv, Jlmu_p, Jlmv_p, Jlmu_u, Jlmv_v, Jlmu_lmu, Jlmv_lmu, Jlmu_lmv,
934  Jlmv_lmv;
935 
936  for (const auto & elem : mesh->active_local_element_ptr_range())
937  {
938  if (sc)
939  sc->set_current_elem(*elem);
940 
941  // Retrive our dof indices for all fields
942  dof_map->dof_indices(elem, qu_dof_indices, qu_num);
943  dof_map->dof_indices(elem, u_dof_indices, u_num);
944  dof_map->dof_indices(elem, lm_u_dof_indices, lm_u_num);
945  dof_map->dof_indices(elem, qv_dof_indices, qv_num);
946  dof_map->dof_indices(elem, v_dof_indices, v_num);
947  dof_map->dof_indices(elem, lm_v_dof_indices, lm_v_num);
948  dof_map->dof_indices(elem, p_dof_indices, p_num);
949  if (cavity)
950  {
951  dof_map->dof_indices(elem, global_lm_dof_indices, global_lm_num);
952  libmesh_assert(global_lm_dof_indices.size() == 1);
953  }
954 
955  vector_n_dofs = qu_dof_indices.size();
956  scalar_n_dofs = u_dof_indices.size();
957  lm_n_dofs = lm_u_dof_indices.size();
958  p_n_dofs = p_dof_indices.size();
960 
961  Jqu_qu.resize(qu_dof_indices.size(), qu_dof_indices.size());
962  Jqv_qv.resize(qv_dof_indices.size(), qv_dof_indices.size());
963  Jqu_u.resize(qu_dof_indices.size(), u_dof_indices.size());
964  Jqv_v.resize(qv_dof_indices.size(), v_dof_indices.size());
965  Ju_qu.resize(u_dof_indices.size(), qu_dof_indices.size());
966  Jv_qv.resize(v_dof_indices.size(), qv_dof_indices.size());
967  Ju_p.resize(u_dof_indices.size(), p_dof_indices.size());
968  Jv_p.resize(v_dof_indices.size(), p_dof_indices.size());
969  Ju_u.resize(u_dof_indices.size(), u_dof_indices.size());
970  Jv_u.resize(v_dof_indices.size(), u_dof_indices.size());
971  Ju_v.resize(u_dof_indices.size(), v_dof_indices.size());
972  Jv_v.resize(v_dof_indices.size(), v_dof_indices.size());
973  Jp_u.resize(p_dof_indices.size(), u_dof_indices.size());
974  Jp_v.resize(p_dof_indices.size(), v_dof_indices.size());
975  Jp_glm.resize(p_dof_indices.size(), global_lm_dof_indices.size());
976  Jglm_p.resize(global_lm_dof_indices.size(), p_dof_indices.size());
977  Jp_lmu.resize(p_dof_indices.size(), lm_u_dof_indices.size());
978  Jp_lmv.resize(p_dof_indices.size(), lm_v_dof_indices.size());
979  Jqu_lmu.resize(qu_dof_indices.size(), lm_u_dof_indices.size());
980  Jqv_lmv.resize(qv_dof_indices.size(), lm_v_dof_indices.size());
981  Ju_lmu.resize(u_dof_indices.size(), lm_u_dof_indices.size());
982  Jv_lmv.resize(v_dof_indices.size(), lm_v_dof_indices.size());
983  Jv_lmu.resize(v_dof_indices.size(), lm_u_dof_indices.size());
984  Ju_lmv.resize(u_dof_indices.size(), lm_v_dof_indices.size());
985  Jlmu_qu.resize(lm_u_dof_indices.size(), qu_dof_indices.size());
986  Jlmv_qv.resize(lm_v_dof_indices.size(), qv_dof_indices.size());
987  Jlmu_p.resize(lm_u_dof_indices.size(), p_dof_indices.size());
988  Jlmv_p.resize(lm_v_dof_indices.size(), p_dof_indices.size());
989  Jlmu_u.resize(lm_u_dof_indices.size(), u_dof_indices.size());
990  Jlmv_v.resize(lm_v_dof_indices.size(), v_dof_indices.size());
991  Jlmu_lmu.resize(lm_u_dof_indices.size(), lm_u_dof_indices.size());
992  Jlmv_lmu.resize(lm_v_dof_indices.size(), lm_u_dof_indices.size());
993  Jlmu_lmv.resize(lm_u_dof_indices.size(), lm_v_dof_indices.size());
994  Jlmv_lmv.resize(lm_v_dof_indices.size(), lm_v_dof_indices.size());
995 
996  // Reinit our volume FE objects
997  vector_fe->reinit(elem);
998  scalar_fe->reinit(elem);
999 
1000  libmesh_assert_equal_to(vector_n_dofs, vector_phi->size());
1001  libmesh_assert_equal_to(scalar_n_dofs, scalar_phi->size());
1002 
1003  // Get our local element dof values
1004  X.get(qu_dof_indices, qu_dof_values);
1005  X.get(u_dof_indices, u_dof_values);
1006  X.get(lm_u_dof_indices, lm_u_dof_values);
1007  X.get(qv_dof_indices, qv_dof_values);
1008  X.get(v_dof_indices, v_dof_values);
1009  X.get(lm_v_dof_indices, lm_v_dof_values);
1010  X.get(p_dof_indices, p_dof_values);
1011  if (cavity)
1012  global_lm_dof_value = X(global_lm_dof_indices[0]);
1013 
1014  // Compute volumetric local qp solutions
1020 
1021  //
1022  // compute volumetric residuals and Jacobians
1023  //
1024 
1025  // qu and u
1026  vector_volume_jacobian(Jqu_qu, Jqu_u);
1027  scalar_volume_jacobian(0, Ju_qu, Ju_p, Ju_u, Ju_v);
1028 
1029  // qv and v
1030  vector_volume_jacobian(Jqv_qv, Jqv_v);
1031  scalar_volume_jacobian(1, Jv_qv, Jv_p, Jv_u, Jv_v);
1032 
1033  // p
1034  pressure_volume_jacobian(Jp_u, Jp_v, Jp_glm, Jglm_p);
1035 
1036  for (auto side : elem->side_index_range())
1037  {
1038  neigh = elem->neighbor_ptr(side);
1039 
1040  // Reinit our face FE objects
1041  vector_fe_face->reinit(elem, side);
1042  scalar_fe_face->reinit(elem, side);
1043  lm_fe_face->reinit(elem, side);
1044 
1045  // Compute face local qp solutions
1053 
1054  if (neigh == nullptr)
1055  {
1056  boundary_info.boundary_ids(elem, side, boundary_ids);
1057  libmesh_assert(boundary_ids.size() == 1);
1058  current_bnd = boundary_ids[0];
1059  if (cavity || (current_bnd != right_bnd))
1060  {
1061  // qu, u
1062  scalar_dirichlet_jacobian(0, Ju_qu, Ju_p, Ju_u);
1063 
1064  // qv, v
1065  scalar_dirichlet_jacobian(1, Jv_qv, Jv_p, Jv_v);
1066 
1067  // Set the LMs on these Dirichlet boundary faces to 0
1070 
1071  continue;
1072  }
1073  }
1074 
1075  //
1076  // if we got here, then we are on an internal face or an outlet face
1077  //
1078 
1079  // qu, u, lm_u
1080  vector_face_jacobian(Jqu_lmu);
1081  scalar_face_jacobian(0, Ju_qu, Ju_p, Ju_u, Ju_lmu, Ju_lmu, Ju_lmv);
1082  lm_face_jacobian(0, Jlmu_qu, Jlmu_p, Jlmu_u, Jlmu_lmu, Jlmu_lmu, Jlmu_lmv);
1083 
1084  // qv, v, lm_v
1085  vector_face_jacobian(Jqv_lmv);
1086  scalar_face_jacobian(1, Jv_qv, Jv_p, Jv_v, Jv_lmv, Jv_lmu, Jv_lmv);
1087  lm_face_jacobian(1, Jlmv_qv, Jlmv_p, Jlmv_v, Jlmv_lmv, Jlmv_lmu, Jlmv_lmv);
1088 
1089  // p
1090  pressure_face_jacobian(Jp_lmu, Jp_lmv);
1091  }
1092 
1093  add_matrix(S, qu_num, qu_num, Jqu_qu);
1094  add_matrix(S, qv_num, qv_num, Jqv_qv);
1095  add_matrix(S, qu_num, u_num, Jqu_u);
1096  add_matrix(S, qv_num, v_num, Jqv_v);
1097  add_matrix(S, u_num, qu_num, Ju_qu);
1098  add_matrix(S, v_num, qv_num, Jv_qv);
1099  add_matrix(S, u_num, p_num, Ju_p);
1100  add_matrix(S, v_num, p_num, Jv_p);
1101  add_matrix(S, u_num, u_num, Ju_u);
1102  add_matrix(S, v_num, u_num, Jv_u);
1103  add_matrix(S, u_num, v_num, Ju_v);
1104  add_matrix(S, v_num, v_num, Jv_v);
1105  add_matrix(S, p_num, u_num, Jp_u);
1106  add_matrix(S, p_num, v_num, Jp_v);
1107  if (global_lm_num != invalid_uint)
1108  {
1109  add_matrix(S, p_num, global_lm_num, Jp_glm);
1110  add_matrix(S, global_lm_num, p_num, Jglm_p);
1111  }
1112  add_matrix(S, p_num, lm_u_num, Jp_lmu);
1113  add_matrix(S, p_num, lm_v_num, Jp_lmv);
1114  add_matrix(S, qu_num, lm_u_num, Jqu_lmu);
1115  add_matrix(S, qv_num, lm_v_num, Jqv_lmv);
1116  add_matrix(S, u_num, lm_u_num, Ju_lmu);
1117  add_matrix(S, v_num, lm_v_num, Jv_lmv);
1118  add_matrix(S, v_num, lm_u_num, Jv_lmu);
1119  add_matrix(S, u_num, lm_v_num, Ju_lmv);
1120  add_matrix(S, lm_u_num, qu_num, Jlmu_qu);
1121  add_matrix(S, lm_v_num, qv_num, Jlmv_qv);
1122  add_matrix(S, lm_u_num, p_num, Jlmu_p);
1123  add_matrix(S, lm_v_num, p_num, Jlmv_p);
1124  add_matrix(S, lm_u_num, u_num, Jlmu_u);
1125  add_matrix(S, lm_v_num, v_num, Jlmv_v);
1126  add_matrix(S, lm_u_num, lm_u_num, Jlmu_lmu);
1127  add_matrix(S, lm_v_num, lm_u_num, Jlmv_lmu);
1128  add_matrix(S, lm_u_num, lm_v_num, Jlmu_lmv);
1129  add_matrix(S, lm_v_num, lm_v_num, Jlmv_lmv);
1130  }
1131 
1132  J->close();
1133 }
1134 
1135 } // namespace libMesh
1136 
1137 #endif
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
void set_current_elem(const Elem &elem)
Set the current element.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:310
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
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
Access multiple components at once.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition: dof_map.C:2164
VectorValue< Real > RealVectorValue
Useful typedefs to allow transparent switching between Real and Complex data types.
std::unique_ptr< FEBase > lm_fe_face
Definition: hdg_problem.h:55
std::vector< Number > v_sol
Definition: hdg_problem.h:224
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:396
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i]...
std::vector< Number > p_sol
Definition: hdg_problem.h:226
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 BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:165
const std::vector< Real > * JxW_face
Definition: hdg_problem.h:209
virtual void zero()=0
Set all entries to zero.
const std::vector< Real > * JxW
Definition: hdg_problem.h:201
const VSoln v_true_soln
Definition: hdg_problem.h:72
unsigned int variable_number(std::string_view var) const
Definition: system.C:1609
const std::vector< std::vector< Real > > * div_vector_phi
Definition: hdg_problem.h:206
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
const std::vector< Point > * q_point
Definition: hdg_problem.h:202
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
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
std::size_t lm_n_dofs
Definition: hdg_problem.h:245
static const boundary_id_type invalid_id
Number used for internal use.
boundary_id_type top_bnd
Definition: hdg_problem.h:60
std::vector< Number > lm_u_sol
Definition: hdg_problem.h:222
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
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
libmesh_assert(ctx)
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
unsigned int n_points() const
Definition: quadrature.h:131
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
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:2598
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
Real forcing(const Point &p) const override
Definition: exact_soln.h:148
void vector_volume_jacobian(DenseMatrix< Number > &Jqq, DenseMatrix< Number > &Jqs)
Definition: hdg_problem.C:163
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
Definition: dense_matrix.h:895
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
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
void compute_qp_soln(std::vector< SolnType > &qp_vec, const unsigned int n_qps, const std::vector< std::vector< PhiType >> &phi, const std::vector< Number > &dof_values)
Definition: hdg_problem.C:36
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
const SparseMatrix< Number > & get_system_matrix() const
The QBase class provides the basic functionality from which various quadrature rules can be derived...
Definition: quadrature.h:61
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:117
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
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