MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
coefficient.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, 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 // GetValues makes a reference, but we need it to be valid on Host
58 qf.HostWrite();
59 for (int iel = 0; iel < ne; ++iel)
60 {
61 qf.GetValues(iel, values);
62 const IntegrationRule &ir = qspace.GetIntRule(iel);
64 for (int iq = 0; iq < ir.Size(); ++iq)
65 {
66 const IntegrationPoint &ip = ir[iq];
67 T.SetIntPoint(&ip);
68 const int iq_p = qspace.GetPermutedIndex(iel, iq);
69 values[iq_p] = Eval(T, ip);
70 }
71 }
72}
73
78
80 const IntegrationPoint & ip)
81{
82 int att = T.Attribute;
83 return (constants(att-1));
84}
85
87{
88 auto &qs = *qf.GetSpace();
89
90 const bool compressed =
92 const int *offsets = qs.Offsets(QSpaceOffsetStorage::COMPRESSED).Read();
93 const int ne = qs.GetNE();
94
95 const int *attributes = [&]()
96 {
97 if (dynamic_cast<QuadratureSpace*>(&qs) != nullptr)
98 {
99 return qs.GetMesh()->GetElementAttributes().Read();
100 }
101 else if (auto *qs_f = dynamic_cast<FaceQuadratureSpace*>(&qs))
102 {
103 MFEM_VERIFY(qs_f->GetFaceType() == FaceType::Boundary,
104 "Interior faces do not have attributes.");
105 return qs.GetMesh()->GetBdrFaceAttributes().Read();
106 }
107 else
108 {
109 MFEM_ABORT("Unsupported case.");
110 }
111 }();
112
113 const real_t *d_c = constants.Read();
114 real_t *d_qf = qf.Write();
115
116 mfem::forall(ne, [=] MFEM_HOST_DEVICE (int e)
117 {
118 const int a = attributes[e];
119 const real_t elementConstant = d_c[a - 1];
120 const int begin = compressed ? e*offsets[0] : offsets[e];
121 const int end = compressed ? (e+1)*offsets[0] : offsets[e+1];
122 for (int i = begin; i < end; ++i)
123 {
124 d_qf[i] = elementConstant;
125 }
126 });
127}
128
129void PWCoefficient::InitMap(const Array<int> & attr,
130 const Array<Coefficient*> & coefs)
131{
132 MFEM_VERIFY(attr.Size() == coefs.Size(),
133 "PWCoefficient: "
134 "Attribute and coefficient arrays have incompatible "
135 "dimensions.");
136
137 for (int i=0; i<attr.Size(); i++)
138 {
139 if (coefs[i] != NULL)
140 {
141 UpdateCoefficient(attr[i], *coefs[i]);
142 }
143 }
144}
145
147{
149
150 std::map<int, Coefficient*>::iterator p = pieces.begin();
151 for (; p != pieces.end(); p++)
152 {
153 if (p->second != NULL)
154 {
155 p->second->SetTime(t);
156 }
157 }
158}
159
161 const IntegrationPoint &ip)
162{
163 const int att = T.Attribute;
164 std::map<int, Coefficient*>::const_iterator p = pieces.find(att);
165 if (p != pieces.end())
166 {
167 if ( p->second != NULL)
168 {
169 return p->second->Eval(T, ip);
170 }
171 }
172 return 0.0;
173}
174
176 const IntegrationPoint & ip)
177{
178 real_t x[3];
179 Vector transip(x, 3);
180
181 T.Transform(ip, transip);
182
183 if (Function)
184 {
185 return Function(transip);
186 }
187 else
188 {
189 return TDFunction(transip, GetTime());
190 }
191}
192
199
201 const IntegrationPoint & ip)
202{
203 T.Transform(ip, transip);
204 return sqrt(transip[0] * transip[0] + transip[1] * transip[1]);
205}
206
208 const IntegrationPoint & ip)
209{
210 T.Transform(ip, transip);
211 return atan2(transip[1], transip[0]);
212}
213
215 const IntegrationPoint & ip)
216{
217 T.Transform(ip, transip);
218 return sqrt(transip * transip);
219}
220
222 const IntegrationPoint & ip)
223{
224 T.Transform(ip, transip);
225 return atan2(transip[1], transip[0]);
226}
227
229 const IntegrationPoint & ip)
230{
231 T.Transform(ip, transip);
232 return atan2(sqrt(transip[0] * transip[0] + transip[1] * transip[1]),
233 transip[2]);
234}
235
237 const IntegrationPoint &ip)
238{
239 Mesh *gf_mesh = GridF->FESpace()->GetMesh();
240 if (T.mesh->GetNE() == gf_mesh->GetNE())
241 {
242 return GridF->GetValue(T, ip, Component);
243 }
244 else
245 {
246 IntegrationPoint coarse_ip;
247 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
248 return GridF->GetValue(*coarse_T, coarse_ip, Component);
249 }
250}
251
256
258{
259 if (Q1) { Q1->SetTime(t); }
260 if (Q2) { Q2->SetTime(t); }
261 this->Coefficient::SetTime(t);
262}
263
265 const IntegrationPoint &ip)
266{
267 if (Q2)
268 {
269 return Transform2(Q1->Eval(T, ip, GetTime()),
270 Q2->Eval(T, ip, GetTime()));
271 }
272 else
273 {
274 return Transform1(Q1->Eval(T, ip, GetTime()));
275 }
276}
277
279{
280 if (weight) { weight->SetTime(t); }
281 this->Coefficient::SetTime(t);
282}
283
285{
286 MFEM_VERIFY(vcenter.Size() <= 3,
287 "SetDeltaCenter::Maximum number of dim supported is 3")
288 for (int i = 0; i < vcenter.Size(); i++) { center[i] = vcenter[i]; }
289 sdim = vcenter.Size();
290}
291
293{
294 vcenter.SetSize(sdim);
295 vcenter = center;
296}
297
299 const IntegrationPoint &ip)
300{
301 real_t w = Scale();
302 return weight ? weight->Eval(T, ip, GetTime())*w : w;
303}
304
306{
307 if (c) { c->SetTime(t); }
308 this->Coefficient::SetTime(t);
309}
310
312 const IntegrationRule &ir)
313{
314 Vector Mi;
315 M.SetSize(vdim, ir.GetNPoints());
316 for (int i = 0; i < ir.GetNPoints(); i++)
317 {
318 M.GetColumnReference(i, Mi);
319 const IntegrationPoint &ip = ir.IntPoint(i);
320 T.SetIntPoint(&ip);
321 Eval(Mi, T, ip);
322 }
323}
324
326{
327 MFEM_VERIFY(vdim == qf.GetVDim(), "Wrong sizes.");
328 QuadratureSpaceBase &qspace = *qf.GetSpace();
329 const int ne = qspace.GetNE();
330 DenseMatrix values;
331 Vector col;
332 // GetValues makes a reference, but we need it to be valid on Host
333 qf.HostWrite();
334 for (int iel = 0; iel < ne; ++iel)
335 {
336 qf.GetValues(iel, values);
337 const IntegrationRule &ir = qspace.GetIntRule(iel);
339 for (int iq = 0; iq < ir.Size(); ++iq)
340 {
341 const IntegrationPoint &ip = ir[iq];
342 T.SetIntPoint(&ip);
343 const int iq_p = qspace.GetPermutedIndex(iel, iq);
344 values.GetColumnReference(iq_p, col);
345 Eval(col, T, ip);
346 }
347 }
348}
349
350void PWVectorCoefficient::InitMap(const Array<int> & attr,
351 const Array<VectorCoefficient*> & coefs)
352{
353 MFEM_VERIFY(attr.Size() == coefs.Size(),
354 "PWVectorCoefficient: "
355 "Attribute and coefficient arrays have incompatible "
356 "dimensions.");
357
358 for (int i=0; i<attr.Size(); i++)
359 {
360 if (coefs[i] != NULL)
361 {
362 UpdateCoefficient(attr[i], *coefs[i]);
363 }
364 }
365}
366
368{
369 MFEM_VERIFY(coef.GetVDim() == vdim,
370 "PWVectorCoefficient::UpdateCoefficient: "
371 "VectorCoefficient has incompatible dimension.");
372 pieces[attr] = &coef;
373}
374
376{
378
379 std::map<int, VectorCoefficient*>::iterator p = pieces.begin();
380 for (; p != pieces.end(); p++)
381 {
382 if (p->second != NULL)
383 {
384 p->second->SetTime(t);
385 }
386 }
387}
388
390 const IntegrationPoint &ip)
391{
392 const int att = T.Attribute;
393 std::map<int, VectorCoefficient*>::const_iterator p = pieces.find(att);
394 if (p != pieces.end())
395 {
396 if ( p->second != NULL)
397 {
398 p->second->Eval(V, T, ip);
399 return;
400 }
401 }
402
403 V.SetSize(vdim);
404 V = 0.0;
405}
406
408 const IntegrationPoint &ip)
409{
410 V.SetSize(vdim);
411 T.Transform(ip, V);
412}
413
415 const IntegrationPoint &ip)
416{
417 real_t x[3];
418 Vector transip(x, 3);
419
420 T.Transform(ip, transip);
421
422 V.SetSize(vdim);
423 if (Function)
424 {
425 Function(transip, V);
426 }
427 else
428 {
429 TDFunction(transip, GetTime(), V);
430 }
431 if (Q)
432 {
433 V *= Q->Eval(T, ip, GetTime());
434 }
435}
436
438 : VectorCoefficient(dim), Coeff(dim), ownCoeff(dim)
439{
440 for (int i = 0; i < dim; i++)
441 {
442 Coeff[i] = NULL;
443 ownCoeff[i] = true;
444 }
445}
446
448{
449 for (int i = 0; i < vdim; i++)
450 {
451 if (Coeff[i]) { Coeff[i]->SetTime(t); }
452 }
454}
455
457{
458 if (ownCoeff[i]) { delete Coeff[i]; }
459 Coeff[i] = c;
460 ownCoeff[i] = own;
461}
462
464{
465 for (int i = 0; i < vdim; i++)
466 {
467 if (ownCoeff[i]) { delete Coeff[i]; }
468 }
469}
470
472 const IntegrationPoint &ip)
473{
474 V.SetSize(vdim);
475 for (int i = 0; i < vdim; i++)
476 {
477 V(i) = this->Eval(i, T, ip);
478 }
479}
480
482 const GridFunction *gf)
483 : VectorCoefficient ((gf) ? gf -> VectorDim() : 0)
484{
485 GridFunc = gf;
486}
487
489{
490 GridFunc = gf; vdim = (gf) ? gf -> VectorDim() : 0;
491}
492
494 const IntegrationPoint &ip)
495{
496 Mesh *gf_mesh = GridFunc->FESpace()->GetMesh();
497 if (T.mesh->GetNE() == gf_mesh->GetNE())
498 {
499 GridFunc->GetVectorValue(T, ip, V);
500 }
501 else
502 {
503 IntegrationPoint coarse_ip;
504 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
505 GridFunc->GetVectorValue(*coarse_T, coarse_ip, V);
506 }
507}
508
511{
512 if (T.mesh == GridFunc->FESpace()->GetMesh())
513 {
514 GridFunc->GetVectorValues(T, ir, M);
515 }
516 else
517 {
518 VectorCoefficient::Eval(M, T, ir);
519 }
520}
521
526
528 const GridFunction *gf)
529 : VectorCoefficient((gf) ?
530 gf -> FESpace() -> GetMesh() -> SpaceDimension() : 0)
531{
532 GridFunc = gf;
533}
534
536{
537 GridFunc = gf; vdim = (gf) ?
538 gf -> FESpace() -> GetMesh() -> SpaceDimension() : 0;
539}
540
542 const IntegrationPoint &ip)
543{
544 Mesh *gf_mesh = GridFunc->FESpace()->GetMesh();
545 if (T.mesh->GetNE() == gf_mesh->GetNE())
546 {
547 GridFunc->GetGradient(T, V);
548 }
549 else
550 {
551 IntegrationPoint coarse_ip;
552 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
553 GridFunc->GetGradient(*coarse_T, V);
554 }
555}
556
559{
560 if (T.mesh == GridFunc->FESpace()->GetMesh())
561 {
562 GridFunc->GetGradients(T, ir, M);
563 }
564 else
565 {
566 VectorCoefficient::Eval(M, T, ir);
567 }
568}
569
571{
572 const FiniteElementSpace &fes = *GridFunc->FESpace();
573 const Mesh &mesh = *fes.GetMesh();
574 const int sdim = mesh.SpaceDimension();
575 const int gf_vdim = fes.GetVDim(); // assumed to be 1 in this class
576 qf.SetVDim(sdim*gf_vdim);
577 if (mesh.GetNE() == 0) { return; }
578 // All mesh element must be the same type:
579 MFEM_VERIFY(mesh.GetNumGeometries(mesh.Dimension()) == 1,
580 "All mesh elements must be the same type!");
581 const IntegrationRule &ir = qf.GetIntRule(0);
582 // All elements must use the same quadrature rule:
583 MFEM_VERIFY(qf.Size() == sdim*gf_vdim*ir.GetNPoints()*mesh.GetNE(),
584 "All mesh elements must use the same quadrature rule!");
585 // QuadratureFunction uses the layout qf_vdim x nq x ne, i.e.
586 // gf_vdim x sdim x nq x nq, so we need to request QVectorLayout::byVDIM:
588}
589
596
598{
599 GridFunc = gf; vdim = (gf) ? gf -> CurlDim() : 0;
600}
601
603 const IntegrationPoint &ip)
604{
605 Mesh *gf_mesh = GridFunc->FESpace()->GetMesh();
606 if (T.mesh->GetNE() == gf_mesh->GetNE())
607 {
608 GridFunc->GetCurl(T, V);
609 }
610 else
611 {
612 IntegrationPoint coarse_ip;
613 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
614 GridFunc->GetCurl(*coarse_T, V);
616}
617
623
625 const IntegrationPoint &ip)
626{
627 Mesh *gf_mesh = GridFunc->FESpace()->GetMesh();
628 if (T.mesh->GetNE() == gf_mesh->GetNE())
629 {
630 return GridFunc->GetDivergence(T);
631 }
632 else
633 {
634 IntegrationPoint coarse_ip;
635 ElementTransformation *coarse_T = RefinedToCoarse(*gf_mesh, T, ip, coarse_ip);
636 return GridFunc->GetDivergence(*coarse_T);
637 }
638}
639
645
647{
648 dir = d_;
649 (*this).vdim = dir.Size();
650}
651
654{
655 V = dir;
656 d.SetTime(GetTime());
657 V *= d.EvalDelta(T, ip);
658}
659
661{
662 if (c) { c->SetTime(t); }
664}
665
667 const IntegrationPoint &ip)
668{
669 V.SetSize(vdim);
670 if (active_attr[T.Attribute-1])
671 {
672 c->SetTime(GetTime());
673 c->Eval(V, T, ip);
674 }
675 else
676 {
677 V = 0.0;
678 }
679}
680
683{
684 if (active_attr[T.Attribute-1])
685 {
686 c->SetTime(GetTime());
687 c->Eval(M, T, ir);
688 }
689 else
690 {
691 M.SetSize(vdim, ir.GetNPoints());
692 M = 0.0;
693 }
694}
695
697{
698 MFEM_VERIFY(qf.GetVDim() == height*width, "Wrong sizes.");
699 QuadratureSpaceBase &qspace = *qf.GetSpace();
700 const int ne = qspace.GetNE();
701 DenseMatrix values, matrix;
702 // GetValues makes a reference, but we need it to be valid on Host
703 qf.HostWrite();
704 for (int iel = 0; iel < ne; ++iel)
705 {
706 qf.GetValues(iel, values);
707 const IntegrationRule &ir = qspace.GetIntRule(iel);
709 for (int iq = 0; iq < ir.Size(); ++iq)
710 {
711 const IntegrationPoint &ip = ir[iq];
712 T.SetIntPoint(&ip);
713 const int iq_p = qspace.GetPermutedIndex(iel, iq);
714 matrix.UseExternalData(&values(0, iq_p), height, width);
715 Eval(matrix, T, ip);
716 if (transpose) { matrix.Transpose(); }
717 }
718 }
719}
720
721void PWMatrixCoefficient::InitMap(const Array<int> & attr,
722 const Array<MatrixCoefficient*> & coefs)
723{
724 MFEM_VERIFY(attr.Size() == coefs.Size(),
725 "PWMatrixCoefficient: "
726 "Attribute and coefficient arrays have incompatible "
727 "dimensions.");
728
729 for (int i=0; i<attr.Size(); i++)
730 {
731 if (coefs[i] != NULL)
732 {
733 UpdateCoefficient(attr[i], *coefs[i]);
734 }
735 }
736}
737
739{
740 MFEM_VERIFY(coef.GetHeight() == height,
741 "PWMatrixCoefficient::UpdateCoefficient: "
742 "MatrixCoefficient has incompatible height.");
743 MFEM_VERIFY(coef.GetWidth() == width,
744 "PWMatrixCoefficient::UpdateCoefficient: "
745 "MatrixCoefficient has incompatible width.");
746 if (symmetric)
747 {
748 MFEM_VERIFY(coef.IsSymmetric(),
749 "PWMatrixCoefficient::UpdateCoefficient: "
750 "MatrixCoefficient has incompatible symmetry.");
751 }
752 pieces[attr] = &coef;
753}
754
756{
758
759 std::map<int, MatrixCoefficient*>::iterator p = pieces.begin();
760 for (; p != pieces.end(); p++)
761 {
762 if (p->second != NULL)
763 {
764 p->second->SetTime(t);
765 }
766 }
767}
768
770 const IntegrationPoint &ip)
771{
772 const int att = T.Attribute;
773 std::map<int, MatrixCoefficient*>::const_iterator p = pieces.find(att);
774 if (p != pieces.end())
775 {
776 if ( p->second != NULL)
777 {
778 p->second->Eval(K, T, ip);
779 return;
780 }
781 }
782
783 K.SetSize(height, width);
784 K = 0.0;
785}
786
788{
789 if (Q) { Q->SetTime(t); }
791}
792
794 const IntegrationPoint &ip)
795{
796 real_t x[3];
797 Vector transip(x, 3);
798
799 T.Transform(ip, transip);
800
801 K.SetSize(height, width);
802
803 if (symmetric) // Use SymmFunction (deprecated version)
804 {
805 MFEM_VERIFY(height == width && SymmFunction,
806 "MatrixFunctionCoefficient is not symmetric");
807
808 Vector Ksym((width * (width + 1)) / 2); // 1x1: 1, 2x2: 3, 3x3: 6
809
810 SymmFunction(transip, Ksym);
811
812 // Copy upper triangular values from Ksym to the full matrix K
813 int os = 0;
814 for (int i=0; i<height; ++i)
815 {
816 for (int j=i; j<width; ++j)
817 {
818 const real_t Kij = Ksym[j - i + os];
819 K(i,j) = Kij;
820 if (j != i) { K(j,i) = Kij; }
821 }
822
823 os += width - i;
824 }
825 }
826 else
827 {
828 if (Function)
829 {
830 Function(transip, K);
831 }
832 else if (TDFunction)
833 {
834 TDFunction(transip, GetTime(), K);
835 }
836 else
837 {
838 K = mat;
839 }
840 }
841
842 if (Q)
843 {
844 K *= Q->Eval(T, ip, GetTime());
845 }
846}
847
850 const IntegrationPoint &ip)
851{
852 MFEM_VERIFY(symmetric && height == width && SymmFunction,
853 "MatrixFunctionCoefficient is not symmetric");
854
855 real_t x[3];
856 Vector transip(x, 3);
857
858 T.Transform(ip, transip);
859
860 K.SetSize((width * (width + 1)) / 2); // 1x1: 1, 2x2: 3, 3x3: 6
861
862 if (SymmFunction)
863 {
864 SymmFunction(transip, K);
865 }
866
867 if (Q)
868 {
869 K *= Q->Eval(T, ip, GetTime());
870 }
871}
872
874{
875 const int vdim = qf.GetVDim();
876 MFEM_VERIFY(vdim == height*(height+1)/2, "Wrong sizes.");
877
878 QuadratureSpaceBase &qspace = *qf.GetSpace();
879 const int ne = qspace.GetNE();
880 qf.HostWrite();
881 DenseMatrix values;
883 for (int iel = 0; iel < ne; ++iel)
884 {
885 qf.GetValues(iel, values);
886 const IntegrationRule &ir = qspace.GetIntRule(iel);
888 for (int iq = 0; iq < ir.Size(); ++iq)
889 {
890 const IntegrationPoint &ip = ir[iq];
891 T.SetIntPoint(&ip);
892 matrix.UseExternalData(&values(0, iq), height);
893 Eval(matrix, T, ip);
894 }
895 }
896}
897
898
900 const IntegrationPoint &ip)
901{
902 Eval(mat_aux, T, ip);
903 for (int j = 0; j < width; ++j)
904 {
905 for (int i = 0; i < height; ++ i)
906 {
907 K(i, j) = mat_aux(i, j);
908 }
909 }
910}
911
917
920 const IntegrationPoint &ip)
921{
922 real_t x[3];
923 Vector transip(x, 3);
924
925 T.Transform(ip, transip);
926
927 K.SetSize(height);
928
929 if (Function)
930 {
931 Function(transip, K);
932 }
933 else if (TDFunction)
934 {
935 TDFunction(transip, GetTime(), K);
936 }
937 else
938 {
939 K = mat;
940 }
941
942 if (Q)
943 {
944 K *= Q->Eval(T, ip, GetTime());
945 }
946}
947
950{
951 Coeff.SetSize(height*width);
952 ownCoeff.SetSize(height*width);
953 for (int i = 0; i < (height*width); i++)
954 {
955 Coeff[i] = NULL;
956 ownCoeff[i] = true;
957 }
958}
959
961{
962 for (int i=0; i < height*width; i++)
963 {
964 if (Coeff[i]) { Coeff[i]->SetTime(t); }
965 }
967}
968
969void MatrixArrayCoefficient::Set(int i, int j, Coefficient * c, bool own)
970{
971 if (ownCoeff[i*width+j]) { delete Coeff[i*width+j]; }
972 Coeff[i*width+j] = c;
973 ownCoeff[i*width+j] = own;
974}
975
977{
978 for (int i=0; i < height*width; i++)
979 {
980 if (ownCoeff[i]) { delete Coeff[i]; }
981 }
982}
983
985 const IntegrationPoint &ip)
986{
987 K.SetSize(height, width);
988 for (int i = 0; i < height; i++)
989 {
990 for (int j = 0; j < width; j++)
991 {
992 K(i,j) = this->Eval(i, j, T, ip);
993 }
994 }
995}
996
999{
1000 Coeff.SetSize(height);
1001 ownCoeff.SetSize(height);
1002 for (int i = 0; i < height; i++)
1003 {
1004 Coeff[i] = NULL;
1005 ownCoeff[i] = true;
1006 }
1007}
1008
1010{
1011 for (int i=0; i < height; i++)
1012 {
1013 if (Coeff[i]) { Coeff[i]->SetTime(t); }
1014 }
1016}
1017
1019{
1020 MFEM_ASSERT(i < height && i >= 0, "Row "
1021 << i << " does not exist. " <<
1022 "Matrix height = " << height << ".");
1023 if (ownCoeff[i]) { delete Coeff[i]; }
1024 Coeff[i] = c;
1025 ownCoeff[i] = own;
1026}
1027
1029{
1030 for (int i=0; i < height; i++)
1031 {
1032 if (ownCoeff[i]) { delete Coeff[i]; }
1033 }
1034}
1035
1038 const IntegrationPoint &ip)
1039{
1040 MFEM_ASSERT(i < height && i >= 0, "Row "
1041 << i << " does not exist. " <<
1042 "Matrix height = " << height << ".");
1043 if (Coeff[i])
1044 {
1045 Coeff[i] -> Eval(V, T, ip);
1046 }
1047 else
1048 {
1049 V = 0.0;
1050 }
1051}
1052
1055 const IntegrationPoint &ip)
1056{
1057 K.SetSize(height, width);
1058 Vector V(width);
1059 for (int i = 0; i < height; i++)
1060 {
1061 this->Eval(i, V, T, ip);
1062 K.SetRow(i, V);
1063 }
1064}
1065
1067{
1068 if (c) { c->SetTime(t); }
1070}
1071
1073 const IntegrationPoint &ip)
1074{
1075 if (active_attr[T.Attribute-1])
1076 {
1077 c->SetTime(GetTime());
1078 c->Eval(K, T, ip);
1079 }
1080 else
1081 {
1082 K.SetSize(height, width);
1083 K = 0.0;
1084 }
1085}
1086
1088{
1089 if (a) { a->SetTime(t); }
1090 if (b) { b->SetTime(t); }
1091 this->Coefficient::SetTime(t);
1092}
1093
1095{
1096 if (a == nullptr)
1097 {
1098 // qf = alpha*aConst + beta * b
1099 const real_t d_alpha_a = aConst*alpha;
1100 const real_t d_beta = beta;
1101 b->Project(qf);
1102 auto d_qf = qf.ReadWrite();
1103 mfem::forall(qf.Size(), [=] MFEM_HOST_DEVICE (int i)
1104 {
1105 d_qf[i] = d_alpha_a + d_beta*d_qf[i];
1106 });
1107 }
1108 else
1109 {
1110 a->Project(qf);
1111 QuadratureFunction qf_b(*qf.GetSpace());
1112 b->Project(qf_b);
1113 add(alpha, qf, beta, qf_b, qf);
1114 }
1115}
1116
1118{
1119 if (a) { a->SetTime(t); }
1120 if (b) { b->SetTime(t); }
1121 this->Coefficient::SetTime(t);
1122}
1123
1125{
1126 if (a == nullptr)
1127 {
1128 // qf = aConst * b
1129 b->Project(qf);
1130 qf *= aConst;
1131 }
1132 else
1133 {
1134 a->Project(qf);
1135 QuadratureFunction qf_b(qf.GetSpace());
1136 b->Project(qf_b);
1137 qf *= qf_b;
1138 }
1139}
1140
1142{
1143 if (a) { a->SetTime(t); }
1144 if (b) { b->SetTime(t); }
1145 this->Coefficient::SetTime(t);
1146}
1147
1149{
1150 if (b == nullptr)
1151 {
1152 if (a == nullptr)
1153 {
1154 qf = aConst / bConst;
1155 }
1156 else
1157 {
1158 a->Project(qf);
1159 qf *= 1.0/bConst;
1160 }
1161 }
1162 else
1163 {
1164 if (a == nullptr)
1165 {
1166 b->Project(qf);
1167 qf.Reciprocal();
1168 qf *= aConst;
1169 }
1170 else
1171 {
1172 a->Project(qf);
1173 QuadratureFunction qf_b(qf.GetSpace());
1174 b->Project(qf_b);
1175 qf /= qf_b;
1176 }
1177 }
1178}
1179
1181{
1182 if (a) { a->SetTime(t); }
1183 this->Coefficient::SetTime(t);
1184}
1185
1188 : a(&A), b(&B), va(A.GetVDim()), vb(B.GetVDim())
1189{
1190 MFEM_ASSERT(A.GetVDim() == B.GetVDim(),
1191 "InnerProductCoefficient: "
1192 "Arguments have incompatible dimensions.");
1193}
1194
1196{
1197 if (a) { a->SetTime(t); }
1198 if (b) { b->SetTime(t); }
1199 this->Coefficient::SetTime(t);
1200}
1201
1203 const IntegrationPoint &ip)
1204{
1205 a->Eval(va, T, ip);
1206 b->Eval(vb, T, ip);
1207 return va * vb;
1208}
1209
1211{
1212 MFEM_VERIFY(a->GetVDim() == b->GetVDim(),
1213 "Incompatible vector coefficients: a->GetVDim(): "
1214 << a->GetVDim() << ", b->GetVDim(): " << b->GetVDim());
1215
1216 const int vdim = a->GetVDim();
1217 MFEM_VERIFY(vdim >= 1, "invalid vdim: " << vdim);
1218
1219 // When running on device, make sure the output data is allocated before any
1220 // local temporary data to reduce potential heap fragmentation:
1221 auto dot_d = qf.Write();
1222
1223 QuadratureFunction qf_a(qf.GetSpace(), vdim);
1224 QuadratureFunction qf_b(qf.GetSpace(), vdim);
1225
1226 a->Project(qf_a);
1227 b->Project(qf_b);
1228
1229 auto a_d = qf_a.Read();
1230 auto b_d = qf_b.Read();
1231
1232 mfem::forall(qf.GetSpace()->GetSize(), [=] MFEM_HOST_DEVICE (int i)
1233 {
1234 const real_t *ai = a_d + i*vdim;
1235 const real_t *bi = b_d + i*vdim;
1236 real_t dot = ai[0]*bi[0];
1237 for (int d = 1; d < vdim; d++)
1238 {
1239 dot += ai[d]*bi[d];
1240 }
1241 dot_d[i] = dot;
1242 });
1243}
1244
1247 : a(&A), b(&B), va(A.GetVDim()), vb(B.GetVDim())
1248{
1249 MFEM_ASSERT(A.GetVDim() == 2 && B.GetVDim() == 2,
1250 "VectorRotProductCoefficient: "
1251 "Arguments must have dimension equal to two.");
1252}
1253
1255{
1256 if (a) { a->SetTime(t); }
1257 if (b) { b->SetTime(t); }
1258 this->Coefficient::SetTime(t);
1259}
1260
1262 const IntegrationPoint &ip)
1263{
1264 a->Eval(va, T, ip);
1265 b->Eval(vb, T, ip);
1266 return va[0] * vb[1] - va[1] * vb[0];
1267}
1268
1270 : a(&A), ma(A.GetHeight(), A.GetWidth())
1271{
1272 MFEM_ASSERT(A.GetHeight() == A.GetWidth(),
1273 "DeterminantCoefficient: "
1274 "Argument must be a square matrix.");
1275}
1276
1278{
1279 if (a) { a->SetTime(t); }
1280 this->Coefficient::SetTime(t);
1281}
1282
1284 const IntegrationPoint &ip)
1285{
1286 a->Eval(ma, T, ip);
1287 return ma.Det();
1288}
1289
1291 : a(&A), ma(A.GetHeight(), A.GetWidth())
1292{
1293 MFEM_ASSERT(A.GetHeight() == A.GetWidth(),
1294 "TraceCoefficient: "
1295 "Argument must be a square matrix.");
1296}
1297
1299{
1300 if (a) { a->SetTime(t); }
1301 this->Coefficient::SetTime(t);
1302}
1303
1305 const IntegrationPoint &ip)
1306{
1307 a->Eval(ma, T, ip);
1308 return ma.Trace();
1309}
1310
1312 int c)
1313 : a(&A), va(A.GetVDim())
1314{
1315 SetComponent(c);
1316}
1317
1319{
1320 MFEM_ASSERT(c < a->GetVDim() && c >= 0,
1321 "VectorComponentCoefficient: "
1322 "Index not in range.");
1323
1324 component = c;
1325}
1326
1328{
1329 if (a) { a->SetTime(t); }
1330 this->Coefficient::SetTime(t);
1331}
1332
1334 const IntegrationPoint &ip)
1335{
1336 a->Eval(va, T, ip);
1337 return va[component];
1338}
1339
1341 int ri, int ci)
1342 : a(&A), ma(A.GetHeight(), A.GetWidth())
1343{
1344 SetRowIndex(ri);
1345 SetColumnIndex(ci);
1346}
1347
1349{
1350 MFEM_ASSERT(ri < a->GetHeight() && ri >= 0,
1351 "MatrixComponentCoefficient: "
1352 "Row index not in range.");
1353
1354 row_idx = ri;
1355}
1356
1358{
1359 MFEM_ASSERT(ci < a->GetWidth() && ci >= 0,
1360 "MatrixComponentCoefficient: "
1361 "Column index not in range.");
1362 col_idx = ci;
1363}
1364
1366{
1367 if (a) { a->SetTime(t); }
1368 this->Coefficient::SetTime(t);
1369}
1370
1372 const IntegrationPoint &ip)
1373{
1374 a->Eval(ma, T, ip);
1375 return ma(row_idx,col_idx);
1376}
1377
1380 ACoef(NULL), BCoef(NULL),
1381 A(dim), B(dim),
1382 alphaCoef(NULL), betaCoef(NULL),
1383 alpha(1.0), beta(1.0)
1384{
1385 A = 0.0; B = 0.0;
1386}
1387
1390 real_t alpha_, real_t beta_)
1391 : VectorCoefficient(A_.GetVDim()),
1392 ACoef(&A_), BCoef(&B_),
1393 A(A_.GetVDim()), B(A_.GetVDim()),
1394 alphaCoef(NULL), betaCoef(NULL),
1395 alpha(alpha_), beta(beta_)
1396{
1397 MFEM_ASSERT(A_.GetVDim() == B_.GetVDim(),
1398 "VectorSumCoefficient: "
1399 "Arguments must have the same dimension.");
1400}
1401
1404 Coefficient &alpha_,
1406 : VectorCoefficient(A_.GetVDim()),
1407 ACoef(&A_), BCoef(&B_),
1408 A(A_.GetVDim()),
1409 B(A_.GetVDim()),
1410 alphaCoef(&alpha_),
1411 betaCoef(&beta_),
1412 alpha(0.0), beta(0.0)
1413{
1414 MFEM_ASSERT(A_.GetVDim() == B_.GetVDim(),
1415 "VectorSumCoefficient: "
1416 "Arguments must have the same dimension.");
1417}
1418
1420{
1421 if (ACoef) { ACoef->SetTime(t); }
1422 if (BCoef) { BCoef->SetTime(t); }
1423 if (alphaCoef) { alphaCoef->SetTime(t); }
1424 if (betaCoef) { betaCoef->SetTime(t); }
1426}
1427
1429 const IntegrationPoint &ip)
1430{
1431 V.SetSize(A.Size());
1432 if ( ACoef) { ACoef->Eval(A, T, ip); }
1433 if ( BCoef) { BCoef->Eval(B, T, ip); }
1434 if (alphaCoef) { alpha = alphaCoef->Eval(T, ip); }
1435 if ( betaCoef) { beta = betaCoef->Eval(T, ip); }
1436 add(alpha, A, beta, B, V);
1437}
1438
1440 real_t A,
1442 : VectorCoefficient(B.GetVDim()), aConst(A), a(NULL), b(&B)
1443{}
1444
1450
1452{
1453 if (a) { a->SetTime(t); }
1454 if (b) { b->SetTime(t); }
1456}
1457
1459 const IntegrationPoint &ip)
1460{
1461 real_t sa = (a == NULL) ? aConst : a->Eval(T, ip);
1462 b->Eval(V, T, ip);
1463 V *= sa;
1464}
1465
1470
1472{
1473 if (a) { a->SetTime(t); }
1475}
1476
1478 const IntegrationPoint &ip)
1479{
1480 a->Eval(V, T, ip);
1481 real_t nv = V.Norml2();
1482 V *= (nv > tol) ? (1.0/nv) : 0.0;
1483}
1484
1488 : VectorCoefficient(3), a(&A), b(&B), va(A.GetVDim()), vb(B.GetVDim())
1489{
1490 MFEM_ASSERT(A.GetVDim() == 3 && B.GetVDim() == 3,
1491 "VectorCrossProductCoefficient: "
1492 "Arguments must have dimension equal to three.");
1493}
1494
1496{
1497 if (a) { a->SetTime(t); }
1498 if (b) { b->SetTime(t); }
1500}
1501
1503 const IntegrationPoint &ip)
1504{
1505 a->Eval(va, T, ip);
1506 b->Eval(vb, T, ip);
1507 V.SetSize(3);
1508 V[0] = va[1] * vb[2] - va[2] * vb[1];
1509 V[1] = va[2] * vb[0] - va[0] * vb[2];
1510 V[2] = va[0] * vb[1] - va[1] * vb[0];
1511}
1512
1515 : VectorCoefficient(A.GetHeight()), a(&A), b(&B),
1516 ma(A.GetHeight(), A.GetWidth()), vb(B.GetVDim())
1517{
1518 MFEM_ASSERT(A.GetWidth() == B.GetVDim(),
1519 "MatrixVectorProductCoefficient: "
1520 "Arguments have incompatible dimensions.");
1521}
1522
1524{
1525 if (a) { a->SetTime(t); }
1526 if (b) { b->SetTime(t); }
1528}
1529
1531 const IntegrationPoint &ip)
1532{
1533 a->Eval(ma, T, ip);
1534 b->Eval(vb, T, ip);
1535 V.SetSize(vdim);
1536 ma.Mult(vb, V);
1537}
1538
1540 const IntegrationPoint &ip)
1541{
1542 M.SetSize(dim);
1543 M = 0.0;
1544 for (int d=0; d<dim; d++) { M(d,d) = 1.0; }
1545}
1546
1549 real_t alpha_, real_t beta_)
1550 : MatrixCoefficient(A.GetHeight(), A.GetWidth()),
1551 a(&A), b(&B), alpha(alpha_), beta(beta_),
1552 ma(A.GetHeight(), A.GetWidth())
1553{
1554 MFEM_ASSERT(A.GetHeight() == B.GetHeight() && A.GetWidth() == B.GetWidth(),
1555 "MatrixSumCoefficient: "
1556 "Arguments must have the same dimensions.");
1557}
1558
1560{
1561 if (a) { a->SetTime(t); }
1562 if (b) { b->SetTime(t); }
1564}
1565
1567 const IntegrationPoint &ip)
1568{
1569 b->Eval(M, T, ip);
1570 if ( beta != 1.0 ) { M *= beta; }
1571 a->Eval(ma, T, ip);
1572 M.Add(alpha, ma);
1573}
1574
1577 : MatrixCoefficient(A.GetHeight(), B.GetWidth()),
1578 a(&A), b(&B),
1579 ma(A.GetHeight(), A.GetWidth()),
1580 mb(B.GetHeight(), B.GetWidth())
1581{
1582 MFEM_ASSERT(A.GetWidth() == B.GetHeight(),
1583 "MatrixProductCoefficient: "
1584 "Arguments must have compatible dimensions.");
1585}
1586
1588 const IntegrationPoint &ip)
1589{
1590 a->Eval(ma, T, ip);
1591 b->Eval(mb, T, ip);
1592 Mult(ma, mb, M);
1593}
1594
1596 real_t A,
1598 : MatrixCoefficient(B.GetHeight(), B.GetWidth()), aConst(A), a(NULL), b(&B)
1599{}
1600
1602 Coefficient &A,
1604 : MatrixCoefficient(B.GetHeight(), B.GetWidth()), aConst(0.0), a(&A), b(&B)
1605{}
1606
1608{
1609 if (a) { a->SetTime(t); }
1610 if (b) { b->SetTime(t); }
1612}
1613
1616 const IntegrationPoint &ip)
1617{
1618 real_t sa = (a == NULL) ? aConst : a->Eval(T, ip);
1619 b->Eval(M, T, ip);
1620 M *= sa;
1621}
1622
1626
1628{
1629 if (a) { a->SetTime(t); }
1631}
1632
1635 const IntegrationPoint &ip)
1636{
1637 a->Eval(M, T, ip);
1638 M.Transpose();
1639}
1640
1642 : MatrixCoefficient(A.GetHeight(), A.GetWidth()), a(&A)
1643{
1644 MFEM_ASSERT(A.GetHeight() == A.GetWidth(),
1645 "InverseMatrixCoefficient: "
1646 "Argument must be a square matrix.");
1647}
1648
1650{
1651 if (a) { a->SetTime(t); }
1653}
1654
1657 const IntegrationPoint &ip)
1658{
1659 a->Eval(M, T, ip);
1660 M.Invert();
1661}
1662
1664 : MatrixCoefficient(A.GetHeight(), A.GetWidth()), a(&A)
1665{
1666 MFEM_ASSERT(A.GetHeight() == A.GetWidth() && A.GetHeight() == 2,
1667 "ExponentialMatrixCoefficient: "
1668 << "Argument must be a square 2x2 matrix."
1669 << " Height = " << A.GetHeight()
1670 << ", Width = " << A.GetWidth());
1671}
1672
1674{
1675 if (a) { a->SetTime(t); }
1677}
1678
1681 const IntegrationPoint &ip)
1682{
1683 a->Eval(M, T, ip);
1684 M.Exponential();
1685}
1686
1689 : MatrixCoefficient(A.GetVDim(), B.GetVDim()), a(&A), b(&B),
1690 va(A.GetVDim()), vb(B.GetVDim())
1691{}
1692
1694{
1695 if (a) { a->SetTime(t); }
1696 if (b) { b->SetTime(t); }
1698}
1699
1701 const IntegrationPoint &ip)
1702{
1703 a->Eval(va, T, ip);
1704 b->Eval(vb, T, ip);
1705 M.SetSize(va.Size(), vb.Size());
1706 for (int i=0; i<va.Size(); i++)
1707 {
1708 for (int j=0; j<vb.Size(); j++)
1709 {
1710 M(i, j) = va[i] * vb[j];
1711 }
1712 }
1713}
1714
1716 : MatrixCoefficient(K.GetVDim(), K.GetVDim()), aConst(A), a(NULL), k(&K),
1717 vk(K.GetVDim())
1718{}
1719
1722 : MatrixCoefficient(K.GetVDim(), K.GetVDim()), aConst(0.0), a(&A), k(&K),
1723 vk(K.GetVDim())
1724{}
1725
1727{
1728 if (a) { a->SetTime(t); }
1729 if (k) { k->SetTime(t); }
1731}
1732
1734 const IntegrationPoint &ip)
1735{
1736 k->Eval(vk, T, ip);
1737 M.SetSize(vk.Size(), vk.Size());
1738 M = 0.0;
1739 real_t k2 = vk*vk;
1740 for (int i=0; i<vk.Size(); i++)
1741 {
1742 M(i, i) = k2;
1743 for (int j=0; j<vk.Size(); j++)
1744 {
1745 M(i, j) -= vk[i] * vk[j];
1746 }
1747 }
1748 M *= ((a == NULL ) ? aConst : a->Eval(T, ip) );
1749}
1750
1752 const IntegrationRule *irs[])
1753{
1754 real_t norm = 0.0;
1756
1757 for (int i = 0; i < mesh.GetNE(); i++)
1758 {
1759 tr = mesh.GetElementTransformation(i);
1760 const IntegrationRule &ir = *irs[mesh.GetElementType(i)];
1761 for (int j = 0; j < ir.GetNPoints(); j++)
1762 {
1763 const IntegrationPoint &ip = ir.IntPoint(j);
1764 tr->SetIntPoint(&ip);
1765 real_t val = fabs(coeff.Eval(*tr, ip));
1766 if (p < infinity())
1767 {
1768 norm += ip.weight * tr->Weight() * pow(val, p);
1769 }
1770 else
1771 {
1772 if (norm < val)
1773 {
1774 norm = val;
1775 }
1776 }
1777 }
1778 }
1779 return norm;
1780}
1781
1783 const IntegrationRule *irs[])
1784{
1785 real_t norm = 0.0;
1787 int vdim = coeff.GetVDim();
1788 Vector vval(vdim);
1789 real_t val;
1790
1791 for (int i = 0; i < mesh.GetNE(); i++)
1792 {
1793 tr = mesh.GetElementTransformation(i);
1794 const IntegrationRule &ir = *irs[mesh.GetElementType(i)];
1795 for (int j = 0; j < ir.GetNPoints(); j++)
1796 {
1797 const IntegrationPoint &ip = ir.IntPoint(j);
1798 tr->SetIntPoint(&ip);
1799 coeff.Eval(vval, *tr, ip);
1800 if (p < infinity())
1801 {
1802 for (int idim(0); idim < vdim; ++idim)
1803 {
1804 norm += ip.weight * tr->Weight() * pow(fabs( vval(idim) ), p);
1805 }
1806 }
1807 else
1808 {
1809 for (int idim(0); idim < vdim; ++idim)
1810 {
1811 val = fabs(vval(idim));
1812 if (norm < val)
1813 {
1814 norm = val;
1815 }
1816 }
1817 }
1818 }
1819 }
1820
1821 return norm;
1822}
1823
1825 const IntegrationRule *irs[])
1826{
1827 real_t norm = LpNormLoop(p, coeff, mesh, irs);
1828
1829 if (p < infinity())
1830 {
1831 // negative quadrature weights may cause norm to be negative
1832 if (norm < 0.0)
1833 {
1834 norm = -pow(-norm, 1.0/p);
1835 }
1836 else
1837 {
1838 norm = pow(norm, 1.0/p);
1839 }
1840 }
1841
1842 return norm;
1843}
1844
1846 const IntegrationRule *irs[])
1847{
1848 real_t norm = LpNormLoop(p, coeff, mesh, irs);
1849
1850 if (p < infinity())
1851 {
1852 // negative quadrature weights may cause norm to be negative
1853 if (norm < 0.0)
1854 {
1855 norm = -pow(-norm, 1.0/p);
1856 }
1857 else
1858 {
1859 norm = pow(norm, 1.0/p);
1860 }
1861 }
1862
1863 return norm;
1864}
1865
1866#ifdef MFEM_USE_MPI
1868 const IntegrationRule *irs[])
1869{
1870 real_t loc_norm = LpNormLoop(p, coeff, pmesh, irs);
1871 real_t glob_norm = 0;
1872
1873 MPI_Comm comm = pmesh.GetComm();
1874
1875 if (p < infinity())
1876 {
1877 MPI_Allreduce(&loc_norm, &glob_norm, 1, MPITypeMap<real_t>::mpi_type, MPI_SUM,
1878 comm);
1879
1880 // negative quadrature weights may cause norm to be negative
1881 if (glob_norm < 0.0)
1882 {
1883 glob_norm = -pow(-glob_norm, 1.0/p);
1884 }
1885 else
1886 {
1887 glob_norm = pow(glob_norm, 1.0/p);
1888 }
1889 }
1890 else
1891 {
1892 MPI_Allreduce(&loc_norm, &glob_norm, 1, MPITypeMap<real_t>::mpi_type, MPI_MAX,
1893 comm);
1894 }
1895
1896 return glob_norm;
1897}
1898
1900 const IntegrationRule *irs[])
1901{
1902 real_t loc_norm = LpNormLoop(p, coeff, pmesh, irs);
1903 real_t glob_norm = 0;
1904
1905 MPI_Comm comm = pmesh.GetComm();
1906
1907 if (p < infinity())
1908 {
1909 MPI_Allreduce(&loc_norm, &glob_norm, 1, MPITypeMap<real_t>::mpi_type, MPI_SUM,
1910 comm);
1911
1912 // negative quadrature weights may cause norm to be negative
1913 if (glob_norm < 0.0)
1914 {
1915 glob_norm = -pow(-glob_norm, 1.0/p);
1916 }
1917 else
1918 {
1919 glob_norm = pow(glob_norm, 1.0/p);
1920 }
1921 }
1922 else
1923 {
1924 MPI_Allreduce(&loc_norm, &glob_norm, 1, MPITypeMap<real_t>::mpi_type, MPI_MAX,
1925 comm);
1926 }
1927
1928 return glob_norm;
1929}
1930#endif
1931
1935
1937{
1938 MFEM_VERIFY(index_ >= 0, "Index must be >= 0");
1939 MFEM_VERIFY(index_ < QuadF.GetVDim(),
1940 "Index must be < QuadratureFunction length");
1941 index = index_;
1942
1943 MFEM_VERIFY(length_ > 0, "Length must be > 0");
1944 MFEM_VERIFY(length_ <= QuadF.GetVDim() - index,
1945 "Length must be <= (QuadratureFunction length - index)");
1946
1947 vdim = length_;
1948}
1949
1952 const IntegrationPoint &ip)
1953{
1954 QuadF.HostRead();
1955
1956 const int el_idx = QuadF.GetSpace()->GetEntityIndex(T);
1957 // Handle the case of "interior boundary elements" and FaceQuadratureSpace
1958 // with FaceType::Boundary.
1959 if (el_idx < 0) { V = 0.0; return; }
1960
1961 const int ip_idx = QuadF.GetSpace()->GetPermutedIndex(el_idx, ip.index);
1962
1963 if (index == 0 && vdim == QuadF.GetVDim())
1964 {
1965 QuadF.GetValues(el_idx, ip_idx, V);
1966 }
1967 else
1968 {
1969 Vector temp;
1970 QuadF.GetValues(el_idx, ip_idx, temp);
1971 V.SetSize(vdim);
1972 for (int i = 0; i < vdim; i++)
1973 {
1974 V(i) = temp(index + i);
1975 }
1976 }
1977
1978 return;
1979}
1980
1985
1987 const QuadratureFunction &qf) : QuadF(qf)
1988{
1989 MFEM_VERIFY(qf.GetVDim() == 1, "QuadratureFunction's vdim must be 1");
1990}
1991
1993 const IntegrationPoint &ip)
1994{
1995 QuadF.HostRead();
1996 Vector temp(1);
1997 const int el_idx = QuadF.GetSpace()->GetEntityIndex(T);
1998 // Handle the case of "interior boundary elements" and FaceQuadratureSpace
1999 // with FaceType::Boundary.
2000 if (el_idx < 0) { return 0.0; }
2001 const int ip_idx = QuadF.GetSpace()->GetPermutedIndex(el_idx, ip.index);
2002 QuadF.GetValues(el_idx, ip_idx, temp);
2003 return temp[0];
2004}
2005
2007{
2008 qf = QuadF;
2009}
2010
2011
2014 : Vector(), storage(storage_), vdim(0), qs(qs_), qf(NULL)
2015{
2016 UseDevice(true);
2017}
2018
2021 CoefficientStorage storage_)
2022 : CoefficientVector(qs_, storage_)
2023{
2024 if (coeff == NULL)
2025 {
2026 SetConstant(1.0);
2027 }
2028 else
2029 {
2030 Project(*coeff);
2031 }
2032}
2033
2036 CoefficientStorage storage_)
2037 : CoefficientVector(qs_, storage_)
2038{
2039 Project(coeff);
2040}
2041
2044 CoefficientStorage storage_)
2045 : CoefficientVector(qs_, storage_)
2046{
2047 Project(coeff);
2048}
2049
2052 CoefficientStorage storage_)
2053 : CoefficientVector(qs_, storage_)
2054{
2055 Project(coeff);
2056}
2057
2059{
2060 vdim = 1;
2061 if (auto *const_coeff = dynamic_cast<ConstantCoefficient*>(&coeff))
2062 {
2063 SetConstant(const_coeff->constant);
2064 }
2065 else if (auto *qf_coeff = dynamic_cast<QuadratureFunctionCoefficient*>(&coeff))
2066 {
2067 MakeRef(qf_coeff->GetQuadFunction());
2068 }
2069 else
2070 {
2071 if (qf == nullptr) { qf = new QuadratureFunction(qs); }
2072 qf->SetVDim(1);
2073 coeff.Project(*qf);
2074 Vector::MakeRef(*qf, 0, qf->Size());
2075 }
2076}
2077
2079{
2080 vdim = coeff.GetVDim();
2081 if (auto *const_coeff = dynamic_cast<VectorConstantCoefficient*>(&coeff))
2082 {
2083 SetConstant(const_coeff->GetVec());
2084 }
2085 else if (auto *qf_coeff =
2086 dynamic_cast<VectorQuadratureFunctionCoefficient*>(&coeff))
2087 {
2088 MakeRef(qf_coeff->GetQuadFunction());
2089 }
2090 else
2091 {
2092 if (qf == nullptr) { qf = new QuadratureFunction(qs, vdim); }
2093 qf->SetVDim(vdim);
2094 coeff.Project(*qf);
2095 Vector::MakeRef(*qf, 0, qf->Size());
2096 }
2097}
2098
2100{
2101 if (auto *const_coeff = dynamic_cast<MatrixConstantCoefficient*>(&coeff))
2102 {
2103 SetConstant(const_coeff->GetMatrix(), transpose);
2104 }
2105 else if (auto *const_sym_coeff =
2106 dynamic_cast<SymmetricMatrixConstantCoefficient*>(&coeff))
2107 {
2108 SetConstant(const_sym_coeff->GetMatrix());
2109 }
2110 else
2111 {
2112 auto *sym_coeff = dynamic_cast<SymmetricMatrixCoefficient*>(&coeff);
2113 const bool sym = sym_coeff && (storage & CoefficientStorage::SYMMETRIC);
2114 const int height = coeff.GetHeight();
2115 const int width = coeff.GetWidth();
2116 vdim = sym ? height*(height + 1)/2 : width*height;
2117
2118 if (qf == nullptr) { qf = new QuadratureFunction(qs, vdim); }
2119 qf->SetVDim(vdim);
2120 if (sym) { sym_coeff->ProjectSymmetric(*qf); }
2121 else { coeff.Project(*qf, transpose); }
2122 Vector::MakeRef(*qf, 0, qf->Size());
2123 }
2124}
2125
2127{
2128 Project(coeff, true);
2129}
2130
2132{
2133 vdim = qf_.GetVDim();
2134 const QuadratureSpaceBase *qs2 = qf_.GetSpace();
2135 MFEM_CONTRACT_VAR(qs2); // qs2 used only for asserts
2136 MFEM_VERIFY(qs2 != NULL, "Invalid QuadratureSpace.")
2137 MFEM_VERIFY(qs2->GetMesh() == qs.GetMesh(), "Meshes differ.");
2138 MFEM_VERIFY(qs2->GetOrder() == qs.GetOrder(), "Orders differ.");
2139 Vector::MakeRef(const_cast<QuadratureFunction&>(qf_), 0, qf_.Size());
2140}
2141
2143{
2144 const int nq = (storage & CoefficientStorage::CONSTANTS) ? 1 : qs.GetSize();
2145 vdim = 1;
2146 SetSize(nq);
2147 Vector::operator=(constant);
2148}
2149
2151{
2152 const int nq = (storage & CoefficientStorage::CONSTANTS) ? 1 : qs.GetSize();
2153 vdim = constant.Size();
2154 SetSize(nq*vdim);
2155 for (int iq = 0; iq < nq; ++iq)
2156 {
2157 for (int vd = 0; vd<vdim; ++vd)
2158 {
2159 (*this)[vd + iq*vdim] = constant[vd];
2160 }
2161 }
2162}
2163
2164void CoefficientVector::SetConstant(const DenseMatrix &constant, bool transpose)
2165{
2166 const int nq = (storage & CoefficientStorage::CONSTANTS) ? 1 : qs.GetSize();
2167 const int width = constant.Width();
2168 const int height = constant.Height();
2169 vdim = width*height;
2170 SetSize(nq*vdim);
2171 for (int iq = 0; iq < nq; ++iq)
2172 {
2173 for (int j = 0; j < width; ++j)
2174 {
2175 for (int i = 0; i < height; ++i)
2176 {
2177 const real_t val = transpose ? constant(j,i) : constant(i,j);
2178 (*this)[i + j*height + iq*vdim] = val;
2179 }
2180 }
2181 }
2182}
2183
2185{
2186 const int nq = (storage & CoefficientStorage::CONSTANTS) ? 1 : qs.GetSize();
2187 const int height = constant.Height();
2188 const bool sym = storage & CoefficientStorage::SYMMETRIC;
2189 vdim = sym ? height*(height + 1)/2 : height*height;
2190 SetSize(nq*vdim);
2191 for (int iq = 0; iq < nq; ++iq)
2192 {
2193 for (int vd = 0; vd < vdim; ++vd)
2194 {
2195 const real_t value = sym ? constant.GetData()[vd] : constant(vd % height,
2196 vd / height);
2197 (*this)[vd + iq*vdim] = value;
2198 }
2199 }
2200}
2201
2202int CoefficientVector::GetVDim() const { return vdim; }
2203
2208
2209}
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition array.hpp:869
int Size() const
Return the logical size of the array.
Definition array.hpp:192
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.
int GetVDim()
Returns dimension of the vector.
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:340
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Definition densemat.hpp:125
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:97
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:210
Mesh * GetMesh() const
Returns the mesh.
Definition fespace.hpp:639
int GetVDim() const
Returns the vector dimension of the finite element space.
Definition fespace.hpp:817
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:53
virtual real_t GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition gridfunc.cpp:429
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:454
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:687
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:96
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition intrules.hpp:255
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Definition intrules.hpp:258
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 this will take ownership of the Coeffi...
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...
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.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the component coefficient at ip.
void SetRowIndex(int ri)
Reset the index.
void SetColumnIndex(int ci)
Reset the index.
MatrixComponentCoefficient(MatrixCoefficient &A)
Construct with a matrix coefficient.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
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:67
Element::Type GetElementType(int i) const
Returns the type of element i.
Definition mesh.cpp:8445
const CoarseFineTransformations & GetRefinementTransforms() const
Definition mesh.cpp:12237
int GetNE() const
Returns number of elements.
Definition mesh.hpp:1390
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1314
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:361
int SpaceDimension() const
Dimension of the physical space containing the mesh.
Definition mesh.hpp:1317
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
Definition mesh.cpp:8014
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:68
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
Definition operator.hpp:74
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:35
MPI_Comm GetComm() const
Definition pmesh.hpp:403
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.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the component coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
VectorComponentCoefficient(VectorCoefficient &A)
Construct with a vector coefficient.
void SetComponent(int c)
Set the component.
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:633
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:709
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
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:1134
constexpr real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
Definition vector.hpp:47
ElementTransformation * RefinedToCoarse(Mesh &coarse_mesh, const ElementTransformation &T, const IntegrationPoint &ip, IntegrationPoint &coarse_ip)
STL namespace.
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.