MFEM  v4.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
coefficient.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_COEFFICIENT
13 #define MFEM_COEFFICIENT
14 
15 #include "../config/config.hpp"
16 #include "../linalg/linalg.hpp"
17 #include "intrules.hpp"
18 #include "eltrans.hpp"
19 
20 namespace mfem
21 {
22 
23 class Mesh;
24 
25 #ifdef MFEM_USE_MPI
26 class ParMesh;
27 #endif
28 
29 
30 /// Base class Coefficient that may optionally depend on time.
32 {
33 protected:
34  double time;
35 
36 public:
37  Coefficient() { time = 0.; }
38 
39  void SetTime(double t) { time = t; }
40  double GetTime() { return time; }
41 
42  /** @brief Evaluate the coefficient in the element described by @a T at the
43  point @a ip. */
44  /** @note When this method is called, the caller must make sure that the
45  IntegrationPoint associated with @a T is the same as @a ip. This can be
46  achieved by calling T.SetIntPoint(&ip). */
47  virtual double Eval(ElementTransformation &T,
48  const IntegrationPoint &ip) = 0;
49 
50  /** @brief Evaluate the coefficient in the element described by @a T at the
51  point @a ip at time @a t. */
52  /** @note When this method is called, the caller must make sure that the
53  IntegrationPoint associated with @a T is the same as @a ip. This can be
54  achieved by calling T.SetIntPoint(&ip). */
56  const IntegrationPoint &ip, double t)
57  {
58  SetTime(t);
59  return Eval(T, ip);
60  }
61 
62  virtual ~Coefficient() { }
63 };
64 
65 
66 /// Subclass constant coefficient.
68 {
69 public:
70  double constant;
71 
72  /// c is value of constant function
73  explicit ConstantCoefficient(double c = 1.0) { constant=c; }
74 
75  /// Evaluate the coefficient
76  virtual double Eval(ElementTransformation &T,
77  const IntegrationPoint &ip)
78  { return (constant); }
79 };
80 
81 /// class for piecewise constant coefficient
83 {
84 private:
85  Vector constants;
86 
87 public:
88 
89  /// Constructs a piecewise constant coefficient in NumOfSubD subdomains
90  explicit PWConstCoefficient(int NumOfSubD = 0) : constants(NumOfSubD)
91  { constants = 0.0; }
92 
93  /** c should be a vector defined by attributes, so for region with
94  attribute i c[i] is the coefficient in that region */
96  { constants.SetSize(c.Size()); constants=c; }
97 
98  /// Update constants
99  void UpdateConstants(Vector &c) { constants.SetSize(c.Size()); constants=c; }
100 
101  /// Member function to access or modify the value of the i-th constant
102  double &operator()(int i) { return constants(i-1); }
103 
104  /// Set domain constants equal to the same constant c
105  void operator=(double c) { constants = c; }
106 
107  /// Returns the number of constants
108  int GetNConst() { return constants.Size(); }
109 
110  /// Evaluate the coefficient function
111  virtual double Eval(ElementTransformation &T,
112  const IntegrationPoint &ip);
113 };
114 
115 
116 /// class for C-function coefficient
118 {
119 protected:
120  double (*Function)(const Vector &);
121  double (*TDFunction)(const Vector &, double);
122 
123 public:
124  /// Define a time-independent coefficient from a C-function
125  FunctionCoefficient(double (*f)(const Vector &))
126  {
127  Function = f;
128  TDFunction = NULL;
129  }
130 
131  /// Define a time-dependent coefficient from a C-function
132  FunctionCoefficient(double (*tdf)(const Vector &, double))
133  {
134  Function = NULL;
135  TDFunction = tdf;
136  }
137 
138  /// (DEPRECATED) Define a time-independent coefficient from a C-function
139  /** @deprecated Use the method where the C-function, @a f, uses a const
140  Vector argument instead of Vector. */
141  FunctionCoefficient(double (*f)(Vector &))
142  {
143  Function = reinterpret_cast<double(*)(const Vector&)>(f);
144  TDFunction = NULL;
145  }
146 
147  /// (DEPRECATED) Define a time-dependent coefficient from a C-function
148  /** @deprecated Use the method where the C-function, @a tdf, uses a const
149  Vector argument instead of Vector. */
150  FunctionCoefficient(double (*tdf)(Vector &, double))
151  {
152  Function = NULL;
153  TDFunction = reinterpret_cast<double(*)(const Vector&,double)>(tdf);
154  }
155 
156  /// Evaluate coefficient
157  virtual double Eval(ElementTransformation &T,
158  const IntegrationPoint &ip);
159 };
160 
161 class GridFunction;
162 
163 /// Coefficient defined by a GridFunction. This coefficient is mesh dependent.
165 {
166 private:
167  GridFunction *GridF;
168  int Component;
169 
170 public:
171  GridFunctionCoefficient() : GridF(NULL), Component(1) { }
172  /** Construct GridFunctionCoefficient from a given GridFunction, and
173  optionally specify a component to use if it is a vector GridFunction. */
175  { GridF = gf; Component = comp; }
176 
177  void SetGridFunction(GridFunction *gf) { GridF = gf; }
178  GridFunction * GetGridFunction() const { return GridF; }
179 
180  virtual double Eval(ElementTransformation &T,
181  const IntegrationPoint &ip);
182 };
183 
185 {
186 private:
187  Coefficient * Q1;
188  Coefficient * Q2;
189  double (*Transform1)(double);
190  double (*Transform2)(double,double);
191 
192 public:
193  TransformedCoefficient (Coefficient * q,double (*F)(double))
194  : Q1(q), Transform1(F) { Q2 = 0; Transform2 = 0; }
196  double (*F)(double,double))
197  : Q1(q1), Q2(q2), Transform2(F) { Transform1 = 0; }
198 
199  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip);
200 };
201 
202 /// Delta function coefficient
204 {
205 protected:
206  double center[3], scale, tol;
208  int sdim;
209  double (*tdf)(double);
210 
211 public:
213  {
214  center[0] = center[1] = center[2] = 0.; scale = 1.; tol = 1e-12;
215  weight = NULL; sdim = 0; tdf = NULL;
216  }
217  DeltaCoefficient(double x, double s)
218  {
219  center[0] = x; center[1] = 0.; center[2] = 0.; scale = s; tol = 1e-12;
220  weight = NULL; sdim = 1; tdf = NULL;
221  }
222  DeltaCoefficient(double x, double y, double s)
223  {
224  center[0] = x; center[1] = y; center[2] = 0.; scale = s; tol = 1e-12;
225  weight = NULL; sdim = 2; tdf = NULL;
226  }
227  DeltaCoefficient(double x, double y, double z, double s)
228  {
229  center[0] = x; center[1] = y; center[2] = z; scale = s; tol = 1e-12;
230  weight = NULL; sdim = 3; tdf = NULL;
231  }
232  void SetDeltaCenter(const Vector& center);
233  void SetScale(double _s) { scale = _s; }
234  /// Set a time-dependent function that multiplies the Scale().
235  void SetFunction(double (*f)(double)) { tdf = f; }
236  /** @brief Set the tolerance used during projection onto GridFunction to
237  identifying the Mesh vertex where the Center() of the delta function
238  lies. */
239  void SetTol(double _tol) { tol = _tol; }
240  /// Set a weight Coefficient that multiplies the DeltaCoefficient.
241  /** The weight Coefficient multiplies the value returned by EvalDelta() but
242  not the value returned by Scale().
243  The weight Coefficient is also used as the L2-weight function when
244  projecting the DeltaCoefficient onto a GridFunction, so that the weighted
245  integral of the projection is exactly equal to the Scale(). */
246  void SetWeight(Coefficient *w) { weight = w; }
247  const double *Center() { return center; }
248  /** @brief Return the scale set by SetScale() multiplied by the
249  time-dependent function specified by SetFunction(), if set. */
250  double Scale() { return tdf ? (*tdf)(GetTime())*scale : scale; }
251  /// See SetTol() for description of the tolerance parameter.
252  double Tol() { return tol; }
253  /// See SetWeight() for description of the weight Coefficient.
254  Coefficient *Weight() { return weight; }
256  /// Return the Scale() multiplied by the weight Coefficient, if any.
257  virtual double EvalDelta(ElementTransformation &T, const IntegrationPoint &ip);
258  /** @brief A DeltaFunction cannot be evaluated. Calling this method will
259  cause an MFEM error, terminating the application. */
260  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
261  { mfem_error("DeltaCoefficient::Eval"); return 0.; }
262  virtual ~DeltaCoefficient() { delete weight; }
263 };
264 
265 /// Coefficient defined on a subset of domain or boundary attributes
267 {
268 private:
269  Coefficient *c;
270  Array<int> active_attr;
271 
272 public:
274  { c = &_c; attr.Copy(active_attr); }
275 
276  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
277  { return active_attr[T.Attribute-1] ? c->Eval(T, ip, GetTime()) : 0.0; }
278 };
279 
281 {
282 protected:
283  int vdim;
284  double time;
285 
286 public:
287  VectorCoefficient(int vd) { vdim = vd; time = 0.; }
288 
289  void SetTime(double t) { time = t; }
290  double GetTime() { return time; }
291 
292  /// Returns dimension of the vector.
293  int GetVDim() { return vdim; }
294 
295  /** @brief Evaluate the vector coefficient in the element described by @a T
296  at the point @a ip, storing the result in @a V. */
297  /** @note When this method is called, the caller must make sure that the
298  IntegrationPoint associated with @a T is the same as @a ip. This can be
299  achieved by calling T.SetIntPoint(&ip). */
300  virtual void Eval(Vector &V, ElementTransformation &T,
301  const IntegrationPoint &ip) = 0;
302 
303  /** @brief Evaluate the vector coefficient in the element described by @a T
304  at all points of @a ir, storing the result in @a M. */
305  /** The dimensions of @a M are GetVDim() by ir.GetNPoints() and they must be
306  set by the implementation of this method.
307 
308  The general implementation provided by the base class (using the Eval
309  method for one IntegrationPoint at a time) can be overloaded for more
310  efficient implementation.
311 
312  @note The IntegrationPoint associated with @a T is not used, and this
313  method will generally modify this IntegrationPoint associated with @a T.
314  */
315  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
316  const IntegrationRule &ir);
317 
318  virtual ~VectorCoefficient() { }
319 };
320 
322 {
323 private:
324  Vector vec;
325 public:
327  : VectorCoefficient(v.Size()), vec(v) { }
329  virtual void Eval(Vector &V, ElementTransformation &T,
330  const IntegrationPoint &ip) { V = vec; }
331 };
332 
334 {
335 private:
336  void (*Function)(const Vector &, Vector &);
337  void (*TDFunction)(const Vector &, double, Vector &);
338  Coefficient *Q;
339 
340 public:
341  /// Construct a time-independent vector coefficient from a C-function
342  VectorFunctionCoefficient(int dim, void (*F)(const Vector &, Vector &),
343  Coefficient *q = NULL)
344  : VectorCoefficient(dim), Q(q)
345  {
346  Function = F;
347  TDFunction = NULL;
348  }
349 
350  /// Construct a time-dependent vector coefficient from a C-function
352  void (*TDF)(const Vector &, double, Vector &),
353  Coefficient *q = NULL)
354  : VectorCoefficient(dim), Q(q)
355  {
356  Function = NULL;
357  TDFunction = TDF;
358  }
359 
361  virtual void Eval(Vector &V, ElementTransformation &T,
362  const IntegrationPoint &ip);
363 
365 };
366 
367 /// Vector coefficient defined by an array of scalar coefficients.
369 {
370 private:
371  Array<Coefficient*> Coeff;
372  Array<bool> ownCoeff;
373 
374 public:
375  /// Construct vector of dim coefficients.
376  explicit VectorArrayCoefficient(int dim);
377 
378  /// Returns i'th coefficient.
379  Coefficient* GetCoeff(int i) { return Coeff[i]; }
380 
381  Coefficient **GetCoeffs() { return Coeff; }
382 
383  /// Sets coefficient in the vector.
384  void Set(int i, Coefficient *c, bool own=true);
385 
386  /// Evaluates i'th component of the vector.
387  double Eval(int i, ElementTransformation &T, const IntegrationPoint &ip)
388  { return Coeff[i] ? Coeff[i]->Eval(T, ip, GetTime()) : 0.0; }
389 
391  virtual void Eval(Vector &V, ElementTransformation &T,
392  const IntegrationPoint &ip);
393 
394  /// Destroys vector coefficient.
395  virtual ~VectorArrayCoefficient();
396 };
397 
398 /// Vector coefficient defined by a vector GridFunction
400 {
401 protected:
403 
404 public:
407 
408  void SetGridFunction(GridFunction *gf);
409  GridFunction * GetGridFunction() const { return GridFunc; }
410 
411  virtual void Eval(Vector &V, ElementTransformation &T,
412  const IntegrationPoint &ip);
413 
414  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
415  const IntegrationRule &ir);
416 
418 };
419 
420 /// Vector coefficient defined as the Gradient of a scalar GridFunction
422 {
423 protected:
425 
426 public:
428 
429  void SetGridFunction(GridFunction *gf);
430  GridFunction * GetGridFunction() const { return GridFunc; }
431 
432  virtual void Eval(Vector &V, ElementTransformation &T,
433  const IntegrationPoint &ip);
434 
435  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
436  const IntegrationRule &ir);
437 
439 };
440 
441 /// Vector coefficient defined as the Curl of a vector GridFunction
443 {
444 protected:
446 
447 public:
449 
450  void SetGridFunction(GridFunction *gf);
451  GridFunction * GetGridFunction() const { return GridFunc; }
452 
454  virtual void Eval(Vector &V, ElementTransformation &T,
455  const IntegrationPoint &ip);
456 
458 };
459 
460 /// Scalar coefficient defined as the Divergence of a vector GridFunction
462 {
463 protected:
465 
466 public:
468 
470  GridFunction * GetGridFunction() const { return GridFunc; }
471 
472  virtual double Eval(ElementTransformation &T,
473  const IntegrationPoint &ip);
474 
476 };
477 
478 /// VectorDeltaCoefficient: DeltaCoefficient with a direction
480 {
481 protected:
484 
485 public:
487  : VectorCoefficient(_vdim), dir(_vdim), d() { }
489  : VectorCoefficient(_dir.Size()), dir(_dir), d() { }
490  VectorDeltaCoefficient(const Vector& _dir, double x, double s)
491  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,s) { }
492  VectorDeltaCoefficient(const Vector& _dir, double x, double y, double s)
493  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,y,s) { }
494  VectorDeltaCoefficient(const Vector& _dir, double x, double y, double z,
495  double s)
496  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,y,z,s) { }
497 
498  /// Replace the associated DeltaCoeficient with a new DeltaCoeficient.
499  /** The new DeltaCoeficient cannot have a specified weight Coefficient, i.e.
500  DeltaCoeficient::Weight() should return NULL. */
501  void SetDeltaCoefficient(const DeltaCoefficient& _d) { d = _d; }
502  /// Return the associated scalar DeltaCoefficient.
504 
505  void SetScale(double s) { d.SetScale(s); }
506  void SetDirection(const Vector& _d);
507 
508  void SetDeltaCenter(const Vector& center) { d.SetDeltaCenter(center); }
509  void GetDeltaCenter(Vector& center) { d.GetDeltaCenter(center); }
510 
511  /** @brief Return the specified direction vector multiplied by the value
512  returned by DeltaCoefficient::EvalDelta() of the associated scalar
513  DeltaCoefficient. */
514  virtual void EvalDelta(Vector &V, ElementTransformation &T,
515  const IntegrationPoint &ip);
517  /** @brief A VectorDeltaFunction cannot be evaluated. Calling this method
518  will cause an MFEM error, terminating the application. */
519  virtual void Eval(Vector &V, ElementTransformation &T,
520  const IntegrationPoint &ip)
521  { mfem_error("VectorDeltaCoefficient::Eval"); }
523 };
524 
525 /// VectorCoefficient defined on a subset of domain or boundary attributes
527 {
528 private:
530  Array<int> active_attr;
531 
532 public:
534  : VectorCoefficient(vc.GetVDim())
535  { c = &vc; attr.Copy(active_attr); }
536 
537  virtual void Eval(Vector &V, ElementTransformation &T,
538  const IntegrationPoint &ip);
539 
540  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
541  const IntegrationRule &ir);
542 };
543 
544 
546 {
547 protected:
548  int height, width;
549  double time;
550 
551 public:
552  explicit MatrixCoefficient(int dim) { height = width = dim; time = 0.; }
553 
554  MatrixCoefficient(int h, int w) : height(h), width(w), time(0.) { }
555 
556  void SetTime(double t) { time = t; }
557  double GetTime() { return time; }
558 
559  int GetHeight() const { return height; }
560  int GetWidth() const { return width; }
561  // For backward compatibility
562  int GetVDim() const { return width; }
563 
564  /** @brief Evaluate the matrix coefficient in the element described by @a T
565  at the point @a ip, storing the result in @a K. */
566  /** @note When this method is called, the caller must make sure that the
567  IntegrationPoint associated with @a T is the same as @a ip. This can be
568  achieved by calling T.SetIntPoint(&ip). */
569  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
570  const IntegrationPoint &ip) = 0;
571 
572  virtual ~MatrixCoefficient() { }
573 };
574 
576 {
577 private:
578  DenseMatrix mat;
579 public:
581  : MatrixCoefficient(m.Height(), m.Width()), mat(m) { }
584  const IntegrationPoint &ip) { M = mat; }
585 };
586 
588 {
589 private:
590  void (*Function)(const Vector &, DenseMatrix &);
591  void (*TDFunction)(const Vector &, double, DenseMatrix &);
592  Coefficient *Q;
593  DenseMatrix mat;
594 
595 public:
596  /// Construct a time-independent square matrix coefficient from a C-function
597  MatrixFunctionCoefficient(int dim, void (*F)(const Vector &, DenseMatrix &),
598  Coefficient *q = NULL)
599  : MatrixCoefficient(dim), Q(q)
600  {
601  Function = F;
602  TDFunction = NULL;
603  mat.SetSize(0);
604  }
605 
606  /// Construct a constant matrix coefficient times a scalar Coefficient
608  : MatrixCoefficient(m.Height(), m.Width()), Q(&q)
609  {
610  Function = NULL;
611  TDFunction = NULL;
612  mat = m;
613  }
614 
615  /// Construct a time-dependent square matrix coefficient from a C-function
617  void (*TDF)(const Vector &, double, DenseMatrix &),
618  Coefficient *q = NULL)
619  : MatrixCoefficient(dim), Q(q)
620  {
621  Function = NULL;
622  TDFunction = TDF;
623  mat.SetSize(0);
624  }
625 
626  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
627  const IntegrationPoint &ip);
628 
630 };
631 
633 {
634 private:
635  Array<Coefficient *> Coeff;
636  Array<bool> ownCoeff;
637 
638 public:
639 
640  explicit MatrixArrayCoefficient (int dim);
641 
642  Coefficient* GetCoeff (int i, int j) { return Coeff[i*width+j]; }
643 
644  void Set(int i, int j, Coefficient * c, bool own=true);
645 
646  double Eval(int i, int j, ElementTransformation &T, const IntegrationPoint &ip)
647  { return Coeff[i*width+j] ? Coeff[i*width+j] -> Eval(T, ip, GetTime()) : 0.0; }
648 
649  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
650  const IntegrationPoint &ip);
651 
652  virtual ~MatrixArrayCoefficient();
653 };
654 
655 /// MatrixCoefficient defined on a subset of domain or boundary attributes
657 {
658 private:
660  Array<int> active_attr;
661 
662 public:
664  : MatrixCoefficient(mc.GetHeight(), mc.GetWidth())
665  { c = &mc; attr.Copy(active_attr); }
666 
667  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
668  const IntegrationPoint &ip);
669 };
670 
671 /// Coefficients based on sums and products of other coefficients
672 
673 /// Scalar coefficient defined as the sum of two scalar coefficients
675 {
676 private:
677  Coefficient * a;
678  Coefficient * b;
679 
680  double alpha;
681  double beta;
682 
683 public:
684  // Result is _alpha * A + _beta * B
686  double _alpha = 1.0, double _beta = 1.0)
687  : a(&A), b(&B), alpha(_alpha), beta(_beta) { }
688 
689  /// Evaluate the coefficient
690  virtual double Eval(ElementTransformation &T,
691  const IntegrationPoint &ip)
692  { return alpha * a->Eval(T, ip) + beta * b->Eval(T, ip); }
693 };
694 
695 /// Scalar coefficient defined as the product of two scalar coefficients
697 {
698 private:
699  Coefficient * a;
700  Coefficient * b;
701 
702 public:
704  : a(&A), b(&B) { }
705 
706  /// Evaluate the coefficient
707  virtual double Eval(ElementTransformation &T,
708  const IntegrationPoint &ip)
709  { return a->Eval(T, ip) * b->Eval(T, ip); }
710 };
711 
712 /// Scalar coefficient defined as a scalar raised to a power
714 {
715 private:
716  Coefficient * a;
717 
718  double p;
719 
720 public:
721  // Result is A^p
723  : a(&A), p(_p) { }
724 
725  /// Evaluate the coefficient
726  virtual double Eval(ElementTransformation &T,
727  const IntegrationPoint &ip)
728  { return pow(a->Eval(T, ip), p); }
729 };
730 
731 /// Scalar coefficient defined as the inner product of two vector coefficients
733 {
734 private:
735  VectorCoefficient * a;
736  VectorCoefficient * b;
737 
738  mutable Vector va;
739  mutable Vector vb;
740 public:
742 
743  /// Evaluate the coefficient
744  virtual double Eval(ElementTransformation &T,
745  const IntegrationPoint &ip);
746 };
747 
748 /// Scalar coefficient defined as a cross product of two vectors in 2D
750 {
751 private:
752  VectorCoefficient * a;
753  VectorCoefficient * b;
754 
755  mutable Vector va;
756  mutable Vector vb;
757 
758 public:
760 
761  virtual double Eval(ElementTransformation &T,
762  const IntegrationPoint &ip);
763 };
764 
765 /// Scalar coefficient defined as the determinant of a matrix coefficient
767 {
768 private:
769  MatrixCoefficient * a;
770 
771  mutable DenseMatrix ma;
772 
773 public:
775 
776  /// Evaluate the coefficient
777  virtual double Eval(ElementTransformation &T,
778  const IntegrationPoint &ip);
779 };
780 
781 /// Vector coefficient defined as the sum of two vector coefficients
783 {
784 private:
785  VectorCoefficient * a;
786  VectorCoefficient * b;
787 
788  double alpha;
789  double beta;
790 
791  mutable Vector va;
792 
793 public:
794  // Result is _alpha * A + _beta * B
796  double _alpha = 1.0, double _beta = 1.0);
797 
798  /// Evaluate the coefficient
799  virtual void Eval(Vector &V, ElementTransformation &T,
800  const IntegrationPoint &ip);
802 };
803 
804 /// Vector coefficient defined as a product of a scalar and a vector
806 {
807 private:
808  Coefficient * a;
809  VectorCoefficient * b;
810 
811 public:
813 
814  virtual void Eval(Vector &V, ElementTransformation &T,
815  const IntegrationPoint &ip);
817 };
818 
819 /// Vector coefficient defined as a cross product of two vectors
821 {
822 private:
823  VectorCoefficient * a;
824  VectorCoefficient * b;
825 
826  mutable Vector va;
827  mutable Vector vb;
828 
829 public:
831 
832  virtual void Eval(Vector &V, ElementTransformation &T,
833  const IntegrationPoint &ip);
835 };
836 
837 /// Vector coefficient defined as a matrix vector product
839 {
840 private:
841  MatrixCoefficient * a;
842  VectorCoefficient * b;
843 
844  mutable DenseMatrix ma;
845  mutable Vector vb;
846 
847 public:
849 
850  virtual void Eval(Vector &V, ElementTransformation &T,
851  const IntegrationPoint &ip);
853 };
854 
855 /// Matrix coefficient defined as the identity of dimension d
857 {
858 private:
859  int dim;
860 
861 public:
863  : MatrixCoefficient(d, d), dim(d) { }
864 
865  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
866  const IntegrationPoint &ip);
867 };
868 
869 /// Matrix coefficient defined as the sum of two matrix coefficients
871 {
872 private:
873  MatrixCoefficient * a;
874  MatrixCoefficient * b;
875 
876  double alpha;
877  double beta;
878 
879  mutable DenseMatrix ma;
880 
881 public:
882  // Result is _alpha * A + _beta * B
884  double _alpha = 1.0, double _beta = 1.0);
885 
886  /// Evaluate the coefficient
887  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
888  const IntegrationPoint &ip);
889 };
890 
891 /// Matrix coefficient defined as a product of a scalar and a matrix
893 {
894 private:
895  Coefficient * a;
896  MatrixCoefficient * b;
897 
898 public:
900 
901  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
902  const IntegrationPoint &ip);
903 };
904 
905 /// Matrix coefficient defined as the transpose a matrix
907 {
908 private:
909  MatrixCoefficient * a;
910 
911 public:
913 
914  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
915  const IntegrationPoint &ip);
916 };
917 
918 /// Matrix coefficient defined as the inverse a matrix
920 {
921 private:
922  MatrixCoefficient * a;
923 
924 public:
926 
927  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
928  const IntegrationPoint &ip);
929 };
930 
931 /// Matrix coefficient defined as the outer product of two vectors
933 {
934 private:
935  VectorCoefficient * a;
936  VectorCoefficient * b;
937 
938  mutable Vector va;
939  mutable Vector vb;
940 
941 public:
943 
944  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
945  const IntegrationPoint &ip);
946 };
947 
948 /** Compute the Lp norm of a function f.
949  \f$ \| f \|_{Lp} = ( \int_\Omega | f |^p d\Omega)^{1/p} \f$ */
950 double ComputeLpNorm(double p, Coefficient &coeff, Mesh &mesh,
951  const IntegrationRule *irs[]);
952 
953 /** Compute the Lp norm of a vector function f = {f_i}_i=1...N.
954  \f$ \| f \|_{Lp} = ( \sum_i \| f_i \|_{Lp}^p )^{1/p} \f$ */
955 double ComputeLpNorm(double p, VectorCoefficient &coeff, Mesh &mesh,
956  const IntegrationRule *irs[]);
957 
958 #ifdef MFEM_USE_MPI
959 /** Compute the global Lp norm of a function f.
960  \f$ \| f \|_{Lp} = ( \int_\Omega | f |^p d\Omega)^{1/p} \f$ */
961 double ComputeGlobalLpNorm(double p, Coefficient &coeff, ParMesh &pmesh,
962  const IntegrationRule *irs[]);
963 
964 /** Compute the global Lp norm of a vector function f = {f_i}_i=1...N.
965  \f$ \| f \|_{Lp} = ( \sum_i \| f_i \|_{Lp}^p )^{1/p} \f$ */
966 double ComputeGlobalLpNorm(double p, VectorCoefficient &coeff, ParMesh &pmesh,
967  const IntegrationRule *irs[]);
968 #endif
969 
970 }
971 
972 #endif
Vector coefficient defined as a cross product of two vectors.
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 ...
double Eval(ElementTransformation &T, const IntegrationPoint &ip, double t)
Evaluate the coefficient in the element described by T at the point ip at time t. ...
Definition: coefficient.hpp:55
void GetDeltaCenter(Vector &center)
void SetTol(double _tol)
Set the tolerance used during projection onto GridFunction to identifying the Mesh vertex where the C...
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:85
Vector coefficient defined by an array of scalar coefficients.
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:27
GridFunction * GetGridFunction() const
void Set(int i, int j, Coefficient *c, bool own=true)
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
void SetWeight(Coefficient *w)
Set a weight Coefficient that multiplies the DeltaCoefficient.
Subclass constant coefficient.
Definition: coefficient.hpp:67
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 ...
TransposeMatrixCoefficient(MatrixCoefficient &A)
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 ...
double(* tdf)(double)
VectorCrossProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
FunctionCoefficient(double(*tdf)(const Vector &, double))
Define a time-dependent coefficient from a C-function.
Scalar coefficient defined as the inner product of two vector coefficients.
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:400
double Eval(int i, ElementTransformation &T, const IntegrationPoint &ip)
Evaluates i&#39;th component of the vector.
Vector coefficient defined as a matrix vector product.
void SetDeltaCenter(const Vector &center)
Definition: coefficient.cpp:69
double Scale()
Return the scale set by SetScale() multiplied by the time-dependent function specified by SetFunction...
FunctionCoefficient(double(*f)(Vector &))
(DEPRECATED) Define a time-independent coefficient from a C-function
Scalar coefficient defined as a cross product of two vectors in 2D.
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 ...
Scalar coefficient defined as the product of two scalar coefficients.
SumCoefficient(Coefficient &A, Coefficient &B, double _alpha=1.0, double _beta=1.0)
void Copy(Array &copy) const
Create a copy of the current array.
Definition: array.hpp:795
GradientGridFunctionCoefficient(GridFunction *gf)
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
double & operator()(int i)
Member function to access or modify the value of the i-th constant.
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
Delta function coefficient.
int Size() const
Returns the size of the vector.
Definition: vector.hpp:150
void SetFunction(double(*f)(double))
Set a time-dependent function that multiplies the Scale().
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 double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
double Tol()
See SetTol() for description of the tolerance parameter.
GridFunction * GetGridFunction() const
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 ...
Vector coefficient defined as the sum of two vector coefficients.
Matrix coefficient defined as a product of a scalar and a matrix.
VectorFunctionCoefficient(int dim, void(*TDF)(const Vector &, double, Vector &), Coefficient *q=NULL)
Construct a time-dependent vector coefficient from a C-function.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
Definition: coefficient.cpp:55
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
A DeltaFunction cannot be evaluated. Calling this method will cause an MFEM error, terminating the application.
void SetTime(double t)
VectorDeltaCoefficient(const Vector &_dir, double x, double y, double s)
DeltaCoefficient(double x, double y, double z, double s)
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate coefficient.
Definition: coefficient.cpp:31
Matrix coefficient defined as the sum of two matrix coefficients.
DeltaCoefficient & GetDeltaCoefficient()
Return the associated scalar DeltaCoefficient.
DeltaCoefficient(double x, double s)
DeterminantCoefficient(MatrixCoefficient &A)
double(* Function)(const Vector &)
Matrix coefficient defined as the inverse a matrix.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
A VectorDeltaFunction cannot be evaluated. Calling this method will cause an MFEM error...
void SetGridFunction(GridFunction *gf)
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
Coefficient * GetCoeff(int i, int j)
Matrix coefficient defined as the outer product of two vectors.
double Eval(int i, int j, ElementTransformation &T, const IntegrationPoint &ip)
VectorCoefficient defined on a subset of domain or boundary attributes.
InnerProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
MatrixFunctionCoefficient(int dim, void(*F)(const Vector &, DenseMatrix &), Coefficient *q=NULL)
Construct a time-independent square matrix coefficient from a C-function.
int dim
Definition: ex3.cpp:48
double ComputeLpNorm(double p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
VectorConstantCoefficient(const Vector &v)
ConstantCoefficient(double c=1.0)
c is value of constant function
Definition: coefficient.hpp:73
const double * Center()
Coefficient defined on a subset of domain or boundary attributes.
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Definition: error.cpp:146
void SetDeltaCenter(const Vector &center)
Coefficient * Weight()
See SetWeight() for description of the weight Coefficient.
ScalarVectorProductCoefficient(Coefficient &A, VectorCoefficient &B)
VectorDeltaCoefficient(const Vector &_dir)
MatrixRestrictedCoefficient(MatrixCoefficient &mc, Array< int > &attr)
void SetDirection(const Vector &_d)
VectorDeltaCoefficient(const Vector &_dir, double x, double y, double z, double s)
Vector coefficient defined as the Gradient of a scalar GridFunction.
Vector coefficient defined as the Curl of a vector GridFunction.
OuterProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
MatrixFunctionCoefficient(int dim, void(*TDF)(const Vector &, double, DenseMatrix &), Coefficient *q=NULL)
Construct a time-dependent square matrix coefficient from a C-function.
void Set(int i, Coefficient *c, bool own=true)
Sets coefficient in the vector.
void SetDeltaCoefficient(const DeltaCoefficient &_d)
Replace the associated DeltaCoeficient with a new DeltaCoeficient.
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 ~VectorArrayCoefficient()
Destroys vector coefficient.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
int GetVDim()
Returns dimension of the vector.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
GridFunction * GetGridFunction() const
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
VectorSumCoefficient(VectorCoefficient &A, VectorCoefficient &B, double _alpha=1.0, double _beta=1.0)
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
void SetTime(double t)
Definition: coefficient.hpp:39
void operator=(double c)
Set domain constants equal to the same constant c.
PowerCoefficient(Coefficient &A, double _p)
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
Definition: coefficient.hpp:76
void SetGridFunction(GridFunction *gf)
void GetDeltaCenter(Vector &center)
Definition: coefficient.cpp:77
MatrixFunctionCoefficient(const DenseMatrix &m, Coefficient &q)
Construct a constant matrix coefficient times a scalar Coefficient.
Scalar coefficient defined as the Divergence of a vector GridFunction.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
MatVecCoefficient(MatrixCoefficient &A, VectorCoefficient &B)
Base class Coefficient that may optionally depend on time.
Definition: coefficient.hpp:31
virtual ~Coefficient()
Definition: coefficient.hpp:62
Vector coefficient defined as a product of a scalar and a vector.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
FunctionCoefficient(double(*f)(const Vector &))
Define a time-independent coefficient from a C-function.
void UpdateConstants(Vector &c)
Update constants.
Definition: coefficient.hpp:99
GridFunction * GetGridFunction() const
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient function.
Definition: coefficient.cpp:24
Coefficient * GetCoeff(int i)
Returns i&#39;th coefficient.
void SetTime(double t)
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 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[])
void SetGridFunction(GridFunction *gf)
PWConstCoefficient(int NumOfSubD=0)
Constructs a piecewise constant coefficient in NumOfSubD subdomains.
Definition: coefficient.hpp:90
virtual double EvalDelta(ElementTransformation &T, const IntegrationPoint &ip)
Return the Scale() multiplied by the weight Coefficient, if any.
Definition: coefficient.cpp:83
MatrixCoefficient defined on a subset of domain or boundary attributes.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
Definition: coefficient.cpp:49
void SetGridFunction(GridFunction *gf)
VectorDeltaCoefficient: DeltaCoefficient with a direction.
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 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 ...
class for piecewise constant coefficient
Definition: coefficient.hpp:82
void SetScale(double _s)
Class for integration point with weight.
Definition: intrules.hpp:25
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
void SetGridFunction(GridFunction *gf)
MatrixSumCoefficient(MatrixCoefficient &A, MatrixCoefficient &B, double _alpha=1.0, double _beta=1.0)
FunctionCoefficient(double(*tdf)(Vector &, double))
(DEPRECATED) Define a time-dependent coefficient from a C-function
TransformedCoefficient(Coefficient *q, double(*F)(double))
int GetNConst()
Returns the number of constants.
Matrix coefficient defined as the transpose a matrix.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
VectorDeltaCoefficient(const Vector &_dir, double x, double s)
DeltaCoefficient(double x, double y, double s)
Scalar coefficient defined as a scalar raised to a power.
DivergenceGridFunctionCoefficient(GridFunction *gf)
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.
VectorFunctionCoefficient(int dim, void(*F)(const Vector &, Vector &), Coefficient *q=NULL)
Construct a time-independent vector coefficient from a C-function.
Scalar coefficient defined as the determinant of a matrix coefficient.
class for C-function coefficient
ProductCoefficient(Coefficient &A, Coefficient &B)
Vector data type.
Definition: vector.hpp:48
TransformedCoefficient(Coefficient *q1, Coefficient *q2, double(*F)(double, double))
Vector coefficient defined by a vector GridFunction.
VectorRestrictedCoefficient(VectorCoefficient &vc, Array< int > &attr)
VectorRotProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
MatrixConstantCoefficient(const DenseMatrix &m)
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
GridFunctionCoefficient(GridFunction *gf, int comp=1)
CurlGridFunctionCoefficient(GridFunction *gf)
Matrix coefficient defined as the identity of dimension d.
GridFunction * GetGridFunction() const
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Definition: densemat.hpp:88
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 ...
double(* TDFunction)(const Vector &, double)
Class for parallel meshes.
Definition: pmesh.hpp:32
InverseMatrixCoefficient(MatrixCoefficient &A)
Coefficients based on sums and products of other coefficients.
MatrixCoefficient(int h, int w)
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
ScalarMatrixProductCoefficient(Coefficient &A, MatrixCoefficient &B)
RestrictedCoefficient(Coefficient &_c, Array< int > &attr)