libMesh/libmesh: coverage diff

Base 3f0912 Head #4573 924896
Total Total +/- New
Rate 66.73% 65.93% -0.80% 100.00%
Hits 81414 80046 -1368 1093
Misses 40585 41357 +772 0
Filename Stmts Miss Cover
include/base/getpot.h 0 +1 -0.11%
include/fe/fe_lagrange_n_dofs.h +84 +12 +85.71%
include/fe/fe_monomial_n_dofs.h +75 +30 +60.00%
include/fe/fe_simplex_lagrange.h +381 0 +100.00%
include/fe/fe_tensor_product_lagrange.h +496 0 +100.00%
include/geom/elem.h 0 +3 -0.69%
include/geom/elem_internal.h 0 +14 -6.39%
include/ghosting/ghosting_functor.h 0 +1 -6.25%
include/ghosting/overlap_coupling.h 0 +2 -33.33%
include/ghosting/point_neighbor_coupling.h 0 +2 -13.33%
include/mesh/replicated_mesh.h 0 +9 -13.24%
include/numerics/dense_matrix_impl.h 0 +1 -0.33%
include/numerics/petsc_vector.h 0 +3 -0.89%
include/parallel/parallel_ghost_sync.h 0 +3 -1.58%
include/reduced_basis/rb_scm_construction.h 0 +5 -83.33%
include/solvers/eigen_solver.h 0 +1 -5.56%
include/systems/eigen_system.h 0 +1 -20.00%
include/systems/generic_projector.h 0 +2 -0.17%
include/utils/mapvector.h 0 +1 -2.17%
src/fe/fe_lagrange.C -77 -21 +1.26%
src/fe/fe_lagrange_shape_2D.C -465 -64 -4.78%
src/fe/fe_lagrange_shape_3D.C -1019 -67 -0.84%
src/fe/fe_monomial.C -71 -33 +16.21%
src/geom/elem.C 0 +16 -1.01%
src/ghosting/ghost_point_neighbors.C 0 +9 -11.84%
src/mesh/boundary_info.C 0 +85 -5.05%
src/mesh/distributed_mesh.C 0 +32 -3.91%
src/mesh/exodusII_io_helper.C 0 +1 -0.04%
src/mesh/mesh_communication.C 0 +74 -9.65%
src/mesh/mesh_generation.C 0 +1 -0.07%
src/mesh/mesh_modification.C 0 +11 -1.47%
src/mesh/mesh_netgen_interface.C 0 +6 -2.74%
src/mesh/mesh_refinement.C 0 +20 -2.81%
src/mesh/mesh_tet_interface.C 0 +13 -3.94%
src/mesh/nemesis_io_helper.C 0 +1 -0.08%
src/mesh/simplex_refiner.C 0 +71 -26.89%
src/mesh/unstructured_mesh.C 0 +7 -0.68%
src/numerics/dense_matrix_blas_lapack.C 0 +4 -1.82%
src/numerics/petsc_matrix.C 0 +1 -0.25%
src/numerics/petsc_preconditioner.C 0 +1 -0.45%
src/numerics/petsc_vector.C 0 +6 -1.29%
src/parallel/parallel_elem.C 0 +1 -0.25%
src/partitioning/linear_partitioner.C 0 +1 -2.56%
src/partitioning/metis_partitioner.C 0 +1 -0.72%
src/partitioning/parmetis_partitioner.C 0 +1 -0.61%
src/partitioning/partitioner.C 0 +38 -5.72%
src/reduced_basis/rb_construction.C 0 +11 -0.88%
src/reduced_basis/rb_construction_base.C 0 +14 -4.76%
src/reduced_basis/rb_scm_construction.C 0 +152 -68.47%
src/reduced_basis/rb_scm_evaluation.C 0 +192 -83.84%
src/solvers/petsc_linear_solver.C 0 +2 -0.63%
src/solvers/slepc_eigen_solver.C 0 +6 -2.24%
src/solvers/tao_optimization_solver.C 0 +65 -28.89%
src/systems/condensed_eigen_system.C 0 +1 -0.66%
src/systems/fem_context.C 0 +3 -0.37%
src/systems/optimization_system.C 0 +18 -26.09%
src/utils/point_locator_tree.C 0 +1 -0.81%
TOTAL -596 +772 -0.80%
code
coverage unchanged
code
coverage increased
code
coverage decreased
+
line added or modified

include/base/getpot.h

2322  
2323  
2324  
2325  
2326  
2327  
2328  
  // (*) recording of requested variables happens in '_request_variable()'
  const variable* sv = _request_variable(VarName);
  if (sv == 0)
    return Default;

  const std::string*  element = sv->get_element(Idx);
  if (element == 0)

include/fe/fe_lagrange_n_dofs.h

42  
43  
44  
45 +
46  
47 +
48  
49  
50 +
51  
52 +
53  
54 +
55 +
56  
57 +
58 +
59  
60  
61  
62  
63 +
64  
65 +
66  
67 +
68 +
69  
70 +
71  
72  
73 +
74  
75 +
76  
77  
78  
79  
80 +
81  
82 +
83  
84  
85  
86  
87  
88 +
89  
90 +
91  
92  
93 +
94  
95 +
96  
97  
98 +
99  
100 +
101  
102  
103  
104  
105 +
106  
107 +
108  
109  
110  
111 +
112  
113 +
114 +
115  
116 +
117  
118  
119  
120 +
121  
122 +
123 +
124  
125  
126  
127  
128  
129 +
130  
131 +
132  
133 +
134 +
135  
136 +
137 +
138  
139 +
140  
141 +
142  
143 +
144  
145 +
146  
147 +
148  
149 +
150  
151 +
152  
153 +
154  
155 +
156 +
157  
158 +
159 +
160  
161 +
162 +
163  
164 +
165  
166  
167 +
168  
169 +
170 +
171  
172 +
173  
174 +
175  
176 +
177 +
178  
179 +
180 +
181  
182  
183  
184 +
185  
186 +
187  
188 +
189 +
190  
191 +
192 +
193  
194 +
195 +
196  
197 +
198 +
199  
200 +
201 +
202  
203 +
204 +
205  
206 +
207 +
208  
209 +
210 +
211  
212 +
213 +
214  
215  
216  
217 +
218 +
219  
220  
221  
 * numbers from the same place.
 */
LIBMESH_DEVICE_INLINE constexpr unsigned int
lagrange_n_dofs (const ElemType t, const Order o)
{
  switch (o)
    {
      // lagrange can only be constant on a single node
    case CONSTANT:
      {
        switch (t)
          {
          case NODEELEM:
            return 1;

          default:
            return invalid_uint;
          }
      }

      // linear Lagrange shape functions
    case FIRST:
      {
        switch (t)
          {
          case NODEELEM:
            return 1;

          case EDGE2:
          case EDGE3:
          case EDGE4:
            return 2;

          case TRI3:
          case TRISHELL3:
          case TRI3SUBDIVISION:
          case TRI6:
          case TRI7:
            return 3;

          case QUAD4:
          case QUADSHELL4:
          case QUAD8:
          case QUADSHELL8:
          case QUAD9:
          case QUADSHELL9:
            return 4;

          case TET4:
          case TET10:
          case TET14:
            return 4;

          case HEX8:
          case HEX20:
          case HEX27:
            return 8;

          case PRISM6:
          case PRISM15:
          case PRISM18:
          case PRISM20:
          case PRISM21:
            return 6;

          case PYRAMID5:
          case PYRAMID13:
          case PYRAMID14:
          case PYRAMID18:
            return 5;

          case INVALID_ELEM:
            return 0;

          case C0POLYGON:
          case C0POLYHEDRON:
            // A polytope's dof count follows from its node count, which
            // its element type does not fix
            return invalid_uint;

          default:
            return invalid_uint;
          }
      }


      // quadratic Lagrange shape functions
    case SECOND:
      {
        switch (t)
          {
          case NODEELEM:
            return 1;

          case EDGE3:
            return 3;

          case TRI6:
          case TRI7:
            return 6;

          case QUAD8:
          case QUADSHELL8:
            return 8;

          case QUAD9:
          case QUADSHELL9:
            return 9;

          case TET10:
          case TET14:
            return 10;

          case HEX20:
            return 20;

          case HEX27:
            return 27;

          case PRISM15:
            return 15;

          case PRISM18:
          case PRISM20:
          case PRISM21:
            return 18;

          case PYRAMID13:
            return 13;

          case PYRAMID14:
          case PYRAMID18:
            return 14;

          case INVALID_ELEM:
            return 0;

          default:
            return invalid_uint;
          }
      }

    case THIRD:
      {
        switch (t)
          {
          case NODEELEM:
            return 1;

          case EDGE4:
            return 4;

          case PRISM20:
            return 20;

          case PRISM21:
            return 21;

          case PYRAMID18:
            return 18;

          case TRI7:
            return 7;

          case TET14:
            return 14;

          case INVALID_ELEM:
            return 0;

          default:
            return invalid_uint;
          }
      }

    default:
      return invalid_uint;
    }
}

include/fe/fe_monomial_n_dofs.h

45  
46  
47  
48 +
49  
50 +
51  
52  
53  
54  
55 +
56 +
57  
58  
59  
60  
61 +
62  
63 +
64  
65 +
66 +
67  
68 +
69  
70  
71 +
72  
73 +
74  
75  
76  
 * in its own right, so what is here is the same switch, moved.
 */
