PLaSK library
Loading...
Searching...
No Matches
edge.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#include "edge.hpp"
15#include <cmath>
16
17#include <boost/algorithm/string.hpp>
18
19namespace plask {
20
21namespace edge {
22
24 return false;
25}
26
27Strategy* Strategy::fromStr(const std::string& str, const MaterialsDB& materialsDB) {
28 std::string lower_name = boost::to_lower_copy(str);
29 if (lower_name == "null") return new Null();
30 if (lower_name == "periodic") return new Periodic();
31 if (lower_name == "extend") return new Extend();
32 if (lower_name == "mirror") return new Mirror();
33 return new SimpleMaterial(materialsDB.get(str));
34}
35
36void SimpleMaterial::applyLo(double, double, double&, shared_ptr<plask::Material> &result_material, const Strategy*) const {
38}
39void SimpleMaterial::applyHi(double, double, double&, shared_ptr<plask::Material> &result_material, const Strategy*) const {
41}
42
44 return new SimpleMaterial(this->material);
45}
46
47std::string SimpleMaterial::str() const {
48 return this->material->str();
49}
50
51
52
53void Null::applyLo(double, double, double&, shared_ptr<plask::Material> &, const Strategy*) const {}
54void Null::applyHi(double, double, double&, shared_ptr<plask::Material> &, const Strategy*) const {}
55
56Null* Null::clone() const {
57 return new Null();
58}
59
60std::string Null::str() const {
61 return "null";
62}
63
64
65void Extend::applyLo(double bbox_lo, double /*bbox_hi*/, double &p, shared_ptr<plask::Material>&, const Strategy*) const {
66 p = bbox_lo + 1e-12;
67}
68void Extend::applyHi(double /*bbox_lo*/, double bbox_hi, double &p, shared_ptr<plask::Material>&, const Strategy*) const {
69 p = bbox_hi - 1e-12;
70}
71
73 return new Extend();
74}
75
76std::string Extend::str() const {
77 return "extend";
78}
79
80
81void Periodic::applyLo(double bbox_lo, double bbox_hi, double& p, shared_ptr<Material>&, const Strategy* opposite) const {
82 if (opposite->type() == MIRROR) {
83 double len = bbox_hi - bbox_lo;
84 double len2 = 2 * len;
85 p = std::fmod(p-bbox_lo, len2) + len2;
86 if (p > len) p = len2 - p;
87 p += bbox_lo;
88 } else {
89 p = std::fmod(p-bbox_lo, bbox_hi - bbox_lo) + bbox_hi;
90 }
91}
92void Periodic::applyHi(double bbox_lo, double bbox_hi, double& p, shared_ptr<Material>&, const Strategy* opposite) const {
93 if (opposite->type() == MIRROR) {
94 double len = bbox_hi - bbox_lo;
95 double len2 = 2 * len;
96 p = std::fmod(p-bbox_lo, len2);
97 if (p > len) p = len2 - p;
98 p += bbox_lo;
99 } else {
100 p = std::fmod(p-bbox_lo, bbox_hi - bbox_lo) + bbox_lo;
101 }
102}
103
105 return new Periodic();
106}
107
108std::string Periodic::str() const {
109 return "periodic";
110}
111
112#define mirror_not_at_zero "Mirror is not located at the axis"
113
114void Mirror::applyLo(double bbox_lo, double, double& p, shared_ptr<Material>&, const Strategy*) const {
115 if (bbox_lo != 0.0)
117 p = -p;
118 //p += 2.0 * (bbox_lo - p);
119}
120void Mirror::applyHi(double, double bbox_hi, double& p, shared_ptr<Material>&, const Strategy*) const {
121 if (bbox_hi != 0.0)
123 p = -p;
124 //p -= 2.0 * (p - bbox_hi);
125}
126
128 return true;
129}
130
132 return new Mirror();
133}
134
135std::string Mirror::str() const {
136 return "mirror";
137}
138
139
140} // namespace edge
141
142} // namespace plask