OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
fixed_bc.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
34#pragma once
35
39
40namespace pfc {
41
43
44class FixedBC : public FieldModifier {
45
46private:
47 double xwidth = 20.0;
48 double alpha = 1.0;
49 double m_rho_low, m_rho_high;
50 std::string m_name = "FixedBC";
51
52public:
53 FixedBC() = default;
54
55 FixedBC(double rho_low, double rho_high)
56 : m_rho_low(rho_low), m_rho_high(rho_high) {}
57
58 void set_rho_low(double rho_low) { m_rho_low = rho_low; }
59 void set_rho_high(double rho_high) { m_rho_high = rho_high; }
60
61 const std::string &get_modifier_name() const override { return m_name; }
62
63 void apply(Model &m, double) override {
64 const World &w = m.get_world();
65 const double Lx = get_size(w, 0);
66 const double dx = get_spacing(w, 0);
67 const double xpos = Lx * dx - xwidth;
68
69 pfc::field::apply_inplace(
70 m, get_field_name(), [=](const pfc::Real3 &X, double current) {
71 const double x = X[0];
72 if (std::abs(x - xpos) < xwidth) {
73 const double S = 1.0 / (1.0 + std::exp(-alpha * (x - xpos)));
74 return m_rho_low * S + m_rho_high * (1.0 - S);
75 }
76 return current; // outside transition band, keep value
77 });
78 }
79};
80
81} // namespace pfc
Definition field_modifier.hpp:240
Definition fixed_bc.hpp:44
void apply(Model &m, double) override
Apply the field modification to the model (pure virtual)
Definition fixed_bc.hpp:63
const std::string & get_modifier_name() const override
Get the name of the field modifier.
Definition fixed_bc.hpp:61
The Model class represents the physics model for simulations in OpenPFC.
Definition model.hpp:95
Core type definitions for World parameters.
std::array< int, 3 > Int3
Type aliases for clarity.
Definition types.hpp:45
Base class for initial conditions and boundary conditions.
Functional, coordinate-space field operations (header-only)
Represents the global simulation domain (the "world").
Definition world.hpp:91