PLaSK library
Loading...
Searching...
No Matches
info.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 "info.hpp"
15#include "db.hpp"
16
17#include <limits>
18
19namespace plask {
20
21const char* MaterialInfo::PROPERTY_NAME_STRING[55] = {
22 "kind",
23 "lattC",
24 "Eg",
25 "CB",
26 "VB",
27 "Dso",
28 "Mso",
29 "Me",
30 "Mhh",
31 "Mlh",
32 "Mh",
33 "ac",
34 "av",
35 "b",
36 "d",
37 "c11",
38 "c12",
39 "c44",
40 "eps",
41 "Eps",
42 "chi",
43 "Na",
44 "Nd",
45 "Ni",
46 "Nf",
47 "EactD",
48 "EactA",
49 "mob",
50 "cond",
51 "condtype",
52 "A",
53 "B",
54 "C",
55 "D",
56 "thermk",
57 "dens",
58 "cp",
59 "nr",
60 "absp",
61 "Nr",
62 "mobe",
63 "mobh",
64 "taue",
65 "tauh",
66 "Ce",
67 "Ch",
68 "e13",
69 "e33",
70 "c13",
71 "c33",
72 "Psp",
73 "y1",
74 "y2",
75 "y3"
76};
77
80 "T",
81 "e",
82 "lam",
83 "n",
84 "h",
85 "doping",
86 "point"
87};
88
89
90
92{
93 for (unsigned i = 0; i < sizeof (PROPERTY_NAME_STRING) / sizeof (PROPERTY_NAME_STRING[0]); ++i)
94 if (name == PROPERTY_NAME_STRING[i]) return PROPERTY_NAME(i);
95 throw plask::Exception("\"" + name + "\" is not a proper name of material's property.");
96}
97
99{
100 for (unsigned i = 0; i < sizeof (ARGUMENT_NAME_STRING) / sizeof (ARGUMENT_NAME_STRING[0]); ++i)
101 if (name == ARGUMENT_NAME_STRING[i]) return ARGUMENT_NAME(i);
102 throw plask::Exception("\"" + name + "\" is not a proper name of argument of material's method.");
103}
104
106 std::string s;
107 std::tie(s, this->note) = plask::splitString2(to_parse, ' ');
108 std::tie(this->className, s) = plask::splitString2(s, '.');
109 this->property = MaterialInfo::parsePropertyName(s);
110}
111
112std::string MaterialInfo::Link::str() const {
113 std::string result;
114 ((result += this->className) += '.') += MaterialInfo::PROPERTY_NAME_STRING[this->property];
115 (result += ' ') += this->note;
116 return result;
117}
118
119
121 this->parent = to_override.parent;
122 for (auto& prop: to_override.propertyInfo)
123 this->propertyInfo[prop.first] = prop.second;
124}
125
127 return propertyInfo[property];
128}
129
131{
132 auto i = propertyInfo.find(property);
134}
135
136/*const MaterialInfo::PropertyInfo& MaterialInfo::operator()(PROPERTY_NAME property) const {
137 return propertyInfo[property];
138}*/
139
141 ArgumentRange(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
142
143boost::tokenizer<boost::char_separator<char> > MaterialInfo::PropertyInfo::eachLine() const {
144 return boost::tokenizer<boost::char_separator<char>>(_info, boost::char_separator<char>("\n\r"));
145}
146
147std::vector<std::string> MaterialInfo::PropertyInfo::eachOfType(const std::string &type) const {
148 std::vector<std::string> result;
149 for (const std::string& line: eachLine()) {
150 auto p = splitString2(line, ':');
151 boost::trim(p.first); boost::trim(p.second);
152 if (p.first == type)
153 result.push_back(p.second);
154 }
155 return result;
156}
157
159 std::string result;
160 for (const std::string& source: eachOfType("source")) {
161 if (source.empty()) continue;
162 if (!result.empty()) result += '\n';
163 result += source;
164 }
165 return result;
166}
167
169 std::string result;
170 for (const std::string& source: eachOfType("note")) {
171 if (source.empty()) continue;
172 if (!result.empty()) result += '\n';
173 result += source;
174 }
175 return result;
176}
177
179 for (const std::string& range_desc: eachOfType(ARGUMENT_NAME_STRING[argument] + std::string(" range"))) {
180 std::string from, to;
181 std::tie(from, to) = splitString2(range_desc, ':');
182 try {
183 return MaterialInfo::PropertyInfo::ArgumentRange(boost::lexical_cast<double>(from), boost::lexical_cast<double>(to));
184 } catch (const std::exception&) {}
185 }
186 return NO_RANGE;
187}
188
189std::vector<MaterialInfo::Link> MaterialInfo::PropertyInfo::getLinks() const {
190 std::vector<MaterialInfo::Link> result;
191 for (const std::string& link_str: eachOfType("see"))
192 try {
194 } catch (const std::exception&) {}
195 return result;
196}
197
199 if (range != NO_RANGE) {
200 std::string s;
201 (s += MaterialInfo::ARGUMENT_NAME_STRING[argument]) += " range: ";
202 s += boost::lexical_cast<std::string>(range.first);
203 s += ":";
204 s += boost::lexical_cast<std::string>(range.second);
205 add(std::move(s));
206 }
207 return *this;
208}
209
213
214MaterialInfo & MaterialInfo::DB::add(const std::string &materialName, const std::string &parentMaterial) {
215 MaterialInfo& result = materialInfo[materialName];
217 return result;
218}
219
220MaterialInfo & MaterialInfo::DB::add(const std::string& materialName) {
221 return materialInfo[materialName];
222}
223
224plask::optional<MaterialInfo> MaterialInfo::DB::get(const std::string &materialName, bool with_inherited_info) const {
225 auto this_mat_info = materialInfo.find(materialName);
226 if (this_mat_info == materialInfo.end())
228
229 if (!with_inherited_info || this_mat_info->second.parent.empty())
231
232 plask::optional<MaterialInfo> parent_info = get(this_mat_info->second.parent, true);
233 if (!parent_info)
235 parent_info->override(this_mat_info->second);
236 return parent_info;
237}
238
240 auto this_mat_info = materialInfo.find(materialName);
241 if (this_mat_info == materialInfo.end())
243
244 auto res = this_mat_info->second.getPropertyInfo(propertyName);
245 return res || !with_inherited_info || this_mat_info->second.parent.empty() ? res : get(this_mat_info->second.parent, propertyName, true);
246}
247
248
249
250}