-
Notifications
You must be signed in to change notification settings - Fork 4
/
fixed_bc.hpp
72 lines (54 loc) · 2.17 KB
/
fixed_bc.hpp
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
/*
OpenPFC, a simulation software for the phase field crystal method.
Copyright (C) 2024 VTT Technical Research Centre of Finland Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
*/
#ifndef PFC_BOUNDARY_CONDITIONS_FIXED_BC_HPP
#define PFC_BOUNDARY_CONDITIONS_FIXED_BC_HPP
#include "../field_modifier.hpp"
namespace pfc {
class FixedBC : public FieldModifier {
private:
double xwidth = 20.0;
double alpha = 1.0;
double m_rho_low, m_rho_high;
std::string m_name = "FixedBC";
public:
FixedBC() = default;
FixedBC(double rho_low, double rho_high) : m_rho_low(rho_low), m_rho_high(rho_high) {}
void set_rho_low(double rho_low) { m_rho_low = rho_low; }
void set_rho_high(double rho_high) { m_rho_high = rho_high; }
const std::string &get_modifier_name() const override { return m_name; }
void apply(Model &m, double) override {
const Decomposition &decomp = m.get_decomposition();
Field &field = m.get_real_field(get_field_name());
const World &w = m.get_world();
Vec3<int> low = decomp.inbox.low;
Vec3<int> high = decomp.inbox.high;
double xpos = w.Lx * w.dx - xwidth;
long int idx = 0;
for (int k = low[2]; k <= high[2]; k++) {
for (int j = low[1]; j <= high[1]; j++) {
for (int i = low[0]; i <= high[0]; i++) {
double x = w.x0 + i * w.dx;
if (std::abs(x - xpos) < xwidth) {
double S = 1.0 / (1.0 + exp(-alpha * (x - xpos)));
field[idx] = m_rho_low * S + m_rho_high * (1.0 - S);
}
idx += 1;
}
}
}
}
};
} // namespace pfc
#endif // PFC_BOUNDARY_CONDITIONS_FIXED_BC_HPP