MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
spacing.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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_SPACING
13#define MFEM_SPACING
14
15#include "../linalg/vector.hpp"
16
17#include <memory>
18#include <vector>
19
20namespace mfem
21{
22
26
27/// Class for spacing functions that define meshes in a dimension, using a
28/// formula or method implemented in a derived class.
30{
31public:
32 /** @brief Base class constructor.
33 @param[in] n Size or number of intervals, which defines elements.
34 @param[in] r Whether to reverse the spacings, false by default.
35 @param[in] s Whether to scale parameters by the refinement or coarsening
36 factor, in the function @a SpacingFunction::ScaleParameters.
37 */
38 SpacingFunction(int n, bool r=false, bool s=false) : n(n), reverse(r), scale(s)
39 { }
40
41 /// Returns the size, or number of intervals (elements).
42 inline int Size() const { return n; }
43
44 /// Sets the size, or number of intervals (elements).
45 virtual void SetSize(int size) = 0;
46
47 /// Sets the property that determines whether the spacing is reversed.
48 void SetReverse(bool r) { reverse = r; }
49
50 /// Returns the width of interval @a p (between 0 and @a Size() - 1).
51 virtual real_t Eval(int p) const = 0;
52
53 /// Returns the width of all intervals, resizing @a s to @a Size().
54 void EvalAll(Vector & s) const
55 {
56 s.SetSize(n);
57 for (int i=0; i<n; ++i)
58 {
59 s[i] = Eval(i);
60 }
61 }
62
63 /** @brief Scales parameters by the factor @a a associated with @a Size().
64
65 Note that parameters may be scaled inversely during coarsening and
66 refining, so the scaling should be linear in the sense that scaling by a
67 number followed by scaling by its inverse has no effect on parameters. */
68 virtual void ScaleParameters(real_t a) { }
69
70 /// Returns the spacing type, indicating the derived class.
71 virtual SpacingType GetSpacingType() const = 0;
72
73 /** @brief Prints all the data necessary to define the spacing function and
74 its current state (size and other parameters).
75
76 The format is generally
77 SpacingType numIntParam numDoubleParam {int params} {double params} */
78 virtual void Print(std::ostream &os) const = 0;
79
80 /// Returns the number of integer parameters defining the spacing function.
81 virtual int NumIntParameters() const = 0;
82
83 /// Returns the number of double parameters defining the spacing function.
84 virtual int NumDoubleParameters() const = 0;
85
86 /// Returns the array of integer parameters defining the spacing function.
87 /// @param[out] p Array of integer parameters, resized appropriately.
88 virtual void GetIntParameters(Array<int> & p) const = 0;
89
90 /// Returns the array of double parameters defining the spacing function.
91 /// @param[out] p Array of double parameters, resized appropriately.
92 virtual void GetDoubleParameters(Vector & p) const = 0;
93
94 /// Returns true if the spacing function is nested during refinement.
95 virtual bool Nested() const = 0;
96
97 /// Returns a clone (deep-copy) of this spacing function.
98 virtual std::unique_ptr<SpacingFunction> Clone() const;
99
100 virtual ~SpacingFunction() = default;
101
102protected:
103 int n; ///< Size, or number of intervals (elements)
104 bool reverse; ///< Whether to reverse the spacing
105 bool scale; ///< Whether to scale parameters in ScaleParameters.
106};
107
108/** @brief Uniform spacing function, dividing the unit interval into @a Size()
109 equally spaced intervals (elements).
110
111 This function is nested and has no scaled parameters. */
113{
114public:
117 {
118 CalculateSpacing();
119 }
120
121 void SetSize(int size) override
122 {
123 n = size;
124 CalculateSpacing();
125 }
126
127 real_t Eval(int p) const override
128 {
129 return s;
130 }
131
132 void Print(std::ostream &os) const override
133 {
134 // SpacingType numIntParam numDoubleParam {int params} {double params}
135 os << int(SpacingType::UNIFORM_SPACING) << " 1 0 " << n << "\n";
136 }
137
140 int NumIntParameters() const override { return 1; }
141 int NumDoubleParameters() const override { return 0; }
142
143 void GetIntParameters(Array<int> & p) const override
144 {
145 p.SetSize(1);
146 p[0] = n;
147 }
148
149 void GetDoubleParameters(Vector & p) const override
150 {
151 p.SetSize(0);
152 }
153
154 bool Nested() const override { return true; }
155
156 std::unique_ptr<SpacingFunction> Clone() const override
157 {
158 return std::unique_ptr<SpacingFunction>(
159 new UniformSpacingFunction(*this));
160 }
161
162private:
163 real_t s; ///< Width of each interval (element)
164
165 /// Calculate interval width @a s
166 void CalculateSpacing()
167 {
168 // Spacing is 1 / n
169 s = 1.0 / ((real_t) n);
170 }
171};
172
173/** @brief Linear spacing function, defining the width of interval i as
174 s + i * d.
175
176 The initial interval width s is prescribed as a parameter, which can be
177 scaled, and d is computed as a function of Size(), to ensure that the widths
178 sum to 1. This function is not nested. */
180{
181public:
182 LinearSpacingFunction(int n, bool r, real_t s, bool scale)
183 : SpacingFunction(n, r, scale), s(s)
184 {
185 MFEM_VERIFY(0.0 < s && s < 1.0, "Initial spacing must be in (0,1)");
186 CalculateDifference();
187 }
188
189 void SetSize(int size) override
190 {
191 n = size;
192 CalculateDifference();
193 }
194
195 void ScaleParameters(real_t a) override
196 {
197 if (scale)
198 {
199 s *= a;
200 CalculateDifference();
201 }
202 }
203
204 real_t Eval(int p) const override
205 {
206 MFEM_ASSERT(0 <= p && p < n, "Access element " << p
207 << " of spacing function, size = " << n);
208 const int i = reverse ? n - 1 - p : p;
209 return s + (i * d);
210 }
211
212 void Print(std::ostream &os) const override
213 {
214 // SpacingType numIntParam numDoubleParam {int params} {double params}
215 os << int(SpacingType::LINEAR) << " 3 1 " << n << " " << (int) reverse
216 << " " << (int) scale << " " << s << "\n";
217 }
218
219 SpacingType GetSpacingType() const override { return SpacingType::LINEAR; }
220 int NumIntParameters() const override { return 3; }
221 int NumDoubleParameters() const override { return 1; }
222
223 void GetIntParameters(Array<int> & p) const override
224 {
225 p.SetSize(3);
226 p[0] = n;
227 p[1] = (int) reverse;
228 p[2] = (int) scale;
229 }
230
231 void GetDoubleParameters(Vector & p) const override
232 {
233 p.SetSize(1);
234 p[0] = s;
235 }
236
237 bool Nested() const override { return false; }
238
239 std::unique_ptr<SpacingFunction> Clone() const override
240 {
241 return std::unique_ptr<SpacingFunction>(
242 new LinearSpacingFunction(*this));
243 }
244
245private:
246 real_t s, d; ///< Spacing parameters, set by @a CalculateDifference
247
248 void CalculateDifference()
249 {
250 if (n < 2)
251 {
252 d = 0.0;
253 return;
254 }
255
256 // Spacings are s, s + d, ..., s + (n-1)d, which must sum to 1:
257 // 1 = ns + dn(n-1)/2
258 d = 2.0 * (1.0 - (n * s)) / ((real_t) (n*(n-1)));
259
260 if (s + ((n-1) * d) <= 0.0)
261 {
262 MFEM_ABORT("Invalid linear spacing parameters");
263 }
264 }
265};
266
267/** @brief Geometric spacing function.
268
269 The spacing of interval i is s*r^i for 0 <= i < n, with
270 s + s*r + s*r^2 + ... + s*r^(n-1) = 1
271 s * (r^n - 1) / (r - 1) = 1
272 The initial spacing s and number of intervals n are inputs, and r is solved
273 for by Newton's method. The parameter s can be scaled. This function is not
274 nested. */
276{
277public:
279 : SpacingFunction(n, r, scale), s(s)
280 {
281 CalculateSpacing();
282 }
283
284 void SetSize(int size) override
285 {
286 n = size;
287 CalculateSpacing();
288 }
289
290 void ScaleParameters(real_t a) override
291 {
292 if (scale)
293 {
294 s *= a;
295 CalculateSpacing();
296 }
297 }
298
299 real_t Eval(int p) const override
300 {
301 const int i = reverse ? n - 1 - p : p;
302 return n == 1 ? 1.0 : s * std::pow(r, i);
303 }
304
305 void Print(std::ostream &os) const override
306 {
307 // SpacingType numIntParam numDoubleParam {int params} {double params}
308 os << int(SpacingType::GEOMETRIC) << " 3 1 " << n << " "
309 << (int) reverse << " " << (int) scale << " " << s << "\n";
310 }
311
313 { return SpacingType::GEOMETRIC; }
314 int NumIntParameters() const override { return 3; }
315 int NumDoubleParameters() const override { return 1; }
316
317 void GetIntParameters(Array<int> & p) const override
318 {
319 p.SetSize(3);
320 p[0] = n;
321 p[1] = (int) reverse;
322 p[2] = (int) scale;
323 }
324
325 void GetDoubleParameters(Vector & p) const override
326 {
327 p.SetSize(1);
328 p[0] = s;
329 }
330
331 bool Nested() const override { return false; }
332
333 std::unique_ptr<SpacingFunction> Clone() const override
334 {
335 return std::unique_ptr<SpacingFunction>(
336 new GeometricSpacingFunction(*this));
337 }
338
339private:
340 real_t s; ///< Initial spacing
341 real_t r; ///< Ratio
342
343 /// Calculate parameters used by @a Eval and @a EvalAll
344 void CalculateSpacing();
345};
346
347/** @brief Bell spacing function, which produces spacing resembling a Bell
348 curve.
349
350 The widths of the first and last intervals (elements) are prescribed, and
351 the remaining interior spacings are computed by an algorithm that minimizes
352 the ratios of adjacent spacings. If the first and last intervals are wide
353 enough, the spacing may decrease in the middle of the domain. The first and
354 last interval widths can be scaled. This function is not nested.
355 */
357{
358public:
359 /** @brief Constructor for BellSpacingFunction.
360 @param[in] n Size or number of intervals, which defines elements.
361 @param[in] r Whether to reverse the spacings.
362 @param[in] s0 Width of the first interval (element).
363 @param[in] s1 Width of the last interval (element).
364 @param[in] s Whether to scale parameters by the refinement or coarsening
365 factor, in the function @a SpacingFunction::ScaleParameters.
366 */
367 BellSpacingFunction(int n, bool r, real_t s0, real_t s1, bool s)
368 : SpacingFunction(n, r, s), s0(s0), s1(s1)
369 {
370 CalculateSpacing();
371 }
372
373 void SetSize(int size) override
374 {
375 n = size;
376 CalculateSpacing();
377 }
378
379 void ScaleParameters(real_t a) override
380 {
381 if (scale)
382 {
383 s0 *= a;
384 s1 *= a;
385 CalculateSpacing();
386 }
387 }
388
389 real_t Eval(int p) const override
390 {
391 const int i = reverse ? n - 1 - p : p;
392 return s[i];
393 }
394
395 void Print(std::ostream &os) const override
396 {
397 // SpacingType numIntParam numDoubleParam {int params} {double params}
398 os << int(SpacingType::BELL) << " 3 2 " << n << " " << (int) reverse
399 << " " << (int) scale << " " << s0 << " " << s1 << "\n";
400 }
401
402 SpacingType GetSpacingType() const override { return SpacingType::BELL; }
403 int NumIntParameters() const override { return 3; }
404 int NumDoubleParameters() const override { return 2; }
405
406 void GetIntParameters(Array<int> & p) const override
407 {
408 p.SetSize(3);
409 p[0] = n;
410 p[1] = (int) reverse;
411 p[2] = (int) scale;
412 }
413
414 void GetDoubleParameters(Vector & p) const override
415 {
416 p.SetSize(2);
417 p[0] = s0;
418 p[1] = s1;
419 }
420
421 bool Nested() const override { return false; }
422
423 std::unique_ptr<SpacingFunction> Clone() const override
424 {
425 return std::unique_ptr<SpacingFunction>(
426 new BellSpacingFunction(*this));
427 }
428
429private:
430 real_t s0, s1; ///< First and last interval widths
431 Vector s; ///< Stores the spacings calculated by @a CalculateSpacing
432
433 /// Calculate parameters used by @a Eval and @a EvalAll
434 void CalculateSpacing();
435};
436
437/** @brief Gaussian spacing function of the general form
438 g(x) = a exp(-(x-m)^2 / c^2) for some scalar parameters a, m, c.
439
440 The widths of the first and last intervals (elements) are prescribed, and
441 the remaining interior spacings are computed by using Newton's method to
442 compute parameters that fit the endpoint widths. The results of this spacing
443 function are very similar to those of @a BellSpacingFunction, but they may
444 differ by about 1%. If the first and last intervals are wide enough, the
445 spacing may decrease in the middle of the domain. The first and last
446 interval widths can be scaled. This function is not nested. */
448{
449public:
450 /** @brief Constructor for BellSpacingFunction.
451 @param[in] n Size or number of intervals, which defines elements.
452 @param[in] r Whether to reverse the spacings.
453 @param[in] s0 Width of the first interval (element).
454 @param[in] s1 Width of the last interval (element).
455 @param[in] s Whether to scale parameters by the refinement or coarsening
456 factor, in the function @a SpacingFunction::ScaleParameters.
457 */
458 GaussianSpacingFunction(int n, bool r, real_t s0, real_t s1, bool s)
459 : SpacingFunction(n, r, s), s0(s0), s1(s1)
460 {
461 CalculateSpacing();
462 }
463
464 void SetSize(int size) override
465 {
466 n = size;
467 CalculateSpacing();
468 }
469
470 void ScaleParameters(real_t a) override
471 {
472 if (scale)
473 {
474 s0 *= a;
475 s1 *= a;
476 CalculateSpacing();
477 }
478 }
479
480 real_t Eval(int p) const override
481 {
482 const int i = reverse ? n - 1 - p : p;
483 return s[i];
484 }
485
486 void Print(std::ostream &os) const override
487 {
488 // SpacingType numIntParam numDoubleParam {int params} {double params}
489 os << int(SpacingType::GAUSSIAN) << " 3 2 " << n << " " << (int) reverse
490 << " " << (int) scale << " " << s0 << " " << s1 << "\n";
491 }
492
494 int NumIntParameters() const override { return 3; }
495 int NumDoubleParameters() const override { return 2; }
496
497 void GetIntParameters(Array<int> & p) const override
498 {
499 p.SetSize(3);
500 p[0] = n;
501 p[1] = (int) reverse;
502 p[2] = (int) scale;
503 }
504
505 void GetDoubleParameters(Vector & p) const override
506 {
507 p.SetSize(2);
508 p[0] = s0;
509 p[1] = s1;
510 }
511
512 bool Nested() const override { return false; }
513
514 std::unique_ptr<SpacingFunction> Clone() const override
515 {
516 return std::unique_ptr<SpacingFunction>(
517 new GaussianSpacingFunction(*this));
518 }
519
520private:
521 real_t s0, s1; ///< First and last interval widths
522 Vector s; ///< Stores the spacings calculated by @a CalculateSpacing
523
524 /// Calculate parameters used by @a Eval and @a EvalAll
525 void CalculateSpacing();
526};
527
528/** @brief Logarithmic spacing function, uniform in log base 10 by default.
529
530 The log base can be changed as an input parameter. Decreasing it makes the
531 distribution more uniform, whereas increasing it makes the spacing vary
532 more. Another input option is a flag to make the distribution symmetric
533 (default is non-symmetric). There are no scaled parameters. This function is
534 nested. */
536{
537public:
538 LogarithmicSpacingFunction(int n, bool r, bool sym=false, real_t b=10.0)
539 : SpacingFunction(n, r), sym(sym), logBase(b)
540 {
541 CalculateSpacing();
542 }
543
544 void SetSize(int size) override
545 {
546 n = size;
547 CalculateSpacing();
548 }
549
550 real_t Eval(int p) const override
551 {
552 const int i = reverse ? n - 1 - p : p;
553 return s[i];
554 }
555
556 void Print(std::ostream &os) const override
557 {
558 // SpacingType numIntParam numDoubleParam {int params} {double params}
559 os << int(SpacingType::LOGARITHMIC) << " 3 1 " << n << " " <<
560 (int) reverse << " " << (int) sym << " " << logBase << "\n";
561 }
562
564 { return SpacingType::LOGARITHMIC; }
565 int NumIntParameters() const override { return 3; }
566 int NumDoubleParameters() const override { return 1; }
567
568 void GetIntParameters(Array<int> & p) const override
569 {
570 p.SetSize(3);
571 p[0] = n;
572 p[1] = (int) reverse;
573 p[2] = (int) sym;
574 }
575
576 void GetDoubleParameters(Vector & p) const override
577 {
578 p.SetSize(1);
579 p[0] = logBase;
580 }
581
582 bool Nested() const override { return true; }
583
584 std::unique_ptr<SpacingFunction> Clone() const override
585 {
586 return std::unique_ptr<SpacingFunction>(
587 new LogarithmicSpacingFunction(*this));
588 }
589
590private:
591 bool sym; ///< Whether to make the spacing symmetric
592 real_t logBase; ///< Base of the logarithmic function
593 Vector s; ///< Stores the spacings calculated by @a CalculateSpacing
594
595 /// Calculate parameters used by @a Eval and @a EvalAll
596 void CalculateSpacing();
597 /// Symmetric case for @a CalculateSpacing
598 void CalculateSymmetric();
599 /// Nonsymmetric case for @a CalculateSpacing
600 void CalculateNonsymmetric();
601};
602
603/** @brief Piecewise spacing function, with spacing functions defining spacing
604 within arbitarily many fixed subintervals of the unit interval.
605
606 The number of elements in each piece (or subinterval) is determined by the
607 constructor input @a relN, which is the relative number of intervals. For
608 equal numbers, relN would be all 1's. The total number of elements for this
609 spacing function must be an integer multiple of the sum of entries in relN
610 (stored in n0).
611
612 The scaling of parameters is done for the spacing function on each
613 subinterval separately. This function is nested if and only if the functions
614 on all subintervals are nested.
615 */
617{
618public:
619 /** @brief Constructor for PiecewiseSpacingFunction.
620 @param[in] n Size or number of intervals, which defines elements.
621 @param[in] np Number of pieces (subintervals of unit interval).
622 @param[in] r Whether to reverse the spacings.
623 @param[in] relN Relative number of elements per piece.
624 @param[in] ipar Integer parameters for all np spacing functions. For each
625 piece, these parameters are type, number of integer
626 parameters, number of double parameters, integer parameters.
627 @param[in] dpar Double parameters for all np spacing functions. The first
628 np - 1 entries define the partition of the unit interval,
629 and the remaining are for the pieces.
630 */
631 PiecewiseSpacingFunction(int n, int np, bool r, Array<int> const& relN,
632 Array<int> const& ipar, Vector const& dpar)
633 : SpacingFunction(n, r), np(np), partition(np - 1)
634 {
635 npartition = relN;
636 SetupPieces(ipar, dpar);
637 CalculateSpacing();
638 }
639
640 /// Copy constructor (deep-copy all data, including SpacingFunction pieces)
642 : SpacingFunction(sf), np(sf.np), partition(sf.partition),
643 npartition(sf.npartition), pieces(), n0(sf.n0), s(sf.s)
644 {
645 // To copy, the pointers must be cloned.
646 for (const auto &f : sf.pieces) { pieces.emplace_back(f->Clone()); }
647 }
648
650 {
652 std::swap(tmp, *this);
653 return *this;
654 }
655
658
659 void SetSize(int size) override
660 {
661 n = size;
662 CalculateSpacing();
663 }
664
665 real_t Eval(int p) const override
666 {
667 const int i = reverse ? n - 1 - p : p;
668 return s[i];
669 }
670
671 void ScaleParameters(real_t a) override;
672
673 void Print(std::ostream &os) const override;
674
675 std::unique_ptr<SpacingFunction> Clone() const override
676 {
677 return std::unique_ptr<SpacingFunction>(
678 new PiecewiseSpacingFunction(*this));
679 }
680
681 void SetupPieces(Array<int> const& ipar, Vector const& dpar);
682
684 int NumIntParameters() const override { return 3; }
685 int NumDoubleParameters() const override { return np - 1; }
686
687 void GetIntParameters(Array<int> & p) const override
688 {
689 p.SetSize(3 + np);
690 p[0] = n;
691 p[1] = np;
692 p[2] = (int) reverse;
693 for (int i=0; i<np; ++i) { p[3 + i] = npartition[i]; }
694 }
695
696 void GetDoubleParameters(Vector & p) const override
697 {
698 p.SetSize(np - 1);
699 p = partition;
700 }
701
702 // PiecewiseSpacingFunction is nested if and only if all pieces are nested.
703 bool Nested() const override;
704
705private:
706 int np; ///< Number of pieces
707 Vector partition; ///< Partition of the unit interval
708 Array<int> npartition; ///< Number of intervals in each partition
709 std::vector<std::unique_ptr<SpacingFunction>> pieces;
710
711 int n0 = 0; ///< Total number of intervals
712
713 Vector s; ///< Stores the spacings calculated by @a CalculateSpacing
714
715 /// Calculate parameters used by @a Eval and @a EvalAll
716 void CalculateSpacing();
717};
718
719/// Returns a new SpacingFunction instance defined by the type and parameters
720std::unique_ptr<SpacingFunction> GetSpacingFunction(const SpacingType type,
721 Array<int> const& ipar,
722 Vector const& dpar);
723}
724#endif
Bell spacing function, which produces spacing resembling a Bell curve.
Definition spacing.hpp:357
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
Definition spacing.hpp:423
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
Definition spacing.hpp:379
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Definition spacing.hpp:373
void GetDoubleParameters(Vector &p) const override
Definition spacing.hpp:414
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...
Definition spacing.hpp:395
BellSpacingFunction(int n, bool r, real_t s0, real_t s1, bool s)
Constructor for BellSpacingFunction.
Definition spacing.hpp:367
void GetIntParameters(Array< int > &p) const override
Definition spacing.hpp:406
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
Definition spacing.hpp:404
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
Definition spacing.hpp:389
bool Nested() const override
Returns true if the spacing function is nested during refinement.
Definition spacing.hpp:421
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
Definition spacing.hpp:402
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
Definition spacing.hpp:403
Gaussian spacing function of the general form g(x) = a exp(-(x-m)^2 / c^2) for some scalar parameters...
Definition spacing.hpp:448
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
Definition spacing.hpp:480
void GetIntParameters(Array< int > &p) const override
Definition spacing.hpp:497
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
Definition spacing.hpp:470
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...
Definition spacing.hpp:486
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
Definition spacing.hpp:495
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
Definition spacing.hpp:494
void GetDoubleParameters(Vector &p) const override
Definition spacing.hpp:505
bool Nested() const override
Returns true if the spacing function is nested during refinement.
Definition spacing.hpp:512
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
Definition spacing.hpp:514
GaussianSpacingFunction(int n, bool r, real_t s0, real_t s1, bool s)
Constructor for BellSpacingFunction.
Definition spacing.hpp:458
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Definition spacing.hpp:464
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
Definition spacing.hpp:493
Geometric spacing function.
Definition spacing.hpp:276
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
Definition spacing.hpp:315
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
Definition spacing.hpp:333
GeometricSpacingFunction(int n, bool r, real_t s, bool scale)
Definition spacing.hpp:278
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
Definition spacing.hpp:314
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
Definition spacing.hpp:312
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
Definition spacing.hpp:290
void GetDoubleParameters(Vector &p) const override
Definition spacing.hpp:325
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...
Definition spacing.hpp:305
bool Nested() const override
Returns true if the spacing function is nested during refinement.
Definition spacing.hpp:331
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
Definition spacing.hpp:299
void GetIntParameters(Array< int > &p) const override
Definition spacing.hpp:317
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Definition spacing.hpp:284
Linear spacing function, defining the width of interval i as s + i * d.
Definition spacing.hpp:180
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...
Definition spacing.hpp:212
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Definition spacing.hpp:189
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
Definition spacing.hpp:220
void GetDoubleParameters(Vector &p) const override
Definition spacing.hpp:231
bool Nested() const override
Returns true if the spacing function is nested during refinement.
Definition spacing.hpp:237
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
Definition spacing.hpp:219
void GetIntParameters(Array< int > &p) const override
Definition spacing.hpp:223
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
Definition spacing.hpp:195
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
Definition spacing.hpp:204
LinearSpacingFunction(int n, bool r, real_t s, bool scale)
Definition spacing.hpp:182
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
Definition spacing.hpp:239
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
Definition spacing.hpp:221
Logarithmic spacing function, uniform in log base 10 by default.
Definition spacing.hpp:536
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
Definition spacing.hpp:565
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
Definition spacing.hpp:566
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
Definition spacing.hpp:550
bool Nested() const override
Returns true if the spacing function is nested during refinement.
Definition spacing.hpp:582
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...
Definition spacing.hpp:556
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
Definition spacing.hpp:563
void GetIntParameters(Array< int > &p) const override
Definition spacing.hpp:568
void GetDoubleParameters(Vector &p) const override
Definition spacing.hpp:576
LogarithmicSpacingFunction(int n, bool r, bool sym=false, real_t b=10.0)
Definition spacing.hpp:538
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
Definition spacing.hpp:584
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Definition spacing.hpp:544
Piecewise spacing function, with spacing functions defining spacing within arbitarily many fixed subi...
Definition spacing.hpp:617
void ScaleParameters(real_t a) override
Scales parameters by the factor a associated with Size().
Definition spacing.cpp:472
PiecewiseSpacingFunction & operator=(PiecewiseSpacingFunction &&sf)=default
PiecewiseSpacingFunction(const PiecewiseSpacingFunction &sf)
Copy constructor (deep-copy all data, including SpacingFunction pieces)
Definition spacing.hpp:641
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...
Definition spacing.cpp:477
bool Nested() const override
Returns true if the spacing function is nested during refinement.
Definition spacing.cpp:598
PiecewiseSpacingFunction(int n, int np, bool r, Array< int > const &relN, Array< int > const &ipar, Vector const &dpar)
Constructor for PiecewiseSpacingFunction.
Definition spacing.hpp:631
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
Definition spacing.hpp:665
void GetDoubleParameters(Vector &p) const override
Definition spacing.hpp:696
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Definition spacing.hpp:659
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
Definition spacing.hpp:685
void SetupPieces(Array< int > const &ipar, Vector const &dpar)
Definition spacing.cpp:407
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
Definition spacing.hpp:683
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
Definition spacing.hpp:675
void GetIntParameters(Array< int > &p) const override
Definition spacing.hpp:687
PiecewiseSpacingFunction & operator=(const PiecewiseSpacingFunction &sf)
Definition spacing.hpp:649
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
Definition spacing.hpp:684
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.
Definition spacing.hpp:105
void EvalAll(Vector &s) const
Returns the width of all intervals, resizing s to Size().
Definition spacing.hpp:54
SpacingFunction(int n, bool r=false, bool s=false)
Base class constructor.
Definition spacing.hpp:38
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().
Definition spacing.hpp:68
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).
Definition spacing.hpp:42
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.
Definition spacing.cpp:78
void SetReverse(bool r)
Sets the property that determines whether the spacing is reversed.
Definition spacing.hpp:48
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.
Definition spacing.hpp:104
int n
Size, or number of intervals (elements)
Definition spacing.hpp:103
virtual bool Nested() const =0
Returns true if the spacing function is nested during refinement.
Uniform spacing function, dividing the unit interval into Size() equally spaced intervals (elements).
Definition spacing.hpp:113
real_t Eval(int p) const override
Returns the width of interval p (between 0 and Size() - 1).
Definition spacing.hpp:127
void SetSize(int size) override
Sets the size, or number of intervals (elements).
Definition spacing.hpp:121
SpacingType GetSpacingType() const override
Returns the spacing type, indicating the derived class.
Definition spacing.hpp:138
void GetIntParameters(Array< int > &p) const override
Definition spacing.hpp:143
bool Nested() const override
Returns true if the spacing function is nested during refinement.
Definition spacing.hpp:154
int NumDoubleParameters() const override
Returns the number of double parameters defining the spacing function.
Definition spacing.hpp:141
std::unique_ptr< SpacingFunction > Clone() const override
Returns a clone (deep-copy) of this spacing function.
Definition spacing.hpp:156
int NumIntParameters() const override
Returns the number of integer parameters defining the spacing function.
Definition spacing.hpp:140
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...
Definition spacing.hpp:132
void GetDoubleParameters(Vector &p) const override
Definition spacing.hpp:149
Vector data type.
Definition vector.hpp:80
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
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.
Definition spacing.cpp:17
SpacingType
Definition spacing.hpp:23
float real_t
Definition config.hpp:43
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
real_t p(const Vector &x, real_t t)
RefCoord s[3]