42 inline int Size()
const {
return n; }
57 for (
int i=0; i<
n; ++i)
78 virtual void Print(std::ostream &os)
const = 0;
98 virtual std::unique_ptr<SpacingFunction>
Clone()
const;
132 void Print(std::ostream &os)
const override
154 bool Nested()
const override {
return true; }
156 std::unique_ptr<SpacingFunction>
Clone()
const override
158 return std::unique_ptr<SpacingFunction>(
166 void CalculateSpacing()
185 MFEM_VERIFY(0.0 <
s &&
s < 1.0,
"Initial spacing must be in (0,1)");
186 CalculateDifference();
192 CalculateDifference();
200 CalculateDifference();
206 MFEM_ASSERT(0 <=
p &&
p <
n,
"Access element " <<
p
207 <<
" of spacing function, size = " <<
n);
212 void Print(std::ostream &os)
const override
216 <<
" " << (
int)
scale <<
" " << s <<
"\n";
237 bool Nested()
const override {
return false; }
239 std::unique_ptr<SpacingFunction>
Clone()
const override
241 return std::unique_ptr<SpacingFunction>(
248 void CalculateDifference()
258 d = 2.0 * (1.0 - (
n *
s)) / ((
real_t) (
n*(
n-1)));
260 if (s + ((
n-1) * d) <= 0.0)
262 MFEM_ABORT(
"Invalid linear spacing parameters");
302 return n == 1 ? 1.0 :
s * std::pow(r, i);
305 void Print(std::ostream &os)
const override
331 bool Nested()
const override {
return false; }
333 std::unique_ptr<SpacingFunction>
Clone()
const override
335 return std::unique_ptr<SpacingFunction>(
344 void CalculateSpacing();
395 void Print(std::ostream &os)
const override
399 <<
" " << (
int)
scale <<
" " << s0 <<
" " << s1 <<
"\n";
421 bool Nested()
const override {
return false; }
423 std::unique_ptr<SpacingFunction>
Clone()
const override
425 return std::unique_ptr<SpacingFunction>(
434 void CalculateSpacing();
486 void Print(std::ostream &os)
const override
490 <<
" " << (
int)
scale <<
" " << s0 <<
" " << s1 <<
"\n";
512 bool Nested()
const override {
return false; }
514 std::unique_ptr<SpacingFunction>
Clone()
const override
516 return std::unique_ptr<SpacingFunction>(
525 void CalculateSpacing();
556 void Print(std::ostream &os)
const override
560 (int)
reverse <<
" " << (
int) sym <<
" " << logBase <<
"\n";
582 bool Nested()
const override {
return true; }
584 std::unique_ptr<SpacingFunction>
Clone()
const override
586 return std::unique_ptr<SpacingFunction>(
596 void CalculateSpacing();
598 void CalculateSymmetric();
600 void CalculateNonsymmetric();
643 npartition(sf.npartition), pieces(), n0(sf.n0),
s(sf.
s)
646 for (
const auto &
f : sf.pieces) { pieces.emplace_back(
f->Clone()); }
652 std::swap(tmp, *
this);
673 void Print(std::ostream &os)
const override;
675 std::unique_ptr<SpacingFunction>
Clone()
const override
677 return std::unique_ptr<SpacingFunction>(
693 for (
int i=0; i<np; ++i) {
p[3 + i] = npartition[i]; }
703 bool Nested()
const override;
709 std::vector<std::unique_ptr<SpacingFunction>> pieces;
716 void CalculateSpacing();
721 Array<int>
const& ipar,
Bell spacing function, which produces spacing resembling a Bell curve.
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
void SetSize(int size) override
Sets the size, or number of intervals (elements).
void GetDoubleParameters(Vector &p) const override
void Print(std::ostream &os) const override
Prints all the data necessary to define the spacing function and its current state (size and other pa...
BellSpacingFunction(int n, bool r, real_t s0, real_t s1, bool s)
Constructor for BellSpacingFunction.
void GetIntParameters(Array< int > &p) const override
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
bool Nested() const override
Returns true if the spacing function is nested during refinement.
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
Gaussian spacing function of the general form g(x) = a exp(-(x-m)^2 / c^2) for some scalar parameters...
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
void GetIntParameters(Array< int > &p) const override
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
void Print(std::ostream &os) const override
Prints all the data necessary to define the spacing function and its current state (size and other pa...
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
void GetDoubleParameters(Vector &p) const override
bool Nested() const override
Returns true if the spacing function is nested during refinement.
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
GaussianSpacingFunction(int n, bool r, real_t s0, real_t s1, bool s)
Constructor for BellSpacingFunction.
void SetSize(int size) override
Sets the size, or number of intervals (elements).
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
Geometric spacing function.
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
GeometricSpacingFunction(int n, bool r, real_t s, bool scale)
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
void GetDoubleParameters(Vector &p) const override
void Print(std::ostream &os) const override
Prints all the data necessary to define the spacing function and its current state (size and other pa...
bool Nested() const override
Returns true if the spacing function is nested during refinement.
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
void GetIntParameters(Array< int > &p) const override
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Linear spacing function, defining the width of interval i as s + i * d.
void Print(std::ostream &os) const override
Prints all the data necessary to define the spacing function and its current state (size and other pa...
void SetSize(int size) override
Sets the size, or number of intervals (elements).
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
void GetDoubleParameters(Vector &p) const override
bool Nested() const override
Returns true if the spacing function is nested during refinement.
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
void GetIntParameters(Array< int > &p) const override
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
LinearSpacingFunction(int n, bool r, real_t s, bool scale)
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
Logarithmic spacing function, uniform in log base 10 by default.
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
bool Nested() const override
Returns true if the spacing function is nested during refinement.
void Print(std::ostream &os) const override
Prints all the data necessary to define the spacing function and its current state (size and other pa...
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
void GetIntParameters(Array< int > &p) const override
void GetDoubleParameters(Vector &p) const override
LogarithmicSpacingFunction(int n, bool r, bool sym=false, real_t b=10.0)
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Piecewise spacing function, with spacing functions defining spacing within arbitarily many fixed subi...
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
PiecewiseSpacingFunction & operator=(PiecewiseSpacingFunction &&sf)=default
PiecewiseSpacingFunction(const PiecewiseSpacingFunction &sf)
Copy constructor (deep-copy all data, including SpacingFunction pieces)
PiecewiseSpacingFunction(PiecewiseSpacingFunction &&sf)=default
void Print(std::ostream &os) const override
Prints all the data necessary to define the spacing function and its current state (size and other pa...
bool Nested() const override
Returns true if the spacing function is nested during refinement.
PiecewiseSpacingFunction(int n, int np, bool r, Array< int > const &relN, Array< int > const &ipar, Vector const &dpar)
Constructor for PiecewiseSpacingFunction.
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
void GetDoubleParameters(Vector &p) const override
void SetSize(int size) override
Sets the size, or number of intervals (elements).
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
void SetupPieces(Array< int > const &ipar, Vector const &dpar)
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
void GetIntParameters(Array< int > &p) const override
PiecewiseSpacingFunction & operator=(const PiecewiseSpacingFunction &sf)
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
virtual void GetDoubleParameters(Vector &p) const =0
virtual void SetSize(int size)=0
Sets the size, or number of intervals (elements).
bool scale
Whether to scale parameters in ScaleParameters.
void EvalAll(Vector &s) const
Returns the width of all intervals, resizing s to Size().
SpacingFunction(int n, bool r=false, bool s=false)
Base class constructor.
virtual SpacingType GetSpacingType() const =0
Returns the spacing type, indicating the derived class.
virtual int NumDoubleParameters() const =0
Returns the number of double parameters defining the spacing function.
virtual void ScaleParameters(real_t a)
Scales parameters by the factor a associated with Size().
virtual void Print(std::ostream &os) const =0
Prints all the data necessary to define the spacing function and its current state (size and other pa...
int Size() const
Returns the size, or number of intervals (elements).
virtual int NumIntParameters() const =0
Returns the number of integer parameters defining the spacing function.
virtual void GetIntParameters(Array< int > &p) const =0
virtual std::unique_ptr< SpacingFunction > Clone() const
Returns a clone (deep-copy) of this spacing function.
void SetReverse(bool r)
Sets the property that determines whether the spacing is reversed.
virtual ~SpacingFunction()=default
virtual real_t Eval(int p) const =0
Returns the width of interval p (between 0 and Size() - 1).
bool reverse
Whether to reverse the spacing.
int n
Size, or number of intervals (elements)
virtual bool Nested() const =0
Returns true if the spacing function is nested during refinement.
std::unique_ptr< SpacingFunction > GetSpacingFunction(const SpacingType spacingType, Array< int > const &ipar, Vector const &dpar)
Returns a new SpacingFunction instance defined by the type and parameters.
std::function< real_t(const Vector &)> f(real_t mass_coeff)
real_t p(const Vector &x, real_t t)