OGS
BaseLib::GradualSubdivision Class Reference

Detailed Description

Gradual subdivision operator with a constant multiplier_

Definition at line 67 of file Subdivision.h.

#include <Subdivision.h>

Inheritance diagram for BaseLib::GradualSubdivision:
[legend]
Collaboration diagram for BaseLib::GradualSubdivision:
[legend]

Public Member Functions

 GradualSubdivision (const double L, const double dL0, const double max_dL, const double multiplier)
 
std::vector< double > operator() () const override
 Returns a vector of subdivided points.
 
- Public Member Functions inherited from BaseLib::ISubdivision
virtual ~ISubdivision ()=default
 

Private Attributes

const double length_
 
const double dL0_
 
const double max_dL_
 
const double multiplier_
 

Constructor & Destructor Documentation

◆ GradualSubdivision()

BaseLib::GradualSubdivision::GradualSubdivision ( const double L,
const double dL0,
const double max_dL,
const double multiplier )

Constructor

Parameters
Ltotal length to be subdivided
dL0initial cell length
max_dLmaximum cell length
multipliermultiplier to cell length

Definition at line 20 of file Subdivision.cpp.

24 : length_(L), dL0_(dL0), max_dL_(max_dL), multiplier_(multiplier)
25{
26 // Check if accumulated subdivisions can ever sum up to length.
27 // Cf. geometric series formula.
28 if (multiplier < 1.0 && dL0 / (1.0 - multiplier) < L)
29 {
31 "Using dL0={:g} and multiplier={:g} the generated subdivisions can "
32 "not sum up to a total length of {:g}.",
33 dL0,
34 multiplier,
35 L);
36 }
37}
#define OGS_FATAL(...)
Definition Error.h:26

References OGS_FATAL.

Member Function Documentation

◆ operator()()

std::vector< double > BaseLib::GradualSubdivision::operator() ( ) const
overridevirtual

Returns a vector of subdivided points.

Implements BaseLib::ISubdivision.

Definition at line 39 of file Subdivision.cpp.

40{
41 std::vector<double> vec_x;
42
43 double x = 0;
44 unsigned i = 0;
45 do
46 {
47 vec_x.push_back(x);
48 x += std::min(max_dL_,
49 dL0_ * std::pow(multiplier_, static_cast<double>(i)));
50 i++;
51 } while (x < length_);
52
53 if (vec_x.back() < length_)
54 {
55 double last_dx = vec_x[vec_x.size() - 1] - vec_x[vec_x.size() - 2];
56 if (length_ - vec_x.back() < last_dx)
57 {
58 vec_x[vec_x.size() - 1] = length_;
59 }
60 else
61 {
62 vec_x.push_back(length_);
63 }
64 }
65 return vec_x;
66}

References dL0_, length_, max_dL_, and multiplier_.

Member Data Documentation

◆ dL0_

const double BaseLib::GradualSubdivision::dL0_
private

Definition at line 87 of file Subdivision.h.

Referenced by operator()().

◆ length_

const double BaseLib::GradualSubdivision::length_
private

Definition at line 86 of file Subdivision.h.

Referenced by operator()().

◆ max_dL_

const double BaseLib::GradualSubdivision::max_dL_
private

Definition at line 88 of file Subdivision.h.

Referenced by operator()().

◆ multiplier_

const double BaseLib::GradualSubdivision::multiplier_
private

Definition at line 89 of file Subdivision.h.

Referenced by operator()().


The documentation for this class was generated from the following files: