MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
coefficient.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#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
22namespace mfem
23{
24
25class Mesh;
26class QuadratureSpaceBase;
27class QuadratureFunction;
28
29#ifdef MFEM_USE_MPI
30class ParMesh;
31#endif
32
33
34/** @brief Base class Coefficients that optionally depend on space and time.
35 These are used by the BilinearFormIntegrator, LinearFormIntegrator, and
36 NonlinearFormIntegrator classes to represent the physical coefficients in
37 the PDEs that are being discretized. This class can also be used in a more
38 general way to represent functions that don't necessarily belong to a FE
39 space, e.g., to project onto GridFunctions to use as initial conditions,
40 exact solutions, etc. See, e.g., ex4 or ex22 for these uses. */
42{
43protected:
45
46public:
47 Coefficient() { time = 0.; }
48
49 /// Set the time for time dependent coefficients
50 virtual void SetTime(real_t t) { time = t; }
51
52 /// Get the time for time dependent coefficients
53 real_t GetTime() { return time; }
54
55 /// Returns dimension of the vector.
56 int GetVDim() { return 1; }
57
58 /** @brief Evaluate the coefficient in the element described by @a T at the
59 point @a ip. */
60 /** @note When this method is called, the caller must make sure that the
61 IntegrationPoint associated with @a T is the same as @a ip. This can be
62 achieved by calling T.SetIntPoint(&ip). */
64 const IntegrationPoint &ip) = 0;
65
66 /** @brief Evaluate the coefficient in the element described by @a T at the
67 point @a ip at time @a t. */
68 /** @note When this method is called, the caller must make sure that the
69 IntegrationPoint associated with @a T is the same as @a ip. This can be
70 achieved by calling T.SetIntPoint(&ip). */
72 const IntegrationPoint &ip, real_t t)
73 {
74 SetTime(t);
75 return Eval(T, ip);
76 }
77
78 /// @brief Fill the QuadratureFunction @a qf by evaluating the coefficient at
79 /// the quadrature points.
80 virtual void Project(QuadratureFunction &qf);
81
82 virtual ~Coefficient() { }
83};
84
85
86/// A coefficient that is constant across space and time
88{
89public:
91
92 /// c is value of constant function
93 explicit ConstantCoefficient(real_t c = 1.0) { constant=c; }
94
95 /// Evaluate the coefficient at @a ip.
97 const IntegrationPoint &ip) override
98 { return (constant); }
99
100 /// Fill the QuadratureFunction @a qf with the constant value.
101 void Project(QuadratureFunction &qf) override;
102};
103
104/** @brief A piecewise constant coefficient with the constants keyed
105 off the element attribute numbers. */
107{
108private:
109 Vector constants;
110
111public:
112
113 /// Constructs a piecewise constant coefficient in NumOfSubD subdomains
114 explicit PWConstCoefficient(int NumOfSubD = 0) : constants(NumOfSubD)
115 { constants = 0.0; }
116
117 /// Construct the constant coefficient using a vector of constants.
118 /** @a c should be a vector defined by attributes, so for region with
119 attribute @a i @a c[i-1] is the coefficient in that region */
121
122 /// Update the constants with vector @a c.
123 void UpdateConstants(const Vector &c) { constants = c; }
124
125 /// Return a reference to the i-th constant
126 real_t &operator()(int i) { return constants(i-1); }
127
128 /// Set the constants for all attributes to constant @a c.
129 void operator=(real_t c) { constants = c; }
130
131 /// Returns the number of constants representing different attributes.
132 int GetNConst() { return constants.Size(); }
133
134 /// Evaluate the coefficient.
136 const IntegrationPoint &ip) override;
137
138 /// Fill the QuadratureFunction @a qf with the piecewise constant values.
139 void Project(QuadratureFunction &qf) override;
140};
141
142/** @brief A piecewise coefficient with the pieces keyed off the element
143 attribute numbers.
144
145 A value of zero will be returned for any missing attribute numbers.
146
147 This object will not assume ownership of any Coefficient objects
148 passed to it. Consequently, the caller must ensure that the
149 individual Coefficient objects are not deleted while this
150 PWCoefficient is still in use.
151
152 \note The keys may either be domain attribute numbers or boundary
153 attribute numbers. If the PWCoefficient is used with a domain
154 integrator the keys are assumed to be domain attribute
155 numbers. Similarly, if the PWCoefficient is used with a boundary
156 integrator the keys are assumed to be boundary attribute numbers.
157*/
159{
160private:
161 /** Internal data structure to store pointers to the appropriate
162 coefficients for different regions of the mesh. The keys used
163 in the map are the mesh attribute numbers (either element
164 attribute or boundary element attribute depending upon
165 context). The values returned for any missing attributes will
166 be zero. The coefficient pointers may be NULL in which case a
167 value of zero is returned.
168
169 The Coefficient objects contained in this map are NOT owned by
170 this PWCoefficient object. This means that they will not be
171 deleted when this object is deleted also the caller must ensure
172 that the various Coefficient objects are not deleted while this
173 PWCoefficient is still needed.
174 */
175 std::map<int, Coefficient*> pieces;
176
177 /** Convenience function to check for compatible array lengths,
178 loop over the arrays, and add their attribute/Coefficient pairs
179 to the internal data structure.
180 */
181 void InitMap(const Array<int> & attr,
182 const Array<Coefficient*> & coefs);
183
184public:
185
186 /// Constructs a piecewise coefficient
187 explicit PWCoefficient() {}
188
189 /// Construct the coefficient using arrays describing the pieces
190 /** \param attr - an array of attribute numbers for each piece
191 \param coefs - the corresponding array of Coefficient pointers
192 Any missing attributes or NULL coefficient pointers will result in a
193 value of zero being returned for that attribute.
194
195 \note Ownership of the Coefficient objects will NOT be
196 transferred to this object.
197 */
199 const Array<Coefficient*> & coefs)
200 { InitMap(attr, coefs); }
201
202 /// Set the time for time dependent coefficients
203 void SetTime(real_t t) override;
204
205 /// Replace a set of coefficients
207 const Array<Coefficient*> & coefs)
208 { InitMap(attr, coefs); }
209
210 /// Replace a single Coefficient for a particular attribute
211 void UpdateCoefficient(int attr, Coefficient & coef)
212 { pieces[attr] = &coef; }
213
214 /// Remove a single Coefficient for a particular attribute
215 void ZeroCoefficient(int attr)
216 { pieces.erase(attr); }
217
218 /// Evaluate the coefficient.
220 const IntegrationPoint &ip) override;
221};
222
223/// A general function coefficient
225{
226protected:
227 std::function<real_t(const Vector &)> Function;
228 std::function<real_t(const Vector &, real_t)> TDFunction;
229
230public:
231 /// Define a time-independent coefficient from a std function
232 /** \param F time-independent std::function */
233 FunctionCoefficient(std::function<real_t(const Vector &)> F)
234 : Function(std::move(F))
235 { }
236
237 /// Define a time-dependent coefficient from a std function
238 /** \param TDF time-dependent function */
239 FunctionCoefficient(std::function<real_t(const Vector &, real_t)> TDF)
240 : TDFunction(std::move(TDF))
241 { }
242
243 /// (DEPRECATED) Define a time-independent coefficient from a C-function
244 /** @deprecated Use the method where the C-function, @a f, uses a const
245 Vector argument instead of Vector. */
246 MFEM_DEPRECATED FunctionCoefficient(real_t (*f)(Vector &))
247 {
248 // Cast first to (void*) to suppress a warning from newer version of
249 // Clang when using -Wextra.
250 Function = reinterpret_cast<real_t(*)(const Vector&)>((void*)f);
251 TDFunction = NULL;
252 }
253
254 /// (DEPRECATED) Define a time-dependent coefficient from a C-function
255 /** @deprecated Use the method where the C-function, @a tdf, uses a const
256 Vector argument instead of Vector. */
257 MFEM_DEPRECATED FunctionCoefficient(real_t (*tdf)(Vector &, real_t))
258 {
259 Function = NULL;
260 // Cast first to (void*) to suppress a warning from newer version of
261 // Clang when using -Wextra.
262 TDFunction =
263 reinterpret_cast<real_t(*)(const Vector&,real_t)>((void*)tdf);
264 }
265
266 /// Evaluate the coefficient at @a ip.
268 const IntegrationPoint &ip) override;
269};
270
271/// A common base class for returning individual components of the domain's
272/// Cartesian coordinates.
274{
275protected:
276 int comp;
278
279 /// @a comp_ index of the desired component (0 -> x, 1 -> y, 2 -> z)
280 CartesianCoefficient(int comp_) : comp(comp_), transip(3) {}
281
282public:
283 /// Evaluate the coefficient at @a ip.
285 const IntegrationPoint &ip) override;
286};
287
288/// Scalar coefficient which returns the x-component of the evaluation point
294
295/// Scalar coefficient which returns the y-component of the evaluation point
301
302/// Scalar coefficient which returns the z-component of the evaluation point
308
309/// Scalar coefficient which returns the radial distance from the axis of
310/// the evaluation point in the cylindrical coordinate system
312{
313private:
314 mutable Vector transip;
315
316public:
318
319 /// Evaluate the coefficient at @a ip.
321 const IntegrationPoint &ip) override;
322};
323
324/// Scalar coefficient which returns the angular position or azimuth (often
325/// denoted by theta) of the evaluation point in the cylindrical coordinate
326/// system
328{
329private:
330 mutable Vector transip;
331
332public:
334
335 /// Evaluate the coefficient at @a ip.
337 const IntegrationPoint &ip) override;
338};
339
340/// Scalar coefficient which returns the height or altitude of
341/// the evaluation point in the cylindrical coordinate system
343
344/// Scalar coefficient which returns the radial distance from the origin of
345/// the evaluation point in the spherical coordinate system
347{
348private:
349 mutable Vector transip;
350
351public:
353
354 /// Evaluate the coefficient at @a ip.
356 const IntegrationPoint &ip) override;
357};
358
359/// Scalar coefficient which returns the azimuthal angle (often denoted by phi)
360/// of the evaluation point in the spherical coordinate system
362{
363private:
364 mutable Vector transip;
365
366public:
368
369 /// Evaluate the coefficient at @a ip.
371 const IntegrationPoint &ip) override;
372};
373
374/// Scalar coefficient which returns the polar angle (often denoted by theta)
375/// of the evaluation point in the spherical coordinate system
377{
378private:
379 mutable Vector transip;
380
381public:
383
384 /// Evaluate the coefficient at @a ip.
386 const IntegrationPoint &ip) override;
387};
388
389class GridFunction;
390
391/// Coefficient defined by a GridFunction. This coefficient is mesh dependent.
393{
394private:
395 const GridFunction *GridF;
396 int Component;
397
398public:
399 GridFunctionCoefficient() : GridF(NULL), Component(1) { }
400 /** Construct GridFunctionCoefficient from a given GridFunction, and
401 optionally specify a component to use if it is a vector GridFunction. */
402 GridFunctionCoefficient (const GridFunction *gf, int comp = 1)
403 { GridF = gf; Component = comp; }
404
405 /// Set the internal GridFunction
406 void SetGridFunction(const GridFunction *gf) { GridF = gf; }
407
408 /// Get the internal GridFunction
409 const GridFunction * GetGridFunction() const { return GridF; }
410
411 /// Evaluate the coefficient at @a ip.
413 const IntegrationPoint &ip) override;
414
415 /// @brief Fill the QuadratureFunction @a qf by evaluating the coefficient at
416 /// the quadrature points.
417 ///
418 /// This function uses the efficient QuadratureFunction::ProjectGridFunction
419 /// to fill the QuadratureFunction.
420 void Project(QuadratureFunction &qf) override;
421};
422
423
424/** @brief A coefficient that depends on 1 or 2 parent coefficients and a
425 transformation rule represented by a C-function.
426
427 $ C(x,t) = T(Q1(x,t)) $ or $ C(x,t) = T(Q1(x,t), Q2(x,t)) $
428
429 where T is the transformation rule, and Q1/Q2 are the parent coefficients.*/
431{
432private:
433 Coefficient * Q1;
434 Coefficient * Q2;
435 std::function<real_t(real_t)> Transform1;
436 std::function<real_t(real_t, real_t)> Transform2;
437
438public:
440 : Q1(q), Transform1(std::move(F)) { Q2 = 0; Transform2 = 0; }
442 std::function<real_t(real_t, real_t)> F)
443 : Q1(q1), Q2(q2), Transform2(std::move(F)) { Transform1 = 0; }
444
445 /// Set the time for internally stored coefficients
446 void SetTime(real_t t) override;
447
448 /// Evaluate the coefficient at @a ip.
449 real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override;
450};
451
452/** @brief Delta function coefficient optionally multiplied by a weight
453 coefficient and a scaled time dependent C-function.
454
455 $ F(x,t) = w(x,t) s T(t) d(x - xc) $
456
457 where w is the optional weight coefficient, @a s is a scale factor
458 T is an optional time-dependent function and d is a delta function.
459
460 WARNING this cannot be used as a normal coefficient. The usual Eval
461 method is disabled. */
463{
464protected:
467 int sdim;
469
470public:
471
472 /// Construct a unit delta function centered at (0.0,0.0,0.0)
474 {
475 center[0] = center[1] = center[2] = 0.; scale = 1.; tol = 1e-12;
476 weight = NULL; sdim = 0; tdf = NULL;
477 }
478
479 /// Construct a delta function scaled by @a s and centered at (x,0.0,0.0)
481 {
482 center[0] = x; center[1] = 0.; center[2] = 0.; scale = s; tol = 1e-12;
483 weight = NULL; sdim = 1; tdf = NULL;
484 }
485
486 /// Construct a delta function scaled by @a s and centered at (x,y,0.0)
488 {
489 center[0] = x; center[1] = y; center[2] = 0.; scale = s; tol = 1e-12;
490 weight = NULL; sdim = 2; tdf = NULL;
491 }
492
493 /// Construct a delta function scaled by @a s and centered at (x,y,z)
495 {
496 center[0] = x; center[1] = y; center[2] = z; scale = s; tol = 1e-12;
497 weight = NULL; sdim = 3; tdf = NULL;
498 }
499
500 /// Set the time for internally stored coefficients
501 void SetTime(real_t t) override;
502
503 /// Set the center location of the delta function.
504 void SetDeltaCenter(const Vector& center);
505
506 /// Set the scale value multiplying the delta function.
507 void SetScale(real_t s_) { scale = s_; }
508
509 /// Set a time-dependent function that multiplies the Scale().
510 void SetFunction(real_t (*f)(real_t)) { tdf = f; }
511
512 /** @brief Set the tolerance used during projection onto GridFunction to
513 identify the Mesh vertex where the Center() of the delta function
514 lies. (default 1e-12)*/
515 void SetTol(real_t tol_) { tol = tol_; }
516
517 /// Set a weight Coefficient that multiplies the DeltaCoefficient.
518 /** The weight Coefficient multiplies the value returned by EvalDelta() but
519 not the value returned by Scale().
520 The weight Coefficient is also used as the L2-weight function when
521 projecting the DeltaCoefficient onto a GridFunction, so that the weighted
522 integral of the projection is exactly equal to the Scale(). */
523 void SetWeight(Coefficient *w) { weight = w; }
524
525 /// Return a pointer to a c-array representing the center of the delta
526 /// function.
527 const real_t *Center() { return center; }
528
529 /** @brief Return the scale factor times the optional time dependent
530 function. Returns $ s T(t) $ with $ T(t) = 1 $ when
531 not set by the user. */
532 real_t Scale() { return tdf ? (*tdf)(GetTime())*scale : scale; }
533
534 /// Return the tolerance used to identify the mesh vertices
535 real_t Tol() { return tol; }
536
537 /// See SetWeight() for description of the weight Coefficient.
538 Coefficient *Weight() { return weight; }
539
540 /// Write the center of the delta function into @a center.
542
543 /// The value of the function assuming we are evaluating at the delta center.
545 /** @brief A DeltaFunction cannot be evaluated. Calling this method will
546 cause an MFEM error, terminating the application. */
548 { mfem_error("DeltaCoefficient::Eval"); return 0.; }
549 virtual ~DeltaCoefficient() { delete weight; }
550};
551
552/** @brief Derived coefficient that takes the value of the parent coefficient
553 for the active attributes and is zero otherwise. */
555{
556private:
557 Coefficient *c;
558 Array<int> active_attr;
559
560public:
561 /** @brief Construct with a parent coefficient and an array with
562 ones marking the attributes on which this coefficient should be
563 active. */
565 { c = &c_; attr.Copy(active_attr); }
566
567 /// Set the time for internally stored coefficients
568 void SetTime(real_t t) override;
569
570 /// Evaluate the coefficient at @a ip.
572 { return active_attr[T.Attribute-1] ? c->Eval(T, ip, GetTime()) : 0.0; }
573};
574
575/// Base class for vector Coefficients that optionally depend on time and space.
577{
578protected:
579 int vdim;
581
582public:
583 /// Initialize the VectorCoefficient with vector dimension @a vd.
584 VectorCoefficient(int vd) { vdim = vd; time = 0.; }
585
586 /// Set the time for time dependent coefficients
587 virtual void SetTime(real_t t) { time = t; }
588
589 /// Get the time for time dependent coefficients
590 real_t GetTime() { return time; }
591
592 /// Returns dimension of the vector.
593 int GetVDim() { return vdim; }
594
595 /** @brief Evaluate the vector coefficient in the element described by @a T
596 at the point @a ip, storing the result in @a V. */
597 /** @note When this method is called, the caller must make sure that the
598 IntegrationPoint associated with @a T is the same as @a ip. This can be
599 achieved by calling T.SetIntPoint(&ip). */
600 virtual void Eval(Vector &V, ElementTransformation &T,
601 const IntegrationPoint &ip) = 0;
602
603 /** @brief Evaluate the vector coefficient in the element described by @a T
604 at all points of @a ir, storing the result in @a M. */
605 /** The dimensions of @a M are GetVDim() by ir.GetNPoints() and they must be
606 set by the implementation of this method.
607
608 The general implementation provided by the base class (using the Eval
609 method for one IntegrationPoint at a time) can be overloaded for more
610 efficient implementation.
611
612 @note The IntegrationPoint associated with @a T is not used, and this
613 method will generally modify this IntegrationPoint associated with @a T.
614 */
615 virtual void Eval(DenseMatrix &M, ElementTransformation &T,
616 const IntegrationRule &ir);
617
618 /// @brief Fill the QuadratureFunction @a qf by evaluating the coefficient at
619 /// the quadrature points.
620 ///
621 /// The @a vdim of the VectorCoefficient should be equal to the @a vdim of
622 /// the QuadratureFunction.
623 virtual void Project(QuadratureFunction &qf);
624
625 virtual ~VectorCoefficient() { }
626};
627
628
629/// Vector coefficient that is constant in space and time.
631{
632private:
633 Vector vec;
634public:
635 /// Construct the coefficient with constant vector @a v.
637 : VectorCoefficient(v.Size()), vec(v) { }
639
640 /// Evaluate the vector coefficient at @a ip.
642 const IntegrationPoint &ip) override { V = vec; }
643
644 /// Return a reference to the constant vector in this class.
645 const Vector& GetVec() const { return vec; }
646};
647
648/** @brief A piecewise vector-valued coefficient with the pieces keyed off the
649 element attribute numbers.
650
651 A value of zero will be returned for any missing attribute numbers.
652
653 This object will not assume ownership of any VectorCoefficient
654 objects passed to it. Consequently, the caller must ensure that
655 the individual VectorCoefficient objects are not deleted while
656 this PWVectorCoefficient is still in use.
657
658 \note The keys may either be domain attribute numbers or boundary
659 attribute numbers. If the PWVectorCoefficient is used with a
660 domain integrator the keys are assumed to be domain attribute
661 numbers. Similarly, if the PWVectorCoefficient is used with a
662 boundary integrator the keys are assumed to be boundary attribute
663 numbers.
664*/
666{
667private:
668 /** Internal data structure to store pointers to the appropriate
669 coefficients for different regions of the mesh. The keys used
670 in the map are the mesh attribute numbers (either element
671 attribute or boundary element attribute depending upon
672 context). The values returned for any missing attributes will
673 be zero. The coefficient pointers may be NULL in which case a
674 value of zero is returned.
675
676 The VectorCoefficient objects contained in this map are NOT
677 owned by this PWVectorCoefficient object. This means that they
678 will not be deleted when this object is deleted also the caller
679 must ensure that the various VectorCoefficient objects are not
680 deleted while this PWVectorCoefficient is still needed.
681 */
682 std::map<int, VectorCoefficient*> pieces;
683
684 /** Convenience function to check for compatible array lengths,
685 loop over the arrays, and add their attribute/VectorCoefficient
686 pairs to the internal data structure.
687 */
688 void InitMap(const Array<int> & attr,
689 const Array<VectorCoefficient*> & coefs);
690
691public:
692
693 /// Constructs a piecewise vector coefficient of dimension vd
694 explicit PWVectorCoefficient(int vd): VectorCoefficient(vd) {}
695
696 /// Construct the coefficient using arrays describing the pieces
697 /** \param vd - dimension of the vector-valued result
698 \param attr - an array of attribute numbers for each piece
699 \param coefs - the corresponding array of VectorCoefficient pointers
700 Any missing attributes or NULL coefficient pointers will result in a
701 zero vector being returned for that attribute.
702
703 \note Ownership of the VectorCoefficient objects will NOT be
704 transferred to this object.
705 */
706 PWVectorCoefficient(int vd, const Array<int> & attr,
707 const Array<VectorCoefficient*> & coefs)
708 : VectorCoefficient(vd) { InitMap(attr, coefs); }
709
710 /// Set the time for time dependent coefficients
711 void SetTime(real_t t) override;
712
713 /// Replace a set of coefficients
715 const Array<VectorCoefficient*> & coefs)
716 { InitMap(attr, coefs); }
717
718 /// Replace a single Coefficient for a particular attribute
719 void UpdateCoefficient(int attr, VectorCoefficient & coef);
720
721 /// Remove a single VectorCoefficient for a particular attribute
722 void ZeroCoefficient(int attr)
723 { pieces.erase(attr); }
724
725 /// Evaluate the coefficient.
727 const IntegrationPoint &ip) override;
729};
730
731/// A vector coefficient which returns the physical location of the
732/// evaluation point in the Cartesian coordinate system.
734{
735public:
736
738
740 /// Evaluate the vector coefficient at @a ip.
742 const IntegrationPoint &ip) override;
743
745};
746
747/// A general vector function coefficient
749{
750private:
751 std::function<void(const Vector &, Vector &)> Function;
752 std::function<void(const Vector &, real_t, Vector &)> TDFunction;
753 Coefficient *Q;
754
755public:
756 /// Define a time-independent vector coefficient from a std function
757 /** \param dim - the size of the vector
758 \param F - time-independent function
759 \param q - optional scalar Coefficient to scale the vector coefficient */
761 std::function<void(const Vector &, Vector &)> F,
762 Coefficient *q = nullptr)
763 : VectorCoefficient(dim), Function(std::move(F)), Q(q)
764 { }
765
766 /// Define a time-dependent vector coefficient from a std function
767 /** \param dim - the size of the vector
768 \param TDF - time-dependent function
769 \param q - optional scalar Coefficient to scale the vector coefficient */
771 std::function<void(const Vector &, real_t, Vector &)> TDF,
772 Coefficient *q = nullptr)
773 : VectorCoefficient(dim), TDFunction(std::move(TDF)), Q(q)
774 { }
775
777 /// Evaluate the vector coefficient at @a ip.
779 const IntegrationPoint &ip) override;
780
782};
783
784/** @brief Vector coefficient defined by an array of scalar coefficients.
785 Coefficients that are not set will evaluate to zero in the vector. This
786 object takes ownership of the array of coefficients inside it and deletes
787 them at object destruction. */
789{
790private:
792 Array<bool> ownCoeff;
793
794public:
795 /** @brief Construct vector of dim coefficients. The actual coefficients
796 still need to be added with Set(). */
797 explicit VectorArrayCoefficient(int dim);
798
799 /// Set the time for internally stored coefficients
800 void SetTime(real_t t) override;
801
802 /// Returns i'th coefficient.
803 Coefficient* GetCoeff(int i) { return Coeff[i]; }
804
805 /// Returns the entire array of coefficients.
806 Coefficient **GetCoeffs() { return Coeff; }
807
808 /// Sets coefficient in the vector.
809 void Set(int i, Coefficient *c, bool own=true);
810
811 /// Set ownership of the i'th coefficient
812 void SetOwnership(int i, bool own) { ownCoeff[i] = own; }
813
814 /// Get ownership of the i'th coefficient
815 bool GetOwnership(int i) const { return ownCoeff[i]; }
816
817 /// Evaluates i'th component of the vector of coefficients and returns the
818 /// value.
820 { return Coeff[i] ? Coeff[i]->Eval(T, ip, GetTime()) : 0.0; }
821
823 /** @brief Evaluate the coefficient. Each element of vector V comes from the
824 associated array of scalar coefficients. */
826 const IntegrationPoint &ip) override;
827
828 /// Destroys vector coefficient.
829 virtual ~VectorArrayCoefficient();
830};
831
832/// Vector coefficient defined by a vector GridFunction
834{
835protected:
837
838public:
839 /** @brief Construct an empty coefficient. Calling Eval() before the grid
840 function is set will cause a segfault. */
842
843 /** @brief Construct the coefficient with grid function @a gf. The
844 grid function is not owned by the coefficient. */
846
847 /** @brief Set the grid function for this coefficient. Also sets the Vector
848 dimension to match that of the @a gf. */
849 void SetGridFunction(const GridFunction *gf);
850
851 /// Returns a pointer to the grid function in this Coefficient
852 const GridFunction * GetGridFunction() const { return GridFunc; }
853
854 /// Evaluate the vector coefficient at @a ip.
856 const IntegrationPoint &ip) override;
857
858 /** @brief Evaluate the vector coefficients at all of the locations in the
859 integration rule and write the vectors into the columns of matrix @a
860 M. */
862 const IntegrationRule &ir) override;
863
864 /// @brief Fill the QuadratureFunction @a qf by evaluating the coefficient at
865 /// the quadrature points.
866 ///
867 /// This function uses the efficient QuadratureFunction::ProjectGridFunction
868 /// to fill the QuadratureFunction.
869 void Project(QuadratureFunction &qf) override;
870
872};
873
874/// Vector coefficient defined as the Gradient of a scalar GridFunction
876{
877protected:
879
880public:
881
882 /** @brief Construct the coefficient with a scalar grid function @a gf. The
883 grid function is not owned by the coefficient. */
885
886 ///Set the scalar grid function.
887 void SetGridFunction(const GridFunction *gf);
888
889 ///Get the scalar grid function.
890 const GridFunction * GetGridFunction() const { return GridFunc; }
891
892 /// Evaluate the gradient vector coefficient at @a ip.
894 const IntegrationPoint &ip) override;
895
896 /** @brief Evaluate the gradient vector coefficient at all of the locations
897 in the integration rule and write the vectors into columns of matrix @a
898 M. */
900 const IntegrationRule &ir) override;
901
902 /// @copydoc VectorCoefficient::Project(QuadratureFunction &)
903 void Project(QuadratureFunction &qf) override;
904
906};
907
908/// Vector coefficient defined as the Curl of a vector GridFunction
910{
911protected:
913
914public:
915 /** @brief Construct the coefficient with a vector grid function @a gf. The
916 grid function is not owned by the coefficient. */
918
919 /// Set the vector grid function.
920 void SetGridFunction(const GridFunction *gf);
921
922 /// Get the vector grid function.
923 const GridFunction * GetGridFunction() const { return GridFunc; }
924
926 /// Evaluate the vector curl coefficient at @a ip.
928 const IntegrationPoint &ip) override;
929
931};
932
933/// Scalar coefficient defined as the Divergence of a vector GridFunction
935{
936protected:
938
939public:
940 /** @brief Construct the coefficient with a vector grid function @a gf. The
941 grid function is not owned by the coefficient. */
943
944 /// Set the vector grid function.
945 void SetGridFunction(const GridFunction *gf) { GridFunc = gf; }
946
947 /// Get the vector grid function.
948 const GridFunction * GetGridFunction() const { return GridFunc; }
949
950 /// Evaluate the scalar divergence coefficient at @a ip.
952 const IntegrationPoint &ip) override;
953
955};
956
957/** @brief Vector coefficient defined by a scalar DeltaCoefficient and a
958 constant vector direction.
959
960 WARNING this cannot be used as a normal coefficient. The usual Eval method
961 is disabled. */
963{
964protected:
967
968public:
969 /// Construct with a vector of dimension @a vdim_.
971 : VectorCoefficient(vdim_), dir(vdim_), d() { }
972
973 /** @brief Construct with a Vector object representing the direction and a
974 unit delta function centered at (0.0,0.0,0.0) */
976 : VectorCoefficient(dir_.Size()), dir(dir_), d() { }
977
978 /** @brief Construct with a Vector object representing the direction and a
979 delta function scaled by @a s and centered at (x,0.0,0.0) */
981 : VectorCoefficient(dir_.Size()), dir(dir_), d(x,s) { }
982
983 /** @brief Construct with a Vector object representing the direction and a
984 delta function scaled by @a s and centered at (x,y,0.0) */
986 : VectorCoefficient(dir_.Size()), dir(dir_), d(x,y,s) { }
987
988 /** @brief Construct with a Vector object representing the direction and a
989 delta function scaled by @a s and centered at (x,y,z) */
991 real_t s)
992 : VectorCoefficient(dir_.Size()), dir(dir_), d(x,y,z,s) { }
993
994 /// Set the time for internally stored coefficients
995 void SetTime(real_t t) override;
996
997 /// Replace the associated DeltaCoefficient with a new DeltaCoefficient.
998 /** The new DeltaCoefficient cannot have a specified weight Coefficient, i.e.
999 DeltaCoefficient::Weight() should return NULL. */
1000 void SetDeltaCoefficient(const DeltaCoefficient& d_) { d = d_; }
1001
1002 /// Return the associated scalar DeltaCoefficient.
1004
1005 void SetScale(real_t s) { d.SetScale(s); }
1006 void SetDirection(const Vector& d_);
1007
1008 void SetDeltaCenter(const Vector& center) { d.SetDeltaCenter(center); }
1009 void GetDeltaCenter(Vector& center) { d.GetDeltaCenter(center); }
1010
1011 /** @brief Return the specified direction vector multiplied by the value
1012 returned by DeltaCoefficient::EvalDelta() of the associated scalar
1013 DeltaCoefficient. */
1014 virtual void EvalDelta(Vector &V, ElementTransformation &T,
1015 const IntegrationPoint &ip);
1016
1018 /** @brief A VectorDeltaFunction cannot be evaluated. Calling this method
1019 will cause an MFEM error, terminating the application. */
1021 const IntegrationPoint &ip) override
1022 { mfem_error("VectorDeltaCoefficient::Eval"); }
1024};
1025
1026/** @brief Derived vector coefficient that has the value of the parent vector
1027 where it is active and is zero otherwise. */
1029{
1030private:
1032 Array<int> active_attr;
1033
1034public:
1035 /** @brief Construct with a parent vector coefficient and an array of zeros
1036 and ones representing the attributes for which this coefficient should be
1037 active. */
1040 { c = &vc; attr.Copy(active_attr); }
1041
1042 /// Set the time for internally stored coefficients
1043 void SetTime(real_t t) override;
1044
1045 /// Evaluate the vector coefficient at @a ip.
1046 void Eval(Vector &V, ElementTransformation &T,
1047 const IntegrationPoint &ip) override;
1048
1049 /** @brief Evaluate the vector coefficient at all of the locations in the
1050 integration rule and write the vectors into the columns of matrix @a
1051 M. */
1053 const IntegrationRule &ir) override;
1054};
1055
1057
1058/** Base class for matrix-valued coefficients that optionally depend on time
1059 and space. */
1061{
1062protected:
1065 bool symmetric; // deprecated
1066
1067public:
1068 /// Construct a dim x dim matrix coefficient.
1069 explicit MatrixCoefficient(int dim, bool symm=false)
1070 { height = width = dim; time = 0.; symmetric = symm; }
1071
1072 /// Construct a h x w matrix coefficient.
1073 MatrixCoefficient(int h, int w, bool symm=false) :
1074 height(h), width(w), time(0.), symmetric(symm) { }
1075
1076 /// Set the time for time dependent coefficients
1077 virtual void SetTime(real_t t) { time = t; }
1078
1079 /// Get the time for time dependent coefficients
1080 real_t GetTime() { return time; }
1081
1082 /// Get the height of the matrix.
1083 int GetHeight() const { return height; }
1084
1085 /// Get the width of the matrix.
1086 int GetWidth() const { return width; }
1087
1088 /// For backward compatibility get the width of the matrix.
1089 int GetVDim() const { return width; }
1090
1091 /** @deprecated Use SymmetricMatrixCoefficient instead */
1092 bool IsSymmetric() const { return symmetric; }
1093
1094 /** @brief Evaluate the matrix coefficient in the element described by @a T
1095 at the point @a ip, storing the result in @a K. */
1096 /** @note When this method is called, the caller must make sure that the
1097 IntegrationPoint associated with @a T is the same as @a ip. This can be
1098 achieved by calling T.SetIntPoint(&ip). */
1100 const IntegrationPoint &ip) = 0;
1101
1102 /// @brief Fill the QuadratureFunction @a qf by evaluating the coefficient at
1103 /// the quadrature points. The matrix will be transposed or not according to
1104 /// the boolean argument @a transpose.
1105 ///
1106 /// The stored entries use the same row/column convention as `Eval()`,
1107 /// unless `transpose == true`, in which case `K^T` is stored instead.
1108 ///
1109 /// The @a vdim of the QuadratureFunction should be equal to the height times
1110 /// the width of the matrix.
1111 virtual void Project(QuadratureFunction &qf, bool transpose=false);
1112
1113 /// (DEPRECATED) Evaluate a symmetric matrix coefficient.
1114 /** @brief Evaluate the upper triangular entries of the matrix coefficient
1115 in the symmetric case, similarly to Eval. Matrix entry (i,j) is stored
1116 in K[j - i + os_i] for 0 <= i <= j < width, os_0 = 0,
1117 os_{i+1} = os_i + width - i. That is, K = {M(0,0), ..., M(0,w-1),
1118 M(1,1), ..., M(1,w-1), ..., M(w-1,w-1) with w = width.
1119 @deprecated Use Eval() instead. */
1121 const IntegrationPoint &ip)
1122 { mfem_error("MatrixCoefficient::EvalSymmetric"); }
1123
1125};
1126
1127
1128/// A matrix coefficient that is constant in space and time.
1130{
1131private:
1132 DenseMatrix mat;
1133public:
1134 ///Construct using matrix @a m for the constant.
1136 : MatrixCoefficient(m.Height(), m.Width()), mat(m) { }
1138 /// Evaluate the matrix coefficient at @a ip.
1140 const IntegrationPoint &ip) override { M = mat; }
1141 /// Return a reference to the constant matrix.
1142 const DenseMatrix& GetMatrix() { return mat; }
1143};
1144
1145
1146/** @brief A piecewise matrix-valued coefficient with the pieces keyed off the
1147 element attribute numbers.
1148
1149 A value of zero will be returned for any missing attribute numbers.
1150
1151 This object will not assume ownership of any MatrixCoefficient
1152 objects passed to it. Consequently, the caller must ensure that
1153 the individual MatrixCoefficient objects are not deleted while
1154 this PWMatrixCoefficient is still in use.
1155
1156 \note The keys may either be domain attribute numbers or boundary
1157 attribute numbers. If the PWMatrixCoefficient is used with a
1158 domain integrator the keys are assumed to be domain attribute
1159 numbers. Similarly, if the PWMatrixCoefficient is used with a
1160 boundary integrator the keys are assumed to be boundary attribute
1161 numbers.
1162*/
1164{
1165private:
1166 /** Internal data structure to store pointers to the appropriate
1167 coefficients for different regions of the mesh. The keys used
1168 in the map are the mesh attribute numbers (either element
1169 attribute or boundary element attribute depending upon
1170 context). The values returned for any missing attributes will
1171 be zero. The coefficient pointers may be NULL in which case a
1172 value of zero is returned.
1173
1174 The MatrixCoefficient objects contained in this map are NOT
1175 owned by this PWMatrixCoefficient object. This means that they
1176 will not be deleted when this object is deleted also the caller
1177 must ensure that the various MatrixCoefficient objects are not
1178 deleted while this PWMatrixCoefficient is still needed.
1179 */
1180 std::map<int, MatrixCoefficient*> pieces;
1181
1182 /** Convenience function to check for compatible array lengths,
1183 loop over the arrays, and add their attribute/MatrixCoefficient
1184 pairs to the internal data structure.
1185 */
1186 void InitMap(const Array<int> & attr,
1187 const Array<MatrixCoefficient*> & coefs);
1188
1189public:
1190
1191 /// Constructs a piecewise matrix coefficient of dimension dim by dim
1192 explicit PWMatrixCoefficient(int dim, bool symm = false)
1193 : MatrixCoefficient(dim, symm) {}
1194
1195 /// Constructs a piecewise matrix coefficient of dimension h by w
1196 explicit PWMatrixCoefficient(int h, int w, bool symm = false)
1197 : MatrixCoefficient(h, w, symm) {}
1198
1199 /// Construct the coefficient using arrays describing the pieces
1200 /** \param dim - size of the square matrix-valued result
1201 \param attr - an array of attribute numbers for each piece
1202 \param coefs - the corresponding array of MatrixCoefficient pointers
1203 \param symm - true if the result will be symmetric, false otherwise
1204 Any missing attributes or NULL coefficient pointers will result in a
1205 zero matrix being returned.
1206
1207 \note Ownership of the MatrixCoefficient objects will NOT be
1208 transferred to this object.
1209 */
1211 const Array<MatrixCoefficient*> & coefs,
1212 bool symm=false)
1213 : MatrixCoefficient(dim, symm) { InitMap(attr, coefs); }
1214
1215 /// Construct the coefficient using arrays describing the pieces
1216 /** \param h - height of the matrix-valued result
1217 \param w - width of the matrix-valued result
1218 \param attr - an array of attribute numbers for each piece
1219 \param coefs - the corresponding array of MatrixCoefficient pointers
1220 \param symm - true if the result will be symmetric, false otherwise
1221 Any missing attributes or NULL coefficient pointers will result in a
1222 zero matrix being returned for that attribute.
1223
1224 \note Ownership of the MatrixCoefficient objects will NOT be
1225 transferred to this object.
1226 */
1227 PWMatrixCoefficient(int h, int w, const Array<int> & attr,
1228 const Array<MatrixCoefficient*> & coefs,
1229 bool symm=false)
1230 : MatrixCoefficient(h, w, symm) { InitMap(attr, coefs); }
1231
1232 /// Set the time for time dependent coefficients
1233 void SetTime(real_t t) override;
1234
1235 /// Replace a set of coefficients
1237 const Array<MatrixCoefficient*> & coefs)
1238 { InitMap(attr, coefs); }
1239
1240 /// Replace a single coefficient for a particular attribute
1241 void UpdateCoefficient(int attr, MatrixCoefficient & coef);
1242
1243 /// Remove a single MatrixCoefficient for a particular attribute
1244 void ZeroCoefficient(int attr)
1245 { pieces.erase(attr); }
1246
1247 /// Evaluate the coefficient.
1249 const IntegrationPoint &ip) override;
1250};
1251
1252/** @brief A matrix coefficient with an optional scalar coefficient multiplier
1253 \a q. The matrix function can either be represented by a std function or
1254 a constant matrix provided when constructing this object. */
1256{
1257private:
1258 std::function<void(const Vector &, DenseMatrix &)> Function;
1259 std::function<void(const Vector &, Vector &)> SymmFunction; // deprecated
1260 std::function<void(const Vector &, real_t, DenseMatrix &)> TDFunction;
1261
1262 Coefficient *Q;
1263 DenseMatrix mat;
1264
1265public:
1266 /// Define a time-independent square matrix coefficient from a std function
1267 /** \param dim - the size of the matrix
1268 \param F - time-independent function
1269 \param q - optional scalar Coefficient to scale the matrix coefficient */
1271 std::function<void(const Vector &, DenseMatrix &)> F,
1272 Coefficient *q = nullptr)
1273 : MatrixCoefficient(dim), Function(std::move(F)), Q(q), mat(0)
1274 { }
1275
1276 /// Define a constant matrix coefficient times a scalar Coefficient
1277 /** \param m - constant matrix
1278 \param q - optional scalar Coefficient to scale the matrix coefficient */
1280 : MatrixCoefficient(m.Height(), m.Width()), Q(&q), mat(m)
1281 { }
1282
1283 /** @brief Define a time-independent symmetric square matrix coefficient from
1284 a std function */
1285 /** \param dim - the size of the matrix
1286 \param SymmF - function used in EvalSymmetric
1287 \param q - optional scalar Coefficient to scale the matrix coefficient
1288 @deprecated Use another constructor without setting SymmFunction. */
1290 std::function<void(const Vector &, Vector &)> SymmF,
1291 Coefficient *q = NULL)
1292 : MatrixCoefficient(dim, true), SymmFunction(std::move(SymmF)), Q(q), mat(0)
1293 { }
1294
1295 /// Define a time-dependent square matrix coefficient from a std function
1296 /** \param dim - the size of the matrix
1297 \param TDF - time-dependent function
1298 \param q - optional scalar Coefficient to scale the matrix coefficient */
1300 std::function<void(const Vector &, real_t, DenseMatrix &)> TDF,
1301 Coefficient *q = nullptr)
1302 : MatrixCoefficient(dim), TDFunction(std::move(TDF)), Q(q)
1303 { }
1304
1305 /// Set the time for internally stored coefficients
1306 void SetTime(real_t t) override;
1307
1308 /// Evaluate the matrix coefficient at @a ip.
1310 const IntegrationPoint &ip) override;
1311
1312 /// (DEPRECATED) Evaluate the symmetric matrix coefficient at @a ip.
1313 /** @deprecated Use Eval() instead. */
1315 const IntegrationPoint &ip) override;
1316
1318};
1319
1320
1321/** @brief Matrix coefficient defined by a matrix of scalar coefficients.
1322 Coefficients that are not set will evaluate to zero in the vector. The
1323 coefficient is stored as a flat Array with indexing (i,j) -> i*width+j. */
1325{
1326private:
1328 Array<bool> ownCoeff;
1329
1330public:
1331 /** @brief Construct a coefficient matrix of dimensions @a dim * @a dim. The
1332 actual coefficients still need to be added with Set(). */
1333 explicit MatrixArrayCoefficient (int dim);
1334
1335 /// Set the time for internally stored coefficients
1336 void SetTime(real_t t) override;
1337
1338 /// Get the coefficient located at (i,j) in the matrix.
1339 Coefficient* GetCoeff (int i, int j) { return Coeff[i*width+j]; }
1340
1341 /** @brief Set the coefficient located at (i,j) in the matrix. By default
1342 this will take ownership of the Coefficient passed in, but this
1343 can be overridden with the @a own parameter. */
1344 void Set(int i, int j, Coefficient * c, bool own=true);
1345
1346 /// Set ownership of the coefficient at (i,j) in the matrix
1347 void SetOwnership(int i, int j, bool own) { ownCoeff[i*width+j] = own; }
1348
1349 /// Get ownership of the coefficient at (i,j) in the matrix
1350 bool GetOwnership(int i, int j) const { return ownCoeff[i*width+j]; }
1351
1353
1354 /// Evaluate coefficient located at (i,j) in the matrix using integration
1355 /// point @a ip.
1357 { return Coeff[i*width+j] ? Coeff[i*width+j] -> Eval(T, ip, GetTime()) : 0.0; }
1358
1359 /// Evaluate the matrix coefficient @a ip.
1361 const IntegrationPoint &ip) override;
1362
1363 virtual ~MatrixArrayCoefficient();
1364};
1365
1366/** @brief Matrix coefficient defined row-wise by an array of vector
1367 coefficients. Rows that are not set will evaluate to zero. The
1368 matrix coefficient is stored as an array indexing the rows of
1369 the matrix. */
1371{
1372private:
1374 Array<bool> ownCoeff;
1375
1376public:
1377 /** @brief Construct a coefficient matrix of dimensions @a dim * @a dim. The
1378 actual coefficients still need to be added with Set(). */
1379 explicit MatrixArrayVectorCoefficient (int dim);
1380
1381 /// Set the time for internally stored coefficients
1382 void SetTime(real_t t) override;
1383
1384 /// Get the vector coefficient located at the i-th row of the matrix
1385 VectorCoefficient* GetCoeff (int i) { return Coeff[i]; }
1386
1387 /** @brief Set the coefficient located at the i-th row of the matrix.
1388 By this will take ownership of the Coefficient passed in, but this
1389 can be overridden with the @a own parameter. */
1390 void Set(int i, VectorCoefficient * c, bool own=true);
1391
1392 /// Set ownership of the i'th coefficient
1393 void SetOwnership(int i, bool own) { ownCoeff[i] = own; }
1394
1395 /// Get ownership of the i'th coefficient
1396 bool GetOwnership(int i) const { return ownCoeff[i]; }
1397
1399
1400 /// Evaluate coefficient located at the i-th row of the matrix using integration
1401 /// point @a ip.
1402 void Eval(int i, Vector &V, ElementTransformation &T,
1403 const IntegrationPoint &ip);
1404
1405 /// Evaluate the matrix coefficient @a ip.
1407 const IntegrationPoint &ip) override;
1408
1410};
1411
1412
1413/** @brief Derived matrix coefficient that has the value of the parent matrix
1414 coefficient where it is active and is zero otherwise. */
1416{
1417private:
1419 Array<int> active_attr;
1420
1421public:
1422 /** @brief Construct with a parent matrix coefficient and an array of zeros
1423 and ones representing the attributes for which this coefficient should be
1424 active. */
1427 { c = &mc; attr.Copy(active_attr); }
1428
1429 /// Set the time for internally stored coefficients
1430 void SetTime(real_t t) override;
1431
1432 /// Evaluate the matrix coefficient at @a ip.
1434 const IntegrationPoint &ip) override;
1435};
1436
1437/// Coefficients based on sums, products, or other functions of coefficients.
1438///@{
1439/** @brief Scalar coefficient defined as the linear combination of two scalar
1440 coefficients or a scalar and a scalar coefficient */
1442{
1443private:
1444 real_t aConst;
1445 Coefficient * a;
1446 Coefficient * b;
1447
1448 real_t alpha;
1449 real_t beta;
1450
1451public:
1452 /// Constructor with one coefficient. Result is alpha_ * A + beta_ * B
1454 real_t alpha_ = 1.0, real_t beta_ = 1.0)
1455 : aConst(A), a(NULL), b(&B), alpha(alpha_), beta(beta_) { }
1456
1457 /// Constructor with two coefficients. Result is alpha_ * A + beta_ * B.
1459 real_t alpha_ = 1.0, real_t beta_ = 1.0)
1460 : aConst(0.0), a(&A), b(&B), alpha(alpha_), beta(beta_) { }
1461
1462 /// Set the time for internally stored coefficients
1463 void SetTime(real_t t) override;
1464
1465 /// @copydoc Coefficient::Project(QuadratureFunction &)
1466 void Project(QuadratureFunction &qf) override;
1467
1468 /// Reset the first term in the linear combination as a constant
1469 void SetAConst(real_t A) { a = NULL; aConst = A; }
1470 /// Return the first term in the linear combination
1471 real_t GetAConst() const { return aConst; }
1472
1473 /// Reset the first term in the linear combination
1474 void SetACoef(Coefficient &A) { a = &A; }
1475 /// Return the first term in the linear combination
1476 Coefficient * GetACoef() const { return a; }
1477
1478 /// Reset the second term in the linear combination
1479 void SetBCoef(Coefficient &B) { b = &B; }
1480 /// Return the second term in the linear combination
1481 Coefficient * GetBCoef() const { return b; }
1482
1483 /// Reset the factor in front of the first term in the linear combination
1484 void SetAlpha(real_t alpha_) { alpha = alpha_; }
1485 /// Return the factor in front of the first term in the linear combination
1486 real_t GetAlpha() const { return alpha; }
1487
1488 /// Reset the factor in front of the second term in the linear combination
1489 void SetBeta(real_t beta_) { beta = beta_; }
1490 /// Return the factor in front of the second term in the linear combination
1491 real_t GetBeta() const { return beta; }
1492
1493 /// Evaluate the coefficient at @a ip.
1495 const IntegrationPoint &ip) override
1496 {
1497 return alpha * ((a == NULL ) ? aConst : a->Eval(T, ip) )
1498 + beta * b->Eval(T, ip);
1499 }
1500};
1501
1502
1503/// Base class for symmetric matrix coefficients that optionally depend on time and space.
1505{
1506protected:
1507
1508 /// Internal matrix used when evaluating this coefficient as a DenseMatrix.
1510public:
1511 /// Construct a dim x dim matrix coefficient.
1514
1515 /// Get the size of the matrix.
1516 int GetSize() const { return height; }
1517
1518 /// @brief Fill the QuadratureFunction @a qf by evaluating the coefficient at
1519 /// the quadrature points.
1520 ///
1521 /// @note As opposed to MatrixCoefficient::Project, this function stores only
1522 /// the @a symmetric part of the matrix at each quadrature point.
1523 ///
1524 /// The @a vdim of the coefficient should be equal to height*(height+1)/2.
1525 virtual void ProjectSymmetric(QuadratureFunction &qf);
1526
1527 /** @brief Evaluate the matrix coefficient in the element described by @a T
1528 at the point @a ip, storing the result as a symmetric matrix @a K. */
1529 /** @note When this method is called, the caller must make sure that the
1530 IntegrationPoint associated with @a T is the same as @a ip. This can be
1531 achieved by calling T.SetIntPoint(&ip). */
1533 const IntegrationPoint &ip) = 0;
1534
1535 /** @brief Evaluate the matrix coefficient in the element described by @a T
1536 at the point @a ip, storing the result as a dense matrix @a K. */
1537 /** This function allows the use of SymmetricMatrixCoefficient in situations
1538 where the symmetry is not taken advantage of.
1539
1540 @note When this method is called, the caller must make sure that the
1541 IntegrationPoint associated with @a T is the same as @a ip. This can be
1542 achieved by calling T.SetIntPoint(&ip). */
1544 const IntegrationPoint &ip) override;
1545
1546
1547 /// @deprecated Return a reference to the internal matrix used when evaluating this coefficient as a DenseMatrix.
1548 MFEM_DEPRECATED const DenseSymmetricMatrix& GetMatrix() { return mat_aux; }
1549
1551};
1552
1553
1554/// A matrix coefficient that is constant in space and time.
1556{
1557private:
1559
1560public:
1561 ///Construct using matrix @a m for the constant.
1565 /// Evaluate the matrix coefficient at @a ip.
1567 const IntegrationPoint &ip) override { M = mat; }
1568
1569 /// Return a reference to the constant matrix.
1570 const DenseSymmetricMatrix& GetMatrix() { return mat; }
1571
1572};
1573
1574
1575/** @brief A matrix coefficient with an optional scalar coefficient multiplier
1576 \a q. The matrix function can either be represented by a std function or
1577 a constant matrix provided when constructing this object. */
1579{
1580private:
1581 std::function<void(const Vector &, DenseSymmetricMatrix &)> Function;
1582 std::function<void(const Vector &, real_t, DenseSymmetricMatrix &)> TDFunction;
1583
1584 Coefficient *Q;
1586
1587public:
1588 /// Define a time-independent symmetric matrix coefficient from a std function
1589 /** \param dim - the size of the matrix
1590 \param F - time-independent function
1591 \param q - optional scalar Coefficient to scale the matrix coefficient */
1593 std::function<void(const Vector &, DenseSymmetricMatrix &)> F,
1594 Coefficient *q = nullptr)
1595 : SymmetricMatrixCoefficient(dim), Function(std::move(F)), Q(q), mat(0)
1596 { }
1597
1598 /// Define a constant matrix coefficient times a scalar Coefficient
1599 /** \param m - constant matrix
1600 \param q - optional scalar Coefficient to scale the matrix coefficient */
1602 Coefficient &q)
1603 : SymmetricMatrixCoefficient(m.Height()), Q(&q), mat(m)
1604 { }
1605
1606 /// Define a time-dependent square matrix coefficient from a std function
1607 /** \param dim - the size of the matrix
1608 \param TDF - time-dependent function
1609 \param q - optional scalar Coefficient to scale the matrix coefficient */
1611 std::function<void(const Vector &, real_t, DenseSymmetricMatrix &)> TDF,
1612 Coefficient *q = nullptr)
1613 : SymmetricMatrixCoefficient(dim), TDFunction(std::move(TDF)), Q(q)
1614 { }
1615
1616 /// Set the time for internally stored coefficients
1617 void SetTime(real_t t) override;
1618
1620 /// Evaluate the matrix coefficient at @a ip.
1622 const IntegrationPoint &ip) override;
1623
1625};
1626
1627
1628/** @brief Scalar coefficient defined as the product of two scalar coefficients
1629 or a scalar and a scalar coefficient. */
1631{
1632private:
1633 real_t aConst;
1634 Coefficient * a;
1635 Coefficient * b;
1636
1637public:
1638 /// Constructor with one coefficient. Result is A * B.
1640 : aConst(A), a(NULL), b(&B) { }
1641
1642 /// Constructor with two coefficients. Result is A * B.
1644 : aConst(0.0), a(&A), b(&B) { }
1645
1646 /// Set the time for internally stored coefficients
1647 void SetTime(real_t t) override;
1648
1649 /// @copydoc Coefficient::Project(QuadratureFunction &)
1650 void Project(QuadratureFunction &qf) override;
1651
1652 /// Reset the first term in the product as a constant
1653 void SetAConst(real_t A) { a = NULL; aConst = A; }
1654 /// Return the first term in the product
1655 real_t GetAConst() const { return aConst; }
1656
1657 /// Reset the first term in the product
1658 void SetACoef(Coefficient &A) { a = &A; }
1659 /// Return the first term in the product
1660 Coefficient * GetACoef() const { return a; }
1661
1662 /// Reset the second term in the product
1663 void SetBCoef(Coefficient &B) { b = &B; }
1664 /// Return the second term in the product
1665 Coefficient * GetBCoef() const { return b; }
1666
1667 /// Evaluate the coefficient at @a ip.
1669 const IntegrationPoint &ip) override
1670 { return ((a == NULL ) ? aConst : a->Eval(T, ip) ) * b->Eval(T, ip); }
1671};
1672
1673/** @brief Scalar coefficient defined as the ratio of two scalars where one or
1674 both scalars are scalar coefficients. */
1676{
1677private:
1678 real_t aConst;
1679 real_t bConst;
1680 Coefficient * a;
1681 Coefficient * b;
1682
1683public:
1684 /** Initialize a coefficient which returns A / B where @a A is a
1685 constant and @a B is a scalar coefficient */
1687 : aConst(A), bConst(1.0), a(NULL), b(&B) { }
1688 /** Initialize a coefficient which returns A / B where @a A and @a B are both
1689 scalar coefficients */
1691 : aConst(0.0), bConst(1.0), a(&A), b(&B) { }
1692 /** Initialize a coefficient which returns A / B where @a A is a
1693 scalar coefficient and @a B is a constant */
1695 : aConst(0.0), bConst(B), a(&A), b(NULL) { }
1696
1697 /// Set the time for internally stored coefficients
1698 void SetTime(real_t t) override;
1699
1700 /// @copydoc Coefficient::Project(QuadratureFunction &)
1701 void Project(QuadratureFunction &qf) override;
1702
1703 /// Reset the numerator in the ratio as a constant
1704 void SetAConst(real_t A) { a = NULL; aConst = A; }
1705 /// Return the numerator of the ratio
1706 real_t GetAConst() const { return aConst; }
1707
1708 /// Reset the denominator in the ratio as a constant
1709 void SetBConst(real_t B) { b = NULL; bConst = B; }
1710 /// Return the denominator of the ratio
1711 real_t GetBConst() const { return bConst; }
1712
1713 /// Reset the numerator in the ratio
1714 void SetACoef(Coefficient &A) { a = &A; }
1715 /// Return the numerator of the ratio
1716 Coefficient * GetACoef() const { return a; }
1717
1718 /// Reset the denominator in the ratio
1719 void SetBCoef(Coefficient &B) { b = &B; }
1720 /// Return the denominator of the ratio
1721 Coefficient * GetBCoef() const { return b; }
1722
1723 /// Evaluate the coefficient
1725 const IntegrationPoint &ip) override
1726 {
1727 real_t den = (b == NULL ) ? bConst : b->Eval(T, ip);
1728 MFEM_ASSERT(den != 0.0, "Division by zero in RatioCoefficient");
1729 return ((a == NULL ) ? aConst : a->Eval(T, ip) ) / den;
1730 }
1731};
1732
1733/// Scalar coefficient defined as a scalar raised to a power
1735{
1736private:
1737 Coefficient * a;
1738
1739 real_t p;
1740
1741public:
1742 /// Construct with a coefficient and a constant power @a p_. Result is A^p.
1744 : a(&A), p(p_) { }
1745
1746 /// Set the time for internally stored coefficients
1747 void SetTime(real_t t) override;
1748
1749 /// Reset the base coefficient
1750 void SetACoef(Coefficient &A) { a = &A; }
1751 /// Return the base coefficient
1752 Coefficient * GetACoef() const { return a; }
1753
1754 /// Reset the exponent
1755 void SetExponent(real_t p_) { p = p_; }
1756 /// Return the exponent
1757 real_t GetExponent() const { return p; }
1758
1759 /// Evaluate the coefficient at @a ip.
1761 const IntegrationPoint &ip) override
1762 { return pow(a->Eval(T, ip), p); }
1763};
1764
1765
1766/// Scalar coefficient defined as the inner product of two vector coefficients
1768{
1769private:
1772
1773 mutable Vector va;
1774 mutable Vector vb;
1775public:
1776 /// Construct with the two vector coefficients. Result is $ A \cdot B $.
1778
1779 /// Set the time for internally stored coefficients
1780 void SetTime(real_t t) override;
1781
1782 /// Reset the first vector in the inner product
1783 void SetACoef(VectorCoefficient &A) { a = &A; }
1784 /// Return the first vector coefficient in the inner product
1785 VectorCoefficient * GetACoef() const { return a; }
1786
1787 /// Reset the second vector in the inner product
1788 void SetBCoef(VectorCoefficient &B) { b = &B; }
1789 /// Return the second vector coefficient in the inner product
1790 VectorCoefficient * GetBCoef() const { return b; }
1791
1792 /// Evaluate the coefficient at @a ip.
1794 const IntegrationPoint &ip) override;
1795
1796 /// @copydoc Coefficient::Project(QuadratureFunction &)
1797 void Project(QuadratureFunction &qf) override;
1798};
1799
1800/// Scalar coefficient defined as a cross product of two vectors in the xy-plane.
1802{
1803private:
1806
1807 mutable Vector va;
1808 mutable Vector vb;
1809
1810public:
1811 /// Constructor with two vector coefficients. Result is $ A_x B_y - A_y * B_x; $.
1813
1814 /// Set the time for internally stored coefficients
1815 void SetTime(real_t t) override;
1816
1817 /// Reset the first vector in the product
1818 void SetACoef(VectorCoefficient &A) { a = &A; }
1819 /// Return the first vector of the product
1820 VectorCoefficient * GetACoef() const { return a; }
1821
1822 /// Reset the second vector in the product
1823 void SetBCoef(VectorCoefficient &B) { b = &B; }
1824 /// Return the second vector of the product
1825 VectorCoefficient * GetBCoef() const { return b; }
1826
1827 /// Evaluate the coefficient at @a ip.
1829 const IntegrationPoint &ip) override;
1830};
1831
1832/// Scalar coefficient defined as the determinant of a matrix coefficient
1834{
1835private:
1837
1838 mutable DenseMatrix ma;
1839
1840public:
1841 /// Construct with the matrix.
1843
1844 /// Set the time for internally stored coefficients
1845 void SetTime(real_t t) override;
1846
1847 /// Reset the matrix coefficient
1848 void SetACoef(MatrixCoefficient &A) { a = &A; }
1849 /// Return the matrix coefficient
1850 MatrixCoefficient * GetACoef() const { return a; }
1851
1852 /// Evaluate the determinant coefficient at @a ip.
1854 const IntegrationPoint &ip) override;
1855};
1856
1857/// Scalar coefficient defined as the trace of a matrix coefficient
1859{
1860private:
1862
1863 mutable DenseMatrix ma;
1864
1865public:
1866 /// Construct with the matrix.
1868
1869 /// Set the time for internally stored coefficients
1870 void SetTime(real_t t) override;
1871
1872 /// Reset the matrix coefficient
1873 void SetACoef(MatrixCoefficient &A) { a = &A; }
1874 /// Return the matrix coefficient
1875 MatrixCoefficient * GetACoef() const { return a; }
1876
1877 /// Evaluate the trace coefficient at @a ip.
1879 const IntegrationPoint &ip) override;
1880};
1881
1882/// Scalar coefficient defined as component of a vector coefficient
1884{
1885private:
1886 VectorCoefficient *a = nullptr;
1887
1888 mutable Vector va;
1889 int component;
1890
1891public:
1892 /// Construct with a vector coefficient.
1894 : a(&A), va(A.GetVDim()), component(0) {};
1895
1896 /// Construct with a vector coefficient and a component index @a c.
1898
1899 /// Set the time for internally stored coefficients
1900 void SetTime(real_t t) override;
1901
1902 /// Reset the vector coefficient
1903 void SetACoef(VectorCoefficient &A) { a = &A; }
1904
1905 /// Return the vector coefficient
1906 VectorCoefficient * GetACoef() const { return a; }
1907
1908 /// Set the component
1909 void SetComponent(int c);
1910
1911 /// Return the component
1912 int GetComponent() const { return component; }
1913
1914 /// Evaluate the component coefficient at @a ip.
1916 const IntegrationPoint &ip) override;
1917};
1918
1919/// Scalar coefficient defined as component of a matrix coefficient
1921{
1922private:
1923 MatrixCoefficient *a = nullptr;
1924
1925 mutable DenseMatrix ma;
1926 int row_idx,col_idx;
1927
1928public:
1929 /// Construct with a matrix coefficient.
1931 : a(&A), ma(A.GetHeight(), A.GetWidth()), row_idx(0), col_idx(0) {};
1932
1933 /// Construct with the matrix coefficient.
1935
1936 /// Set the time for internally stored coefficients
1937 void SetTime(real_t t) override;
1938
1939 /// Reset the matrix coefficient
1940 void SetACoef(MatrixCoefficient &A) { a = &A; }
1941
1942 /// Return the matrix coefficient
1943 MatrixCoefficient * GetACoef() const { return a; }
1944
1945 /// Reset the index
1946 void SetRowIndex(int ri);
1947
1948 /// Return the index
1949 int GetRowIndex() const { return row_idx; }
1950
1951 /// Reset the index
1952 void SetColumnIndex(int ci);
1953
1954 /// Return the index
1955 int GetColumnIndex() const { return col_idx; }
1956
1957
1958 /// Evaluate the component coefficient at @a ip.
1960 const IntegrationPoint &ip) override;
1961};
1962
1963/// Vector coefficient defined as the linear combination of two vectors
1965{
1966private:
1967 VectorCoefficient * ACoef;
1968 VectorCoefficient * BCoef;
1969
1970 Vector A;
1971 Vector B;
1972
1973 Coefficient * alphaCoef;
1974 Coefficient * betaCoef;
1975
1976 real_t alpha;
1977 real_t beta;
1978
1979 mutable Vector va;
1980
1981public:
1982 /** Constructor with no coefficients.
1983 To be used with the various "Set" methods */
1985
1986 /** Constructor with two vector coefficients.
1987 Result is alpha_ * A + beta_ * B */
1989 real_t alpha_ = 1.0, real_t beta_ = 1.0);
1990
1991 /** Constructor with scalar coefficients.
1992 Result is alpha_ * A_ + beta_ * B_ */
1994 Coefficient &alpha_, Coefficient &beta_);
1995
1996 /// Set the time for internally stored coefficients
1997 void SetTime(real_t t) override;
1998
1999 /// Reset the first vector coefficient
2000 void SetACoef(VectorCoefficient &A_) { ACoef = &A_; }
2001 /// Return the first vector coefficient
2002 VectorCoefficient * GetACoef() const { return ACoef; }
2003
2004 /// Reset the second vector coefficient
2005 void SetBCoef(VectorCoefficient &B_) { BCoef = &B_; }
2006 /// Return the second vector coefficient
2007 VectorCoefficient * GetBCoef() const { return BCoef; }
2008
2009 /// Reset the factor in front of the first vector coefficient
2010 void SetAlphaCoef(Coefficient &A_) { alphaCoef = &A_; }
2011 /// Return the factor in front of the first vector coefficient
2012 Coefficient * GetAlphaCoef() const { return alphaCoef; }
2013
2014 /// Reset the factor in front of the second vector coefficient
2015 void SetBetaCoef(Coefficient &B_) { betaCoef = &B_; }
2016 /// Return the factor in front of the second vector coefficient
2017 Coefficient * GetBetaCoef() const { return betaCoef; }
2018
2019 /// Reset the first vector as a constant
2020 void SetA(const Vector &A_) { A = A_; ACoef = NULL; }
2021 /// Return the first vector constant
2022 const Vector & GetA() const { return A; }
2023
2024 /// Reset the second vector as a constant
2025 void SetB(const Vector &B_) { B = B_; BCoef = NULL; }
2026 /// Return the second vector constant
2027 const Vector & GetB() const { return B; }
2028
2029 /// Reset the factor in front of the first vector coefficient as a constant
2030 void SetAlpha(real_t alpha_) { alpha = alpha_; alphaCoef = NULL; }
2031 /// Return the factor in front of the first vector coefficient
2032 real_t GetAlpha() const { return alpha; }
2033
2034 /// Reset the factor in front of the second vector coefficient as a constant
2035 void SetBeta(real_t beta_) { beta = beta_; betaCoef = NULL; }
2036 /// Return the factor in front of the second vector coefficient
2037 real_t GetBeta() const { return beta; }
2038
2039 /// Evaluate the coefficient at @a ip.
2040 void Eval(Vector &V, ElementTransformation &T,
2041 const IntegrationPoint &ip) override;
2043};
2044
2045/// Vector coefficient defined as a product of scalar and vector coefficients.
2047{
2048private:
2049 real_t aConst;
2050 Coefficient * a;
2052
2053public:
2054 /// Constructor with constant and vector coefficient. Result is A * B.
2056
2057 /// Constructor with two coefficients. Result is A * B.
2059
2060 /// Set the time for internally stored coefficients
2061 void SetTime(real_t t) override;
2062
2063 /// Reset the scalar factor as a constant
2064 void SetAConst(real_t A) { a = NULL; aConst = A; }
2065 /// Return the scalar factor
2066 real_t GetAConst() const { return aConst; }
2067
2068 /// Reset the scalar factor
2069 void SetACoef(Coefficient &A) { a = &A; }
2070 /// Return the scalar factor
2071 Coefficient * GetACoef() const { return a; }
2072
2073 /// Reset the vector factor
2074 void SetBCoef(VectorCoefficient &B) { b = &B; }
2075 /// Return the vector factor
2076 VectorCoefficient * GetBCoef() const { return b; }
2077
2078 /// Evaluate the coefficient at @a ip.
2079 void Eval(Vector &V, ElementTransformation &T,
2080 const IntegrationPoint &ip) override;
2082};
2083
2084/// Vector coefficient defined as a normalized vector field (returns v/|v|)
2086{
2087private:
2089
2090 real_t tol;
2091
2092public:
2093 /** @brief Return a vector normalized to a length of one
2094
2095 This class evaluates the vector coefficient @a A and, if |A| > @a tol,
2096 returns the normalized vector A / |A|. If |A| <= @a tol, the zero
2097 vector is returned.
2098 */
2100
2101 /// Set the time for internally stored coefficients
2102 void SetTime(real_t t) override;
2103
2104 /// Reset the vector coefficient
2105 void SetACoef(VectorCoefficient &A) { a = &A; }
2106 /// Return the vector coefficient
2107 VectorCoefficient * GetACoef() const { return a; }
2108
2109 /// Evaluate the coefficient at @a ip.
2110 void Eval(Vector &V, ElementTransformation &T,
2111 const IntegrationPoint &ip) override;
2113};
2114
2115/// Vector coefficient defined as a cross product of two vectors
2117{
2118private:
2121
2122 mutable Vector va;
2123 mutable Vector vb;
2124
2125public:
2126 /// Construct with the two coefficients. Result is A x B.
2128
2129 /// Set the time for internally stored coefficients
2130 void SetTime(real_t t) override;
2131
2132 /// Reset the first term in the product
2133 void SetACoef(VectorCoefficient &A) { a = &A; }
2134 /// Return the first term in the product
2135 VectorCoefficient * GetACoef() const { return a; }
2136
2137 /// Reset the second term in the product
2138 void SetBCoef(VectorCoefficient &B) { b = &B; }
2139 /// Return the second term in the product
2140 VectorCoefficient * GetBCoef() const { return b; }
2141
2142 /// Evaluate the coefficient at @a ip.
2143 void Eval(Vector &V, ElementTransformation &T,
2144 const IntegrationPoint &ip) override;
2146};
2147
2148/** @brief Vector coefficient defined as a product of a matrix coefficient and
2149 a vector coefficient. */
2151{
2152private:
2155
2156 mutable DenseMatrix ma;
2157 mutable Vector vb;
2158
2159public:
2160 /// Constructor with two coefficients. Result is A*B.
2162
2163 /// Set the time for internally stored coefficients
2164 void SetTime(real_t t) override;
2165
2166 /// Reset the matrix coefficient
2167 void SetACoef(MatrixCoefficient &A) { a = &A; }
2168 /// Return the matrix coefficient
2169 MatrixCoefficient * GetACoef() const { return a; }
2170
2171 /// Reset the vector coefficient
2172 void SetBCoef(VectorCoefficient &B) { b = &B; }
2173 /// Return the vector coefficient
2174 VectorCoefficient * GetBCoef() const { return b; }
2175
2176 /// Evaluate the vector coefficient at @a ip.
2177 void Eval(Vector &V, ElementTransformation &T,
2178 const IntegrationPoint &ip) override;
2180};
2181
2182/// Convenient alias for the MatrixVectorProductCoefficient
2184
2185/// Constant matrix coefficient defined as the identity of dimension d
2187{
2188private:
2189 int dim;
2190
2191public:
2192 /// Construct with the dimension of the square identity matrix.
2195
2196 /// Evaluate the matrix coefficient at @a ip.
2198 const IntegrationPoint &ip) override;
2199};
2200
2201/// Matrix coefficient defined as the linear combination of two matrices
2203{
2204private:
2207
2208 real_t alpha;
2209 real_t beta;
2210
2211 mutable DenseMatrix ma;
2212
2213public:
2214 /// Construct with the two coefficients. Result is alpha_ * A + beta_ * B.
2216 real_t alpha_ = 1.0, real_t beta_ = 1.0);
2217
2218 /// Set the time for internally stored coefficients
2219 void SetTime(real_t t) override;
2220
2221 /// Reset the first matrix coefficient
2222 void SetACoef(MatrixCoefficient &A) { a = &A; }
2223 /// Return the first matrix coefficient
2224 MatrixCoefficient * GetACoef() const { return a; }
2225
2226 /// Reset the second matrix coefficient
2227 void SetBCoef(MatrixCoefficient &B) { b = &B; }
2228 /// Return the second matrix coefficient
2229 MatrixCoefficient * GetBCoef() const { return b; }
2230
2231 /// Reset the factor in front of the first matrix coefficient
2232 void SetAlpha(real_t alpha_) { alpha = alpha_; }
2233 /// Return the factor in front of the first matrix coefficient
2234 real_t GetAlpha() const { return alpha; }
2235
2236 /// Reset the factor in front of the second matrix coefficient
2237 void SetBeta(real_t beta_) { beta = beta_; }
2238 /// Return the factor in front of the second matrix coefficient
2239 real_t GetBeta() const { return beta; }
2240
2241 /// Evaluate the matrix coefficient at @a ip.
2243 const IntegrationPoint &ip) override;
2244};
2245
2246/// Matrix coefficient defined as the product of two matrices
2248{
2249private:
2252
2253 mutable DenseMatrix ma;
2254 mutable DenseMatrix mb;
2255
2256public:
2257 /// Construct with the two coefficients. Result is A * B.
2259
2260 /// Reset the first matrix coefficient
2261 void SetACoef(MatrixCoefficient &A) { a = &A; }
2262 /// Return the first matrix coefficient
2263 MatrixCoefficient * GetACoef() const { return a; }
2264
2265 /// Reset the second matrix coefficient
2266 void SetBCoef(MatrixCoefficient &B) { b = &B; }
2267 /// Return the second matrix coefficient
2268 MatrixCoefficient * GetBCoef() const { return b; }
2269
2270 /// Evaluate the matrix coefficient at @a ip.
2272 const IntegrationPoint &ip) override;
2273};
2274
2275/** @brief Matrix coefficient defined as a product of a scalar coefficient and a
2276 matrix coefficient.*/
2278{
2279private:
2280 real_t aConst;
2281 Coefficient * a;
2283
2284public:
2285 /// Constructor with one coefficient. Result is A*B.
2287
2288 /// Constructor with two coefficients. Result is A*B.
2290
2291 /// Set the time for internally stored coefficients
2292 void SetTime(real_t t) override;
2293
2294 /// Reset the scalar factor as a constant
2295 void SetAConst(real_t A) { a = NULL; aConst = A; }
2296 /// Return the scalar factor
2297 real_t GetAConst() const { return aConst; }
2298
2299 /// Reset the scalar factor
2300 void SetACoef(Coefficient &A) { a = &A; }
2301 /// Return the scalar factor
2302 Coefficient * GetACoef() const { return a; }
2303
2304 /// Reset the matrix factor
2305 void SetBCoef(MatrixCoefficient &B) { b = &B; }
2306 /// Return the matrix factor
2307 MatrixCoefficient * GetBCoef() const { return b; }
2308
2309 /// Evaluate the matrix coefficient at @a ip.
2311 const IntegrationPoint &ip) override;
2312};
2313
2314/// Matrix coefficient defined as the transpose of a matrix coefficient
2316{
2317private:
2319
2320public:
2321 /// Construct with the matrix coefficient. Result is $ A^T $.
2323
2324 /// Set the time for internally stored coefficients
2325 void SetTime(real_t t) override;
2326
2327 /// Reset the matrix coefficient
2328 void SetACoef(MatrixCoefficient &A) { a = &A; }
2329 /// Return the matrix coefficient
2330 MatrixCoefficient * GetACoef() const { return a; }
2331
2332 /// Evaluate the matrix coefficient at @a ip.
2334 const IntegrationPoint &ip) override;
2335};
2336
2337/// Matrix coefficient defined as the inverse of a matrix coefficient.
2339{
2340private:
2342
2343public:
2344 /// Construct with the matrix coefficient. Result is $ A^{-1} $.
2346
2347 /// Set the time for internally stored coefficients
2348 void SetTime(real_t t) override;
2349
2350 /// Reset the matrix coefficient
2351 void SetACoef(MatrixCoefficient &A) { a = &A; }
2352 /// Return the matrix coefficient
2353 MatrixCoefficient * GetACoef() const { return a; }
2354
2355 /// Evaluate the matrix coefficient at @a ip.
2357 const IntegrationPoint &ip) override;
2358};
2359
2360/// Matrix coefficient defined as the exponential of a matrix coefficient.
2362{
2363private:
2365
2366public:
2367 /// Construct the matrix coefficient. Result is $ \exp(A) $.
2369
2370 /// Set the time for internally stored coefficients
2371 void SetTime(real_t t) override;
2372
2373 /// Reset the matrix coefficient
2374 void SetACoef(MatrixCoefficient &A) { a = &A; }
2375 /// Return the matrix coefficient
2376 MatrixCoefficient * GetACoef() const { return a; }
2377
2378 /// Evaluate the matrix coefficient at @a ip.
2380 const IntegrationPoint &ip) override;
2381};
2382
2383/// Matrix coefficient defined as the outer product of two vector coefficients.
2385{
2386private:
2389
2390 mutable Vector va;
2391 mutable Vector vb;
2392
2393public:
2394 /// Construct with two vector coefficients. Result is $ A B^T $.
2396
2397 /// Set the time for internally stored coefficients
2398 void SetTime(real_t t) override;
2399
2400 /// Reset the first vector in the outer product
2401 void SetACoef(VectorCoefficient &A) { a = &A; }
2402 /// Return the first vector coefficient in the outer product
2403 VectorCoefficient * GetACoef() const { return a; }
2404
2405 /// Reset the second vector in the outer product
2406 void SetBCoef(VectorCoefficient &B) { b = &B; }
2407 /// Return the second vector coefficient in the outer product
2408 VectorCoefficient * GetBCoef() const { return b; }
2409
2410 /// Evaluate the matrix coefficient at @a ip.
2412 const IntegrationPoint &ip) override;
2413};
2414
2415/** @brief Matrix coefficient defined as -a k x k x, for a vector k and scalar a
2416
2417 This coefficient returns $a * (|k|^2 I - k \otimes k)$, where I is
2418 the identity matrix and $\otimes$ indicates the outer product. This
2419 can be evaluated for vectors of any dimension but in three
2420 dimensions it corresponds to computing the cross product with k twice.
2421*/
2423{
2424private:
2425 real_t aConst;
2426 Coefficient * a;
2428
2429 mutable Vector vk;
2430
2431public:
2434
2435 /// Set the time for internally stored coefficients
2436 void SetTime(real_t t) override;
2437
2438 /// Reset the scalar factor as a constant
2439 void SetAConst(real_t A) { a = NULL; aConst = A; }
2440 /// Return the scalar factor
2441 real_t GetAConst() const { return aConst; }
2442
2443 /// Reset the scalar factor
2444 void SetACoef(Coefficient &A) { a = &A; }
2445 /// Return the scalar factor
2446 Coefficient * GetACoef() const { return a; }
2447
2448 /// Reset the vector factor
2449 void SetKCoef(VectorCoefficient &K) { k = &K; }
2450 /// Return the vector factor
2451 VectorCoefficient * GetKCoef() const { return k; }
2452
2453 /// Evaluate the matrix coefficient at @a ip.
2455 const IntegrationPoint &ip) override;
2456};
2457///@}
2458
2459/** @brief Vector quadrature function coefficient which requires that the
2460 quadrature rules used for this vector coefficient be the same as those that
2461 live within the supplied QuadratureFunction. */
2463{
2464private:
2465 const QuadratureFunction &QuadF; //do not own
2466 int index;
2467
2468public:
2469 /// Constructor with a quadrature function as input
2471
2472 /** Set the starting index within the QuadFunc that'll be used to project
2473 outwards as well as the corresponding length. The projected length should
2474 have the bounds of 1 <= length <= (length QuadFunc - index). */
2475 void SetComponent(int index_, int length_);
2476
2477 const QuadratureFunction& GetQuadFunction() const { return QuadF; }
2478
2480 void Eval(Vector &V, ElementTransformation &T,
2481 const IntegrationPoint &ip) override;
2482
2483 void Project(QuadratureFunction &qf) override;
2484
2486};
2487
2488/** @brief Quadrature function coefficient which requires that the quadrature
2489 rules used for this coefficient be the same as those that live within the
2490 supplied QuadratureFunction. */
2492{
2493private:
2494 const QuadratureFunction &QuadF;
2495
2496public:
2497 /// Constructor with a quadrature function as input
2499
2500 const QuadratureFunction& GetQuadFunction() const { return QuadF; }
2501
2502 real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override;
2503
2504 void Project(QuadratureFunction &qf) override;
2505
2507};
2508
2509/// Flags that determine what storage optimizations to use in CoefficientVector
2510enum class CoefficientStorage : int
2511{
2512 FULL = 0, ///< Store the coefficient as a full QuadratureFunction.
2513 CONSTANTS = 1 << 0, ///< Store constants using only @a vdim entries.
2514 SYMMETRIC = 1 << 1, ///< Store the triangular part of symmetric matrices.
2515 COMPRESSED = CONSTANTS | SYMMETRIC ///< Enable all above compressions.
2516};
2517
2522
2524{
2525 return int(a) & int(b);
2526}
2527
2528
2529/// @brief Class to represent a coefficient evaluated at quadrature points.
2530///
2531/// In the general case, a CoefficientVector is the same as a QuadratureFunction
2532/// with a coefficient projected onto it.
2533///
2534/// This class allows for some "compression" of the coefficient data, according
2535/// to the storage flags given by CoefficientStorage. For example, constant
2536/// coefficients can be stored using only @a vdim values, and symmetric matrices
2537/// can be stored using e.g. the upper triangular part of the matrix.
2539{
2540protected:
2541 CoefficientStorage storage; ///< Storage optimizations (see CoefficientStorage).
2542 int vdim; ///< Number of values per quadrature point.
2543 QuadratureSpaceBase &qs; ///< Associated QuadratureSpaceBase.
2544 QuadratureFunction *qf; ///< Internal QuadratureFunction (owned, may be NULL).
2545public:
2546 /// Create an empty CoefficientVector.
2549
2550 /// @brief Create a CoefficientVector from the given Coefficient and
2551 /// QuadratureSpaceBase.
2552 ///
2553 /// If @a coeff is NULL, it will be interpreted as a constant with value one.
2554 /// @sa CoefficientStorage for a description of @a storage_.
2557
2558 /// @brief Create a CoefficientVector from the given Coefficient and
2559 /// QuadratureSpaceBase.
2560 ///
2561 /// @sa CoefficientStorage for a description of @a storage_.
2564
2565 /// @brief Create a CoefficientVector from the given VectorCoefficient and
2566 /// QuadratureSpaceBase.
2567 ///
2568 /// @sa CoefficientStorage for a description of @a storage_.
2571
2572 /// @brief Create a CoefficientVector from the given MatrixCoefficient and
2573 /// QuadratureSpaceBase.
2574 ///
2575 /// @sa CoefficientStorage for a description of @a storage_.
2578
2579 /// @brief Evaluate the given Coefficient at the quadrature points defined by
2580 /// @ref qs.
2581 void Project(Coefficient &coeff);
2582
2583 /// @brief Evaluate the given VectorCoefficient at the quadrature points
2584 /// defined by @ref qs.
2585 ///
2586 /// @sa CoefficientVector for a description of the @a compress argument.
2587 void Project(VectorCoefficient &coeff);
2588
2589 /// @brief Evaluate the given MatrixCoefficient at the quadrature points
2590 /// defined by @ref qs.
2591 ///
2592 /// @sa CoefficientVector for a description of the @a compress argument.
2593 void Project(MatrixCoefficient &coeff, bool transpose=false);
2594
2595 /// @brief Project the transpose of @a coeff.
2596 ///
2597 /// @sa Project(MatrixCoefficient&, QuadratureSpace&, bool, bool)
2599
2600 /// Make this vector a reference to the given QuadratureFunction.
2601 void MakeRef(const QuadratureFunction &qf_);
2602
2603 /// Set this vector to the given constant.
2604 void SetConstant(real_t constant);
2605
2606 /// Set this vector to the given constant vector.
2607 void SetConstant(const Vector &constant);
2608
2609 /// Set this vector to the given constant matrix.
2610 void SetConstant(const DenseMatrix &constant, bool transpose=false);
2611
2612 /// Set this vector to the given constant symmetric matrix.
2613 void SetConstant(const DenseSymmetricMatrix &constant);
2614
2615 /// Return the number of values per quadrature point.
2616 int GetVDim() const;
2617
2619};
2620
2621/** @brief Compute the Lp norm of a function f.
2622 $ \| f \|_{Lp} = ( \int_\Omega | f |^p d\Omega)^{1/p} $ */
2624 const IntegrationRule *irs[]);
2625
2626/** @brief Compute the Lp norm of a vector function f = {f_i}_i=1...N.
2627 $ \| f \|_{Lp} = ( \sum_i \| f_i \|_{Lp}^p )^{1/p} $ */
2629 const IntegrationRule *irs[]);
2630
2631#ifdef MFEM_USE_MPI
2632/** @brief Compute the global Lp norm of a function f.
2633 $ \| f \|_{Lp} = ( \int_\Omega | f |^p d\Omega)^{1/p} $ */
2635 const IntegrationRule *irs[]);
2636
2637/** @brief Compute the global Lp norm of a vector function f = {f_i}_i=1...N.
2638 $ \| f \|_{Lp} = ( \sum_i \| f_i \|_{Lp}^p )^{1/p} $ */
2640 const IntegrationRule *irs[]);
2641#endif
2642
2643}
2644
2645#endif
void Copy(Array &copy) const
Create a copy of the internal array to the provided copy.
Definition array.hpp:1071
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
CartesianCoefficient(int comp_)
comp_ index of the desired component (0 -> x, 1 -> y, 2 -> z)
Scalar coefficient which returns the x-component of the evaluation point.
Scalar coefficient which returns the y-component of the evaluation point.
Scalar coefficient which returns the z-component of the evaluation point.
Class to represent a coefficient evaluated at quadrature points.
void SetConstant(real_t constant)
Set this vector to the given constant.
int vdim
Number of values per quadrature point.
void Project(Coefficient &coeff)
Evaluate the given Coefficient at the quadrature points defined by qs.
int GetVDim() const
Return the number of values per quadrature point.
CoefficientVector(QuadratureSpaceBase &qs_, CoefficientStorage storage_=CoefficientStorage::FULL)
Create an empty CoefficientVector.
QuadratureFunction * qf
Internal QuadratureFunction (owned, may be NULL).
CoefficientStorage storage
Storage optimizations (see CoefficientStorage).
QuadratureSpaceBase & qs
Associated QuadratureSpaceBase.
void ProjectTranspose(MatrixCoefficient &coeff)
Project the transpose of coeff.
void MakeRef(const QuadratureFunction &qf_)
Make this vector a reference to the given QuadratureFunction.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
real_t GetTime()
Get the time for time dependent coefficients.
virtual void SetTime(real_t t)
Set the time for time dependent coefficients.
virtual ~Coefficient()
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip, real_t t)
Evaluate the coefficient in the element described by T at the point ip at time t.
virtual void Project(QuadratureFunction &qf)
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
int GetVDim()
Returns dimension of the vector.
virtual real_t Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
A coefficient that is constant across space and time.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf with the constant value.
ConstantCoefficient(real_t c=1.0)
c is value of constant function
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
Matrix coefficient defined as -a k x k x, for a vector k and scalar a.
void SetKCoef(VectorCoefficient &K)
Reset the vector factor.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
CrossCrossCoefficient(real_t A, VectorCoefficient &K)
void SetACoef(Coefficient &A)
Reset the scalar factor.
void SetAConst(real_t A)
Reset the scalar factor as a constant.
real_t GetAConst() const
Return the scalar factor.
Coefficient * GetACoef() const
Return the scalar factor.
VectorCoefficient * GetKCoef() const
Return the vector factor.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
Vector coefficient defined as the Curl of a vector GridFunction.
void SetGridFunction(const GridFunction *gf)
Set the vector grid function.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector curl coefficient at ip.
const GridFunction * GetGridFunction() const
Get the vector grid function.
CurlGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a vector grid function gf. The grid function is not owned by the coeff...
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
Delta function coefficient optionally multiplied by a weight coefficient and a scaled time dependent ...
DeltaCoefficient(real_t x, real_t s)
Construct a delta function scaled by s and centered at (x,0.0,0.0)
const real_t * Center()
DeltaCoefficient(real_t x, real_t y, real_t s)
Construct a delta function scaled by s and centered at (x,y,0.0)
void GetDeltaCenter(Vector &center)
Write the center of the delta function into center.
Coefficient * Weight()
See SetWeight() for description of the weight Coefficient.
real_t(* tdf)(real_t)
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetTol(real_t tol_)
Set the tolerance used during projection onto GridFunction to identify the Mesh vertex where the Cent...
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
A DeltaFunction cannot be evaluated. Calling this method will cause an MFEM error,...
real_t Scale()
Return the scale factor times the optional time dependent function. Returns with when not set by th...
DeltaCoefficient()
Construct a unit delta function centered at (0.0,0.0,0.0)
void SetDeltaCenter(const Vector &center)
Set the center location of the delta function.
DeltaCoefficient(real_t x, real_t y, real_t z, real_t s)
Construct a delta function scaled by s and centered at (x,y,z)
void SetFunction(real_t(*f)(real_t))
Set a time-dependent function that multiplies the Scale().
void SetWeight(Coefficient *w)
Set a weight Coefficient that multiplies the DeltaCoefficient.
virtual real_t EvalDelta(ElementTransformation &T, const IntegrationPoint &ip)
The value of the function assuming we are evaluating at the delta center.
void SetScale(real_t s_)
Set the scale value multiplying the delta function.
real_t Tol()
Return the tolerance used to identify the mesh vertices.
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
Scalar coefficient defined as the determinant of a matrix coefficient.
DeterminantCoefficient(MatrixCoefficient &A)
Construct with the matrix.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the determinant coefficient at ip.
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
Scalar coefficient defined as the Divergence of a vector GridFunction.
void SetGridFunction(const GridFunction *gf)
Set the vector grid function.
const GridFunction * GetGridFunction() const
Get the vector grid function.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the scalar divergence coefficient at ip.
DivergenceGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a vector grid function gf. The grid function is not owned by the coeff...
Matrix coefficient defined as the exponential of a matrix coefficient.
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
ExponentialMatrixCoefficient(MatrixCoefficient &A)
Construct the matrix coefficient. Result is .
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
A general function coefficient.
FunctionCoefficient(std::function< real_t(const Vector &, real_t)> TDF)
Define a time-dependent coefficient from a std function.
std::function< real_t(const Vector &)> Function
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
std::function< real_t(const Vector &, real_t)> TDFunction
MFEM_DEPRECATED FunctionCoefficient(real_t(*f)(Vector &))
(DEPRECATED) Define a time-independent coefficient from a C-function
FunctionCoefficient(std::function< real_t(const Vector &)> F)
Define a time-independent coefficient from a std function.
MFEM_DEPRECATED FunctionCoefficient(real_t(*tdf)(Vector &, real_t))
(DEPRECATED) Define a time-dependent coefficient from a C-function
Vector coefficient defined as the Gradient of a scalar GridFunction.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the gradient vector coefficient at ip.
void SetGridFunction(const GridFunction *gf)
Set the scalar grid function.
const GridFunction * GetGridFunction() const
Get the scalar grid function.
GradientGridFunctionCoefficient(const GridFunction *gf)
Construct the coefficient with a scalar grid function gf. The grid function is not owned by the coeff...
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
const GridFunction * GetGridFunction() const
Get the internal GridFunction.
void SetGridFunction(const GridFunction *gf)
Set the internal GridFunction.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
GridFunctionCoefficient(const GridFunction *gf, int comp=1)
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:53
Constant matrix coefficient defined as the identity of dimension d.
IdentityMatrixCoefficient(int d)
Construct with the dimension of the square identity matrix.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
Scalar coefficient defined as the inner product of two vector coefficients.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
VectorCoefficient * GetACoef() const
Return the first vector coefficient in the inner product.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
VectorCoefficient * GetBCoef() const
Return the second vector coefficient in the inner product.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetBCoef(VectorCoefficient &B)
Reset the second vector in the inner product.
void SetACoef(VectorCoefficient &A)
Reset the first vector in the inner product.
InnerProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with the two vector coefficients. Result is .
Class for integration point with weight.
Definition intrules.hpp:35
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:96
Matrix coefficient defined as the inverse of a matrix coefficient.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
InverseMatrixCoefficient(MatrixCoefficient &A)
Construct with the matrix coefficient. Result is .
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
Matrix coefficient defined by a matrix of scalar coefficients. Coefficients that are not set will eva...
Coefficient * GetCoeff(int i, int j)
Get the coefficient located at (i,j) in the matrix.
void Set(int i, int j, Coefficient *c, bool own=true)
Set the coefficient located at (i,j) in the matrix. By default this will take ownership of the Coeffi...
bool GetOwnership(int i, int j) const
Get ownership of the coefficient at (i,j) in the matrix.
MatrixArrayCoefficient(int dim)
Construct a coefficient matrix of dimensions dim * dim. The actual coefficients still need to be adde...
real_t Eval(int i, int j, ElementTransformation &T, const IntegrationPoint &ip)
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetOwnership(int i, int j, bool own)
Set ownership of the coefficient at (i,j) in the matrix.
Matrix coefficient defined row-wise by an array of vector coefficients. Rows that are not set will ev...
void SetOwnership(int i, bool own)
Set ownership of the i'th coefficient.
void Eval(int i, Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
MatrixArrayVectorCoefficient(int dim)
Construct a coefficient matrix of dimensions dim * dim. The actual coefficients still need to be adde...
void SetTime(real_t t) override
Set the time for internally stored coefficients.
bool GetOwnership(int i) const
Get ownership of the i'th coefficient.
void Set(int i, VectorCoefficient *c, bool own=true)
Set the coefficient located at the i-th row of the matrix. By this will take ownership of the Coeffic...
VectorCoefficient * GetCoeff(int i)
Get the vector coefficient located at the i-th row of the matrix.
virtual void Project(QuadratureFunction &qf, bool transpose=false)
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points....
MatrixCoefficient(int dim, bool symm=false)
Construct a dim x dim matrix coefficient.
virtual void SetTime(real_t t)
Set the time for time dependent coefficients.
real_t GetTime()
Get the time for time dependent coefficients.
int GetVDim() const
For backward compatibility get the width of the matrix.
MatrixCoefficient(int h, int w, bool symm=false)
Construct a h x w matrix coefficient.
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
int GetWidth() const
Get the width of the matrix.
virtual void EvalSymmetric(Vector &K, ElementTransformation &T, const IntegrationPoint &ip)
(DEPRECATED) Evaluate a symmetric matrix coefficient.
int GetHeight() const
Get the height of the matrix.
Scalar coefficient defined as component of a matrix coefficient.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the component coefficient at ip.
int GetColumnIndex() const
Return the index.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
void SetRowIndex(int ri)
Reset the index.
int GetRowIndex() const
Return the index.
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
void SetColumnIndex(int ci)
Reset the index.
MatrixComponentCoefficient(MatrixCoefficient &A)
Construct with a matrix coefficient.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
A matrix coefficient that is constant in space and time.
MatrixConstantCoefficient(const DenseMatrix &m)
Construct using matrix m for the constant.
const DenseMatrix & GetMatrix()
Return a reference to the constant matrix.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
A matrix coefficient with an optional scalar coefficient multiplier q. The matrix function can either...
MatrixFunctionCoefficient(int dim, std::function< void(const Vector &, DenseMatrix &)> F, Coefficient *q=nullptr)
Define a time-independent square matrix coefficient from a std function.
void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
MatrixFunctionCoefficient(int dim, std::function< void(const Vector &, real_t, DenseMatrix &)> TDF, Coefficient *q=nullptr)
Define a time-dependent square matrix coefficient from a std function.
void EvalSymmetric(Vector &K, ElementTransformation &T, const IntegrationPoint &ip) override
(DEPRECATED) Evaluate the symmetric matrix coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
MatrixFunctionCoefficient(const DenseMatrix &m, Coefficient &q)
Define a constant matrix coefficient times a scalar Coefficient.
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.
Matrix coefficient defined as the product of two matrices.
MatrixProductCoefficient(MatrixCoefficient &A, MatrixCoefficient &B)
Construct with the two coefficients. Result is A * B.
MatrixCoefficient * GetACoef() const
Return the first matrix coefficient.
MatrixCoefficient * GetBCoef() const
Return the second matrix coefficient.
void SetBCoef(MatrixCoefficient &B)
Reset the second matrix coefficient.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void SetACoef(MatrixCoefficient &A)
Reset the first matrix coefficient.
Derived matrix coefficient that has the value of the parent matrix coefficient where it is active and...
void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
MatrixRestrictedCoefficient(MatrixCoefficient &mc, Array< int > &attr)
Construct with a parent matrix coefficient and an array of zeros and ones representing the attributes...
Matrix coefficient defined as the linear combination of two matrices.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
MatrixCoefficient * GetBCoef() const
Return the second matrix coefficient.
void SetBeta(real_t beta_)
Reset the factor in front of the second matrix coefficient.
real_t GetBeta() const
Return the factor in front of the second matrix coefficient.
void SetAlpha(real_t alpha_)
Reset the factor in front of the first matrix coefficient.
MatrixSumCoefficient(MatrixCoefficient &A, MatrixCoefficient &B, real_t alpha_=1.0, real_t beta_=1.0)
Construct with the two coefficients. Result is alpha_ * A + beta_ * B.
void SetACoef(MatrixCoefficient &A)
Reset the first matrix coefficient.
MatrixCoefficient * GetACoef() const
Return the first matrix coefficient.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
real_t GetAlpha() const
Return the factor in front of the first matrix coefficient.
void SetBCoef(MatrixCoefficient &B)
Reset the second matrix coefficient.
Vector coefficient defined as a product of a matrix coefficient and a vector coefficient.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
MatrixVectorProductCoefficient(MatrixCoefficient &A, VectorCoefficient &B)
Constructor with two coefficients. Result is A*B.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
void SetBCoef(VectorCoefficient &B)
Reset the vector coefficient.
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
VectorCoefficient * GetBCoef() const
Return the vector coefficient.
Mesh data type.
Definition mesh.hpp:67
Vector coefficient defined as a normalized vector field (returns v/|v|)
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
VectorCoefficient * GetACoef() const
Return the vector coefficient.
void SetACoef(VectorCoefficient &A)
Reset the vector coefficient.
NormalizedVectorCoefficient(VectorCoefficient &A, real_t tol=1e-6)
Return a vector normalized to a length of one.
Matrix coefficient defined as the outer product of two vector coefficients.
VectorCoefficient * GetACoef() const
Return the first vector coefficient in the outer product.
void SetACoef(VectorCoefficient &A)
Reset the first vector in the outer product.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetBCoef(VectorCoefficient &B)
Reset the second vector in the outer product.
OuterProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with two vector coefficients. Result is .
VectorCoefficient * GetBCoef() const
Return the second vector coefficient in the outer product.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
A piecewise coefficient with the pieces keyed off the element attribute numbers.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
PWCoefficient(const Array< int > &attr, const Array< Coefficient * > &coefs)
Construct the coefficient using arrays describing the pieces.
PWCoefficient()
Constructs a piecewise coefficient.
void ZeroCoefficient(int attr)
Remove a single Coefficient for a particular attribute.
void UpdateCoefficient(int attr, Coefficient &coef)
Replace a single Coefficient for a particular attribute.
void SetTime(real_t t) override
Set the time for time dependent coefficients.
void UpdateCoefficients(const Array< int > &attr, const Array< Coefficient * > &coefs)
Replace a set of coefficients.
A piecewise constant coefficient with the constants keyed off the element attribute numbers.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf with the piecewise constant values.
PWConstCoefficient(const Vector &c)
Construct the constant coefficient using a vector of constants.
int GetNConst()
Returns the number of constants representing different attributes.
real_t & operator()(int i)
Return a reference to the i-th constant.
void UpdateConstants(const Vector &c)
Update the constants with vector c.
PWConstCoefficient(int NumOfSubD=0)
Constructs a piecewise constant coefficient in NumOfSubD subdomains.
void operator=(real_t c)
Set the constants for all attributes to constant c.
A piecewise matrix-valued coefficient with the pieces keyed off the element attribute numbers.
void UpdateCoefficient(int attr, MatrixCoefficient &coef)
Replace a single coefficient for a particular attribute.
PWMatrixCoefficient(int dim, bool symm=false)
Constructs a piecewise matrix coefficient of dimension dim by dim.
PWMatrixCoefficient(int dim, const Array< int > &attr, const Array< MatrixCoefficient * > &coefs, bool symm=false)
Construct the coefficient using arrays describing the pieces.
PWMatrixCoefficient(int h, int w, const Array< int > &attr, const Array< MatrixCoefficient * > &coefs, bool symm=false)
Construct the coefficient using arrays describing the pieces.
PWMatrixCoefficient(int h, int w, bool symm=false)
Constructs a piecewise matrix coefficient of dimension h by w.
void SetTime(real_t t) override
Set the time for time dependent coefficients.
void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
void ZeroCoefficient(int attr)
Remove a single MatrixCoefficient for a particular attribute.
void UpdateCoefficients(const Array< int > &attr, const Array< MatrixCoefficient * > &coefs)
Replace a set of coefficients.
A piecewise vector-valued coefficient with the pieces keyed off the element attribute numbers.
void UpdateCoefficients(const Array< int > &attr, const Array< VectorCoefficient * > &coefs)
Replace a set of coefficients.
PWVectorCoefficient(int vd, const Array< int > &attr, const Array< VectorCoefficient * > &coefs)
Construct the coefficient using arrays describing the pieces.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
void ZeroCoefficient(int attr)
Remove a single VectorCoefficient for a particular attribute.
void UpdateCoefficient(int attr, VectorCoefficient &coef)
Replace a single Coefficient for a particular attribute.
void SetTime(real_t t) override
Set the time for time dependent coefficients.
PWVectorCoefficient(int vd)
Constructs a piecewise vector coefficient of dimension vd.
Class for parallel meshes.
Definition pmesh.hpp:35
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
Scalar coefficient defined as a scalar raised to a power.
real_t GetExponent() const
Return the exponent.
void SetExponent(real_t p_)
Reset the exponent.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
Coefficient * GetACoef() const
Return the base coefficient.
PowerCoefficient(Coefficient &A, real_t p_)
Construct with a coefficient and a constant power p_. Result is A^p.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetACoef(Coefficient &A)
Reset the base coefficient.
Scalar coefficient defined as the product of two scalar coefficients or a scalar and a scalar coeffic...
void SetBCoef(Coefficient &B)
Reset the second term in the product.
Coefficient * GetACoef() const
Return the first term in the product.
ProductCoefficient(real_t A, Coefficient &B)
Constructor with one coefficient. Result is A * B.
ProductCoefficient(Coefficient &A, Coefficient &B)
Constructor with two coefficients. Result is A * B.
real_t GetAConst() const
Return the first term in the product.
Coefficient * GetBCoef() const
Return the second term in the product.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetACoef(Coefficient &A)
Reset the first term in the product.
void SetAConst(real_t A)
Reset the first term in the product as a constant.
Quadrature function coefficient which requires that the quadrature rules used for this coefficient be...
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient in the element described by T at the point ip.
QuadratureFunctionCoefficient(const QuadratureFunction &qf)
Constructor with a quadrature function as input.
const QuadratureFunction & GetQuadFunction() const
Represents values or vectors of values at quadrature points on a mesh.
Definition qfunction.hpp:24
Abstract base class for QuadratureSpace and FaceQuadratureSpace.
Definition qspace.hpp:32
Scalar coefficient defined as the ratio of two scalars where one or both scalars are scalar coefficie...
Coefficient * GetBCoef() const
Return the denominator of the ratio.
void SetBConst(real_t B)
Reset the denominator in the ratio as a constant.
void SetAConst(real_t A)
Reset the numerator in the ratio as a constant.
void SetBCoef(Coefficient &B)
Reset the denominator in the ratio.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient.
RatioCoefficient(real_t A, Coefficient &B)
real_t GetBConst() const
Return the denominator of the ratio.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
Coefficient * GetACoef() const
Return the numerator of the ratio.
RatioCoefficient(Coefficient &A, Coefficient &B)
RatioCoefficient(Coefficient &A, real_t B)
void SetTime(real_t t) override
Set the time for internally stored coefficients.
real_t GetAConst() const
Return the numerator of the ratio.
void SetACoef(Coefficient &A)
Reset the numerator in the ratio.
Derived coefficient that takes the value of the parent coefficient for the active attributes and is z...
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
RestrictedCoefficient(Coefficient &c_, Array< int > &attr)
Construct with a parent coefficient and an array with ones marking the attributes on which this coeff...
void SetTime(real_t t) override
Set the time for internally stored coefficients.
Matrix coefficient defined as a product of a scalar coefficient and a matrix coefficient.
real_t GetAConst() const
Return the scalar factor.
void SetACoef(Coefficient &A)
Reset the scalar factor.
void SetBCoef(MatrixCoefficient &B)
Reset the matrix factor.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
MatrixCoefficient * GetBCoef() const
Return the matrix factor.
ScalarMatrixProductCoefficient(real_t A, MatrixCoefficient &B)
Constructor with one coefficient. Result is A*B.
Coefficient * GetACoef() const
Return the scalar factor.
void SetAConst(real_t A)
Reset the scalar factor as a constant.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
Vector coefficient defined as a product of scalar and vector coefficients.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
real_t GetAConst() const
Return the scalar factor.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
Coefficient * GetACoef() const
Return the scalar factor.
void SetBCoef(VectorCoefficient &B)
Reset the vector factor.
VectorCoefficient * GetBCoef() const
Return the vector factor.
ScalarVectorProductCoefficient(real_t A, VectorCoefficient &B)
Constructor with constant and vector coefficient. Result is A * B.
void SetACoef(Coefficient &A)
Reset the scalar factor.
void SetAConst(real_t A)
Reset the scalar factor as a constant.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
Scalar coefficient defined as the linear combination of two scalar coefficients or a scalar and a sca...
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
void SetBCoef(Coefficient &B)
Reset the second term in the linear combination.
Coefficient * GetACoef() const
Return the first term in the linear combination.
SumCoefficient(real_t A, Coefficient &B, real_t alpha_=1.0, real_t beta_=1.0)
Constructor with one coefficient. Result is alpha_ * A + beta_ * B.
void SetAlpha(real_t alpha_)
Reset the factor in front of the first term in the linear combination.
SumCoefficient(Coefficient &A, Coefficient &B, real_t alpha_=1.0, real_t beta_=1.0)
Constructor with two coefficients. Result is alpha_ * A + beta_ * B.
void SetACoef(Coefficient &A)
Reset the first term in the linear combination.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetBeta(real_t beta_)
Reset the factor in front of the second term in the linear combination.
real_t GetBeta() const
Return the factor in front of the second term in the linear combination.
real_t GetAlpha() const
Return the factor in front of the first term in the linear combination.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
Coefficient * GetBCoef() const
Return the second term in the linear combination.
void SetAConst(real_t A)
Reset the first term in the linear combination as a constant.
real_t GetAConst() const
Return the first term in the linear combination.
Base class for symmetric matrix coefficients that optionally depend on time and space.
virtual void ProjectSymmetric(QuadratureFunction &qf)
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
virtual void Eval(DenseSymmetricMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result as ...
SymmetricMatrixCoefficient(int dimension)
Construct a dim x dim matrix coefficient.
MFEM_DEPRECATED const DenseSymmetricMatrix & GetMatrix()
DenseSymmetricMatrix mat_aux
Internal matrix used when evaluating this coefficient as a DenseMatrix.
int GetSize() const
Get the size of the matrix.
A matrix coefficient that is constant in space and time.
const DenseSymmetricMatrix & GetMatrix()
Return a reference to the constant matrix.
SymmetricMatrixConstantCoefficient(const DenseSymmetricMatrix &m)
Construct using matrix m for the constant.
void Eval(DenseSymmetricMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
A matrix coefficient with an optional scalar coefficient multiplier q. The matrix function can either...
void SetTime(real_t t) override
Set the time for internally stored coefficients.
SymmetricMatrixFunctionCoefficient(const DenseSymmetricMatrix &m, Coefficient &q)
Define a constant matrix coefficient times a scalar Coefficient.
void Eval(DenseSymmetricMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
SymmetricMatrixFunctionCoefficient(int dim, std::function< void(const Vector &, DenseSymmetricMatrix &)> F, Coefficient *q=nullptr)
Define a time-independent symmetric matrix coefficient from a std function.
SymmetricMatrixFunctionCoefficient(int dim, std::function< void(const Vector &, real_t, DenseSymmetricMatrix &)> TDF, Coefficient *q=nullptr)
Define a time-dependent square matrix coefficient from a std function.
Scalar coefficient defined as the trace of a matrix coefficient.
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the trace coefficient at ip.
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
TraceCoefficient(MatrixCoefficient &A)
Construct with the matrix.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
A coefficient that depends on 1 or 2 parent coefficients and a transformation rule represented by a C...
void SetTime(real_t t) override
Set the time for internally stored coefficients.
TransformedCoefficient(Coefficient *q, std::function< real_t(real_t)> F)
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
TransformedCoefficient(Coefficient *q1, Coefficient *q2, std::function< real_t(real_t, real_t)> F)
Matrix coefficient defined as the transpose of a matrix coefficient.
MatrixCoefficient * GetACoef() const
Return the matrix coefficient.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
TransposeMatrixCoefficient(MatrixCoefficient &A)
Construct with the matrix coefficient. Result is .
void SetACoef(MatrixCoefficient &A)
Reset the matrix coefficient.
void Eval(DenseMatrix &M, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient at ip.
Vector coefficient defined by an array of scalar coefficients. Coefficients that are not set will eva...
bool GetOwnership(int i) const
Get ownership of the i'th coefficient.
virtual ~VectorArrayCoefficient()
Destroys vector coefficient.
Coefficient ** GetCoeffs()
Returns the entire array of coefficients.
void SetOwnership(int i, bool own)
Set ownership of the i'th coefficient.
VectorArrayCoefficient(int dim)
Construct vector of dim coefficients. The actual coefficients still need to be added with Set().
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void Set(int i, Coefficient *c, bool own=true)
Sets coefficient in the vector.
real_t Eval(int i, ElementTransformation &T, const IntegrationPoint &ip)
Coefficient * GetCoeff(int i)
Returns i'th coefficient.
Base class for vector Coefficients that optionally depend on time and space.
int GetVDim()
Returns dimension of the vector.
virtual void SetTime(real_t t)
Set the time for time dependent coefficients.
VectorCoefficient(int vd)
Initialize the VectorCoefficient with vector dimension vd.
real_t GetTime()
Get the time for time dependent coefficients.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
virtual void Project(QuadratureFunction &qf)
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
Scalar coefficient defined as component of a vector coefficient.
void SetACoef(VectorCoefficient &A)
Reset the vector coefficient.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the component coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
int GetComponent() const
Return the component.
VectorComponentCoefficient(VectorCoefficient &A)
Construct with a vector coefficient.
VectorCoefficient * GetACoef() const
Return the vector coefficient.
void SetComponent(int c)
Set the component.
Vector coefficient that is constant in space and time.
const Vector & GetVec() const
Return a reference to the constant vector in this class.
VectorConstantCoefficient(const Vector &v)
Construct the coefficient with constant vector v.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
Vector coefficient defined as a cross product of two vectors.
void SetBCoef(VectorCoefficient &B)
Reset the second term in the product.
VectorCoefficient * GetACoef() const
Return the first term in the product.
VectorCoefficient * GetBCoef() const
Return the second term in the product.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
VectorCrossProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Construct with the two coefficients. Result is A x B.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetACoef(VectorCoefficient &A)
Reset the first term in the product.
Vector coefficient defined by a scalar DeltaCoefficient and a constant vector direction.
void GetDeltaCenter(Vector &center)
VectorDeltaCoefficient(const Vector &dir_, real_t x, real_t y, real_t z, real_t s)
Construct with a Vector object representing the direction and a delta function scaled by s and center...
VectorDeltaCoefficient(const Vector &dir_)
Construct with a Vector object representing the direction and a unit delta function centered at (0....
VectorDeltaCoefficient(const Vector &dir_, real_t x, real_t s)
Construct with a Vector object representing the direction and a delta function scaled by s and center...
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetDeltaCoefficient(const DeltaCoefficient &d_)
Replace the associated DeltaCoefficient with a new DeltaCoefficient.
void SetDirection(const Vector &d_)
virtual void EvalDelta(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Return the specified direction vector multiplied by the value returned by DeltaCoefficient::EvalDelta...
VectorDeltaCoefficient(const Vector &dir_, real_t x, real_t y, real_t s)
Construct with a Vector object representing the direction and a delta function scaled by s and center...
DeltaCoefficient & GetDeltaCoefficient()
Return the associated scalar DeltaCoefficient.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
A VectorDeltaFunction cannot be evaluated. Calling this method will cause an MFEM error,...
VectorDeltaCoefficient(int vdim_)
Construct with a vector of dimension vdim_.
void SetDeltaCenter(const Vector &center)
A general vector function coefficient.
VectorFunctionCoefficient(int dim, std::function< void(const Vector &, real_t, Vector &)> TDF, Coefficient *q=nullptr)
Define a time-dependent vector coefficient from a std function.
VectorFunctionCoefficient(int dim, std::function< void(const Vector &, Vector &)> F, Coefficient *q=nullptr)
Define a time-independent vector coefficient from a std function.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
Vector coefficient defined by a vector GridFunction.
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
void SetGridFunction(const GridFunction *gf)
Set the grid function for this coefficient. Also sets the Vector dimension to match that of the gf.
VectorGridFunctionCoefficient()
Construct an empty coefficient. Calling Eval() before the grid function is set will cause a segfault.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
const GridFunction * GetGridFunction() const
Returns a pointer to the grid function in this Coefficient.
Vector quadrature function coefficient which requires that the quadrature rules used for this vector ...
void Project(QuadratureFunction &qf) override
Fill the QuadratureFunction qf by evaluating the coefficient at the quadrature points.
VectorQuadratureFunctionCoefficient(const QuadratureFunction &qf)
Constructor with a quadrature function as input.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
const QuadratureFunction & GetQuadFunction() const
void SetComponent(int index_, int length_)
Derived vector coefficient that has the value of the parent vector where it is active and is zero oth...
VectorRestrictedCoefficient(VectorCoefficient &vc, Array< int > &attr)
Construct with a parent vector coefficient and an array of zeros and ones representing the attributes...
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient at ip.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
Scalar coefficient defined as a cross product of two vectors in the xy-plane.
VectorRotProductCoefficient(VectorCoefficient &A, VectorCoefficient &B)
Constructor with two vector coefficients. Result is .
void SetBCoef(VectorCoefficient &B)
Reset the second vector in the product.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
void SetACoef(VectorCoefficient &A)
Reset the first vector in the product.
VectorCoefficient * GetBCoef() const
Return the second vector of the product.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
VectorCoefficient * GetACoef() const
Return the first vector of the product.
Vector coefficient defined as the linear combination of two vectors.
void SetB(const Vector &B_)
Reset the second vector as a constant.
real_t GetAlpha() const
Return the factor in front of the first vector coefficient.
const Vector & GetB() const
Return the second vector constant.
void SetAlpha(real_t alpha_)
Reset the factor in front of the first vector coefficient as a constant.
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
const Vector & GetA() const
Return the first vector constant.
real_t GetBeta() const
Return the factor in front of the second vector coefficient.
void SetA(const Vector &A_)
Reset the first vector as a constant.
void SetBeta(real_t beta_)
Reset the factor in front of the second vector coefficient as a constant.
Coefficient * GetAlphaCoef() const
Return the factor in front of the first vector coefficient.
void SetBCoef(VectorCoefficient &B_)
Reset the second vector coefficient.
void SetTime(real_t t) override
Set the time for internally stored coefficients.
void SetAlphaCoef(Coefficient &A_)
Reset the factor in front of the first vector coefficient.
Coefficient * GetBetaCoef() const
Return the factor in front of the second vector coefficient.
VectorCoefficient * GetBCoef() const
Return the second vector coefficient.
void SetBetaCoef(Coefficient &B_)
Reset the factor in front of the second vector coefficient.
VectorCoefficient * GetACoef() const
Return the first vector coefficient.
void SetACoef(VectorCoefficient &A_)
Reset the first vector coefficient.
Vector data type.
Definition vector.hpp:82
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
Vector beta_
const real_t alpha
Definition ex15.cpp:369
int dim
Definition ex24.cpp:53
constexpr int dimension
This example only works in 3D. Kernels for 2D are not implemented.
Definition hooke.cpp:45
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
int operator&(CoefficientStorage a, CoefficientStorage b)
VectorCoefficient DiagonalMatrixCoefficient
void mfem_error(const char *msg)
Definition error.cpp:154
real_t ComputeGlobalLpNorm(real_t p, Coefficient &coeff, ParMesh &pmesh, const IntegrationRule *irs[])
Compute the global Lp norm of a function f. .
CartesianZCoefficient CylindricalZCoefficient
real_t ComputeLpNorm(real_t p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
Compute the Lp norm of a function f. .
CoefficientStorage
Flags that determine what storage optimizations to use in CoefficientVector.
@ SYMMETRIC
Store the triangular part of symmetric matrices.
@ CONSTANTS
Store constants using only vdim entries.
@ COMPRESSED
Enable all above compressions.
@ FULL
Store the coefficient as a full QuadratureFunction.
CoefficientStorage operator|(CoefficientStorage a, CoefficientStorage b)
float real_t
Definition config.hpp:46
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
MatrixVectorProductCoefficient MatVecCoefficient
Convenient alias for the MatrixVectorProductCoefficient.
STL namespace.
real_t p(const Vector &x, real_t t)