42 inline int Size()
const {
return n; }
61 for (
int i=0; i<
n; ++i)
82 virtual void Print(std::ostream &os)
const = 0;
102 virtual std::unique_ptr<SpacingFunction>
Clone()
const;
143 void Print(std::ostream &os)
const override
165 bool Nested()
const override {
return true; }
167 std::unique_ptr<SpacingFunction>
Clone()
const override
169 return std::unique_ptr<SpacingFunction>(
177 void CalculateSpacing()
196 MFEM_VERIFY(0.0 < s && s < 1.0,
"Initial spacing must be in (0,1)");
197 CalculateDifference();
203 CalculateDifference();
211 CalculateDifference();
217 MFEM_ASSERT(0 <=
p &&
p <
n,
"Access element " <<
p
218 <<
" of spacing function, size = " <<
n);
223 void Print(std::ostream &os)
const override
227 <<
" " << (
int)
scale <<
" " << s <<
"\n";
248 bool Nested()
const override {
return false; }
250 std::unique_ptr<SpacingFunction>
Clone()
const override
252 return std::unique_ptr<SpacingFunction>(
259 void CalculateDifference()
269 d = 2.0 * (1.0 - (
n * s)) / ((
real_t) (
n*(
n-1)));
271 if (s + ((
n-1) * d) <= 0.0)
273 MFEM_ABORT(
"Invalid linear spacing parameters");
313 return n == 1 ? 1.0 : s * std::pow(r, i);
316 void Print(std::ostream &os)
const override
320 << (int)
reverse <<
" " << (
int)
scale <<
" " << s <<
"\n";
342 bool Nested()
const override {
return false; }
344 std::unique_ptr<SpacingFunction>
Clone()
const override
346 return std::unique_ptr<SpacingFunction>(
355 void CalculateSpacing();
406 void Print(std::ostream &os)
const override
410 <<
" " << (
int)
scale <<
" " << s0 <<
" " << s1 <<
"\n";
432 bool Nested()
const override {
return false; }
434 std::unique_ptr<SpacingFunction>
Clone()
const override
436 return std::unique_ptr<SpacingFunction>(
445 void CalculateSpacing();
497 void Print(std::ostream &os)
const override
501 <<
" " << (
int)
scale <<
" " << s0 <<
" " << s1 <<
"\n";
523 bool Nested()
const override {
return false; }
525 std::unique_ptr<SpacingFunction>
Clone()
const override
527 return std::unique_ptr<SpacingFunction>(
536 void CalculateSpacing();
567 void Print(std::ostream &os)
const override
571 (int)
reverse <<
" " << (
int) sym <<
" " << logBase <<
"\n";
593 bool Nested()
const override {
return true; }
595 std::unique_ptr<SpacingFunction>
Clone()
const override
597 return std::unique_ptr<SpacingFunction>(
607 void CalculateSpacing();
609 void CalculateSymmetric();
611 void CalculateNonsymmetric();
654 npartition(sf.npartition), pieces(), n0(sf.n0), s(sf.s)
657 for (
const auto &
f : sf.pieces) { pieces.emplace_back(
f->Clone()); }
663 std::swap(tmp, *
this);
684 void Print(std::ostream &os)
const override;
686 std::unique_ptr<SpacingFunction>
Clone()
const override
688 return std::unique_ptr<SpacingFunction>(
698 for (
const auto &
p : pieces)
701 count +=
p->NumIntParameters() + 3;
709 for (
const auto &
p : pieces)
711 count +=
p->NumDoubleParameters();
720 MFEM_VERIFY(npartition.
Size() ==
f.Size(),
"");
722 for (
int i=0; i<
f.Size(); ++i)
724 const int ir = reorient &&
reverse ?
f.Size() - 1 - i : i;
725 npartition[i] *=
f[ir];
736 for (
int i=0; i<np; ++i) {
p[3 + i] = npartition[i]; }
740 for (
int i=0; i<np; ++i)
743 p[os++] = pieces[i]->NumIntParameters();
744 p[os++] = pieces[i]->NumDoubleParameters();
746 pieces[i]->GetIntParameters(ipar);
757 for (
int i=0; i<partition.
Size(); ++i) {
p[i] = partition[i]; }
758 int os = partition.
Size();
760 for (
int i=0; i<np; ++i)
762 pieces[i]->GetDoubleParameters(dpar);
771 bool Nested()
const override;
777 std::vector<std::unique_ptr<SpacingFunction>> pieces;
784 void CalculateSpacing();
794 int rel_num_elems_full,
798 num_elems(rel_num_elems), first_elem(rel_first_elem)
807 num_elems_full(sf.num_elems_full), num_elems(sf.num_elems),
808 first_elem(sf.first_elem), s(sf.s)
814 std::swap(tmp, *
this);
835 void Print(std::ostream &os)
const override;
837 std::unique_ptr<SpacingFunction>
Clone()
const override
839 return std::unique_ptr<SpacingFunction>(
853 fullSpacing->GetIntParameters(ipar);
854 p.SetSize(8 + ipar.
Size());
859 p[4] = num_elems_full;
860 p[5] = (int) fullSpacing->GetSpacingType();
863 for (
int i=0; i<ipar.
Size(); ++i) {
p[8 + i] = ipar[i]; }
868 fullSpacing->GetDoubleParameters(
p);
872 bool Nested()
const override {
return fullSpacing->Nested(); }
875 std::unique_ptr<SpacingFunction> fullSpacing;
885 void CalculateSpacing();
890 Array<int>
const& ipar,
int Size() const
Return the logical size of the array.
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 GaussianSpacingFunction.
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).
Partial spacing function, defined as part of an existing spacing function.
PartialSpacingFunction(int n, bool r, int rel_first_elem, int rel_num_elems, int rel_num_elems_full, Array< int > const &ipar, Vector const &dpar, SpacingType typeFull)
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...
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
void SetSize(int size) override
Sets the size, or number of intervals (elements).
void GetIntParameters(Array< int > &p) const override
void SetupFull(SpacingType typeFull, Array< int > const &ipar, Vector const &dpar)
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
PartialSpacingFunction & operator=(const PartialSpacingFunction &sf)
PartialSpacingFunction(const PartialSpacingFunction &sf)
Copy constructor (deep-copy all data, including SpacingFunction pieces)
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
PartialSpacingFunction & operator=(PartialSpacingFunction &&sf)=default
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
PartialSpacingFunction(PartialSpacingFunction &&sf)=default
void GetDoubleParameters(Vector &p) const override
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...
Array< int > RelativePieceSizes() const
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 ScalePartition(Array< int > const &f, bool reorient)
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.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
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)