MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
coefficient.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// Implementation of Coefficient class
13
14#include "fem.hpp"
15#include "../general/forall.hpp"
16
17#include <cmath>
18#include <limits>
19
20namespace mfem
21{
22
23using namespace std;
24
25// Given an ElementTransformation and IntegrationPoint in a refined mesh,
26// return the ElementTransformation of the parent coarse element, and set
27// coarse_ip to the location of the original ip within the coarse element.
29 Mesh &coarse_mesh, const ElementTransformation &T,
30 const IntegrationPoint &ip, IntegrationPoint &coarse_ip)
31{
32 const Mesh &fine_mesh = *T.mesh;
33 // Get the element transformation of the coarse element containing the
34 // fine element.
35 int fine_element = T.ElementNo;
37 int coarse_element = cf.embeddings[fine_element].parent;
38 ElementTransformation *coarse_T = coarse_mesh.GetElementTransformation(
39 coarse_element);
40 // Transform the integration point from fine element coordinates to coarse
41 // element coordinates.
43 IntegrationPointTransformation fine_to_coarse;
44 IsoparametricTransformation &emb_tr = fine_to_coarse.Transf;
45 emb_tr.SetIdentityTransformation(geom);
46 emb_tr.SetPointMat(cf.point_matrices[geom](cf.embeddings[fine_element].matrix));
47 fine_to_coarse.Transform(ip, coarse_ip);
48 coarse_T->SetIntPoint(&coarse_ip);
49 return coarse_T;
50}
51
53{
54 QuadratureSpaceBase &qspace = *qf.GetSpace();
55 const int ne = qspace.GetNE();
56 Vector values;
57 for (int iel = 0; iel < ne; ++iel)
58 {
59 qf.GetValues(iel, values);
60 const IntegrationRule &ir = qspace.GetIntRule(iel);
62 for (int iq = 0; iq < ir.Size(); ++iq)
63 {
64 const IntegrationPoint &ip = ir[iq];
65 T.SetIntPoint(&ip);
66 const int iq_p = qspace.GetPermutedIndex(iel, iq);
67 values[iq_p] = Eval(T, ip);
68 }
69 }
70}
71
76
78 const IntegrationPoint & ip)
79{
80 int att = T.Attribute;
81 return (constants(att-1));
82}
83
85{
86 auto &qs = *qf.GetSpace();
87
88 const bool compressed =
90 const int *offsets = qs.Offsets(QSpaceOffsetStorage::COMPRESSED).Read();
91 const int ne = qs.GetNE();
92
93 const int *attributes = [&]()
94 {
95 if (dynamic_cast<QuadratureSpace*>(&qs) != nullptr)
96 {
97 return qs.GetMesh()->GetElementAttributes().Read();
98 }
99 else if (auto *qs_f = dynamic_cast<FaceQuadratureSpace*>(&qs))
100 {
101 MFEM_VERIFY(qs_f->GetFaceType() == FaceType::Boundary,
102 "Interior faces do not have attributes.");
103 return qs.GetMesh()->GetBdrFaceAttributes().Read();
104 }
105 else
106 {
107 MFEM_ABORT("Unsupported case.");
108 }
109 }();
110
111 const real_t *d_c = constants.Read();
112 real_t *d_qf = qf.Write();
113
114 mfem::forall(ne, [=] MFEM_HOST_DEVICE (int e)
115 {
116 const int a = attributes[e];
117 const real_t elementConstant = d_c[a - 1];
118 const int begin = compressed ? e*offsets[0] : offsets[e];
119 const int end = compressed ? (e+1)*offsets[0] : offsets[e+1];
120 for (int i = begin; i < end; ++i)
121 {
122 d_qf[i] = elementConstant;
123 }
124 });
125}
126
127void PWCoefficient::InitMap(const Array<int> & attr,
128 const Array<Coefficient*> & coefs)
129{
130 MFEM_VERIFY(attr.Size() == coefs.Size(),
131 "PWCoefficient: "
132 "Attribute and coefficient arrays have incompatible "
133 "dimensions.");
134
135 for (int i=0; i<attr.Size(); i++)
136 {
137 if (coefs[i] != NULL)
138 {
139 UpdateCoefficient(attr[i], *coefs[i]);
140 }
141 }
142}
143
145{
147
148 std::map<int, Coefficient*>::iterator p = pieces.begin();
149 for (; p != pieces.end(); p++)
150 {
151 if (p->second != NULL)
152 {
153 p->second->SetTime(t);
154 }
155 }
156}
157
159 const IntegrationPoint &ip)
160{
161 const int att = T.Attribute;
162 std::map<int, Coefficient*>::const_iterator p = pieces.find(att);
163 if (p != pieces.end())
164 {
165 if ( p->second != NULL)
166 {
167 return p->second->Eval(T, ip);
168 }
169 }
170 return 0.0;
171}
172
174 const IntegrationPoint & ip)
175{
176 real_t x[3];
177 Vector transip(x, 3);
178
179 T.Transform(ip, transip);
180
181 if (Function)
182 {
183 return Function(transip);
184 }
185 else
186 {
187 return TDFunction(transip, GetTime());
188 }
189}
190
197
199 const IntegrationPoint & ip)
200{
201 T.Transform(ip, transip);
202 return sqrt(transip[0] * transip[0] + transip[1] * transip[1]);
203}
204
206 const IntegrationPoint & ip)
207{
208 T.Transform(ip, transip);
209 return atan2(transip[1], transip[0]);
210}
211
213 const IntegrationPoint & ip)
214{
215 T.Transform(ip, transip);
216 return sqrt(transip * transip);
217}
218
220 const IntegrationPoint & ip)
221{
222 T.Transform(ip, transip);
223 return atan2(transip[1], transip[0]);
224}
225
227 const IntegrationPoint & ip)
228{
229 T.Transform(ip, transip);
230 return atan2(sqrt(transip[0] * transip[0] + transip[1] * transip[1]),
231 transip[2]);
232}
233
235 const IntegrationPoint &ip)
236{
237 Mesh *gf_mesh = GridF->FESpace()->GetMesh();
238 if (T.mesh->GetNE() == gf_mesh->GetNE())
239 {
240 return GridF->GetValue(T, ip, Component);
241 }
242 else
243 {
244 IntegrationPoint coarse_ip;
245 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
246 return GridF->GetValue(*coarse_T, coarse_ip, Component);
247 }
248}
249
254
256{
257 if (Q1) { Q1->SetTime(t); }
258 if (Q2) { Q2->SetTime(t); }
259 this->Coefficient::SetTime(t);
260}
261
263 const IntegrationPoint &ip)
264{
265 if (Q2)
266 {
267 return Transform2(Q1->Eval(T, ip, GetTime()),
268 Q2->Eval(T, ip, GetTime()));
269 }
270 else
271 {
272 return Transform1(Q1->Eval(T, ip, GetTime()));
273 }
274}
275
277{
278 if (weight) { weight->SetTime(t); }
279 this->Coefficient::SetTime(t);
280}
281
283{
284 MFEM_VERIFY(vcenter.Size() <= 3,
285 "SetDeltaCenter::Maximum number of dim supported is 3")
286 for (int i = 0; i < vcenter.Size(); i++) { center[i] = vcenter[i]; }
287 sdim = vcenter.Size();
288}
289
291{
292 vcenter.SetSize(sdim);
293 vcenter = center;
294}
295
297 const IntegrationPoint &ip)
298{
299 real_t w = Scale();
300 return weight ? weight->Eval(T, ip, GetTime())*w : w;
301}
302
304{
305 if (c) { c->SetTime(t); }
306 this->Coefficient::SetTime(t);
307}
308
310 const IntegrationRule &ir)
311{
312 Vector Mi;
313 M.SetSize(vdim, ir.GetNPoints());
314 for (int i = 0; i < ir.GetNPoints(); i++)
315 {
316 M.GetColumnReference(i, Mi);
317 const IntegrationPoint &ip = ir.IntPoint(i);
318 T.SetIntPoint(&ip);
319 Eval(Mi, T, ip);
320 }
321}
322
324{
325 MFEM_VERIFY(vdim == qf.GetVDim(), "Wrong sizes.");
326 QuadratureSpaceBase &qspace = *qf.GetSpace();
327 const int ne = qspace.GetNE();
328 DenseMatrix values;
329 Vector col;
330 for (int iel = 0; iel < ne; ++iel)
331 {
332 qf.GetValues(iel, values);
333 const IntegrationRule &ir = qspace.GetIntRule(iel);
335 for (int iq = 0; iq < ir.Size(); ++iq)
336 {
337 const IntegrationPoint &ip = ir[iq];
338 T.SetIntPoint(&ip);
339 const int iq_p = qspace.GetPermutedIndex(iel, iq);
340 values.GetColumnReference(iq_p, col);
341 Eval(col, T, ip);
342 }
343 }
344}
345
346void PWVectorCoefficient::InitMap(const Array<int> & attr,
347 const Array<VectorCoefficient*> & coefs)
348{
349 MFEM_VERIFY(attr.Size() == coefs.Size(),
350 "PWVectorCoefficient: "
351 "Attribute and coefficient arrays have incompatible "
352 "dimensions.");
353
354 for (int i=0; i<attr.Size(); i++)
355 {
356 if (coefs[i] != NULL)
357 {
358 UpdateCoefficient(attr[i], *coefs[i]);
359 }
360 }
361}
362
364{
365 MFEM_VERIFY(coef.GetVDim() == vdim,
366 "PWVectorCoefficient::UpdateCoefficient: "
367 "VectorCoefficient has incompatible dimension.");
368 pieces[attr] = &coef;
369}
370
372{
374
375 std::map<int, VectorCoefficient*>::iterator p = pieces.begin();
376 for (; p != pieces.end(); p++)
377 {
378 if (p->second != NULL)
379 {
380 p->second->SetTime(t);
381 }
382 }
383}
384
386 const IntegrationPoint &ip)
387{
388 const int att = T.Attribute;
389 std::map<int, VectorCoefficient*>::const_iterator p = pieces.find(att);
390 if (p != pieces.end())
391 {
392 if ( p->second != NULL)
393 {
394 p->second->Eval(V, T, ip);
395 return;
396 }
397 }
398
399 V.SetSize(vdim);
400 V = 0.0;
401}
402
404 const IntegrationPoint &ip)
405{
406 V.SetSize(vdim);
407 T.Transform(ip, V);
408}
409
411 const IntegrationPoint &ip)
412{
413 real_t x[3];
414 Vector transip(x, 3);
415
416 T.Transform(ip, transip);
417
418 V.SetSize(vdim);
419 if (Function)
420 {
421 Function(transip, V);
422 }
423 else
424 {
425 TDFunction(transip, GetTime(), V);
426 }
427 if (Q)
428 {
429 V *= Q->Eval(T, ip, GetTime());
430 }
431}
432
434 : VectorCoefficient(dim), Coeff(dim), ownCoeff(dim)
435{
436 for (int i = 0; i < dim; i++)
437 {
438 Coeff[i] = NULL;
439 ownCoeff[i] = true;
440 }
441}
442
444{
445 for (int i = 0; i < vdim; i++)
446 {
447 if (Coeff[i]) { Coeff[i]->SetTime(t); }
448 }
450}
451
453{
454 if (ownCoeff[i]) { delete Coeff[i]; }
455 Coeff[i] = c;
456 ownCoeff[i] = own;
457}
458
460{
461 for (int i = 0; i < vdim; i++)
462 {
463 if (ownCoeff[i]) { delete Coeff[i]; }
464 }
465}
466
468 const IntegrationPoint &ip)
469{
470 V.SetSize(vdim);
471 for (int i = 0; i < vdim; i++)
472 {
473 V(i) = this->Eval(i, T, ip);
474 }
475}
476
478 const GridFunction *gf)
479 : VectorCoefficient ((gf) ? gf -> VectorDim() : 0)
480{
481 GridFunc = gf;
482}
483
485{
486 GridFunc = gf; vdim = (gf) ? gf -> VectorDim() : 0;
487}
488
490 const IntegrationPoint &ip)
491{
492 Mesh *gf_mesh = GridFunc->FESpace()->GetMesh();
493 if (T.mesh->GetNE() == gf_mesh->GetNE())
494 {
495 GridFunc->GetVectorValue(T, ip, V);
496 }
497 else
498 {
499 IntegrationPoint coarse_ip;
500 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
501 GridFunc->GetVectorValue(*coarse_T, coarse_ip, V);
502 }
503}
504
507{
508 if (T.mesh == GridFunc->FESpace()->GetMesh())
509 {
510 GridFunc->GetVectorValues(T, ir, M);
511 }
512 else
513 {
514 VectorCoefficient::Eval(M, T, ir);
515 }
516}
517
522
524 const GridFunction *gf)
525 : VectorCoefficient((gf) ?
526 gf -> FESpace() -> GetMesh() -> SpaceDimension() : 0)
527{
528 GridFunc = gf;
529}
530
532{
533 GridFunc = gf; vdim = (gf) ?
534 gf -> FESpace() -> GetMesh() -> SpaceDimension() : 0;
535}
536
538 const IntegrationPoint &ip)
539{
540 Mesh *gf_mesh = GridFunc->FESpace()->GetMesh();
541 if (T.mesh->GetNE() == gf_mesh->GetNE())
542 {
543 GridFunc->GetGradient(T, V);
544 }
545 else
546 {
547 IntegrationPoint coarse_ip;
548 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
549 GridFunc->GetGradient(*coarse_T, V);
550 }
551}
552
555{
556 if (T.mesh == GridFunc->FESpace()->GetMesh())
557 {
558 GridFunc->GetGradients(T, ir, M);
559 }
560 else
561 {
562 VectorCoefficient::Eval(M, T, ir);
563 }
564}
565
567{
568 const FiniteElementSpace &fes = *GridFunc->FESpace();
569 const Mesh &mesh = *fes.GetMesh();
570 const int sdim = mesh.SpaceDimension();
571 const int gf_vdim = fes.GetVDim(); // assumed to be 1 in this class
572 qf.SetVDim(sdim*gf_vdim);
573 if (mesh.GetNE() == 0) { return; }
574 // All mesh element must be the same type:
575 MFEM_VERIFY(mesh.GetNumGeometries(mesh.Dimension()) == 1,
576 "All mesh elements must be the same type!");
577 const IntegrationRule &ir = qf.GetIntRule(0);
578 // All elements must use the same quadrature rule:
579 MFEM_VERIFY(qf.Size() == sdim*gf_vdim*ir.GetNPoints()*mesh.GetNE(),
580 "All mesh elements must use the same quadrature rule!");
581 // QuadratureFunction uses the layout qf_vdim x nq x ne, i.e.
582 // gf_vdim x sdim x nq x nq, so we need to request QVectorLayout::byVDIM:
584}
585
592
594{
595 GridFunc = gf; vdim = (gf) ? gf -> CurlDim() : 0;
596}
597
599 const IntegrationPoint &ip)
600{
601 Mesh *gf_mesh = GridFunc->FESpace()->GetMesh();
602 if (T.mesh->GetNE() == gf_mesh->GetNE())
603 {
604 GridFunc->GetCurl(T, V);
605 }
606 else
607 {
608 IntegrationPoint coarse_ip;
609 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
610 GridFunc->GetCurl(*coarse_T, V);
611 }
612}
619
621 const IntegrationPoint &ip)
622{
623 Mesh *gf_mesh = GridFunc->FESpace()->GetMesh();
624 if (T.mesh->GetNE() == gf_mesh->GetNE())
625 {
626 return GridFunc->GetDivergence(T);
627 }
628 else
629 {
630 IntegrationPoint coarse_ip;
631 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
632 return GridFunc->GetDivergence(*coarse_T);
633 }
634}
635
641
643{
644 dir = d_;
645 (*this).vdim = dir.Size();
646}
647
650{
651 V = dir;
652 d.SetTime(GetTime());
653 V *= d.EvalDelta(T, ip);
654}
655
657{
658 if (c) { c->SetTime(t); }
660}
661
663 const IntegrationPoint &ip)
664{
665 V.SetSize(vdim);
666 if (active_attr[T.Attribute-1])
667 {
668 c->SetTime(GetTime());
669 c->Eval(V, T, ip);
670 }
671 else
672 {
673 V = 0.0;
674 }
675}
676
679{
680 if (active_attr[T.Attribute-1])
681 {
682 c->SetTime(GetTime());
683 c->Eval(M, T, ir);
684 }
685 else
686 {
687 M.SetSize(vdim, ir.GetNPoints());
688 M = 0.0;
689 }
690}
691
693{
694 MFEM_VERIFY(qf.GetVDim() == height*width, "Wrong sizes.");
695 QuadratureSpaceBase &qspace = *qf.GetSpace();
696 const int ne = qspace.GetNE();
697 DenseMatrix values, matrix;
698 for (int iel = 0; iel < ne; ++iel)
699 {
700 qf.GetValues(iel, values);
701 const IntegrationRule &ir = qspace.GetIntRule(iel);
703 for (int iq = 0; iq < ir.Size(); ++iq)
704 {
705 const IntegrationPoint &ip = ir[iq];
706 T.SetIntPoint(&ip);
707 const int iq_p = qspace.GetPermutedIndex(iel, iq);
708 matrix.UseExternalData(&values(0, iq_p), height, width);
709 Eval(matrix, T, ip);
710 if (transpose) { matrix.Transpose(); }
711 }
712 }
713}
714
715void PWMatrixCoefficient::InitMap(const Array<int> & attr,
716 const Array<MatrixCoefficient*> & coefs)
717{
718 MFEM_VERIFY(attr.Size() == coefs.Size(),
719 "PWMatrixCoefficient: "
720 "Attribute and coefficient arrays have incompatible "
721 "dimensions.");
722
723 for (int i=0; i<attr.Size(); i++)
724 {
725 if (coefs[i] != NULL)
726 {
727 UpdateCoefficient(attr[i], *coefs[i]);
728 }
729 }
730}
731
733{
734 MFEM_VERIFY(coef.GetHeight() == height,
735 "PWMatrixCoefficient::UpdateCoefficient: "
736 "MatrixCoefficient has incompatible height.");
737 MFEM_VERIFY(coef.GetWidth() == width,
738 "PWMatrixCoefficient::UpdateCoefficient: "
739 "MatrixCoefficient has incompatible width.");
740 if (symmetric)
741 {
742 MFEM_VERIFY(coef.IsSymmetric(),
743 "PWMatrixCoefficient::UpdateCoefficient: "
744 "MatrixCoefficient has incompatible symmetry.");
745 }
746 pieces[attr] = &coef;
747}
748
750{
752
753 std::map<int, MatrixCoefficient*>::iterator p = pieces.begin();
754 for (; p != pieces.end(); p++)
755 {
756 if (p->second != NULL)
757 {
758 p->second->SetTime(t);
759 }
760 }
761}
762
764 const IntegrationPoint &ip)
765{
766 const int att = T.Attribute;
767 std::map<int, MatrixCoefficient*>::const_iterator p = pieces.find(att);
768 if (p != pieces.end())
769 {
770 if ( p->second != NULL)
771 {
772 p->second->Eval(K, T, ip);
773 return;
774 }
775 }
776
777 K.SetSize(height, width);
778 K = 0.0;
779}
780
782{
783 if (Q) { Q->SetTime(t); }
785}
786
788 const IntegrationPoint &ip)
789{
790 real_t x[3];
791 Vector transip(x, 3);
792
793 T.Transform(ip, transip);
794
795 K.SetSize(height, width);
796
797 if (symmetric) // Use SymmFunction (deprecated version)
798 {
799 MFEM_VERIFY(height == width && SymmFunction,
800 "MatrixFunctionCoefficient is not symmetric");
801
802 Vector Ksym((width * (width + 1)) / 2); // 1x1: 1, 2x2: 3, 3x3: 6
803
804 SymmFunction(transip, Ksym);
805
806 // Copy upper triangular values from Ksym to the full matrix K
807 int os = 0;
808 for (int i=0; i<height; ++i)
809 {
810 for (int j=i; j<width; ++j)
811 {
812 const real_t Kij = Ksym[j - i + os];
813 K(i,j) = Kij;
814 if (j != i) { K(j,i) = Kij; }
815 }
816
817 os += width - i;
818 }
819 }
820 else
821 {
822 if (Function)
823 {
824 Function(transip, K);
825 }
826 else if (TDFunction)
827 {
828 TDFunction(transip, GetTime(), K);
829 }
830 else
831 {
832 K = mat;
833 }
834 }
835
836 if (Q)
837 {
838 K *= Q->Eval(T, ip, GetTime());
839 }
840}
841
844 const IntegrationPoint &ip)
845{
846 MFEM_VERIFY(symmetric && height == width && SymmFunction,
847 "MatrixFunctionCoefficient is not symmetric");
848
849 real_t x[3];
850 Vector transip(x, 3);
851
852 T.Transform(ip, transip);
853
854 K.SetSize((width * (width + 1)) / 2); // 1x1: 1, 2x2: 3, 3x3: 6
855
856 if (SymmFunction)
857 {
858 SymmFunction(transip, K);
859 }
860
861 if (Q)
862 {
863 K *= Q->Eval(T, ip, GetTime());
864 }
865}
866
868{
869 const int vdim = qf.GetVDim();
870 MFEM_VERIFY(vdim == height*(height+1)/2, "Wrong sizes.");
871
872 QuadratureSpaceBase &qspace = *qf.GetSpace();
873 const int ne = qspace.GetNE();
874 qf.HostWrite();
875 DenseMatrix values;
877 for (int iel = 0; iel < ne; ++iel)
878 {
879 qf.GetValues(iel, values);
880 const IntegrationRule &ir = qspace.GetIntRule(iel);
882 for (int iq = 0; iq < ir.Size(); ++iq)
883 {
884 const IntegrationPoint &ip = ir[iq];
885 T.SetIntPoint(&ip);
886 matrix.UseExternalData(&values(0, iq), height);
887 Eval(matrix, T, ip);
888 }
889 }
890}
891
892
894 const IntegrationPoint &ip)
895{
896 Eval(mat_aux, T, ip);
897 for (int j = 0; j < width; ++j)
898 {
899 for (int i = 0; i < height; ++ i)
900 {
901 K(i, j) = mat_aux(i, j);
902 }
903 }
904}
905
911
914 const IntegrationPoint &ip)
915{
916 real_t x[3];
917 Vector transip(x, 3);
918
919 T.Transform(ip, transip);
920
921 K.SetSize(height);
922
923 if (Function)
924 {
925 Function(transip, K);
926 }
927 else if (TDFunction)
928 {
929 TDFunction(transip, GetTime(), K);
930 }
931 else
932 {
933 K = mat;
934 }
935
936 if (Q)
937 {
938 K *= Q->Eval(T, ip, GetTime());
939 }
940}
941
944{
945 Coeff.SetSize(height*width);
946 ownCoeff.SetSize(height*width);
947 for (int i = 0; i < (height*width); i++)
948 {
949 Coeff[i] = NULL;
950 ownCoeff[i] = true;
951 }
952}
953
955{
956 for (int i=0; i < height*width; i++)
957 {
958 if (Coeff[i]) { Coeff[i]->SetTime(t); }
959 }
961}
962
963void MatrixArrayCoefficient::Set(int i, int j, Coefficient * c, bool own)
964{
965 if (ownCoeff[i*width+j]) { delete Coeff[i*width+j]; }
966 Coeff[i*width+j] = c;
967 ownCoeff[i*width+j] = own;
968}
969
971{
972 for (int i=0; i < height*width; i++)
973 {
974 if (ownCoeff[i]) { delete Coeff[i]; }
975 }
976}
977
979 const IntegrationPoint &ip)
980{
981 K.SetSize(height, width);
982 for (int i = 0; i < height; i++)
983 {
984 for (int j = 0; j < width; j++)
985 {
986 K(i,j) = this->Eval(i, j, T, ip);
987 }
988 }
989}
990
993{
994 Coeff.SetSize(height);
995 ownCoeff.SetSize(height);
996 for (int i = 0; i < height; i++)
997 {
998 Coeff[i] = NULL;
999 ownCoeff[i] = true;
1000 }
1001}
1002
1004{
1005 for (int i=0; i < height; i++)
1006 {
1007 if (Coeff[i]) { Coeff[i]->SetTime(t); }
1008 }
1010}
1011
1013{
1014 MFEM_ASSERT(i < height && i >= 0, "Row "
1015 << i << " does not exist. " <<
1016 "Matrix height = " << height << ".");
1017 if (ownCoeff[i]) { delete Coeff[i]; }
1018 Coeff[i] = c;
1019 ownCoeff[i] = own;
1020}
1021
1023{
1024 for (int i=0; i < height; i++)
1025 {
1026 if (ownCoeff[i]) { delete Coeff[i]; }
1027 }
1028}
1029
1032 const IntegrationPoint &ip)
1033{
1034 MFEM_ASSERT(i < height && i >= 0, "Row "
1035 << i << " does not exist. " <<
1036 "Matrix height = " << height << ".");
1037 if (Coeff[i])
1038 {
1039 Coeff[i] -> Eval(V, T, ip);
1040 }
1041 else
1042 {
1043 V = 0.0;
1044 }
1045}
1046
1049 const IntegrationPoint &ip)
1050{
1051 K.SetSize(height, width);
1052 Vector V(width);
1053 for (int i = 0; i < height; i++)
1054 {
1055 this->Eval(i, V, T, ip);
1056 K.SetRow(i, V);
1057 }
1058}
1059
1061{
1062 if (c) { c->SetTime(t); }
1064}
1065
1067 const IntegrationPoint &ip)
1068{
1069 if (active_attr[T.Attribute-1])
1070 {
1071 c->SetTime(GetTime());
1072 c->Eval(K, T, ip);
1073 }
1074 else
1075 {
1076 K.SetSize(height, width);
1077 K = 0.0;
1078 }
1079}
1080
1082{
1083 if (a) { a->SetTime(t); }
1084 if (b) { b->SetTime(t); }
1085 this->Coefficient::SetTime(t);
1086}
1087
1089{
1090 if (a == nullptr)
1091 {
1092 // qf = alpha*aConst + beta * b
1093 const real_t d_alpha_a = aConst*alpha;
1094 const real_t d_beta = beta;
1095 b->Project(qf);
1096 auto d_qf = qf.ReadWrite();
1097 mfem::forall(qf.Size(), [=] MFEM_HOST_DEVICE (int i)
1098 {
1099 d_qf[i] = d_alpha_a + d_beta*d_qf[i];
1100 });
1101 }
1102 else
1103 {
1104 a->Project(qf);
1105 QuadratureFunction qf_b(*qf.GetSpace());
1106 b->Project(qf_b);
1107 add(alpha, qf, beta, qf_b, qf);
1108 }
1109}
1110
1112{
1113 if (a) { a->SetTime(t); }
1114 if (b) { b->SetTime(t); }
1115 this->Coefficient::SetTime(t);
1116}
1117
1119{
1120 if (a == nullptr)
1121 {
1122 // qf = aConst * b
1123 b->Project(qf);
1124 qf *= aConst;
1125 }
1126 else
1127 {
1128 a->Project(qf);
1129 QuadratureFunction qf_b(qf.GetSpace());
1130 b->Project(qf_b);
1131 qf *= qf_b;
1132 }
1133}
1134
1136{
1137 if (a) { a->SetTime(t); }
1138 if (b) { b->SetTime(t); }
1139 this->Coefficient::SetTime(t);
1140}
1141
1143{
1144 if (b == nullptr)
1145 {
1146 if (a == nullptr)
1147 {
1148 qf = aConst / bConst;
1149 }
1150 else
1151 {
1152 a->Project(qf);
1153 qf *= 1.0/bConst;
1154 }
1155 }
1156 else
1157 {
1158 if (a == nullptr)
1159 {
1160 b->Project(qf);
1161 qf.Reciprocal();
1162 qf *= aConst;
1163 }
1164 else
1165 {
1166 a->Project(qf);
1167 QuadratureFunction qf_b(qf.GetSpace());
1168 b->Project(qf_b);
1169 qf /= qf_b;
1170 }
1171 }
1172}
1173
1175{
1176 if (a) { a->SetTime(t); }
1177 this->Coefficient::SetTime(t);
1178}
1179
1182 : a(&A), b(&B), va(A.GetVDim()), vb(B.GetVDim())
1183{
1184 MFEM_ASSERT(A.GetVDim() == B.GetVDim(),
1185 "InnerProductCoefficient: "
1186 "Arguments have incompatible dimensions.");
1187}
1188
1190{
1191 if (a) { a->SetTime(t); }
1192 if (b) { b->SetTime(t); }
1193 this->Coefficient::SetTime(t);
1194}
1195
1197 const IntegrationPoint &ip)
1198{
1199 a->Eval(va, T, ip);
1200 b->Eval(vb, T, ip);
1201 return va * vb;
1202}
1203
1205{
1206 MFEM_VERIFY(a->GetVDim() == b->GetVDim(),
1207 "Incompatible vector coefficients: a->GetVDim(): "
1208 << a->GetVDim() << ", b->GetVDim(): " << b->GetVDim());
1209
1210 const int vdim = a->GetVDim();
1211 MFEM_VERIFY(vdim >= 1, "invalid vdim: " << vdim);
1212
1213 // When running on device, make sure the output data is allocated before any
1214 // local temporary data to reduce potential heap fragmentation:
1215 auto dot_d = qf.Write();
1216
1217 QuadratureFunction qf_a(qf.GetSpace(), vdim);
1218 QuadratureFunction qf_b(qf.GetSpace(), vdim);
1219
1220 a->Project(qf_a);
1221 b->Project(qf_b);
1222
1223 auto a_d = qf_a.Read();
1224 auto b_d = qf_b.Read();
1225
1226 mfem::forall(qf.GetSpace()->GetSize(), [=] MFEM_HOST_DEVICE (int i)
1227 {
1228 const real_t *ai = a_d + i*vdim;
1229 const real_t *bi = b_d + i*vdim;
1230 real_t dot = ai[0]*bi[0];
1231 for (int d = 1; d < vdim; d++)
1232 {
1233 dot += ai[d]*bi[d];
1234 }
1235 dot_d[i] = dot;
1236 });
1237}
1238
1241 : a(&A), b(&B), va(A.GetVDim()), vb(B.GetVDim())
1242{
1243 MFEM_ASSERT(A.GetVDim() == 2 && B.GetVDim() == 2,
1244 "VectorRotProductCoefficient: "
1245 "Arguments must have dimension equal to two.");
1246}
1247
1249{
1250 if (a) { a->SetTime(t); }
1251 if (b) { b->SetTime(t); }
1252 this->Coefficient::SetTime(t);
1253}
1254
1256 const IntegrationPoint &ip)
1257{
1258 a->Eval(va, T, ip);
1259 b->Eval(vb, T, ip);
1260 return va[0] * vb[1] - va[1] * vb[0];
1261}
1262
1264 : a(&A), ma(A.GetHeight(), A.GetWidth())
1265{
1266 MFEM_ASSERT(A.GetHeight() == A.GetWidth(),
1267 "DeterminantCoefficient: "
1268 "Argument must be a square matrix.");
1269}
1270
1272{
1273 if (a) { a->SetTime(t); }
1274 this->Coefficient::SetTime(t);
1275}
1276
1278 const IntegrationPoint &ip)
1279{
1280 a->Eval(ma, T, ip);
1281 return ma.Det();
1282}
1283
1285 : a(&A), ma(A.GetHeight(), A.GetWidth())
1286{
1287 MFEM_ASSERT(A.GetHeight() == A.GetWidth(),
1288 "TraceCoefficient: "
1289 "Argument must be a square matrix.");
1290}
1291
1293{
1294 if (a) { a->SetTime(t); }
1295 this->Coefficient::SetTime(t);
1296}
1297
1299 const IntegrationPoint &ip)
1300{
1301 a->Eval(ma, T, ip);
1302 return ma.Trace();
1303}
1304
1307 ACoef(NULL), BCoef(NULL),
1308 A(dim), B(dim),
1309 alphaCoef(NULL), betaCoef(NULL),
1310 alpha(1.0), beta(1.0)
1311{
1312 A = 0.0; B = 0.0;
1313}
1314
1317 real_t alpha_, real_t beta_)
1318 : VectorCoefficient(A_.GetVDim()),
1319 ACoef(&A_), BCoef(&B_),
1320 A(A_.GetVDim()), B(A_.GetVDim()),
1321 alphaCoef(NULL), betaCoef(NULL),
1322 alpha(alpha_), beta(beta_)
1323{
1324 MFEM_ASSERT(A_.GetVDim() == B_.GetVDim(),
1325 "VectorSumCoefficient: "
1326 "Arguments must have the same dimension.");
1327}
1328
1331 Coefficient &alpha_,
1333 : VectorCoefficient(A_.GetVDim()),
1334 ACoef(&A_), BCoef(&B_),
1335 A(A_.GetVDim()),
1336 B(A_.GetVDim()),
1337 alphaCoef(&alpha_),
1338 betaCoef(&beta_),
1339 alpha(0.0), beta(0.0)
1340{
1341 MFEM_ASSERT(A_.GetVDim() == B_.GetVDim(),
1342 "VectorSumCoefficient: "
1343 "Arguments must have the same dimension.");
1344}
1345
1347{
1348 if (ACoef) { ACoef->SetTime(t); }
1349 if (BCoef) { BCoef->SetTime(t); }
1350 if (alphaCoef) { alphaCoef->SetTime(t); }
1351 if (betaCoef) { betaCoef->SetTime(t); }
1353}
1354
1356 const IntegrationPoint &ip)
1357{
1358 V.SetSize(A.Size());
1359 if ( ACoef) { ACoef->Eval(A, T, ip); }
1360 if ( BCoef) { BCoef->Eval(B, T, ip); }
1361 if (alphaCoef) { alpha = alphaCoef->Eval(T, ip); }
1362 if ( betaCoef) { beta = betaCoef->Eval(T, ip); }
1363 add(alpha, A, beta, B, V);
1364}
1365
1367 real_t A,
1369 : VectorCoefficient(B.GetVDim()), aConst(A), a(NULL), b(&B)
1370{}
1371
1377
1379{
1380 if (a) { a->SetTime(t); }
1381 if (b) { b->SetTime(t); }
1383}
1384
1386 const IntegrationPoint &ip)
1387{
1388 real_t sa = (a == NULL) ? aConst : a->Eval(T, ip);
1389 b->Eval(V, T, ip);
1390 V *= sa;
1391}
1392
1397
1399{
1400 if (a) { a->SetTime(t); }
1402}
1403
1405 const IntegrationPoint &ip)
1406{
1407 a->Eval(V, T, ip);
1408 real_t nv = V.Norml2();
1409 V *= (nv > tol) ? (1.0/nv) : 0.0;
1410}
1411
1415 : VectorCoefficient(3), a(&A), b(&B), va(A.GetVDim()), vb(B.GetVDim())
1416{
1417 MFEM_ASSERT(A.GetVDim() == 3 && B.GetVDim() == 3,
1418 "VectorCrossProductCoefficient: "
1419 "Arguments must have dimension equal to three.");
1420}
1421
1423{
1424 if (a) { a->SetTime(t); }
1425 if (b) { b->SetTime(t); }
1427}
1428
1430 const IntegrationPoint &ip)
1431{
1432 a->Eval(va, T, ip);
1433 b->Eval(vb, T, ip);
1434 V.SetSize(3);
1435 V[0] = va[1] * vb[2] - va[2] * vb[1];
1436 V[1] = va[2] * vb[0] - va[0] * vb[2];
1437 V[2] = va[0] * vb[1] - va[1] * vb[0];
1438}
1439
1442 : VectorCoefficient(A.GetHeight()), a(&A), b(&B),
1443 ma(A.GetHeight(), A.GetWidth()), vb(B.GetVDim())
1444{
1445 MFEM_ASSERT(A.GetWidth() == B.GetVDim(),
1446 "MatrixVectorProductCoefficient: "
1447 "Arguments have incompatible dimensions.");
1448}
1449
1451{
1452 if (a) { a->SetTime(t); }
1453 if (b) { b->SetTime(t); }
1455}
1456
1458 const IntegrationPoint &ip)
1459{
1460 a->Eval(ma, T, ip);
1461 b->Eval(vb, T, ip);
1462 V.SetSize(vdim);
1463 ma.Mult(vb, V);
1464}
1465
1467 const IntegrationPoint &ip)
1468{
1469 M.SetSize(dim);
1470 M = 0.0;
1471 for (int d=0; d<dim; d++) { M(d,d) = 1.0; }
1472}
1473
1476 real_t alpha_, real_t beta_)
1477 : MatrixCoefficient(A.GetHeight(), A.GetWidth()),
1478 a(&A), b(&B), alpha(alpha_), beta(beta_),
1479 ma(A.GetHeight(), A.GetWidth())
1480{
1481 MFEM_ASSERT(A.GetHeight() == B.GetHeight() && A.GetWidth() == B.GetWidth(),
1482 "MatrixSumCoefficient: "
1483 "Arguments must have the same dimensions.");
1484}
1485
1487{
1488 if (a) { a->SetTime(t); }
1489 if (b) { b->SetTime(t); }
1491}
1492
1494 const IntegrationPoint &ip)
1495{
1496 b->Eval(M, T, ip);
1497 if ( beta != 1.0 ) { M *= beta; }
1498 a->Eval(ma, T, ip);
1499 M.Add(alpha, ma);
1500}
1501
1504 : MatrixCoefficient(A.GetHeight(), B.GetWidth()),
1505 a(&A), b(&B),
1506 ma(A.GetHeight(), A.GetWidth()),
1507 mb(B.GetHeight(), B.GetWidth())
1508{
1509 MFEM_ASSERT(A.GetWidth() == B.GetHeight(),
1510 "MatrixProductCoefficient: "
1511 "Arguments must have compatible dimensions.");
1512}
1513
1515 const IntegrationPoint &ip)
1516{
1517 a->Eval(ma, T, ip);
1518 b->Eval(mb, T, ip);
1519 Mult(ma, mb, M);
1520}
1521
1523 real_t A,
1525 : MatrixCoefficient(B.GetHeight(), B.GetWidth()), aConst(A), a(NULL), b(&B)
1526{}
1527
1529 Coefficient &A,
1531 : MatrixCoefficient(B.GetHeight(), B.GetWidth()), aConst(0.0), a(&A), b(&B)
1532{}
1533
1535{
1536 if (a) { a->SetTime(t); }
1537 if (b) { b->SetTime(t); }
1539}
1540
1543 const IntegrationPoint &ip)
1544{
1545 real_t sa = (a == NULL) ? aConst : a->Eval(T, ip);
1546 b->Eval(M, T, ip);
1547 M *= sa;
1548}
1549
1553
1555{
1556 if (a) { a->SetTime(t); }
1558}
1559
1562 const IntegrationPoint &ip)
1563{
1564 a->Eval(M, T, ip);
1565 M.Transpose();
1566}
1567
1569 : MatrixCoefficient(A.GetHeight(), A.GetWidth()), a(&A)
1570{
1571 MFEM_ASSERT(A.GetHeight() == A.GetWidth(),
1572 "InverseMatrixCoefficient: "
1573 "Argument must be a square matrix.");
1574}
1575
1577{
1578 if (a) { a->SetTime(t); }
1580}
1581
1584 const IntegrationPoint &ip)
1585{
1586 a->Eval(M, T, ip);
1587 M.Invert();
1588}
1589
1591 : MatrixCoefficient(A.GetHeight(), A.GetWidth()), a(&A)
1592{
1593 MFEM_ASSERT(A.GetHeight() == A.GetWidth() && A.GetHeight() == 2,
1594 "ExponentialMatrixCoefficient: "
1595 << "Argument must be a square 2x2 matrix."
1596 << " Height = " << A.GetHeight()
1597 << ", Width = " << A.GetWidth());
1598}
1599
1601{
1602 if (a) { a->SetTime(t); }
1604}
1605
1608 const IntegrationPoint &ip)
1609{
1610 a->Eval(M, T, ip);
1611 M.Exponential();
1612}
1613
1616 : MatrixCoefficient(A.GetVDim(), B.GetVDim()), a(&A), b(&B),
1617 va(A.GetVDim()), vb(B.GetVDim())
1618{}
1619
1621{
1622 if (a) { a->SetTime(t); }
1623 if (b) { b->SetTime(t); }
1625}
1626
1628 const IntegrationPoint &ip)
1629{
1630 a->Eval(va, T, ip);
1631 b->Eval(vb, T, ip);
1632 M.SetSize(va.Size(), vb.Size());
1633 for (int i=0; i<va.Size(); i++)
1634 {
1635 for (int j=0; j<vb.Size(); j++)
1636 {
1637 M(i, j) = va[i] * vb[j];
1638 }
1639 }
1640}
1641
1643 : MatrixCoefficient(K.GetVDim(), K.GetVDim()), aConst(A), a(NULL), k(&K),
1644 vk(K.GetVDim())
1645{}
1646
1649 : MatrixCoefficient(K.GetVDim(), K.GetVDim()), aConst(0.0), a(&A), k(&K),
1650 vk(K.GetVDim())
1651{}
1652
1654{
1655 if (a) { a->SetTime(t); }
1656 if (k) { k->SetTime(t); }
1658}
1659
1661 const IntegrationPoint &ip)
1662{
1663 k->Eval(vk, T, ip);
1664 M.SetSize(vk.Size(), vk.Size());
1665 M = 0.0;
1666 real_t k2 = vk*vk;
1667 for (int i=0; i<vk.Size(); i++)
1668 {
1669 M(i, i) = k2;
1670 for (int j=0; j<vk.Size(); j++)
1671 {
1672 M(i, j) -= vk[i] * vk[j];
1673 }
1674 }
1675 M *= ((a == NULL ) ? aConst : a->Eval(T, ip) );
1676}
1677
1679 const IntegrationRule *irs[])
1680{
1681 real_t norm = 0.0;
1683
1684 for (int i = 0; i < mesh.GetNE(); i++)
1685 {
1686 tr = mesh.GetElementTransformation(i);
1687 const IntegrationRule &ir = *irs[mesh.GetElementType(i)];
1688 for (int j = 0; j < ir.GetNPoints(); j++)
1689 {
1690 const IntegrationPoint &ip = ir.IntPoint(j);
1691 tr->SetIntPoint(&ip);
1692 real_t val = fabs(coeff.Eval(*tr, ip));
1693 if (p < infinity())
1694 {
1695 norm += ip.weight * tr->Weight() * pow(val, p);
1696 }
1697 else
1698 {
1699 if (norm < val)
1700 {
1701 norm = val;
1702 }
1703 }
1704 }
1705 }
1706 return norm;
1707}
1708
1710 const IntegrationRule *irs[])
1711{
1712 real_t norm = 0.0;
1714 int vdim = coeff.GetVDim();
1715 Vector vval(vdim);
1716 real_t val;
1717
1718 for (int i = 0; i < mesh.GetNE(); i++)
1719 {
1720 tr = mesh.GetElementTransformation(i);
1721 const IntegrationRule &ir = *irs[mesh.GetElementType(i)];
1722 for (int j = 0; j < ir.GetNPoints(); j++)
1723 {
1724 const IntegrationPoint &ip = ir.IntPoint(j);
1725 tr->SetIntPoint(&ip);
1726 coeff.Eval(vval, *tr, ip);
1727 if (p < infinity())
1728 {
1729 for (int idim(0); idim < vdim; ++idim)
1730 {
1731 norm += ip.weight * tr->Weight() * pow(fabs( vval(idim) ), p);
1732 }
1733 }
1734 else
1735 {
1736 for (int idim(0); idim < vdim; ++idim)
1737 {
1738 val = fabs(vval(idim));
1739 if (norm < val)
1740 {
1741 norm = val;
1742 }
1743 }
1744 }
1745 }
1746 }
1747
1748 return norm;
1749}
1750
1752 const IntegrationRule *irs[])
1753{
1754 real_t norm = LpNormLoop(p, coeff, mesh, irs);
1755
1756 if (p < infinity())
1757 {
1758 // negative quadrature weights may cause norm to be negative
1759 if (norm < 0.0)
1760 {
1761 norm = -pow(-norm, 1.0/p);
1762 }
1763 else
1764 {
1765 norm = pow(norm, 1.0/p);
1766 }
1767 }
1768
1769 return norm;
1770}
1771
1773 const IntegrationRule *irs[])
1774{
1775 real_t norm = LpNormLoop(p, coeff, mesh, irs);
1776
1777 if (p < infinity())
1778 {
1779 // negative quadrature weights may cause norm to be negative
1780 if (norm < 0.0)
1781 {
1782 norm = -pow(-norm, 1.0/p);
1783 }
1784 else
1785 {
1786 norm = pow(norm, 1.0/p);
1787 }
1788 }
1789
1790 return norm;
1791}
1792
1793#ifdef MFEM_USE_MPI
1795 const IntegrationRule *irs[])
1796{
1797 real_t loc_norm = LpNormLoop(p, coeff, pmesh, irs);
1798 real_t glob_norm = 0;
1799
1800 MPI_Comm comm = pmesh.GetComm();
1801
1802 if (p < infinity())
1803 {
1804 MPI_Allreduce(&loc_norm, &glob_norm, 1, MPITypeMap<real_t>::mpi_type, MPI_SUM,
1805 comm);
1806
1807 // negative quadrature weights may cause norm to be negative
1808 if (glob_norm < 0.0)
1809 {
1810 glob_norm = -pow(-glob_norm, 1.0/p);
1811 }
1812 else
1813 {
1814 glob_norm = pow(glob_norm, 1.0/p);
1815 }
1816 }
1817 else
1818 {
1819 MPI_Allreduce(&loc_norm, &glob_norm, 1, MPITypeMap<real_t>::mpi_type, MPI_MAX,
1820 comm);
1821 }
1822
1823 return glob_norm;
1824}
1825
1827 const IntegrationRule *irs[])
1828{
1829 real_t loc_norm = LpNormLoop(p, coeff, pmesh, irs);
1830 real_t glob_norm = 0;
1831
1832 MPI_Comm comm = pmesh.GetComm();
1833
1834 if (p < infinity())
1835 {
1836 MPI_Allreduce(&loc_norm, &glob_norm, 1, MPITypeMap<real_t>::mpi_type, MPI_SUM,
1837 comm);
1838
1839 // negative quadrature weights may cause norm to be negative
1840 if (glob_norm < 0.0)
1841 {
1842 glob_norm = -pow(-glob_norm, 1.0/p);
1843 }
1844 else
1845 {
1846 glob_norm = pow(glob_norm, 1.0/p);
1847 }
1848 }
1849 else
1850 {
1851 MPI_Allreduce(&loc_norm, &glob_norm, 1, MPITypeMap<real_t>::mpi_type, MPI_MAX,
1852 comm);
1853 }
1854
1855 return glob_norm;
1856}
1857#endif
1858
1862
1864{
1865 MFEM_VERIFY(index_ >= 0, "Index must be >= 0");
1866 MFEM_VERIFY(index_ < QuadF.GetVDim(),
1867 "Index must be < QuadratureFunction length");
1868 index = index_;
1869
1870 MFEM_VERIFY(length_ > 0, "Length must be > 0");
1871 MFEM_VERIFY(length_ <= QuadF.GetVDim() - index,
1872 "Length must be <= (QuadratureFunction length - index)");
1873
1874 vdim = length_;
1875}
1876
1879 const IntegrationPoint &ip)
1880{
1881 QuadF.HostRead();
1882
1883 const int el_idx = QuadF.GetSpace()->GetEntityIndex(T);
1884 // Handle the case of "interior boundary elements" and FaceQuadratureSpace
1885 // with FaceType::Boundary.
1886 if (el_idx < 0) { V = 0.0; return; }
1887
1888 const int ip_idx = QuadF.GetSpace()->GetPermutedIndex(el_idx, ip.index);
1889
1890 if (index == 0 && vdim == QuadF.GetVDim())
1891 {
1892 QuadF.GetValues(el_idx, ip_idx, V);
1893 }
1894 else
1895 {
1896 Vector temp;
1897 QuadF.GetValues(el_idx, ip_idx, temp);
1898 V.SetSize(vdim);
1899 for (int i = 0; i < vdim; i++)
1900 {
1901 V(i) = temp(index + i);
1902 }
1903 }
1904
1905 return;
1906}
1907
1912
1914 const QuadratureFunction &qf) : QuadF(qf)
1915{
1916 MFEM_VERIFY(qf.GetVDim() == 1, "QuadratureFunction's vdim must be 1");
1917}
1918
1920 const IntegrationPoint &ip)
1921{
1922 QuadF.HostRead();
1923 Vector temp(1);
1924 const int el_idx = QuadF.GetSpace()->GetEntityIndex(T);
1925 // Handle the case of "interior boundary elements" and FaceQuadratureSpace
1926 // with FaceType::Boundary.
1927 if (el_idx < 0) { return 0.0; }
1928 const int ip_idx = QuadF.GetSpace()->GetPermutedIndex(el_idx, ip.index);
1929 QuadF.GetValues(el_idx, ip_idx, temp);
1930 return temp[0];
1931}
1932
1934{
1935 qf = QuadF;
1936}
1937
1938
1941 : Vector(), storage(storage_), vdim(0), qs(qs_), qf(NULL)
1942{
1943 UseDevice(true);
1944}
1945
1948 CoefficientStorage storage_)
1949 : CoefficientVector(qs_, storage_)
1950{
1951 if (coeff == NULL)
1952 {
1953 SetConstant(1.0);
1954 }
1955 else
1956 {
1957 Project(*coeff);
1958 }
1959}
1960
1963 CoefficientStorage storage_)
1964 : CoefficientVector(qs_, storage_)
1965{
1966 Project(coeff);
1967}
1968
1971 CoefficientStorage storage_)
1972 : CoefficientVector(qs_, storage_)
1973{
1974 Project(coeff);
1975}
1976
1979 CoefficientStorage storage_)
1980 : CoefficientVector(qs_, storage_)
1981{
1982 Project(coeff);
1983}
1984
1986{
1987 vdim = 1;
1988 if (auto *const_coeff = dynamic_cast<ConstantCoefficient*>(&coeff))
1989 {
1990 SetConstant(const_coeff->constant);
1991 }
1992 else if (auto *qf_coeff = dynamic_cast<QuadratureFunctionCoefficient*>(&coeff))
1993 {
1994 MakeRef(qf_coeff->GetQuadFunction());
1995 }
1996 else
1997 {
1998 if (qf == nullptr) { qf = new QuadratureFunction(qs); }
1999 qf->SetVDim(1);
2000 coeff.Project(*qf);
2001 Vector::MakeRef(*qf, 0, qf->Size());
2002 }
2003}
2004
2006{
2007 vdim = coeff.GetVDim();
2008 if (auto *const_coeff = dynamic_cast<VectorConstantCoefficient*>(&coeff))
2009 {
2010 SetConstant(const_coeff->GetVec());
2011 }
2012 else if (auto *qf_coeff =
2013 dynamic_cast<VectorQuadratureFunctionCoefficient*>(&coeff))
2014 {
2015 MakeRef(qf_coeff->GetQuadFunction());
2016 }
2017 else
2018 {
2019 if (qf == nullptr) { qf = new QuadratureFunction(qs, vdim); }
2020 qf->SetVDim(vdim);
2021 coeff.Project(*qf);
2022 Vector::MakeRef(*qf, 0, qf->Size());
2023 }
2024}
2025
2027{
2028 if (auto *const_coeff = dynamic_cast<MatrixConstantCoefficient*>(&coeff))
2029 {
2030 SetConstant(const_coeff->GetMatrix(), transpose);
2031 }
2032 else if (auto *const_sym_coeff =
2033 dynamic_cast<SymmetricMatrixConstantCoefficient*>(&coeff))
2034 {
2035 SetConstant(const_sym_coeff->GetMatrix());
2036 }
2037 else
2038 {
2039 auto *sym_coeff = dynamic_cast<SymmetricMatrixCoefficient*>(&coeff);
2040 const bool sym = sym_coeff && (storage & CoefficientStorage::SYMMETRIC);
2041 const int height = coeff.GetHeight();
2042 const int width = coeff.GetWidth();
2043 vdim = sym ? height*(height + 1)/2 : width*height;
2044
2045 if (qf == nullptr) { qf = new QuadratureFunction(qs, vdim); }
2046 qf->SetVDim(vdim);
2047 if (sym) { sym_coeff->ProjectSymmetric(*qf); }
2048 else { coeff.Project(*qf, transpose); }
2049 Vector::MakeRef(*qf, 0, qf->Size());
2050 }
2051}
2052
2054{
2055 Project(coeff, true);
2056}
2057
2059{
2060 vdim = qf_.GetVDim();
2061 const QuadratureSpaceBase *qs2 = qf_.GetSpace();
2062 MFEM_CONTRACT_VAR(qs2); // qs2 used only for asserts
2063 MFEM_VERIFY(qs2 != NULL, "Invalid QuadratureSpace.")
2064 MFEM_VERIFY(qs2->GetMesh() == qs.GetMesh(), "Meshes differ.");
2065 MFEM_VERIFY(qs2->GetOrder() == qs.GetOrder(), "Orders differ.");
2066 Vector::MakeRef(const_cast<QuadratureFunction&>(qf_), 0, qf_.Size());
2067}
2068
2070{
2071 const int nq = (storage & CoefficientStorage::CONSTANTS) ? 1 : qs.GetSize();
2072 vdim = 1;
2073 SetSize(nq);
2074 Vector::operator=(constant);
2075}
2076
2078{
2079 const int nq = (storage & CoefficientStorage::CONSTANTS) ? 1 : qs.GetSize();
2080 vdim = constant.Size();
2081 SetSize(nq*vdim);
2082 for (int iq = 0; iq < nq; ++iq)
2083 {
2084 for (int vd = 0; vd<vdim; ++vd)
2085 {
2086 (*this)[vd + iq*vdim] = constant[vd];
2087 }
2088 }
2089}
2090
2091void CoefficientVector::SetConstant(const DenseMatrix &constant, bool transpose)
2092{
2093 const int nq = (storage & CoefficientStorage::CONSTANTS) ? 1 : qs.GetSize();
2094 const int width = constant.Width();
2095 const int height = constant.Height();
2096 vdim = width*height;
2097 SetSize(nq*vdim);
2098 for (int iq = 0; iq < nq; ++iq)
2099 {
2100 for (int j = 0; j < width; ++j)
2101 {
2102 for (int i = 0; i < height; ++i)
2103 {
2104 const real_t val = transpose ? constant(j,i) : constant(i,j);
2105 (*this)[i + j*height + iq*vdim] = val;
2106 }
2107 }
2108 }
2109}
2110
2112{
2113 const int nq = (storage & CoefficientStorage::CONSTANTS) ? 1 : qs.GetSize();
2114 const int height = constant.Height();
2115 const bool sym = storage & CoefficientStorage::SYMMETRIC;
2116 vdim = sym ? height*(height + 1)/2 : height*height;
2117 SetSize(nq*vdim);
2118 for (int iq = 0; iq < nq; ++iq)
2119 {
2120 for (int vd = 0; vd < vdim; ++vd)
2121 {
2122 const real_t value = sym ? constant.GetData()[vd] : constant(vd % height,
2123 vd / height);
2124 (*this)[vd + iq*vdim] = value;
2125 }
2126 }
2127}
2128
2129int CoefficientVector::GetVDim() const { return vdim; }
2130
2135
2136}
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition array.hpp:840
int Size() const
Return the logical size of the array.
Definition array.hpp:166
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
Class to represent a coefficient evaluated at quadrature points.
void SetConstant(real_t constant)
Set this vector to the given constant.
int vdim
Number of values per quadrature point.
void Project(Coefficient &coeff)
Evaluate the given Coefficient at the quadrature points defined by qs.
int GetVDim() const
Return the number of values per quadrature point.
CoefficientVector(QuadratureSpaceBase &qs_, CoefficientStorage storage_=CoefficientStorage::FULL)
Create an empty CoefficientVector.
QuadratureFunction * qf
Internal QuadratureFunction (owned, may be NULL).
CoefficientStorage storage
Storage optimizations (see CoefficientStorage).
QuadratureSpaceBase & qs
Associated QuadratureSpaceBase.
void ProjectTranspose(MatrixCoefficient &coeff)
Project the transpose of coeff.
void MakeRef(const QuadratureFunction &qf_)
Make this vector a reference to the given QuadratureFunction.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
real_t GetTime()
Get the time for time dependent coefficients.
virtual void SetTime(real_t t)
Set the time for time dependent coefficients.
virtual void Project(QuadratureFunction &qf)
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
virtual real_t Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
A coefficient that is constant across space and time.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf with the constant value.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
CrossCrossCoefficient(real_t A, VectorCoefficient &K)
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void SetGridFunction(const GridFunction *gf)
Set the vector grid function.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector curl coefficient at ip.
CurlGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a vector grid function gf. The grid function is not owned by the coeff...
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void GetDeltaCenter(Vector &center)
Write the center of the delta function into center.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
real_t Scale()
Return the scale factor times the optional time dependent function. Returns with when not set by th...
void SetDeltaCenter(const Vector &center)
Set the center location of the delta function.
virtual real_t EvalDelta(ElementTransformation &T, const IntegrationPoint &ip)
The value of the function assuming we are evaluating at the delta center.
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
void Mult(const real_t *x, real_t *y) const
Matrix vector multiplication.
Definition densemat.cpp:108
void Transpose()
(*this) = (*this)^t
void SetRow(int r, const real_t *row)
void GetColumnReference(int c, Vector &col)
Definition densemat.hpp:331
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Definition densemat.hpp:116
void Invert()
Replaces the current matrix with its inverse.
Definition densemat.cpp:674
real_t Trace() const
Trace of a square matrix.
Definition densemat.cpp:409
void UseExternalData(real_t *d, int h, int w)
Change the data array and the size of the DenseMatrix.
Definition densemat.hpp:88
void Add(const real_t c, const DenseMatrix &A)
Adds the matrix A multiplied by the number c to the matrix.
Definition densemat.cpp:589
real_t Det() const
Definition densemat.cpp:496
void SetSize(int s)
Change the size of the DenseSymmetricMatrix to s x s.
Definition symmat.cpp:32
void UseExternalData(real_t *d, int s)
Change the data array and the size of the DenseSymmetricMatrix.
Definition symmat.hpp:54
real_t * GetData() const
Returns the matrix data array.
Definition symmat.hpp:86
DeterminantCoefficient(MatrixCoefficient &A)
Construct with the matrix.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the determinant coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the scalar divergence coefficient at ip.
DivergenceGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a vector grid function gf. The grid function is not owned by the coeff...
const Mesh * mesh
The Mesh object containing the element.
Definition eltrans.hpp:97
Geometry::Type GetGeometryType() const
Return the Geometry::Type of the reference element.
Definition eltrans.hpp:175
void SetIntPoint(const IntegrationPoint *ip)
Set the integration point ip that weights and Jacobians will be evaluated at.
Definition eltrans.hpp:106
virtual void Transform(const IntegrationPoint &, Vector &)=0
Transform integration point from reference coordinates to physical coordinates and store them in the ...
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
ExponentialMatrixCoefficient(MatrixCoefficient &A)
Construct the matrix coefficient. Result is .
Class representing the storage layout of a FaceQuadratureFunction.
Definition qspace.hpp:214
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:208
Mesh * GetMesh() const
Returns the mesh.
Definition fespace.hpp:644
int GetVDim() const
Returns the vector dimension of the finite element space.
Definition fespace.hpp:819
std::function< real_t(const Vector &)> Function
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
std::function< real_t(const Vector &, real_t)> TDFunction
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the gradient vector coefficient at ip.
void SetGridFunction(const GridFunction *gf)
Set the scalar grid function.
GradientGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a scalar grid function gf. The grid function is not owned by the coeff...
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:32
virtual real_t GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition gridfunc.cpp:449
void GetGradients(ElementTransformation &tr, const IntegrationRule &ir, DenseMatrix &grad) const
Extension of GetGradient(...) for a collection of IntegrationPoints.
FiniteElementSpace * FESpace()
virtual void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition gridfunc.cpp:474
real_t GetDivergence(ElementTransformation &tr) const
void GetCurl(ElementTransformation &tr, Vector &curl) const
void GetGradient(ElementTransformation &tr, Vector &grad) const
Gradient of a scalar function at a quadrature point.
void GetVectorValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
Definition gridfunc.cpp:707
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
InnerProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with the two vector coefficients. Result is .
IsoparametricTransformation Transf
Definition eltrans.hpp:733
void Transform(const IntegrationPoint &, IntegrationPoint &)
Definition eltrans.cpp:587
Class for integration point with weight.
Definition intrules.hpp:35
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:100
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition intrules.hpp:256
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Definition intrules.hpp:259
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
InverseMatrixCoefficient(MatrixCoefficient &A)
Construct with the matrix coefficient. Result is .
void SetTime(real_t t) override
Set the time for internally stored coefficients.
A standard isoparametric element transformation.
Definition eltrans.hpp:629
void SetPointMat(const DenseMatrix &pm)
Set the underlying point matrix describing the transformation.
Definition eltrans.hpp:668
void SetIdentityTransformation(Geometry::Type GeomType)
Set the FiniteElement Geometry for the reference elements being used.
Definition eltrans.cpp:417
void Set(int i, int j, Coefficient *c, bool own=true)
Set the coefficient located at (i,j) in the matrix. By default by default this will take ownership of...
MatrixArrayCoefficient(int dim)
Construct a coefficient matrix of dimensions dim * dim. The actual coefficients still need to be adde...
real_t Eval(int i, int j, ElementTransformation &T, const IntegrationPoint &ip)
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Eval(int i, Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
MatrixArrayVectorCoefficient(int dim)
Construct a coefficient matrix of dimensions dim * dim. The actual coefficients still need to be adde...
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Set(int i, VectorCoefficient *c, bool own=true)
Set the coefficient located at the i-th row of the matrix. By this will take ownership of the Coeffic...
Base class for Matrix Coefficients that optionally depend on time and space.
virtual void Project(QuadratureFunction &qf, bool transpose=false)
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points....
virtual void SetTime(real_t t)
Set the time for time dependent coefficients.
real_t GetTime()
Get the time for time dependent coefficients.
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
int GetWidth() const
Get the width of the matrix.
int GetHeight() const
Get the height of the matrix.
A matrix coefficient that is constant in space and time.
void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void EvalSymmetric(Vector &K, ElementTransformation &T, const IntegrationPoint &ip) override
(DEPRECATED) Evaluate the symmetric matrix coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
MatrixProductCoefficient(MatrixCoefficient &A, MatrixCoefficient &B)
Construct with the two coefficients. Result is A * B.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
MatrixSumCoefficient(MatrixCoefficient &A, MatrixCoefficient &B, real_t alpha_=1.0, real_t beta_=1.0)
Construct with the two coefficients. Result is alpha_ * A + beta_ * B.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
MatrixVectorProductCoefficient(MatrixCoefficient &A, VectorCoefficient &B)
Constructor with two coefficients. Result is A*B.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
Mesh data type.
Definition mesh.hpp:65
Element::Type GetElementType(int i) const
Returns the type of element i.
Definition mesh.cpp:7962
const CoarseFineTransformations & GetRefinementTransforms() const
Definition mesh.cpp:11749
int GetNE() const
Returns number of elements.
Definition mesh.hpp:1377
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1306
void GetElementTransformation(int i, IsoparametricTransformation *ElTr) const
Builds the transformation defining the i-th element in ElTr. ElTr must be allocated in advance and wi...
Definition mesh.cpp:360
int SpaceDimension() const
Dimension of the physical space containing the mesh.
Definition mesh.hpp:1309
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
Definition mesh.cpp:7558
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
NormalizedVectorCoefficient(VectorCoefficient &A, real_t tol=1e-6)
Return a vector normalized to a length of one.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition operator.hpp:66
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
Definition operator.hpp:72
void SetTime(real_t t) override
Set the time for internally stored coefficients.
OuterProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with two vector coefficients. Result is .
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
void UpdateCoefficient(int attr, Coefficient &coef)
Replace a single Coefficient for a particular attribute.
void SetTime(real_t t) override
Set the time for time dependent coefficients.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf with the piecewise constant values.
void UpdateCoefficient(int attr, MatrixCoefficient &coef)
Replace a single coefficient for a particular attribute.
void SetTime(real_t t) override
Set the time for time dependent coefficients.
void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
void UpdateCoefficient(int attr, VectorCoefficient &coef)
Replace a single Coefficient for a particular attribute.
void SetTime(real_t t) override
Set the time for time dependent coefficients.
Class for parallel meshes.
Definition pmesh.hpp:34
MPI_Comm GetComm() const
Definition pmesh.hpp:405
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
Quadrature function coefficient which requires that the quadrature rules used for this coefficient be...
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient in the element described by T at the point ip.
QuadratureFunctionCoefficient(const QuadratureFunction &qf)
Constructor with a quadrature function as input.
Represents values or vectors of values at quadrature points on a mesh.
Definition qfunction.hpp:24
void SetVDim(int vdim_)
Set the vector dimension, updating the size by calling Vector::SetSize().
Definition qfunction.hpp:90
QuadratureSpaceBase * GetSpace()
Get the associated QuadratureSpaceBase object.
Definition qfunction.hpp:94
void ProjectGridFunction(const GridFunction &gf)
Evaluate a grid function at each quadrature point.
void GetValues(int idx, Vector &values)
Return all values associated with mesh element idx in a Vector.
int GetVDim() const
Get the vector dimension.
Definition qfunction.hpp:87
const IntegrationRule & GetIntRule(int idx) const
Get the IntegrationRule associated with entity (element or face) idx.
Abstract base class for QuadratureSpace and FaceQuadratureSpace.
Definition qspace.hpp:32
int GetNE() const
Return the number of entities.
Definition qspace.hpp:113
virtual ElementTransformation * GetTransformation(int idx)=0
Get the (element or face) transformation of entity idx.
int GetSize() const
Return the total number of quadrature points.
Definition qspace.hpp:107
const IntegrationRule & GetIntRule(int idx) const
Return the IntegrationRule associated with entity idx.
Definition qspace.hpp:125
virtual int GetEntityIndex(const ElementTransformation &T) const =0
Returns the index in the quadrature space of the entity associated with the transformation T.
virtual int GetPermutedIndex(int idx, int iq) const =0
Returns the permuted index of the iq quadrature point in entity idx.
const Array< int > & Offsets(QSpaceOffsetStorage storage) const
Entity quadrature point offset array.
Definition qspace.cpp:40
int GetOrder() const
Return the order of the quadrature rule(s) used by all elements.
Definition qspace.hpp:110
Mesh * GetMesh() const
Returns the mesh.
Definition qspace.hpp:116
Class representing the storage layout of a QuadratureFunction.
Definition qspace.hpp:164
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
ScalarMatrixProductCoefficient(real_t A, MatrixCoefficient &B)
Constructor with one coefficient. Result is A*B.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
ScalarVectorProductCoefficient(real_t A, VectorCoefficient &B)
Constructor with constant and vector coefficient. Result is A * B.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
Base class for symmetric matrix coefficients that optionally depend on time and space.
virtual void ProjectSymmetric(QuadratureFunction &qf)
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
virtual void Eval(DenseSymmetricMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result as ...
DenseSymmetricMatrix mat_aux
Internal matrix used when evaluating this coefficient as a DenseMatrix.
A matrix coefficient that is constant in space and time.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Eval(DenseSymmetricMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the trace coefficient at ip.
TraceCoefficient(MatrixCoefficient &A)
Construct with the matrix.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
TransposeMatrixCoefficient(MatrixCoefficient &A)
Construct with the matrix coefficient. Result is .
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
virtual ~VectorArrayCoefficient()
Destroys vector coefficient.
VectorArrayCoefficient(int dim)
Construct vector of dim coefficients. The actual coefficients still need to be added with Set().
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Set(int i, Coefficient *c, bool own=true)
Sets coefficient in the vector.
real_t Eval(int i, ElementTransformation &T, const IntegrationPoint &ip)
Base class for vector Coefficients that optionally depend on time and space.
int GetVDim()
Returns dimension of the vector.
virtual void SetTime(real_t t)
Set the time for time dependent coefficients.
real_t GetTime()
Get the time for time dependent coefficients.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
virtual void Project(QuadratureFunction &qf)
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
Vector coefficient that is constant in space and time.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
VectorCrossProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with the two coefficients. Result is A x B.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetDirection(const Vector &d_)
virtual void EvalDelta(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Return the specified direction vector multiplied by the value returned by DeltaCoefficient::EvalDelta...
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
void SetGridFunction(const GridFunction *gf)
Set the grid function for this coefficient. Also sets the Vector dimension to match that of the gf.
VectorGridFunctionCoefficient()
Construct an empty coefficient. Calling Eval() before the grid function is set will cause a segfault.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
Vector quadrature function coefficient which requires that the quadrature rules used for this vector ...
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
VectorQuadratureFunctionCoefficient(const QuadratureFunction &qf)
Constructor with a quadrature function as input.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
void SetComponent(int index_, int length_)
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
VectorRotProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Constructor with two vector coefficients. Result is .
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
Vector data type.
Definition vector.hpp:82
virtual const real_t * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
Definition vector.hpp:524
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:520
virtual real_t * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:536
real_t Norml2() const
Returns the l2 norm of the vector.
Definition vector.cpp:968
virtual bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
Definition vector.hpp:148
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:584
void Reciprocal()
(*this)(i) = 1.0 / (*this)(i)
Definition vector.cpp:384
virtual real_t * HostWrite()
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), false).
Definition vector.hpp:532
Vector & operator=(const real_t *v)
Copy Size() entries from v.
Definition vector.cpp:197
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:528
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
Definition vector.hpp:660
Vector beta_
const real_t alpha
Definition ex15.cpp:369
int dim
Definition ex24.cpp:53
Mesh * GetMesh(int type)
Definition ex29.cpp:218
int index(int i, int j, int nx, int ny)
Definition life.cpp:236
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
Definition vector.hpp:47
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
Definition table.cpp:505
real_t ComputeGlobalLpNorm(real_t p, Coefficient &coeff, ParMesh &pmesh, const IntegrationRule *irs[])
Compute the global Lp norm of a function f. .
void add(const Vector &v1, const Vector &v2, Vector &v)
Definition vector.cpp:414
real_t ComputeLpNorm(real_t p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
Compute the Lp norm of a function f. .
CoefficientStorage
Flags that determine what storage optimizations to use in CoefficientVector.
@ SYMMETRIC
Store the triangular part of symmetric matrices.
@ CONSTANTS
Store constants using only vdim entries.
float real_t
Definition config.hpp:46
real_t LpNormLoop(real_t p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
void forall(int N, lambda &&body)
Definition forall.hpp:839
ElementTransformation * RefinedToCoarse(Mesh &coarse_mesh, const ElementTransformation &T, const IntegrationPoint &ip, IntegrationPoint &coarse_ip)
real_t p(const Vector &x, real_t t)
MFEM_HOST_DEVICE real_t norm(const Complex &z)
Defines the coarse-fine transformations of all fine elements.
Definition ncmesh.hpp:90
Array< Embedding > embeddings
Fine element positions in their parents.
Definition ncmesh.hpp:92
DenseTensor point_matrices[Geometry::NumGeom]
Definition ncmesh.hpp:96
Helper struct to convert a C++ type to an MPI type.