MFEM  v4.3.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
coefficient.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2021, 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 
16 #include <cmath>
17 #include <limits>
18 
19 namespace mfem
20 {
21 
22 using namespace std;
23 
25  const IntegrationPoint & ip)
26 {
27  int att = T.Attribute;
28  return (constants(att-1));
29 }
30 
32  const IntegrationPoint & ip)
33 {
34  double x[3];
35  Vector transip(x, 3);
36 
37  T.Transform(ip, transip);
38 
39  if (Function)
40  {
41  return Function(transip);
42  }
43  else
44  {
45  return TDFunction(transip, GetTime());
46  }
47 }
48 
50  const IntegrationPoint &ip)
51 {
52  return GridF -> GetValue (T, ip, Component);
53 }
54 
56  const IntegrationPoint &ip)
57 {
58  if (Q2)
59  {
60  return (*Transform2)(Q1->Eval(T, ip, GetTime()),
61  Q2->Eval(T, ip, GetTime()));
62  }
63  else
64  {
65  return (*Transform1)(Q1->Eval(T, ip, GetTime()));
66  }
67 }
68 
70 {
71  MFEM_VERIFY(vcenter.Size() <= 3,
72  "SetDeltaCenter::Maximum number of dim supported is 3")
73  for (int i = 0; i < vcenter.Size(); i++) { center[i] = vcenter[i]; }
74  sdim = vcenter.Size();
75 }
76 
78 {
79  vcenter.SetSize(sdim);
80  vcenter = center;
81 }
82 
84  const IntegrationPoint &ip)
85 {
86  double w = Scale();
87  return weight ? weight->Eval(T, ip, GetTime())*w : w;
88 }
89 
91  const IntegrationRule &ir)
92 {
93  Vector Mi;
94  M.SetSize(vdim, ir.GetNPoints());
95  for (int i = 0; i < ir.GetNPoints(); i++)
96  {
97  M.GetColumnReference(i, Mi);
98  const IntegrationPoint &ip = ir.IntPoint(i);
99  T.SetIntPoint(&ip);
100  Eval(Mi, T, ip);
101  }
102 }
103 
105  const IntegrationPoint &ip)
106 {
107  double x[3];
108  Vector transip(x, 3);
109 
110  T.Transform(ip, transip);
111 
112  V.SetSize(vdim);
113  if (Function)
114  {
115  Function(transip, V);
116  }
117  else
118  {
119  TDFunction(transip, GetTime(), V);
120  }
121  if (Q)
122  {
123  V *= Q->Eval(T, ip, GetTime());
124  }
125 }
126 
128  : VectorCoefficient(dim), Coeff(dim), ownCoeff(dim)
129 {
130  for (int i = 0; i < dim; i++)
131  {
132  Coeff[i] = NULL;
133  ownCoeff[i] = true;
134  }
135 }
136 
137 void VectorArrayCoefficient::Set(int i, Coefficient *c, bool own)
138 {
139  if (ownCoeff[i]) { delete Coeff[i]; }
140  Coeff[i] = c;
141  ownCoeff[i] = own;
142 }
143 
145 {
146  for (int i = 0; i < vdim; i++)
147  {
148  if (ownCoeff[i]) { delete Coeff[i]; }
149  }
150 }
151 
153  const IntegrationPoint &ip)
154 {
155  V.SetSize(vdim);
156  for (int i = 0; i < vdim; i++)
157  {
158  V(i) = this->Eval(i, T, ip);
159  }
160 }
161 
163  const GridFunction *gf)
164  : VectorCoefficient ((gf) ? gf -> VectorDim() : 0)
165 {
166  GridFunc = gf;
167 }
168 
170 {
171  GridFunc = gf; vdim = (gf) ? gf -> VectorDim() : 0;
172 }
173 
175  const IntegrationPoint &ip)
176 {
177  GridFunc->GetVectorValue(T, ip, V);
178 }
179 
182 {
183  GridFunc->GetVectorValues(T, ir, M);
184 }
185 
187  const GridFunction *gf)
188  : VectorCoefficient((gf) ?
189  gf -> FESpace() -> GetMesh() -> SpaceDimension() : 0)
190 {
191  GridFunc = gf;
192 }
193 
195 {
196  GridFunc = gf; vdim = (gf) ?
197  gf -> FESpace() -> GetMesh() -> SpaceDimension() : 0;
198 }
199 
201  const IntegrationPoint &ip)
202 {
203  GridFunc->GetGradient(T, V);
204 }
205 
208 {
209  GridFunc->GetGradients(T, ir, M);
210 }
211 
213  const GridFunction *gf)
214  : VectorCoefficient(0)
215 {
216  SetGridFunction(gf);
217 }
218 
220 {
221  if (gf)
222  {
223  int sdim = gf -> FESpace() -> GetMesh() -> SpaceDimension();
224  MFEM_VERIFY(sdim == 2 || sdim == 3,
225  "CurlGridFunctionCoefficient "
226  "only defind for spaces of dimension 2 or 3.");
227  }
228  GridFunc = gf;
229  vdim = (gf) ? (2 * gf -> FESpace() -> GetMesh() -> SpaceDimension() - 3) : 0;
230 }
231 
233  const IntegrationPoint &ip)
234 {
235  GridFunc->GetCurl(T, V);
236 }
237 
239  const GridFunction *gf) : Coefficient()
240 {
241  GridFunc = gf;
242 }
243 
245  const IntegrationPoint &ip)
246 {
247  return GridFunc->GetDivergence(T);
248 }
249 
251 {
252  dir = d_;
253  (*this).vdim = dir.Size();
254 }
255 
258 {
259  V = dir;
260  d.SetTime(GetTime());
261  V *= d.EvalDelta(T, ip);
262 }
263 
265  const IntegrationPoint &ip)
266 {
267  V.SetSize(vdim);
268  if (active_attr[T.Attribute-1])
269  {
270  c->SetTime(GetTime());
271  c->Eval(V, T, ip);
272  }
273  else
274  {
275  V = 0.0;
276  }
277 }
278 
281 {
282  if (active_attr[T.Attribute-1])
283  {
284  c->SetTime(GetTime());
285  c->Eval(M, T, ir);
286  }
287  else
288  {
289  M.SetSize(vdim, ir.GetNPoints());
290  M = 0.0;
291  }
292 }
293 
295  const IntegrationPoint &ip)
296 {
297  double x[3];
298  Vector transip(x, 3);
299 
300  T.Transform(ip, transip);
301 
302  K.SetSize(height, width);
303 
304  if (symmetric) // Use SymmFunction (deprecated version)
305  {
306  MFEM_VERIFY(height == width && SymmFunction,
307  "MatrixFunctionCoefficient is not symmetric");
308 
309  Vector Ksym((width * (width + 1)) / 2); // 1x1: 1, 2x2: 3, 3x3: 6
310 
311  SymmFunction(transip, Ksym);
312 
313  // Copy upper triangular values from Ksym to the full matrix K
314  int os = 0;
315  for (int i=0; i<height; ++i)
316  {
317  for (int j=i; j<width; ++j)
318  {
319  const double Kij = Ksym[j - i + os];
320  K(i,j) = Kij;
321  if (j != i) { K(j,i) = Kij; }
322  }
323 
324  os += width - i;
325  }
326  }
327  else
328  {
329  if (Function)
330  {
331  Function(transip, K);
332  }
333  else if (TDFunction)
334  {
335  TDFunction(transip, GetTime(), K);
336  }
337  else
338  {
339  K = mat;
340  }
341  }
342 
343  if (Q)
344  {
345  K *= Q->Eval(T, ip, GetTime());
346  }
347 }
348 
351  const IntegrationPoint &ip)
352 {
353  MFEM_VERIFY(symmetric && height == width && SymmFunction,
354  "MatrixFunctionCoefficient is not symmetric");
355 
356  double x[3];
357  Vector transip(x, 3);
358 
359  T.Transform(ip, transip);
360 
361  K.SetSize((width * (width + 1)) / 2); // 1x1: 1, 2x2: 3, 3x3: 6
362 
363  if (SymmFunction)
364  {
365  SymmFunction(transip, K);
366  }
367 
368  if (Q)
369  {
370  K *= Q->Eval(T, ip, GetTime());
371  }
372 }
373 
376  const IntegrationPoint &ip)
377 {
378  double x[3];
379  Vector transip(x, 3);
380 
381  T.Transform(ip, transip);
382 
383  K.SetSize(dim);
384 
385  if (Function)
386  {
387  Function(transip, K);
388  }
389  else if (TDFunction)
390  {
391  TDFunction(transip, GetTime(), K);
392  }
393  else
394  {
395  K = mat;
396  }
397 
398  if (Q)
399  {
400  K *= Q->Eval(T, ip, GetTime());
401  }
402 }
403 
405  : MatrixCoefficient (dim)
406 {
407  Coeff.SetSize(height*width);
408  ownCoeff.SetSize(height*width);
409  for (int i = 0; i < (height*width); i++)
410  {
411  Coeff[i] = NULL;
412  ownCoeff[i] = true;
413  }
414 }
415 
416 void MatrixArrayCoefficient::Set(int i, int j, Coefficient * c, bool own)
417 {
418  if (ownCoeff[i*width+j]) { delete Coeff[i*width+j]; }
419  Coeff[i*width+j] = c;
420  ownCoeff[i*width+j] = own;
421 }
422 
424 {
425  for (int i=0; i < height*width; i++)
426  {
427  if (ownCoeff[i]) { delete Coeff[i]; }
428  }
429 }
430 
432  const IntegrationPoint &ip)
433 {
434  for (int i = 0; i < height; i++)
435  {
436  for (int j = 0; j < width; j++)
437  {
438  K(i,j) = this->Eval(i, j, T, ip);
439  }
440  }
441 }
442 
444  const IntegrationPoint &ip)
445 {
446  if (active_attr[T.Attribute-1])
447  {
448  c->SetTime(GetTime());
449  c->Eval(K, T, ip);
450  }
451  else
452  {
453  K.SetSize(height, width);
454  K = 0.0;
455  }
456 }
457 
460  : a(&A), b(&B)
461 {
462  MFEM_ASSERT(A.GetVDim() == B.GetVDim(),
463  "InnerProductCoefficient: "
464  "Arguments have incompatible dimensions.");
465 }
466 
468  const IntegrationPoint &ip)
469 {
470  a->Eval(va, T, ip);
471  b->Eval(vb, T, ip);
472  return va * vb;
473 }
474 
477  : a(&A), b(&B), va(A.GetVDim()), vb(B.GetVDim())
478 {
479  MFEM_ASSERT(A.GetVDim() == 2 && B.GetVDim() == 2,
480  "VectorRotProductCoefficient: "
481  "Arguments must have dimension equal to two.");
482 }
483 
485  const IntegrationPoint &ip)
486 {
487  a->Eval(va, T, ip);
488  b->Eval(vb, T, ip);
489  return va[0] * vb[1] - va[1] * vb[0];
490 }
491 
493  : a(&A), ma(A.GetHeight(), A.GetWidth())
494 {
495  MFEM_ASSERT(A.GetHeight() == A.GetWidth(),
496  "DeterminantCoefficient: "
497  "Argument must be a square matrix.");
498 }
499 
501  const IntegrationPoint &ip)
502 {
503  a->Eval(ma, T, ip);
504  return ma.Det();
505 }
506 
508  : VectorCoefficient(dim),
509  ACoef(NULL), BCoef(NULL),
510  A(dim), B(dim),
511  alphaCoef(NULL), betaCoef(NULL),
512  alpha(1.0), beta(1.0)
513 {
514  A = 0.0; B = 0.0;
515 }
516 
518  VectorCoefficient &B_,
519  double alpha_, double beta_)
520  : VectorCoefficient(A_.GetVDim()),
521  ACoef(&A_), BCoef(&B_),
522  A(A_.GetVDim()), B(A_.GetVDim()),
523  alphaCoef(NULL), betaCoef(NULL),
524  alpha(alpha_), beta(beta_)
525 {
526  MFEM_ASSERT(A_.GetVDim() == B_.GetVDim(),
527  "VectorSumCoefficient: "
528  "Arguments must have the same dimension.");
529 }
530 
532  VectorCoefficient &B_,
533  Coefficient &alpha_,
534  Coefficient &beta_)
535  : VectorCoefficient(A_.GetVDim()),
536  ACoef(&A_), BCoef(&B_),
537  A(A_.GetVDim()),
538  B(A_.GetVDim()),
539  alphaCoef(&alpha_),
540  betaCoef(&beta_),
541  alpha(0.0), beta(0.0)
542 {
543  MFEM_ASSERT(A_.GetVDim() == B_.GetVDim(),
544  "VectorSumCoefficient: "
545  "Arguments must have the same dimension.");
546 }
547 
549  const IntegrationPoint &ip)
550 {
551  V.SetSize(A.Size());
552  if ( ACoef) { ACoef->Eval(A, T, ip); }
553  if ( BCoef) { BCoef->Eval(B, T, ip); }
554  if (alphaCoef) { alpha = alphaCoef->Eval(T, ip); }
555  if ( betaCoef) { beta = betaCoef->Eval(T, ip); }
556  add(alpha, A, beta, B, V);
557 }
558 
560  double A,
562  : VectorCoefficient(B.GetVDim()), aConst(A), a(NULL), b(&B)
563 {}
564 
566  Coefficient &A,
568  : VectorCoefficient(B.GetVDim()), aConst(0.0), a(&A), b(&B)
569 {}
570 
572  const IntegrationPoint &ip)
573 {
574  double sa = (a == NULL) ? aConst : a->Eval(T, ip);
575  b->Eval(V, T, ip);
576  V *= sa;
577 }
578 
580  double tol_)
581  : VectorCoefficient(A.GetVDim()), a(&A), tol(tol_)
582 {}
583 
585  const IntegrationPoint &ip)
586 {
587  a->Eval(V, T, ip);
588  double nv = V.Norml2();
589  V *= (nv > tol) ? (1.0/nv) : 0.0;
590 }
591 
595  : VectorCoefficient(3), a(&A), b(&B), va(A.GetVDim()), vb(B.GetVDim())
596 {
597  MFEM_ASSERT(A.GetVDim() == 3 && B.GetVDim() == 3,
598  "VectorCrossProductCoefficient: "
599  "Arguments must have dimension equal to three.");
600 }
601 
603  const IntegrationPoint &ip)
604 {
605  a->Eval(va, T, ip);
606  b->Eval(vb, T, ip);
607  V.SetSize(3);
608  V[0] = va[1] * vb[2] - va[2] * vb[1];
609  V[1] = va[2] * vb[0] - va[0] * vb[2];
610  V[2] = va[0] * vb[1] - va[1] * vb[0];
611 }
612 
615  : VectorCoefficient(A.GetHeight()), a(&A), b(&B),
616  ma(A.GetHeight(), A.GetWidth()), vb(B.GetVDim())
617 {
618  MFEM_ASSERT(A.GetWidth() == B.GetVDim(),
619  "MatrixVectorProductCoefficient: "
620  "Arguments have incompatible dimensions.");
621 }
622 
624  const IntegrationPoint &ip)
625 {
626  a->Eval(ma, T, ip);
627  b->Eval(vb, T, ip);
628  V.SetSize(vdim);
629  ma.Mult(vb, V);
630 }
631 
633  const IntegrationPoint &ip)
634 {
635  M.SetSize(dim);
636  M = 0.0;
637  for (int d=0; d<dim; d++) { M(d,d) = 1.0; }
638 }
639 
642  double alpha_, double beta_)
643  : MatrixCoefficient(A.GetHeight(), A.GetWidth()),
644  a(&A), b(&B), alpha(alpha_), beta(beta_),
645  ma(A.GetHeight(), A.GetWidth())
646 {
647  MFEM_ASSERT(A.GetHeight() == B.GetHeight() && A.GetWidth() == B.GetWidth(),
648  "MatrixSumCoefficient: "
649  "Arguments must have the same dimensions.");
650 }
651 
653  const IntegrationPoint &ip)
654 {
655  b->Eval(M, T, ip);
656  if ( beta != 1.0 ) { M *= beta; }
657  a->Eval(ma, T, ip);
658  M.Add(alpha, ma);
659 }
660 
662  double A,
664  : MatrixCoefficient(B.GetHeight(), B.GetWidth()), aConst(A), a(NULL), b(&B)
665 {}
666 
668  Coefficient &A,
670  : MatrixCoefficient(B.GetHeight(), B.GetWidth()), aConst(0.0), a(&A), b(&B)
671 {}
672 
675  const IntegrationPoint &ip)
676 {
677  double sa = (a == NULL) ? aConst : a->Eval(T, ip);
678  b->Eval(M, T, ip);
679  M *= sa;
680 }
681 
683  : MatrixCoefficient(A.GetWidth(), A.GetHeight()), a(&A)
684 {}
685 
688  const IntegrationPoint &ip)
689 {
690  a->Eval(M, T, ip);
691  M.Transpose();
692 }
693 
695  : MatrixCoefficient(A.GetHeight(), A.GetWidth()), a(&A)
696 {
697  MFEM_ASSERT(A.GetHeight() == A.GetWidth(),
698  "InverseMatrixCoefficient: "
699  "Argument must be a square matrix.");
700 }
701 
704  const IntegrationPoint &ip)
705 {
706  a->Eval(M, T, ip);
707  M.Invert();
708 }
709 
712  : MatrixCoefficient(A.GetVDim(), B.GetVDim()), a(&A), b(&B),
713  va(A.GetVDim()), vb(B.GetVDim())
714 {}
715 
717  const IntegrationPoint &ip)
718 {
719  a->Eval(va, T, ip);
720  b->Eval(vb, T, ip);
721  M.SetSize(va.Size(), vb.Size());
722  for (int i=0; i<va.Size(); i++)
723  {
724  for (int j=0; j<vb.Size(); j++)
725  {
726  M(i, j) = va[i] * vb[j];
727  }
728  }
729 }
730 
732  : MatrixCoefficient(K.GetVDim(), K.GetVDim()), aConst(A), a(NULL), k(&K),
733  vk(K.GetVDim())
734 {}
735 
738  : MatrixCoefficient(K.GetVDim(), K.GetVDim()), aConst(0.0), a(&A), k(&K),
739  vk(K.GetVDim())
740 {}
741 
743  const IntegrationPoint &ip)
744 {
745  k->Eval(vk, T, ip);
746  M.SetSize(vk.Size(), vk.Size());
747  M = 0.0;
748  double k2 = vk*vk;
749  for (int i=0; i<vk.Size(); i++)
750  {
751  M(i, i) = k2;
752  for (int j=0; j<vk.Size(); j++)
753  {
754  M(i, j) -= vk[i] * vk[j];
755  }
756  }
757  M *= ((a == NULL ) ? aConst : a->Eval(T, ip) );
758 }
759 
760 double LpNormLoop(double p, Coefficient &coeff, Mesh &mesh,
761  const IntegrationRule *irs[])
762 {
763  double norm = 0.0;
765 
766  for (int i = 0; i < mesh.GetNE(); i++)
767  {
768  tr = mesh.GetElementTransformation(i);
769  const IntegrationRule &ir = *irs[mesh.GetElementType(i)];
770  for (int j = 0; j < ir.GetNPoints(); j++)
771  {
772  const IntegrationPoint &ip = ir.IntPoint(j);
773  tr->SetIntPoint(&ip);
774  double val = fabs(coeff.Eval(*tr, ip));
775  if (p < infinity())
776  {
777  norm += ip.weight * tr->Weight() * pow(val, p);
778  }
779  else
780  {
781  if (norm < val)
782  {
783  norm = val;
784  }
785  }
786  }
787  }
788  return norm;
789 }
790 
791 double LpNormLoop(double p, VectorCoefficient &coeff, Mesh &mesh,
792  const IntegrationRule *irs[])
793 {
794  double norm = 0.0;
796  int vdim = coeff.GetVDim();
797  Vector vval(vdim);
798  double val;
799 
800  for (int i = 0; i < mesh.GetNE(); i++)
801  {
802  tr = mesh.GetElementTransformation(i);
803  const IntegrationRule &ir = *irs[mesh.GetElementType(i)];
804  for (int j = 0; j < ir.GetNPoints(); j++)
805  {
806  const IntegrationPoint &ip = ir.IntPoint(j);
807  tr->SetIntPoint(&ip);
808  coeff.Eval(vval, *tr, ip);
809  if (p < infinity())
810  {
811  for (int idim(0); idim < vdim; ++idim)
812  {
813  norm += ip.weight * tr->Weight() * pow(fabs( vval(idim) ), p);
814  }
815  }
816  else
817  {
818  for (int idim(0); idim < vdim; ++idim)
819  {
820  val = fabs(vval(idim));
821  if (norm < val)
822  {
823  norm = val;
824  }
825  }
826  }
827  }
828  }
829 
830  return norm;
831 }
832 
833 double ComputeLpNorm(double p, Coefficient &coeff, Mesh &mesh,
834  const IntegrationRule *irs[])
835 {
836  double norm = LpNormLoop(p, coeff, mesh, irs);
837 
838  if (p < infinity())
839  {
840  // negative quadrature weights may cause norm to be negative
841  if (norm < 0.0)
842  {
843  norm = -pow(-norm, 1.0/p);
844  }
845  else
846  {
847  norm = pow(norm, 1.0/p);
848  }
849  }
850 
851  return norm;
852 }
853 
854 double ComputeLpNorm(double p, VectorCoefficient &coeff, Mesh &mesh,
855  const IntegrationRule *irs[])
856 {
857  double norm = LpNormLoop(p, coeff, mesh, irs);
858 
859  if (p < infinity())
860  {
861  // negative quadrature weights may cause norm to be negative
862  if (norm < 0.0)
863  {
864  norm = -pow(-norm, 1.0/p);
865  }
866  else
867  {
868  norm = pow(norm, 1.0/p);
869  }
870  }
871 
872  return norm;
873 }
874 
875 #ifdef MFEM_USE_MPI
876 double ComputeGlobalLpNorm(double p, Coefficient &coeff, ParMesh &pmesh,
877  const IntegrationRule *irs[])
878 {
879  double loc_norm = LpNormLoop(p, coeff, pmesh, irs);
880  double glob_norm = 0;
881 
882  MPI_Comm comm = pmesh.GetComm();
883 
884  if (p < infinity())
885  {
886  MPI_Allreduce(&loc_norm, &glob_norm, 1, MPI_DOUBLE, MPI_SUM, comm);
887 
888  // negative quadrature weights may cause norm to be negative
889  if (glob_norm < 0.0)
890  {
891  glob_norm = -pow(-glob_norm, 1.0/p);
892  }
893  else
894  {
895  glob_norm = pow(glob_norm, 1.0/p);
896  }
897  }
898  else
899  {
900  MPI_Allreduce(&loc_norm, &glob_norm, 1, MPI_DOUBLE, MPI_MAX, comm);
901  }
902 
903  return glob_norm;
904 }
905 
906 double ComputeGlobalLpNorm(double p, VectorCoefficient &coeff, ParMesh &pmesh,
907  const IntegrationRule *irs[])
908 {
909  double loc_norm = LpNormLoop(p, coeff, pmesh, irs);
910  double glob_norm = 0;
911 
912  MPI_Comm comm = pmesh.GetComm();
913 
914  if (p < infinity())
915  {
916  MPI_Allreduce(&loc_norm, &glob_norm, 1, MPI_DOUBLE, MPI_SUM, comm);
917 
918  // negative quadrature weights may cause norm to be negative
919  if (glob_norm < 0.0)
920  {
921  glob_norm = -pow(-glob_norm, 1.0/p);
922  }
923  else
924  {
925  glob_norm = pow(glob_norm, 1.0/p);
926  }
927  }
928  else
929  {
930  MPI_Allreduce(&loc_norm, &glob_norm, 1, MPI_DOUBLE, MPI_MAX, comm);
931  }
932 
933  return glob_norm;
934 }
935 #endif
936 
938  QuadratureFunction &qf)
939  : VectorCoefficient(qf.GetVDim()), QuadF(qf), index(0) { }
940 
942 {
943  MFEM_VERIFY(index_ >= 0, "Index must be >= 0");
944  MFEM_VERIFY(index_ < QuadF.GetVDim(),
945  "Index must be < QuadratureFunction length");
946  index = index_;
947 
948  MFEM_VERIFY(length_ > 0, "Length must be > 0");
949  MFEM_VERIFY(length_ <= QuadF.GetVDim() - index,
950  "Length must be <= (QuadratureFunction length - index)");
951 
952  vdim = length_;
953 }
954 
957  const IntegrationPoint &ip)
958 {
959  QuadF.HostRead();
960 
961  if (index == 0 && vdim == QuadF.GetVDim())
962  {
963  QuadF.GetElementValues(T.ElementNo, ip.index, V);
964  }
965  else
966  {
967  Vector temp;
968  QuadF.GetElementValues(T.ElementNo, ip.index, temp);
969  V.SetSize(vdim);
970  for (int i = 0; i < vdim; i++)
971  {
972  V(i) = temp(index + i);
973  }
974  }
975 
976  return;
977 }
978 
980  QuadratureFunction &qf) : QuadF(qf)
981 {
982  MFEM_VERIFY(qf.GetVDim() == 1, "QuadratureFunction's vdim must be 1");
983 }
984 
986  const IntegrationPoint &ip)
987 {
988  QuadF.HostRead();
989  Vector temp(1);
990  QuadF.GetElementValues(T.ElementNo, ip.index, temp);
991  return temp[0];
992 }
993 
994 }
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition: intrules.hpp:247
int GetVDim() const
Get the vector dimension.
Definition: gridfunc.hpp:802
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient at ip.
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:90
void GetVectorValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
Definition: gridfunc.cpp:655
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient at ip.
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:30
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...
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
Base class for vector Coefficients that optionally depend on time and space.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector curl coefficient at ip.
TransposeMatrixCoefficient(MatrixCoefficient &A)
Construct with the matrix coefficient. Result is .
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 ...
VectorCrossProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with the two coefficients. Result is A x B.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
virtual void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition: gridfunc.cpp:425
NormalizedVectorCoefficient(VectorCoefficient &A, double tol=1e-6)
Return a vector normalized to a length of one.
void SetSize(int s)
Change the size of the DenseSymmetricMatrix to s x s.
Definition: symmat.cpp:39
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:513
MatrixVectorProductCoefficient(MatrixCoefficient &A, VectorCoefficient &B)
Constructor with two coefficients. Result is A*B.
double Eval(int i, ElementTransformation &T, const IntegrationPoint &ip)
double Det() const
Definition: densemat.cpp:451
void SetDeltaCenter(const Vector &center)
Set the center location of the delta function.
Definition: coefficient.cpp:69
double GetTime()
Get the time for time dependent coefficients.
Element::Type GetElementType(int i) const
Returns the type of element i.
Definition: mesh.cpp:5748
double Norml2() const
Returns the l2 norm of the vector.
Definition: vector.cpp:783
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 ...
void SetIntPoint(const IntegrationPoint *ip)
Set the integration point ip that weights and Jacobians will be evaluated at.
Definition: eltrans.hpp:85
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
int Size() const
Returns the size of the vector.
Definition: vector.hpp:190
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector 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...
int GetNE() const
Returns number of elements.
Definition: mesh.hpp:846
GradientGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a scalar grid function gf. The grid function is not owned by the coeff...
CrossCrossCoefficient(double A, VectorCoefficient &K)
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
Definition: coefficient.cpp:55
void SetTime(double t)
Set the time for time dependent coefficients.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
Definition: coefficient.cpp:31
void add(const Vector &v1, const Vector &v2, Vector &v)
Definition: vector.cpp:291
DeterminantCoefficient(MatrixCoefficient &A)
Construct with the matrix.
ScalarMatrixProductCoefficient(double A, MatrixCoefficient &B)
Constructor with one coefficient. Result is A*B.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
int GetHeight() const
Get the height of the matrix.
double Eval(int i, int j, ElementTransformation &T, const IntegrationPoint &ip)
InnerProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with the two vector coefficients. Result is .
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Definition: intrules.hpp:250
double ComputeLpNorm(double p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
Compute the Lp norm of a function f. .
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
double GetTime()
Get the time for time dependent coefficients.
double LpNormLoop(double p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
QuadratureFunctionCoefficient(QuadratureFunction &qf)
Constructor with a quadrature function as input.
void Add(const double c, const DenseMatrix &A)
Adds the matrix A multiplied by the number c to the matrix.
Definition: densemat.cpp:544
double b
Definition: lissajous.cpp:42
OuterProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with two vector coefficients. Result is .
void SetGridFunction(const GridFunction *gf)
Set the vector grid function.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
void Invert()
Replaces the current matrix with its inverse.
Definition: densemat.cpp:633
void Set(int i, Coefficient *c, bool own=true)
Sets coefficient in the vector.
double Weight()
Return the weight of the Jacobian matrix of the transformation at the currently set IntegrationPoint...
Definition: eltrans.hpp:123
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
virtual ~VectorArrayCoefficient()
Destroys vector coefficient.
int GetVDim()
Returns dimension of the vector.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
virtual const double * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
Definition: vector.hpp:430
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the determinant coefficient at ip.
void SetComponent(int index_, int length_)
void SetTime(double t)
Set the time for time dependent coefficients.
Definition: coefficient.hpp:48
void GetDeltaCenter(Vector &center)
Write the center of the delta function into center.
Definition: coefficient.cpp:77
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
void SetGridFunction(const GridFunction *gf)
Set the scalar grid function.
void Transpose()
(*this) = (*this)^t
Definition: densemat.cpp:1374
MPI_Comm GetComm() const
Definition: pmesh.hpp:276
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
Definition: coefficient.hpp:39
VectorQuadratureFunctionCoefficient(QuadratureFunction &qf)
Constructor with a quadrature function as input.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition: array.hpp:674
Base class for Matrix Coefficients that optionally depend on time and space.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
Definition: coefficient.cpp:24
void GetColumnReference(int c, Vector &col)
Definition: densemat.hpp:285
void SetTime(double t)
Set the time for time dependent coefficients.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient at ip.
virtual void EvalDelta(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Return the specified direction vector multiplied by the value returned by DeltaCoefficient::EvalDelta...
double ComputeGlobalLpNorm(double p, Coefficient &coeff, ParMesh &pmesh, const IntegrationRule *irs[])
Compute the global Lp norm of a function f. .
double GetDivergence(ElementTransformation &tr) const
Definition: gridfunc.cpp:1380
virtual double EvalDelta(ElementTransformation &T, const IntegrationPoint &ip)
The value of the function assuming we are evaluating at the delta center.
Definition: coefficient.cpp:83
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
Definition: coefficient.cpp:49
double a
Definition: lissajous.cpp:41
MatrixArrayCoefficient(int dim)
Construct a coefficient matrix of dimensions dim * dim. The actual coefficients still need to be adde...
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the gradient vector coefficient at ip.
Class for integration point with weight.
Definition: intrules.hpp:25
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the scalar divergence coefficient at ip.
double GetTime()
Get the time for time dependent coefficients.
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: mesh.cpp:347
DivergenceGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a vector grid function gf. The grid function is not owned by the coeff...
Mesh * GetMesh(int type)
Definition: ex29.cpp:218
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
int dim
Definition: ex24.cpp:53
void SetDirection(const Vector &d_)
void GetElementValues(int idx, Vector &values)
Return all values associated with mesh element idx in a Vector.
Definition: gridfunc.hpp:948
void SetGridFunction(const GridFunction *gf)
Set the grid function for this coefficient. Also sets the Vector dimension to match that of the gf...
int index(int i, int j, int nx, int ny)
Definition: life.cpp:237
void GetGradients(ElementTransformation &tr, const IntegrationRule &ir, DenseMatrix &grad) const
Definition: gridfunc.cpp:1636
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
double infinity()
Define a shortcut for std::numeric_limits&lt;double&gt;::infinity()
Definition: vector.hpp:46
MatrixSumCoefficient(MatrixCoefficient &A, MatrixCoefficient &B, double alpha_=1.0, double beta_=1.0)
Construct with the two coefficients. Result is alpha_ * A + beta_ * B.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
VectorArrayCoefficient(int dim)
Construct vector of dim coefficients. The actual coefficients still need to be added with Set()...
virtual void Eval(DenseSymmetricMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
const double alpha
Definition: ex15.cpp:369
void GetCurl(ElementTransformation &tr, Vector &curl) const
Definition: gridfunc.cpp:1466
Vector data type.
Definition: vector.hpp:60
void Mult(const double *x, double *y) const
Matrix vector multiplication.
Definition: densemat.cpp:175
virtual void Transform(const IntegrationPoint &, Vector &)=0
Transform integration point from reference coordinates to physical coordinates and store them in the ...
int GetWidth() const
Get the width of the matrix.
VectorRotProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Constructor with two vector coefficients. Result is .
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
virtual void EvalSymmetric(Vector &K, ElementTransformation &T, const IntegrationPoint &ip)
(DEPRECATED) Evaluate the symmetric matrix coefficient at ip.
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Definition: densemat.hpp:105
Class for parallel meshes.
Definition: pmesh.hpp:32
InverseMatrixCoefficient(MatrixCoefficient &A)
Construct with the matrix coefficient. Result is .
Class representing a function through its values (scalar or vector) at quadrature points...
Definition: gridfunc.hpp:734
void GetGradient(ElementTransformation &tr, Vector &grad) const
Definition: gridfunc.cpp:1568
ScalarVectorProductCoefficient(double A, VectorCoefficient &B)
Constructor with constant and vector coefficient. Result is A * B.
VectorGridFunctionCoefficient()
Construct an empty coefficient. Calling Eval() before the grid function is set will cause a segfault...