LIBMESH_DEVICE_INLINE constexpr unsigned int
monomial_n_dofs (const ElemType t, const Order o)
{
  switch (o)
    {

      // constant shape functions
      // no matter what shape there is only one DOF.
    case CONSTANT:
      return (t != INVALID_ELEM) ? 1 : 0;


      // Discontinuous linear shape functions
      // expressed in the monomials.
    case FIRST:
      {
        switch (t)
          {
          case NODEELEM:
            return 1;

          case EDGE2:
          case EDGE3:
          case EDGE4:
            return 2;

          case C0POLYGON:
          case TRI3:
          case TRISHELL3:
          case TRI6:
81  
82  
83  
84 +
85  
86 +
87  
88  
89  
          case QUADSHELL8:
          case QUAD9:
          case QUADSHELL9:
            return 3;

          case TET4:
          case TET10:
          case TET14:
          case HEX8:
99  
100  
101  
102 +
103  
104 +
105 +
106  
107 +
108 +
109  
110  
111  
112  
113  
114  
115 +
116  
117 +
118  
119 +
120 +
121  
122 +
123  
124  
125 +
126  
127 +
128  
129  
130  
          case PYRAMID14:
          case PYRAMID18:
          case C0POLYHEDRON:
            return 4;

          case INVALID_ELEM:
            return 0;

          default:
            return invalid_uint;
          }
      }


      // Discontinuous quadratic shape functions
      // expressed in the monomials.
    case SECOND:
      {
        switch (t)
          {
          case NODEELEM:
            return 1;

          case EDGE2:
          case EDGE3:
          case EDGE4:
            return 3;

          case C0POLYGON:
          case TRI3:
          case TRISHELL3:
          case TRI6:
135  
136  
137  
138 +
139  
140 +
141  
142  
143  
          case QUADSHELL8:
          case QUAD9:
          case QUADSHELL9:
            return 6;

          case TET4:
          case TET10:
          case TET14:
          case HEX8:
153  
154  
155  
156 +
157  
158 +
159 +
160  
161 +
162 +
163  
164  
165  
166  
167  
168  
169 +
170  
171 +
172  
173 +
174 +
175  
176 +
177  
178  
179 +
180  
181 +
182  
183  
184  
          case PYRAMID14:
          case PYRAMID18:
          case C0POLYHEDRON:
            return 10;

          case INVALID_ELEM:
            return 0;

          default:
            return invalid_uint;
          }
      }


      // Discontinuous cubic shape functions
      // expressed in the monomials.
    case THIRD:
      {
        switch (t)
          {
          case NODEELEM:
            return 1;

          case EDGE2:
          case EDGE3:
          case EDGE4:
            return 4;

          case C0POLYGON:
          case TRI3:
          case TRISHELL3:
          case TRI6:
189  
190  
191  
192 +
193  
194 +
195  
196  
197  
          case QUADSHELL8:
          case QUAD9:
          case QUADSHELL9:
            return 10;

          case TET4:
          case TET10:
          case TET14:
          case HEX8:
207  
208  
209  
210 +
211  
212 +
213 +
214  
215 +
216 +
217  
218  
219  
220  
221  
222  
223 +
224  
225 +
226  
227 +
228 +
229  
230 +
231  
232 +
233  
234 +
235  
236  
237  
          case PYRAMID14:
          case PYRAMID18:
          case C0POLYHEDRON:
            return 20;

          case INVALID_ELEM:
            return 0;

          default:
            return invalid_uint;
          }
      }


      // Discontinuous quartic shape functions
      // expressed in the monomials.
    case FOURTH:
      {
        switch (t)
          {
          case NODEELEM:
            return 1;

          case EDGE2:
          case EDGE3:
            return 5;

          case C0POLYGON:
          case TRI3:
          case TRISHELL3:
          case TRI6:
242  
243  
244  
245 +
246  
247 +
248  
249  
250  
          case QUADSHELL8:
          case QUAD9:
          case QUADSHELL9:
            return 15;

          case TET4:
          case TET10:
          case TET14:
          case HEX8:
259  
260  
261  
262 +
263  
264 +
265 +
266  
267 +
268 +
269  
270  
271  
272  
273 +
274  
275 +
276 +
277  
278 +
279 +
280  
281 +
282  
283 +
284  
285 +
286  
287  
288  
          case PYRAMID13:
          case PYRAMID14:
          case C0POLYHEDRON:
            return 35;

          case INVALID_ELEM:
            return 0;

          default:
            return invalid_uint;
          }
      }


    default:
      {
        const unsigned int order = static_cast<unsigned int>(o);
        switch (t)
          {
          case NODEELEM:
            return 1;

          case EDGE2:
          case EDGE3:
            return (order+1);

          case C0POLYGON:
          case TRI3:
          case TRISHELL3:
          case TRI6:
293  
294  
295  
296 +
297  
298 +
299  
300  
301  
          case QUADSHELL8:
          case QUAD9:
          case QUADSHELL9:
            return (order+1)*(order+2)/2;

          case TET4:
          case TET10:
          case TET14:
          case HEX8:
310  
311  
312  
313 +
314  
315 +
316 +
317  
318 +
319 +
320  
321  
322  
          case PYRAMID13:
          case PYRAMID14:
          case C0POLYHEDRON:
            return (order+1)*(order+2)*(order+3)/6;

          case INVALID_ELEM:
            return 0;

          default:
            return invalid_uint;
          }
      }
    }

include/fe/fe_simplex_lagrange.h

49  
50  
51  
52 +
53  
54  
55 +
56 +
57  
58 +
59  
60 +
61 +
62 +
63 +
64 +
65 +
66  
67  
68  
 * coordinates are affine in xi and eta.
 */
LIBMESH_DEVICE_INLINE
Real tri_dzeta(const unsigned int i,
               const unsigned int j)
{
  libmesh_assert_less(i, 3);
  libmesh_assert_less(j, 2);

  switch (i)
    {
    case 0:
      return -1.;
    case 1:
      return j == 0 ? 1. : 0.;
    default:
      return j == 0 ? 0. : 1.;
    }
}

72  
73  
74  
75 +
76  
77  
78 +
79 +
80  
81 +
82  
83 +
84 +
85 +
86 +
87 +
88 +
89  
90  
91  
92  
93 +
94  
95  
96 +
97 +
98  
99 +
100  
101 +
102 +
103 +
104 +
105 +
106 +
107 +
108 +
109  
110  
111  
112  
113 +
114  
115  
116 +
117 +
118  
119 +
120  
121 +
122 +
123 +
124 +
125 +
126 +
127 +
128 +
129 +
130 +
131  
132  
133  
134  
135  
136 +
137  
138  
139 +
140 +
141  
142 +
143  
144 +
145 +
146 +
147 +
148 +
149 +
150  
151  
152  
 * mid-edge shape the two coordinates of the vertices it lies between.
 */
LIBMESH_DEVICE_INLINE
unsigned short tri6_zeta_index(const unsigned int i,
                               const unsigned int j)
{
  libmesh_assert_less(i, 6);
  libmesh_assert_less(j, 2);

  switch (i)
    {
    case 0: return 0;
    case 1: return 1;
    case 2: return 2;
    case 3: return j == 0 ? 0 : 1;
    case 4: return j == 0 ? 1 : 2;
    default: return j == 0 ? 2 : 0;
    }
}

LIBMESH_DEVICE_INLINE
Real tet_dzeta(const unsigned int i,
               const unsigned int j)
{
  libmesh_assert_less(i, 4);
  libmesh_assert_less(j, 3);

  switch (i)
    {
    case 0:
      return -1.;
    case 1:
      return j == 0 ? 1. : 0.;
    case 2:
      return j == 1 ? 1. : 0.;
    default:
      return j == 2 ? 1. : 0.;
    }
}

LIBMESH_DEVICE_INLINE
unsigned short tet10_zeta_index(const unsigned int i,
                                const unsigned int j)
{
  libmesh_assert_less(i, 10);
  libmesh_assert_less(j, 2);

  switch (i)
    {
    case 0: return 0;
    case 1: return 1;
    case 2: return 2;
    case 3: return 3;
    case 4: return j == 0 ? 0 : 1;
    case 5: return j == 0 ? 1 : 2;
    case 6: return j == 0 ? 2 : 0;
    case 7: return j == 0 ? 0 : 3;
    case 8: return j == 0 ? 1 : 3;
    default: return j == 0 ? 2 : 3;
    }
}

#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
LIBMESH_DEVICE_INLINE
unsigned short tet_second_deriv_index(const unsigned int i,
                                      const unsigned int j)
{
  libmesh_assert_less(i, 6);
  libmesh_assert_less(j, 2);

  switch (i)
    {
    case 0: return 0;
    case 1: return static_cast<unsigned short>(j);
    case 2: return 1;
    case 3: return j == 0 ? 0 : 2;
    case 4: return j == 0 ? 1 : 2;
    default: return 2;
    }
}
#endif
156  
157  
158  
159 +
160  
161  
162  
163 +
164  
165 +
166  
167 +
168 +
169 +
170  
171  
172  
173  
174 +
175  
176  
177 +
178 +
179  
180 +
181  
182  
183  
 * The linear triangle's shape functions are its barycentric
 * coordinates.
 */
Real fe_lagrange_tri3_shape(const unsigned int i,
                            const Real xi,
                            const Real eta)
{
  libmesh_assert_less(i, 3);

  switch (i)
    {
    case 0: return 1. - xi - eta;
    case 1: return xi;
    default: return eta;
    }
}

LIBMESH_DEVICE_INLINE
Real fe_lagrange_tri3_shape_deriv(const unsigned int i,
                                  const unsigned int j)
{
  libmesh_assert_less(i, 3);
  libmesh_assert_less(j, 2);

  return tri_dzeta(i, j);
}

LIBMESH_DEVICE_INLINE
186  
187  
188  
189 +
190  
191  
192  
193 +
194  
195 +
196 +
197 +
198  
199 +
200 +
201  
202 +
203  
204  
205  
206 +
207  
208  
209  
210  
211 +
212 +
213  
214 +
215 +
216 +
217  
218 +
219 +
220  
221 +
222  
223  
224  
 * 4*zeta_a*zeta_b at the node between vertices a and b, which
 * tri6_zeta_index() names.
 */
Real fe_lagrange_tri6_shape(const unsigned int i,
                            const Real xi,
                            const Real eta)
{
  libmesh_assert_less(i, 6);

  const Real bary[3] = {1. - xi - eta, xi, eta};
  const unsigned short m = tri6_zeta_index(i, 0);
  const unsigned short n = tri6_zeta_index(i, 1);

  if (i < 3)
    return bary[m] * (2. * bary[m] - 1.);

  return 4. * bary[m] * bary[n];
}

LIBMESH_DEVICE_INLINE
Real fe_lagrange_tri6_shape_deriv(const unsigned int i,
                                  const unsigned int j,
                                  const Real xi,
                                  const Real eta)
{
  libmesh_assert_less(i, 6);
  libmesh_assert_less(j, 2);

  const Real bary[3] = {1. - xi - eta, xi, eta};
  const unsigned short m = tri6_zeta_index(i, 0);
  const unsigned short n = tri6_zeta_index(i, 1);

  if (i < 3)
    return (4. * bary[m] - 1.) * tri_dzeta(m, j);

  return 4. * bary[n] * tri_dzeta(m, j) + 4. * bary[m] * tri_dzeta(n, j);
}

LIBMESH_DEVICE_INLINE
230  
231  
232  
233 +
234  
235  
236  
237 +
238  
239 +
240 +
241 +
242 +
243  
244 +
245  
246 +
247 +
248 +
249 +
250 +
251 +
252 +
253  
254  
255  
 * the arithmetic, and so the rounding, is the same as the .C file this
 * came from.
 */
Real fe_lagrange_tri7_shape(const unsigned int i,
                            const Real xi,
                            const Real eta)
{
  libmesh_assert_less(i, 7);

  const Real zeta1 = xi;
  const Real zeta2 = eta;
  const Real zeta0 = 1. - zeta1 - zeta2;
  const Real bubble_27th = zeta0*zeta1*zeta2;

  switch (i)
    {
    case 0: return 2.*zeta0*(zeta0-0.5) + 3.*bubble_27th;
    case 1: return 2.*zeta1*(zeta1-0.5) + 3.*bubble_27th;
    case 2: return 2.*zeta2*(zeta2-0.5) + 3.*bubble_27th;
    case 3: return 4.*zeta0*zeta1 - 12.*bubble_27th;
    case 4: return 4.*zeta1*zeta2 - 12.*bubble_27th;
    case 5: return 4.*zeta2*zeta0 - 12.*bubble_27th;
    default: return 27.*bubble_27th;
    }
}

259  
260  
261  
262 +
263  
264  
265  
266  
267 +
268 +
269  
270 +
271 +
272 +
273  
274 +
275 +
276 +
277 +
278  
279 +
280 +
281 +
282 +
283  
284 +
285 +
286  
287 +
288 +
289 +
290 +
291 +
292 +
293 +
294  
295  
296 +
297  
298 +
299 +
300 +
301 +
302 +
303 +
304 +
305  
306  
307  
308  
309  
310 +
311  
312  
313 +
314 +
315  
316 +
317 +
318  
319 +
320 +
321  
322 +
323 +
324  
325 +
326 +
327  
328  
329  
 * eta, zeta_1 = xi, zeta_2 = eta collapses the product rule to one term
 * per direction.
 */
Real fe_lagrange_tri7_shape_deriv(const unsigned int i,
                                  const unsigned int j,
                                  const Real xi,
                                  const Real eta)
{
  libmesh_assert_less(i, 7);
  libmesh_assert_less(j, 2);

  const Real zeta1 = xi;
  const Real zeta2 = eta;
  const Real zeta0 = 1. - zeta1 - zeta2;

  const Real dzeta0dxi  = -1.;
  const Real dzeta1dxi  = 1.;
  const Real dzeta2dxi  = 0.;
  const Real dbubbledxi = zeta2 * (1. - 2.*zeta1 - zeta2);

  const Real dzeta0deta = -1.;
  const Real dzeta1deta = 0.;
  const Real dzeta2deta = 1.;
  const Real dbubbledeta= zeta1 * (1. - zeta1 - 2.*zeta2);

  if (j == 0)
    switch (i)
      {
      case 0: return (4.*zeta0-1.)*dzeta0dxi + 3.*dbubbledxi;
      case 1: return (4.*zeta1-1.)*dzeta1dxi + 3.*dbubbledxi;
      case 2: return (4.*zeta2-1.)*dzeta2dxi + 3.*dbubbledxi;
      case 3: return 4.*zeta1*dzeta0dxi + 4.*zeta0*dzeta1dxi - 12.*dbubbledxi;
      case 4: return 4.*zeta2*dzeta1dxi + 4.*zeta1*dzeta2dxi - 12.*dbubbledxi;
      case 5: return 4.*zeta2*dzeta0dxi + 4*zeta0*dzeta2dxi - 12.*dbubbledxi;
      default: return 27.*dbubbledxi;
      }

  switch (i)
    {
    case 0: return (4.*zeta0-1.)*dzeta0deta + 3.*dbubbledeta;
    case 1: return (4.*zeta1-1.)*dzeta1deta + 3.*dbubbledeta;
    case 2: return (4.*zeta2-1.)*dzeta2deta + 3.*dbubbledeta;
    case 3: return 4.*zeta1*dzeta0deta + 4.*zeta0*dzeta1deta - 12.*dbubbledeta;
    case 4: return 4.*zeta2*dzeta1deta + 4.*zeta1*dzeta2deta - 12.*dbubbledeta;
    case 5: return 4.*zeta2*dzeta0deta + 4*zeta0*dzeta2deta - 12.*dbubbledeta;
    default: return 27.*dbubbledeta;
    }
}

#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
LIBMESH_DEVICE_INLINE
Real fe_lagrange_tri6_shape_second_deriv(const unsigned int i,
                                         const unsigned int j)
{
  libmesh_assert_less(i, 6);
  libmesh_assert_less(j, 3);

  const unsigned short my_j = j == 2 ? 1 : 0;
  const unsigned short my_k = j == 0 ? 0 : 1;

  if (i < 3)
    return 4. * tri_dzeta(i, my_j) * tri_dzeta(i, my_k);

  const unsigned short m = tri6_zeta_index(i, 0);
  const unsigned short n = tri6_zeta_index(i, 1);

  return 4. * (tri_dzeta(n, my_j) * tri_dzeta(m, my_k) +
               tri_dzeta(m, my_j) * tri_dzeta(n, my_k));
}

LIBMESH_DEVICE_INLINE
333  
334  
335  
336 +
337  
338  
339  
340  
341 +
342 +
343  
344 +
345 +
346  
347 +
348 +
349 +
350 +
351  
352 +
353 +
354 +
355 +
356  
357 +
358  
359 +
360 +
361  
362 +
363 +
364 +
365 +
366 +
367 +
368 +
369  
370  
371 +
372 +
373  
374 +
375 +
376 +
377 +
378 +
379 +
380 +
381  
382  
383 +
384  
385 +
386 +
387 +
388 +
389 +
390 +
391 +
392  
393  
394  
 * 2*eta mixed.  The Tri6 halves are constants, since a quadratic's
 * second derivative does not depend on the point.
 */
Real fe_lagrange_tri7_shape_second_deriv(const unsigned int i,
                                         const unsigned int j,
                                         const Real xi,
                                         const Real eta)
{
  libmesh_assert_less(i, 7);
  libmesh_assert_less(j, 3);

  const Real zeta1 = xi;
  const Real zeta2 = eta;

  const Real dzeta0dxi  = -1.;
  const Real dzeta1dxi  = 1.;
  const Real dzeta2dxi  = 0.;
  const Real d2bubbledxi2 = -2. * zeta2;

  const Real dzeta0deta = -1.;
  const Real dzeta1deta = 0.;
  const Real dzeta2deta = 1.;
  const Real d2bubbledeta2 = -2. * zeta1;

  const Real d2bubbledxideta = (1. - 2.*zeta1 - 2.*zeta2);

  if (j == 0)
    switch (i)
      {
      case 0: return 4.*dzeta0dxi*dzeta0dxi + 3.*d2bubbledxi2;
      case 1: return 4.*dzeta1dxi*dzeta1dxi + 3.*d2bubbledxi2;
      case 2: return 4.*dzeta2dxi*dzeta2dxi + 3.*d2bubbledxi2;
      case 3: return 8.*dzeta0dxi*dzeta1dxi - 12.*d2bubbledxi2;
      case 4: return 8.*dzeta1dxi*dzeta2dxi - 12.*d2bubbledxi2;
      case 5: return 8.*dzeta0dxi*dzeta2dxi - 12.*d2bubbledxi2;
      default: return 27.*d2bubbledxi2;
      }

  if (j == 1)
    switch (i)
      {
      case 0: return 4.*dzeta0dxi*dzeta0deta + 3.*d2bubbledxideta;
      case 1: return 4.*dzeta1dxi*dzeta1deta + 3.*d2bubbledxideta;
      case 2: return 4.*dzeta2dxi*dzeta2deta + 3.*d2bubbledxideta;
      case 3: return 4.*dzeta1deta*dzeta0dxi + 4.*dzeta0deta*dzeta1dxi - 12.*d2bubbledxideta;
      case 4: return 4.*dzeta2deta*dzeta1dxi + 4.*dzeta1deta*dzeta2dxi - 12.*d2bubbledxideta;
      case 5: return 4.*dzeta2deta*dzeta0dxi + 4.*dzeta0deta*dzeta2dxi - 12.*d2bubbledxideta;
      default: return 27.*d2bubbledxideta;
      }

  switch (i)
    {
    case 0: return 4.*dzeta0deta*dzeta0deta + 3.*d2bubbledeta2;
    case 1: return 4.*dzeta1deta*dzeta1deta + 3.*d2bubbledeta2;
    case 2: return 4.*dzeta2deta*dzeta2deta + 3.*d2bubbledeta2;
    case 3: return 8.*dzeta0deta*dzeta1deta - 12.*d2bubbledeta2;
    case 4: return 8.*dzeta1deta*dzeta2deta - 12.*d2bubbledeta2;
    case 5: return 8.*dzeta0deta*dzeta2deta - 12.*d2bubbledeta2;
    default: return 27.*d2bubbledeta2;
    }
}

399  
400  
401  
402 +
403  
404  
405  
406  
407 +
408  
409 +
410  
411 +
412 +
413 +
414 +
415  
416  
417  
418  
419 +
420  
421  
422 +
423 +
424  
425 +
426  
427  
428  
 * The linear tet's shape functions are its barycentric coordinates,
 * as for the triangle.
 */
Real fe_lagrange_tet4_shape(const unsigned int i,
                            const Real xi,
                            const Real eta,
                            const Real zeta)
{
  libmesh_assert_less(i, 4);

  switch (i)
    {
    case 0: return 1. - xi - eta - zeta;
    case 1: return xi;
    case 2: return eta;
    default: return zeta;
    }
}

LIBMESH_DEVICE_INLINE
Real fe_lagrange_tet4_shape_deriv(const unsigned int i,
                                  const unsigned int j)
{
  libmesh_assert_less(i, 4);
  libmesh_assert_less(j, 3);

  return tet_dzeta(i, j);
}

LIBMESH_DEVICE_INLINE
430  
431  
432  
433 +
434  
435  
436  
437  
438 +
439  
440 +
441 +
442 +
443  
444 +
445 +
446  
447 +
448  
449  
450  
451 +
452  
453  
454  
455  
456  
457 +
458 +
459  
460 +
461 +
462 +
463  
464 +
465 +
466  
467 +
468  
469  
470  
 * Quadratic on the tet, in the same two forms as Tri6:
 * zeta*(2*zeta - 1) at a vertex and 4*zeta_a*zeta_b at a mid-edge node.
 */
Real fe_lagrange_tet10_shape(const unsigned int i,
                             const Real xi,
                             const Real eta,
                             const Real zeta)
{
  libmesh_assert_less(i, 10);

  const Real bary[4] = {1. - xi - eta - zeta, xi, eta, zeta};
  const unsigned short m = tet10_zeta_index(i, 0);
  const unsigned short n = tet10_zeta_index(i, 1);

  if (i < 4)
    return bary[m] * (2. * bary[m] - 1.);

  return 4. * bary[m] * bary[n];
}

LIBMESH_DEVICE_INLINE
Real fe_lagrange_tet10_shape_deriv(const unsigned int i,
                                   const unsigned int j,
                                   const Real xi,
                                   const Real eta,
                                   const Real zeta)
{
  libmesh_assert_less(i, 10);
  libmesh_assert_less(j, 3);

  const Real bary[4] = {1. - xi - eta - zeta, xi, eta, zeta};
  const unsigned short m = tet10_zeta_index(i, 0);
  const unsigned short n = tet10_zeta_index(i, 1);

  if (i < 4)
    return (4. * bary[m] - 1.) * tet_dzeta(m, j);

  return 4. * bary[n] * tet_dzeta(m, j) + 4. * bary[m] * tet_dzeta(n, j);
}

LIBMESH_DEVICE_INLINE
477  
478  
479  
480 +
481  
482  
483  
484  
485 +
486  
487  
488 +
489 +
490 +
491 +
492  
493  
494 +
495 +
496 +
497 +
498  
499 +
500  
501 +
502 +
503 +
504 +
505 +
506 +
507 +
508 +
509 +
510 +
511 +
512 +
513 +
514 +
515  
516  
517  
 * fe_lagrange_tet10_shape() so that the arithmetic, and so the rounding,
 * is the same as the .C file this came from.
 */
Real fe_lagrange_tet14_shape(const unsigned int i,
                             const Real xi,
                             const Real eta,
                             const Real zeta)
{
  libmesh_assert_less(i, 14);

  // Area coordinates, pg. 205, Vol. I, Carey, Oden, Becker FEM
  const Real zeta1 = xi;
  const Real zeta2 = eta;
  const Real zeta3 = zeta;
  const Real zeta0 = 1. - zeta1 - zeta2 - zeta3;

  // Bubble functions (not yet scaled) on side nodes
  const Real bubble_012 = zeta0*zeta1*zeta2;
  const Real bubble_013 = zeta0*zeta1*zeta3;
  const Real bubble_123 = zeta1*zeta2*zeta3;
  const Real bubble_023 = zeta0*zeta2*zeta3;

  switch (i)
    {
    case 0: return zeta0*(2.*zeta0 - 1.) + 3.*(bubble_012+bubble_013+bubble_023);
    case 1: return zeta1*(2.*zeta1 - 1.) + 3.*(bubble_012+bubble_013+bubble_123);
    case 2: return zeta2*(2.*zeta2 - 1.) + 3.*(bubble_012+bubble_023+bubble_123);
    case 3: return zeta3*(2.*zeta3 - 1.) + 3.*(bubble_013+bubble_023+bubble_123);
    case 4: return 4.*zeta0*zeta1 - 12.*(bubble_012+bubble_013);
    case 5: return 4.*zeta1*zeta2 - 12.*(bubble_012+bubble_123);
    case 6: return 4.*zeta2*zeta0 - 12.*(bubble_012+bubble_023);
    case 7: return 4.*zeta0*zeta3 - 12.*(bubble_013+bubble_023);
    case 8: return 4.*zeta1*zeta3 - 12.*(bubble_013+bubble_123);
    case 9: return 4.*zeta2*zeta3 - 12.*(bubble_023+bubble_123);
    case 10: return 27.*bubble_012;
    case 11: return 27.*bubble_013;
    case 12: return 27.*bubble_123;
    default: return 27.*bubble_023;
    }
}

523  
524  
525  
526 +
527  
528  
529  
530  
531  
532 +
533 +
534  
535 +
536 +
537 +
538 +
539  
540 +
541 +
542 +
543 +
544 +
545 +
546 +
547 +
548  
549 +
550 +
551 +
552 +
553 +
554 +
555 +
556 +
557  
558 +
559 +
560 +
561 +
562 +
563 +
564 +
565 +
566  
567 +
568 +
569  
570 +
571 +
572 +
573 +
574 +
575 +
576 +
577 +
578 +
579 +
580 +
581 +
582 +
583 +
584  
585  
586 +
587 +
588  
589 +
590 +
591 +
592 +
593 +
594 +
595 +
596 +
597 +
598 +
599 +
600 +
601 +
602 +
603  
604  
605 +
606  
607 +
608 +
609 +
610 +
611 +
612 +
613 +
614 +
615 +
616 +
617 +
618 +
619 +
620 +
621  
622  
623  
624  
625  
626 +
627  
628  
629 +
630 +
631  
632 +
633 +
634  
635 +
636 +
637  
638 +
639 +
640  
641 +
642 +
643  
644  
645  
 * vertex loses a factor outright while the faces containing it pick up
 * the difference of the two coordinates that vary.
 */
Real fe_lagrange_tet14_shape_deriv(const unsigned int i,
                                   const unsigned int j,
                                   const Real xi,
                                   const Real eta,
                                   const Real zeta)
{
  libmesh_assert_less(i, 14);
  libmesh_assert_less(j, 3);

  const Real zeta1 = xi;
  const Real zeta2 = eta;
  const Real zeta3 = zeta;
  const Real zeta0 = 1. - zeta1 - zeta2 - zeta3;

  const Real dzeta0dxi = -1.;
  const Real dzeta1dxi =  1.;
  const Real dzeta2dxi =  0.;
  const Real dzeta3dxi =  0.;
  const Real dbubble012dxi = (zeta0-zeta1)*zeta2;
  const Real dbubble013dxi = (zeta0-zeta1)*zeta3;
  const Real dbubble123dxi = zeta2*zeta3;
  const Real dbubble023dxi = -zeta2*zeta3;

  const Real dzeta0deta = -1.;
  const Real dzeta1deta =  0.;
  const Real dzeta2deta =  1.;
  const Real dzeta3deta =  0.;
  const Real dbubble012deta = (zeta0-zeta2)*zeta1;
  const Real dbubble013deta = -zeta1*zeta3;
  const Real dbubble123deta = zeta1*zeta3;
  const Real dbubble023deta = (zeta0-zeta2)*zeta3;

  const Real dzeta0dzeta = -1.;
  const Real dzeta1dzeta =  0.;
  const Real dzeta2dzeta =  0.;
  const Real dzeta3dzeta =  1.;
  const Real dbubble012dzeta = -zeta1*zeta2;
  const Real dbubble013dzeta = (zeta0-zeta3)*zeta1;
  const Real dbubble123dzeta = zeta1*zeta2;
  const Real dbubble023dzeta = (zeta0-zeta3)*zeta2;

  if (j == 0)
    switch (i)
      {
        case 0: return (4.*zeta0 - 1.)*dzeta0dxi + 3.*(dbubble012dxi+dbubble013dxi+dbubble023dxi);
        case 1: return (4.*zeta1 - 1.)*dzeta1dxi + 3.*(dbubble012dxi+dbubble013dxi+dbubble123dxi);
        case 2: return (4.*zeta2 - 1.)*dzeta2dxi + 3.*(dbubble012dxi+dbubble023dxi+dbubble123dxi);
        case 3: return (4.*zeta3 - 1.)*dzeta3dxi + 3.*(dbubble013dxi+dbubble023dxi+dbubble123dxi);
        case 4: return 4.*(zeta0*dzeta1dxi + dzeta0dxi*zeta1) - 12.*(dbubble012dxi+dbubble013dxi);
        case 5: return 4.*(zeta1*dzeta2dxi + dzeta1dxi*zeta2) - 12.*(dbubble012dxi+dbubble123dxi);
        case 6: return 4.*(zeta0*dzeta2dxi + dzeta0dxi*zeta2) - 12.*(dbubble012dxi+dbubble023dxi);
        case 7: return 4.*(zeta0*dzeta3dxi + dzeta0dxi*zeta3) - 12.*(dbubble013dxi+dbubble023dxi);
        case 8: return 4.*(zeta1*dzeta3dxi + dzeta1dxi*zeta3) - 12.*(dbubble013dxi+dbubble123dxi);
        case 9: return 4.*(zeta2*dzeta3dxi + dzeta2dxi*zeta3) - 12.*(dbubble023dxi+dbubble123dxi);
        case 10: return 27.*dbubble012dxi;
        case 11: return 27.*dbubble013dxi;
        case 12: return 27.*dbubble123dxi;
        default: return 27.*dbubble023dxi;
      }

  if (j == 1)
    switch (i)
      {
        case 0: return (4.*zeta0 - 1.)*dzeta0deta + 3.*(dbubble012deta+dbubble013deta+dbubble023deta);
        case 1: return (4.*zeta1 - 1.)*dzeta1deta + 3.*(dbubble012deta+dbubble013deta+dbubble123deta);
        case 2: return (4.*zeta2 - 1.)*dzeta2deta + 3.*(dbubble012deta+dbubble023deta+dbubble123deta);
        case 3: return (4.*zeta3 - 1.)*dzeta3deta + 3.*(dbubble013deta+dbubble023deta+dbubble123deta);
        case 4: return 4.*(zeta0*dzeta1deta + dzeta0deta*zeta1) - 12.*(dbubble012deta+dbubble013deta);
        case 5: return 4.*(zeta1*dzeta2deta + dzeta1deta*zeta2) - 12.*(dbubble012deta+dbubble123deta);
        case 6: return 4.*(zeta0*dzeta2deta + dzeta0deta*zeta2) - 12.*(dbubble012deta+dbubble023deta);
        case 7: return 4.*(zeta0*dzeta3deta + dzeta0deta*zeta3) - 12.*(dbubble013deta+dbubble023deta);
        case 8: return 4.*(zeta1*dzeta3deta + dzeta1deta*zeta3) - 12.*(dbubble013deta+dbubble123deta);
        case 9: return 4.*(zeta2*dzeta3deta + dzeta2deta*zeta3) - 12.*(dbubble023deta+dbubble123deta);
        case 10: return 27.*dbubble012deta;
        case 11: return 27.*dbubble013deta;
        case 12: return 27.*dbubble123deta;
        default: return 27.*dbubble023deta;
      }

  switch (i)
    {
      case 0: return (4.*zeta0 - 1.)*dzeta0dzeta + 3.*(dbubble012dzeta+dbubble013dzeta+dbubble023dzeta);
      case 1: return (4.*zeta1 - 1.)*dzeta1dzeta + 3.*(dbubble012dzeta+dbubble013dzeta+dbubble123dzeta);
      case 2: return (4.*zeta2 - 1.)*dzeta2dzeta + 3.*(dbubble012dzeta+dbubble023dzeta+dbubble123dzeta);
      case 3: return (4.*zeta3 - 1.)*dzeta3dzeta + 3.*(dbubble013dzeta+dbubble023dzeta+dbubble123dzeta);
      case 4: return 4.*(zeta0*dzeta1dzeta + dzeta0dzeta*zeta1) - 12.*(dbubble012dzeta+dbubble013dzeta);
      case 5: return 4.*(zeta1*dzeta2dzeta + dzeta1dzeta*zeta2) - 12.*(dbubble012dzeta+dbubble123dzeta);
      case 6: return 4.*(zeta0*dzeta2dzeta + dzeta0dzeta*zeta2) - 12.*(dbubble012dzeta+dbubble023dzeta);
      case 7: return 4.*(zeta0*dzeta3dzeta + dzeta0dzeta*zeta3) - 12.*(dbubble013dzeta+dbubble023dzeta);
      case 8: return 4.*(zeta1*dzeta3dzeta + dzeta1dzeta*zeta3) - 12.*(dbubble013dzeta+dbubble123dzeta);
      case 9: return 4.*(zeta2*dzeta3dzeta + dzeta2dzeta*zeta3) - 12.*(dbubble023dzeta+dbubble123dzeta);
      case 10: return 27.*dbubble012dzeta;
      case 11: return 27.*dbubble013dzeta;
      case 12: return 27.*dbubble123dzeta;
      default: return 27.*dbubble023dzeta;
    }
}

#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
LIBMESH_DEVICE_INLINE
Real fe_lagrange_tet10_shape_second_deriv(const unsigned int i,
                                          const unsigned int j)
{
  libmesh_assert_less(i, 10);
  libmesh_assert_less(j, 6);

  const unsigned short my_j = tet_second_deriv_index(j, 0);
  const unsigned short my_k = tet_second_deriv_index(j, 1);

  if (i < 4)
    return 4. * tet_dzeta(i, my_j) * tet_dzeta(i, my_k);

  const unsigned short m = tet10_zeta_index(i, 0);
  const unsigned short n = tet10_zeta_index(i, 1);

  return 4. * (tet_dzeta(n, my_j) * tet_dzeta(m, my_k) +
               tet_dzeta(m, my_j) * tet_dzeta(n, my_k));
}

LIBMESH_DEVICE_INLINE
649  
650  
651  
652 +
653  
654  
655  
656  
657  
658 +
659 +
660  
661 +
662  
663 +
664 +
665 +
666 +
667  
668  
669  
670 +
671  
672  
673 +
674 +
675 +
676 +
677 +
678 +
679  
680  
681 +
682 +
683 +
684 +
685 +
686 +
687  
688  
689 +
690 +
691 +
692 +
693 +
694 +
695  
696  
697 +
698 +
699 +
700 +
701 +
702 +
703  
704  
705 +
706 +
707 +
708 +
709 +
710 +
711  
712  
713 +
714 +
715 +
716 +
717 +
718 +
719  
720  
721 +
722  
723 +
724 +
725 +
726 +
727 +
728 +
729 +
730 +
731 +
732 +
733 +
734 +
735 +
736 +
737  
738  
739  
 * Tet10 half at all.  Each bubble is trilinear in the barycentric
 * coordinates, so its second derivatives are linear in the point.
 */
Real fe_lagrange_tet14_shape_second_deriv(const unsigned int i,
                                          const unsigned int j,
                                          const Real xi,
                                          const Real eta,
                                          const Real zeta)
{
  libmesh_assert_less(i, 14);
  libmesh_assert_less(j, 6);

  const Real returnval = (i < 10) ? fe_lagrange_tet10_shape_second_deriv(i, j) : 0.;

  const Real zeta1 = xi;
  const Real zeta2 = eta;
  const Real zeta3 = zeta;
  const Real zeta0 = 1. - zeta1 - zeta2 - zeta3;

  // Fill these with whichever derivative we're concerned with
  Real d2bubble012, d2bubble013, d2bubble023, d2bubble123;
  switch (j)
    {
      // d^2()/dxi^2
    case 0:
      d2bubble012 = -2.*zeta2;
      d2bubble013 = -2.*zeta3;
      d2bubble023 = 0.;
      d2bubble123 = 0.;
      break;

      // d^2()/dxideta
    case 1:
      d2bubble012 = (zeta0-zeta1)-zeta2;
      d2bubble013 = -zeta3;
      d2bubble123 = zeta3;
      d2bubble023 = -zeta3;
      break;

      // d^2()/deta^2
    case 2:
      d2bubble012 = -2.*zeta1;
      d2bubble013 = 0.;
      d2bubble123 = 0.;
      d2bubble023 = -2.*zeta3;
      break;

      // d^2()/dxi dzeta
    case 3:
      d2bubble012 = -zeta2;
      d2bubble013 = (zeta0-zeta3)-zeta1;
      d2bubble123 = zeta2;
      d2bubble023 = -zeta2;
      break;

      // d^2()/deta dzeta
    case 4:
      d2bubble012 = -zeta1;
      d2bubble013 = -zeta1;
      d2bubble123 = zeta1;
      d2bubble023 = (zeta0-zeta3)-zeta2;
      break;

      // d^2()/dzeta^2
    default:
      d2bubble012 = 0.;
      d2bubble013 = -2.*zeta1;
      d2bubble123 = 0.;
      d2bubble023 = -2.*zeta2;
      break;
    }

  switch (i)
    {
    case 0: return returnval + 3.*(d2bubble012+d2bubble013+d2bubble023);
    case 1: return returnval + 3.*(d2bubble012+d2bubble013+d2bubble123);
    case 2: return returnval + 3.*(d2bubble012+d2bubble023+d2bubble123);
    case 3: return returnval + 3.*(d2bubble013+d2bubble023+d2bubble123);
    case 4: return returnval - 12.*(d2bubble012+d2bubble013);
    case 5: return returnval - 12.*(d2bubble012+d2bubble123);
    case 6: return returnval - 12.*(d2bubble012+d2bubble023);
    case 7: return returnval - 12.*(d2bubble013+d2bubble023);
    case 8: return returnval - 12.*(d2bubble013+d2bubble123);
    case 9: return returnval - 12.*(d2bubble023+d2bubble123);
    case 10: return 27.*d2bubble012;
    case 11: return 27.*d2bubble013;
    case 12: return 27.*d2bubble123;
    default: return 27.*d2bubble023;
    }
}

include/fe/fe_tensor_product_lagrange.h

46  
47  
48  
49 +
50  
51 +
52 +
53  
54  
55  
56 +
57  
58 +
59 +
60  
61  
62  
63 +
64  
65 +
66  
67 +
68  
69 +
70  
71  
72 +
73 +
74  
75  
76 +
77 +
78 +
79  
80  
81  
82  
83 +
84  
85 +
86  
87 +
88  
89 +
90  
91  
92 +
93 +
94  
95  
96 +
97 +
98 +
99  
100  
101  
102  
103 +
104  
105 +
106 +
107  
108  
109  
110 +
111  
112 +
113 +
114  
115  
116  
117 +
118  
119 +
120 +
121  
122  
123  
124 +
125  
126 +
127  
128 +
129  
130 +
131  
132  
133  
 * i1(i) in eta (times i2(i) in zeta in 3D).  These maps are what let the
 * shapes below be written once per element rather than once per node.
 */
unsigned int quad4_i0(const unsigned int i)
{
  libmesh_assert_less(i, 4);
  return (i == 0 || i == 3) ? 0u : 1u;
}

LIBMESH_DEVICE_INLINE
unsigned int quad4_i1(const unsigned int i)
{
  libmesh_assert_less(i, 4);
  return i < 2 ? 0u : 1u;
}

LIBMESH_DEVICE_INLINE
unsigned int quad9_i0(const unsigned int i)
{
  libmesh_assert_less(i, 9);

  switch (i)
    {
    case 0:
    case 3:
    case 7:
      return 0;
    case 1:
    case 2:
    case 5:
      return 1;
    default:
      return 2;
    }
}

LIBMESH_DEVICE_INLINE
unsigned int quad9_i1(const unsigned int i)
{
  libmesh_assert_less(i, 9);

  switch (i)
    {
    case 0:
    case 1:
    case 4:
      return 0;
    case 2:
    case 3:
    case 6:
      return 1;
    default:
      return 2;
    }
}

LIBMESH_DEVICE_INLINE
unsigned int hex8_i0(const unsigned int i)
{
  libmesh_assert_less(i, 8);
  return (i == 0 || i == 3 || i == 4 || i == 7) ? 0u : 1u;
}

LIBMESH_DEVICE_INLINE
unsigned int hex8_i1(const unsigned int i)
{
  libmesh_assert_less(i, 8);
  return (i == 0 || i == 1 || i == 4 || i == 5) ? 0u : 1u;
}

LIBMESH_DEVICE_INLINE
unsigned int hex8_i2(const unsigned int i)
{
  libmesh_assert_less(i, 8);
  return i < 4 ? 0u : 1u;
}

LIBMESH_DEVICE_INLINE
unsigned int hex27_i0(const unsigned int i)
{
  libmesh_assert_less(i, 27);

  switch (i)
    {
    case 0:
    case 3:
    case 4:
    case 7:
136  
137  
138  
139 +
140 +
141  
142  
143  
    case 15:
    case 19:
    case 24:
      return 0;
    case 1:
    case 2:
    case 5:
    case 6:
146  
147  
148  
149 +
150 +
151 +
152  
153  
154  
155  
156 +
157  
158 +
159  
160 +
161  
162 +
163  
164  
165  
    case 14:
    case 17:
    case 22:
      return 1;
    default:
      return 2;
    }
}

LIBMESH_DEVICE_INLINE
unsigned int hex27_i1(const unsigned int i)
{
  libmesh_assert_less(i, 27);

  switch (i)
    {
    case 0:
    case 1:
    case 4:
    case 5:
168  
169  
170  
171 +
172 +
173  
174  
175  
    case 13:
    case 16:
    case 21:
      return 0;
    case 2:
    case 3:
    case 6:
    case 7:
178  
179  
180  
181 +
182 +
183 +
184  
185  
186  
187  
188 +
189  
190 +
191  
192 +
193  
194 +
195  
196  
197  
    case 15:
    case 18:
    case 23:
      return 1;
    default:
      return 2;
    }
}

LIBMESH_DEVICE_INLINE
unsigned int hex27_i2(const unsigned int i)
{
  libmesh_assert_less(i, 27);

  switch (i)
    {
    case 0:
    case 1:
    case 2:
    case 3:
200  
201  
202  
203 +
204 +
205  
206  
207  
    case 10:
    case 11:
    case 20:
      return 0;
    case 4:
    case 5:
    case 6:
    case 7:
210  
211  
212  
213 +
214 +
215 +
216  
217  
218  
    case 18:
    case 19:
    case 25:
      return 1;
    default:
      return 2;
    }
}

220  
221  
222  
223 +
224  
225  
226  
227 +
228  
229 +
230 +
231  
232  
233  
/**
 * Quad4 is the product of two linear 1D shapes, one per reference coordinate.
 */
Real fe_lagrange_quad4_shape(const unsigned int i,
                             const Real xi,
                             const Real eta)
{
  libmesh_assert_less(i, 4);

  return fe_lagrange_1D_linear_shape(quad4_i0(i), xi) *
         fe_lagrange_1D_linear_shape(quad4_i1(i), eta);
}

LIBMESH_DEVICE_INLINE
235  
236  
237  
238 +
239  
240  
241  
242  
243 +
244 +
245  
246 +
247  
248 +
249 +
250 +
251  
252 +
253 +
254 +
255  
256  
257  
 * Differentiating a product of two 1D shapes replaces the factor in the
 * requested direction with its 1D derivative and leaves the others.
 */
Real fe_lagrange_quad4_shape_deriv(const unsigned int i,
                                   const unsigned int j,
                                   const Real xi,
                                   const Real eta)
{
  libmesh_assert_less(i, 4);
  libmesh_assert_less(j, 2);

  switch (j)
    {
    case 0:
      return fe_lagrange_1D_linear_shape_deriv(quad4_i0(i), 0, xi) *
             fe_lagrange_1D_linear_shape(quad4_i1(i), eta);

    default:
      return fe_lagrange_1D_linear_shape(quad4_i0(i), xi) *
             fe_lagrange_1D_linear_shape_deriv(quad4_i1(i), 0, eta);
    }
}

259  
260  
261  
262 +
263  
264  
265  
266 +
267  
268 +
269 +
270  
271  
272  
/**
 * Quad9 is the product of two quadratic 1D shapes, one per reference coordinate.
 */
Real fe_lagrange_quad9_shape(const unsigned int i,
                             const Real xi,
                             const Real eta)
{
  libmesh_assert_less(i, 9);

  return fe_lagrange_1D_quadratic_shape(quad9_i0(i), xi) *
         fe_lagrange_1D_quadratic_shape(quad9_i1(i), eta);
}

LIBMESH_DEVICE_INLINE
274  
275  
276  
277 +
278  
279  
280  
281  
282 +
283 +
284  
285 +
286  
287 +
288 +
289 +
290  
291 +
292 +
293 +
294  
295  
296  
 * Differentiating a product of two 1D shapes replaces the factor in the
 * requested direction with its 1D derivative and leaves the others.
 */
Real fe_lagrange_quad9_shape_deriv(const unsigned int i,
                                   const unsigned int j,
                                   const Real xi,
                                   const Real eta)
{
  libmesh_assert_less(i, 9);
  libmesh_assert_less(j, 2);

  switch (j)
    {
    case 0:
      return fe_lagrange_1D_quadratic_shape_deriv(quad9_i0(i), 0, xi) *
             fe_lagrange_1D_quadratic_shape(quad9_i1(i), eta);

    default:
      return fe_lagrange_1D_quadratic_shape(quad9_i0(i), xi) *
             fe_lagrange_1D_quadratic_shape_deriv(quad9_i1(i), 0, eta);
    }
}

298  
299  
300  
301 +
302  
303  
304  
305  
306 +
307  
308 +
309 +
310 +
311  
312  
313  
/**
 * Hex8 is the product of three linear 1D shapes, one per reference coordinate.
 */
Real fe_lagrange_hex8_shape(const unsigned int i,
                            const Real xi,
                            const Real eta,
                            const Real zeta)
{
  libmesh_assert_less(i, 8);

  return fe_lagrange_1D_linear_shape(hex8_i0(i), xi) *
         fe_lagrange_1D_linear_shape(hex8_i1(i), eta) *
         fe_lagrange_1D_linear_shape(hex8_i2(i), zeta);
}

LIBMESH_DEVICE_INLINE
315  
316  
317  
318 +
319  
320  
321  
322  
323  
324 +
325 +
326  
327 +
328  
329 +
330 +
331 +
332 +
333  
334 +
335 +
336 +
337 +
338  
339 +
340 +
341 +
342 +
343  
344  
345  
 * Differentiating a product of three 1D shapes replaces the factor in the
 * requested direction with its 1D derivative and leaves the others.
 */
Real fe_lagrange_hex8_shape_deriv(const unsigned int i,
                                  const unsigned int j,
                                  const Real xi,
                                  const Real eta,
                                  const Real zeta)
{
  libmesh_assert_less(i, 8);
  libmesh_assert_less(j, 3);

  switch (j)
    {
    case 0:
      return fe_lagrange_1D_linear_shape_deriv(hex8_i0(i), 0, xi) *
             fe_lagrange_1D_linear_shape(hex8_i1(i), eta) *
             fe_lagrange_1D_linear_shape(hex8_i2(i), zeta);

    case 1:
      return fe_lagrange_1D_linear_shape(hex8_i0(i), xi) *
             fe_lagrange_1D_linear_shape_deriv(hex8_i1(i), 0, eta) *
             fe_lagrange_1D_linear_shape(hex8_i2(i), zeta);

    default:
      return fe_lagrange_1D_linear_shape(hex8_i0(i), xi) *
             fe_lagrange_1D_linear_shape(hex8_i1(i), eta) *
             fe_lagrange_1D_linear_shape_deriv(hex8_i2(i), 0, zeta);
    }
}

347  
348  
349  
350 +
351  
352  
353  
354  
355 +
356  
357 +
358 +
359 +
360  
361  
362  
/**
 * Hex27 is the product of three quadratic 1D shapes, one per reference coordinate.
 */
Real fe_lagrange_hex27_shape(const unsigned int i,
                             const Real xi,
                             const Real eta,
                             const Real zeta)
{
  libmesh_assert_less(i, 27);

  return fe_lagrange_1D_quadratic_shape(hex27_i0(i), xi) *
         fe_lagrange_1D_quadratic_shape(hex27_i1(i), eta) *
         fe_lagrange_1D_quadratic_shape(hex27_i2(i), zeta);
}

LIBMESH_DEVICE_INLINE
364  
365  
366  
367 +
368  
369  
370  
371  
372  
373 +
374 +
375  
376 +
377  
378 +
379 +
380 +
381 +
382  
383 +
384 +
385 +
386 +
387  
388 +
389 +
390 +
391 +
392  
393  
394  
 * Differentiating a product of three 1D shapes replaces the factor in the
 * requested direction with its 1D derivative and leaves the others.
 */
Real fe_lagrange_hex27_shape_deriv(const unsigned int i,
                                   const unsigned int j,
                                   const Real xi,
                                   const Real eta,
                                   const Real zeta)
{
  libmesh_assert_less(i, 27);
  libmesh_assert_less(j, 3);

  switch (j)
    {
    case 0:
      return fe_lagrange_1D_quadratic_shape_deriv(hex27_i0(i), 0, xi) *
             fe_lagrange_1D_quadratic_shape(hex27_i1(i), eta) *
             fe_lagrange_1D_quadratic_shape(hex27_i2(i), zeta);

    case 1:
      return fe_lagrange_1D_quadratic_shape(hex27_i0(i), xi) *
             fe_lagrange_1D_quadratic_shape_deriv(hex27_i1(i), 0, eta) *
             fe_lagrange_1D_quadratic_shape(hex27_i2(i), zeta);

    default:
      return fe_lagrange_1D_quadratic_shape(hex27_i0(i), xi) *
             fe_lagrange_1D_quadratic_shape(hex27_i1(i), eta) *
             fe_lagrange_1D_quadratic_shape_deriv(hex27_i2(i), 0, zeta);
    }
}

400  
401  
402  
403 +
404  
405  
406  
407  
408 +
409 +
410  
411 +
412  
413 +
414  
415 +
416  
417 +
418 +
419 +
420  
421  
422  
 * 1D second derivative, and a mixed pair takes two 1D first
 * derivatives.
 */
Real fe_lagrange_quad4_shape_second_deriv(const unsigned int i,
                                          const unsigned int j,
                                          const Real xi,
                                          const Real eta)
{
  libmesh_assert_less(i, 4);
  libmesh_assert_less(j, 3);

  switch (j)
    {
    case 0:
    case 2:
      return 0.;

    default:
      return fe_lagrange_1D_linear_shape_deriv(quad4_i0(i), 0, xi) *
             fe_lagrange_1D_linear_shape_deriv(quad4_i1(i), 0, eta);
    }
}

426  
427  
428  
429 +
430  
431  
432  
433  
434 +
435 +
436  
437 +
438  
439 +
440 +
441 +
442  
443 +
444 +
445 +
446  
447 +
448 +
449 +
450  
451  
452  
 * 1D second derivative, and a mixed pair takes two 1D first
 * derivatives.
 */
Real fe_lagrange_quad9_shape_second_deriv(const unsigned int i,
                                          const unsigned int j,
                                          const Real xi,
                                          const Real eta)
{
  libmesh_assert_less(i, 9);
  libmesh_assert_less(j, 3);

  switch (j)
    {
    case 0:
      return fe_lagrange_1D_quadratic_shape_second_deriv(quad9_i0(i), 0, xi) *
             fe_lagrange_1D_quadratic_shape(quad9_i1(i), eta);

    case 1:
      return fe_lagrange_1D_quadratic_shape_deriv(quad9_i0(i), 0, xi) *
             fe_lagrange_1D_quadratic_shape_deriv(quad9_i1(i), 0, eta);

    default:
      return fe_lagrange_1D_quadratic_shape(quad9_i0(i), xi) *
             fe_lagrange_1D_quadratic_shape_second_deriv(quad9_i1(i), 0, eta);
    }
}

456  
457  
458  
459 +
460  
461  
462  
463  
464  
465 +
466 +
467  
468 +
469  
470 +
471  
472  
473 +
474  
475 +
476 +
477 +
478 +
479  
480 +
481 +
482 +
483 +
484  
485 +
486 +
487 +
488 +
489  
490  
491  
 * 1D second derivative, and a mixed pair takes two 1D first
 * derivatives.
 */
Real fe_lagrange_hex8_shape_second_deriv(const unsigned int i,
                                         const unsigned int j,
                                         const Real xi,
                                         const Real eta,
                                         const Real zeta)
{
  libmesh_assert_less(i, 8);
  libmesh_assert_less(j, 6);

  switch (j)
    {
    case 0:
    case 2:
    case 5:
      return 0.;

    case 1:
      return fe_lagrange_1D_linear_shape_deriv(hex8_i0(i), 0, xi) *
             fe_lagrange_1D_linear_shape_deriv(hex8_i1(i), 0, eta) *
             fe_lagrange_1D_linear_shape(hex8_i2(i), zeta);

    case 3:
      return fe_lagrange_1D_linear_shape_deriv(hex8_i0(i), 0, xi) *
             fe_lagrange_1D_linear_shape(hex8_i1(i), eta) *
             fe_lagrange_1D_linear_shape_deriv(hex8_i2(i), 0, zeta);

    default:
      return fe_lagrange_1D_linear_shape(hex8_i0(i), xi) *
             fe_lagrange_1D_linear_shape_deriv(hex8_i1(i), 0, eta) *
             fe_lagrange_1D_linear_shape_deriv(hex8_i2(i), 0, zeta);
    }
}

495  
496  
497  
498 +
499  
500  
501  
502  
503  
504 +
505 +
506  
507 +
508  
509 +
510 +
511 +
512 +
513  
514 +
515 +
516 +
517 +
518  
519 +
520 +
521 +
522 +
523  
524 +
525 +
526 +
527 +
528  
529 +
530 +
531 +
532 +
533  
534 +
535 +
536 +
537 +
538  
539  
540  
 * 1D second derivative, and a mixed pair takes two 1D first
 * derivatives.
 */
Real fe_lagrange_hex27_shape_second_deriv(const unsigned int i,
                                          const unsigned int j,
                                          const Real xi,
                                          const Real eta,
                                          const Real zeta)
{
  libmesh_assert_less(i, 27);
  libmesh_assert_less(j, 6);

  switch (j)
    {
    case 0:
      return fe_lagrange_1D_quadratic_shape_second_deriv(hex27_i0(i), 0, xi) *
             fe_lagrange_1D_quadratic_shape(hex27_i1(i), eta) *
             fe_lagrange_1D_quadratic_shape(hex27_i2(i), zeta);

    case 1:
      return fe_lagrange_1D_quadratic_shape_deriv(hex27_i0(i), 0, xi) *
             fe_lagrange_1D_quadratic_shape_deriv(hex27_i1(i), 0, eta) *
             fe_lagrange_1D_quadratic_shape(hex27_i2(i), zeta);

    case 2:
      return fe_lagrange_1D_quadratic_shape(hex27_i0(i), xi) *
             fe_lagrange_1D_quadratic_shape_second_deriv(hex27_i1(i), 0, eta) *
             fe_lagrange_1D_quadratic_shape(hex27_i2(i), zeta);

    case 3:
      return fe_lagrange_1D_quadratic_shape_deriv(hex27_i0(i), 0, xi) *
             fe_lagrange_1D_quadratic_shape(hex27_i1(i), eta) *
             fe_lagrange_1D_quadratic_shape_deriv(hex27_i2(i), 0, zeta);

    case 4:
      return fe_lagrange_1D_quadratic_shape(hex27_i0(i), xi) *
             fe_lagrange_1D_quadratic_shape_deriv(hex27_i1(i), 0, eta) *
             fe_lagrange_1D_quadratic_shape_deriv(hex27_i2(i), 0, zeta);

    default:
      return fe_lagrange_1D_quadratic_shape(hex27_i0(i), xi) *
             fe_lagrange_1D_quadratic_shape(hex27_i1(i), eta) *
             fe_lagrange_1D_quadratic_shape_second_deriv(hex27_i2(i), 0, zeta);
    }
}

553  
554  
555  
556 +
557  
558  
559  
560 +
561  
562 +
563  
564 +
565 +
566 +
567 +
568 +
569 +
570 +
571 +
572  
573  
574  
 * +- eta) and a mid-edge shape is 0.5*(1 - xi^2)*(1 -+ eta) or its
 * transpose.
 */
