43 struct TemporaryReplaceDefault;
71 for (
const auto&
item: src.constructors) {
72 constructors[
item.first] =
item.second;
74 info.update(src.
info);
82 template <
typename MaterialType>
84 Register(
const std::string& name) { getDefault().add<MaterialType>(name); }
85 Register() { getDefault().add<MaterialType>(); }
89 template <
typename MaterialType>
127 if (!composition.empty())
throw Exception(
"redundant composition given for material '{0}'", materialName);
131 if (!
isnan(doping) && doping != 0.)
throw Exception(
"redundant doping given for material '{0}'", materialName);
158 virtual shared_ptr<Material>
operator()(
double m1_weight)
const = 0;
202 shared_ptr<Material>
operator()(
double m1_weight)
const override {
203 return (*constructor)(mixedComposition(m1_weight), NAN);
207 return material1composition == material2composition ? (*constructor)(material1composition, NAN) : shared_ptr<Material>();
228 double m1DopAmount,
double m2DopAmount,
double shape=1.)
229 :
MixedCompositionOnlyFactory(constructor, material1composition, material2composition, shape), m1DopAmount(m1DopAmount), m2DopAmount(m2DopAmount) {}
236 shared_ptr<Material>
operator()(
double m1_weight)
const override {
237 return (*constructor)(mixedComposition(m1_weight),
238 m1DopAmount * pow(m1_weight, shape) + m2DopAmount * (1.0 - pow(m1_weight, shape)));
242 return (material1composition == material2composition) && (m1DopAmount == m2DopAmount) ?
243 (*constructor)(material1composition, m1DopAmount) : shared_ptr<Material>();
263 MixedDopantFactory(shared_ptr<const MaterialConstructor> constructor,
double m1DopAmount,
double m2DopAmount,
double shape=1.)
271 shared_ptr<Material>
operator()(
double m1_weight)
const override {
272 return (*constructor)(
Material::Composition(), m1DopAmount * pow(m1_weight, shape) + m2DopAmount * (1.0 - pow(m1_weight, shape)));
276 return m1DopAmount == m2DopAmount ? (*constructor)(
Material::Composition(), m1DopAmount) : shared_ptr<Material>();
315 typedef std::map<std::string, shared_ptr<const MaterialConstructor> > constructors_map_t;
318 constructors_map_t constructors;
321 struct iter_val:
public std::function<const constructors_map_t::mapped_type&(const constructors_map_t::value_type&)> {
322 const constructors_map_t::mapped_type& operator()(
const constructors_map_t::value_type &pair)
const {
return pair.second; }
331 typedef boost::transform_iterator<iter_val, constructors_map_t::const_iterator>
iterator;
356 return constructors.size();
376 bool requireDopant = Material::is_with_dopant<MaterialType>::value >
379 template <
typename MaterialType>
385 ensureCompositionIsNotEmpty(composition);
389 bool isAlloy()
const override {
return true; }
392 template <
typename MaterialType>
398 ensureCompositionIsNotEmpty(composition);
399 ensureNoDoping(doping);
403 bool isAlloy()
const override {
return true; }
406 template <
typename MaterialType>
412 ensureCompositionIsEmpty(composition);
416 bool isAlloy()
const override {
return false; }
419 template <
typename MaterialType>
425 ensureCompositionIsEmpty(composition);
426 ensureNoDoping(doping);
430 bool isAlloy()
const override {
return false; }
437 shared_ptr<Material> material;
438 shared_ptr<const MaterialsDB::MaterialConstructor> constructor;
451 bool isAlloy()
const override;
553 template <
typename MaterialType,
bool requireComposition,
bool requireDopant>
554 void add(
const std::string& name) {
568 template <
typename MaterialType>
569 void add(
const std::string& name) {
580 template <
typename MaterialType>
589 void remove(
const std::string& name);
604 shared_ptr<const MaterialConstructor> getConstructor(
const Material::Composition& composition,
const std::string& label =
"",
const std::string&
dopant_name =
"")
const;