Skip to content

Commit a82399a

Browse files
committed
refactor(examples): Use pfc::constants::pi in 05_simulator.cpp
Removed global PI constant and replaced all uses with compile-time constant pfc::constants::pi in FFT operator preparation and domain discretization calculations. Implements User Story #49.
1 parent acb74a3 commit a82399a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

examples/05_simulator.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <iostream>
66
#include <limits>
77
#include <memory>
8+
#include <openpfc/constants.hpp>
89
#include <openpfc/core/decomposition.hpp>
910
#include <openpfc/core/world.hpp>
1011
#include <openpfc/factory/decomposition_factory.hpp>
@@ -40,8 +41,6 @@
4041

4142
using namespace pfc;
4243

43-
const double PI = 3.141592653589793238463;
44-
4544
class GaussianIC : public FieldModifier {
4645
private:
4746
double D = 1.0;
@@ -107,9 +106,9 @@ class Diffusion : public Model {
107106
size_t idx = 0;
108107
auto spacing = get_spacing(w);
109108
auto size = get_size(w);
110-
double fx = 2.0 * PI / (spacing[0] * size[0]);
111-
double fy = 2.0 * PI / (spacing[1] * size[1]);
112-
double fz = 2.0 * PI / (spacing[2] * size[2]);
109+
double fx = 2.0 * constants::pi / (spacing[0] * size[0]);
110+
double fy = 2.0 * constants::pi / (spacing[1] * size[1]);
111+
double fz = 2.0 * constants::pi / (spacing[2] * size[2]);
113112
for (int k = low[2]; k <= high[2]; k++) {
114113
for (int j = low[1]; j <= high[1]; j++) {
115114
for (int i = low[0]; i <= high[0]; i++) {
@@ -177,7 +176,7 @@ void run_simulator(Simulator &s) {
177176
void run() {
178177
// Construct world, decomposition, fft and model
179178
int L = 64;
180-
double h = 2.0 * PI / 8.0;
179+
double h = 2.0 * constants::pi / 8.0;
181180
double o = -0.5 * L * h;
182181
std::array<int, 3> dimensions = {L, L, L};
183182
std::array<double, 3> discretization = {h, h, h};

0 commit comments

Comments
 (0)