Real fe_lagrange_quad8_shape(const unsigned int i,
                             const Real xi,
                             const Real eta)
{
  libmesh_assert_less(i, 8);

  switch (i)
    {
    case 0: return 0.25 * (1.0 - xi) * (1.0 - eta) * (-1.0 - xi - eta);
    case 1: return 0.25 * (1.0 + xi) * (1.0 - eta) * (-1.0 + xi - eta);
    case 2: return 0.25 * (1.0 + xi) * (1.0 + eta) * (-1.0 + xi + eta);
    case 3: return 0.25 * (1.0 - xi) * (1.0 + eta) * (-1.0 - xi + eta);
    case 4: return 0.5  * (1.0 - xi * xi) * (1.0 - eta);
    case 5: return 0.5  * (1.0 + xi) * (1.0 - eta * eta);
    case 6: return 0.5  * (1.0 - xi * xi) * (1.0 + eta);
    default: return 0.5 * (1.0 - xi) * (1.0 - eta * eta);
    }
}

576  
577  
578  
579 +
580  
581  
582  
583  
584 +
585 +
586  
587 +
588  
589  
590 +
591 +
592  
593 +
594 +
595 +
596 +
597 +
598 +
599 +
600 +
601 +
602 +
603 +
604 +
605  
606  
607  
608 +
609 +
610  
611 +
612 +
613 +
614 +
615 +
616 +
617 +
618 +
619 +
620 +
621 +
622 +
623  
624  
625  
/**
 * Differentiated in place: the serendipity forms are not products, so each derivative is written out.
 */
Real fe_lagrange_quad8_shape_deriv(const unsigned int i,
                                   const unsigned int j,
                                   const Real xi,
                                   const Real eta)
{
  libmesh_assert_less(i, 8);
  libmesh_assert_less(j, 2);

  switch (j)
    {
      // d/dxi
    case 0:
      switch (i)
        {
        case 0: return .25*(1. - eta)*((1. - xi)*(-1.) +
                                       (-1.)*(-1. - xi - eta));
        case 1: return .25*(1. - eta)*((1. + xi)*(1.) +
                                       (1.)*(-1. + xi - eta));
        case 2: return .25*(1. + eta)*((1. + xi)*(1.) +
                                       (1.)*(-1. + xi + eta));
        case 3: return .25*(1. + eta)*((1. - xi)*(-1.) +
                                       (-1.)*(-1. - xi + eta));
        case 4: return .5*(-2.*xi)*(1. - eta);
        case 5: return .5*(1.)*(1. - eta*eta);
        case 6: return .5*(-2.*xi)*(1. + eta);
        default: return .5*(-1.)*(1. - eta*eta);
        }

      // d/deta
    default:
      switch (i)
        {
        case 0: return .25*(1. - xi)*((1. - eta)*(-1.) +
                                      (-1.)*(-1. - xi - eta));
        case 1: return .25*(1. + xi)*((1. - eta)*(-1.) +
                                      (-1.)*(-1. + xi - eta));
        case 2: return .25*(1. + xi)*((1. + eta)*(1.) +
                                      (1.)*(-1. + xi + eta));
        case 3: return .25*(1. - xi)*((1. + eta)*(1.) +
                                      (1.)*(-1. - xi + eta));
        case 4: return .5*(1. - xi*xi)*(-1.);
        case 5: return .5*(1. + xi)*(-2.*eta);
        case 6: return .5*(1. - xi*xi)*(1.);
        default: return .5*(1. - xi)*(-2.*eta);
        }
    }
}
629  
630  
631  
632 +
633  
634  
635  
636  
637 +
638 +
639  
640 +
641  
642 +
643 +
644  
645 +
646  
647 +
648 +
649  
650 +
651 +
652 +
653 +
654 +
655 +
656 +
657  
658  
659 +
660 +
661  
662 +
663 +
664 +
665 +
666 +
667 +
668 +
669 +
670  
671  
672 +
673 +
674  
675 +
676  
677 +
678 +
679  
680 +
681 +
682 +
683 +
684 +
685 +
686 +
687  
688  
689  
/**
 * Second derivatives of the serendipity forms, likewise written out.
 */
Real fe_lagrange_quad8_shape_second_deriv(const unsigned int i,
                                          const unsigned int j,
                                          const Real xi,
                                          const Real eta)
{
  libmesh_assert_less(i, 8);
  libmesh_assert_less(j, 3);

  switch (j)
    {
    case 0:
      switch (i)
        {
        case 0:
        case 1:
          return 0.5 * (1.0 - eta);
        case 2:
        case 3:
          return 0.5 * (1.0 + eta);
        case 4:
          return eta - 1.0;
        case 6:
          return -1.0 - eta;
        default:
          return 0.0;
        }

    case 1:
      switch (i)
        {
        case 0: return 0.25 * (1.0 - 2.0 * xi - 2.0 * eta);
        case 1: return 0.25 * (-1.0 - 2.0 * xi + 2.0 * eta);
        case 2: return 0.25 * (1.0 + 2.0 * xi + 2.0 * eta);
        case 3: return 0.25 * (-1.0 + 2.0 * xi - 2.0 * eta);
        case 4: return xi;
        case 5: return -eta;
        case 6: return -xi;
        default: return eta;
        }

    default:
      switch (i)
        {
        case 0:
        case 3:
          return 0.5 * (1.0 - xi);
        case 1:
        case 2:
          return 0.5 * (1.0 + xi);
        case 5:
          return -1.0 - xi;
        case 7:
          return xi - 1.0;
        default:
          return 0.0;
        }
    }
}
696  
697  
698  
699 +
700  
701  
702  
703  
704 +
705  
706 +
707 +
708 +
709  
710 +
711  
712 +
713 +
714 +
715 +
716 +
717 +
718 +
719 +
720 +
721 +
722 +
723 +
724 +
725 +
726 +
727 +
728 +
729 +
730 +
731 +
732  
733  
734  
 * x, y, z = (reference + 1)/2, which is the form in which the vertex and
 * mid-edge expressions are usually tabulated.
 */
Real fe_lagrange_hex20_shape(const unsigned int i,
                             const Real xi,
                             const Real eta,
                             const Real zeta)
{
  libmesh_assert_less(i, 20);

  const Real x = 0.5 * (xi + 1.0);
  const Real y = 0.5 * (eta + 1.0);
  const Real z = 0.5 * (zeta + 1.0);

  switch (i)
    {
    case 0: return (1.0 - x) * (1.0 - y) * (1.0 - z) * (1.0 - 2.0 * x - 2.0 * y - 2.0 * z);
    case 1: return x * (1.0 - y) * (1.0 - z) * (2.0 * x - 2.0 * y - 2.0 * z - 1.0);
    case 2: return x * y * (1.0 - z) * (2.0 * x + 2.0 * y - 2.0 * z - 3.0);
    case 3: return (1.0 - x) * y * (1.0 - z) * (2.0 * y - 2.0 * x - 2.0 * z - 1.0);
    case 4: return (1.0 - x) * (1.0 - y) * z * (2.0 * z - 2.0 * x - 2.0 * y - 1.0);
    case 5: return x * (1.0 - y) * z * (2.0 * x - 2.0 * y + 2.0 * z - 3.0);
    case 6: return x * y * z * (2.0 * x + 2.0 * y + 2.0 * z - 5.0);
    case 7: return (1.0 - x) * y * z * (2.0 * y - 2.0 * x + 2.0 * z - 3.0);
    case 8: return 4.0 * x * (1.0 - x) * (1.0 - y) * (1.0 - z);
    case 9: return 4.0 * x * y * (1.0 - y) * (1.0 - z);
    case 10: return 4.0 * x * (1.0 - x) * y * (1.0 - z);
    case 11: return 4.0 * (1.0 - x) * y * (1.0 - y) * (1.0 - z);
    case 12: return 4.0 * (1.0 - x) * (1.0 - y) * z * (1.0 - z);
    case 13: return 4.0 * x * (1.0 - y) * z * (1.0 - z);
    case 14: return 4.0 * x * y * z * (1.0 - z);
    case 15: return 4.0 * (1.0 - x) * y * z * (1.0 - z);
    case 16: return 4.0 * x * (1.0 - x) * (1.0 - y) * z;
    case 17: return 4.0 * x * y * (1.0 - y) * z;
    case 18: return 4.0 * x * (1.0 - x) * y * z;
    default: return 4.0 * (1.0 - x) * y * (1.0 - y) * z;
    }
}

736  
737  
738  
739 +
740  
741  
742  
743  
744  
745 +
746 +
747  
748 +
749 +
750 +
751  
752 +
753  
754 +
755 +
756  
757 +
758 +
759 +
760 +
761 +
762 +
763 +
764 +
765 +
766 +
767 +
768 +
769 +
770 +
771 +
772 +
773 +
774 +
775 +
776 +
777  
778  
779 +
780 +
781  
782 +
783 +
784 +
785 +
786 +
787 +
788 +
789 +
790 +
791 +
792 +
793 +
794 +
795 +
796 +
797 +
798 +
799 +
800 +
801 +
802  
803  
804 +
805 +
806  
807 +
808 +
809 +
810 +
811 +
812 +
813 +
814 +
815 +
816 +
817 +
818 +
819 +
820 +
821 +
822 +
823 +
824 +
825 +
826 +
827  
828  
829  
/**
 * Differentiated in place: the serendipity forms are not products, so each derivative is written out.
 */
Real fe_lagrange_hex20_shape_deriv(const unsigned int i,
                                   const unsigned int j,
                                   const Real xi,
                                   const Real eta,
                                   const Real zeta)
{
  libmesh_assert_less(i, 20);
  libmesh_assert_less(j, 3);

  const Real x = 0.5 * (xi + 1.0);
  const Real y = 0.5 * (eta + 1.0);
  const Real z = 0.5 * (zeta + 1.0);

  switch (j)
    {
    case 0:
      switch (i)
        {
        case 0: return 0.5 * (1.0 - y) * (1.0 - z) * ((1.0 - x) * (-2.0) + (-1.0) * (1.0 - 2.0 * x - 2.0 * y - 2.0 * z));
        case 1: return 0.5 * (1.0 - y) * (1.0 - z) * (x * 2.0 + (2.0 * x - 2.0 * y - 2.0 * z - 1.0));
        case 2: return 0.5 * y * (1.0 - z) * (x * 2.0 + (2.0 * x + 2.0 * y - 2.0 * z - 3.0));
        case 3: return 0.5 * y * (1.0 - z) * ((1.0 - x) * (-2.0) + (-1.0) * (2.0 * y - 2.0 * x - 2.0 * z - 1.0));
        case 4: return 0.5 * (1.0 - y) * z * ((1.0 - x) * (-2.0) + (-1.0) * (2.0 * z - 2.0 * x - 2.0 * y - 1.0));
        case 5: return 0.5 * (1.0 - y) * z * (x * 2.0 + (2.0 * x - 2.0 * y + 2.0 * z - 3.0));
        case 6: return 0.5 * y * z * (x * 2.0 + (2.0 * x + 2.0 * y + 2.0 * z - 5.0));
        case 7: return 0.5 * y * z * ((1.0 - x) * (-2.0) + (-1.0) * (2.0 * y - 2.0 * x + 2.0 * z - 3.0));
        case 8: return 2.0 * (1.0 - y) * (1.0 - z) * (1.0 - 2.0 * x);
        case 9: return 2.0 * y * (1.0 - y) * (1.0 - z);
        case 10: return 2.0 * y * (1.0 - z) * (1.0 - 2.0 * x);
        case 11: return -2.0 * y * (1.0 - y) * (1.0 - z);
        case 12: return -2.0 * (1.0 - y) * z * (1.0 - z);
        case 13: return 2.0 * (1.0 - y) * z * (1.0 - z);
        case 14: return 2.0 * y * z * (1.0 - z);
        case 15: return -2.0 * y * z * (1.0 - z);
        case 16: return 2.0 * (1.0 - y) * z * (1.0 - 2.0 * x);
        case 17: return 2.0 * y * (1.0 - y) * z;
        case 18: return 2.0 * y * z * (1.0 - 2.0 * x);
        default: return -2.0 * y * (1.0 - y) * z;
        }

    case 1:
      switch (i)
        {
        case 0: return 0.5 * (1.0 - x) * (1.0 - z) * ((1.0 - y) * (-2.0) + (-1.0) * (1.0 - 2.0 * x - 2.0 * y - 2.0 * z));
        case 1: return 0.5 * x * (1.0 - z) * ((1.0 - y) * (-2.0) + (-1.0) * (2.0 * x - 2.0 * y - 2.0 * z - 1.0));
        case 2: return 0.5 * x * (1.0 - z) * (y * 2.0 + (2.0 * x + 2.0 * y - 2.0 * z - 3.0));
        case 3: return 0.5 * (1.0 - x) * (1.0 - z) * (y * 2.0 + (2.0 * y - 2.0 * x - 2.0 * z - 1.0));
        case 4: return 0.5 * (1.0 - x) * z * ((1.0 - y) * (-2.0) + (-1.0) * (2.0 * z - 2.0 * x - 2.0 * y - 1.0));
        case 5: return 0.5 * x * z * ((1.0 - y) * (-2.0) + (-1.0) * (2.0 * x - 2.0 * y + 2.0 * z - 3.0));
        case 6: return 0.5 * x * z * (y * 2.0 + (2.0 * x + 2.0 * y + 2.0 * z - 5.0));
        case 7: return 0.5 * (1.0 - x) * z * (y * 2.0 + (2.0 * y - 2.0 * x + 2.0 * z - 3.0));
        case 8: return -2.0 * x * (1.0 - x) * (1.0 - z);
        case 9: return 2.0 * x * (1.0 - z) * (1.0 - 2.0 * y);
        case 10: return 2.0 * x * (1.0 - x) * (1.0 - z);
        case 11: return 2.0 * (1.0 - x) * (1.0 - z) * (1.0 - 2.0 * y);
        case 12: return -2.0 * (1.0 - x) * z * (1.0 - z);
        case 13: return -2.0 * x * z * (1.0 - z);
        case 14: return 2.0 * x * z * (1.0 - z);
        case 15: return 2.0 * (1.0 - x) * z * (1.0 - z);
        case 16: return -2.0 * x * (1.0 - x) * z;
        case 17: return 2.0 * x * z * (1.0 - 2.0 * y);
        case 18: return 2.0 * x * (1.0 - x) * z;
        default: return 2.0 * (1.0 - x) * z * (1.0 - 2.0 * y);
        }

    default:
      switch (i)
        {
        case 0: return 0.5 * (1.0 - x) * (1.0 - y) * ((1.0 - z) * (-2.0) + (-1.0) * (1.0 - 2.0 * x - 2.0 * y - 2.0 * z));
        case 1: return 0.5 * x * (1.0 - y) * ((1.0 - z) * (-2.0) + (-1.0) * (2.0 * x - 2.0 * y - 2.0 * z - 1.0));
        case 2: return 0.5 * x * y * ((1.0 - z) * (-2.0) + (-1.0) * (2.0 * x + 2.0 * y - 2.0 * z - 3.0));
        case 3: return 0.5 * (1.0 - x) * y * ((1.0 - z) * (-2.0) + (-1.0) * (2.0 * y - 2.0 * x - 2.0 * z - 1.0));
        case 4: return 0.5 * (1.0 - x) * (1.0 - y) * (z * 2.0 + (2.0 * z - 2.0 * x - 2.0 * y - 1.0));
        case 5: return 0.5 * x * (1.0 - y) * (z * 2.0 + (2.0 * x - 2.0 * y + 2.0 * z - 3.0));
        case 6: return 0.5 * x * y * (z * 2.0 + (2.0 * x + 2.0 * y + 2.0 * z - 5.0));
        case 7: return 0.5 * (1.0 - x) * y * (z * 2.0 + (2.0 * y - 2.0 * x + 2.0 * z - 3.0));
        case 8: return -2.0 * x * (1.0 - x) * (1.0 - y);
        case 9: return -2.0 * x * y * (1.0 - y);
        case 10: return -2.0 * x * (1.0 - x) * y;
        case 11: return -2.0 * (1.0 - x) * y * (1.0 - y);
        case 12: return 2.0 * (1.0 - x) * (1.0 - y) * (1.0 - 2.0 * z);
        case 13: return 2.0 * x * (1.0 - y) * (1.0 - 2.0 * z);
        case 14: return 2.0 * x * y * (1.0 - 2.0 * z);
        case 15: return 2.0 * (1.0 - x) * y * (1.0 - 2.0 * z);
        case 16: return 2.0 * x * (1.0 - x) * (1.0 - y);
        case 17: return 2.0 * x * y * (1.0 - y);
        case 18: return 2.0 * x * (1.0 - x) * y;
        default: return 2.0 * (1.0 - x) * y * (1.0 - y);
        }
    }
}
833  
834  
835  
836 +
837  
838  
839  
840  
841  
842 +
843 +
844  
845 +
846 +
847 +
848  
849 +
850  
851 +
852 +
853  
854 +
855 +
856 +
857 +
858 +
859 +
860 +
861 +
862 +
863 +
864 +
865 +
866 +
867  
868  
869 +
870 +
871  
872 +
873 +
874 +
875 +
876 +
877 +
878 +
879 +
880 +
881 +
882 +
883 +
884 +
885 +
886 +
887 +
888 +
889 +
890 +
891 +
892  
893  
894 +
895 +
896  
897 +
898 +
899 +
900 +
901 +
902 +
903 +
904 +
905 +
906 +
907 +
908 +
909 +
910  
911  
912 +
913 +
914  
915 +
916 +
917 +
918 +
919 +
920 +
921 +
922 +
923 +
924 +
925 +
926 +
927 +
928 +
929 +
930 +
931 +
932 +
933 +
934 +
935  
936  
937 +
938 +
939  
940 +
941 +
942 +
943 +
944 +
945 +
946 +
947 +
948 +
949 +
950 +
951 +
952 +
953 +
954 +
955 +
956 +
957 +
958 +
959 +
960  
961  
962 +
963 +
964  
965 +
966 +
967 +
968 +
969 +
970 +
971 +
972 +
973 +
974 +
975 +
976 +
977 +
978  
979  
980  
/**
 * Second derivatives of the serendipity forms, likewise written out.
 */
