MFEM  v4.1.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-2020, 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 #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  const Vector& GetVec() { return vec; }
332 };
333 
335 {
336 private:
337  void (*Function)(const Vector &, Vector &);
338  void (*TDFunction)(const Vector &, double, Vector &);
339  Coefficient *Q;
340 
341 public:
342  /// Construct a time-independent vector coefficient from a C-function
343  VectorFunctionCoefficient(int dim, void (*F)(const Vector &, Vector &),
344  Coefficient *q = NULL)
345  : VectorCoefficient(dim), Q(q)
346  {
347  Function = F;
348  TDFunction = NULL;
349  }
350 
351  /// Construct a time-dependent vector coefficient from a C-function
353  void (*TDF)(const Vector &, double, Vector &),
354  Coefficient *q = NULL)
355  : VectorCoefficient(dim), Q(q)
356  {
357  Function = NULL;
358  TDFunction = TDF;
359  }
360 
362  virtual void Eval(Vector &V, ElementTransformation &T,
363  const IntegrationPoint &ip);
364 
366 };
367 
368 /// Vector coefficient defined by an array of scalar coefficients.
370 {
371 private:
372  Array<Coefficient*> Coeff;
373  Array<bool> ownCoeff;
374 
375 public:
376  /// Construct vector of dim coefficients.
377  explicit VectorArrayCoefficient(int dim);
378 
379  /// Returns i'th coefficient.
380  Coefficient* GetCoeff(int i) { return Coeff[i]; }
381 
382  Coefficient **GetCoeffs() { return Coeff; }
383 
384  /// Sets coefficient in the vector.
385  void Set(int i, Coefficient *c, bool own=true);
386 
387  /// Evaluates i'th component of the vector.
388  double Eval(int i, ElementTransformation &T, const IntegrationPoint &ip)
389  { return Coeff[i] ? Coeff[i]->Eval(T, ip, GetTime()) : 0.0; }
390 
392  virtual void Eval(Vector &V, ElementTransformation &T,
393  const IntegrationPoint &ip);
394 
395  /// Destroys vector coefficient.
396  virtual ~VectorArrayCoefficient();
397 };
398 
399 /// Vector coefficient defined by a vector GridFunction
401 {
402 protected:
404 
405 public:
408 
409  void SetGridFunction(GridFunction *gf);
410  GridFunction * GetGridFunction() const { return GridFunc; }
411 
412  virtual void Eval(Vector &V, ElementTransformation &T,
413  const IntegrationPoint &ip);
414 
415  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
416  const IntegrationRule &ir);
417 
419 };
420 
421 /// Vector coefficient defined as the Gradient of a scalar GridFunction
423 {
424 protected:
426 
427 public:
429 
430  void SetGridFunction(GridFunction *gf);
431  GridFunction * GetGridFunction() const { return GridFunc; }
432 
433  virtual void Eval(Vector &V, ElementTransformation &T,
434  const IntegrationPoint &ip);
435 
436  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
437  const IntegrationRule &ir);
438 
440 };
441 
442 /// Vector coefficient defined as the Curl of a vector GridFunction
444 {
445 protected:
447 
448 public:
450 
451  void SetGridFunction(GridFunction *gf);
452  GridFunction * GetGridFunction() const { return GridFunc; }
453 
455  virtual void Eval(Vector &V, ElementTransformation &T,
456  const IntegrationPoint &ip);
457 
459 };
460 
461 /// Scalar coefficient defined as the Divergence of a vector GridFunction
463 {
464 protected:
466 
467 public:
469 
471  GridFunction * GetGridFunction() const { return GridFunc; }
472 
473  virtual double Eval(ElementTransformation &T,
474  const IntegrationPoint &ip);
475 
477 };
478 
479 /// VectorDeltaCoefficient: DeltaCoefficient with a direction
481 {
482 protected:
485 
486 public:
488  : VectorCoefficient(_vdim), dir(_vdim), d() { }
490  : VectorCoefficient(_dir.Size()), dir(_dir), d() { }
491  VectorDeltaCoefficient(const Vector& _dir, double x, double s)
492  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,s) { }
493  VectorDeltaCoefficient(const Vector& _dir, double x, double y, double s)
494  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,y,s) { }
495  VectorDeltaCoefficient(const Vector& _dir, double x, double y, double z,
496  double s)
497  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,y,z,s) { }
498 
499  /// Replace the associated DeltaCoeficient with a new DeltaCoeficient.
500  /** The new DeltaCoeficient cannot have a specified weight Coefficient, i.e.
501  DeltaCoeficient::Weight() should return NULL. */
502  void SetDeltaCoefficient(const DeltaCoefficient& _d) { d = _d; }
503  /// Return the associated scalar DeltaCoefficient.
505 
506  void SetScale(double s) { d.SetScale(s); }
507  void SetDirection(const Vector& _d);
508 
509  void SetDeltaCenter(const Vector& center) { d.SetDeltaCenter(center); }
510  void GetDeltaCenter(Vector& center) { d.GetDeltaCenter(center); }
511 
512  /** @brief Return the specified direction vector multiplied by the value
513  returned by DeltaCoefficient::EvalDelta() of the associated scalar
514  DeltaCoefficient. */
515  virtual void EvalDelta(Vector &V, ElementTransformation &T,
516  const IntegrationPoint &ip);
518  /** @brief A VectorDeltaFunction cannot be evaluated. Calling this method
519  will cause an MFEM error, terminating the application. */
520  virtual void Eval(Vector &V, ElementTransformation &T,
521  const IntegrationPoint &ip)
522  { mfem_error("VectorDeltaCoefficient::Eval"); }
524 };
525 
526 /// VectorCoefficient defined on a subset of domain or boundary attributes
528 {
529 private:
531  Array<int> active_attr;
532 
533 public:
535  : VectorCoefficient(vc.GetVDim())
536  { c = &vc; attr.Copy(active_attr); }
537 
538  virtual void Eval(Vector &V, ElementTransformation &T,
539  const IntegrationPoint &ip);
540 
541  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
542  const IntegrationRule &ir);
543 };
544 
545 
547 {
548 protected:
549  int height, width;
550  double time;
551 
552 public:
553  explicit MatrixCoefficient(int dim) { height = width = dim; time = 0.; }
554 
555  MatrixCoefficient(int h, int w) : height(h), width(w), time(0.) { }
556 
557  void SetTime(double t) { time = t; }
558  double GetTime() { return time; }
559 
560  int GetHeight() const { return height; }
561  int GetWidth() const { return width; }
562  // For backward compatibility
563  int GetVDim() const { return width; }
564 
565  /** @brief Evaluate the matrix coefficient in the element described by @a T
566  at the point @a ip, storing the result in @a K. */
567  /** @note When this method is called, the caller must make sure that the
568  IntegrationPoint associated with @a T is the same as @a ip. This can be
569  achieved by calling T.SetIntPoint(&ip). */
570  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
571  const IntegrationPoint &ip) = 0;
572 
573  virtual ~MatrixCoefficient() { }
574 };
575 
577 {
578 private:
579  DenseMatrix mat;
580 public:
582  : MatrixCoefficient(m.Height(), m.Width()), mat(m) { }
585  const IntegrationPoint &ip) { M = mat; }
586 };
587 
589 {
590 private:
591  void (*Function)(const Vector &, DenseMatrix &);
592  void (*TDFunction)(const Vector &, double, DenseMatrix &);
593  Coefficient *Q;
594  DenseMatrix mat;
595 
596 public:
597  /// Construct a time-independent square matrix coefficient from a C-function
598  MatrixFunctionCoefficient(int dim, void (*F)(const Vector &, DenseMatrix &),
599  Coefficient *q = NULL)
600  : MatrixCoefficient(dim), Q(q)
601  {
602  Function = F;
603  TDFunction = NULL;
604  mat.SetSize(0);
605  }
606 
607  /// Construct a constant matrix coefficient times a scalar Coefficient
609  : MatrixCoefficient(m.Height(), m.Width()), Q(&q)
610  {
611  Function = NULL;
612  TDFunction = NULL;
613  mat = m;
614  }
615 
616  /// Construct a time-dependent square matrix coefficient from a C-function
618  void (*TDF)(const Vector &, double, DenseMatrix &),
619  Coefficient *q = NULL)
620  : MatrixCoefficient(dim), Q(q)
621  {
622  Function = NULL;
623  TDFunction = TDF;
624  mat.SetSize(0);
625  }
626 
627  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
628  const IntegrationPoint &ip);
629 
631 };
632 
634 {
635 private:
636  Array<Coefficient *> Coeff;
637  Array<bool> ownCoeff;
638 
639 public:
640 
641  explicit MatrixArrayCoefficient (int dim);
642 
643  Coefficient* GetCoeff (int i, int j) { return Coeff[i*width+j]; }
644 
645  void Set(int i, int j, Coefficient * c, bool own=true);
646 
647  double Eval(int i, int j, ElementTransformation &T, const IntegrationPoint &ip)
648  { return Coeff[i*width+j] ? Coeff[i*width+j] -> Eval(T, ip, GetTime()) : 0.0; }
649 
650  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
651  const IntegrationPoint &ip);
652 
653  virtual ~MatrixArrayCoefficient();
654 };
655 
656 /// MatrixCoefficient defined on a subset of domain or boundary attributes
658 {
659 private:
661  Array<int> active_attr;
662 
663 public:
665  : MatrixCoefficient(mc.GetHeight(), mc.GetWidth())
666  { c = &mc; attr.Copy(active_attr); }
667 
668  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
669  const IntegrationPoint &ip);
670 };
671 
672 /// Coefficients based on sums and products of other coefficients
673 
674 /// Scalar coefficient defined as the sum of two scalar coefficients
676 {
677 private:
678  Coefficient * a;
679  Coefficient * b;
680 
681  double alpha;
682  double beta;
683 
684 public:
685  // Result is _alpha * A + _beta * B
687  double _alpha = 1.0, double _beta = 1.0)
688  : a(&A), b(&B), alpha(_alpha), beta(_beta) { }
689 
690  /// Evaluate the coefficient
691  virtual double Eval(ElementTransformation &T,
692  const IntegrationPoint &ip)
693  { return alpha * a->Eval(T, ip) + beta * b->Eval(T, ip); }
694 };
695 
696 /// Scalar coefficient defined as the product of two scalar coefficients
698 {
699 private:
700  Coefficient * a;
701  Coefficient * b;
702 
703 public:
705  : a(&A), b(&B) { }
706 
707  /// Evaluate the coefficient
708  virtual double Eval(ElementTransformation &T,
709  const IntegrationPoint &ip)
710  { return a->Eval(T, ip) * b->Eval(T, ip); }
711 };
712 
713 /// Scalar coefficient defined as a scalar raised to a power
715 {
716 private:
717  Coefficient * a;
718 
719  double p;
720 
721 public:
722  // Result is A^p
724  : a(&A), p(_p) { }
725 
726  /// Evaluate the coefficient
727  virtual double Eval(ElementTransformation &T,
728  const IntegrationPoint &ip)
729  { return pow(a->Eval(T, ip), p); }
730 };
731 
732 /// Scalar coefficient defined as the inner product of two vector coefficients
734 {
735 private:
736  VectorCoefficient * a;
737  VectorCoefficient * b;
738 
739  mutable Vector va;
740  mutable Vector vb;
741 public:
743 
744  /// Evaluate the coefficient
745  virtual double Eval(ElementTransformation &T,
746  const IntegrationPoint &ip);
747 };
748 
749 /// Scalar coefficient defined as a cross product of two vectors in 2D
751 {
752 private:
753  VectorCoefficient * a;
754  VectorCoefficient * b;
755 
756  mutable Vector va;
757  mutable Vector vb;
758 
759 public:
761 
762  virtual double Eval(ElementTransformation &T,
763  const IntegrationPoint &ip);
764 };
765 
766 /// Scalar coefficient defined as the determinant of a matrix coefficient
768 {
769 private:
770  MatrixCoefficient * a;
771 
772  mutable DenseMatrix ma;
773 
774 public:
776 
777  /// Evaluate the coefficient
778  virtual double Eval(ElementTransformation &T,
779  const IntegrationPoint &ip);
780 };
781 
782 /// Vector coefficient defined as the sum of two vector coefficients
784 {
785 private:
786  VectorCoefficient * a;
787  VectorCoefficient * b;
788 
789  double alpha;
790  double beta;
791 
792  mutable Vector va;
793 
794 public:
795  // Result is _alpha * A + _beta * B
797  double _alpha = 1.0, double _beta = 1.0);
798 
799  /// Evaluate the coefficient
800  virtual void Eval(Vector &V, ElementTransformation &T,
801  const IntegrationPoint &ip);
803 };
804 
805 /// Vector coefficient defined as a product of a scalar and a vector
807 {
808 private:
809  Coefficient * a;
810  VectorCoefficient * b;
811 
812 public:
814 
815  virtual void Eval(Vector &V, ElementTransformation &T,
816  const IntegrationPoint &ip);
818 };
819 
820 /// Vector coefficient defined as a cross product of two vectors
822 {
823 private:
824  VectorCoefficient * a;
825  VectorCoefficient * b;
826 
827  mutable Vector va;
828  mutable Vector vb;
829 
830 public:
832 
833  virtual void Eval(Vector &V, ElementTransformation &T,
834  const IntegrationPoint &ip);
836 };
837 
838 /// Vector coefficient defined as a matrix vector product
840 {
841 private:
842  MatrixCoefficient * a;
843  VectorCoefficient * b;
844 
845  mutable DenseMatrix ma;
846  mutable Vector vb;
847 
848 public:
850 
851  virtual void Eval(Vector &V, ElementTransformation &T,
852  const IntegrationPoint &ip);
854 };
855 
856 /// Matrix coefficient defined as the identity of dimension d
858 {
859 private:
860  int dim;
861 
862 public:
864  : MatrixCoefficient(d, d), dim(d) { }
865 
866  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
867  const IntegrationPoint &ip);
868 };
869 
870 /// Matrix coefficient defined as the sum of two matrix coefficients
872 {
873 private:
874  MatrixCoefficient * a;
875  MatrixCoefficient * b;
876 
877  double alpha;
878  double beta;
879 
880  mutable DenseMatrix ma;
881 
882 public:
883  // Result is _alpha * A + _beta * B
885  double _alpha = 1.0, double _beta = 1.0);
886 
887  /// Evaluate the coefficient
888  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
889  const IntegrationPoint &ip);
890 };
891 
892 /// Matrix coefficient defined as a product of a scalar and a matrix
894 {
895 private:
896  Coefficient * a;
897  MatrixCoefficient * b;
898 
899 public:
901 
902  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
903  const IntegrationPoint &ip);
904 };
905 
906 /// Matrix coefficient defined as the transpose a matrix
908 {
909 private:
910  MatrixCoefficient * a;
911 
912 public:
914 
915  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
916  const IntegrationPoint &ip);
917 };
918 
919 /// Matrix coefficient defined as the inverse a matrix
921 {
922 private:
923  MatrixCoefficient * a;
924 
925 public:
927 
928  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
929  const IntegrationPoint &ip);
930 };
931 
932 /// Matrix coefficient defined as the outer product of two vectors
934 {
935 private:
936  VectorCoefficient * a;
937  VectorCoefficient * b;
938 
939  mutable Vector va;
940  mutable Vector vb;
941 
942 public:
944 
945  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
946  const IntegrationPoint &ip);
947 };
948 
949 /** Compute the Lp norm of a function f.
950  \f$ \| f \|_{Lp} = ( \int_\Omega | f |^p d\Omega)^{1/p} \f$ */
951 double ComputeLpNorm(double p, Coefficient &coeff, Mesh &mesh,
952  const IntegrationRule *irs[]);
953 
954 /** Compute the Lp norm of a vector function f = {f_i}_i=1...N.
955  \f$ \| f \|_{Lp} = ( \sum_i \| f_i \|_{Lp}^p )^{1/p} \f$ */
956 double ComputeLpNorm(double p, VectorCoefficient &coeff, Mesh &mesh,
957  const IntegrationRule *irs[]);
958 
959 #ifdef MFEM_USE_MPI
960 /** Compute the global Lp norm of a function f.
961  \f$ \| f \|_{Lp} = ( \int_\Omega | f |^p d\Omega)^{1/p} \f$ */
962 double ComputeGlobalLpNorm(double p, Coefficient &coeff, ParMesh &pmesh,
963  const IntegrationRule *irs[]);
964 
965 /** Compute the global Lp norm of a vector function f = {f_i}_i=1...N.
966  \f$ \| f \|_{Lp} = ( \sum_i \| f_i \|_{Lp}^p )^{1/p} \f$ */
967 double ComputeGlobalLpNorm(double p, VectorCoefficient &coeff, ParMesh &pmesh,
968  const IntegrationRule *irs[]);
969 #endif
970 
971 }
972 
973 #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:90
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:407
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:812
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:157
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.
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:153
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.
int dim
Definition: ex24.cpp:43
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:90
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)