MFEM v4.8.0
Finite element discretization library
Loading...
Searching...
No Matches
hybridization_ext.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#include "hybridization_ext.hpp"
13#include "hybridization.hpp"
14#include "pfespace.hpp"
15#include "../general/forall.hpp"
17#include "../linalg/kernels.hpp"
18
19namespace mfem
20{
21
23 : h(hybridization_)
24{ }
25
26static int GetNFacesPerElement(const Mesh &mesh)
27{
28 const int dim = mesh.Dimension();
29 switch (dim)
30 {
31 case 2: return mesh.GetElement(0)->GetNEdges();
32 case 3: return mesh.GetElement(0)->GetNFaces();
33 default: MFEM_ABORT("Invalid dimension.");
34 }
35}
36
38{
39 Mesh &mesh = *h.fes.GetMesh();
40 const int ne = mesh.GetNE();
41 const int nf = mesh.GetNFbyType(FaceType::Interior);
42 const int m = h.fes.GetFE(0)->GetDof(); // num hat dofs per el
43 const int n = h.c_fes.GetFaceElement(0)->GetDof(); // num c dofs per face
44 const int n_faces_per_el = GetNFacesPerElement(mesh);
45
46 // Assemble Ct_mat using EA
47 Vector emat(m * n * 2 * nf);
48 h.c_bfi->AssembleEAInteriorFaces(h.c_fes, h.fes, emat, false);
49
50 const auto *tbe = dynamic_cast<const TensorBasisElement*>(h.fes.GetFE(0));
51 MFEM_VERIFY(tbe, "");
52 // Note: copying the DOF map here (instead of using a reference) because
53 // reading it on GPU can cause issues in other parts of the code when using
54 // the debug device. The DOF map is accessed in other places without
55 // explicitly calling HostRead, which fails on non-const access if the device
56 // pointer is valid.
57 Array<int> dof_map = tbe->GetDofMap();
58
59 Ct_mat.SetSize(m * n * n_faces_per_el * ne);
60 const auto d_emat = Reshape(emat.Read(), m, n, 2, nf);
61 const int *d_dof_map = dof_map.Read();
62 const auto d_face_to_el = Reshape(face_to_el.Read(), 2, 2, nf);
63 auto d_Ct_mat = Reshape(Ct_mat.Write(), m, n, n_faces_per_el, ne);
64
65 mfem::forall(Ct_mat.Size(), [=] MFEM_HOST_DEVICE (int i)
66 {
67 d_Ct_mat[i] = 0.0;
68 });
69
70 mfem::forall(m*n*2*nf, [=] MFEM_HOST_DEVICE (int idx)
71 {
72 const int i_lex = idx % m;
73 const int j = (idx / m) % n;
74 const int ie = (idx / m / n) % 2;
75 const int f = idx / m / n / 2;
76
77 const int e = d_face_to_el(0, ie, f);
78 const int fi = d_face_to_el(1, ie, f);
79
80 // Skip elements belonging to face neighbors of shared faces
81 if (e < ne)
82 {
83 // Convert to back to native MFEM ordering in the volume
84 const int i_s = d_dof_map[i_lex];
85 const int i = (i_s >= 0) ? i_s : -1 - i_s;
86 d_Ct_mat(i, j, fi, e) = d_emat(i_lex, j, ie, f);
87 }
88 });
89}
90
91namespace internal
92{
93template <typename T, int SIZE>
94struct LocalMemory
95{
96 T data[SIZE];
97 MFEM_HOST_DEVICE inline operator T *() const { return (T*)data; }
98};
99
100template <typename T>
101struct LocalMemory<T,0>
102{
103 MFEM_HOST_DEVICE inline operator T *() const { return (T*)nullptr; }
104};
105};
106
107template <int MID, int MBD>
109{
110 const Mesh &mesh = *h.fes.GetMesh();
111 const int ne = mesh.GetNE();
112 const int n_faces_per_el = GetNFacesPerElement(mesh);
113 const int m = h.fes.GetFE(0)->GetDof();
114 const int n = h.c_fes.GetFaceElement(0)->GetDof();
115
116 AhatInvCt_mat.SetSize(Ct_mat.Size());
117 auto d_AhatInvCt = Reshape(AhatInvCt_mat.Write(), m, n, n_faces_per_el, ne);
118
119 {
120 const int nidofs = idofs.Size();
121 const int nbdofs = bdofs.Size();
122
123 MFEM_VERIFY(nidofs <= MID, "");
124 MFEM_VERIFY(nbdofs <= MBD, "");
125
126 Ahat_ii.SetSize(nidofs*nidofs*ne);
127 Ahat_ib.SetSize(nidofs*nbdofs*ne);
128 Ahat_bi.SetSize(nbdofs*nidofs*ne);
129 Ahat_bb.SetSize(nbdofs*nbdofs*ne);
130
131 Ahat_ii_piv.SetSize(nidofs*ne);
132 Ahat_bb_piv.SetSize(nbdofs*ne);
133
134 const auto *d_idofs = idofs.Read();
135 const auto *d_bdofs = bdofs.Read();
136
137 const auto d_hat_dof_marker = Reshape(hat_dof_marker.Read(), m, ne);
138 auto d_Ahat = Reshape(Ahat.Read(), m, m, ne);
139
140 auto d_A_ii = Reshape(Ahat_ii.Write(), nidofs, nidofs, ne);
141 auto d_A_ib_all = Reshape(Ahat_ib.Write(), nidofs*nbdofs, ne);
142 auto d_A_bi_all = Reshape(Ahat_bi.Write(), nbdofs*nidofs, ne);
143 auto d_A_bb_all = Reshape(Ahat_bb.Write(), nbdofs*nbdofs, ne);
144
145 auto d_ipiv_ii = Reshape(Ahat_ii_piv.Write(), nidofs, ne);
146 auto d_ipiv_bb = Reshape(Ahat_bb_piv.Write(), nbdofs, ne);
147
148 const auto d_Ct_mat = Reshape(Ct_mat.Read(), m, n, n_faces_per_el, ne);
149
150 static constexpr bool GLOBAL = (MID == 0 && MBD == 0);
151
152 using internal::LocalMemory;
153
154 mfem::forall(ne, [=] MFEM_HOST_DEVICE (int e)
155 {
156 constexpr int MD1D = DofQuadLimits::HDIV_MAX_D1D;
157 constexpr int MAX_DOFS = 3*MD1D*(MD1D-1)*(MD1D-1);
158 constexpr int MAX_IDOFS = (MID == 0 && MBD == 0) ? MAX_DOFS : MID;
159 constexpr int MAX_BDOFS = (MID == 0 && MBD == 0) ? MAX_DOFS : MBD;
160
161 LocalMemory<int,MAX_IDOFS> idofs_loc;
162 LocalMemory<int,MAX_BDOFS> bdofs_loc;
163 for (int i = 0; i < nidofs; i++) { idofs_loc[i] = d_idofs[i]; }
164 for (int i = 0; i < nbdofs; i++) { bdofs_loc[i] = d_bdofs[i]; }
165
166 LocalMemory<int,MAX_BDOFS> essdofs_loc;
167 int nbfdofs = 0;
168 int nessdofs = 0;
169 for (int i = 0; i < nbdofs; i++)
170 {
171 const int dof_idx = bdofs_loc[i];
172 if (d_hat_dof_marker(dof_idx, e) == ESSENTIAL)
173 {
174 essdofs_loc[nessdofs] = dof_idx;
175 nessdofs += 1;
176 }
177 else
178 {
179 bdofs_loc[nbfdofs] = dof_idx;
180 nbfdofs += 1;
181 }
182 }
183
184 LocalMemory<real_t, MID*MID> A_ii_loc;
185 LocalMemory<real_t, MBD*MID> A_bi_loc;
186 LocalMemory<real_t, MID*MBD> A_ib_loc;
187 LocalMemory<real_t, MBD*MBD> A_bb_loc;
188
189 DeviceMatrix A_ii(GLOBAL ? &d_A_ii(0,0,e) : A_ii_loc, nidofs, nidofs);
190 DeviceMatrix A_ib(GLOBAL ? &d_A_ib_all(0,e) : A_ib_loc, nidofs, nbfdofs);
191 DeviceMatrix A_bi(GLOBAL ? &d_A_bi_all(0,e) : A_bi_loc, nbfdofs, nidofs);
192 DeviceMatrix A_bb(GLOBAL ? &d_A_bb_all(0,e) : A_bb_loc, nbfdofs, nbfdofs);
193
194 for (int j = 0; j < nidofs; j++)
195 {
196 const int jj = idofs_loc[j];
197 for (int i = 0; i < nidofs; i++)
198 {
199 A_ii(i,j) = d_Ahat(idofs_loc[i], jj, e);
200 }
201 for (int i = 0; i < nbfdofs; i++)
202 {
203 A_bi(i,j) = d_Ahat(bdofs_loc[i], jj, e);
204 }
205 }
206 for (int j = 0; j < nbfdofs; j++)
207 {
208 const int jj = bdofs_loc[j];
209 for (int i = 0; i < nidofs; i++)
210 {
211 A_ib(i,j) = d_Ahat(idofs_loc[i], jj, e);
212 }
213 for (int i = 0; i < nbfdofs; i++)
214 {
215 A_bb(i,j) = d_Ahat(bdofs_loc[i], jj, e);
216 }
217 }
218
219 LocalMemory<int,MID> ipiv_ii_loc;
220 LocalMemory<int,MBD> ipiv_bb_loc;
221
222 auto ipiv_ii = GLOBAL ? &d_ipiv_ii(0,e) : ipiv_ii_loc;
223 auto ipiv_bb = GLOBAL ? &d_ipiv_ii(0,e) : ipiv_bb_loc;
224
225 kernels::LUFactor(A_ii, nidofs, ipiv_ii);
226 kernels::BlockFactor(A_ii, nidofs, ipiv_ii, nbfdofs, A_ib, A_bi, A_bb);
227 kernels::LUFactor(A_bb, nbfdofs, ipiv_bb);
228
229 for (int f = 0; f < n_faces_per_el; ++f)
230 {
231 for (int j = 0; j < n; ++j)
232 {
233 LocalMemory<real_t,MAX_BDOFS> Sb_inv_Cb_t;
234 for (int i = 0; i < nbfdofs; ++i)
235 {
236 Sb_inv_Cb_t[i] = d_Ct_mat(bdofs_loc[i], j, f, e);
237 }
238 kernels::LUSolve(A_bb, nbfdofs, ipiv_bb, Sb_inv_Cb_t);
239 for (int i = 0; i < nbfdofs; ++i)
240 {
241 const int b_i = bdofs_loc[i];
242 d_AhatInvCt(b_i, j, f, e) = Sb_inv_Cb_t[i];
243 }
244 for (int i = 0; i < nidofs; ++i)
245 {
246 d_AhatInvCt(idofs_loc[i], j, f, e) = 0.0;
247 }
248 for (int i = 0; i < nessdofs; ++i)
249 {
250 d_AhatInvCt(essdofs_loc[i], j, f, e) = 0.0;
251 }
252 }
253 }
254
255 // Write out to global memory
256 if (!GLOBAL)
257 {
258 DeviceMatrix d_A_bi(&d_A_bi_all(0,e), nbfdofs, nidofs);
259 DeviceMatrix d_A_ib(&d_A_ib_all(0,e), nidofs, nbfdofs);
260 DeviceMatrix d_A_bb(&d_A_bb_all(0,e), nbfdofs, nbfdofs);
261
262 for (int j = 0; j < nidofs; j++)
263 {
264 d_ipiv_ii(j,e) = ipiv_ii[j];
265 for (int i = 0; i < nidofs; i++)
266 {
267 d_A_ii(i,j,e) = A_ii(i,j);
268 }
269 for (int i = 0; i < nbfdofs; i++)
270 {
271 d_A_bi(i,j) = A_bi(i,j);
272 }
273 }
274 for (int j = 0; j < nbfdofs; j++)
275 {
276 d_ipiv_bb(j,e) = ipiv_bb[j];
277 for (int i = 0; i < nidofs; i++)
278 {
279 d_A_ib(i,j) = A_ib(i,j);
280 }
281 for (int i = 0; i < nbfdofs; i++)
282 {
283 d_A_bb(i,j) = A_bb(i,j);
284 }
285 }
286 }
287 });
288 }
289}
290
292{
293 const Mesh &mesh = *h.fes.GetMesh();
294 const int ne = mesh.GetNE();
295 const int n_faces_per_el = GetNFacesPerElement(mesh);
296 const int m = h.fes.GetFE(0)->GetDof();
297 const int n = h.c_fes.GetFaceElement(0)->GetDof();
298
299 Vector AhatInvCt_mat;
300
301 {
302 const int NI = idofs.Size();
303 const int NB = bdofs.Size();
304 // 2D
305 if (NI == 0 && NB <= 4) { FactorElementMatrices<0,4>(AhatInvCt_mat); }
306 else if (NI <= 4 && NB <= 8) { FactorElementMatrices<4,8>(AhatInvCt_mat); }
307 else if (NI <= 12 && NB <= 12) { FactorElementMatrices<12,12>(AhatInvCt_mat); }
308 else if (NI <= 24 && NB <= 16) { FactorElementMatrices<12,16>(AhatInvCt_mat); }
309 // 3D
310 else if (NI <= 0 && NB <= 6) { FactorElementMatrices<0,6>(AhatInvCt_mat); }
311 else if (NI <= 12 && NB <= 24) { FactorElementMatrices<12,24>(AhatInvCt_mat); }
312 else if (NI <= 54 && NB <= 54) { FactorElementMatrices<54,54>(AhatInvCt_mat); }
313 // Fallback
314 else { FactorElementMatrices<0,0>(AhatInvCt_mat); }
315 }
316
317 const auto d_AhatInvCt =
318 Reshape(AhatInvCt_mat.Read(), m, n, n_faces_per_el, ne);
319
320 const int nf = h.fes.GetNFbyType(FaceType::Interior);
321 const int n_face_connections = 2*n_faces_per_el - 1;
322 Array<int> face_to_face(nf * n_face_connections);
323
324 Array<real_t> CAhatInvCt(nf*n_face_connections*n*n);
325
326 const auto d_Ct = Reshape(Ct_mat.Read(), m, n, n_faces_per_el, ne);
327 const auto d_face_to_el = Reshape(face_to_el.Read(), 2, 2, nf);
328 const auto d_el_to_face = Reshape(el_to_face.Read(), n_faces_per_el, ne);
329 auto d_CAhatInvCt = Reshape(CAhatInvCt.Write(), n, n, n_face_connections, nf);
330 auto d_face_to_face = Reshape(face_to_face.Write(), n_face_connections, nf);
331
332 mfem::forall(n*n*n_face_connections*nf, [=] MFEM_HOST_DEVICE (int i)
333 {
334 d_CAhatInvCt[i] = 0.0;
335 });
336
337 mfem::forall(nf, [=] MFEM_HOST_DEVICE (int fi)
338 {
339 int idx = 0;
340 for (int ei = 0; ei < 2; ++ei)
341 {
342 const int e = d_face_to_el(0, ei, fi);
343 if (e < 0 || e >= ne) { continue; }
344 for (int fj_i = 0; fj_i < n_faces_per_el; ++fj_i)
345 {
346 const int fj = d_el_to_face(fj_i, e);
347 // Explicitly allow fi == fj (self-connections)
348 if (fj < 0) { continue; }
349
350 // Have we seen this face before? It is possible in some
351 // configurations to encounter the same neighboring face twice
352 int idx_j = idx;
353 for (int i = 0; i < idx; ++i)
354 {
355 if (d_face_to_face(i, fi) == fj)
356 {
357 idx_j = i;
358 break;
359 }
360 }
361 // This is a new face, record it and increment the counter
362 if (idx_j == idx)
363 {
364 d_face_to_face(idx, fi) = fj;
365 idx++;
366 }
367 }
368 }
369 // Fill unused entries with -1 to indicate invalid
370 for (; idx < n_face_connections; ++idx)
371 {
372 d_face_to_face(idx, fi) = -1;
373 }
374 });
375
376 mfem::forall(nf*n_face_connections, [=] MFEM_HOST_DEVICE (int idx)
377 {
378 const int idx_j = idx % n_face_connections;
379 const int fi = idx / n_face_connections;
380
381 const int fj = d_face_to_face(idx_j, fi);
382 if (fj < 0) { return; }
383
384 for (int ei = 0; ei < 2; ++ei)
385 {
386 const int e = d_face_to_el(0, ei, fi);
387 if (e < 0 || e >= ne) { continue; }
388 const int fi_i = d_face_to_el(1, ei, fi);
389
390 int fj_i = -1;
391 for (int ej = 0; ej < 2; ++ej)
392 {
393 if (d_face_to_el(0, ej, fj) == e)
394 {
395 fj_i = d_face_to_el(1, ej, fj);
396 break;
397 }
398 }
399 if (fj_i >= 0)
400 {
401 const real_t *Ct_i = &d_Ct(0, 0, fi_i, e);
402 const real_t *AhatInvCt_i = &d_AhatInvCt(0, 0, fj_i, e);
403 real_t *CAhatInvCt_i = &d_CAhatInvCt(0, 0, idx_j, fi);
404 kernels::AddMultAtB(m, n, n, Ct_i, AhatInvCt_i, CAhatInvCt_i);
405 }
406 }
407 });
408
409 const int ncdofs = h.c_fes.GetVSize();
411 const FaceRestriction *face_restr =
413 const auto c_gather_map = Reshape(face_restr->GatherMap().Read(), n, nf);
414
415 h.H.reset(new SparseMatrix);
416 h.H->OverrideSize(ncdofs, ncdofs);
417
418 h.H->GetMemoryI().New(ncdofs + 1, h.H->GetMemoryI().GetMemoryType());
419
420 {
421 int *I = h.H->WriteI();
422
423 mfem::forall(ncdofs, [=] MFEM_HOST_DEVICE (int i) { I[i] = 0; });
424
425 mfem::forall(nf*n, [=] MFEM_HOST_DEVICE (int idx_i)
426 {
427 const int i = idx_i % n;
428 const int fi = idx_i / n;
429 const int ii = c_gather_map(i, fi);
430
431 for (int idx = 0; idx < n_face_connections; ++idx)
432 {
433 const int fj = d_face_to_face(idx, fi);
434 if (fj < 0) { break; }
435 for (int j = 0; j < n; ++j)
436 {
437 if (d_CAhatInvCt(i, j, idx, fi) != 0)
438 {
439 I[ii]++;
440 }
441 }
442 }
443 });
444 }
445
446 // At this point, I[i] contains the number of nonzeros in row I. Perform a
447 // partial sum to get I in CSR format. This is serial, so perform on host.
448 //
449 // At the same time, we find any empty rows and add a single nonzero (we will
450 // put 1 on the diagonal) and record the row index.
451 Array<int> empty_rows;
452 {
453 int *I = h.H->HostReadWriteI();
454 int empty_row_count = 0;
455 for (int i = 0; i < ncdofs; i++)
456 {
457 if (I[i] == 0) { empty_row_count++; }
458 }
459 empty_rows.SetSize(empty_row_count);
460
461 int empty_row_idx = 0;
462 int sum = 0;
463 for (int i = 0; i < ncdofs; i++)
464 {
465 int nnz = I[i];
466 if (nnz == 0)
467 {
468 empty_rows[empty_row_idx] = i;
469 empty_row_idx++;
470 nnz = 1;
471 }
472 I[i] = sum;
473 sum += nnz;
474 }
475 I[ncdofs] = sum;
476 }
477
478 const int nnz = h.H->HostReadI()[ncdofs];
479 h.H->GetMemoryJ().New(nnz, h.H->GetMemoryJ().GetMemoryType());
480 h.H->GetMemoryData().New(nnz, h.H->GetMemoryData().GetMemoryType());
481
482 {
483 int *I = h.H->ReadWriteI();
484 int *J = h.H->WriteJ();
485 real_t *V = h.H->WriteData();
486
487 mfem::forall(nf*n, [=] MFEM_HOST_DEVICE (int idx_i)
488 {
489 const int i = idx_i % n;
490 const int fi = idx_i / n;
491 const int ii = c_gather_map[i + fi*n];
492 for (int idx = 0; idx < n_face_connections; ++idx)
493 {
494 const int fj = d_face_to_face(idx, fi);
495 if (fj < 0) { break; }
496 for (int j = 0; j < n; ++j)
497 {
498 const real_t val = d_CAhatInvCt(i, j, idx, fi);
499 if (val != 0)
500 {
501 const int k = I[ii];
502 const int jj = c_gather_map(j, fj);
503 I[ii]++;
504 J[k] = jj;
505 V[k] = val;
506 }
507 }
508 }
509 });
510
511 const int *d_empty_rows = empty_rows.Read();
512 mfem::forall(empty_rows.Size(), [=] MFEM_HOST_DEVICE (int idx)
513 {
514 const int i = d_empty_rows[idx];
515 const int k = I[i];
516 I[i]++;
517 J[k] = i;
518 V[k] = 1.0;
519 });
520 }
521
522 // Shift back down (serial, done on host)
523 {
524 int *I = h.H->HostReadWriteI();
525 for (int i = ncdofs - 1; i > 0; --i)
526 {
527 I[i] = I[i-1];
528 }
529 I[0] = 0;
530 }
531
532#ifdef MFEM_USE_MPI
533 auto *c_pfes = dynamic_cast<ParFiniteElementSpace*>(&h.c_fes);
534 if (c_pfes)
535 {
536 OperatorHandle pP(h.pH.Type()), dH(h.pH.Type());
537 pP.ConvertFrom(c_pfes->Dof_TrueDof_Matrix());
538 dH.MakeSquareBlockDiag(c_pfes->GetComm(),c_pfes->GlobalVSize(),
539 c_pfes->GetDofOffsets(), h.H.get());
540 h.pH.MakePtAP(dH, pP);
541 h.H.reset();
542 }
543#endif
544}
545
547{
548 Mesh &mesh = *h.fes.GetMesh();
549 const int ne = mesh.GetNE();
550 const int nf = mesh.GetNFbyType(FaceType::Interior);
551
552 const int n_hat_dof_per_el = h.fes.GetFE(0)->GetDof();
553 const int n_c_dof_per_face = h.c_fes.GetFaceElement(0)->GetDof();
554 const int n_faces_per_el = GetNFacesPerElement(mesh);
555
557 const FaceRestriction *face_restr =
559
560 Vector x_evec(face_restr->Height());
561 face_restr->Mult(x, x_evec);
562
563 const int *d_el_to_face = el_to_face.Read();
564 const auto d_Ct = Reshape(Ct_mat.Read(), n_hat_dof_per_el, n_c_dof_per_face,
565 n_faces_per_el, ne);
566 const auto d_x_evec = Reshape(x_evec.Read(), n_c_dof_per_face, nf);
567 auto d_y = Reshape(y.Write(), n_hat_dof_per_el, ne);
568
569 mfem::forall(ne * n_hat_dof_per_el, [=] MFEM_HOST_DEVICE (int idx)
570 {
571 const int e = idx / n_hat_dof_per_el;
572 const int i = idx % n_hat_dof_per_el;
573 d_y(i, e) = 0.0;
574 for (int fi = 0; fi < n_faces_per_el; ++fi)
575 {
576 const int f = d_el_to_face[e*n_faces_per_el + fi];
577 if (f < 0) { continue; }
578 for (int j = 0; j < n_c_dof_per_face; ++j)
579 {
580 d_y(i, e) += d_Ct(i, j, fi, e)*d_x_evec(j, f);
581 }
582 }
583 });
584}
585
587{
588 Mesh &mesh = *h.fes.GetMesh();
589 const int ne = mesh.GetNE();
590 const int nf = mesh.GetNFbyType(FaceType::Interior);
591
592 const int n_hat_dof_per_el = h.fes.GetFE(0)->GetDof();
593 const int n_c_dof_per_face = h.c_fes.GetFaceElement(0)->GetDof();
594 const int n_faces_per_el = GetNFacesPerElement(mesh);
595
597 const FaceRestriction *face_restr = h.c_fes.GetFaceRestriction(
598 ordering, FaceType::Interior);
599
600 Vector y_evec(face_restr->Height());
601 const auto d_face_to_el = Reshape(face_to_el.Read(), 2, 2, nf);
602 const auto d_Ct = Reshape(Ct_mat.Read(), n_hat_dof_per_el, n_c_dof_per_face,
603 n_faces_per_el, ne);
604 auto d_x = Reshape(x.Read(), n_hat_dof_per_el, ne);
605 auto d_y_evec = Reshape(y_evec.Write(), n_c_dof_per_face, nf);
606
607 mfem::forall(nf * n_c_dof_per_face, [=] MFEM_HOST_DEVICE (int idx)
608 {
609 const int f = idx / n_c_dof_per_face;
610 const int j = idx % n_c_dof_per_face;
611 d_y_evec(j, f) = 0.0;
612 for (int el_i = 0; el_i < 2; ++el_i)
613 {
614 const int e = d_face_to_el(0, el_i, f);
615 const int fi = d_face_to_el(1, el_i, f);
616
617 // Skip face neighbor elements of shared faces
618 if (e >= ne) { continue; }
619
620 for (int i = 0; i < n_hat_dof_per_el; ++i)
621 {
622 d_y_evec(j, f) += d_Ct(i, j, fi, e)*d_x(i, e);
623 }
624 }
625 });
626
627 y.SetSize(face_restr->Width());
628 face_restr->MultTranspose(y_evec, y);
629}
630
632{
633 const int n = elmat.Width();
634 const real_t *d_elmat = elmat.Read();
635 real_t *d_Ahat = Ahat.ReadWrite();
636 const int offset = el*n*n;
637 mfem::forall(n*n, [=] MFEM_HOST_DEVICE (int i)
638 {
639 d_Ahat[offset + i] += d_elmat[i];
640 });
641}
642
644 const DenseMatrix &elmat)
645{
646 DenseMatrix B = elmat; // deep copy
647 const int n = h.fes.GetFE(0)->GetDof();
648 // Create mapping e2f from element DOF indices to face DOF indices
649 Array<int> e2f(n);
650 e2f = -1;
651 int el;
652 {
653 Mesh &mesh = *h.fes.GetMesh();
654 int info;
655 mesh.GetBdrElementAdjacentElement(bdr_el, el, info);
656 Array<int> lvdofs;
657 lvdofs.Reserve(elmat.Height());
659 mesh.Dimension() - 1, info, lvdofs);
660 // Convert local element dofs to local element vdofs.
661 const int vdim = h.fes.GetVDim();
662 Ordering::DofsToVDofs<Ordering::byNODES>(n/vdim, vdim, lvdofs);
663 MFEM_ASSERT(lvdofs.Size() == elmat.Height(), "internal error");
664
665 B.AdjustDofDirection(lvdofs);
667 // Create a map from local element vdofs to local boundary (face) vdofs.
668 for (int i = 0; i < lvdofs.Size(); i++)
669 {
670 e2f[lvdofs[i]] = i;
671 }
672 }
673
674 const int offset = el*n*n;
676 for (int j = 0; j < n; ++j)
677 {
678 const int j_f = e2f[j];
679 if (j_f < 0) { continue; }
680 for (int i = 0; i < n; ++i)
681 {
682 const int i_f = e2f[i];
683 if (i_f < 0) { continue; }
684 Ahat[offset + i + j*n] += B(i_f, j_f);
685 }
686 }
687}
688
690{
691 const real_t *d_elmats = elmats.Read();
692 real_t *d_Ahat = Ahat.ReadWrite();
693 mfem::forall(elmats.TotalSize(), [=] MFEM_HOST_DEVICE (int i)
694 {
695 d_Ahat[i] += d_elmats[i];
696 });
697}
698
699void HybridizationExtension::Init(const Array<int> &ess_tdof_list)
700{
701 // Verify that preconditions for the extension are met
702 const Mesh &mesh = *h.fes.GetMesh();
703 const int dim = mesh.Dimension();
704 const int ne = h.fes.GetNE();
705 const int ndof_per_el = h.fes.GetFE(0)->GetDof();
706 const int ndof_per_face = h.c_fes.GetFaceElement(0)->GetDof();
707
708 MFEM_VERIFY(!h.fes.IsVariableOrder(), "");
709 MFEM_VERIFY(dim == 2 || dim == 3, "");
710 MFEM_VERIFY(mesh.Conforming(), "");
711 MFEM_VERIFY(UsesTensorBasis(h.fes), "");
712
713 // Set up array for idofs and bdofs
714 {
715 const TensorBasisElement* tbe =
716 dynamic_cast<const TensorBasisElement*>(h.fes.GetFE(0));
717 MFEM_VERIFY(tbe != nullptr, "");
718 const Array<int> &dof_map = tbe->GetDofMap();
719
720 const int n_faces_per_el = GetNFacesPerElement(mesh);
721
722 Array<int> all_face_dofs;
723 for (int f = 0; f < n_faces_per_el; ++f)
724 {
725 Array<int> face_map(ndof_per_face);
726 h.fes.GetFE(0)->GetFaceMap(f, face_map);
727 all_face_dofs.Append(face_map);
728 }
729
730 Array<bool> b_marker(ndof_per_el);
731 b_marker = false;
732 for (int i = 0; i < all_face_dofs.Size(); ++i)
733 {
734 const int j_s = all_face_dofs[i];
735 const int j = (j_s >= 0) ? j_s : -1 - j_s;
736 const int j_nat_s = dof_map[j];
737 const int j_nat = (j_nat_s >= 0) ? j_nat_s : -1 - j_nat_s;
738 b_marker[j_nat] = true;
739 }
740
741 for (int i = 0; i < ndof_per_el; ++i)
742 {
743 if (b_marker[i]) { bdofs.Append(i); }
744 else { idofs.Append(i); }
745 }
746 }
747
748 // Set up face info arrays
749 const int n_faces_per_el = GetNFacesPerElement(mesh);
750 el_to_face.SetSize(ne * n_faces_per_el);
752 el_to_face = -1;
753
754 {
755 int face_idx = 0;
756 for (int f = 0; f < mesh.GetNumFaces(); ++f)
757 {
758 const Mesh::FaceInformation info = mesh.GetFaceInformation(f);
759 if (!info.IsInterior()) { continue; }
760
761 const int el1 = info.element[0].index;
762 const int fi1 = info.element[0].local_face_id;
763 el_to_face[el1 * n_faces_per_el + fi1] = face_idx;
764
765 const int el2 = info.element[1].index;
766 const int fi2 = info.element[1].local_face_id;
767 if (!info.IsShared())
768 {
769 el_to_face[el2 * n_faces_per_el + fi2] = face_idx;
770 }
771
772 face_to_el[0 + 4*face_idx] = el1;
773 face_to_el[1 + 4*face_idx] = fi1;
774 face_to_el[2 + 4*face_idx] = info.IsShared() ? ne + el2 : el2;
775 face_to_el[3 + 4*face_idx] = fi2;
776
777 ++face_idx;
778 }
779 }
780
781 // Count the number of dofs in the discontinuous version of fes:
782 num_hat_dofs = ne*ndof_per_el;
783 {
784 h.hat_offsets.SetSize(ne + 1);
785 int *d_hat_offsets = h.hat_offsets.Write();
786 mfem::forall(ne + 1, [=] MFEM_HOST_DEVICE (int i)
787 {
788 d_hat_offsets[i] = i*ndof_per_el;
789 });
790 }
791
792 Ahat.SetSize(ne*ndof_per_el*ndof_per_el);
793 Ahat.UseDevice(true);
794 Ahat = 0.0;
795
796 ConstructC();
797
799 const Operator *R_op = h.fes.GetElementRestriction(ordering);
800 const auto *R = dynamic_cast<const ElementRestriction*>(R_op);
801 MFEM_VERIFY(R, "");
802
803 // Find out which "hat DOFs" are essential (depend only on essential Lagrange
804 // multiplier DOFs).
805 {
806 const int ntdofs = h.fes.GetTrueVSize();
807 // free_tdof_marker is 1 if the DOF is free, 0 if the DOF is essential
808 Array<int> free_tdof_marker(ntdofs);
809 {
810 int *d_free_tdof_marker = free_tdof_marker.Write();
811 mfem::forall(ntdofs, [=] MFEM_HOST_DEVICE (int i)
812 {
813 d_free_tdof_marker[i] = 1;
814 });
815 const int n_ess_dofs = ess_tdof_list.Size();
816 const int *d_ess_tdof_list = ess_tdof_list.Read();
817 mfem::forall(n_ess_dofs, [=] MFEM_HOST_DEVICE (int i)
818 {
819 d_free_tdof_marker[d_ess_tdof_list[i]] = 0;
820 });
821 }
822
823 Array<int> free_vdofs_marker;
824#ifdef MFEM_USE_MPI
825 auto *pfes = dynamic_cast<ParFiniteElementSpace*>(&h.fes);
826 if (pfes)
827 {
828 HypreParMatrix *P = pfes->Dof_TrueDof_Matrix();
829 free_vdofs_marker.SetSize(h.fes.GetVSize());
830 // TODO: would be nice to do this on device
831 P->BooleanMult(1, free_tdof_marker.HostRead(),
832 0, free_vdofs_marker.HostWrite());
833 }
834 else
835 {
836 free_vdofs_marker.MakeRef(free_tdof_marker);
837 }
838#else
839 free_vdofs_marker.MakeRef(free_tdof_marker);
840#endif
841
843 {
844 // The gather map from the ElementRestriction operator gives us the
845 // index of the L-dof corresponding to a given (element, local DOF)
846 // index pair.
847 const int *gather_map = R->GatherMap().Read();
848 const int *d_free_vdofs_marker = free_vdofs_marker.Read();
849 const auto d_Ct_mat = Reshape(Ct_mat.Read(), ndof_per_el,
850 ndof_per_face, n_faces_per_el, ne);
851 DofType *d_hat_dof_marker = hat_dof_marker.Write();
852
853 // Set the hat_dofs_marker to 1 or 0 according to whether the DOF is
854 // "free" or "essential". (For now, we mark all free DOFs as free
855 // interior as a placeholder). Then, as a later step, the "free" DOFs
856 // will be further classified as "interior free" or "boundary free".
857 mfem::forall(num_hat_dofs, [=] MFEM_HOST_DEVICE (int i)
858 {
859 const int j_s = gather_map[i];
860 const int j = (j_s >= 0) ? j_s : -1 - j_s;
861 if (d_free_vdofs_marker[j])
862 {
863 const int i_loc = i % ndof_per_el;
864 const int e = i / ndof_per_el;
865 d_hat_dof_marker[i] = INTERIOR;
866 for (int f = 0; f < n_faces_per_el; ++f)
867 {
868 for (int k = 0; k < ndof_per_face; ++k)
869 {
870 if (d_Ct_mat(i_loc, k, f, e) != 0.0)
871 {
872 d_hat_dof_marker[i] = BOUNDARY;
873 break;
874 }
875 }
876 }
877 }
878 else
879 {
880 d_hat_dof_marker[i] = ESSENTIAL;
881 }
882 });
883 }
884 }
885
886 // Create the hat DOF gather map. This is used to apply the action of R and
887 // R^T
888 {
889 const int vsize = h.fes.GetVSize();
891 const int *d_offsets = R->Offsets().Read();
892 const int *d_indices = R->Indices().Read();
893 int *d_hat_dof_gather_map = hat_dof_gather_map.Write();
894 mfem::forall(num_hat_dofs, [=] MFEM_HOST_DEVICE (int i)
895 {
896 d_hat_dof_gather_map[i] = -1;
897 });
898 mfem::forall(vsize, [=] MFEM_HOST_DEVICE (int i)
899 {
900 const int offset = d_offsets[i];
901 const int j_s = d_indices[offset];
902 const int hat_dof_index = (j_s >= 0) ? j_s : -1 - j_s;
903 // Note: -1 is used as a special value (invalid), so the negative
904 // DOF indices start at -2.
905 d_hat_dof_gather_map[hat_dof_index] = (j_s >= 0) ? i : (-2 - i);
906 });
907 }
908}
909
910void HybridizationExtension::MultR(const Vector &x_hat, Vector &x) const
911{
913
914 // If R is null, then L-vector and T-vector are the same, and we don't need
915 // an intermediate temporary variable.
916 //
917 // If R is not null, we first convert to intermediate L-vector (with the
918 // correct BCs), and then from L-vector to T-vector.
919 if (!R)
920 {
921 MFEM_ASSERT(x.Size() == h.fes.GetVSize(), "");
922 tmp2.MakeRef(x, 0);
923 }
924 else
925 {
926 tmp2.SetSize(R->Width());
927 R->MultTranspose(x, tmp2);
928 }
929
931 const auto *restr = static_cast<const ElementRestriction*>(
932 h.fes.GetElementRestriction(ordering));
933 const int *gather_map = restr->GatherMap().Read();
934 const DofType *d_hat_dof_marker = hat_dof_marker.Read();
935 const real_t *d_evec = x_hat.Read();
936 real_t *d_lvec = tmp2.ReadWrite();
937 mfem::forall(num_hat_dofs, [=] MFEM_HOST_DEVICE (int i)
938 {
939 // Skip essential DOFs
940 if (d_hat_dof_marker[i] == ESSENTIAL) { return; }
941
942 const int j_s = gather_map[i];
943 const int sgn = (j_s >= 0) ? 1 : -1;
944 const int j = (j_s >= 0) ? j_s : -1 - j_s;
945
946 d_lvec[j] = sgn*d_evec[i];
947 });
948
949 // Convert from L-vector to T-vector.
950 if (R) { R->Mult(tmp2, x); }
951}
952
954{
955 Vector b_lvec;
957 if (!R)
958 {
959 b_lvec.MakeRef(const_cast<Vector&>(b), 0, b.Size());
960 }
961 else
962 {
964 b_lvec.MakeRef(tmp1, 0, tmp1.Size());
965 R->MultTranspose(b, b_lvec);
966 }
967
968 b_hat.SetSize(num_hat_dofs);
969 const int *d_hat_dof_gather_map = hat_dof_gather_map.Read();
970 const real_t *d_b_lvec = b_lvec.Read();
971 real_t *d_b_hat = b_hat.Write();
972 mfem::forall(num_hat_dofs, [=] MFEM_HOST_DEVICE (int i)
973 {
974 const int j_s = d_hat_dof_gather_map[i];
975 if (j_s == -1) // invalid
976 {
977 d_b_hat[i] = 0.0;
978 }
979 else
980 {
981 const int sgn = (j_s >= 0) ? 1 : -1;
982 const int j = (j_s >= 0) ? j_s : -2 - j_s;
983 d_b_hat[i] = sgn*d_b_lvec[j];
984 }
985 });
986}
987
989{
990 const int ne = h.fes.GetMesh()->GetNE();
991 const int n = h.fes.GetFE(0)->GetDof();
992
993 const int nidofs = idofs.Size();
994 const int nbdofs = bdofs.Size();
995
996 const auto d_hat_dof_marker = Reshape(hat_dof_marker.Read(), n, ne);
997
998 const auto d_A_ii = Reshape(Ahat_ii.Read(), nidofs, nidofs, ne);
999 const auto d_A_ib = Reshape(Ahat_ib.Read(), nidofs*nbdofs, ne);
1000 const auto d_A_bi = Reshape(Ahat_bi.Read(), nbdofs*nidofs, ne);
1001 const auto d_A_bb = Reshape(Ahat_bb.Read(), nbdofs*nbdofs, ne);
1002
1003 const auto d_ipiv_ii = Reshape(Ahat_ii_piv.Read(), nidofs, ne);
1004 const auto d_ipiv_bb = Reshape(Ahat_bb_piv.Read(), nbdofs, ne);
1005
1006 const auto *d_idofs = idofs.Read();
1007 const auto *d_bdofs = bdofs.Read();
1008
1009 Vector ivals(nidofs*ne);
1010 Vector bvals(nbdofs*ne);
1011 auto d_ivals = Reshape(ivals.Write(), nidofs, ne);
1012 auto d_bvals = Reshape(bvals.Write(), nbdofs, ne);
1013
1014 auto d_x = Reshape(x.ReadWrite(), n, ne);
1015
1016 mfem::forall(ne, [=] MFEM_HOST_DEVICE (int e)
1017 {
1018 constexpr int MD1D = DofQuadLimits::HDIV_MAX_D1D;
1019 constexpr int MAX_DOFS = 3*MD1D*(MD1D-1)*(MD1D-1);
1020 internal::LocalMemory<int,MAX_DOFS> bdofs_loc;
1021
1022 int nbfdofs = 0;
1023 for (int i = 0; i < nbdofs; i++)
1024 {
1025 const int dof_idx = d_bdofs[i];
1026 if (d_hat_dof_marker(dof_idx, e) != ESSENTIAL)
1027 {
1028 bdofs_loc[nbfdofs] = dof_idx;
1029 nbfdofs += 1;
1030 }
1031 }
1032
1033 for (int i = 0; i < nidofs; ++i)
1034 {
1035 d_ivals(i, e) = d_x(d_idofs[i], e);
1036 }
1037 for (int i = 0; i < nbfdofs; ++i)
1038 {
1039 d_bvals(i, e) = d_x(bdofs_loc[i], e);
1040 }
1041
1042 if (nidofs > 0)
1043 {
1044 // Block forward substitution:
1045 // B1 <- L^{-1} P B1
1046 kernels::LSolve(&d_A_ii(0,0,e), nidofs, &d_ipiv_ii(0,e), &d_ivals(0,e));
1047 // B2 <- B2 - L21 B1
1049 nidofs, nbfdofs, 1, &d_A_bi(0,e), &d_ivals(0,e), &d_bvals(0, e));
1050 }
1051
1052 // Schur complement solve
1053 kernels::LUSolve(&d_A_bb(0,e), nbfdofs, &d_ipiv_bb(0,e), &d_bvals(0,e));
1054
1055 if (nidofs > 0)
1056 {
1057 // Block backward substitution
1058 // Y1 <- Y1 - U12 X2
1060 nbfdofs, nidofs, 1, &d_A_ib(0,e), &d_bvals(0,e), &d_ivals(0, e));
1061 // Y1 <- U^{-1} Y1
1062 kernels::USolve(&d_A_ii(0,0,e), nidofs, &d_ivals(0,e));
1063 }
1064
1065 for (int i = 0; i < nidofs; ++i)
1066 {
1067 d_x(d_idofs[i], e) = d_ivals(i, e);
1068 }
1069 for (int i = 0; i < nbfdofs; ++i)
1070 {
1071 d_x(bdofs_loc[i], e) = d_bvals(i, e);
1072 }
1073 });
1074}
1075
1077{
1078 Vector b_hat(num_hat_dofs);
1079 MultRt(b, b_hat);
1080 {
1081 const auto *d_hat_dof_marker = hat_dof_marker.Read();
1082 auto *d_b_hat = b_hat.ReadWrite();
1083 mfem::forall(num_hat_dofs, [=] MFEM_HOST_DEVICE (int i)
1084 {
1085 if (d_hat_dof_marker[i] == ESSENTIAL) { d_b_hat[i] = 0.0; }
1086 });
1087 }
1088 MultAhatInv(b_hat);
1090 if (P)
1091 {
1092 Vector bl(P->Height());
1093 b_r.SetSize(P->Width());
1094 MultC(b_hat, bl);
1095 P->MultTranspose(bl, b_r);
1096 }
1097 else
1098 {
1099 MultC(b_hat, b_r);
1100 }
1101}
1102
1104 const Vector &b, const Vector &sol_r, Vector &sol) const
1105{
1106 // tmp1 = A_hat^{-1} ( R^T b - C^T lambda )
1107 Vector b_hat(num_hat_dofs);
1108 MultRt(b, b_hat);
1109
1112 if (P)
1113 {
1114 Vector sol_l(P->Height());
1115 P->Mult(sol_r, sol_l);
1116 MultCt(sol_l, tmp1);
1117 }
1118 else
1119 {
1120 MultCt(sol_r, tmp1);
1121 }
1122 add(b_hat, -1.0, tmp1, tmp1);
1123 // Eliminate essential DOFs
1124 const auto *d_hat_dof_marker = hat_dof_marker.Read();
1125 real_t *d_tmp1 = tmp1.ReadWrite();
1126 mfem::forall(num_hat_dofs, [=] MFEM_HOST_DEVICE (int i)
1127 {
1128 if (d_hat_dof_marker[i] == ESSENTIAL) { d_tmp1[i] = 0.0; }
1129 });
1131 MultR(tmp1, sol);
1132}
1133
1134}
const T * HostRead() const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), false).
Definition array.hpp:341
void Reserve(int capacity)
Ensures that the allocated size is at least the given size.
Definition array.hpp:165
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition array.hpp:758
int Size() const
Return the logical size of the array.
Definition array.hpp:147
void MakeRef(T *data_, int size_, bool own_data=false)
Make this Array a reference to a pointer.
Definition array.hpp:943
T * Write(bool on_dev=true)
Shortcut for mfem::Write(a.GetMemory(), a.Size(), on_dev).
Definition array.hpp:345
int Append(const T &el)
Append element 'el' to array, resize if necessary.
Definition array.hpp:830
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition array.hpp:337
T * HostWrite()
Shortcut for mfem::Write(a.GetMemory(), a.Size(), false).
Definition array.hpp:349
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
void AdjustDofDirection(Array< int > &dofs)
const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Definition densemat.hpp:474
Rank 3 tensor (array of matrices)
int TotalSize() const
const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
A basic generic Tensor class, appropriate for use on the GPU.
Definition dtensor.hpp:82
Operator that converts FiniteElementSpace L-vectors to E-vectors.
const Array< int > & GatherMap() const
virtual MFEM_DEPRECATED int GetNFaces(int &nFaceVertices) const =0
virtual int GetNEdges() const =0
Base class for operators that extracts Face degrees of freedom.
void MultTranspose(const Vector &x, Vector &y) const override
Set the face degrees of freedom in the element degrees of freedom y to the values given in x.
virtual const Array< int > & GatherMap() const
Low-level access to the underlying gather map.
void Mult(const Vector &x, Vector &y) const override=0
Extract the face degrees of freedom from x into y.
void SubDofOrder(Geometry::Type Geom, int SDim, int Info, Array< int > &dofs) const
Get the local dofs for a given sub-manifold.
Definition fe_coll.cpp:512
bool IsVariableOrder() const
Returns true if the space contains elements of varying polynomial orders.
Definition fespace.hpp:709
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
Definition fespace.hpp:851
static void AdjustVDofs(Array< int > &vdofs)
Remove the orientation information encoded into an array of dofs Some basis function types have a rel...
Definition fespace.cpp:310
virtual const Operator * GetProlongationMatrix() const
Definition fespace.hpp:727
virtual const Operator * GetRestrictionOperator() const
An abstract operator that performs the same action as GetRestrictionMatrix.
Definition fespace.hpp:746
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
Definition fespace.cpp:3835
int GetNE() const
Returns number of elements in the mesh.
Definition fespace.hpp:891
const ElementRestrictionOperator * GetElementRestriction(ElementDofOrdering e_ordering) const
Return an Operator that converts L-vectors to E-vectors.
Definition fespace.cpp:1510
const FiniteElement * GetFaceElement(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th face in the ...
Definition fespace.cpp:3914
int GetNFbyType(FaceType type) const
Returns the number of faces according to the requested type.
Definition fespace.hpp:908
const FiniteElementCollection * FEColl() const
Definition fespace.hpp:878
Mesh * GetMesh() const
Returns the mesh.
Definition fespace.hpp:679
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Definition fespace.hpp:848
int GetVDim() const
Returns the vector dimension of the finite element space.
Definition fespace.hpp:841
virtual const FaceRestriction * GetFaceRestriction(ElementDofOrdering f_ordering, FaceType, L2FaceValues mul=L2FaceValues::DoubleValued) const
Return an Operator that converts L-vectors to E-vectors on each face.
Definition fespace.cpp:1543
virtual void GetFaceMap(const int face_id, Array< int > &face_map) const
Return the mapping from lexicographic face DOFs to lexicographic element DOFs for the given local fac...
Definition fe_base.cpp:507
int GetDof() const
Returns the number of degrees of freedom in the finite element.
Definition fe_base.hpp:334
Vector Ct_mat
Constraint matrix (transposed) stored element-wise.
void ConstructC()
Construct the constraint matrix.
void Init(const Array< int > &ess_tdof_list)
Prepare for assembly; form the constraint matrix.
void FactorElementMatrices(Vector &AhatInvCt_mat)
void ReduceRHS(const Vector &b, Vector &b_r) const
Given a right-hand side on the original space, compute the corresponding right-hand side for the Lagr...
void ComputeSolution(const Vector &b, const Vector &sol_r, Vector &sol) const
Given Lagrange multipliers sol_r and the original right-hand side b, recover the solution sol on the ...
HybridizationExtension(class Hybridization &hybridization_)
Constructor.
Vector tmp2
Temporary vectors.
void ConstructH()
Form the Schur complement matrix .
void MultR(const Vector &b, Vector &b_hat) const
Apply the action of R mapping from "hat DOFs" to T-vector.
void MultC(const Vector &x, Vector &y) const
Compute the action of C x.
void MultAhatInv(Vector &x) const
Apply the elementwise A_hat^{-1}.
int num_hat_dofs
Number of Lagrange multipliers.
void AssembleMatrix(int el, const class DenseMatrix &elmat)
Assemble the element matrix A into the hybridized system matrix.
void MultCt(const Vector &x, Vector &y) const
Compute the action of C^t x.
class Hybridization & h
The associated Hybridization object.=.
void MultRt(const Vector &b, Vector &b_hat) const
Apply the action of R^t mapping into the "hat DOF" space.
void AssembleBdrMatrix(int bdr_el, const class DenseMatrix &elmat)
Assemble the boundary element matrix A into the hybridized system matrix.
void AssembleElementMatrices(const class DenseTensor &el_mats)
Invert and store the element matrices Ahat.
Auxiliary class Hybridization, used to implement BilinearForm hybridization.
Array< int > hat_offsets
FiniteElementSpace & c_fes
std::unique_ptr< SparseMatrix > H
The Schur complement system for the Lagrange multiplier.
FiniteElementSpace & fes
The finite element space.
std::unique_ptr< BilinearFormIntegrator > c_bfi
The constraint integrator.
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:408
void BooleanMult(int alpha, const int *x, int beta, int *y)
The "Boolean" analog of y = alpha * A * x + beta * y, where elements in the sparsity pattern of the m...
Definition hypre.hpp:787
Mesh data type.
Definition mesh.hpp:64
bool Conforming() const
Return a bool indicating whether this mesh is conforming.
Definition mesh.hpp:2365
int GetNumFaces() const
Return the number of faces (3D), edges (2D) or vertices (1D).
Definition mesh.cpp:6531
Geometry::Type GetElementGeometry(int i) const
Definition mesh.hpp:1434
virtual int GetNFbyType(FaceType type) const
Returns the number of faces according to the requested type, does not count master nonconforming face...
Definition mesh.cpp:6547
const Element * GetElement(int i) const
Return pointer to the i'th element object.
Definition mesh.hpp:1339
int GetNE() const
Returns number of elements.
Definition mesh.hpp:1282
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1216
FaceInformation GetFaceInformation(int f) const
Definition mesh.cpp:1193
void GetBdrElementAdjacentElement(int bdr_el, int &el, int &info) const
For the given boundary element, bdr_el, return its adjacent element and its info, i....
Definition mesh.cpp:7584
Pointer to an Operator of a specified type.
Definition handle.hpp:34
void MakePtAP(OperatorHandle &A, OperatorHandle &P)
Reset the OperatorHandle to hold the product P^t A P.
Definition handle.cpp:124
void MakeSquareBlockDiag(MPI_Comm comm, HYPRE_BigInt glob_size, HYPRE_BigInt *row_starts, SparseMatrix *diag)
Reset the OperatorHandle to hold a parallel square block-diagonal matrix using the currently set type...
Definition handle.cpp:61
Operator::Type Type() const
Get the currently set operator type id.
Definition handle.hpp:99
Abstract operator.
Definition operator.hpp:25
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition operator.hpp:66
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
Definition operator.hpp:72
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Definition operator.hpp:93
Abstract parallel finite element space.
Definition pfespace.hpp:29
Data type sparse matrix.
Definition sparsemat.hpp:51
const Array< int > & GetDofMap() const
Get an Array<int> that maps lexicographically ordered indices to the indices of the respective nodes/...
Definition fe_base.hpp:1273
Vector data type.
Definition vector.hpp:82
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:494
virtual real_t * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:510
int Size() const
Returns the size of the vector.
Definition vector.hpp:226
virtual void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
Definition vector.hpp:144
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:558
virtual real_t * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
Definition vector.hpp:514
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:502
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
Definition vector.hpp:622
int dim
Definition ex24.cpp:53
real_t b
Definition lissajous.cpp:42
MFEM_HOST_DEVICE void AddMultAtB(const int Aheight, const int Awidth, const int Bwidth, const TA *Adata, const TB *Bdata, TC *Cdata, const TB alpha, const TA beta)
Compute C = alpha*At*B + beta*C.
Definition kernels.hpp:411
MFEM_HOST_DEVICE void LSolve(const real_t *data, const int m, const int *ipiv, real_t *x)
Assuming L.U = P.A factored matrix of size (m x m), compute X <- L^{-1} P X, for a vector X of length...
Definition kernels.hpp:1700
MFEM_HOST_DEVICE void USolve(const real_t *data, const int m, real_t *x)
Assuming L.U = P.A factored matrix of size (m x m), compute X <- U^{-1} X, for a vector X of length m...
Definition kernels.hpp:1725
MFEM_HOST_DEVICE void BlockFactor(const real_t *data, int m, const int *ipiv, int n, real_t *A12, real_t *A21, real_t *A22)
Definition kernels.hpp:1783
MFEM_HOST_DEVICE bool LUFactor(real_t *A, const int m, int *ipiv, const real_t tol=0.0)
Compute the LU factorization of the m x m matrix A.
Definition kernels.hpp:1825
MFEM_HOST_DEVICE void SubMult(const int m, const int n, const int r, const real_t *A21, const real_t *X1, real_t *X2)
Given an (n x m) matrix A21, compute X2 <- X2 - A21 X1, for matrices X1, and X2 of size (m x r) and (...
Definition kernels.hpp:1755
MFEM_HOST_DEVICE void LUSolve(const real_t *data, const int m, const int *ipiv, real_t *x)
Assuming L.U = P.A for a factored matrix (m x m),.
Definition kernels.hpp:1745
void add(const Vector &v1, const Vector &v2, Vector &v)
Definition vector.cpp:391
MFEM_HOST_DEVICE DeviceTensor< sizeof...(Dims), T > Reshape(T *ptr, Dims... dims)
Wrap a pointer as a DeviceTensor with automatically deduced template parameters.
Definition dtensor.hpp:131
bool UsesTensorBasis(const FiniteElementSpace &fes)
Return true if the mesh contains only one topology and the elements are tensor elements.
Definition fespace.hpp:1555
float real_t
Definition config.hpp:43
@ SIZE
Number of host and device memory types.
ElementDofOrdering
Constants describing the possible orderings of the DOFs in one element.
Definition fespace.hpp:83
@ NATIVE
Native ordering as defined by the FiniteElement.
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
void forall(int N, lambda &&body)
Definition forall.hpp:753
This structure is used as a human readable output format that deciphers the information contained in ...
Definition mesh.hpp:1980
struct mfem::Mesh::FaceInformation::@15 element[2]
bool IsInterior() const
return true if the face is an interior face to the computation domain, either a local or shared inter...
Definition mesh.hpp:2014
bool IsShared() const
Return true if the face is a shared interior face which is NOT a master nonconforming face.
Definition mesh.hpp:2005