Real fe_lagrange_hex20_shape_second_deriv(const unsigned int i,
                                          const unsigned int j,
                                          const Real xi,
                                          const Real eta,
                                          const Real zeta)
{
  libmesh_assert_less(i, 20);
  libmesh_assert_less(j, 6);

  const Real x = 0.5 * (xi + 1.0);
  const Real y = 0.5 * (eta + 1.0);
  const Real z = 0.5 * (zeta + 1.0);

  switch (j)
    {
    case 0:
      switch (i)
        {
        case 0:
        case 1: return (1.0 - y) * (1.0 - z);
        case 2:
        case 3: return y * (1.0 - z);
        case 4:
        case 5: return (1.0 - y) * z;
        case 6:
        case 7: return y * z;
        case 8: return -2.0 * (1.0 - y) * (1.0 - z);
        case 10: return -2.0 * y * (1.0 - z);
        case 16: return -2.0 * (1.0 - y) * z;
        case 18: return -2.0 * y * z;
        default: return 0.0;
        }

    case 1:
      switch (i)
        {
        case 0: return (1.25 - x - y - 0.5 * z) * (1.0 - z);
        case 1: return (-x + y + 0.5 * z - 0.25) * (1.0 - z);
        case 2: return (x + y - 0.5 * z - 0.75) * (1.0 - z);
        case 3: return (-y + x + 0.5 * z - 0.25) * (1.0 - z);
        case 4: return -0.25 * z * (4.0 * x + 4.0 * y - 2.0 * z - 3.0);
        case 5: return -0.25 * z * (-4.0 * y + 4.0 * x + 2.0 * z - 1.0);
        case 6: return 0.25 * z * (-5.0 + 4.0 * x + 4.0 * y + 2.0 * z);
        case 7: return 0.25 * z * (4.0 * x - 4.0 * y - 2.0 * z + 1.0);
        case 8: return (-1.0 + 2.0 * x) * (1.0 - z);
        case 9: return (1.0 - 2.0 * y) * (1.0 - z);
        case 10: return (1.0 - 2.0 * x) * (1.0 - z);
        case 11: return (-1.0 + 2.0 * y) * (1.0 - z);
        case 12: return z * (1.0 - z);
        case 13: return -z * (1.0 - z);
        case 14: return z * (1.0 - z);
        case 15: return -z * (1.0 - z);
        case 16: return (-1.0 + 2.0 * x) * z;
        case 17: return (1.0 - 2.0 * y) * z;
        case 18: return (1.0 - 2.0 * x) * z;
        default: return (-1.0 + 2.0 * y) * z;
        }

    case 2:
      switch (i)
        {
        case 0:
        case 3: return (1.0 - x) * (1.0 - z);
        case 1:
        case 2: return x * (1.0 - z);
        case 4:
        case 7: return (1.0 - x) * z;
        case 5:
        case 6: return x * z;
        case 9: return -2.0 * x * (1.0 - z);
        case 11: return -2.0 * (1.0 - x) * (1.0 - z);
        case 17: return -2.0 * x * z;
        case 19: return -2.0 * (1.0 - x) * z;
        default: return 0.0;
        }

    case 3:
      switch (i)
        {
        case 0: return (1.25 - x - 0.5 * y - z) * (1.0 - y);
        case 1: return (-x + 0.5 * y + z - 0.25) * (1.0 - y);
        case 2: return -0.25 * y * (2.0 * y + 4.0 * x - 4.0 * z - 1.0);
        case 3: return -0.25 * y * (-2.0 * y + 4.0 * x + 4.0 * z - 3.0);
        case 4: return (-z + x + 0.5 * y - 0.25) * (1.0 - y);
        case 5: return (x - 0.5 * y + z - 0.75) * (1.0 - y);
        case 6: return 0.25 * y * (2.0 * y + 4.0 * x + 4.0 * z - 5.0);
        case 7: return 0.25 * y * (-2.0 * y + 4.0 * x - 4.0 * z + 1.0);
        case 8: return (-1.0 + 2.0 * x) * (1.0 - y);
        case 9: return -y * (1.0 - y);
        case 10: return (-1.0 + 2.0 * x) * y;
        case 11: return y * (1.0 - y);
        case 12: return (-1.0 + 2.0 * z) * (1.0 - y);
        case 13: return (1.0 - 2.0 * z) * (1.0 - y);
        case 14: return (1.0 - 2.0 * z) * y;
        case 15: return (-1.0 + 2.0 * z) * y;
        case 16: return (1.0 - 2.0 * x) * (1.0 - y);
        case 17: return y * (1.0 - y);
        case 18: return (1.0 - 2.0 * x) * y;
        default: return -y * (1.0 - y);
        }

    case 4:
      switch (i)
        {
        case 0: return (1.25 - 0.5 * x - y - z) * (1.0 - x);
        case 1: return 0.25 * x * (2.0 * x - 4.0 * y - 4.0 * z + 3.0);
        case 2: return -0.25 * x * (2.0 * x + 4.0 * y - 4.0 * z - 1.0);
        case 3: return (-y + 0.5 * x + z - 0.25) * (1.0 - x);
        case 4: return (-z + 0.5 * x + y - 0.25) * (1.0 - x);
        case 5: return -0.25 * x * (2.0 * x - 4.0 * y + 4.0 * z - 1.0);
        case 6: return 0.25 * x * (2.0 * x + 4.0 * y + 4.0 * z - 5.0);
        case 7: return (y - 0.5 * x + z - 0.75) * (1.0 - x);
        case 8: return x * (1.0 - x);
        case 9: return (-1.0 + 2.0 * y) * x;
        case 10: return -x * (1.0 - x);
        case 11: return (-1.0 + 2.0 * y) * (1.0 - x);
        case 12: return (-1.0 + 2.0 * z) * (1.0 - x);
        case 13: return (-1.0 + 2.0 * z) * x;
        case 14: return (1.0 - 2.0 * z) * x;
        case 15: return (1.0 - 2.0 * z) * (1.0 - x);
        case 16: return -x * (1.0 - x);
        case 17: return (1.0 - 2.0 * y) * x;
        case 18: return x * (1.0 - x);
        default: return (1.0 - 2.0 * y) * (1.0 - x);
        }

    default:
      switch (i)
        {
        case 0:
        case 4: return (1.0 - x) * (1.0 - y);
        case 1:
        case 5: return x * (1.0 - y);
        case 2:
        case 6: return x * y;
        case 3:
        case 7: return (1.0 - x) * y;
        case 12: return -2.0 * (1.0 - x) * (1.0 - y);
        case 13: return -2.0 * x * (1.0 - y);
        case 14: return -2.0 * x * y;
        case 15: return -2.0 * (1.0 - x) * y;
        default: return 0.0;
        }
    }
}

include/geom/elem.h

2727  
2728  
2729  
2730  
2731  
2732  
2733  
inline
bool Elem::operator != (const Elem & rhs) const
{
  return !(*this == rhs);
}


3291  
3292  
3293  
3294  
3295  
3296  
3297  
3298  
3299  
3300  
inline
const Elem * Elem::raw_child_ptr (unsigned int i) const
{
  if (!_children)
    return nullptr;

  return _children[i];
}

inline

include/geom/elem_internal.h

257  
258  
259  
260  
261  
262  
263  
  if (elem->has_children())
    for (auto & c : elem->child_ref_range())
      if (!c.is_remote() && c.has_neighbor(neighbor_in))
        ElemInternal::total_family_tree_by_neighbor (&c, family, neighbor_in, false);
}


306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  

template <class T>
void
total_family_tree_by_subneighbor(T elem,
                                 std::vector<T> & family,
                                 T neighbor_in,
                                 T subneighbor,
                                 bool reset = true)
{
  // Clear the vector if the flag reset tells us to.
  if (reset)
    family.clear();

  // To simplify this function we need an existing neighbor
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
  libmesh_assert (neighbor_in->is_ancestor_of(subneighbor));

  // Add this element to the family tree if applicable.
  if (neighbor_in == subneighbor)
    family.push_back(elem);

  // Recurse into the elements children, if it has any.
  // Do not clear the vector any more.
  if (elem->has_children())
    for (auto & c : elem->child_ref_range())
      if (!c.is_remote())
        for (auto child_neigh : c.neighbor_ptr_range())
          if (child_neigh &&
              (child_neigh == neighbor_in ||
               (child_neigh->parent() == neighbor_in && child_neigh->is_ancestor_of(subneighbor))))
            c.total_family_tree_by_subneighbor(family, child_neigh, subneighbor, false);
}



include/ghosting/ghosting_functor.h

296  
297  
298  
299  
300  
301  
302  
   * may want to delete the no-longer-relevant parts of those caches
   * after a redistribution is complete.
   */
  virtual void delete_remote_elements () {};

protected:
  const MeshBase * _mesh;

include/ghosting/overlap_coupling.h

88  
89  
90  
91  
92  
93  
94  
95  
  virtual void redistribute () override
  { this->mesh_reinit(); }

  virtual void delete_remote_elements() override
  { this->mesh_reinit(); }

  /**
   * For the specified range of active elements, find the elements

include/ghosting/point_neighbor_coupling.h

107  
108  
109  
110  
111  
112  
113  
114  
  virtual void redistribute () override
  { this->mesh_reinit(); }

  virtual void delete_remote_elements() override
  { this->mesh_reinit(); }

  /**
   * For the specified range of active elements, find the elements

include/mesh/replicated_mesh.h

109  
110  
111  
112  
113  
114  
115  
    libmesh_assert(*returnval == *this);
#endif
    return returnval;
  }

  /**
   * Destructor.
139  
140  
141  
142  
143  
144  
145  
146  
  virtual dof_id_type n_nodes () const override final
  { return _n_nodes; }

  virtual dof_id_type parallel_n_nodes () const override final
  { return _n_nodes; }

  virtual dof_id_type max_node_id () const override final
  { return cast_int<dof_id_type>(_nodes.size()); }
151  
152  
153  
154  
155  
156  
157  
158  
  virtual dof_id_type n_elem () const override final
  { return _n_elem; }

  virtual dof_id_type parallel_n_elem () const override final
  { return _n_elem; }

  virtual dof_id_type n_active_elem () const override final;

250  
251  
252  
253  
254  
255  
256  
  DECLARE_ELEM_ITERATORS(pid_, processor_id_type pid, pid)
  DECLARE_ELEM_ITERATORS(type_, ElemType type, type)

  DECLARE_ELEM_ITERATORS(active_subdomain_, subdomain_id_type sid, sid)
  DECLARE_ELEM_ITERATORS(active_subdomain_set_, std::set<subdomain_id_type> ss, ss)

  DECLARE_ELEM_ITERATORS(not_active_,,);
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
  DECLARE_ELEM_ITERATORS(active_pid_, processor_id_type pid, pid)
  DECLARE_ELEM_ITERATORS(local_level_, unsigned int level, level)
  DECLARE_ELEM_ITERATORS(local_not_level_, unsigned int level, level)
  DECLARE_ELEM_ITERATORS(active_local_subdomain_, subdomain_id_type sid, sid)
  DECLARE_ELEM_ITERATORS(active_local_subdomain_set_, std::set<subdomain_id_type> ss, ss)

  // Backwards compatibility
  virtual SimpleRange<element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_subdomain_element_ptr_range(sid); }
  virtual SimpleRange<const_element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) const override final { return active_subdomain_element_ptr_range(sid); }
  virtual SimpleRange<element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_local_subdomain_element_ptr_range(sid); }
  virtual SimpleRange<const_element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) const override final { return active_local_subdomain_element_ptr_range(sid); }
  virtual SimpleRange<element_iterator> active_subdomain_set_elements_ptr_range(std::set<subdomain_id_type> ss) override final { return active_subdomain_set_element_ptr_range(ss); }
  virtual SimpleRange<const_element_iterator> active_subdomain_set_elements_ptr_range(std::set<subdomain_id_type> ss) const override final { return active_subdomain_set_element_ptr_range(ss); }

include/numerics/dense_matrix_impl.h

218  
219  
220  
221  
222  
223  
224  
void DenseMatrix<T>::right_multiply_transpose (const DenseMatrix<T> & B)
{
  if (this->use_blas_lapack)
    this->_multiply_blas(B, RIGHT_MULTIPLY_TRANSPOSE);
  else
    this->_right_multiply_transpose(B);
}

include/numerics/petsc_vector.h

701  
702  
703  
704  
705  
706  
707  
      LibmeshPetscCall(VecGhostRestoreLocalForm(_vec,&localrep));
    }
  else
    this->_type = SERIAL;
}


811  
812  
813  
814  
815  
816  
817  
818  
  if (this->comm().size() == 1)
    {
      libmesh_assert(ghost.empty());
      this->init(n, n_local, fast, ptype);
      return;
    }

  PetscInt petsc_n=static_cast<PetscInt>(n);

include/parallel/parallel_ghost_sync.h

473  
474  
475  
476  
477  
478  
479  
        continue;
      const Elem * parent = elem->parent();
      if (!parent || !elem->active())
        continue;

      ghost_objects_from_proc[obj_procid]++;
    }
505  
506  
507  
508  
509  
510  
511  
        continue;
      const Elem * parent = elem->parent();
      if (!parent || !elem->active())
        continue;

      requested_objs_id[obj_procid].push_back(elem->id());
      requested_objs_parent_id_child_num[obj_procid].emplace_back
725  
726  
727  
728  
729  
730  
731  
              query_id[i] = node.id();
            }
          else
            query_id[i] = DofObject::invalid_id;
        }

      // Gather whatever data the user wants

include/reduced_basis/rb_scm_construction.h

130  
131  
132  
133  
134  
135  
136  
   * a negative value of the argument indicates we are
   * not performing a bounding box solve.
   */
  virtual void set_eigensolver_properties(int) {}

  /**
   * Set the name of the associated RB system --- we need
142  
143  
144  
145  
146  
147  
148  
149  
  /**
   * Get/set SCM_training_tolerance: tolerance for SCM greedy.
   */
  Real get_SCM_training_tolerance() const                         { return SCM_training_tolerance; }
  void set_SCM_training_tolerance(Real SCM_training_tolerance_in) { this->SCM_training_tolerance = SCM_training_tolerance_in; }

  /**
   * Perform the SCM greedy algorithm to develop a lower bound
159  
160  
161  
162  
163  
164  
165  
   * default is does nothing. Override in subclass to attach a specific
   * vector.
   */
  virtual void attach_deflation_space() {}

protected:

221  
222  
223  
224  
225  
226  
227  
   * indicator to be used in the SCM greedy.
   * Override in subclasses to specialize behavior.
   */
  virtual Real SCM_greedy_error_indicator(Real LB, Real UB) { return fabs(UB-LB)/fabs(UB); }

  //----------- PROTECTED DATA MEMBERS -----------//

include/solvers/eigen_solver.h

146  
147  
148  
149  
150  
151  
152  
   * Sets the position of the spectrum.
   */
  void set_position_of_spectrum (PositionOfSpectrum pos)
  {_position_of_spectrum= pos;}

  void set_position_of_spectrum (Real pos);
  void set_position_of_spectrum (Real pos, PositionOfSpectrum target);

include/systems/eigen_system.h

127  
128  
129  
130  
131  
132  
133  
  /**
   * \returns The number of converged eigenpairs.
   */
  unsigned int get_n_converged () const {return _n_converged_eigenpairs;}

  /**
   * \returns The number of eigen solver iterations.

include/systems/generic_projector.h

1810  
1811  
1812  
1813  
1814  
1815  
1816  
                {
                  erase_nonhanging_vars(node, remaining_vars, vertices);
                  if (remaining_vars.empty())
                    continue;
                }

              erase_copied_vars(node, false, remaining_vars);
1880  
1881  
1882  
1883  
1884  
1885  
1886  
                {
                  erase_nonhanging_vars(node, remaining_vars, vertices);
                  if (remaining_vars.empty())
                    continue;
                }

              erase_copied_vars(node, false, remaining_vars);

include/utils/mapvector.h

55  
56  
57  
58  
59  
60  
61  

    Val & operator*() const { return it->second; }

    index_t index() const { return it->first; }

    veclike_iterator & operator++() { ++it; return *this; }

src/fe/fe_lagrange.C

449  
450  
451  
452 +
453 +
454 +
455  
456 +
457  
458  
459 +
460 +
461  
462 +
463  
464  
465 +
466  
467  
468  
469 +
470  
471  
472  
  // here, reads the same ones.  What stays is what a header cannot do:
  // report our errors, and ask a polytope for the node count its element
  // type does not fix, which only makes it a first-order element.
  const unsigned int n = FECounts::lagrange_n_dofs(t, o);
  if (n != invalid_uint)
    return n;

  if (o == FIRST && (t == C0POLYGON || t == C0POLYHEDRON))
    {
      // Polygons and polyhedra require using newer FE APIs
      if (!e)
        libmesh_error_msg("Code (see stack trace) used an outdated FE function overload.\n"
                          "n_dofs() on a polygon or polyhedron is not defined by ElemType alone.");
      return e->n_nodes();
    }

  libmesh_error_msg_if(o > THIRD || o < CONSTANT,
                       "ERROR: Invalid Order " << Utility::enum_to_string(o) <<
                       " selected for LAGRANGE FE family!");

  libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) <<
                    " for " << Utility::enum_to_string(o) << " order approximation!");
}

934  
935  
936  
937  
938  
939  
940  
941  
942  
// of explicit instantiation at the end of this function.
// This could be macro-ified.
template <> unsigned int FE<0,LAGRANGE>::n_dofs(const ElemType t, const Order o) { return lagrange_n_dofs(t, nullptr, o); }
template <> unsigned int FE<1,LAGRANGE>::n_dofs(const ElemType t, const Order o) { return lagrange_n_dofs(t, nullptr, o); }
template <> unsigned int FE<2,LAGRANGE>::n_dofs(const ElemType t, const Order o) { return lagrange_n_dofs(t, nullptr, o); }
template <> unsigned int FE<3,LAGRANGE>::n_dofs(const ElemType t, const Order o) { return lagrange_n_dofs(t, nullptr, o); }

template <> unsigned int FE<0,LAGRANGE>::n_dofs(const Elem * e, const Order o) { return lagrange_n_dofs(e->type(), e, o); }
template <> unsigned int FE<1,LAGRANGE>::n_dofs(const Elem * e, const Order o) { return lagrange_n_dofs(e->type(), e, o); }

src/fe/fe_lagrange_shape_2D.C

349  
350  
351  
352 +
353  
354  
355  
            {
              // Compute quad shape functions as a tensor-product
              libmesh_assert_less (i, 4);
              return libMesh::detail::fe_lagrange_quad4_shape(i, p(0), p(1));
            }

          case TRI3:
358  
359  
360  
361 +
362  
363  
364  
          case TRI7:
            {
              libmesh_assert_less (i, 3);
              return libMesh::detail::fe_lagrange_tri3_shape(i, p(0), p(1));
            }

          case C0POLYGON:
410  
411  
412  
413 +
414  
415  
416  
          case QUADSHELL8:
            {
              libmesh_assert_less (i, 8);
              return libMesh::detail::fe_lagrange_quad8_shape(i, p(0), p(1));
            }

          case QUAD4:
421  
422  
423  
424 +
425  
426  
427  
          case QUADSHELL9:
            {
              libmesh_assert_less (i, 9);
              return libMesh::detail::fe_lagrange_quad9_shape(i, p(0), p(1));
            }

          case TRI3:
432  
433  
434  
435 +
436  
437  
438  
          case TRI7:
            {
              libmesh_assert_less (i, 6);
              return libMesh::detail::fe_lagrange_tri6_shape(i, p(0), p(1));
            }

          default:
450  
451  
452  
453 +
454  
455  
456  
          case TRI7:
            {
              libmesh_assert_less (i, 7);
              return libMesh::detail::fe_lagrange_tri7_shape(i, p(0), p(1));
            }

          default:
499  
500  
501  
502 +
503  
504  
505  
          case QUADSHELL9:
            {
              libmesh_assert_less (i, 4);
              return libMesh::detail::fe_lagrange_quad4_shape_deriv(i, j, p(0), p(1));
            }

          case TRI3:
508  
509  
510  
511 +
512  
513  
514  
          case TRI7:
            {
              libmesh_assert_less (i, 3);
              return libMesh::detail::fe_lagrange_tri3_shape_deriv(i, j);
            }

          case C0POLYGON:
598  
599  
600  
601 +
602  
603  
604  
          case QUADSHELL8:
            {
              libmesh_assert_less (i, 8);
              return libMesh::detail::fe_lagrange_quad8_shape_deriv(i, j, p(0), p(1));
            }

          case QUAD4:
609  
610  
611  
612 +
613  
614  
615  
          case QUADSHELL9:
            {
              libmesh_assert_less (i, 9);
              return libMesh::detail::fe_lagrange_quad9_shape_deriv(i, j, p(0), p(1));
            }

          case TRI3:
620  
621  
622  
623 +
624  
625  
626  
          case TRI7:
            {
              libmesh_assert_less (i, 6);
              return libMesh::detail::fe_lagrange_tri6_shape_deriv(i, j, p(0), p(1));
            }

          default:
638  
639  
640  
641 +
642  
643  
644  
          case TRI7:
            {
              libmesh_assert_less (i, 7);
              return libMesh::detail::fe_lagrange_tri7_shape_deriv(i, j, p(0), p(1));
            }

          default:
692  
693  
694  
695 +
696  
697  
698  
          case QUADSHELL9:
            {
              libmesh_assert_less (i, 4);
              return libMesh::detail::fe_lagrange_quad4_shape_second_deriv(i, j, p(0), p(1));
            }

          // All second derivatives for linear triangles are zero.
725  
726  
727  
728 +
729  
730  
731  
          case QUADSHELL8:
            {
              libmesh_assert_less (j, 3);
              return libMesh::detail::fe_lagrange_quad8_shape_second_deriv(i, j, p(0), p(1));
            } // end case QUAD8

          case QUAD4:
736  
737  
738  
739 +
740  
741  
742  
          case QUADSHELL9:
            {
              libmesh_assert_less (i, 9);
              return libMesh::detail::fe_lagrange_quad9_shape_second_deriv(i, j, p(0), p(1));
            } // end case QUAD9

          case TRI3:
747  
748  
749  
750 +
751  
752  
753  
          case TRI7:
            {
              libmesh_assert_less (j, 3);
              return libMesh::detail::fe_lagrange_tri6_shape_second_deriv(i, j);
            }  // end case TRI6+TRI7

          default:
770  
771  
772  
773 +
774  
775  
776  
          case TRI7:
            {
              libmesh_assert_less (j, 3);
              return libMesh::detail::fe_lagrange_tri7_shape_second_deriv(i, j, p(0), p(1));
            }  // end case TRI6+TRI7

          default:

src/fe/fe_lagrange_shape_3D.C

112  
113  
114  
115 +
116  
117  
118  
                  const Point & q_point = p[qp];

                  for (unsigned int i : make_range(n_sf))
                    v[i][qp] = libMesh::detail::fe_lagrange_hex8_shape(i, q_point(0), q_point(1), q_point(2));
                }
              return;
            }
143  
144  
145  
146 +
147  
148  
149  
                  const Point & q_point = p[qp];

                  for (unsigned int i : make_range(n_sf))
                    v[i][qp] = libMesh::detail::fe_lagrange_hex27_shape(i, q_point(0), q_point(1), q_point(2));
                }
              return;
            }
232  
233  
234  
235 +
236  
237 +
238 +
239 +
240  
241  
242  
              for (auto qp : index_range(p))
                {
                  const Point & q_point = p[qp];
                  for (unsigned int i : make_range(n_sf))
                    {
                      (*comps[0])[i][qp] = libMesh::detail::fe_lagrange_hex8_shape_deriv(i, 0, q_point(0), q_point(1), q_point(2));
                      (*comps[1])[i][qp] = libMesh::detail::fe_lagrange_hex8_shape_deriv(i, 1, q_point(0), q_point(1), q_point(2));
                      (*comps[2])[i][qp] = libMesh::detail::fe_lagrange_hex8_shape_deriv(i, 2, q_point(0), q_point(1), q_point(2));
                    }
                }
              return;
266  
267  
268  
269 +
270  
271 +
272 +
273 +
274  
275  
276  
              for (auto qp : index_range(p))
                {
                  const Point & q_point = p[qp];
                  for (unsigned int i : make_range(n_sf))
                    {
                      (*comps[0])[i][qp] = libMesh::detail::fe_lagrange_hex27_shape_deriv(i, 0, q_point(0), q_point(1), q_point(2));
                      (*comps[1])[i][qp] = libMesh::detail::fe_lagrange_hex27_shape_deriv(i, 1, q_point(0), q_point(1), q_point(2));
                      (*comps[2])[i][qp] = libMesh::detail::fe_lagrange_hex27_shape_deriv(i, 2, q_point(0), q_point(1), q_point(2));
                    }
                }
              return;
570  
571  
572  
573 +
574  
575  
576  
            {
              libmesh_assert_less (i, 8);

              return libMesh::detail::fe_lagrange_hex8_shape(i, p(0), p(1), p(2));
            }

            // linear tetrahedral shape functions
579  
580  
581  
582 +
583  
584  
585  
          case TET14:
            {
              libmesh_assert_less (i, 4);
              return libMesh::detail::fe_lagrange_tet4_shape(i, p(0), p(1), p(2));
            }

            // linear prism shape functions
692  
693  
694  
695 +
696  
697  
698  
          case HEX20:
            {
              libmesh_assert_less (i, 20);
              return libMesh::detail::fe_lagrange_hex20_shape(i, p(0), p(1), p(2));
            }

            // triquadratic hexahedral shape functions
704  
705  
706  
707 +
708  
709  
710  
            {
              libmesh_assert_less (i, 27);

              return libMesh::detail::fe_lagrange_hex27_shape(i, p(0), p(1), p(2));
            }

            // quadratic tetrahedral shape functions
718  
719  
720  
721 +
722  
723  
724  
          case TET14:
            {
              libmesh_assert_less (i, 14);
              return libMesh::detail::fe_lagrange_tet10_shape(i, p(0), p(1), p(2));
            }

            // "serendipity" prism
1115  
1116  
1117  
1118 +
1119  
1120  
1121  
          case TET14:
            {
              libmesh_assert_less (i, 14);
              return libMesh::detail::fe_lagrange_tet14_shape(i, p(0), p(1), p(2));
            }

          default:
1162  
1163  
1164  
1165 +
1166  
1167  
1168  
            {
              libmesh_assert_less (i, 8);

              return libMesh::detail::fe_lagrange_hex8_shape_deriv(i, j, p(0), p(1), p(2));
            }

            // linear tetrahedral shape functions
1171  
1172  
1173  
1174 +
1175  
1176  
1177  
          case TET14:
            {
              libmesh_assert_less (i, 4);
              return libMesh::detail::fe_lagrange_tet4_shape_deriv(i, j);
            }

            // linear prism shape functions
1415  
1416  
1417  
1418 +
1419  
1420  
1421  
          case HEX20:
            {
              libmesh_assert_less (i, 20);
              return libMesh::detail::fe_lagrange_hex20_shape_deriv(i, j, p(0), p(1), p(2));
            }

            // triquadratic hexahedral shape functions
1427  
1428  
1429  
1430 +
1431  
1432  
1433  
            {
              libmesh_assert_less (i, 27);

              return libMesh::detail::fe_lagrange_hex27_shape_deriv(i, j, p(0), p(1), p(2));
            }

            // quadratic tetrahedral shape functions
1439  
1440  
1441  
1442 +
1443  
1444  
1445  
          case TET14:
            {
              libmesh_assert_less (i, 10);
              return libMesh::detail::fe_lagrange_tet10_shape_deriv(i, j, p(0), p(1), p(2));
            }


2044  
2045  
2046  
2047 +
2048  
2049  
2050  
          case TET14:
            {
              libmesh_assert_less (i, 14);
              return libMesh::detail::fe_lagrange_tet14_shape_deriv(i, j, p(0), p(1), p(2));
            }

          case PRISM20:
2335  
2336  
2337  
2338 +
2339  
2340  
2341  
          case HEX27:
            {
              libmesh_assert_less (i, 8);
              return libMesh::detail::fe_lagrange_hex8_shape_second_deriv(i, j, p(0), p(1), p(2));
            }

          // All second derivatives for piecewise-linear polyhedra are
2362  
2363  
2364  
2365 +
2366  
2367  
2368  
          case HEX20:
            {
              libmesh_assert_less (i, 20);
              return libMesh::detail::fe_lagrange_hex20_shape_second_deriv(i, j, p(0), p(1), p(2));
            }

            // triquadratic hexahedral shape functions
2373  
2374  
2375  
2376 +
2377  
2378  
2379  
          case HEX27:
            {
              libmesh_assert_less (i, 27);
              return libMesh::detail::fe_lagrange_hex27_shape_second_deriv(i, j, p(0), p(1), p(2));
            }

            // quadratic tetrahedral shape functions
2384  
2385  
2386  
2387 +
2388 +
2389  
2390  
2391  
          case TET10:
          case TET14:
            {
              libmesh_assert_less (i, 10);
              return libMesh::detail::fe_lagrange_tet10_shape_second_deriv(i, j);
            }


3488  
3489  
3490  
3491 +
3492  
3493  
3494  
          case TET14:
            {
              libmesh_assert_less (i, 14);
              return libMesh::detail::fe_lagrange_tet14_shape_second_deriv(i, j, p(0), p(1), p(2));
            }

          case PRISM20:

src/fe/fe_monomial.C

39  
40  
41  
42 +
43  
44 +
45  
46  
47  
48 +
49  
50  
51  
{
  // The counts live in a header so that device code, which cannot call in
  // here, reads the same ones; reporting the error stays here.
  const unsigned int n = FECounts::monomial_n_dofs(t, o);

  libmesh_error_msg_if(n == invalid_uint,
                       "ERROR: Bad ElemType = " << Utility::enum_to_string(t) <<
                       " for " << Utility::enum_to_string(o) << " order approximation!");

  return n;
} // monomial_n_dofs()


121  
122  
123  
124  
125  
126  
127  
128  
129  

// Full specialization of n_dofs() function for every dimension
template <> unsigned int FE<0,MONOMIAL>::n_dofs(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
template <> unsigned int FE<1,MONOMIAL>::n_dofs(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
template <> unsigned int FE<2,MONOMIAL>::n_dofs(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
template <> unsigned int FE<3,MONOMIAL>::n_dofs(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }

template <> unsigned int FE<0,MONOMIAL>::n_dofs(const Elem * e, const Order o) { return monomial_n_dofs(e, o); }
template <> unsigned int FE<1,MONOMIAL>::n_dofs(const Elem * e, const Order o) { return monomial_n_dofs(e, o); }

src/geom/elem.C

1425  
1426  
1427  
1428  
1429  
1430  
1431  
      // want to handle neighbor links from subactive descendents.
      const unsigned int member_level = neigh_family_member->level();
      if (member_level < this_level)
        continue;

      // Ideally, the neighbor link ought to either be correct
      // already or ought to be to remote_elem.
1456  
1457  
1458  
1459  
1460  
1461  
1462  
1463  
          if (this->ancestor())
            continue;

          if (member_subactive && this->has_children())
            continue;
        }

      // If neigh is at a coarser level than us, some of neigh's
1467  
1468  
1469  
1470  
1471  
1472  
1473  
1474  
1475  
1476  
1477  
        {
          libmesh_assert(member_subactive);

          this->side_ptr(my_side, n);
          neigh_family_member->side_ptr(neigh_side, nn);

          if (*my_side != *neigh_side)
            continue;
        }

      neigh_family_member->set_neighbor(nn, this);
1541  
1542  
1543  
1544  
1545  
1546  
1547  
              // neighbor
              Elem * my_ancestor = this->parent();
              libmesh_assert(my_ancestor);
              while (!neigh->has_neighbor(my_ancestor))
                {
                  my_ancestor = my_ancestor->parent();
                  libmesh_assert(my_ancestor);
1550  
1551  
1552  
1553  
1554  
1555  
1556  
1557  
1558  
1559  
1560  
1561  
1562  
1563  
1564  
1565  
1566  
1567  
              // My neighbor may have descendants which consider me a
              // neighbor
              std::vector<Elem *> family;
              neigh->total_family_tree_by_subneighbor (family, my_ancestor, this);

              for (auto & n : family)
                {
                  libmesh_assert (n);
                  if (n->is_remote())
                    continue;
                  unsigned int my_s = n->which_neighbor_am_i(this);
                  libmesh_assert_less (my_s, n->n_neighbors());
                  libmesh_assert_equal_to (n->neighbor_ptr(my_s), this);
                  // TODO: we may want to make remote_elem non-const.
                  n->set_neighbor(my_s, const_cast<RemoteElem *>(remote_elem));
                }
            }
#endif
2377  
2378  
2379  
2380  
2381  
2382  
2383  
2384  
2385  
2386  
2387  
2388  
2389  



void Elem::total_family_tree_by_subneighbor (std::vector<Elem *> & family,
                                             Elem * neighbor,
                                             Elem * subneighbor,
                                             bool reset)
{
  ElemInternal::total_family_tree_by_subneighbor(this, family, neighbor, subneighbor, reset);
}



src/ghosting/ghost_point_neighbors.C

183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
      if (check_disjoint_bcs)
        {
          // Also ghost their disjoint neighbors
          for (auto s : elem->side_index_range())
          {
            for (const auto & [id, boundary_ptr] : *db)
            {
              if (!_mesh->get_boundary_info().has_boundary_id(elem, s, id))
                continue;

              unsigned int neigh_side = invalid_uint;
              const Elem * neigh =
                  db->neighbor(id, *point_locator, elem, s, &neigh_side);

              if (!neigh || neigh == remote_elem)
                continue;

              if (neigh->processor_id() != p)
                coupled_elements.emplace(neigh, nullcm);
            }
          }
        }

src/mesh/boundary_info.C

333  
334  
335  
336  
337  
338  
339  
                    other_boundary_info._ns_id_to_name) ||
      !compare_maps(_es_id_to_name,
                    other_boundary_info._es_id_to_name))
    return false;

  return true;
}
447  
448  
449  
450  
451  
452  
453  
  std::set<boundary_id_type> request_boundary_ids(_boundary_ids);
  request_boundary_ids.insert(invalid_id);
  if (!_mesh->is_serial())
    this->comm().set_union(request_boundary_ids);

  this->sync(request_boundary_ids,
             boundary_mesh);
483  
484  
485  
486  
487  
488  
489  
   * easily misused.
   */
  if (!_mesh->is_serial())
    boundary_mesh.delete_remote_elements();

  /**
   * If the boundary_mesh is still serial, that means we *can't*
504  
505  
506  
507  
508  
509  
510  
   */
  std::unique_ptr<MeshBase> mesh_copy;
  if (boundary_mesh.is_serial() && !_mesh->is_serial())
    mesh_copy = _mesh->clone();

  auto serializer = std::make_unique<MeshSerializer>
    (const_cast<MeshBase &>(*_mesh), boundary_mesh.is_serial());
