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
19
namespace
plask
{
20
21
namespace
edge {
22
23
bool
Strategy::canMoveOutsideBoundingBox
()
const
{
24
return
false
;
25
}
26
27
Strategy
*
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
36
void
SimpleMaterial::applyLo
(
double
,
double
,
double
&, shared_ptr<plask::Material> &
result_material
,
const
Strategy
*)
const
{
37
result_material
=
material
;
38
}
39
void
SimpleMaterial::applyHi
(
double
,
double
,
double
&, shared_ptr<plask::Material> &
result_material
,
const
Strategy
*)
const
{
40
result_material
=
material
;
41
}
42
43
SimpleMaterial
*
SimpleMaterial::clone
()
const
{
44
return
new
SimpleMaterial
(this->
material
);
45
}
46
47
std::string
SimpleMaterial::str
()
const
{
48
return
this->
material
->str();
49
}
50
51
52
53
void
Null::applyLo
(
double
,
double
,
double
&, shared_ptr<plask::Material> &,
const
Strategy
*)
const
{}
54
void
Null::applyHi
(
double
,
double
,
double
&, shared_ptr<plask::Material> &,
const
Strategy
*)
const
{}
55
56
Null
*
Null::clone
()
const
{
57
return
new
Null
();
58
}
59
60
std::string
Null::str
()
const
{
61
return
"null"
;
62
}
63
64
65
void
Extend::applyLo
(
double
bbox_lo
,
double
/*bbox_hi*/
,
double
&p, shared_ptr<plask::Material>&,
const
Strategy
*)
const
{
66
p =
bbox_lo
+ 1
e
-12;
67
}
68
void
Extend::applyHi
(
double
/*bbox_lo*/
,
double
bbox_hi
,
double
&p, shared_ptr<plask::Material>&,
const
Strategy
*)
const
{
69
p =
bbox_hi
- 1
e
-12;
70
}
71
72
Extend
*
Extend::clone
()
const
{
73
return
new
Extend
();
74
}
75
76
std::string
Extend::str
()
const
{
77
return
"extend"
;
78
}
79
80
81
void
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
}
92
void
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
104
Periodic
*
Periodic::clone
()
const
{
105
return
new
Periodic
();
106
}
107
108
std::string
Periodic::str
()
const
{
109
return
"periodic"
;
110
}
111
112
#define mirror_not_at_zero "Mirror is not located at the axis"
113
114
void
Mirror::applyLo
(
double
bbox_lo
,
double
,
double
& p,
shared_ptr<Material>
&,
const
Strategy
*)
const
{
115
if
(
bbox_lo
!= 0.0)
116
throw
Exception
(
mirror_not_at_zero
);
117
p = -p;
118
//p += 2.0 * (bbox_lo - p);
119
}
120
void
Mirror::applyHi
(
double
,
double
bbox_hi
,
double
& p,
shared_ptr<Material>
&,
const
Strategy
*)
const
{
121
if
(
bbox_hi
!= 0.0)
122
throw
Exception
(
mirror_not_at_zero
);
123
p = -p;
124
//p -= 2.0 * (p - bbox_hi);
125
}
126
127
bool
Mirror::canMoveOutsideBoundingBox
()
const
{
128
return
true
;
129
}
130
131
Mirror
*
Mirror::clone
()
const
{
132
return
new
Mirror
();
133
}
134
135
std::string
Mirror::str
()
const
{
136
return
"mirror"
;
137
}
138
139
140
}
// namespace edge
141
142
}
// namespace plask
plask
geometry
edge.cpp
Generated by
1.9.8