PLaSK library

Loading...
Searching...
No Matches
info.hpp
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#ifndef PLASK__MATERIAL_INFO_H
15#define PLASK__MATERIAL_INFO_H
16
21#include <string>
22#include <map>
23#include <vector>
24#include <utility>
25
26#include <boost/tokenizer.hpp>
27
28#include "../optional.hpp"
29
30#include <plask/config.hpp> // for PLASK_API
31
32 namespace plask {
33
39 struct PLASK_API MaterialInfo {
40
41 enum PROPERTY_NAME {
42 kind,
43 lattC,
44 Eg,
45 CB,
46 VB,
47 Dso,
48 Mso,
49 Me,
50 Mhh,
51 Mlh,
52 Mh,
53 ac,
54 av,
55 b,
56 d,
57 c11,
58 c12,
59 c44,
60 eps,
61 Eps,
62 chi,
63 Na,
64 Nd,
65 Ni,
66 Nf,
67 EactD,
68 EactA,
69 mob,
70 cond,
71 condtype,
72 A,
73 B,
74 C,
75 D,
76 thermk,
77 dens,
78 cp,
79 nr,
80 absp,
81 Nr,
82 mobe,
83 mobh,
84 taue,
85 tauh,
86 Ce,
87 Ch,
88 e13,
89 e15,
90 e33,
91 c13,
92 c33,
93 Psp,
94 y1,
95 y2,
96 y3
97 };
98
100 static const char* PROPERTY_NAME_STRING[55];
101
102 static PROPERTY_NAME parsePropertyName(const std::string& name);
103
105 enum ARGUMENT_NAME {
106 T,
107 e,
108 lam,
109 n,
110 h,
111 doping,
112 point
113 };
114
116 static const char* ARGUMENT_NAME_STRING[7];
117
118 static ARGUMENT_NAME parseArgumentName(const std::string& name);
119
123 struct PLASK_API Link {
125 std::string className;
127 PROPERTY_NAME property;
129 std::string note;
130
131 Link(std::string className, PROPERTY_NAME property, std::string note = std::string())
132 : className(className), property(property), note(note) {}
133
138 Link(const std::string& to_parse);
139
144 std::string str() const;
145 };
146
148 class PLASK_API PropertyInfo {
149
151 std::string _info;
152
160 PropertyInfo& add(const std::string& infoToAdd) {
161 if (_info.empty()) _info = infoToAdd; else (_info += '\n') += infoToAdd;
162 return *this;
163 }
164
165 public:
166
167 boost::tokenizer<boost::char_separator<char>> eachLine() const;
168
169 std::vector<std::string> eachOfType(const std::string& type) const;
170
171 typedef std::pair<double, double> ArgumentRange;
172
174 PropertyInfo(std::string info = ""): _info(std::move(info)) {}
175
177 static const ArgumentRange NO_RANGE;
178
184 PropertyInfo& set(const std::string& new_info) { this->_info = new_info; return *this; }
185
190 const std::string& get() const { return _info; }
191
196 std::string getSource() const;
197
202 std::string getNote() const;
203
209 ArgumentRange getArgumentRange(ARGUMENT_NAME argument) const;
210
217 std::vector<Link> getLinks() const;
218
224 PropertyInfo& addSource(const std::string& sourceToAdd) {
225 return add("source: " + sourceToAdd);
226 }
227
233 PropertyInfo& addNote(const std::string& sourceToAdd) {
234 return add("note: " + sourceToAdd);
235 }
236
243 PropertyInfo& setArgumentRange(ARGUMENT_NAME argument, ArgumentRange range);
244
251 PropertyInfo& setArgumentRange(ARGUMENT_NAME argument, double from, double to) {
252 return setArgumentRange(argument, ArgumentRange(from, to));
253 }
254
260 PropertyInfo& addLink(const Link& link) { return add("see: " + link.str()); }
261 };
262
264 std::string parent;
265
266 private:
268 std::map<PROPERTY_NAME, PropertyInfo> propertyInfo;
269
270 public:
271
278 void override(const MaterialInfo &to_override);
279
284 PropertyInfo& operator()(PROPERTY_NAME property);
285
291 plask::optional<PropertyInfo> getPropertyInfo(PROPERTY_NAME property) const;
292
294 typedef std::map<PROPERTY_NAME, PropertyInfo>::iterator iterator;
295
297 typedef std::map<PROPERTY_NAME, PropertyInfo>::const_iterator const_iterator;
298
303 iterator begin() { return propertyInfo.begin(); }
304
309 const_iterator begin() const { return propertyInfo.begin(); }
310
315 iterator end() { return propertyInfo.end(); }
316
321 const_iterator end() const { return propertyInfo.end(); }
322
323 //const PropertyInfo& operator()(PROPERTY_NAME property) const;
324
326 class PLASK_API DB {
327
329 std::map<std::string, MaterialInfo> materialInfo;
330
331 public:
332
337 static DB& getDefault();
338
342 void clear() {
343 materialInfo.clear();
344 }
345
350 void update(const DB& src) {
351 for (const auto& item: src.materialInfo) {
352 materialInfo[item.first] = item.second;
353 }
354 }
355
362 MaterialInfo& add(const std::string& materialName, const std::string& parentMaterial);
363
369 MaterialInfo& add(const std::string& materialName);
370
377 plask::optional<MaterialInfo> get(const std::string& materialName, bool with_inherited_info = true) const;
378
385 plask::optional<MaterialInfo::PropertyInfo> get(const std::string& materialName, PROPERTY_NAME propertyName, bool with_inherited_info = true) const;
386
388 typedef std::map<std::string, MaterialInfo>::iterator iterator;
389
391 typedef std::map<std::string, MaterialInfo>::const_iterator const_iterator;
392
397 iterator begin() { return materialInfo.begin(); }
398
403 const_iterator begin() const { return materialInfo.begin(); }
404
409 iterator end() { return materialInfo.end(); }
410
415 const_iterator end() const { return materialInfo.end(); }
416
417 };
418
422 class PLASK_API Register {
423
424 void set(PropertyInfo&) {}
425
426 template <typename Setter1, typename ...Setters>
427 void set(PropertyInfo& i, const Setter1& setter1, const Setters&... setters) {
428 setter1.set(i);
429 set(i, setters...);
430 }
431
432 public:
433 Register(const std::string& materialName, const std::string& parentMaterial) {
434 MaterialInfo::DB::getDefault().add(materialName, parentMaterial);
435 }
436
437 template <typename ...PropertySetters>
438 Register(const std::string& materialName, const std::string& parentMaterial, PROPERTY_NAME property, const PropertySetters&... propertySetters) {
439 set(MaterialInfo::DB::getDefault().add(materialName, parentMaterial)(property), propertySetters...);
440 }
441
442 Register(const std::string& materialName) {
443 MaterialInfo::DB::getDefault().add(materialName);
444 }
445
446 template <typename ...PropertySetters>
447 Register(const std::string& materialName, PROPERTY_NAME property, const PropertySetters&... propertySetters) {
448 set(MaterialInfo::DB::getDefault().add(materialName)(property), propertySetters...);
449 }
450
451 /*template <typename MaterialType, typename ParentType, typename ...PropertySetters>
452 Register(const PropertySetters&... propertySetters) {
453 set(MaterialInfo::DB::getDefault().add(MaterialType::NAME, ParentType::NAME), propertySetters...);
454 }
455
456 template <typename MaterialType, typename ...PropertySetters>
457 Register(const PropertySetters&... propertySetters) {
458 set(MaterialInfo::DB::getDefault().add(MaterialType::NAME), propertySetters...);
459 }*/
460
461 };
462
463 /*struct RegisterProperty {
464
465 PropertyInfo& property;
466
467 RegisterProperty(Register& material, PROPERTY_NAME property)
468 : property(material(property)) {}
469
470 RegisterProperty(std::string& material_name, PROPERTY_NAME property)
471 : property(MaterialInfo::DB::getDefault().add(material_name)(property)) {}
472
473 template <typename MaterialType>
474 RegisterProperty(PROPERTY_NAME property)
475 : property(MaterialInfo::DB::getDefault().add(MaterialType::NAME)(property)) {}
476
477 RegisterProperty& source(const std::string& source) { property.addSource(source); return *this; }
478
479 RegisterProperty& info(const std::string& info) { property.add(info); return *this; }
480
481 RegisterProperty& argumentRange(ARGUMENT_NAME argument, PropertyInfo::ArgumentRange range) {
482 property.setArgumentRange(argument, range); return *this;
483 }
484
485 RegisterProperty& argumentRange(ARGUMENT_NAME argument, double from, double to) {
486 property.setArgumentRange(argument, from, to); return *this;
487 }
488
489 };*/
490
491};
492
493 struct MISource {
494 std::string value;
495 MISource(const std::string& value): value(value) {}
496 void set(MaterialInfo::PropertyInfo& p) const { p.addSource(value); }
497};
498
499 struct MINote {
500 std::string value;
501 MINote(const std::string& value): value(value) {}
502 void set(MaterialInfo::PropertyInfo& p) const { p.addNote(value); }
503};
504
505 struct MIArgumentRange {
506 MaterialInfo::ARGUMENT_NAME arg; double from, to;
507 MIArgumentRange(MaterialInfo::ARGUMENT_NAME arg, double from, double to): arg(arg), from(from), to(to) {}
508 void set(MaterialInfo::PropertyInfo& p) const { p.setArgumentRange(arg, from, to); }
509};
510
511 struct MISee {
512 MaterialInfo::Link value;
513 template<typename ...Args> MISee(Args&&... params): value(std::forward<Args>(params)...) {}
514 void set(MaterialInfo::PropertyInfo& p) const { p.addLink(value); }
515};
516
517 template <typename materialClass>
518 struct MISeeClass {
519 MaterialInfo::Link value;
520 template<typename ...Args> MISeeClass(Args&&... params): value(materialClass::NAME, std::forward<Args>(params)...) {}
521 void set(MaterialInfo::PropertyInfo& p) const { p.addLink(value); }
522};
523
524}
525
526#define MI_PARENT(material, parent) static plask::MaterialInfo::Register __materialinfo__parent__ ## material(material::NAME, parent::NAME);
527#define MI_PROPERTY(material, property, ...) static plask::MaterialInfo::Register __materialinfo__property__ ## material ## property(material::NAME, plask::MaterialInfo::property, ##__VA_ARGS__);
528#define MI_PARENT_PROPERTY(material, parent, property, ...) static plask::MaterialInfo::Register __materialinfo__parent__property__ ## material ## property(material::NAME, parent::NAME, plask::MaterialInfo::property, ##__VA_ARGS__);
529
530#endif // PLASK__MATERIAL_INFO_H