573  
574  
575  
576  
577  
578  
579  
580  
581  
582  
583  
584  
585  
586  
587  
  // leave those pointers dangling.  Fix them up if needed.
  if (mesh_copy.get())
    {
      for (auto & new_elem : boundary_mesh.element_ptr_range())
        {
          const dof_id_type interior_parent_id =
            new_elem->interior_parent()->id();

          if (!mesh_copy->query_elem_ptr(interior_parent_id))
            new_elem->set_interior_parent
              (const_cast<RemoteElem *>(remote_elem));
        }
    }

  // Don't repartition this mesh; we want it to stay in sync with the
872  
873  
874  
875  
876  
877  
878  
879  
880  
881  
882  
883  
      if (elem->has_children())
        for (auto c : make_range(elem->n_children()))
          if (elem->child_ptr(c) == remote_elem &&
              elem->is_child_on_side(c, s))
            {
              for (auto sc : make_range(new_elem->n_children()))
                if (!new_elem->raw_child_ptr(sc))
                  new_elem->add_child
                    (const_cast<RemoteElem*>(remote_elem), sc);
            }
#endif

886  
887  
888  
889  
890  
891  
892  
893  
894  
895  
896  
897  
898  
899  
900  
901  
902  
903  
904  
905  
906  
907  
908  
909  
910  
911  
912  
913  
914  
915  
916  
917  
918  
919  
920  
921  
922  
923  
924  
925  
926  
927  
      // On non-local elements on DistributedMesh we might have
      // RemoteElem neighbor links to construct
      if (!_mesh->is_serial() &&
          (elem->processor_id() != this->processor_id()))
        {
          const unsigned short n_nodes = elem->n_nodes();

          const unsigned short bdy_n_sides = new_elem->n_sides();
          const unsigned short bdy_n_nodes = new_elem->n_nodes();

          // Check every interior side for a RemoteElem
          for (auto interior_side : elem->side_index_range())
            {
              // Might this interior side have a RemoteElem that
              // needs a corresponding Remote on a boundary side?
              if (elem->neighbor_ptr(interior_side) != remote_elem)
                continue;

              // Which boundary side?
              for (unsigned short boundary_side = 0;
                   boundary_side != bdy_n_sides; ++boundary_side)
                {
                  // Look for matching node points.  This is safe in
                  // *this* context.
                  bool found_all_nodes = true;
                  for (unsigned short boundary_node = 0;
                       boundary_node != bdy_n_nodes; ++boundary_node)
                    {
                      if (!new_elem->is_node_on_side(boundary_node,
                                                     boundary_side))
                        continue;

                      bool found_this_node = false;
                      for (unsigned short interior_node = 0;
                           interior_node != n_nodes; ++interior_node)
                        {
                          if (!elem->is_node_on_side(interior_node,
                                                     interior_side))
                            continue;

                          if (new_elem->point(boundary_node) ==
                              elem->point(interior_node))
930  
931  
932  
933  
934  
935  
936  
937  
938  
939  
940  
941  
942  
943  
944  
945  
946  
                              break;
                            }
                        }
                      if (!found_this_node)
                        {
                          found_all_nodes = false;
                          break;
                        }
                    }

                  if (found_all_nodes)
                    {
                      new_elem->set_neighbor
                        (boundary_side,
                         const_cast<RemoteElem *>(remote_elem));
                      break;
                    }
1185  
1186  
1187  
1188  
1189  
1190  
1191  
  // Don't add the same ID twice
  for (const auto & pr : as_range(_boundary_shellface_id.equal_range(elem)))
    if (pr.second.first == shellface &&
        pr.second.second == id)
      return;

  _boundary_shellface_id.emplace(elem, std::make_pair(shellface, id));
2493  
2494  
2495  
2496  
2497  
2498  
2499  
2500  
2501  
2502  
2503  
2504  
2505  
2506  
2507  
2508  
2509  

#ifdef LIBMESH_ENABLE_AMR

          while (p != nullptr)
          {
            const Elem * parent = p->parent();
            if (parent && !parent->is_child_on_side(parent->which_child_am_i(p), side))
              break;
            p = parent;
          }
#endif
          // We're on that side of our top_parent; return it
          if (!p)
            returnval.push_back(side);
        }
        // Otherwise we trust what we got and return the side
        else
2676  
2677  
2678  
2679  
2680  
2681  
2682  
2683  
  std::size_t n_edge_bcs=0;

  for (const auto & pr : _boundary_edge_id)
    if (pr.first->processor_id() == this->processor_id())
      n_edge_bcs++;

  this->comm().sum (n_edge_bcs);

2698  
2699  
2700  
2701  
2702  
2703  
2704  
2705  
  std::size_t n_shellface_bcs=0;

  for (const auto & pr : _boundary_shellface_id)
    if (pr.first->processor_id() == this->processor_id())
      n_shellface_bcs++;

  this->comm().sum (n_shellface_bcs);

2804  
2805  
2806  
2807  
2808  
2809  
2810  
2811  
2812  
              if (!mesh_is_serial)
                {
                  const processor_id_type proc_id =
                    side->node_ptr(i)->processor_id();
                  if (proc_id != my_proc_id)
                    nodes_to_push[proc_id].emplace(side->node_id(i), bcid);
                }
            }
        }
2819  
2820  
2821  
2822  
2823  
2824  
2825  
2826  
2827  
2828  
2829  
2830  
2831  
2832  
2833  
2834  
2835  
2836  
2837  
2838  
2839  
2840  
2841  
  // Otherwise we need to push ghost node bcids to their owners, then
  // pull ghost node bcids from their owners.

  for (auto & [proc_id, s] : nodes_to_push)
    {
      node_vecs_to_push[proc_id].assign(s.begin(), s.end());
      s.clear();
    }

  auto nodes_action_functor =
    [this]
    (processor_id_type,
     const vec_type & received_nodes)
    {
      for (const auto & [dof_id, bndry_id] : received_nodes)
        this->add_node(_mesh->node_ptr(dof_id), bndry_id);
    };

  Parallel::push_parallel_vector_data
    (this->comm(), node_vecs_to_push, nodes_action_functor);

  // At this point we should know all the BCs for our own nodes; now
  // we need BCs for ghost nodes.
2843  
2844  
2845  
2846  
2847  
2848  
2849  
2850  
2851  
2852  
2853  
2854  
2855  
2856  
2857  
2858  
2859  
2860  
2861  
2862  
2863  
2864  
2865  
2866  
2867  
2868  
2869  
2870  
2871  
2872  
2873  
2874  
2875  
2876  
2877  
2878  
2879  
2880  
2881  
2882  
2883  
    node_ids_requested;

  // Determine what nodes we need to request
  for (const auto & node : _mesh->node_ptr_range())
    {
      const processor_id_type pid = node->processor_id();
      if (pid != my_proc_id)
        node_ids_requested[pid].push_back(node->id());
    }

  typedef std::vector<boundary_id_type> datum_type;

  auto node_bcid_gather_functor =
    [this]
    (processor_id_type,
     const std::vector<dof_id_type> & ids,
     std::vector<datum_type> & data)
    {
      const std::size_t query_size = ids.size();
      data.resize(query_size);

      for (std::size_t i=0; i != query_size; ++i)
        this->boundary_ids(_mesh->node_ptr(ids[i]), data[i]);
    };

  auto node_bcid_action_functor =
    [this]
    (processor_id_type,
     const std::vector<dof_id_type> & ids,
     const std::vector<datum_type> & data)
    {
      for (auto i : index_range(ids))
        this->add_node(_mesh->node_ptr(ids[i]), data[i]);
    };

  datum_type * datum_type_ex = nullptr;
  Parallel::pull_parallel_vector_data
    (this->comm(), node_ids_requested, node_bcid_gather_functor,
     node_bcid_action_functor, datum_type_ex);
}

3108  
3109  
3110  
3111  
3112  
3113  
3114  
3115  
3116  
3117  
3118  
        // subdomain id.
        if (neigh == remote_elem)
          {
            const processor_id_type pid = elem->processor_id();
            sides_requested[pid].emplace_back(elem->id(), side);
            requested_boundary_ids[pid].push_back(std::move(matched_ids));
            continue;
          }

        add_matched_side(elem, side, matched_ids);
      } // end for side
3132  
3133  
3134  
3135  
3136  
3137  
3138  
3139  
3140  
3141  
3142  
3143  
3144  
3145  
3146  
3147  
  // below rather than skipping it when its own request list is empty.

  auto neighbor_subdomain_gather_functor =
    [this]
    (processor_id_type,
     const std::vector<elem_side_type> & elem_sides,
     std::vector<subdomain_id_type> & neighbor_subdomains)
    {
      neighbor_subdomains.resize(elem_sides.size());
      for (auto i : index_range(elem_sides))
        {
          const Elem & elem = _mesh->elem_ref(elem_sides[i].first);
          const Elem * neigh = elem.neighbor_ptr(elem_sides[i].second);

          // The requester saw a RemoteElem neighbor here, so there is
          // a neighbor, and we own elem, so our connectivity for it is
3149  
3150  
3151  
3152  
3153  
3154  
3155  
3156  
3157  
3158  
3159  
3160  
3161  
3162  
3163  
3164  
3165  
3166  
3167  
3168  
3169  
3170  
3171  
3172  
3173  
3174  
          libmesh_assert(neigh);
          libmesh_assert(neigh != remote_elem);

          neighbor_subdomains[i] = neigh->subdomain_id();
        }
    };

  auto neighbor_subdomain_action_functor =
    [this, &requested_boundary_ids, &add_matched_side]
    (processor_id_type pid,
     const std::vector<elem_side_type> & elem_sides,
     const std::vector<subdomain_id_type> & neighbor_subdomains)
    {
      const auto & bids = libmesh_map_find(requested_boundary_ids, pid);
      libmesh_assert_equal_to(bids.size(), elem_sides.size());

      for (auto i : index_range(elem_sides))
        {
          const Elem * elem = _mesh->elem_ptr(elem_sides[i].first);

          // If the side turned out to be truly interior after all,
          // skip it.
          if (neighbor_subdomains[i] != elem->subdomain_id())
            add_matched_side(elem, elem_sides[i].second, bids[i]);
        }
    };

src/mesh/distributed_mesh.C

870  
871  
872  
873  
874  
875  
876  
877  
878  
879  
880  
881  
882  
883  
884  
885  
886  
887  
888  
}


void DistributedMesh::own_node (Node & n)
{
  // This had better be a node in our mesh
  libmesh_assert(_nodes[n.id()] == &n);

  _nodes[n.id()] = nullptr;
  _n_nodes--;

  n.set_id(DofObject::invalid_id);
  n.processor_id() = this->processor_id();

  this->add_node(&n);
}


Node * DistributedMesh::add_node (Node * n)
1617  
1618  
1619  
1620  
1621  
1622  
1623  
1624  
1625  
1626  
1627  
1628  
1629  
1630  
1631  
1632  
1633  
1634  
1635  
1636  
1637  
              // else does, better figure out who should own it next.
              if (!used_nodes.count(n))
                {
                  if (auto it = repartitioned_node_pids.find(n);
                      sender_could_become_owner)
                    {
                      if (it != repartitioned_node_pids.end() &&
                          pid < it->second)
                        it->second = pid;
                      else
                        repartitioned_node_pids[n] = pid;
                    }
                  else
                    if (it == repartitioned_node_pids.end())
                      repartitioned_node_pids[n] =
                        DofObject::invalid_processor_id;

                  repartitioned_node_sets_to_push[pid].insert(n);
                }
            }
        };
1645  
1646  
1647  
1648  
1649  
1650  
1651  
1652  
1653  
1654  
      // Repartition (what used to be) our own nodes first
      for (auto & [n, p] : repartitioned_node_pids)
        {
          Node & node = this->node_ref(n);
          libmesh_assert_equal_to(node.processor_id(), this->processor_id());
          libmesh_assert_not_equal_to_msg(p, DofObject::invalid_processor_id, "Node " << n << " is lost?");
          node.processor_id() = p;
        }

      // Then push to repartition others' ghosted copies.
1658  
1659  
1660  
1661  
1662  
1663  
1664  
1665  
1666  
1667  
1668  
1669  
1670  
1671  
1672  
1673  
1674  
1675  
1676  
1677  
1678  
1679  

      for (auto & [p, nodeset] : repartitioned_node_sets_to_push)
        {
          auto & rn_vec = repartitioned_node_vecs[p];
          for (auto n : nodeset)
            rn_vec.emplace_back(n, repartitioned_node_pids[n]);
        }

      auto repartition_node_functor =
        [this]
        (processor_id_type libmesh_dbg_var(pid),
         const std::vector<std::pair<dof_id_type, processor_id_type>> & ids_and_pids)
        {
          for (auto [n, p] : ids_and_pids)
            {
              libmesh_assert_not_equal_to(p, DofObject::invalid_processor_id);
              Node & node = this->node_ref(n);
              libmesh_assert_equal_to(node.processor_id(), pid);
              node.processor_id() = p;
            }
        };

1756  
1757  
1758  
1759  
1760  
1761  
1762  
1763  
1764  
1765  
1766  
1767  
1768  
1769  
1770  
1771  
1772  
1773  
1774  
1775  
1776  
1777  
1778  
1779  
1780  
1781  
1782  
1783  
1784  
1785  
1786  
1787  
1788  
1789  
1790  
1791  
1792  



void DistributedMesh::fix_broken_node_and_element_numbering ()
{
  // We can't use range-for here because we need access to the special
  // iterators' methods, not just to their dereferenced values.

  // Nodes first
  for (auto pr = this->_nodes.begin(),
           end = this->_nodes.end(); pr != end; ++pr)
    {
      Node * n = *pr;
      if (n != nullptr)
        {
          const dof_id_type id = pr.index();
          n->set_id() = id;
          libmesh_assert_equal_to(this->node_ptr(id), n);
        }
    }

  // Elements next
  for (auto pr = this->_elements.begin(),
           end = this->_elements.end(); pr != end; ++pr)
    {
      Elem * e = *pr;
      if (e != nullptr)
        {
          const dof_id_type id = pr.index();
          e->set_id() = id;
          libmesh_assert_equal_to(this->elem_ptr(id), e);
        }
    }
}



src/mesh/exodusII_io_helper.C

2292  
2293  
2294  
2295  
2296  
2297  
2298  

  // Do nothing if no variables are detected
  if (count == 0)
    return;

  // Second read the actual names and convert them into a format we can use
  NamesData names_table(count, libmesh_max_str_length);

src/mesh/mesh_communication.C

143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
      const auto & constraint_rows = mesh->get_constraint_rows();

      std::unordered_set<const Elem *> constraining_nodes_elems;
      for (const Elem * elem : connected_elements)
        {
          for (const Node & node : elem->node_ref_range())
            {
              // Retain all elements containing constraining nodes
              if (const auto it = constraint_rows.find(&node);
                  it != constraint_rows.end())
                for (auto & p : it->second)
                  {
                    const Elem * constraining_elem = p.first.first;
                    libmesh_assert(constraining_elem ==
                                   mesh->elem_ptr(constraining_elem->id()));
                    if (!connected_elements.count(constraining_elem) &&
162  
163  
164  
165  
166  
167  
168  
            }
        }

      newer_connected_elements.insert(constraining_nodes_elems.begin(),
                                      constraining_nodes_elems.end());
    }

208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
          if (e->active() && e->has_children())
            {
              std::vector<const Elem *> subactive_family;
              e->total_family_tree(subactive_family);
              for (const auto & f : subactive_family)
                {
                  libmesh_assert(f != remote_elem);
                  if (!connected_elements.count(f) &&
                      !new_connected_elements.count(f))
                    newer_connected_elements.insert(f);
                }
            }
        };
583  
584  
585  
586  
587  
588  
589  
590  
591  
592  
593  
594  
595  
596  
597  
598  
599  

      for (auto & [node, row] : constraint_rows)
        {
          if (!connected_nodes.count(node))
            continue;

          serialized_row_type serialized_row;
          for (auto [elem_and_node, coef] : row)
            serialized_row.emplace_back(std::make_pair(elem_and_node.first->id(),
                                                       elem_and_node.second),
                                        coef);

          all_constraint_rows_to_send[pid].emplace_back
            (node->id(), std::move(serialized_row));
        }
    }

616  
617  
618  
619  
620  
621  
622  
623  
624  
625  
626  
627  
628  
629  
630  
631  
632  
633  
634  
635  
636  
637  
638  
  if (have_constraint_rows)
    {
      auto constraint_row_action =
        [&mesh, &constraint_rows]
        (processor_id_type /* src_pid */,
         const std::vector<std::pair<dof_id_type, serialized_row_type>> rows)
        {
          for (auto & [node_id, serialized_row] : rows)
            {
              MeshBase::constraint_rows_mapped_type row;
              for (auto [elem_and_node, coef] : serialized_row)
                row.emplace_back(std::make_pair(mesh.elem_ptr(elem_and_node.first),
                                                elem_and_node.second),
                                 coef);

              constraint_rows[mesh.node_ptr(node_id)] = row;
            }
        };

      TIMPI::push_parallel_vector_data(mesh.comm(),
                                       all_constraint_rows_to_send,
                                       constraint_row_action);

1090  
1091  
1092  
1093  
1094  
1095  
1096  
      // the parent's owner needs us to send them.
      const processor_id_type their_proc_id = elem->parent()->processor_id();
      if (their_proc_id != proc_id)
        coarsening_elements_to_ghost[their_proc_id].push_back(elem);
    }

  std::map<processor_id_type, std::vector<const Node *>> all_nodes_to_send;
