MFEM  v4.2.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 <functional>
16 
17 #include "../config/config.hpp"
18 #include "../linalg/linalg.hpp"
19 #include "intrules.hpp"
20 #include "eltrans.hpp"
21 
22 namespace mfem
23 {
24 
25 class Mesh;
26 
27 #ifdef MFEM_USE_MPI
28 class ParMesh;
29 #endif
30 
31 
32 /** @brief Base class Coefficients that optionally depend on space and time.
33  These are used by the BilinearFormIntegrator, LinearFormIntegrator, and
34  NonlinearFormIntegrator classes to represent the physical coefficients in
35  the PDEs that are being discretized. This class can also be used in a more
36  general way to represent functions that don't necessarily belong to a FE
37  space, e.g., to project onto GridFunctions to use as initial conditions,
38  exact solutions, etc. See, e.g., ex4 or ex22 for these uses. */
40 {
41 protected:
42  double time;
43 
44 public:
45  Coefficient() { time = 0.; }
46 
47  /// Set the time for time dependent coefficients
48  void SetTime(double t) { time = t; }
49 
50  /// Get the time for time dependent coefficients
51  double GetTime() { return time; }
52 
53  /** @brief Evaluate the coefficient in the element described by @a T at the
54  point @a ip. */
55  /** @note When this method is called, the caller must make sure that the
56  IntegrationPoint associated with @a T is the same as @a ip. This can be
57  achieved by calling T.SetIntPoint(&ip). */
58  virtual double Eval(ElementTransformation &T,
59  const IntegrationPoint &ip) = 0;
60 
61  /** @brief Evaluate the coefficient in the element described by @a T at the
62  point @a ip at time @a t. */
63  /** @note When this method is called, the caller must make sure that the
64  IntegrationPoint associated with @a T is the same as @a ip. This can be
65  achieved by calling T.SetIntPoint(&ip). */
67  const IntegrationPoint &ip, double t)
68  {
69  SetTime(t);
70  return Eval(T, ip);
71  }
72 
73  virtual ~Coefficient() { }
74 };
75 
76 
77 /// A coefficient that is constant across space and time
79 {
80 public:
81  double constant;
82 
83  /// c is value of constant function
84  explicit ConstantCoefficient(double c = 1.0) { constant=c; }
85 
86  /// Evaluate the coefficient at @a ip.
87  virtual double Eval(ElementTransformation &T,
88  const IntegrationPoint &ip)
89  { return (constant); }
90 };
91 
92 /** @brief A piecewise constant coefficient with the constants keyed
93  off the element attribute numbers. */
95 {
96 private:
97  Vector constants;
98 
99 public:
100 
101  /// Constructs a piecewise constant coefficient in NumOfSubD subdomains
102  explicit PWConstCoefficient(int NumOfSubD = 0) : constants(NumOfSubD)
103  { constants = 0.0; }
104 
105  /// Construct the constant coefficient using a vector of constants.
106  /** @a c should be a vector defined by attributes, so for region with
107  attribute @a i @a c[i-1] is the coefficient in that region */
109  { constants.SetSize(c.Size()); constants=c; }
110 
111  /// Update the constants with vector @a c.
112  void UpdateConstants(Vector &c) { constants.SetSize(c.Size()); constants=c; }
113 
114  /// Return a reference to the i-th constant
115  double &operator()(int i) { return constants(i-1); }
116 
117  /// Set the constants for all attributes to constant @a c.
118  void operator=(double c) { constants = c; }
119 
120  /// Returns the number of constants representing different attributes.
121  int GetNConst() { return constants.Size(); }
122 
123  /// Evaluate the coefficient.
124  virtual double Eval(ElementTransformation &T,
125  const IntegrationPoint &ip);
126 };
127 
128 /// A general function coefficient
130 {
131 protected:
132  std::function<double(const Vector &)> Function;
133  std::function<double(const Vector &, double)> TDFunction;
134 
135 public:
136  /// Define a time-independent coefficient from a std function
137  /** \param F time-independent std::function */
138  FunctionCoefficient(std::function<double(const Vector &)> F)
139  : Function(std::move(F))
140  { }
141 
142  /// Define a time-dependent coefficient from a std function
143  /** \param TDF time-dependent function */
144  FunctionCoefficient(std::function<double(const Vector &, double)> TDF)
145  : TDFunction(std::move(TDF))
146  { }
147 
148  /// (DEPRECATED) Define a time-independent coefficient from a C-function
149  /** @deprecated Use the method where the C-function, @a f, uses a const
150  Vector argument instead of Vector. */
151  MFEM_DEPRECATED FunctionCoefficient(double (*f)(Vector &))
152  {
153  Function = reinterpret_cast<double(*)(const Vector&)>(f);
154  TDFunction = NULL;
155  }
156 
157  /// (DEPRECATED) Define a time-dependent coefficient from a C-function
158  /** @deprecated Use the method where the C-function, @a tdf, uses a const
159  Vector argument instead of Vector. */
160  MFEM_DEPRECATED FunctionCoefficient(double (*tdf)(Vector &, double))
161  {
162  Function = NULL;
163  TDFunction = reinterpret_cast<double(*)(const Vector&,double)>(tdf);
164  }
165 
166  /// Evaluate the coefficient at @a ip.
167  virtual double Eval(ElementTransformation &T,
168  const IntegrationPoint &ip);
169 };
170 
171 class GridFunction;
172 
173 /// Coefficient defined by a GridFunction. This coefficient is mesh dependent.
175 {
176 private:
177  const GridFunction *GridF;
178  int Component;
179 
180 public:
181  GridFunctionCoefficient() : GridF(NULL), Component(1) { }
182  /** Construct GridFunctionCoefficient from a given GridFunction, and
183  optionally specify a component to use if it is a vector GridFunction. */
184  GridFunctionCoefficient (const GridFunction *gf, int comp = 1)
185  { GridF = gf; Component = comp; }
186 
187  /// Set the internal GridFunction
188  void SetGridFunction(const GridFunction *gf) { GridF = gf; }
189 
190  /// Get the internal GridFunction
191  const GridFunction * GetGridFunction() const { return GridF; }
192 
193  /// Evaluate the coefficient at @a ip.
194  virtual double Eval(ElementTransformation &T,
195  const IntegrationPoint &ip);
196 };
197 
198 
199 /** @brief A coefficient that depends on 1 or 2 parent coefficients and a
200  transformation rule represented by a C-function.
201 
202  \f$ C(x,t) = T(Q1(x,t)) \f$ or \f$ C(x,t) = T(Q1(x,t), Q2(x,t)) \f$
203 
204  where T is the transformation rule, and Q1/Q2 are the parent coefficients.*/
206 {
207 private:
208  Coefficient * Q1;
209  Coefficient * Q2;
210  double (*Transform1)(double);
211  double (*Transform2)(double,double);
212 
213 public:
214  TransformedCoefficient (Coefficient * q,double (*F)(double))
215  : Q1(q), Transform1(F) { Q2 = 0; Transform2 = 0; }
217  double (*F)(double,double))
218  : Q1(q1), Q2(q2), Transform2(F) { Transform1 = 0; }
219 
220  /// Evaluate the coefficient at @a ip.
221  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip);
222 };
223 
224 /** @brief Delta function coefficient optionally multiplied by a weight
225  coefficient and a scaled time dependent C-function.
226 
227  \f$ F(x,t) = w(x,t) s T(t) d(x - xc) \f$
228 
229  where w is the optional weight coefficient, @a s is a scale factor
230  T is an optional time-dependent function and d is a delta function.
231 
232  WARNING this cannot be used as a normal coefficient. The usual Eval
233  method is disabled. */
235 {
236 protected:
237  double center[3], scale, tol;
239  int sdim;
240  double (*tdf)(double);
241 
242 public:
243 
244  /// Construct a unit delta function centered at (0.0,0.0,0.0)
246  {
247  center[0] = center[1] = center[2] = 0.; scale = 1.; tol = 1e-12;
248  weight = NULL; sdim = 0; tdf = NULL;
249  }
250 
251  /// Construct a delta function scaled by @a s and centered at (x,0.0,0.0)
252  DeltaCoefficient(double x, double s)
253  {
254  center[0] = x; center[1] = 0.; center[2] = 0.; scale = s; tol = 1e-12;
255  weight = NULL; sdim = 1; tdf = NULL;
256  }
257 
258  /// Construct a delta function scaled by @a s and centered at (x,y,0.0)
259  DeltaCoefficient(double x, double y, double s)
260  {
261  center[0] = x; center[1] = y; center[2] = 0.; scale = s; tol = 1e-12;
262  weight = NULL; sdim = 2; tdf = NULL;
263  }
264 
265  /// Construct a delta function scaled by @a s and centered at (x,y,z)
266  DeltaCoefficient(double x, double y, double z, double s)
267  {
268  center[0] = x; center[1] = y; center[2] = z; scale = s; tol = 1e-12;
269  weight = NULL; sdim = 3; tdf = NULL;
270  }
271 
272  /// Set the center location of the delta function.
273  void SetDeltaCenter(const Vector& center);
274 
275  /// Set the scale value multiplying the delta function.
276  void SetScale(double _s) { scale = _s; }
277 
278  /// Set a time-dependent function that multiplies the Scale().
279  void SetFunction(double (*f)(double)) { tdf = f; }
280 
281  /** @brief Set the tolerance used during projection onto GridFunction to
282  identify the Mesh vertex where the Center() of the delta function
283  lies. (default 1e-12)*/
284  void SetTol(double _tol) { tol = _tol; }
285 
286  /// Set a weight Coefficient that multiplies the DeltaCoefficient.
287  /** The weight Coefficient multiplies the value returned by EvalDelta() but
288  not the value returned by Scale().
289  The weight Coefficient is also used as the L2-weight function when
290  projecting the DeltaCoefficient onto a GridFunction, so that the weighted
291  integral of the projection is exactly equal to the Scale(). */
292  void SetWeight(Coefficient *w) { weight = w; }
293 
294  /// Return a pointer to a c-array representing the center of the delta
295  /// function.
296  const double *Center() { return center; }
297 
298  /** @brief Return the scale factor times the optional time dependent
299  function. Returns \f$ s T(t) \f$ with \f$ T(t) = 1 \f$ when
300  not set by the user. */
301  double Scale() { return tdf ? (*tdf)(GetTime())*scale : scale; }
302 
303  /// Return the tolerance used to identify the mesh vertices
304  double Tol() { return tol; }
305 
306  /// See SetWeight() for description of the weight Coefficient.
307  Coefficient *Weight() { return weight; }
308 
309  /// Write the center of the delta function into @a center.
311 
312  /// The value of the function assuming we are evaluating at the delta center.
313  virtual double EvalDelta(ElementTransformation &T, const IntegrationPoint &ip);
314  /** @brief A DeltaFunction cannot be evaluated. Calling this method will
315  cause an MFEM error, terminating the application. */
316  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
317  { mfem_error("DeltaCoefficient::Eval"); return 0.; }
318  virtual ~DeltaCoefficient() { delete weight; }
319 };
320 
321 /** @brief Derived coefficient that takes the value of the parent coefficient
322  for the active attributes and is zero otherwise. */
324 {
325 private:
326  Coefficient *c;
327  Array<int> active_attr;
328 
329 public:
330  /** @brief Construct with a parent coefficient and an array with
331  ones marking the attributes on which this coefficient should be
332  active. */
334  { c = &_c; attr.Copy(active_attr); }
335 
336  /// Evaluate the coefficient at @a ip.
337  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
338  { return active_attr[T.Attribute-1] ? c->Eval(T, ip, GetTime()) : 0.0; }
339 };
340 
341 /// Base class for vector Coefficients that optionally depend on time and space.
343 {
344 protected:
345  int vdim;
346  double time;
347 
348 public:
349  /// Initialize the VectorCoefficient with vector dimension @a vd.
350  VectorCoefficient(int vd) { vdim = vd; time = 0.; }
351 
352  /// Set the time for time dependent coefficients
353  void SetTime(double t) { time = t; }
354 
355  /// Get the time for time dependent coefficients
356  double GetTime() { return time; }
357 
358  /// Returns dimension of the vector.
359  int GetVDim() { return vdim; }
360 
361  /** @brief Evaluate the vector coefficient in the element described by @a T
362  at the point @a ip, storing the result in @a V. */
363  /** @note When this method is called, the caller must make sure that the
364  IntegrationPoint associated with @a T is the same as @a ip. This can be
365  achieved by calling T.SetIntPoint(&ip). */
366  virtual void Eval(Vector &V, ElementTransformation &T,
367  const IntegrationPoint &ip) = 0;
368 
369  /** @brief Evaluate the vector coefficient in the element described by @a T
370  at all points of @a ir, storing the result in @a M. */
371  /** The dimensions of @a M are GetVDim() by ir.GetNPoints() and they must be
372  set by the implementation of this method.
373 
374  The general implementation provided by the base class (using the Eval
375  method for one IntegrationPoint at a time) can be overloaded for more
376  efficient implementation.
377 
378  @note The IntegrationPoint associated with @a T is not used, and this
379  method will generally modify this IntegrationPoint associated with @a T.
380  */
381  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
382  const IntegrationRule &ir);
383 
384  virtual ~VectorCoefficient() { }
385 };
386 
387 
388 /// Vector coefficient that is constant in space and time.
390 {
391 private:
392  Vector vec;
393 public:
394  /// Construct the coefficient with constant vector @a v.
396  : VectorCoefficient(v.Size()), vec(v) { }
398 
399  /// Evaluate the vector coefficient at @a ip.
400  virtual void Eval(Vector &V, ElementTransformation &T,
401  const IntegrationPoint &ip) { V = vec; }
402 
403  /// Return a reference to the constant vector in this class.
404  const Vector& GetVec() { return vec; }
405 };
406 
407 /// A general vector function coefficient
409 {
410 private:
411  std::function<void(const Vector &, Vector &)> Function;
412  std::function<void(const Vector &, double, Vector &)> TDFunction;
413  Coefficient *Q;
414 
415 public:
416  /// Define a time-independent vector coefficient from a std function
417  /** \param dim - the size of the vector
418  \param F - time-independent function
419  \param q - optional scalar Coefficient to scale the vector coefficient */
421  std::function<void(const Vector &, Vector &)> F,
422  Coefficient *q = nullptr)
423  : VectorCoefficient(dim), Function(std::move(F)), Q(q)
424  { }
425 
426  /// Define a time-dependent vector coefficient from a std function
427  /** \param dim - the size of the vector
428  \param TDF - time-dependent function
429  \param q - optional scalar Coefficient to scale the vector coefficient */
431  std::function<void(const Vector &, double, Vector &)> TDF,
432  Coefficient *q = nullptr)
433  : VectorCoefficient(dim), TDFunction(std::move(TDF)), Q(q)
434  { }
435 
437  /// Evaluate the vector coefficient at @a ip.
438  virtual void Eval(Vector &V, ElementTransformation &T,
439  const IntegrationPoint &ip);
440 
442 };
443 
444 /** @brief Vector coefficient defined by an array of scalar coefficients.
445  Coefficients that are not set will evaluate to zero in the vector. This
446  object takes ownership of the array of coefficients inside it and deletes
447  them at object destruction. */
449 {
450 private:
451  Array<Coefficient*> Coeff;
452  Array<bool> ownCoeff;
453 
454 public:
455  /** @brief Construct vector of dim coefficients. The actual coefficients
456  still need to be added with Set(). */
457  explicit VectorArrayCoefficient(int dim);
458 
459  /// Returns i'th coefficient.
460  Coefficient* GetCoeff(int i) { return Coeff[i]; }
461 
462  /// Returns the entire array of coefficients.
463  Coefficient **GetCoeffs() { return Coeff; }
464 
465  /// Sets coefficient in the vector.
466  void Set(int i, Coefficient *c, bool own=true);
467 
468  /// Evaluates i'th component of the vector of coefficients and returns the
469  /// value.
470  double Eval(int i, ElementTransformation &T, const IntegrationPoint &ip)
471  { return Coeff[i] ? Coeff[i]->Eval(T, ip, GetTime()) : 0.0; }
472 
474  /** @brief Evaluate the coefficient. Each element of vector V comes from the
475  associated array of scalar coefficients. */
476  virtual void Eval(Vector &V, ElementTransformation &T,
477  const IntegrationPoint &ip);
478 
479  /// Destroys vector coefficient.
480  virtual ~VectorArrayCoefficient();
481 };
482 
483 /// Vector coefficient defined by a vector GridFunction
485 {
486 protected:
488 
489 public:
490  /** @brief Construct an empty coefficient. Calling Eval() before the grid
491  function is set will cause a segfault. */
493 
494  /** @brief Construct the coefficient with grid function @a gf. The
495  grid function is not owned by the coefficient. */
497 
498  /** @brief Set the grid function for this coefficient. Also sets the Vector
499  dimension to match that of the @a gf. */
500  void SetGridFunction(const GridFunction *gf);
501 
502  /// Returns a pointer to the grid function in this Coefficient
503  const GridFunction * GetGridFunction() const { return GridFunc; }
504 
505  /// Evaluate the vector coefficient at @a ip.
506  virtual void Eval(Vector &V, ElementTransformation &T,
507  const IntegrationPoint &ip);
508 
509  /** @brief Evaluate the vector coefficients at all of the locations in the
510  integration rule and write the vectors into the columns of matrix @a
511  M. */
512  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
513  const IntegrationRule &ir);
514 
516 };
517 
518 /// Vector coefficient defined as the Gradient of a scalar GridFunction
520 {
521 protected:
523 
524 public:
525 
526  /** @brief Construct the coefficient with a scalar grid function @a gf. The
527  grid function is not owned by the coefficient. */
529 
530  ///Set the scalar grid function.
531  void SetGridFunction(const GridFunction *gf);
532 
533  ///Get the scalar grid function.
534  const GridFunction * GetGridFunction() const { return GridFunc; }
535 
536  /// Evaluate the gradient vector coefficient at @a ip.
537  virtual void Eval(Vector &V, ElementTransformation &T,
538  const IntegrationPoint &ip);
539 
540  /** @brief Evaluate the gradient vector coefficient at all of the locations
541  in the integration rule and write the vectors into columns of matrix @a
542  M. */
543  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
544  const IntegrationRule &ir);
545 
547 };
548 
549 /// Vector coefficient defined as the Curl of a vector GridFunction
551 {
552 protected:
554 
555 public:
556  /** @brief Construct the coefficient with a vector grid function @a gf. The
557  grid function is not owned by the coefficient. */
559 
560  /// Set the vector grid function.
561  void SetGridFunction(const GridFunction *gf);
562 
563  /// Get the vector grid function.
564  const GridFunction * GetGridFunction() const { return GridFunc; }
565 
567  /// Evaluate the vector curl coefficient at @a ip.
568  virtual void Eval(Vector &V, ElementTransformation &T,
569  const IntegrationPoint &ip);
570 
572 };
573 
574 /// Scalar coefficient defined as the Divergence of a vector GridFunction
576 {
577 protected:
579 
580 public:
581  /** @brief Construct the coefficient with a vector grid function @a gf. The
582  grid function is not owned by the coefficient. */
584 
585  /// Set the vector grid function.
586  void SetGridFunction(const GridFunction *gf) { GridFunc = gf; }
587 
588  /// Get the vector grid function.
589  const GridFunction * GetGridFunction() const { return GridFunc; }
590 
591  /// Evaluate the scalar divergence coefficient at @a ip.
592  virtual double Eval(ElementTransformation &T,
593  const IntegrationPoint &ip);
594 
596 };
597 
598 /** @brief Vector coefficient defined by a scalar DeltaCoefficient and a
599  constant vector direction.
600 
601  WARNING this cannot be used as a normal coefficient. The usual Eval method
602  is disabled. */
604 {
605 protected:
608 
609 public:
610  /// Construct with a vector of dimension @a _vdim.
612  : VectorCoefficient(_vdim), dir(_vdim), d() { }
613 
614  /** @brief Construct with a Vector object representing the direction and a
615  unit delta function centered at (0.0,0.0,0.0) */
617  : VectorCoefficient(_dir.Size()), dir(_dir), d() { }
618 
619  /** @brief Construct with a Vector object representing the direction and a
620  delta function scaled by @a s and centered at (x,0.0,0.0) */
621  VectorDeltaCoefficient(const Vector& _dir, double x, double s)
622  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,s) { }
623 
624  /** @brief Construct with a Vector object representing the direction and a
625  delta function scaled by @a s and centered at (x,y,0.0) */
626  VectorDeltaCoefficient(const Vector& _dir, double x, double y, double s)
627  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,y,s) { }
628 
629  /** @brief Construct with a Vector object representing the direction and a
630  delta function scaled by @a s and centered at (x,y,z) */
631  VectorDeltaCoefficient(const Vector& _dir, double x, double y, double z,
632  double s)
633  : VectorCoefficient(_dir.Size()), dir(_dir), d(x,y,z,s) { }
634 
635  /// Replace the associated DeltaCoefficient with a new DeltaCoefficient.
636  /** The new DeltaCoefficient cannot have a specified weight Coefficient, i.e.
637  DeltaCoefficient::Weight() should return NULL. */
638  void SetDeltaCoefficient(const DeltaCoefficient& _d) { d = _d; }
639 
640  /// Return the associated scalar DeltaCoefficient.
642 
643  void SetScale(double s) { d.SetScale(s); }
644  void SetDirection(const Vector& _d);
645 
646  void SetDeltaCenter(const Vector& center) { d.SetDeltaCenter(center); }
647  void GetDeltaCenter(Vector& center) { d.GetDeltaCenter(center); }
648 
649  /** @brief Return the specified direction vector multiplied by the value
650  returned by DeltaCoefficient::EvalDelta() of the associated scalar
651  DeltaCoefficient. */
652  virtual void EvalDelta(Vector &V, ElementTransformation &T,
653  const IntegrationPoint &ip);
654 
656  /** @brief A VectorDeltaFunction cannot be evaluated. Calling this method
657  will cause an MFEM error, terminating the application. */
658  virtual void Eval(Vector &V, ElementTransformation &T,
659  const IntegrationPoint &ip)
660  { mfem_error("VectorDeltaCoefficient::Eval"); }
662 };
663 
664 /** @brief Derived vector coefficient that has the value of the parent vector
665  where it is active and is zero otherwise. */
667 {
668 private:
670  Array<int> active_attr;
671 
672 public:
673  /** @brief Construct with a parent vector coefficient and an array of zeros
674  and ones representing the attributes for which this coefficient should be
675  active. */
677  : VectorCoefficient(vc.GetVDim())
678  { c = &vc; attr.Copy(active_attr); }
679 
680  /// Evaluate the vector coefficient at @a ip.
681  virtual void Eval(Vector &V, ElementTransformation &T,
682  const IntegrationPoint &ip);
683 
684  /** @brief Evaluate the vector coefficient at all of the locations in the
685  integration rule and write the vectors into the columns of matrix @a
686  M. */
687  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
688  const IntegrationRule &ir);
689 };
690 
691 
692 /// Base class for Matrix Coefficients that optionally depend on time and space.
694 {
695 protected:
696  int height, width;
697  double time;
698  bool symmetric;
699 
700 public:
701  /// Construct a dim x dim matrix coefficient.
702  explicit MatrixCoefficient(int dim, bool symm=false)
703  { height = width = dim; time = 0.; symmetric = symm; }
704 
705  /// Construct a h x w matrix coefficient.
706  MatrixCoefficient(int h, int w, bool symm=false) :
707  height(h), width(w), time(0.), symmetric(symm) { }
708 
709  /// Set the time for time dependent coefficients
710  void SetTime(double t) { time = t; }
711 
712  /// Get the time for time dependent coefficients
713  double GetTime() { return time; }
714 
715  /// Get the height of the matrix.
716  int GetHeight() const { return height; }
717 
718  /// Get the width of the matrix.
719  int GetWidth() const { return width; }
720 
721  /// For backward compatibility get the width of the matrix.
722  int GetVDim() const { return width; }
723 
724  bool IsSymmetric() const { return symmetric; }
725 
726  /** @brief Evaluate the matrix coefficient in the element described by @a T
727  at the point @a ip, storing the result in @a K. */
728  /** @note When this method is called, the caller must make sure that the
729  IntegrationPoint associated with @a T is the same as @a ip. This can be
730  achieved by calling T.SetIntPoint(&ip). */
731  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
732  const IntegrationPoint &ip) = 0;
733 
734  /** @brief Evaluate the upper triangular entries of the matrix coefficient
735  in the symmetric case, similarly to Eval. Matrix entry (i,j) is stored
736  in K[j - i + os_i] for 0 <= i <= j < width, os_0 = 0,
737  os_{i+1} = os_i + width - i. That is, K = {M(0,0), ..., M(0,w-1),
738  M(1,1), ..., M(1,w-1), ..., M(w-1,w-1) with w = width. */
740  const IntegrationPoint &ip)
741  { mfem_error("MatrixCoefficient::EvalSymmetric"); }
742 
743  virtual ~MatrixCoefficient() { }
744 };
745 
746 
747 /// A matrix coefficient that is constant in space and time.
749 {
750 private:
751  DenseMatrix mat;
752 public:
753  ///Construct using matrix @a m for the constant.
755  : MatrixCoefficient(m.Height(), m.Width()), mat(m) { }
757  /// Evaluate the matrix coefficient at @a ip.
759  const IntegrationPoint &ip) { M = mat; }
760 };
761 
762 
763 /** @brief A matrix coefficient with an optional scalar coefficient multiplier
764  \a q. The matrix function can either be represented by a std function or
765  a constant matrix provided when constructing this object. */
767 {
768 private:
769  std::function<void(const Vector &, DenseMatrix &)> Function;
770  std::function<void(const Vector &, Vector &)> SymmFunction;
771  std::function<void(const Vector &, double, DenseMatrix &)> TDFunction;
772 
773  Coefficient *Q;
774  DenseMatrix mat;
775 
776 public:
777  /// Define a time-independent square matrix coefficient from a std function
778  /** \param dim - the size of the matrix
779  \param F - time-independent function
780  \param q - optional scalar Coefficient to scale the matrix coefficient */
782  std::function<void(const Vector &, DenseMatrix &)> F,
783  Coefficient *q = nullptr)
784  : MatrixCoefficient(dim), Function(std::move(F)), Q(q), mat(0)
785  { }
786 
787  /// Define a constant matrix coefficient times a scalar Coefficient
788  /** \param m - constant matrix
789  \param q - optional scalar Coefficient to scale the matrix coefficient */
791  : MatrixCoefficient(m.Height(), m.Width()), Q(&q), mat(m)
792  { }
793 
794  /// Define a time-dependent square matrix coefficient from a std function
795  /** \param dim - the size of the matrix
796  \param TDF - time-dependent function
797  \param q - optional scalar Coefficient to scale the matrix coefficient */
799  std::function<void(const Vector &, double, DenseMatrix &)> TDF,
800  Coefficient *q = nullptr)
801  : MatrixCoefficient(dim), TDFunction(std::move(TDF)), Q(q)
802  { }
803 
804  /** @brief Define a time-independent symmetric square matrix coefficient from
805  a std function */
806  /** \param dim - the size of the matrix
807  \param SymmF - function used in EvalSymmetric
808  \param q - optional scalar Coefficient to scale the matrix coefficient */
810  std::function<void(const Vector &, Vector &)> SymmF,
811  Coefficient *q = NULL)
812  : MatrixCoefficient(dim, true), SymmFunction(std::move(SymmF)), Q(q), mat(0)
813  { }
814 
815  /// Evaluate the matrix coefficient at @a ip.
816  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
817  const IntegrationPoint &ip);
818 
819  /// Evaluate the symmetric matrix coefficient at @a ip.
820  virtual void EvalSymmetric(Vector &K, ElementTransformation &T,
821  const IntegrationPoint &ip);
822 
824 };
825 
826 
827 
828 /** @brief Matrix coefficient defined by a matrix of scalar coefficients.
829  Coefficients that are not set will evaluate to zero in the vector. The
830  coefficient is stored as a flat Array with indexing (i,j) -> i*width+j. */
832 {
833 private:
834  Array<Coefficient *> Coeff;
835  Array<bool> ownCoeff;
836 
837 public:
838  /** @brief Construct a coefficient matrix of dimensions @a dim * @a dim. The
839  actual coefficients still need to be added with Set(). */
840  explicit MatrixArrayCoefficient (int dim);
841 
842  /// Get the coefficient located at (i,j) in the matrix.
843  Coefficient* GetCoeff (int i, int j) { return Coeff[i*width+j]; }
844 
845  /** @brief Set the coefficient located at (i,j) in the matrix. By default by
846  default this will take ownership of the Coefficient passed in, but this
847  can be overridden with the @a own parameter. */
848  void Set(int i, int j, Coefficient * c, bool own=true);
849 
850  /// Evaluate coefficient located at (i,j) in the matrix using integration
851  /// point @a ip.
852  double Eval(int i, int j, ElementTransformation &T, const IntegrationPoint &ip)
853  { return Coeff[i*width+j] ? Coeff[i*width+j] -> Eval(T, ip, GetTime()) : 0.0; }
854 
855  /// Evaluate the matrix coefficient @a ip.
856  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
857  const IntegrationPoint &ip);
858 
859  virtual ~MatrixArrayCoefficient();
860 };
861 
862 
863 /** @brief Derived matrix coefficient that has the value of the parent matrix
864  coefficient where it is active and is zero otherwise. */
866 {
867 private:
869  Array<int> active_attr;
870 
871 public:
872  /** @brief Construct with a parent matrix coefficient and an array of zeros
873  and ones representing the attributes for which this coefficient should be
874  active. */
876  : MatrixCoefficient(mc.GetHeight(), mc.GetWidth())
877  { c = &mc; attr.Copy(active_attr); }
878 
879  /// Evaluate the matrix coefficient at @a ip.
880  virtual void Eval(DenseMatrix &K, ElementTransformation &T,
881  const IntegrationPoint &ip);
882 };
883 
884 /// Coefficients based on sums, products, or other functions of coefficients.
885 ///@{
886 /** @brief Scalar coefficient defined as the linear combination of two scalar
887  coefficients or a scalar and a scalar coefficient */
889 {
890 private:
891  double aConst;
892  Coefficient * a;
893  Coefficient * b;
894 
895  double alpha;
896  double beta;
897 
898 public:
899  /// Constructor with one coefficient. Result is _alpha * A + _beta * B
901  double _alpha = 1.0, double _beta = 1.0)
902  : aConst(A), a(NULL), b(&B), alpha(_alpha), beta(_beta) { }
903 
904  /// Constructor with two coefficients. Result is _alpha * A + _beta * B.
906  double _alpha = 1.0, double _beta = 1.0)
907  : aConst(0.0), a(&A), b(&B), alpha(_alpha), beta(_beta) { }
908 
909  /// Reset the first term in the linear combination as a constant
910  void SetAConst(double A) { a = NULL; aConst = A; }
911  /// Return the first term in the linear combination
912  double GetAConst() const { return aConst; }
913 
914  /// Reset the first term in the linear combination
915  void SetACoef(Coefficient &A) { a = &A; }
916  /// Return the first term in the linear combination
917  Coefficient * GetACoef() const { return a; }
918 
919  /// Reset the second term in the linear combination
920  void SetBCoef(Coefficient &B) { b = &B; }
921  /// Return the second term in the linear combination
922  Coefficient * GetBCoef() const { return b; }
923 
924  /// Reset the factor in front of the first term in the linear combination
925  void SetAlpha(double _alpha) { alpha = _alpha; }
926  /// Return the factor in front of the first term in the linear combination
927  double GetAlpha() const { return alpha; }
928 
929  /// Reset the factor in front of the second term in the linear combination
930  void SetBeta(double _beta) { beta = _beta; }
931  /// Return the factor in front of the second term in the linear combination
932  double GetBeta() const { return beta; }
933 
934  /// Evaluate the coefficient at @a ip.
935  virtual double Eval(ElementTransformation &T,
936  const IntegrationPoint &ip)
937  {
938  return alpha * ((a == NULL ) ? aConst : a->Eval(T, ip) )
939  + beta * b->Eval(T, ip);
940  }
941 };
942 
943 /** @brief Scalar coefficient defined as the product of two scalar coefficients
944  or a scalar and a scalar coefficient. */
946 {
947 private:
948  double aConst;
949  Coefficient * a;
950  Coefficient * b;
951 
952 public:
953  /// Constructor with one coefficient. Result is A * B.
955  : aConst(A), a(NULL), b(&B) { }
956 
957  /// Constructor with two coefficients. Result is A * B.
959  : aConst(0.0), a(&A), b(&B) { }
960 
961  /// Reset the first term in the product as a constant
962  void SetAConst(double A) { a = NULL; aConst = A; }
963  /// Return the first term in the product
964  double GetAConst() const { return aConst; }
965 
966  /// Reset the first term in the product
967  void SetACoef(Coefficient &A) { a = &A; }
968  /// Return the first term in the product
969  Coefficient * GetACoef() const { return a; }
970 
971  /// Reset the second term in the product
972  void SetBCoef(Coefficient &B) { b = &B; }
973  /// Return the second term in the product
974  Coefficient * GetBCoef() const { return b; }
975 
976  /// Evaluate the coefficient at @a ip.
977  virtual double Eval(ElementTransformation &T,
978  const IntegrationPoint &ip)
979  { return ((a == NULL ) ? aConst : a->Eval(T, ip) ) * b->Eval(T, ip); }
980 };
981 
982 /** @brief Scalar coefficient defined as the ratio of two scalars where one or
983  both scalars are scalar coefficients. */
985 {
986 private:
987  double aConst;
988  double bConst;
989  Coefficient * a;
990  Coefficient * b;
991 
992 public:
993  /** Initialize a coefficient which returns A / B where @a A is a
994  constant and @a B is a scalar coefficient */
996  : aConst(A), bConst(1.0), a(NULL), b(&B) { }
997  /** Initialize a coefficient which returns A / B where @a A and @a B are both
998  scalar coefficients */
1000  : aConst(0.0), bConst(1.0), a(&A), b(&B) { }
1001  /** Initialize a coefficient which returns A / B where @a A is a
1002  scalar coefficient and @a B is a constant */
1004  : aConst(0.0), bConst(B), a(&A), b(NULL) { }
1005 
1006  /// Reset the numerator in the ratio as a constant
1007  void SetAConst(double A) { a = NULL; aConst = A; }
1008  /// Return the numerator of the ratio
1009  double GetAConst() const { return aConst; }
1010 
1011  /// Reset the denominator in the ratio as a constant
1012  void SetBConst(double B) { b = NULL; bConst = B; }
1013  /// Return the denominator of the ratio
1014  double GetBConst() const { return bConst; }
1015 
1016  /// Reset the numerator in the ratio
1017  void SetACoef(Coefficient &A) { a = &A; }
1018  /// Return the numerator of the ratio
1019  Coefficient * GetACoef() const { return a; }
1020 
1021  /// Reset the denominator in the ratio
1022  void SetBCoef(Coefficient &B) { b = &B; }
1023  /// Return the denominator of the ratio
1024  Coefficient * GetBCoef() const { return b; }
1025 
1026  /// Evaluate the coefficient
1027  virtual double Eval(ElementTransformation &T,
1028  const IntegrationPoint &ip)
1029  {
1030  double den = (b == NULL ) ? bConst : b->Eval(T, ip);
1031  MFEM_ASSERT(den != 0.0, "Division by zero in RatioCoefficient");
1032  return ((a == NULL ) ? aConst : a->Eval(T, ip) ) / den;
1033  }
1034 };
1035 
1036 /// Scalar coefficient defined as a scalar raised to a power
1038 {
1039 private:
1040  Coefficient * a;
1041 
1042  double p;
1043 
1044 public:
1045  /// Construct with a coefficient and a constant power @a _p. Result is A^p.
1047  : a(&A), p(_p) { }
1048 
1049  /// Reset the base coefficient
1050  void SetACoef(Coefficient &A) { a = &A; }
1051  /// Return the base coefficient
1052  Coefficient * GetACoef() const { return a; }
1053 
1054  /// Reset the exponent
1055  void SetExponent(double _p) { p = _p; }
1056  /// Return the exponent
1057  double GetExponent() const { return p; }
1058 
1059  /// Evaluate the coefficient at @a ip.
1060  virtual double Eval(ElementTransformation &T,
1061  const IntegrationPoint &ip)
1062  { return pow(a->Eval(T, ip), p); }
1063 };
1064 
1065 
1066 /// Scalar coefficient defined as the inner product of two vector coefficients
1068 {
1069 private:
1070  VectorCoefficient * a;
1071  VectorCoefficient * b;
1072 
1073  mutable Vector va;
1074  mutable Vector vb;
1075 public:
1076  /// Construct with the two vector coefficients. Result is \f$ A \cdot B \f$.
1078 
1079  /// Reset the first vector in the inner product
1080  void SetACoef(VectorCoefficient &A) { a = &A; }
1081  /// Return the first vector coefficient in the inner product
1082  VectorCoefficient * GetACoef() const { return a; }
1083 
1084  /// Reset the second vector in the inner product
1085  void SetBCoef(VectorCoefficient &B) { b = &B; }
1086  /// Return the second vector coefficient in the inner product
1087  VectorCoefficient * GetBCoef() const { return b; }
1088 
1089  /// Evaluate the coefficient at @a ip.
1090  virtual double Eval(ElementTransformation &T,
1091  const IntegrationPoint &ip);
1092 };
1093 
1094 /// Scalar coefficient defined as a cross product of two vectors in the xy-plane.
1096 {
1097 private:
1098  VectorCoefficient * a;
1099  VectorCoefficient * b;
1100 
1101  mutable Vector va;
1102  mutable Vector vb;
1103 
1104 public:
1105  /// Constructor with two vector coefficients. Result is \f$ A_x B_y - A_y * B_x; \f$.
1107 
1108  /// Reset the first vector in the product
1109  void SetACoef(VectorCoefficient &A) { a = &A; }
1110  /// Return the first vector of the product
1111  VectorCoefficient * GetACoef() const { return a; }
1112 
1113  /// Reset the second vector in the product
1114  void SetBCoef(VectorCoefficient &B) { b = &B; }
1115  /// Return the second vector of the product
1116  VectorCoefficient * GetBCoef() const { return b; }
1117 
1118  /// Evaluate the coefficient at @a ip.
1119  virtual double Eval(ElementTransformation &T,
1120  const IntegrationPoint &ip);
1121 };
1122 
1123 /// Scalar coefficient defined as the determinant of a matrix coefficient
1125 {
1126 private:
1127  MatrixCoefficient * a;
1128 
1129  mutable DenseMatrix ma;
1130 
1131 public:
1132  /// Construct with the matrix.
1134 
1135  /// Reset the matrix coefficient
1136  void SetACoef(MatrixCoefficient &A) { a = &A; }
1137  /// Return the matrix coefficient
1138  MatrixCoefficient * GetACoef() const { return a; }
1139 
1140  /// Evaluate the determinant coefficient at @a ip.
1141  virtual double Eval(ElementTransformation &T,
1142  const IntegrationPoint &ip);
1143 };
1144 
1145 /// Vector coefficient defined as the linear combination of two vectors
1147 {
1148 private:
1149  VectorCoefficient * ACoef;
1150  VectorCoefficient * BCoef;
1151 
1152  Vector A;
1153  Vector B;
1154 
1155  Coefficient * alphaCoef;
1156  Coefficient * betaCoef;
1157 
1158  double alpha;
1159  double beta;
1160 
1161  mutable Vector va;
1162 
1163 public:
1164  /** Constructor with no coefficients.
1165  To be used with the various "Set" methods */
1166  VectorSumCoefficient(int dim);
1167 
1168  /** Constructor with two vector coefficients.
1169  Result is _alpha * A + _beta * B */
1171  double _alpha = 1.0, double _beta = 1.0);
1172 
1173  /** Constructor with scalar coefficients.
1174  Result is _alpha * _A + _beta * _B */
1176  Coefficient &_alpha, Coefficient &_beta);
1177 
1178  /// Reset the first vector coefficient
1179  void SetACoef(VectorCoefficient &A) { ACoef = &A; }
1180  /// Return the first vector coefficient
1181  VectorCoefficient * GetACoef() const { return ACoef; }
1182 
1183  /// Reset the second vector coefficient
1184  void SetBCoef(VectorCoefficient &B) { BCoef = &B; }
1185  /// Return the second vector coefficient
1186  VectorCoefficient * GetBCoef() const { return BCoef; }
1187 
1188  /// Reset the factor in front of the first vector coefficient
1189  void SetAlphaCoef(Coefficient &A) { alphaCoef = &A; }
1190  /// Return the factor in front of the first vector coefficient
1191  Coefficient * GetAlphaCoef() const { return alphaCoef; }
1192 
1193  /// Reset the factor in front of the second vector coefficient
1194  void SetBetaCoef(Coefficient &B) { betaCoef = &B; }
1195  /// Return the factor in front of the second vector coefficient
1196  Coefficient * GetBetaCoef() const { return betaCoef; }
1197 
1198  /// Reset the first vector as a constant
1199  void SetA(const Vector &_A) { A = _A; ACoef = NULL; }
1200  /// Return the first vector constant
1201  const Vector & GetA() const { return A; }
1202 
1203  /// Reset the second vector as a constant
1204  void SetB(const Vector &_B) { B = _B; BCoef = NULL; }
1205  /// Return the second vector constant
1206  const Vector & GetB() const { return B; }
1207 
1208  /// Reset the factor in front of the first vector coefficient as a constant
1209  void SetAlpha(double _alpha) { alpha = _alpha; alphaCoef = NULL; }
1210  /// Return the factor in front of the first vector coefficient
1211  double GetAlpha() const { return alpha; }
1212 
1213  /// Reset the factor in front of the second vector coefficient as a constant
1214  void SetBeta(double _beta) { beta = _beta; betaCoef = NULL; }
1215  /// Return the factor in front of the second vector coefficient
1216  double GetBeta() const { return beta; }
1217 
1218  /// Evaluate the coefficient at @a ip.
1219  virtual void Eval(Vector &V, ElementTransformation &T,
1220  const IntegrationPoint &ip);
1222 };
1223 
1224 /// Vector coefficient defined as a product of scalar and vector coefficients.
1226 {
1227 private:
1228  double aConst;
1229  Coefficient * a;
1230  VectorCoefficient * b;
1231 
1232 public:
1233  /// Constructor with constant and vector coefficient. Result is A * B.
1235 
1236  /// Constructor with two coefficients. Result is A * B.
1238 
1239  /// Reset the scalar factor as a constant
1240  void SetAConst(double A) { a = NULL; aConst = A; }
1241  /// Return the scalar factor
1242  double GetAConst() const { return aConst; }
1243 
1244  /// Reset the scalar factor
1245  void SetACoef(Coefficient &A) { a = &A; }
1246  /// Return the scalar factor
1247  Coefficient * GetACoef() const { return a; }
1248 
1249  /// Reset the vector factor
1250  void SetBCoef(VectorCoefficient &B) { b = &B; }
1251  /// Return the vector factor
1252  VectorCoefficient * GetBCoef() const { return b; }
1253 
1254  /// Evaluate the coefficient at @a ip.
1255  virtual void Eval(Vector &V, ElementTransformation &T,
1256  const IntegrationPoint &ip);
1258 };
1259 
1260 /// Vector coefficient defined as a normalized vector field (returns v/|v|)
1262 {
1263 private:
1264  VectorCoefficient * a;
1265 
1266  double tol;
1267 
1268 public:
1269  /** @brief Return a vector normalized to a length of one
1270 
1271  This class evaluates the vector coefficient @a A and, if |A| > @a tol,
1272  returns the normalized vector A / |A|. If |A| <= @a tol, the zero
1273  vector is returned.
1274  */
1275  NormalizedVectorCoefficient(VectorCoefficient &A, double tol = 1e-6);
1276 
1277  /// Reset the vector coefficient
1278  void SetACoef(VectorCoefficient &A) { a = &A; }
1279  /// Return the vector coefficient
1280  VectorCoefficient * GetACoef() const { return a; }
1281 
1282  /// Evaluate the coefficient at @a ip.
1283  virtual void Eval(Vector &V, ElementTransformation &T,
1284  const IntegrationPoint &ip);
1286 };
1287 
1288 /// Vector coefficient defined as a cross product of two vectors
1290 {
1291 private:
1292  VectorCoefficient * a;
1293  VectorCoefficient * b;
1294 
1295  mutable Vector va;
1296  mutable Vector vb;
1297 
1298 public:
1299  /// Construct with the two coefficients. Result is A x B.
1301 
1302  /// Reset the first term in the product
1303  void SetACoef(VectorCoefficient &A) { a = &A; }
1304  /// Return the first term in the product
1305  VectorCoefficient * GetACoef() const { return a; }
1306 
1307  /// Reset the second term in the product
1308  void SetBCoef(VectorCoefficient &B) { b = &B; }
1309  /// Return the second term in the product
1310  VectorCoefficient * GetBCoef() const { return b; }
1311 
1312  /// Evaluate the coefficient at @a ip.
1313  virtual void Eval(Vector &V, ElementTransformation &T,
1314  const IntegrationPoint &ip);
1316 };
1317 
1318 /** @brief Vector coefficient defined as a product of a matrix coefficient and
1319  a vector coefficient. */
1321 {
1322 private:
1323  MatrixCoefficient * a;
1324  VectorCoefficient * b;
1325 
1326  mutable DenseMatrix ma;
1327  mutable Vector vb;
1328 
1329 public:
1330  /// Constructor with two coefficients. Result is A*B.
1332 
1333  /// Reset the matrix coefficient
1334  void SetACoef(MatrixCoefficient &A) { a = &A; }
1335  /// Return the matrix coefficient
1336  MatrixCoefficient * GetACoef() const { return a; }
1337 
1338  /// Reset the vector coefficient
1339  void SetBCoef(VectorCoefficient &B) { b = &B; }
1340  /// Return the vector coefficient
1341  VectorCoefficient * GetBCoef() const { return b; }
1342 
1343  /// Evaluate the vector coefficient at @a ip.
1344  virtual void Eval(Vector &V, ElementTransformation &T,
1345  const IntegrationPoint &ip);
1347 };
1348 
1349 /// Convenient alias for the MatrixVectorProductCoefficient
1351 
1352 /// Constant matrix coefficient defined as the identity of dimension d
1354 {
1355 private:
1356  int dim;
1357 
1358 public:
1359  /// Construct with the dimension of the square identity matrix.
1361  : MatrixCoefficient(d, d), dim(d) { }
1362 
1363  /// Evaluate the matrix coefficient at @a ip.
1364  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
1365  const IntegrationPoint &ip);
1366 };
1367 
1368 /// Matrix coefficient defined as the linear combination of two matrices
1370 {
1371 private:
1372  MatrixCoefficient * a;
1373  MatrixCoefficient * b;
1374 
1375  double alpha;
1376  double beta;
1377 
1378  mutable DenseMatrix ma;
1379 
1380 public:
1381  /// Construct with the two coefficients. Result is _alpha * A + _beta * B.
1383  double _alpha = 1.0, double _beta = 1.0);
1384 
1385  /// Reset the first matrix coefficient
1386  void SetACoef(MatrixCoefficient &A) { a = &A; }
1387  /// Return the first matrix coefficient
1388  MatrixCoefficient * GetACoef() const { return a; }
1389 
1390  /// Reset the second matrix coefficient
1391  void SetBCoef(MatrixCoefficient &B) { b = &B; }
1392  /// Return the second matrix coefficient
1393  MatrixCoefficient * GetBCoef() const { return b; }
1394 
1395  /// Reset the factor in front of the first matrix coefficient
1396  void SetAlpha(double _alpha) { alpha = _alpha; }
1397  /// Return the factor in front of the first matrix coefficient
1398  double GetAlpha() const { return alpha; }
1399 
1400  /// Reset the factor in front of the second matrix coefficient
1401  void SetBeta(double _beta) { beta = _beta; }
1402  /// Return the factor in front of the second matrix coefficient
1403  double GetBeta() const { return beta; }
1404 
1405  /// Evaluate the matrix coefficient at @a ip.
1406  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
1407  const IntegrationPoint &ip);
1408 };
1409 
1410 /** @brief Matrix coefficient defined as a product of a scalar coefficient and a
1411  matrix coefficient.*/
1413 {
1414 private:
1415  double aConst;
1416  Coefficient * a;
1417  MatrixCoefficient * b;
1418 
1419 public:
1420  /// Constructor with one coefficient. Result is A*B.
1422 
1423  /// Constructor with two coefficients. Result is A*B.
1425 
1426  /// Reset the scalar factor as a constant
1427  void SetAConst(double A) { a = NULL; aConst = A; }
1428  /// Return the scalar factor
1429  double GetAConst() const { return aConst; }
1430 
1431  /// Reset the scalar factor
1432  void SetACoef(Coefficient &A) { a = &A; }
1433  /// Return the scalar factor
1434  Coefficient * GetACoef() const { return a; }
1435 
1436  /// Reset the matrix factor
1437  void SetBCoef(MatrixCoefficient &B) { b = &B; }
1438  /// Return the matrix factor
1439  MatrixCoefficient * GetBCoef() const { return b; }
1440 
1441  /// Evaluate the matrix coefficient at @a ip.
1442  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
1443  const IntegrationPoint &ip);
1444 };
1445 
1446 /// Matrix coefficient defined as the transpose a matrix coefficient
1448 {
1449 private:
1450  MatrixCoefficient * a;
1451 
1452 public:
1453  /// Construct with the matrix coefficient. Result is \f$ A^T \f$.
1455 
1456  /// Reset the matrix coefficient
1457  void SetACoef(MatrixCoefficient &A) { a = &A; }
1458  /// Return the matrix coefficient
1459  MatrixCoefficient * GetACoef() const { return a; }
1460 
1461  /// Evaluate the matrix coefficient at @a ip.
1462  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
1463  const IntegrationPoint &ip);
1464 };
1465 
1466 /// Matrix coefficient defined as the inverse a matrix coefficient.
1468 {
1469 private:
1470  MatrixCoefficient * a;
1471 
1472 public:
1473  /// Construct with the matrix coefficient. Result is \f$ A^{-1} \f$.
1475 
1476  /// Reset the matrix coefficient
1477  void SetACoef(MatrixCoefficient &A) { a = &A; }
1478  /// Return the matrix coefficient
1479  MatrixCoefficient * GetACoef() const { return a; }
1480 
1481  /// Evaluate the matrix coefficient at @a ip.
1482  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
1483  const IntegrationPoint &ip);
1484 };
1485 
1486 /// Matrix coefficient defined as the outer product of two vector coefficients.
1488 {
1489 private:
1490  VectorCoefficient * a;
1491  VectorCoefficient * b;
1492 
1493  mutable Vector va;
1494  mutable Vector vb;
1495 
1496 public:
1497  /// Construct with two vector coefficients. Result is \f$ A B^T \f$.
1499 
1500  /// Reset the first vector in the outer product
1501  void SetACoef(VectorCoefficient &A) { a = &A; }
1502  /// Return the first vector coefficient in the outer product
1503  VectorCoefficient * GetACoef() const { return a; }
1504 
1505  /// Reset the second vector in the outer product
1506  void SetBCoef(VectorCoefficient &B) { b = &B; }
1507  /// Return the second vector coefficient in the outer product
1508  VectorCoefficient * GetBCoef() const { return b; }
1509 
1510  /// Evaluate the matrix coefficient at @a ip.
1511  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
1512  const IntegrationPoint &ip);
1513 };
1514 
1515 /** @brief Matrix coefficient defined as -a k x k x, for a vector k and scalar a
1516 
1517  This coefficient returns \f$a * (|k|^2 I - k \otimes k)\f$, where I is
1518  the identity matrix and \f$\otimes\f$ indicates the outer product. This
1519  can be evaluated for vectors of any dimension but in three
1520  dimensions it corresponds to computing the cross product with k twice.
1521 */
1523 {
1524 private:
1525  double aConst;
1526  Coefficient * a;
1527  VectorCoefficient * k;
1528 
1529  mutable Vector vk;
1530 
1531 public:
1534 
1535  /// Reset the scalar factor as a constant
1536  void SetAConst(double A) { a = NULL; aConst = A; }
1537  /// Return the scalar factor
1538  double GetAConst() const { return aConst; }
1539 
1540  /// Reset the scalar factor
1541  void SetACoef(Coefficient &A) { a = &A; }
1542  /// Return the scalar factor
1543  Coefficient * GetACoef() const { return a; }
1544 
1545  /// Reset the vector factor
1546  void SetKCoef(VectorCoefficient &K) { k = &K; }
1547  /// Return the vector factor
1548  VectorCoefficient * GetKCoef() const { return k; }
1549 
1550  /// Evaluate the matrix coefficient at @a ip.
1551  virtual void Eval(DenseMatrix &M, ElementTransformation &T,
1552  const IntegrationPoint &ip);
1553 };
1554 ///@}
1555 
1556 class QuadratureFunction;
1557 
1558 /** @brief Vector quadrature function coefficient which requires that the
1559  quadrature rules used for this vector coefficient be the same as those that
1560  live within the supplied QuadratureFunction. */
1562 {
1563 private:
1564  const QuadratureFunction &QuadF; //do not own
1565  int index;
1566 
1567 public:
1568  /// Constructor with a quadrature function as input
1570 
1571  /** Set the starting index within the QuadFunc that'll be used to project
1572  outwards as well as the corresponding length. The projected length should
1573  have the bounds of 1 <= length <= (length QuadFunc - index). */
1574  void SetComponent(int _index, int _length);
1575 
1576  const QuadratureFunction& GetQuadFunction() const { return QuadF; }
1577 
1579  virtual void Eval(Vector &V, ElementTransformation &T,
1580  const IntegrationPoint &ip);
1581 
1583 };
1584 
1585 /** @brief Quadrature function coefficient which requires that the quadrature
1586  rules used for this coefficient be the same as those that live within the
1587  supplied QuadratureFunction. */
1589 {
1590 private:
1591  const QuadratureFunction &QuadF;
1592 
1593 public:
1594  /// Constructor with a quadrature function as input
1596 
1597  const QuadratureFunction& GetQuadFunction() const { return QuadF; }
1598 
1599  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip);
1600 
1602 };
1603 
1604 /** @brief Compute the Lp norm of a function f.
1605  \f$ \| f \|_{Lp} = ( \int_\Omega | f |^p d\Omega)^{1/p} \f$ */
1606 double ComputeLpNorm(double p, Coefficient &coeff, Mesh &mesh,
1607  const IntegrationRule *irs[]);
1608 
1609 /** @brief Compute the Lp norm of a vector function f = {f_i}_i=1...N.
1610  \f$ \| f \|_{Lp} = ( \sum_i \| f_i \|_{Lp}^p )^{1/p} \f$ */
1611 double ComputeLpNorm(double p, VectorCoefficient &coeff, Mesh &mesh,
1612  const IntegrationRule *irs[]);
1613 
1614 #ifdef MFEM_USE_MPI
1615 /** @brief Compute the global Lp norm of a function f.
1616  \f$ \| f \|_{Lp} = ( \int_\Omega | f |^p d\Omega)^{1/p} \f$ */
1617 double ComputeGlobalLpNorm(double p, Coefficient &coeff, ParMesh &pmesh,
1618  const IntegrationRule *irs[]);
1619 
1620 /** @brief Compute the global Lp norm of a vector function f = {f_i}_i=1...N.
1621  \f$ \| f \|_{Lp} = ( \sum_i \| f_i \|_{Lp}^p )^{1/p} \f$ */
1622 double ComputeGlobalLpNorm(double p, VectorCoefficient &coeff, ParMesh &pmesh,
1623  const IntegrationRule *irs[]);
1624 #endif
1625 
1626 }
1627 
1628 #endif
FunctionCoefficient(std::function< double(const Vector &)> F)
Define a time-independent coefficient from a std function.
Vector coefficient defined as a cross product of two vectors.
double GetAConst() const
Return the first term in the product.
A coefficient that depends on 1 or 2 parent coefficients and a transformation rule represented by a C...
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient at ip.
RatioCoefficient(Coefficient &A, Coefficient &B)
A matrix coefficient that is constant in space and time.
void SetACoef(Coefficient &A)
Reset the scalar factor.
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:66
void GetDeltaCenter(Vector &center)
VectorCoefficient * GetACoef() const
Return the first vector coefficient in the inner product.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
void SetTol(double _tol)
Set the tolerance used during projection onto GridFunction to identify the Mesh vertex where the Cent...
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:90
Vector coefficient defined by an array of scalar coefficients. Coefficients that are not set will eva...
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
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
Coefficient * GetBCoef() const
Return the second term in the product.
MatrixFunctionCoefficient(int dim, std::function< void(const Vector &, double, DenseMatrix &)> TDF, Coefficient *q=nullptr)
Define a time-dependent square matrix coefficient from a std function.
void SetBeta(double _beta)
Reset the factor in front of the second matrix coefficient.
Coefficient * GetACoef() const
Return the scalar factor.
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...
IdentityMatrixCoefficient(int d)
Construct with the dimension of the square identity matrix.
VectorCoefficient * GetACoef() const
Return the vector coefficient.
PWConstCoefficient(Vector &c)
Construct the constant coefficient using a vector of constants.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
void SetWeight(Coefficient *w)
Set a weight Coefficient that multiplies the DeltaCoefficient.
Base class for vector Coefficients that optionally depend on time and space.
A coefficient that is constant across space and time.
Definition: coefficient.hpp:78
Coefficient ** GetCoeffs()
Returns the entire array of coefficients.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector curl coefficient at ip.
void SetAConst(double A)
Reset the first term in the product as a constant.
TransposeMatrixCoefficient(MatrixCoefficient &A)
Construct with the matrix coefficient. Result is .
double GetBConst() const
Return the denominator of the ratio.
void SetBCoef(VectorCoefficient &B)
Reset the second vector coefficient.
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)
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.
Scalar coefficient defined as the inner product of two vector coefficients.
NormalizedVectorCoefficient(VectorCoefficient &A, double tol=1e-6)
Return a vector normalized to a length of one.
void SetBCoef(MatrixCoefficient &B)
Reset the matrix factor.
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:459
void SetKCoef(VectorCoefficient &K)
Reset the vector factor.
MatrixVectorProductCoefficient(MatrixCoefficient &A, VectorCoefficient &B)
Constructor with two coefficients. Result is A*B.
double Eval(int i, ElementTransformation &T, const IntegrationPoint &ip)
void SetDeltaCenter(const Vector &center)
Set the center location of the delta function.
Definition: coefficient.cpp:69
MatrixCoefficient(int h, int w, bool symm=false)
Construct a h x w matrix coefficient.
double Scale()
Return the scale factor times the optional time dependent function. Returns with when not set by th...
MatrixCoefficient * GetBCoef() const
Return the matrix factor.
Vector quadrature function coefficient which requires that the quadrature rules used for this vector ...
void SetACoef(Coefficient &A)
Reset the numerator in the ratio.
Vector coefficient that is constant in space and time.
void SetAlpha(double _alpha)
Reset the factor in front of the first term in the linear combination.
Scalar coefficient defined as a cross product of two vectors in the xy-plane.
double GetTime()
Get the time for time dependent coefficients.
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
Scalar coefficient defined as the product of two scalar coefficients or a scalar and a scalar coeffic...
void SetBCoef(VectorCoefficient &B)
Reset the second term in the product.
SumCoefficient(Coefficient &A, Coefficient &B, double _alpha=1.0, double _beta=1.0)
Constructor with two coefficients. Result is _alpha * A + _beta * B.
void Copy(Array &copy) const
Create a copy of the internal array to the provided copy.
Definition: array.hpp:831
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
Coefficient * GetBCoef() const
Return the denominator of the ratio.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
double & operator()(int i)
Return a reference to the i-th constant.
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
Delta function coefficient optionally multiplied by a weight coefficient and a scaled time dependent ...
int Size() const
Returns the size of the vector.
Definition: vector.hpp:160
void SetFunction(double(*f)(double))
Set a time-dependent function that multiplies the Scale().
Scalar coefficient defined as the ratio of two scalars where one or both scalars are scalar coefficie...
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...
Matrix coefficient defined by a matrix of scalar coefficients. Coefficients that are not set will eva...
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 double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
double Tol()
Return the tolerance used to identify the mesh vertices.
void SetExponent(double _p)
Reset the exponent.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
void SetGridFunction(const GridFunction *gf)
Set the vector grid function.
Vector coefficient defined as the linear combination of two vectors.
void SetACoef(VectorCoefficient &A)
Reset the first vector coefficient.
MFEM_DEPRECATED FunctionCoefficient(double(*f)(Vector &))
(DEPRECATED) Define a time-independent coefficient from a C-function
Matrix coefficient defined as a product of a scalar coefficient and a matrix coefficient.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at 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.
Coefficient * GetACoef() const
Return the scalar factor.
VectorCoefficient * GetKCoef() const
Return the vector factor.
void SetTime(double t)
Set the time for time dependent coefficients.
void SetBCoef(VectorCoefficient &B)
Reset the second vector in the inner product.
VectorDeltaCoefficient(const Vector &_dir, double x, double y, double s)
Construct with a Vector object representing the direction and a delta function scaled by s and center...
virtual void EvalSymmetric(Vector &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the upper triangular entries of the matrix coefficient in the symmetric case, similarly to Eval. Matrix entry (i,j) is stored in K[j - i + os_i] for 0 &lt;= i &lt;= j &lt; width, os_0 = 0, os_{i+1} = os_i + width - i. That is, K = {M(0,0), ..., M(0,w-1), M(1,1), ..., M(1,w-1), ..., M(w-1,w-1) with w = width.
Matrix coefficient defined as -a k x k x, for a vector k and scalar a.
DeltaCoefficient(double x, double y, double z, double s)
Construct a delta function scaled by s and centered at (x,y,z)
void SetB(const Vector &_B)
Reset the second vector as a constant.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
Definition: coefficient.cpp:31
double GetBeta() const
Return the factor in front of the second matrix coefficient.
MatrixFunctionCoefficient(int dim, std::function< void(const Vector &, DenseMatrix &)> F, Coefficient *q=nullptr)
Define a time-independent square matrix coefficient from a std function.
Matrix coefficient defined as the linear combination of two matrices.
DeltaCoefficient & GetDeltaCoefficient()
Return the associated scalar DeltaCoefficient.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
DeltaCoefficient(double x, double s)
Construct a delta function scaled by s and centered at (x,0.0,0.0)
void SetComponent(int _index, int _length)
DeterminantCoefficient(MatrixCoefficient &A)
Construct with the matrix.
VectorCoefficient * GetBCoef() const
Return the vector factor.
Matrix coefficient defined as the inverse a matrix coefficient.
void SetACoef(Coefficient &A)
Reset the first term in the product.
ScalarMatrixProductCoefficient(double A, MatrixCoefficient &B)
Constructor with one coefficient. Result is A*B.
FunctionCoefficient(std::function< double(const Vector &, double)> TDF)
Define a time-dependent coefficient from a std function.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
A VectorDeltaFunction cannot be evaluated. Calling this method will cause an MFEM error...
Coefficient * GetACoef() const
Return the first term in the product.
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.
RatioCoefficient(double A, Coefficient &B)
Coefficient * GetCoeff(int i, int j)
Get the coefficient located at (i,j) in the matrix.
Matrix coefficient defined as the outer product of two vector coefficients.
void SetBCoef(Coefficient &B)
Reset the second term in the product.
MFEM_DEPRECATED FunctionCoefficient(double(*tdf)(Vector &, double))
(DEPRECATED) Define a time-dependent coefficient from a C-function
void SetACoef(MatrixCoefficient &A)
Reset the first matrix coefficient.
double Eval(int i, int j, ElementTransformation &T, const IntegrationPoint &ip)
void SetAConst(double A)
Reset the scalar factor as a constant.
Derived vector coefficient that has the value of the parent vector where it is active and is zero oth...
Coefficient * GetACoef() const
Return the scalar factor.
double GetAConst() const
Return the scalar factor.
InnerProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with the two vector coefficients. Result is .
Coefficient * GetACoef() const
Return the first term in the linear combination.
MatrixCoefficient(int dim, bool symm=false)
Construct a dim x dim matrix coefficient.
Quadrature function coefficient which requires that the quadrature rules used for this coefficient be...
void SetAConst(double A)
Reset the scalar factor as a constant.
VectorCoefficient * GetBCoef() const
Return the second vector coefficient in the outer product.
double ComputeLpNorm(double p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
Compute the Lp norm of a function f. .
std::function< double(const Vector &, double)> TDFunction
VectorConstantCoefficient(const Vector &v)
Construct the coefficient with constant vector v.
ConstantCoefficient(double c=1.0)
c is value of constant function
Definition: coefficient.hpp:84
VectorCoefficient * GetBCoef() const
Return the second vector coefficient.
void SetBCoef(VectorCoefficient &B)
Reset the vector coefficient.
void SetBCoef(VectorCoefficient &B)
Reset the second vector in the outer product.
const QuadratureFunction & GetQuadFunction() const
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
A matrix coefficient with an optional scalar coefficient multiplier q. The matrix function can either...
VectorDeltaCoefficient(int _vdim)
Construct with a vector of dimension _vdim.
const double * Center()
double GetTime()
Get the time for time dependent coefficients.
void SetAlpha(double _alpha)
Reset the factor in front of the first vector coefficient as a constant.
VectorCoefficient * GetACoef() const
Return the first vector of the product.
Derived coefficient that takes the value of the parent coefficient for the active attributes and is z...
QuadratureFunctionCoefficient(QuadratureFunction &qf)
Constructor with a quadrature function as input.
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.
RatioCoefficient(Coefficient &A, double B)
MatrixFunctionCoefficient(int dim, std::function< void(const Vector &, Vector &)> SymmF, Coefficient *q=NULL)
Define a time-independent symmetric square matrix coefficient from a std function.
const Vector & GetVec()
Return a reference to the constant vector in this class.
VectorDeltaCoefficient(const Vector &_dir)
Construct with a Vector object representing the direction and a unit delta function centered at (0...
MatrixRestrictedCoefficient(MatrixCoefficient &mc, Array< int > &attr)
Construct with a parent matrix coefficient and an array of zeros and ones representing the attributes...
std::function< double(const Vector &)> Function
void SetDirection(const Vector &_d)
Coefficient * GetBetaCoef() const
Return the factor in front of the second vector coefficient.
VectorDeltaCoefficient(const Vector &_dir, double x, double y, double z, double s)
Construct with a Vector object representing the direction and a delta function scaled by s and center...
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)
Construct with two vector coefficients. Result is .
const GridFunction * GetGridFunction() const
Get the internal GridFunction.
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 Set(int i, Coefficient *c, bool own=true)
Sets coefficient in the vector.
DeltaCoefficient()
Construct a unit delta function centered at (0.0,0.0,0.0)
void SetDeltaCoefficient(const DeltaCoefficient &_d)
Replace the associated DeltaCoefficient with a new DeltaCoefficient.
void SetACoef(VectorCoefficient &A)
Reset the first vector in the inner product.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
virtual ~VectorArrayCoefficient()
Destroys vector coefficient.
VectorFunctionCoefficient(int dim, std::function< void(const Vector &, Vector &)> F, Coefficient *q=nullptr)
Define a time-independent vector coefficient from a std function.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
int GetVDim()
Returns dimension of the vector.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
void SetACoef(Coefficient &A)
Reset the scalar factor.
VectorCoefficient * GetACoef() const
Return the first vector coefficient in the outer product.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
void SetACoef(VectorCoefficient &A)
Reset the first term in the product.
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 determinant coefficient at ip.
const GridFunction * GetGridFunction() const
Get the vector grid function.
void SetBCoef(VectorCoefficient &B)
Reset the vector factor.
void SetTime(double t)
Set the time for time dependent coefficients.
Definition: coefficient.hpp:48
void operator=(double c)
Set the constants for all attributes to constant c.
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
PowerCoefficient(Coefficient &A, double _p)
Construct with a coefficient and a constant power _p. Result is A^p.
A general vector function coefficient.
const GridFunction * GetGridFunction() const
Returns a pointer to the grid function in this Coefficient.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
Definition: coefficient.hpp:87
Coefficient * GetAlphaCoef() const
Return the factor in front of the first vector coefficient.
VectorCoefficient * GetBCoef() const
Return the second term in the product.
void GetDeltaCenter(Vector &center)
Write the center of the delta function into center.
Definition: coefficient.cpp:77
MatrixFunctionCoefficient(const DenseMatrix &m, Coefficient &q)
Define a constant matrix coefficient times a scalar Coefficient.
Scalar coefficient defined as the Divergence of a vector GridFunction.
MatrixVectorProductCoefficient MatVecCoefficient
Convenient alias for the MatrixVectorProductCoefficient.
void SetACoef(Coefficient &A)
Reset the base coefficient.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
bool IsSymmetric() const
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.
const GridFunction * GetGridFunction() const
Get the scalar grid function.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
Definition: coefficient.hpp:39
void SetBCoef(VectorCoefficient &B)
Reset the second vector in the product.
virtual ~Coefficient()
Definition: coefficient.hpp:73
VectorQuadratureFunctionCoefficient(QuadratureFunction &qf)
Constructor with a quadrature function as input.
Vector coefficient defined as a product of scalar and vector coefficients.
MatrixCoefficient * GetACoef() const
Return the first matrix coefficient.
double GetAConst() const
Return the first term in the linear combination.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
void UpdateConstants(Vector &c)
Update the constants with vector c.
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
Coefficient * GetCoeff(int i)
Returns i&#39;th coefficient.
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. .
void SetAConst(double A)
Reset the first term in the linear combination as a constant.
SumCoefficient(double A, Coefficient &B, double _alpha=1.0, double _beta=1.0)
Constructor with one coefficient. Result is _alpha * A + _beta * B.
PWConstCoefficient(int NumOfSubD=0)
Constructs a piecewise constant coefficient in NumOfSubD subdomains.
void SetAlphaCoef(Coefficient &A)
Reset the factor in front of the first vector coefficient.
Coefficient * GetACoef() const
Return the numerator of the ratio.
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
Vector coefficient defined as a product of a matrix coefficient and a vector coefficient.
VectorCoefficient * GetACoef() const
Return the first vector coefficient.
const QuadratureFunction & GetQuadFunction() const
Derived matrix coefficient that has the value of the parent matrix coefficient where it is active and...
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
Definition: coefficient.cpp:49
Vector coefficient defined by a scalar DeltaCoefficient and a constant vector direction.
int GetVDim() const
For backward compatibility get the width of the matrix.
MatrixCoefficient * GetBCoef() const
Return the second matrix coefficient.
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.
A piecewise constant coefficient with the constants keyed off the element attribute numbers...
Definition: coefficient.hpp:94
void SetACoef(VectorCoefficient &A)
Reset the vector coefficient.
void SetScale(double _s)
Set the scale value multiplying the delta function.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
Class for integration point with weight.
Definition: intrules.hpp:25
VectorCoefficient * GetBCoef() const
Return the vector coefficient.
double GetAConst() const
Return the scalar factor.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the scalar divergence coefficient at ip.
double GetBeta() const
Return the factor in front of the second term in the linear combination.
double GetAlpha() const
Return the factor in front of the first vector coefficient.
void SetAConst(double A)
Reset the numerator in the ratio as a constant.
const Vector & GetB() const
Return the second vector constant.
MatrixSumCoefficient(MatrixCoefficient &A, MatrixCoefficient &B, double _alpha=1.0, double _beta=1.0)
Construct with the two coefficients. Result is _alpha * A + _beta * B.
void SetBetaCoef(Coefficient &B)
Reset the factor in front of the second vector coefficient.
DivergenceGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a vector grid function gf. The grid function is not owned by the coeff...
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient.
Coefficient * GetBCoef() const
Return the second term in the linear combination.
TransformedCoefficient(Coefficient *q, double(*F)(double))
const GridFunction * GetGridFunction() const
Get the vector grid function.
void SetAlpha(double _alpha)
Reset the factor in front of the first matrix coefficient.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
Vector coefficient defined as a normalized vector field (returns v/|v|)
VectorCoefficient(int vd)
Initialize the VectorCoefficient with vector dimension vd.
int GetNConst()
Returns the number of constants representing different attributes.
int dim
Definition: ex24.cpp:53
void SetAConst(double A)
Reset the scalar factor as a constant.
VectorFunctionCoefficient(int dim, std::function< void(const Vector &, double, Vector &)> TDF, Coefficient *q=nullptr)
Define a time-dependent vector coefficient from a std function.
void SetACoef(VectorCoefficient &A)
Reset the first vector in the product.
void SetGridFunction(const GridFunction *gf)
Set the grid function for this coefficient. Also sets the Vector dimension to match that of the gf...
void SetBeta(double _beta)
Reset the factor in front of the second term in the linear combination.
Matrix coefficient defined as the transpose a matrix coefficient.
void SetBConst(double B)
Reset the denominator in the ratio as a constant.
void SetBCoef(Coefficient &B)
Reset the second term in the linear combination.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
VectorDeltaCoefficient(const Vector &_dir, double x, double s)
Construct with a Vector object representing the direction and a delta function scaled by s and center...
VectorCoefficient * GetBCoef() const
Return the second vector coefficient in the inner product.
double GetAConst() const
Return the scalar factor.
DeltaCoefficient(double x, double y, double s)
Construct a delta function scaled by s and centered at (x,y,0.0)
Scalar coefficient defined as a scalar raised to a power.
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()...
double GetTime()
Get the time for time dependent coefficients.
Definition: coefficient.hpp:51
Scalar coefficient defined as the determinant of a matrix coefficient.
A general function coefficient.
void SetACoef(VectorCoefficient &A)
Reset the first vector in the outer product.
ProductCoefficient(Coefficient &A, Coefficient &B)
Constructor with two coefficients. Result is A * B.
Vector data type.
Definition: vector.hpp:51
TransformedCoefficient(Coefficient *q1, Coefficient *q2, double(*F)(double, double))
GridFunctionCoefficient(const GridFunction *gf, int comp=1)
Vector coefficient defined by a vector GridFunction.
int GetWidth() const
Get the width of the matrix.
VectorRestrictedCoefficient(VectorCoefficient &vc, Array< int > &attr)
Construct with a parent vector coefficient and an array of zeros and ones representing the attributes...
VectorRotProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Constructor with two vector coefficients. Result is .
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
void SetACoef(Coefficient &A)
Reset the scalar factor.
void SetBeta(double _beta)
Reset the factor in front of the second vector coefficient as a constant.
MatrixConstantCoefficient(const DenseMatrix &m)
Construct using matrix m for the constant.
double GetAlpha() const
Return the factor in front of the first term in the linear combination.
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
double GetAlpha() const
Return the factor in front of the first matrix coefficient.
virtual void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient at ip.
VectorCoefficient * GetACoef() const
Return the first term in the product.
double GetAConst() const
Return the numerator of the ratio.
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
Constant matrix coefficient defined as the identity of dimension d.
double GetExponent() const
Return the exponent.
virtual void EvalSymmetric(Vector &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the symmetric matrix coefficient at ip.
Coefficient * GetACoef() const
Return the base coefficient.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient at ip.
void SetGridFunction(const GridFunction *gf)
Set the internal GridFunction.
void SetBCoef(Coefficient &B)
Reset the denominator in the ratio.
InverseMatrixCoefficient(MatrixCoefficient &A)
Construct with the matrix coefficient. Result is .
Scalar coefficient defined as the linear combination of two scalar coefficients or a scalar and a sca...
ProductCoefficient(double A, Coefficient &B)
Constructor with one coefficient. Result is A * B.
Class representing a function through its values (scalar or vector) at quadrature points...
Definition: gridfunc.hpp:670
void SetA(const Vector &_A)
Reset the first vector as a constant.
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient at ip.
const Vector & GetA() const
Return the first vector constant.
VectorCoefficient * GetBCoef() const
Return the second vector of the product.
void SetACoef(Coefficient &A)
Reset the first term in the linear combination.
double GetBeta() const
Return the factor in front of the second vector coefficient.
void SetBCoef(MatrixCoefficient &B)
Reset the second matrix coefficient.
ScalarVectorProductCoefficient(double A, VectorCoefficient &B)
Constructor with constant and vector coefficient. Result is A * B.
double f(const Vector &p)
VectorGridFunctionCoefficient()
Construct an empty coefficient. Calling Eval() before the grid function is set will cause a segfault...
RestrictedCoefficient(Coefficient &_c, Array< int > &attr)
Construct with a parent coefficient and an array with ones marking the attributes on which this coeff...