OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
single_seed.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 VTT Technical Research Centre of Finland Ltd
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
32#ifndef PFC_INITIAL_CONDITIONS_SINGLE_SEED_HPP
33#define PFC_INITIAL_CONDITIONS_SINGLE_SEED_HPP
34
35#include "../field_modifier.hpp"
37
38namespace pfc {
39
40class SingleSeed : public FieldModifier {
41 double amp_eq, rho_seed;
42
43public:
44 void set_amplitude(double amplitude) { amp_eq = amplitude; }
45 double get_amplitude() const { return amp_eq; }
46
47 void set_density(double density) { rho_seed = density; }
48 double get_density() const { return rho_seed; }
49
50 void apply(Model &m, double) override {
51 // Functional coordinate-space implementation using field::apply
52 const double s = 1.0 / sqrt(2.0);
53 const std::array<double, 3> q1 = {s, s, 0};
54 const std::array<double, 3> q2 = {s, 0, s};
55 const std::array<double, 3> q3 = {0, s, s};
56 const std::array<double, 3> q4 = {s, 0, -s};
57 const std::array<double, 3> q5 = {s, -s, 0};
58 const std::array<double, 3> q6 = {0, s, -s};
59 const std::array<std::array<double, 3>, 6> q = {q1, q2, q3, q4, q5, q6};
60
61 const double r2 = pow(64.0, 2);
62 const double amplitude = amp_eq;
63 const double rho = rho_seed;
64
65 pfc::field::apply(m, get_field_name(), [=](const pfc::Real3 &X) {
66 const double x = X[0];
67 const double y = X[1];
68 const double z = X[2];
69 if (x * x + y * y + z * z >= r2) {
70 return 0.0; // Outside seed: leave as zero
71 }
72 double u = rho;
73 for (int qi = 0; qi < 6; ++qi) {
74 u += 2.0 * amplitude * std::cos(q[qi][0] * x + q[qi][1] * y + q[qi][2] * z);
75 }
76 return u;
77 });
78 }
79};
80
81} // namespace pfc
82
83#endif // PFC_INITIAL_CONDITIONS_SINGLE_SEED_HPP
Definition field_modifier.hpp:240
The Model class represents the physics model for simulations in OpenPFC.
Definition model.hpp:95
Definition single_seed.hpp:40
void apply(Model &m, double) override
Apply the field modification to the model (pure virtual)
Definition single_seed.hpp:50
Functional, coordinate-space field operations (header-only)
Represents the global simulation domain (the "world").
Definition world.hpp:91