@@ -19,6 +19,15 @@ class CahnHilliard : public Model {
1919 double D = 1.0 ; // Diffusion coefficient
2020
2121public:
22+ /* *
23+ * @brief Constructs a CahnHilliard instance with the given World object.
24+ *
25+ * @param world The World object to initialize the model.
26+ */
27+ explicit CahnHilliard (const World &world) : Model(world) {
28+ // Additional initialization if needed
29+ }
30+
2231 void initialize (double dt) override {
2332 FFT &fft = get_fft ();
2433 const Decomposition &decomp = get_decomposition ();
@@ -37,16 +46,17 @@ class CahnHilliard : public Model {
3746 std::array<int , 3 > o_high = decomp.outbox .high ;
3847 size_t idx = 0 ;
3948 double pi = std::atan (1.0 ) * 4.0 ;
40- double fx = 2.0 * pi / (w.dx * w.Lx );
41- double fy = 2.0 * pi / (w.dy * w.Ly );
42- double fz = 2.0 * pi / (w.dz * w.Lz );
49+ auto spacing = w.spacing ();
50+ auto size = w.size ();
51+ double fx = 2.0 * pi / (spacing[0 ] * size[0 ]);
52+ double fy = 2.0 * pi / (spacing[1 ] * size[1 ]);
53+ double fz = 2.0 * pi / (spacing[2 ] * size[2 ]);
4354 for (int k = o_low[2 ]; k <= o_high[2 ]; k++) {
4455 for (int j = o_low[1 ]; j <= o_high[1 ]; j++) {
4556 for (int i = o_low[0 ]; i <= o_high[0 ]; i++) {
46- // Laplacian operator -k^2
47- double ki = (i <= w.Lx / 2 ) ? i * fx : (i - w.Lx ) * fx;
48- double kj = (j <= w.Ly / 2 ) ? j * fy : (j - w.Ly ) * fy;
49- double kk = (k <= w.Lz / 2 ) ? k * fz : (k - w.Lz ) * fz;
57+ double ki = (i <= size[0 ] / 2 ) ? i * fx : (i - size[0 ]) * fx;
58+ double kj = (j <= size[1 ] / 2 ) ? j * fy : (j - size[1 ]) * fy;
59+ double kk = (k <= size[2 ] / 2 ) ? k * fz : (k - size[2 ]) * fz;
5060 double kLap = -(ki * ki + kj * kj + kk * kk);
5161 double L = kLap * (-D - D * gamma * kLap );
5262 opL[idx] = std::exp (L * dt);
@@ -104,8 +114,9 @@ int main(int argc, char **argv) {
104114 // Construct world, decomposition, fft and model
105115 World world ({Lx, Ly, Lz}, {x0, y0, z0}, {dx, dy, dz});
106116 Decomposition decomp (world);
107- FFT fft (decomp);
108- CahnHilliard model;
117+ auto plan_options = heffte::default_options<heffte::backend::fftw>();
118+ FFT fft (decomp, MPI_COMM_WORLD, plan_options, world);
119+ CahnHilliard model (world);
109120 model.set_fft (fft);
110121
111122 // Define time
@@ -129,9 +140,9 @@ int main(int argc, char **argv) {
129140 // set uri as format cahn_hilliard_%04i.vti, where %04i is replaced by file_count
130141 writer.set_uri (sprintf (" cahn_hilliard_%04i.vti" , file_count));
131142 writer.set_field_name (" concentration" );
132- writer.set_domain (world.get_size (), decomp.get_inbox_size (), decomp.get_inbox_offset ());
133- writer.set_origin (world.get_origin ());
134- writer.set_spacing (world.get_discretization ());
143+ writer.set_domain (world.size (), decomp.get_inbox_size (), decomp.get_inbox_offset ());
144+ writer.set_origin (world.origin ());
145+ writer.set_spacing (world.spacing ());
135146 writer.initialize ();
136147 writer.write (field);
137148
0 commit comments