-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mesher.cpp
95 lines (77 loc) · 2.73 KB
/
Mesher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**********************************************************************************************************************
* A simple mesher on start 1D domain.
*
* Created by Michael Lewis on 8/5/20.
*********************************************************************************************************************/
#include "Mesher.hpp"
/**
* Initialize a new Mesher
* @throws OutOfMemoryError Indicates insufficient memory for this new Mesher
*/
Mesher::Mesher() : start(0), stop(1), step(0.5) {}
/**
* Initialize a new Mesher with the domain of integration
* @param start_ Start point for the domain of integration
* @param stop_ End point for the domain of integration
* @param step_ The distance between each point in the mesh
* @throws OutOfMemoryError Indicates insufficient memory for this new Mesher
*/
Mesher::Mesher(double start_, double stop_, double step_) : start(start_), stop(stop_), step(step_) {}
/**
* Initialize a deep copy of the source Mesher
* @param mesher The Mesher that will be deeply copied
* @throws OutOfMemoryError Indicates insufficient memory for this new Mesher
*/
Mesher::Mesher(const Mesher &mesher) : start(mesher.start), stop(mesher.stop), step(mesher.step) {}
/**
* Destroy this Mesher
*/
Mesher::~Mesher() {}
/**
* Create a deep copy of the source Mesher
* @param mesher The Mesher that will be deeply copied
* @return This Mesher whose members have been reassigned to the values provided by the source
*/
Mesher & Mesher::operator=(const Mesher &mesher) {
// Avoid self assign
if (this == &mesher) { return *this; }
start = mesher.start;
stop = mesher.stop;
step = mesher.step;
return *this;
}
/**
* Create a vector of mesh points using this Meshers member variables
* @return A {@link std::vector} containing mesh points
*/
std::vector<double> Mesher::xarr() {
double steps = (stop - start) / step;
// Create the container and add the start_ point
std::vector<double> result;
result.push_back(start);
double curr = start;
for (int i = 0; i < steps; ++i) {
curr += step;
result.push_back(curr);
}
return result;
}
/**
* Create a vector of mesh points
* @param start_ Initial value of the property
* @param stop_ Ending value for the property
* @param step_ The distance between mesh points
* @return A {@link std::vector} containing mesh points
*/
std::vector<double> Mesher::xarr(double start_, double stop_, double step_) const {
double steps = (stop_ - start_) / step_;
// Create the container and add the start point
std::vector<double> result;
result.push_back(start_);
double curr = start_;
for (int i = 0; i < steps; ++i) {
curr += step_;
result.push_back(curr);
}
return result;
}