1114  
1115  
1116  
1117  
1118  
1119  
1120  
1121  
1122  
1123  
1124  
1125  
1126  
1127  
1128  
1129  
1130  
1131  
1132  
1133  
1134  
1135  
1136  
1137  
1138  
1139  
1140  
1141  
1142  
1143  
1144  
1145  
1146  
1147  
1148  
1149  
1150  
1151  
1152  

          // Make some fake element iterators defining this vector of
          // elements
          Elem * const * elempp = const_cast<Elem * const *>(elems.data());
          Elem * const * elemend = elempp+elems.size();
          const MeshBase::const_element_iterator elem_it =
            MeshBase::const_element_iterator(elempp, elemend, Predicates::NotNull<Elem * const *>());
          const MeshBase::const_element_iterator elem_end =
            MeshBase::const_element_iterator(elemend, elemend, Predicates::NotNull<Elem * const *>());

          for (auto & gf : as_range(mesh.ghosting_functors_begin(),
                                    mesh.ghosting_functors_end()))
            {
              GhostingFunctor::map_type elements_to_ghost;
              libmesh_assert(gf);
              (*gf)(elem_it, elem_end, p, elements_to_ghost);

              // We can ignore the CouplingMatrix in ->second, but we
              // need to ghost all the elements in ->first.
              for (auto & pr : elements_to_ghost)
                {
                  const Elem * elem = pr.first;
                  libmesh_assert(elem);
                  while (elem)
                    {
                      libmesh_assert(elem != remote_elem);
                      elements_to_send.insert(elem);
                      for (auto & n : elem->node_ref_range())
                        nodes_to_send.insert(&n);
                      elem = elem->parent();
                    }
                }
            }

          all_nodes_to_send[p].assign(nodes_to_send.begin(), nodes_to_send.end());
          all_elems_to_send[p].assign(elements_to_send.begin(), elements_to_send.end());
        }
    }

1395  
1396  
1397  
1398  
1399  
1400  
1401  
1402  
1403  
1404  
1405  
1406  
1407  
1408  
1409  
1410  
1411  
1412  
1413  
1414  
1415  
1416  
1417  
1418  
1419  
1420  
1421  
1422  
1423  
1424  
1425  
1426  
1427  
1428  
1429  
1430  
1431  
1432  
1433  
1434  
1435  
1436  
1437  
1438  
               std::vector<std::tuple<dof_id_type, unsigned int, Real>>>
        serialized_rows;

      for (auto & row : constraint_rows)
        {
          const Node * node = row.first;
          const dof_id_type rowid = node->id();
          libmesh_assert(node == mesh.node_ptr(rowid));

          std::vector<std::tuple<dof_id_type, unsigned int, Real>>
            serialized_row;
          for (auto & entry : row.second)
            serialized_row.push_back
              (std::make_tuple(entry.first.first->id(),
                               entry.first.second, entry.second));

          serialized_rows.emplace(rowid, std::move(serialized_row));
        }

      if (root_id == DofObject::invalid_processor_id)
        mesh.comm().set_union(serialized_rows);
      else
        mesh.comm().set_union(serialized_rows, root_id);

      if (root_id == DofObject::invalid_processor_id ||
          root_id == mesh.processor_id())
        {
          for (auto & row : serialized_rows)
            {
              const dof_id_type rowid = row.first;
              const Node * node = mesh.node_ptr(rowid);

              std::vector<std::pair<std::pair<const Elem *, unsigned int>, Real>>
                deserialized_row;
              for (auto & entry : row.second)
                deserialized_row.push_back
                  (std::make_pair(std::make_pair(mesh.elem_ptr(std::get<0>(entry)),
                                                 std::get<1>(entry)),
                                                 std::get<2>(entry)));

              constraint_rows.emplace(node, deserialized_row);
            }
        }
#ifdef DEBUG
1575  
1576  
1577  
1578  
1579  
1580  
1581  
          {
            // But we might have gotten a definitive id from a
            // different request
            if (!definitive_ids.count(mesh.node_ptr(old_id)))
              data_changed = true;
          }
        else
1604  
1605  
1606  
1607  
1608  
1609  
1610  
1611  
1612  
1613  
1614  
1615  
1616  
1617  
1618  
1619  
1620  
1621  
1622  
1623  
1624  
1625  
1626  
1627  
1628  
1629  
1630  
1631  
1632  
1633  
1634  
1635  
1636  
1637  
1638  
1639  
1640  
1641  
1642  
1643  
{
  typedef std::pair<unsigned char,unsigned char> datum;

  SyncPLevels(MeshBase & _mesh) :
    mesh(_mesh) {}

  MeshBase & mesh;

  // Find the p_level of each requested Elem
  void gather_data (const std::vector<dof_id_type> & ids,
                    std::vector<datum> & ids_out) const
  {
    ids_out.reserve(ids.size());

    for (const auto & id : ids)
      {
        Elem & elem = mesh.elem_ref(id);
        ids_out.push_back
          (std::make_pair(cast_int<unsigned char>(elem.p_level()),
                          static_cast<unsigned char>(elem.p_refinement_flag())));
      }
  }

  void act_on_data (const std::vector<dof_id_type> & old_ids,
                    const std::vector<datum> & new_p_levels) const
  {
    for (auto i : index_range(old_ids))
      {
        Elem & elem = mesh.elem_ref(old_ids[i]);
        // Make sure these are consistent
        elem.hack_p_level_and_refinement_flag
          (new_p_levels[i].first,
           static_cast<Elem::RefinementState>(new_p_levels[i].second));
        // Make sure parents' levels are consistent
        elem.set_p_level(new_p_levels[i].first);
      }
  }
};
#endif // LIBMESH_ENABLE_AMR

1828  
1829  
1830  
1831  
1832  
1833  
1834  

// ------------------------------------------------------------
#ifdef LIBMESH_ENABLE_AMR
void MeshCommunication::make_p_levels_parallel_consistent(MeshBase & mesh)
{
  // This function must be run on all processors at once
  libmesh_parallel_only(mesh.comm());
1837  
1838  
1839  
1840  
1841  
1842  
1843  
1844  
1845  

  SyncPLevels syncplevels(mesh);
  Parallel::sync_dofobject_data_by_id
    (mesh.comm(), mesh.elements_begin(), mesh.elements_end(),
     syncplevels);
}
#endif // LIBMESH_ENABLE_AMR


1898  
1899  
1900  
1901  
1902  
1903  
1904  
        if (node.processor_id() > proc_ids[i])
          {
            data_changed = true;
            node.processor_id() = proc_ids[i];
          }
      }

src/mesh/mesh_generation.C

2546  
2547  
2548  
2549  
2550  
2551  
2552  

  // If cross_section is distributed, so is its extrusion
  if (!cross_section.is_serial())
    mesh.delete_remote_elements();

  // We know a priori how many elements we'll need
  mesh.reserve_elem(nz*orig_elem);

src/mesh/mesh_modification.C

258  
259  
260  
261  
262  
263  
264  
      Elem * elem = mesh.query_elem_ptr(e_id);

      if (!elem)
        continue;

      const unsigned int max_permutation = elem->n_permutations();
      if (!max_permutation)
744  
745  
746  
747  
748  
749  
750  
751  
752  
753  
754  
755  
756  
757  
758  
759  
760  
761  
              // final tet.
              if (next_subelem == 3)
                {
                  subelem[next_subelem]->set_node(0, elem->node_ptr(opposing_nodes[highest_n][0]));
                  subelem[next_subelem]->set_node(1, elem->node_ptr(opposing_nodes[highest_n][1]));
                  subelem[next_subelem]->set_node(2, elem->node_ptr(opposing_nodes[highest_n][2]));
                  subelem[next_subelem]->set_node(3, elem->node_ptr(opposing_node[highest_n]));
                  subelem[next_subelem]->orient(&boundary_info);
                  ++next_subelem;

                  subelem[next_subelem]->set_node(0, elem->node_ptr(opposing_nodes[highest_n][0]));
                  subelem[next_subelem]->set_node(1, elem->node_ptr(opposing_nodes[highest_n][1]));
                  subelem[next_subelem]->set_node(2, elem->node_ptr(opposing_nodes[highest_n][2]));
                  subelem[next_subelem]->set_node(3, elem->node_ptr(highest_n));
                  subelem[next_subelem]->orient(&boundary_info);
                  ++next_subelem;

                  // We don't need the 6th tet after all

src/mesh/mesh_netgen_interface.C

484  
485  
486  
487  
488  
489  
490  
      std::array<double, 3> point_val;

      // We should only be getting new nodes if we asked for them
      if (!_desired_volume)
        {
          std::cout <<
            "NetGen output " << n_points <<
497  
498  
499  
500  
501  
502  
503  
504  
505  
506  
507  
508  
509  
510  
          libmesh_error();
        }
      else
        for (auto i : make_range(old_nodes, n_points))
          {
            // i+1 since ng uses ONE-BASED numbering
            Ng_GetPoint (ngmesh, i+1, point_val.data());
            const Point p(point_val[0], point_val[1], point_val[2]);
            Node * n_new = this->_mesh.add_point(p);
            const dof_id_type n_new_id = n_new->id();
            ng_to_libmesh_id[i+1] = n_new_id;
          }
    }

src/mesh/mesh_refinement.C

1021  
1022  
1023  
1024  
1025  
1026  
1027  
1028  
1029  
1030  
1031  
1032  
1033  
1034  
1035  
1036  
1037  
1038  
1039  
1040  
1041  
1042  
1043  
1044  
1045  
1046  
1047  
1048  
1049  
1050  
              // our change has to propagate to neighboring
              // processors.
              if (my_flag_changed && !_mesh.is_serial())
                for (auto n : elem->side_index_range())
                  {
                    Elem * neigh =
                      topological_neighbor(elem, point_locator.get(), n);

                    if (!neigh)
                      continue;
                    if (neigh == remote_elem ||
                        neigh->processor_id() !=
                        this->processor_id())
                      {
                        compatible_with_refinement = false;
                        break;
                      }
                    // FIXME - for non-level one meshes we should
                    // test all descendants
                    if (neigh->has_children())
                      for (auto & child : neigh->child_ref_range())
                        if (&child == remote_elem ||
                            child.processor_id() !=
                            this->processor_id())
                          {
                            compatible_with_refinement = false;
                            break;
                          }
                  }
            }
1133  
1134  
1135  
1136  
1137  
1138  
1139  
                break;
              if (child.processor_id() != elem->processor_id())
                {
                  uncoarsenable_parents[elem->processor_id()].push_back(elem->id());
                  break;
                }
            }
1177  
1178  
1179  
1180  
1181  
1182  
1183  

          for (const auto & id : my_uncoarsenable_parents)
            {
              Elem & elem = _mesh.elem_ref(id);
              libmesh_assert(elem.refinement_flag() == Elem::INACTIVE ||
                             elem.refinement_flag() == Elem::COARSEN_INACTIVE);
              elem.set_refinement_flag(Elem::INACTIVE);
1514  
1515  
1516  
1517  
1518  
1519  
1520  
  // levels changed in sync
  if (mesh_p_changed && !_mesh.is_serial())
    {
      MeshCommunication().make_p_levels_parallel_consistent (_mesh);
    }

  return (mesh_changed || mesh_p_changed);
1601  
1602  
1603  
1604  
1605  
1606  
1607  
1608  
1609  
          if (elem->p_refinement_flag() == Elem::REFINE &&
              elem->active())
            {
              elem->set_p_level(elem->p_level()+1);
              elem->set_p_refinement_flag(Elem::JUST_REFINED);
              mesh_p_changed = true;
            }
        }
    }
1647  
1648  
1649  
1650  
1651  
1652  
1653  

  if (mesh_p_changed && !_mesh.is_replicated())
    {
      MeshCommunication().make_p_levels_parallel_consistent (_mesh);
    }

  // Clear the _new_nodes_map and _unused_elements data structures.

src/mesh/mesh_tet_interface.C

200  
201  
202  
203  
204  
205  
206  
207  
208  
            // independent of element traversal.
            if (!mesh.is_replicated())
              {
                side_elem->set_id(max_orig_id + max_sides*elem->id() + s);
#ifdef LIBMESH_ENABLE_UNIQUE_ID
                side_elem->set_unique_id(max_unique_id + max_sides*elem->id() + s);
#endif
              }
          }
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
        typedef std::unordered_multimap<key_type, val_type> map_type;
        map_type side_to_elem_map;

        std::unique_ptr<Elem> my_side, their_side;

        for (auto & elem : elems_to_add)
          {
            for (auto s : elem->side_index_range())
              {
                if (elem->neighbor_ptr(s))
                  continue;
                const dof_id_type key = elem->low_order_key(s);
                auto bounds = side_to_elem_map.equal_range(key);
                if (bounds.first != bounds.second)
                  {
                    elem->side_ptr(my_side, s);
                    while (bounds.first != bounds.second)
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  

        // At this point we *should* have a match for everything, so
        // anything we don't have a match for is remote.
        for (auto & elem : elems_to_add)
          for (auto s : elem->side_index_range())
            if (!elem->neighbor_ptr(s))
              elem->set_neighbor(s, const_cast<RemoteElem*>(remote_elem));
      }

    // Remove volume and edge elements
    for (Elem * elem : elems_to_delete)

src/mesh/nemesis_io_helper.C

2880  
2881  
2882  
2883  
2884  
2885  
2886  
  processor_id_type pid_broadcasting_names = this->processor_id();
  const std::size_t n_names = result.size();
  if (!n_names)
    pid_broadcasting_names = DofObject::invalid_processor_id;

  libmesh_assert(this->comm().semiverify
                 (n_names ? nullptr : &n_names));

src/mesh/simplex_refiner.C

150  
151  
152  
153  
154  
155  
156  
157  
158  
      if (const processor_id_type pid = elem.processor_id();
          pid != _mesh.processor_id() && !_mesh.is_serial() &&
          !_desired_volume_func.get() &&
          elem.id() == coarse_id)
        edge_queries[pid].emplace_back(vertices.first->id(),
                                       vertices.second->id());

      // Test should_refine, but also test for any edges that were
      // already refined by neighbors, which might happen even if
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
  // some unsplit edges that could have been split by their
  // remote_elem neighbors, and we'll need to query those.
  auto edge_gather_functor =
    [this]
    (processor_id_type,
     const std::vector<std::pair<dof_id_type, dof_id_type>> & edges,
     std::vector<refinement_datum> & edge_refinements)
    {
      // Fill those requests
      const std::size_t query_size = edges.size();
      edge_refinements.resize(query_size);
      for (std::size_t i=0; i != query_size; ++i)
        {
          auto vertex_ids = edges[i];
          std::pair<Node *, Node *> vertices
            {_mesh.node_ptr(vertex_ids.first),
             _mesh.node_ptr(vertex_ids.second)};
          fill_refinement_datum(vertices, edge_refinements[i]);
        }
    };

  auto edge_action_functor =
    [this]
    (processor_id_type,
     const std::vector<std::pair<dof_id_type, dof_id_type>> &,
     const std::vector<refinement_datum> & edge_refinements
    )
    {
      for (const auto & one_edges_refinements : edge_refinements)
        for (const auto & refinement : one_edges_refinements)
          {
            std::pair<Node *, Node *> vertices
              {_mesh.node_ptr(std::get<0>(refinement)),
               _mesh.node_ptr(std::get<1>(refinement))};

            if ((Point&)(*vertices.first) >
                (Point&)(*vertices.second))
              std::swap(vertices.first, vertices.second);

            if (auto it = new_nodes.find(vertices);
                it != new_nodes.end())
              {
                _mesh.renumber_node(it->second->id(),
                                    std::get<2>(refinement));
                it->second->processor_id() = std::get<3>(refinement);
              }
            else
              {
                Node * new_node =
                  _mesh.add_point((*(Point*)vertices.first +
                                   *(Point*)vertices.second)/2,
                                  std::get<2>(refinement),
                                  std::get<3>(refinement));
                new_nodes[vertices] = new_node;
              }
          }
    };
419  
420  
421  
422  
423  
424  
425  
426  
427  
428  
429  
430  

      if (newly_refined_elements && !_mesh.is_replicated())
        {
          bool have_edge_queries = !edge_queries.empty();
          _mesh.comm().max(have_edge_queries);
          refinement_datum * refinement_data_ex = nullptr;
          if (have_edge_queries)
            Parallel::pull_parallel_vector_data
              (_mesh.comm(), edge_queries, edge_gather_functor,
               edge_action_functor, refinement_data_ex);
        }
    }
437  
438  
439  
440  
441  
442  
443  
444  
445  
446  
447  
448  
449  
450  
451  
452  
453  
      // and elements that still have temporary id and unique_id
      // values.  Give them permanent ones.
      std::unordered_map<processor_id_type, std::vector<dof_id_type>> elems_to_query;
      for (const auto & [coarse_id, added_elem_map] : added_elements)
        {
          if (added_elem_map.empty())
            continue;

          const processor_id_type pid =
            added_elem_map.begin()->second->processor_id();
          if (pid == _mesh.processor_id())
            continue;

          elems_to_query[pid].push_back(coarse_id);
        }

      // Return fine element data based on vertex_average()
460  
461  
462  
463  
464  
465  
466  
467  
468  
469  
470  
471  
472  
473  
474  
475  
476  
477  
478  
479  
480  
481  
482  
483  
484  
485  
486  
487  
488  
489  
490  
491  
492  
493  
494  
495  
496  
497  
498  
499  
500  
501  
502  
503  
504  
505  
506  
507  
508  
509  
510  
511  
512  
513  
514  
515  
516  
517  
518  
519  
520  
521  
522  
523  
524  
525  
526  
527  
528  
529  
530  
531  
532  
533  
534  
        elem_refinement_datum;

      auto added_gather_functor =
        [this]
        (processor_id_type,
         const std::vector<dof_id_type> & coarse_elems,
         std::vector<elem_refinement_datum> & coarse_refinements)
        {
          // Fill those requests
          const std::size_t query_size = coarse_elems.size();
          coarse_refinements.resize(query_size);
          for (auto i : make_range(query_size))
            {
              const dof_id_type coarse_id = coarse_elems[i];
              const auto & added =
                libmesh_map_find(added_elements, coarse_id);

              for (auto [vertex_avg, elem] : added)
                {
                  coarse_refinements[i].emplace_back
                    (vertex_avg,
                     elem->id()
#ifdef LIBMESH_ENABLE_UNIQUE_ID
                     , elem->unique_id()
#endif
                    );
                }
            }
        };

      auto added_action_functor =
        [this]
        (processor_id_type,
         const std::vector<dof_id_type> & coarse_elems,
         const std::vector<elem_refinement_datum> & coarse_refinements)
        {
          const std::size_t query_size = coarse_elems.size();
          for (auto i : make_range(query_size))
            {
              const dof_id_type coarse_id = coarse_elems[i];
              const auto & refinement_data = coarse_refinements[i];
              const auto & our_added =
                libmesh_map_find(added_elements, coarse_id);
              for (auto [vertex_avg, id
#ifdef LIBMESH_ENABLE_UNIQUE_ID
                         , unique_id
#endif
                   ] : refinement_data)
                {
                  Elem & our_elem = *libmesh_map_find(our_added,
                                                      vertex_avg);
                  libmesh_assert_equal_to(our_elem.vertex_average(),
                                          vertex_avg);

#ifdef LIBMESH_ENABLE_UNIQUE_ID
                  our_elem.set_unique_id(unique_id);
#endif
                  _mesh.renumber_elem(our_elem.id(), id);
                }
            }
        };

      elem_refinement_datum * refinement_data_ex = nullptr;
      Parallel::pull_parallel_vector_data
        (_mesh.comm(), elems_to_query, added_gather_functor,
         added_action_functor, refinement_data_ex);

      // That took care of our element ids; now get node ids.
      MeshCommunication mc;
      mc.make_node_proc_ids_parallel_consistent (_mesh);
      mc.make_node_ids_parallel_consistent (_mesh);
      mc.make_node_unique_ids_parallel_consistent (_mesh);
    }

  // In theory the operations on ghost elements are, after remote edge
564  
565  
566  
567  
568  
569  
570  
571  
572  
573  
574  
575  
576  
577  
578  
579  
580  
581  
582  
583  
584  
585  
586  
587  
588  
589  
590  
591  
592  
}


void SimplexRefiner::fill_refinement_datum(std::pair<Node *, Node *> vertices,
                                           refinement_datum & vec)
{
  auto it = new_nodes.find(vertices);
  if (it == new_nodes.end())
    return;

  vec.emplace_back(vertices.first->id(),
                   vertices.second->id(),
                   it->second->id(),
                   it->second->processor_id());

  std::pair<Node *, Node *> subedge {vertices.first, it->second};
  if ((Point&)(*subedge.first) >
      (Point&)(*subedge.second))
    std::swap(subedge.first, subedge.second);
  fill_refinement_datum(subedge, vec);

  subedge = std::make_pair(it->second, vertices.second);
  if ((Point&)(*subedge.first) >
      (Point&)(*subedge.second))
    std::swap(subedge.first, subedge.second);
  fill_refinement_datum(subedge, vec);
}


src/mesh/unstructured_mesh.C

225  
226  
227  
228  
229  
230  
231  
          if (!mesh.is_replicated() &&
              hi_node->processor_id() != my_pid &&
              chosen_pid == my_pid)
            mesh.own_node(*hi_node);

          hi_node->processor_id() = chosen_pid;
        }
1251  
1252  
1253  
1254  
1255  
1256  
1257  
                       // did not, then those likewise must be remote
                       // children.
                       (current_elem->subactive() && neigh->has_children() &&
                        (neigh->level()+1) == current_elem->level())))
                    {
#ifdef DEBUG
                      // Let's make sure that "had children made remote"
1269  
1270  
1271  
1272  
1273  
1274  
1275  
                        libmesh_assert_not_equal_to (current_elem->processor_id(),
                                                     this->processor_id());
#endif // DEBUG
                      neigh = const_cast<RemoteElem *>(remote_elem);
                    }
                  // If neigh and current_elem are more than one level
                  // apart, figuring out whether we have a remote
1362  
1363  
1364  
1365  
1366  
1367  
1368  
1369  
          // children to search.
          if (pip == remote_elem || pip->active())
            {
              current_elem->set_interior_parent(pip);
              continue;
            }

          // For node comparisons we'll need a sensible tolerance
1379  
1380  
1381  
1382  
1383  
1384  
1385  
1386  
              if (&child == remote_elem)
                {
                  current_elem->set_interior_parent
                    (const_cast<RemoteElem *>(remote_elem));
                  continue;
                }

              bool child_contains_our_nodes = true;

src/numerics/dense_matrix_blas_lapack.C

66  
67  
68  
69  
70  
71  
72  
73  
      libmesh_fallthrough();
    case RIGHT_MULTIPLY_TRANSPOSE:
      {
        result_size = other.m() * this->m();
        if (other.n() == this->n())
          break;
      }
      libmesh_fallthrough();
147  
148  
149  
150  
151  
152  
153  

  else if (flag == RIGHT_MULTIPLY_TRANSPOSE)
    {
      transa[0] = 't';
      std::swap(M,K);
    }

178  
179  
180  
181  
182  
183  
184  
    case LEFT_MULTIPLY:            { this->_m = other.m(); break; }
    case RIGHT_MULTIPLY:           { this->_n = other.n(); break; }
    case LEFT_MULTIPLY_TRANSPOSE:  { this->_m = other.n(); break; }
    case RIGHT_MULTIPLY_TRANSPOSE: { this->_n = other.m(); break; }
    default:
      libmesh_error_msg("Unknown flag selected.");
    }

src/numerics/petsc_matrix.C

818  
819  
820  
821  
822  
823  
824  
  // If we're not reusing submatrix and submatrix is already initialized
  // then we need to clear it, otherwise we get a memory leak.
  if (!reuse_submatrix && submatrix.initialized())
    submatrix.clear();

  // Construct row and column index sets.
  WrappedPetsc<IS> isrow;

src/numerics/petsc_preconditioner.C

125  
126  
127  
128  
129  
130  
131  
    CasePCSetType(IDENTITY_PRECOND,     PCNONE)
    CasePCSetType(CHOLESKY_PRECOND,     PCCHOLESKY)
    CasePCSetType(ICC_PRECOND,          PCICC)
    CasePCSetType(ILU_PRECOND,          PCILU)
    CasePCSetType(LU_PRECOND,           PCLU)
    CasePCSetType(ASM_PRECOND,          PCASM)
    CasePCSetType(JACOBI_PRECOND,       PCJACOBI)

src/numerics/petsc_vector.C

711  
712  
713  
714  
715  
716  
717  
  //      (my_local_size == my_size))
  // But we do need to stay in sync for degenerate cases
  if (this->n_processors() == 1)
    return;


  // Build a parallel vector, initialize it with the local
798  
799  
800  
801  
802  
803  
804  
805  
806  
807  
808  
809  
810  
811  
  // only one processor
  if (n_processors() == 1)
    {
      v_local.resize(n);

      LibmeshPetscCall(VecGetArray (_vec, &values));

      for (PetscInt i=0; i<n; i++)
        v_local[i] = static_cast<Real>(values[i]);

      LibmeshPetscCall(VecRestoreArray (_vec, &values));
    }

  // otherwise multiple processors

src/parallel/parallel_elem.C

968  
969  
970  
971  
972  
973  
974  
              mesh->interior_mesh().query_elem_ptr(interior_parent_id);
            if (!ip )
              elem->set_interior_parent
                (const_cast<RemoteElem *>(remote_elem));
            else
              elem->set_interior_parent(ip);
          }

src/partitioning/linear_partitioner.C

102  
103  
104  
105  
106  
107  
108  
              if ((e/blksize) < n)
                elem->processor_id() = cast_int<processor_id_type>(e/blksize);
              else
                elem->processor_id() = 0;
            }

          e++;

src/partitioning/metis_partitioner.C

507  
508  
509  
510  
511  
512  
513  

      // Otherwise  use kway
      else
        Metis::METIS_PartGraphKway(&n,
                                   &ncon,
                                   csr_graph.offsets.data(),
                                   csr_graph.vals.data(),

src/partitioning/parmetis_partitioner.C

401  
402  
403  
404  
405  
406  
407  
         // nodes.
         if (elem->type() == NODEELEM &&
             elem->mapping_type() == RATIONAL_BERNSTEIN_MAP)
           _pmetis->vwgt[local_index] = 50;
         else
           _pmetis->vwgt[local_index] = elem->n_nodes();

src/partitioning/partitioner.C

93  
94  
95  
96  
97  
98  
99  
            data[i] = node.processor_id();
          }
        else
          data[i] = DofObject::invalid_processor_id;
      }
  }

121  
122  
123  
124  
125  
126  
127  
                bad_pids.erase(it);
              }
            else
              proc_id = node.choose_processor_id(proc_id, new_proc_id);

            if (proc_id == new_proc_id)
              data_changed = true;
1197  
1198  
1199  
1200  
1201  
1202  
1203  
1204  
1205  
1206  
1207  
1208  
1209  
1210  
1211  
1212  
1213  
          // Use a set to avoid duplicates.  Use a well-defined method
          // of ordering that set to make debugging easier.
          std::set<const Elem *, CompareElemIdsByLevel> constraining_elems;
          for (const Node & node : elem->node_ref_range())
            {
              if (const auto row_it = mesh_constrained_nodes.find(&node);
                  row_it != end_it)
                for (const auto & [pr, coef] : row_it->second)
                  {
                    libmesh_ignore(coef); // avoid gcc 7 warning
                    constraining_elems.insert(pr.first);
                  }
            }
          for (const Elem * constraining_elem : constraining_elems)
            elems_constrained_by.emplace(constraining_elem, elem);
        }

1217  
1218  
1219  
1220  
1221  
1222  
1223  
1224  
1225  
        {
          // get all relevant interior elements
          std::set<const Elem *> neighbor_set;
          elem->find_interior_neighbors(neighbor_set);

          for (const auto & neighbor : neighbor_set)
            interior_to_boundary_map.emplace(neighbor, elem);
        }
    }
1336  
1337  
1338  
1339  
1340  
1341  
1342  
1343  
1344  
1345  
1346  
1347  
1348  
1349  
1350  
1351  
1352  
1353  
1354  
1355  
1356  
1357  
1358  
1359  
1360  
1361  
        {
          // get all relevant interior elements
          std::set<const Elem *> neighbor_set;
          elem->find_interior_neighbors(neighbor_set);

          for (const auto & neighbor : neighbor_set)
            {
              const dof_id_type neighbor_global_index_by_pid =
                _global_index_by_pid_map[neighbor->id()];

              graph_row.push_back(neighbor_global_index_by_pid);
            }
        }

      // Check for any boundary neighbors
      for (const auto & pr : as_range(interior_to_boundary_map.equal_range(elem)))
        {
          const Elem * neighbor = pr.second;

          const dof_id_type neighbor_global_index_by_pid =
            _global_index_by_pid_map[neighbor->id()];

          graph_row.push_back(neighbor_global_index_by_pid);
        }

      // Check for any constraining elements
1366  
1367  
1368  
1369  
1370  
1371  
1372  
1373  
1374  
1375  
1376  
1377  
1378  
1379  
1380  
1381  
1382  
1383  
1384  
1385  
1386  
1387  
1388  
1389  
1390  
1391  
1392  
1393  
1394  
1395  
1396  
1397  
1398  
1399  
1400  
1401  
1402  
1403  
1404  
1405  
1406  
1407  
1408  
1409  
1410  
1411  
1412  
          // Use a set to avoid duplicates.  Use a well-defined method
          // of ordering that set to make debugging easier.
          std::set<const Elem *, CompareElemIdsByLevel> constraining_elems;
          for (const Node & node : elem->node_ref_range())
            {
              if (const auto row_it = mesh_constrained_nodes.find(&node);
                  row_it != end_it)
                for (const auto & [pr, coef] : row_it->second)
                  {
                    libmesh_ignore(coef); // avoid gcc 7 warning
                    constraining_elems.insert(pr.first);
                  }
            }
          for (const Elem * constraining_elem : constraining_elems)
            {
              const dof_id_type constraining_global_index_by_pid =
                _global_index_by_pid_map[constraining_elem->id()];

              graph_row.push_back(constraining_global_index_by_pid);

              // We can't be sure if the constraining element's owner sees
              // the assembly element, so to get a symmetric connectivity
              // graph we'll need to tell them about us to be safe.
              if (constraining_elem->processor_id() != mesh.processor_id())
                connections_to_push[constraining_elem->processor_id()].emplace_back
                  (global_index_by_pid, constraining_global_index_by_pid);
            }
        }

      // Check for any constrained elements
      for (const auto & pr : as_range(elems_constrained_by.equal_range(elem)))
        {
          const Elem * constrained = pr.second;
          const dof_id_type constrained_global_index_by_pid =
            _global_index_by_pid_map[constrained->id()];

          graph_row.push_back(constrained_global_index_by_pid);

          // We can't be sure if the constrained element's owner sees
          // the assembly element, so to get a symmetric connectivity
          // graph we'll need to tell them about us to be safe.
          if (constrained->processor_id() != mesh.processor_id())
            connections_to_push[constrained->processor_id()].emplace_back
              (global_index_by_pid, constrained_global_index_by_pid);
        }
    }

1416  
1417  
1418  
1419  
1420  
1421  
1422  
1423  
1424  
1425  
1426  
1427  
1428  
1429  
1430  
1431  
1432  
1433  
1434  
1435  
  // processor doesn't see our assembly element.  Let's push those
  // entries, to ensure they're counted on both sides.
  auto symmetrize_entries =
    [this, first_local_elem]
    (processor_id_type /*src_pid*/,
     const std::vector<std::pair<dof_id_type, dof_id_type>> & incoming_entries)
    {
      for (auto [i, j] : incoming_entries)
        {
          libmesh_assert_greater_equal(j, first_local_elem);
          const std::size_t jl = j - first_local_elem;
          libmesh_assert_less(jl, _dual_graph.size());
          std::vector<dof_id_type> & graph_row = _dual_graph[jl];
          if (std::find(graph_row.begin(), graph_row.end(), i) == graph_row.end())
          {
//            std::cerr << "Pushing back (" << j << ", " << i << ") from " << src_pid << std::endl;
            graph_row.push_back(i);
          }
        }
    };

src/reduced_basis/rb_construction.C

870  
871  
872  
873  
874  
875  
876  
877  
878  
879  
880  
      // periodic constraints
      if (assemble_matrix && symmetrize)
        {
          DenseMatrix<Number> Ke_transpose;
          context.get_elem_jacobian().get_transpose(Ke_transpose);
          context.get_elem_jacobian() += Ke_transpose;
          context.get_elem_jacobian() *= 0.5;
        }

      // As discussed above, we can set apply_dof_constraints=false to
      // get A instead of C^T A C
1053  
1054  
1055  
1056  
1057  
1058  
1059  
1060  
1061  
1062  
1063  
1064  
1065  
1066  
1067  
1068  
1069  
1070  
1071  
1072  
1073  
1074  
1075  
1076  
1077  
1078  
1079  
1080  
1081  
1082  
                               apply_dof_constraints);
}

void RBConstruction::add_scaled_Aq(Number scalar,
                                   unsigned int q_a,
                                   SparseMatrix<Number> * input_matrix,
                                   bool symmetrize)
{
  LOG_SCOPE("add_scaled_Aq()", "RBConstruction");

  libmesh_error_msg_if(q_a >= get_rb_theta_expansion().get_n_A_terms(),
                       "Error: We must have q < Q_a in add_scaled_Aq.");

  if (!symmetrize)
    {
      input_matrix->add(scalar, *get_Aq(q_a));
      input_matrix->close();
    }
  else
    {
      add_scaled_matrix_and_vector(scalar,
                                   &rb_assembly_expansion->get_A_assembly(q_a),
                                   input_matrix,
                                   nullptr,
                                   symmetrize);
    }
}

