Canoe
Comprehensive Atmosphere N' Ocean Engine
absorber_factory.cpp
Go to the documentation of this file.
1 // athena
2 #include <athena/athena.hpp>
3 
4 // external
5 #include <yaml-cpp/yaml.h>
6 
7 #include <application/exceptions.hpp>
8 
9 // canoe
10 #include <air_parcel.hpp>
11 #include <index_map.hpp>
12 
13 // opacity
14 #include "Giants/freedman.hpp"
15 #include "Giants/hydrogen_cia.hpp"
17 #include "hitran_absorber.hpp"
18 #include "nitrogen_cia.hpp"
19 #include "oxygen_cia.hpp"
20 
22  std::vector<std::string> const& names, std::string band_name,
23  YAML::Node const& rad) {
24  AbsorberContainer absorbers;
25 
26  for (auto& name : names) {
27  bool found = false;
28  for (auto& my : rad["opacity-sources"]) {
29  if (name == my["name"].as<std::string>()) {
30  absorbers.push_back(AbsorberFactory::CreateFrom(my, band_name));
31  found = true;
32  break;
33  }
34  }
35 
36  if (!found) {
37  throw NotFoundError("AbsorberFactory", "Opacity " + name);
38  }
39  }
40 
41  return absorbers;
42 }
43 
45  std::string band_name) {
46  if (!my["name"]) {
47  throw NotFoundError("AbsorberFactory", "'name' field in absorber");
48  }
49 
50  if (!my["class"]) {
51  throw NotFoundError("AbsorberFactory", "'class' field in absorber " +
52  my["name"].as<std::string>());
53  }
54 
55  auto ab = createAbsorberPartial(my["name"].as<std::string>(),
56  my["class"].as<std::string>());
57 
58  if (my["data"]) {
59  ab->SetOpacityFile(my["data"].as<std::string>());
60  } else {
61  ab->SetOpacityFile("kcoeff-" + band_name + ".nc");
62  }
63 
64  if (my["dependent-species"]) {
65  auto species = my["dependent-species"].as<std::vector<std::string>>();
66  ab->SetSpeciesIndex(species);
67  }
68 
69  if (my["model"]) {
70  ab->SetModel(my["model"].as<std::string>());
71  }
72 
73  if (my["parameters"]) {
74  ab->SetRealsFrom(my["parameters"]);
75  }
76 
77  ab->CheckFail();
78 
79  return ab;
80 }
81 
82 namespace gp = GiantPlanets;
83 
85  std::string type) {
86  AbsorberPtr ab;
87 
88  if (type == "XIZ-H2-H2-CIA") {
89  ab = std::make_shared<XizH2H2CIA>();
90  } else if (type == "XIZ-H2-He-CIA") {
91  ab = std::make_shared<XizH2HeCIA>();
92  } else if (type == "Hitran") {
93  ab = std::make_shared<HitranAbsorber>(name);
94  } else if (type == "freedman_simple") {
95  ab = std::make_shared<FreedmanSimple>();
96  } else if (type == "freedman_mean") {
97  ab = std::make_shared<FreedmanSimple>();
98  } else if (type == "radio-NH3") {
99  ab = std::make_shared<gp::MwrAbsorberNH3>();
100  } else if (type == "radio-H2O") {
101  ab = std::make_shared<gp::MwrAbsorberH2O>();
102  } else if (type == "radio-H2S") {
103  ab = std::make_shared<gp::MwrAbsorberH2S>();
104  } else if (type == "radio-PH3") {
105  ab = std::make_shared<gp::MwrAbsorberPH3>();
106  } else if (type == "radio-CIA") {
107  ab = std::make_shared<gp::MwrAbsorberCIA>();
108  } else if (type == "radio-Electron") {
109  ab = std::make_shared<gp::MwrAbsorberElectron>();
110  } else {
111  throw NotFoundError("createAbsorberPartial", "Class = " + type);
112  }
113 
114  return ab;
115 }
std::shared_ptr< Absorber > AbsorberPtr
Definition: absorber.hpp:70
std::vector< AbsorberPtr > AbsorberContainer
Definition: absorber.hpp:71
static AbsorberPtr createAbsorberPartial(std::string name, std::string type)
Only create an absorber based on its name and class.
static AbsorberPtr CreateFrom(YAML::Node const &my, std::string band_name)
Create an absorber from YAML node.
This file contains declaration of Absorber.