void RBConstruction::assemble_misc_matrices()
{
1590  
1591  
1592  
1593  
1594  
1595  
1596  
  if (rel_greedy_error < this->rel_training_tolerance)
    {
      libMesh::out << "Relative error tolerance reached." << std::endl;
      return true;
    }

  RBEvaluation & rbe = get_rb_evaluation();

src/reduced_basis/rb_construction_base.C

72  
73  
74  
75  
76  
77  
78  
79  
  unsigned int remainder = n_global_samples%communicator.size();
  if (communicator.rank() < remainder)
    {
      n_local_samples = (quotient + 1);
      first_local_index = communicator.rank()*(quotient+1);
    }
  else
    {
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
}

template <class Base>
void RBConstructionBase<Base>::set_params_from_training_set_and_broadcast(unsigned int global_index)
{
  libmesh_error_msg_if(!_training_parameters_initialized,
                       "Error: training parameters must first be initialized.");

  processor_id_type root_id = 0;
  if ((this->get_first_local_training_index() <= global_index) &&
      (global_index < this->get_last_local_training_index()))
    {
      // Set parameters on only one processor
      set_params_from_training_set(global_index);

      // set root_id, only non-zero on one processor
      root_id = this->processor_id();
    }

  // broadcast
  this->comm().max(root_id);
  broadcast_parameters(root_id);
}

template <class Base>
void RBConstructionBase<Base>::initialize_training_parameters(const RBParameters & mu_min,
511  
512  
513  
514  
515  
516  
517  
518  
519  
520  
521  
522  
    }
  else
    {
      if (!serial_training_set)
        {
          // seed the random number generator with the provided value
          // and the processor ID so that the seed is different
          // on different processors
          std::srand( static_cast<unsigned>( training_parameters_random_seed*(1+communicator.rank()) ));
        }
      else
        {

src/reduced_basis/rb_scm_construction.C

44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
namespace libMesh
{

RBSCMConstruction::RBSCMConstruction (EquationSystems & es,
                                      const std::string & name_in,
                                      const unsigned int number_in)
  : Parent(es, name_in, number_in),
    SCM_training_tolerance(0.5),
    RB_system_name(""),
    rb_scm_eval(nullptr)
{

  // set assemble_before_solve flag to false
  // so that we control matrix assembly.
  assemble_before_solve = false;

  // We symmetrize all operators hence use symmetric solvers
  set_eigenproblem_type(GHEP);

}

RBSCMConstruction::~RBSCMConstruction () = default;

void RBSCMConstruction::clear()
{
  Parent::clear();
}

void RBSCMConstruction::set_rb_scm_evaluation(RBSCMEvaluation & rb_scm_eval_in)
{
  rb_scm_eval = &rb_scm_eval_in;
}

RBSCMEvaluation & RBSCMConstruction::get_rb_scm_evaluation()
{
  libmesh_error_msg_if(!rb_scm_eval, "Error: RBSCMEvaluation object hasn't been initialized yet");

  return *rb_scm_eval;
}

RBThetaExpansion & RBSCMConstruction::get_rb_theta_expansion()
{
  return get_rb_scm_evaluation().get_rb_theta_expansion();
}

void RBSCMConstruction::process_parameters_file(const std::string & parameters_filename)
{
  // First read in data from parameters_filename
  GetPot infile(parameters_filename);
  const unsigned int n_training_samples = infile("n_training_samples",1);
  const bool deterministic_training     = infile("deterministic_training",false);

  // Read in training_parameters_random_seed value.  This is used to
  // seed the RNG when picking the training parameters.  By default the
  // value is -1, which means use std::time to seed the RNG.
  unsigned int training_parameters_random_seed_in = static_cast<unsigned int>(-1);
  training_parameters_random_seed_in = infile("training_parameters_random_seed",
                                              training_parameters_random_seed_in);
  set_training_random_seed(static_cast<int>(training_parameters_random_seed_in));

  // SCM Greedy termination tolerance
  const Real SCM_training_tolerance_in = infile("SCM_training_tolerance", SCM_training_tolerance);
  set_SCM_training_tolerance(SCM_training_tolerance_in);

  // Initialize the parameter ranges and the parameters themselves
  unsigned int n_continuous_parameters = infile.vector_variable_size("parameter_names");
  RBParameters mu_min_in;
  RBParameters mu_max_in;
  for (unsigned int i=0; i<n_continuous_parameters; i++)
    {
      // Read in the parameter names
      std::string param_name = infile("parameter_names", "NONE", i);

      {
        Real min_val = infile(param_name, 0., 0);
        mu_min_in.set_value(param_name, min_val);
      }

      {
        Real max_val = infile(param_name, 0., 1);
        mu_max_in.set_value(param_name, max_val);
      }
    }

  std::map<std::string, std::vector<Real>> discrete_parameter_values_in;

  unsigned int n_discrete_parameters = infile.vector_variable_size("discrete_parameter_names");
  for (unsigned int i=0; i<n_discrete_parameters; i++)
    {
      std::string param_name = infile("discrete_parameter_names", "NONE", i);

140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
      discrete_parameter_values_in[param_name] = vals_for_param;
    }

  initialize_parameters(mu_min_in, mu_max_in, discrete_parameter_values_in);

  std::map<std::string,bool> log_scaling;
  const RBParameters & mu = get_parameters();
  unsigned int i=0;
  for (const auto & pr : mu)
    {
      const std::string & param_name = pr.first;
      log_scaling[param_name] = static_cast<bool>(infile("log_scaling", 0, i++));
    }

  initialize_training_parameters(this->get_parameters_min(),
                                 this->get_parameters_max(),
                                 n_training_samples,
                                 log_scaling,
                                 deterministic_training);   // use deterministic parameters
}

void RBSCMConstruction::print_info()
{
  // Print out info that describes the current setup
  libMesh::out << std::endl << "RBSCMConstruction parameters:" << std::endl;
  libMesh::out << "system name: " << this->name() << std::endl;
  libMesh::out << "SCM Greedy tolerance: " << get_SCM_training_tolerance() << std::endl;
  if (rb_scm_eval)
    {
      libMesh::out << "A_q operators attached: " << get_rb_theta_expansion().get_n_A_terms() << std::endl;
    }
  else
    {
      libMesh::out << "RBThetaExpansion member is not set yet" << std::endl;
    }
  libMesh::out << "Number of parameters: " << get_n_params() << std::endl;
  for (const auto & pr : get_parameters())
    {
      const std::string & param_name = pr.first;
      libMesh::out <<   "Parameter " << param_name
                   << ": Min = " << get_parameter_min(param_name)
                   << ", Max = " << get_parameter_max(param_name) << std::endl;
    }
  print_discrete_parameter_values();
  libMesh::out << "n_training_samples: " << get_n_training_samples() << std::endl;
  libMesh::out << std::endl;
}

void RBSCMConstruction::resize_SCM_vectors()
{
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
  rb_scm_eval->B_max.resize(get_rb_theta_expansion().get_n_A_terms());
}

void RBSCMConstruction::add_scaled_symm_Aq(unsigned int q_a, Number scalar)
{
  LOG_SCOPE("add_scaled_symm_Aq()", "RBSCMConstruction");
  // Load the operators from the RBConstruction
  EquationSystems & es = this->get_equation_systems();
  RBConstruction & rb_system = es.get_system<RBConstruction>(RB_system_name);
  rb_system.add_scaled_Aq(scalar, q_a, &get_matrix_A(), true);
}

void RBSCMConstruction::load_matrix_B()
{
  // Load the operators from the RBConstruction
  EquationSystems & es = this->get_equation_systems();
  RBConstruction & rb_system = es.get_system<RBConstruction>(RB_system_name);

  matrix_B->zero();
  matrix_B->close();
  matrix_B->add(1.,*rb_system.get_inner_product_matrix());
}

void RBSCMConstruction::perform_SCM_greedy()
{
  LOG_SCOPE("perform_SCM_greedy()", "RBSCMConstruction");

  // initialize rb_scm_eval's parameters
  rb_scm_eval->initialize_parameters(*this);

#ifdef LIBMESH_ENABLE_CONSTRAINTS
  // Get a list of constrained dofs from rb_system
  std::set<dof_id_type> constrained_dofs_set;
  EquationSystems & es = this->get_equation_systems();
  RBConstruction & rb_system = es.get_system<RBConstruction>(RB_system_name);

  for (dof_id_type i=0; i<rb_system.n_dofs(); i++)
    {
      if (rb_system.get_dof_map().is_constrained_dof(i))
        {
          constrained_dofs_set.insert(i);
        }
    }

  // Use these constrained dofs to identify which dofs we want to "get rid of"
  // (i.e. condense) in our eigenproblems.
  this->initialize_condensed_dofs(constrained_dofs_set);
#endif // LIBMESH_ENABLE_CONSTRAINTS

  // Copy the inner product matrix over from rb_system to be used as matrix_B
  load_matrix_B();

  attach_deflation_space();

  compute_SCM_bounding_box();
  // This loads the new parameter into current_parameters
  enrich_C_J(0);

  unsigned int SCM_iter=0;
  while (true)
    {
      // matrix_A is reinitialized for the current parameters
      // on each call to evaluate_stability_constant
      evaluate_stability_constant();

      std::pair<unsigned int,Real> SCM_error_pair = compute_SCM_bounds_on_training_set();

      libMesh::out << "SCM iteration " << SCM_iter
                   << ", max_SCM_error = " << SCM_error_pair.second << std::endl;

      if (SCM_error_pair.second < SCM_training_tolerance)
        {
          libMesh::out << std::endl << "SCM tolerance of " << SCM_training_tolerance << " reached."
                       << std::endl << std::endl;
          break;
        }

      // If we need another SCM iteration, then enrich C_J
      enrich_C_J(SCM_error_pair.first);

      libMesh::out << std::endl << "-----------------------------------" << std::endl << std::endl;

      SCM_iter++;
    }
}

void RBSCMConstruction::compute_SCM_bounding_box()
{
  LOG_SCOPE("compute_SCM_bounding_box()", "RBSCMConstruction");

  // Resize the bounding box vectors
  rb_scm_eval->B_min.resize(get_rb_theta_expansion().get_n_A_terms());
  rb_scm_eval->B_max.resize(get_rb_theta_expansion().get_n_A_terms());

  for (unsigned int q=0; q<get_rb_theta_expansion().get_n_A_terms(); q++)
    {
      matrix_A->zero();
      add_scaled_symm_Aq(q, 1.);

      // Compute B_min(q)
      eigen_solver->set_position_of_spectrum(SMALLEST_REAL);
      set_eigensolver_properties(q);

      solve();
      // TODO: Assert convergence for eigensolver

      unsigned int nconv = get_n_converged();
      if (nconv != 0)
        {
          std::pair<Real, Real> eval = get_eigenpair(0);

          // ensure that the eigenvalue is real
          libmesh_assert_less (eval.second, TOLERANCE);

          rb_scm_eval->set_B_min(q, eval.first);
          libMesh::out << std::endl << "B_min("<<q<<") = " << rb_scm_eval->get_B_min(q) << std::endl;
        }
      else
        libmesh_error_msg("Eigen solver for computing B_min did not converge");

      // Compute B_max(q)
      eigen_solver->set_position_of_spectrum(LARGEST_REAL);
      set_eigensolver_properties(q);

      solve();
      // TODO: Assert convergence for eigensolver

      nconv = get_n_converged();
      if (nconv != 0)
        {
          std::pair<Real, Real> eval = get_eigenpair(0);

          // ensure that the eigenvalue is real
          libmesh_assert_less (eval.second, TOLERANCE);

          rb_scm_eval->set_B_max(q,eval.first);
          libMesh::out << "B_max("<<q<<") = " << rb_scm_eval->get_B_max(q) << std::endl;
        }
      else
        libmesh_error_msg("Eigen solver for computing B_max did not converge");
    }
}

void RBSCMConstruction::evaluate_stability_constant()
{
  LOG_SCOPE("evaluate_stability_constant()", "RBSCMConstruction");

  // Get current index of C_J
  const unsigned int j = cast_int<unsigned int>(rb_scm_eval->C_J.size()-1);

  eigen_solver->set_position_of_spectrum(SMALLEST_REAL);

355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
407  
408  
409  
410  
411  
412  
413  
414  
415  
416  
417  
418  
419  
420  
421  
422  
  // For non-coercive time-dependent problems, B is set to the mass matrix

  // Set matrix A corresponding to mu_star
  matrix_A->zero();
  for (unsigned int q=0; q<get_rb_theta_expansion().get_n_A_terms(); q++)
    {
      add_scaled_symm_Aq(q, get_rb_theta_expansion().eval_A_theta(q,get_parameters()));
    }

  set_eigensolver_properties(-1);
  solve();
  // TODO: Assert convergence for eigensolver

  unsigned int nconv = get_n_converged();
  if (nconv != 0)
    {
      std::pair<Real, Real> eval = get_eigenpair(0);

      // ensure that the eigenvalue is real
      libmesh_assert_less (eval.second, TOLERANCE);

      // Store the coercivity constant corresponding to mu_star
      rb_scm_eval->set_C_J_stability_constraint(j,eval.first);
      libMesh::out << std::endl << "Stability constant for C_J("<<j<<") = "
                   << rb_scm_eval->get_C_J_stability_constraint(j) << std::endl << std::endl;

      // Compute and store the vector y = (y_1, \ldots, y_Q) for the
      // eigenvector currently stored in eigen_system.solution.
      // We use this later to compute the SCM upper bounds.
      Real norm_B2 = libmesh_real( B_inner_product(*solution, *solution) );

      for (unsigned int q=0; q<get_rb_theta_expansion().get_n_A_terms(); q++)
        {
          Real norm_Aq2 = libmesh_real( Aq_inner_product(q, *solution, *solution) );

          rb_scm_eval->set_SCM_UB_vector(j,q,norm_Aq2/norm_B2);
        }
    }
  else
    libmesh_error_msg("Error: Eigensolver did not converge in evaluate_stability_constant");
}

Number RBSCMConstruction::B_inner_product(const NumericVector<Number> & v,
                                          const NumericVector<Number> & w) const
{
  matrix_B->vector_mult(*inner_product_storage_vector, w);

  return v.dot(*inner_product_storage_vector);
}

Number RBSCMConstruction::Aq_inner_product(unsigned int q,
                                           const NumericVector<Number> & v,
                                           const NumericVector<Number> & w)
{
  libmesh_error_msg_if(q >= get_rb_theta_expansion().get_n_A_terms(),
                       "Error: We must have q < Q_a in Aq_inner_product.");

  matrix_A->zero();
  add_scaled_symm_Aq(q, 1.);
  matrix_A->vector_mult(*inner_product_storage_vector, w);

  return v.dot(*inner_product_storage_vector);
}

std::pair<unsigned int,Real> RBSCMConstruction::compute_SCM_bounds_on_training_set()
{
  LOG_SCOPE("compute_SCM_bounds_on_training_set()", "RBSCMConstruction");

424  
425  
426  
427  
428  
429  
430  
431  
432  
433  
434  
435  
436  
437  
438  
439  
440  
441  
442  
443  
444  
445  
446  
447  
448  
449  
450  
451  
452  
453  
454  
455  
456  
457  
458  
459  
460  
461  
462  
463  
464  
465  
466  
467  
468  
469  
470  
471  
472  
473  
474  
475  
476  
477  
478  
479  
480  
481  
  unsigned int new_C_J_index = 0;
  Real max_SCM_error = 0.;

  numeric_index_type first_index = get_first_local_training_index();
  for (unsigned int i=0; i<get_local_n_training_samples(); i++)
    {
      set_params_from_training_set(first_index+i);
      rb_scm_eval->set_parameters( get_parameters() );
      Real LB = rb_scm_eval->get_SCM_LB();
      Real UB = rb_scm_eval->get_SCM_UB();

      Real error_i = SCM_greedy_error_indicator(LB, UB);

      if (error_i > max_SCM_error)
        {
          max_SCM_error = error_i;
          new_C_J_index = i;
        }
    }

  numeric_index_type global_index = first_index + new_C_J_index;
  std::pair<numeric_index_type,Real> error_pair(global_index, max_SCM_error);
  get_global_max_error_pair(this->comm(),error_pair);

  return error_pair;
}

void RBSCMConstruction::enrich_C_J(unsigned int new_C_J_index)
{
  LOG_SCOPE("enrich_C_J()", "RBSCMConstruction");

  set_params_from_training_set_and_broadcast(new_C_J_index);

  rb_scm_eval->C_J.push_back(get_parameters());

  libMesh::out << std::endl << "SCM: Added mu = (";

  bool first = true;
  for (const auto & pr : get_parameters())
    {
      if (!first)
        libMesh::out << ",";
      const std::string & param_name = pr.first;
      RBParameters C_J_params = rb_scm_eval->C_J[rb_scm_eval->C_J.size()-1];
      libMesh::out << C_J_params.get_value(param_name);
      first = false;
    }
  libMesh::out << ")" << std::endl;

  // Finally, resize C_J_stability_vector and SCM_UB_vectors
  rb_scm_eval->C_J_stability_vector.push_back(0.);

  std::vector<Real> zero_vector(get_rb_theta_expansion().get_n_A_terms());
  rb_scm_eval->SCM_UB_vectors.push_back(zero_vector);
}


} // namespace libMesh

src/reduced_basis/rb_scm_evaluation.C

49  
50  
51  
52  
53  
54  
55  
56  
namespace libMesh
{

RBSCMEvaluation::RBSCMEvaluation (const Parallel::Communicator & comm_in) :
  ParallelObject(comm_in)
{
  // Clear SCM data vectors
  B_min.clear();
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
  C_J.clear();
  C_J_stability_vector.clear();
  SCM_UB_vectors.clear();
}

RBSCMEvaluation::~RBSCMEvaluation () = default;

void RBSCMEvaluation::set_rb_theta_expansion(RBThetaExpansion & rb_theta_expansion_in)
{
  rb_theta_expansion = &rb_theta_expansion_in;
}

RBThetaExpansion & RBSCMEvaluation::get_rb_theta_expansion()
{
  libmesh_error_msg_if(!rb_theta_expansion, "Error: rb_theta_expansion hasn't been initialized yet");

  return *rb_theta_expansion;
}

void RBSCMEvaluation::set_C_J_stability_constraint(unsigned int j, Real stability_const_in)
{
  libmesh_error_msg_if(j >= C_J_stability_vector.size(), "Error: Input parameter j is too large in set_C_J_stability_constraint.");

  // we assume that C_J_stability_vector is resized elsewhere
  // to be the same size as C_J.
  libmesh_assert_equal_to (C_J_stability_vector.size(), C_J.size());

  C_J_stability_vector[j] = stability_const_in;
}

Real RBSCMEvaluation::get_C_J_stability_constraint(unsigned int j) const
{
  libmesh_error_msg_if(j >= C_J_stability_vector.size(), "Error: Input parameter j is too large in get_C_J_stability_constraint.");

  return C_J_stability_vector[j];
}

void RBSCMEvaluation::set_SCM_UB_vector(unsigned int j, unsigned int q, Real y_q)
{
  // First make sure that j <= J
  libmesh_error_msg_if(j >= SCM_UB_vectors.size(), "Error: We must have j < J in set_SCM_UB_vector.");

  // Next make sure that q <= Q_a or Q_a_hat
  libmesh_error_msg_if(q >= SCM_UB_vectors[0].size(), "Error: q is too large in set_SCM_UB_vector.");

  SCM_UB_vectors[j][q] = y_q;
}

Real RBSCMEvaluation::get_SCM_UB_vector(unsigned int j, unsigned int q)
{
  // First make sure that j <= J
  libmesh_error_msg_if(j >= SCM_UB_vectors.size(), "Error: We must have j < J in get_SCM_UB_vector.");
  libmesh_error_msg_if(q >= SCM_UB_vectors[0].size(), "Error: q is too large in get_SCM_UB_vector.");

  return SCM_UB_vectors[j][q];
}

const RBParameters & RBSCMEvaluation::get_C_J_entry(unsigned int j)
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
  return C_J[j];
}

Real RBSCMEvaluation::get_B_min(unsigned int q) const
{
  libmesh_error_msg_if(q >= B_min.size(), "Error: q is too large in get_B_min.");

  return B_min[q];
}


Real RBSCMEvaluation::get_B_max(unsigned int q) const
{
  libmesh_error_msg_if(q >= B_max.size(), "Error: q is too large in get_B_max.");

  return B_max[q];
}

void RBSCMEvaluation::set_B_min(unsigned int q, Real B_min_val)
{
  libmesh_error_msg_if(q >= B_min.size(), "Error: q is too large in set_B_min.");

  B_min[q] = B_min_val;
}

void RBSCMEvaluation::set_B_max(unsigned int q, Real B_max_val)
{
  libmesh_error_msg_if(q >= B_max.size(), "Error: q is too large in set_B_max.");

  B_max[q] = B_max_val;
}

Real RBSCMEvaluation::get_SCM_LB()
{
  LOG_SCOPE("get_SCM_LB()", "RBSCMEvaluation");

  // Initialize the LP
  glp_prob * lp;
  lp = glp_create_prob();
  glp_set_obj_dir(lp,GLP_MIN);

  // Add columns to the LP: corresponds to
  // the variables y_1,...y_Q_a.
  // These are the same for each \mu in the SCM
  // training set, hence can do this up front.
  glp_add_cols(lp,rb_theta_expansion->get_n_A_terms());

  for (unsigned int q=0; q<rb_theta_expansion->get_n_A_terms(); q++)
    {
      if (B_max[q] < B_min[q]) // Invalid bound, set as free variable
        {
          // GLPK indexing is not zero based!
          glp_set_col_bnds(lp, q+1, GLP_FR, 0., 0.);
173  
174  
175  
176  
177  
178  
179  
      else
        {
          // GLPK indexing is not zero based!
          glp_set_col_bnds(lp, q+1, GLP_DB, double(B_min[q]), double(B_max[q]));
        }

      // If B_max is not defined, just set lower bounds...
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
  // variables that define the constraints at each
  // mu \in C_J_M
  unsigned int n_rows = cast_int<unsigned int>(C_J.size());
  glp_add_rows(lp, n_rows);

  // Now put current_parameters in saved_parameters
  save_current_parameters();

  unsigned int matrix_size = n_rows*rb_theta_expansion->get_n_A_terms();
  std::vector<int> ia(matrix_size+1);
  std::vector<int> ja(matrix_size+1);
  std::vector<double> ar(matrix_size+1);
  unsigned int count=0;
  for (unsigned int m=0; m<n_rows; m++)
    {
      set_current_parameters_from_C_J(m);

      // Set the lower bound on the auxiliary variable
      // due to the stability constant at mu_index
      glp_set_row_bnds(lp, m+1, GLP_LO, double(C_J_stability_vector[m]), 0.);

      // Now define the matrix that relates the y's
      // to the auxiliary variables at the current
      // value of mu.
      for (unsigned int q=0; q<rb_theta_expansion->get_n_A_terms(); q++)
        {
          count++;

          ia[count] = m+1;
          ja[count] = q+1;

          // This can only handle Reals right now
          ar[count] = double(libmesh_real( rb_theta_expansion->eval_A_theta(q,get_parameters()) ));
        }
    }

  // Now load the original parameters back into current_parameters
  // in order to set the coefficients of the objective function
  reload_current_parameters();

  glp_load_matrix(lp, matrix_size, ia.data(), ja.data(), ar.data());

  for (unsigned int q=0; q<rb_theta_expansion->get_n_A_terms(); q++)
    {
      glp_set_obj_coef(lp,q+1, double(libmesh_real( rb_theta_expansion->eval_A_theta(q,get_parameters()) )) );
    }

  // Use this command to initialize the basis for the LP
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
  //lpx_cpx_basis(lp); //glp_cpx_basis(lp);

  glp_smcp parm;
  glp_init_smcp(&parm);
  parm.msg_lev = GLP_MSG_ERR;
  parm.meth = GLP_DUAL;


  // use the simplex method and solve the LP
  glp_simplex(lp, &parm);

  Real min_J_obj = glp_get_obj_val(lp);

  //   int simplex_status =  glp_get_status(lp);
  //   if (simplex_status == GLP_UNBND)
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
  //   }

  // Destroy the LP
  glp_delete_prob(lp);

  return min_J_obj;
}

Real RBSCMEvaluation::get_SCM_UB()
{
  LOG_SCOPE("get_SCM_UB()", "RBSCMEvaluation");

278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
407  
408  
409  
410  
411  
412  
413  
414  
415  
416  
417  
418  
419  
420  
421  
422  
423  
424  
425  
426  
427  
428  
429  
430  
431  
432  
433  
434  
435  
436  
437  
438  
439  
440  
441  
442  
443  
444  
445  
446  
447  
448  
449  
450  
451  
452  
453  
454  
455  
456  
457  
458  
459  
460  
461  
462  
463  
464  
465  
466  
467  
468  
469  
470  
471  
472  
473  
474  
475  
476  
477  
478  
479  
480  
481  
482  
483  
484  
485  
486  
487  
488  
489  
490  
491  
492  
493  
494  
495  
496  
497  
498  
499  
500  
501  
502  
503  
504  
505  
506  
507  
508  
509  
510  
511  
512  
513  
514  
515  
516  
517  
518  
519  
520  
521  
522  
523  
524  
525  
526  
527  
528  
529  
530  
531  
532  
533  
534  
535  
536  
537  
538  
539  
540  
541  
542  
543  
544  
545  
546  
547  
548  
549  
  // to C_J_M (SCM_UB_vectors contains vectors for all of
  // C_J).
  Real min_J_obj = 0.;
  for (unsigned int m=0; m<n_rows; m++)
    {
      const std::vector<Real> UB_vector = SCM_UB_vectors[m];

      Real J_obj = 0.;
      for (unsigned int q=0; q<rb_theta_expansion->get_n_A_terms(); q++)
        {
          J_obj += libmesh_real( rb_theta_expansion->eval_A_theta(q,get_parameters()) )*UB_vector[q];
        }

      if ((m==0) || (J_obj < min_J_obj))
        {
          min_J_obj = J_obj;
        }
    }

  return min_J_obj;
}

void RBSCMEvaluation::set_current_parameters_from_C_J(unsigned int C_J_index)
{
  set_parameters(C_J[C_J_index]);
}

void RBSCMEvaluation::save_current_parameters()
{
  saved_parameters = get_parameters();
}

void RBSCMEvaluation::reload_current_parameters()
{
  set_parameters(saved_parameters);
}

void RBSCMEvaluation::legacy_write_offline_data_to_files(const std::string & directory_name,
                                                         const bool write_binary_data)
{
  LOG_SCOPE("legacy_write_offline_data_to_files()", "RBSCMEvaluation");

  if (this->processor_id() == 0)
    {
      // Make a directory to store all the data files
      if (mkdir(directory_name.c_str(), 0777) == -1)
        {
          libMesh::out << "In RBSCMEvaluation::write_offline_data_to_files, directory "
                       << directory_name << " already exists, overwriting contents." << std::endl;
        }

      // The writing mode: ENCODE for binary, WRITE for ASCII
      XdrMODE mode = write_binary_data ? ENCODE : WRITE;

      // The suffix to use for all the files that are written out
      const std::string suffix = write_binary_data ? ".xdr" : ".dat";

      // Stream for building the file names
      std::ostringstream file_name;

      // Write out the parameter ranges
      file_name.str("");
      file_name << directory_name << "/parameter_ranges" << suffix;
      std::string continuous_param_file_name = file_name.str();

      // Write out the discrete parameter values
      file_name.str("");
      file_name << directory_name << "/discrete_parameter_values" << suffix;
      std::string discrete_param_file_name = file_name.str();

      write_parameter_data_to_files(continuous_param_file_name,
                                    discrete_param_file_name,
                                    write_binary_data);

      // Write out the bounding box min values
      file_name.str("");
      file_name << directory_name << "/B_min" << suffix;
      Xdr B_min_out(file_name.str(), mode);

      for (auto i : make_range(B_min.size()))
        {
          Real B_min_i = get_B_min(i);
          B_min_out << B_min_i;
        }
      B_min_out.close();


      // Write out the bounding box max values
      file_name.str("");
      file_name << directory_name << "/B_max" << suffix;
      Xdr B_max_out(file_name.str(), mode);

      for (auto i : make_range(B_max.size()))
        {
          Real B_max_i = get_B_max(i);
          B_max_out << B_max_i;
        }
      B_max_out.close();

      // Write out the length of the C_J data
      file_name.str("");
      file_name << directory_name << "/C_J_length" << suffix;
      Xdr C_J_length_out(file_name.str(), mode);

      unsigned int C_J_length = cast_int<unsigned int>(C_J.size());
      C_J_length_out << C_J_length;
      C_J_length_out.close();

      // Write out C_J_stability_vector
      file_name.str("");
      file_name << directory_name << "/C_J_stability_vector" << suffix;
      Xdr C_J_stability_vector_out(file_name.str(), mode);

      for (auto i : make_range(C_J_stability_vector.size()))
        {
          Real C_J_stability_constraint_i = get_C_J_stability_constraint(i);
          C_J_stability_vector_out << C_J_stability_constraint_i;
        }
      C_J_stability_vector_out.close();

      // Write out C_J
      file_name.str("");
      file_name << directory_name << "/C_J" << suffix;
      Xdr C_J_out(file_name.str(), mode);

      for (const auto & param : C_J)
        for (const auto & pr : param)
          for (const auto & value_vector : pr.second)
            {
              // Need to make a copy of the value so that it's not const
              // Xdr is not templated on const's
              libmesh_error_msg_if(value_vector.size() != 1,
                                   "Error: multi-value RB parameters are not yet supported here.");
              Real param_value = value_vector[0];
              C_J_out << param_value;
            }
      C_J_out.close();

      // Write out SCM_UB_vectors get_SCM_UB_vector
      file_name.str("");
      file_name << directory_name << "/SCM_UB_vectors" << suffix;
      Xdr SCM_UB_vectors_out(file_name.str(), mode);

      for (auto i : make_range(SCM_UB_vectors.size()))
        for (auto j : make_range(rb_theta_expansion->get_n_A_terms()))
          {
            Real SCM_UB_vector_ij = get_SCM_UB_vector(i,j);
            SCM_UB_vectors_out << SCM_UB_vector_ij;
          }
      SCM_UB_vectors_out.close();
    }
}


void RBSCMEvaluation::legacy_read_offline_data_from_files(const std::string & directory_name,
                                                          const bool read_binary_data)
{
  LOG_SCOPE("legacy_read_offline_data_from_files()", "RBSCMEvaluation");

  // The reading mode: DECODE for binary, READ for ASCII
  XdrMODE mode = read_binary_data ? DECODE : READ;

  // The suffix to use for all the files that are written out
  const std::string suffix = read_binary_data ? ".xdr" : ".dat";

  // The string stream we'll use to make the file names
  std::ostringstream file_name;

  // Read in the parameter ranges
  file_name.str("");
  file_name << directory_name << "/parameter_ranges" << suffix;
  std::string continuous_param_file_name = file_name.str();

  // Read in the discrete parameter values
  file_name.str("");
  file_name << directory_name << "/discrete_parameter_values" << suffix;
  std::string discrete_param_file_name = file_name.str();
  read_parameter_data_from_files(continuous_param_file_name,
                                 discrete_param_file_name,
                                 read_binary_data);

  // Read in the bounding box min values
  // Note that there are Q_a values
  file_name.str("");
  file_name << directory_name << "/B_min" << suffix;
  Xdr B_min_in(file_name.str(), mode);

  B_min.clear();
  for (unsigned int i=0; i<rb_theta_expansion->get_n_A_terms(); i++)
    {
      Real B_min_val;
      B_min_in >> B_min_val;
      B_min.push_back(B_min_val);
    }
  B_min_in.close();


  // Read in the bounding box max values
  // Note that there are Q_a values
  file_name.str("");
  file_name << directory_name << "/B_max" << suffix;
  Xdr B_max_in(file_name.str(), mode);

  B_max.clear();
  for (unsigned int i=0; i<rb_theta_expansion->get_n_A_terms(); i++)
    {
      Real B_max_val;
      B_max_in >> B_max_val;
      B_max.push_back(B_max_val);
    }

  // Read in the length of the C_J data
  file_name.str("");
  file_name << directory_name << "/C_J_length" << suffix;
  Xdr C_J_length_in(file_name.str(), mode);

  unsigned int C_J_length;
  C_J_length_in >> C_J_length;
  C_J_length_in.close();

  // Read in C_J_stability_vector
  file_name.str("");
  file_name << directory_name << "/C_J_stability_vector" << suffix;
  Xdr C_J_stability_vector_in(file_name.str(), mode);

  C_J_stability_vector.clear();
  for (unsigned int i=0; i<C_J_length; i++)
    {
      Real C_J_stability_val;
      C_J_stability_vector_in >> C_J_stability_val;
      C_J_stability_vector.push_back(C_J_stability_val);
    }
  C_J_stability_vector_in.close();

  // Read in C_J
  file_name.str("");
  file_name << directory_name << "/C_J" << suffix;
  Xdr C_J_in(file_name.str(), mode);

  // Resize C_J based on C_J_stability_vector and Q_a
  C_J.resize( C_J_length );
  for (auto & params : C_J)
    for (const auto & pr : get_parameters())
      {
        const std::string & param_name = pr.first;
        Real param_value;
        C_J_in >> param_value;
        params.set_value(param_name, param_value);
      }
  C_J_in.close();


  // Read in SCM_UB_vectors get_SCM_UB_vector
  file_name.str("");
  file_name << directory_name << "/SCM_UB_vectors" << suffix;
  Xdr SCM_UB_vectors_in(file_name.str(), mode);

  // Resize SCM_UB_vectors based on C_J_stability_vector and Q_a
  SCM_UB_vectors.resize( C_J_stability_vector.size() );
  for (auto i : index_range(SCM_UB_vectors))
    {
      SCM_UB_vectors[i].resize( rb_theta_expansion->get_n_A_terms() );
      for (unsigned int j=0; j<rb_theta_expansion->get_n_A_terms(); j++)
        {
          SCM_UB_vectors_in >> SCM_UB_vectors[i][j];
        }
    }
  SCM_UB_vectors_in.close();
}

} // namespace libMesh

src/solvers/petsc_linear_solver.C

93  
94  
95  
96  
97  
98  
99  
  _subset_solve_mode(SUBSET_ZERO)
{
  if (this->n_processors() == 1)
    this->_preconditioner_type = ILU_PRECOND;
  else
    this->_preconditioner_type = BLOCK_JACOBI_PRECOND;
}
123  
124  
125  
126  
127  
128  
129  
      if (!this->_preconditioner)
        {
          if (this->n_processors() == 1)
            this->_preconditioner_type = ILU_PRECOND;
          else
            this->_preconditioner_type = BLOCK_JACOBI_PRECOND;
        }

src/solvers/slepc_eigen_solver.C

600  
601  
602  
603  
604  
605  
606  
607  
      LibmeshPetscCall(EPSSetType (_eps, EPSARNOLDI)); return;
    case LANCZOS:
      LibmeshPetscCall(EPSSetType (_eps, EPSLANCZOS)); return;
    case KRYLOVSCHUR:
      LibmeshPetscCall(EPSSetType (_eps, EPSKRYLOVSCHUR)); return;
      // case ARPACK:
      // LibmeshPetscCall(EPSSetType (_eps, (char *) EPSARPACK)); return;

658  
659  
660  
661  
662  
663  
664  
665  
666  
667  
668  
669  
670  
671  
        LibmeshPetscCall(EPSSetWhichEigenpairs (_eps, EPS_SMALLEST_MAGNITUDE));
        return;
      }
    case LARGEST_REAL:
      {
        LibmeshPetscCall(EPSSetWhichEigenpairs (_eps, EPS_LARGEST_REAL));
        return;
      }
    case SMALLEST_REAL:
      {
        LibmeshPetscCall(EPSSetWhichEigenpairs (_eps, EPS_SMALLEST_REAL));
        return;
      }
    case LARGEST_IMAGINARY:

src/solvers/tao_optimization_solver.C

203  
204  
205  
206  
207  
208  
209  
  //---------------------------------------------------------------
  // This function is called by Tao to evaluate the equality constraints at x
  PetscErrorCode
  __libmesh_tao_equality_constraints(Tao /*tao*/, Vec x, Vec ce, void * ctx)
  {
    PetscFunctionBegin;

222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
    // We'll use current_local_solution below, so let's ensure that it's consistent
    // with the vector x that was passed in.
    PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
    PetscVector<Number> X(x, sys.comm());

    // Perform a swap so that sys.solution points to the input vector
    // "x", update sys.current_local_solution based on "x", then swap
    // back.
    X.swap(X_sys);
    sys.update();
    X.swap(X_sys);

    // We'll also pass the constraints vector ce into the assembly routine
    // so let's make a PETSc vector for that too.
    PetscVector<Number> eq_constraints(ce, sys.comm());

    // Clear the gradient prior to assembly
    eq_constraints.zero();

    // Enforce constraints exactly on the current_local_solution.
    sys.get_dof_map().enforce_constraints_exactly(sys, sys.current_local_solution.get());

    if (solver->equality_constraints_object != nullptr)
      solver->equality_constraints_object->equality_constraints(*(sys.current_local_solution), eq_constraints, sys);
    else
      libmesh_error_msg("Constraints function not defined in __libmesh_tao_equality_constraints");

    eq_constraints.close();

    PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
  }

  //---------------------------------------------------------------
  // This function is called by Tao to evaluate the Jacobian of the
  // equality constraints at x
  PetscErrorCode
  __libmesh_tao_equality_constraints_jacobian(Tao /*tao*/, Vec x, Mat J, Mat Jpre, void * ctx)
  {
    PetscFunctionBegin;

274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
    // We'll use current_local_solution below, so let's ensure that it's consistent
    // with the vector x that was passed in.
    PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
    PetscVector<Number> X(x, sys.comm());

    // Perform a swap so that sys.solution points to the input vector
    // "x", update sys.current_local_solution based on "x", then swap
    // back.
    X.swap(X_sys);
    sys.update();
    X.swap(X_sys);

    // Let's also wrap J and Jpre in PetscMatrix objects for convenience
    PetscMatrix<Number> J_petsc(J, sys.comm());
    PetscMatrix<Number> Jpre_petsc(Jpre, sys.comm());

    // Enforce constraints exactly on the current_local_solution.
    sys.get_dof_map().enforce_constraints_exactly(sys, sys.current_local_solution.get());

    if (solver->equality_constraints_jacobian_object != nullptr)
      solver->equality_constraints_jacobian_object->equality_constraints_jacobian(*(sys.current_local_solution), J_petsc, sys);
    else
      libmesh_error_msg("Constraints function not defined in __libmesh_tao_equality_constraints_jacobian");

    J_petsc.close();
    Jpre_petsc.close();

    PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
  }

  //---------------------------------------------------------------
  // This function is called by Tao to evaluate the inequality constraints at x
  PetscErrorCode
  __libmesh_tao_inequality_constraints(Tao /*tao*/, Vec x, Vec cineq, void * ctx)
  {
    PetscFunctionBegin;

323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
    // We'll use current_local_solution below, so let's ensure that it's consistent
    // with the vector x that was passed in.
    PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
    PetscVector<Number> X(x, sys.comm());

    // Perform a swap so that sys.solution points to the input vector
    // "x", update sys.current_local_solution based on "x", then swap
    // back.
    X.swap(X_sys);
    sys.update();
    X.swap(X_sys);

    // We'll also pass the constraints vector ce into the assembly routine
    // so let's make a PETSc vector for that too.
    PetscVector<Number> ineq_constraints(cineq, sys.comm());

    // Clear the gradient prior to assembly
    ineq_constraints.zero();

    // Enforce constraints exactly on the current_local_solution.
    sys.get_dof_map().enforce_constraints_exactly(sys, sys.current_local_solution.get());

    if (solver->inequality_constraints_object != nullptr)
      solver->inequality_constraints_object->inequality_constraints(*(sys.current_local_solution), ineq_constraints, sys);
    else
      libmesh_error_msg("Constraints function not defined in __libmesh_tao_inequality_constraints");

    ineq_constraints.close();

    PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
  }

  //---------------------------------------------------------------
  // This function is called by Tao to evaluate the Jacobian of the
  // equality constraints at x
  PetscErrorCode
  __libmesh_tao_inequality_constraints_jacobian(Tao /*tao*/, Vec x, Mat J, Mat Jpre, void * ctx)
  {
    PetscFunctionBegin;

375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
    // We'll use current_local_solution below, so let's ensure that it's consistent
    // with the vector x that was passed in.
    PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
    PetscVector<Number> X(x, sys.comm());

    // Perform a swap so that sys.solution points to the input vector
    // "x", update sys.current_local_solution based on "x", then swap
    // back.
    X.swap(X_sys);
    sys.update();
    X.swap(X_sys);

    // Let's also wrap J and Jpre in PetscMatrix objects for convenience
    PetscMatrix<Number> J_petsc(J, sys.comm());
    PetscMatrix<Number> Jpre_petsc(Jpre, sys.comm());

    // Enforce constraints exactly on the current_local_solution.
    sys.get_dof_map().enforce_constraints_exactly(sys, sys.current_local_solution.get());

    if (solver->inequality_constraints_jacobian_object != nullptr)
      solver->inequality_constraints_jacobian_object->inequality_constraints_jacobian(*(sys.current_local_solution), J_petsc, sys);
    else
      libmesh_error_msg("Constraints function not defined in __libmesh_tao_inequality_constraints_jacobian");

    J_petsc.close();
    Jpre_petsc.close();

    PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
  }

} // end extern "C"
//---------------------------------------------------------------------
547  
548  
549  
550  
551  
552  
553  
554  
555  
556  
557  
558  
559  
560  
561  
562  
563  
564  
  if (this->lower_and_upper_bounds_object)
    {
      // Need to actually compute the bounds vectors first
      this->lower_and_upper_bounds_object->lower_and_upper_bounds(this->system());

      LibmeshPetscCall(TaoSetVariableBounds(_tao,
                                            lb->vec(),
                                            ub->vec()));
    }

  if (this->equality_constraints_object)
    LibmeshPetscCall(TaoSetEqualityConstraintsRoutine(_tao, ceq->vec(), __libmesh_tao_equality_constraints, this));

  if (this->equality_constraints_jacobian_object)
    LibmeshPetscCall(TaoSetJacobianEqualityRoutine(_tao,
                                                   ceq_jac->mat(),
                                                   ceq_jac->mat(),
                                                   __libmesh_tao_equality_constraints_jacobian,
566  
567  
568  
569  
570  
571  
572  
573  
574  
575  
576  

  // Optionally set inequality constraints
  if (this->inequality_constraints_object)
    LibmeshPetscCall(TaoSetInequalityConstraintsRoutine(_tao, cineq->vec(), __libmesh_tao_inequality_constraints, this));

  // Optionally set inequality constraints Jacobian
  if (this->inequality_constraints_jacobian_object)
    LibmeshPetscCall(TaoSetJacobianInequalityRoutine(_tao,
                                                     cineq_jac->mat(),
                                                     cineq_jac->mat(),
                                                     __libmesh_tao_inequality_constraints_jacobian,
594  
595  
596  
597  
598  
599  
600  


template <typename T>
void TaoOptimizationSolver<T>::get_dual_variables()
{
  LOG_SCOPE("get_dual_variables()", "TaoOptimizationSolver");

603  
604  
605  
606  
607  
608  
609  
610  
611  
612  
613  
614  
615  
  PetscVector<T> * lambda_ineq_petsc =
    cast_ptr<PetscVector<T> *>(this->system().lambda_ineq.get());

  Vec lambda_eq_petsc_vec = lambda_eq_petsc->vec();
  Vec lambda_ineq_petsc_vec = lambda_ineq_petsc->vec();

  LibmeshPetscCall(TaoGetDualVariables(_tao,
                                       &lambda_eq_petsc_vec,
                                       &lambda_ineq_petsc_vec));
}


template <typename T>

src/systems/condensed_eigen_system.C

66  
67  
68  
69  
70  
71  
72  

  // Now erase the condensed dofs
  for (const auto dof : global_dirichlet_dofs_set)
    if ((dof_map.first_dof() <= dof) && (dof < dof_map.end_dof()))
      local_non_condensed_dofs_set.erase(dof);

  // Finally, move local_non_condensed_dofs_set over to a vector for convenience in solve()

src/systems/fem_context.C

1667  
1668  
1669  
1670  
1671  
1672  
1673  
1674  
1675  
1676  
1677  
1678  
1679  
1680  
1681  
1682  
1683  
  if (this->get_mesh_x_var() != libMesh::invalid_uint)
    for (unsigned int i=0; i != n_nodes; ++i)
      const_cast<Elem &>(this->get_elem()).point(i)(0) =
        libmesh_real(this->get_elem_solution(this->get_mesh_x_var())(i));

  if (this->get_mesh_y_var() != libMesh::invalid_uint)
    for (unsigned int i=0; i != n_nodes; ++i)
      const_cast<Elem &>(this->get_elem()).point(i)(1) =
        libmesh_real(this->get_elem_solution(this->get_mesh_y_var())(i));

  if (this->get_mesh_z_var() != libMesh::invalid_uint)
    for (unsigned int i=0; i != n_nodes; ++i)
      const_cast<Elem &>(this->get_elem()).point(i)(2) =
        libmesh_real(this->get_elem_solution(this->get_mesh_z_var())(i));
  //    }
  // FIXME - If the coordinate data is not in our own system, someone
  // had better get around to implementing that... - RHS

src/systems/optimization_system.C

79  
80  
81  
82  
83  
84  
85  
}


void OptimizationSystem::
initialize_equality_constraints_storage(const std::vector<std::set<numeric_index_type>> & constraint_jac_sparsity)
{
  numeric_index_type n_eq_constraints =
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  

  // Assign rows to each processor as evenly as possible
  unsigned int n_procs = comm().size();
  numeric_index_type n_local_rows = n_eq_constraints / n_procs;
  if (comm().rank() < (n_eq_constraints % n_procs))
    n_local_rows++;

  C_eq->init(n_eq_constraints, n_local_rows, false, PARALLEL);
  lambda_eq->init(n_eq_constraints, n_local_rows, false, PARALLEL);

  // Get the maximum number of non-zeros per row
  numeric_index_type max_nnz = 0;
  for (numeric_index_type i=0; i<n_eq_constraints; i++)
    {
      numeric_index_type nnz =
        cast_int<numeric_index_type>(constraint_jac_sparsity[i].size());
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
        max_nnz = nnz;
    }

  C_eq_jac->init(n_eq_constraints,
                 get_dof_map().n_dofs(),
                 n_local_rows,
                 get_dof_map().n_local_dofs(),
                 max_nnz,
                 max_nnz);

  eq_constraint_jac_sparsity = constraint_jac_sparsity;
}


void OptimizationSystem::
initialize_inequality_constraints_storage(const std::vector<std::set<numeric_index_type>> & constraint_jac_sparsity)
{
  numeric_index_type n_ineq_constraints =
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  

  // Assign rows to each processor as evenly as possible
  unsigned int n_procs = comm().size();
  numeric_index_type n_local_rows = n_ineq_constraints / n_procs;
  if (comm().rank() < (n_ineq_constraints % n_procs))
    n_local_rows++;

  C_ineq->init(n_ineq_constraints, n_local_rows, false, PARALLEL);
  lambda_ineq->init(n_ineq_constraints, n_local_rows, false, PARALLEL);

  // Get the maximum number of non-zeros per row
  numeric_index_type max_nnz = 0;
  for (numeric_index_type i=0; i<n_ineq_constraints; i++)
    {
      numeric_index_type nnz =
        cast_int<numeric_index_type>(constraint_jac_sparsity[i].size());
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
        max_nnz = nnz;
    }

  C_ineq_jac->init(n_ineq_constraints,
                   get_dof_map().n_dofs(),
                   n_local_rows,
                   get_dof_map().n_local_dofs(),
                   max_nnz,
                   max_nnz);

  ineq_constraint_jac_sparsity = constraint_jac_sparsity;
}


void OptimizationSystem::solve ()

src/utils/point_locator_tree.C

306  
307  
308  
309  
310  
311  
312  
        }
    }

  return nullptr;
}