1#include "InitializeRadiation/InitializeRadiation.h"
8 pugi::xml_document xmldoc;
10 std::string xml_error_string;
11 if (!
open_xml_file(xml_input_file, xmldoc, xml_error_string)) {
15 pugi::xml_node helios = xmldoc.child(
"helios");
20 int radiation_block_count = 0;
21 for (pugi::xml_node radiation_block = helios.child(
"radiation"); radiation_block; radiation_block = radiation_block.next_sibling(
"radiation")) {
22 radiation_block_count++;
24 if (radiation_block_count > 1) {
25 std::cout <<
"WARNING: Only one 'radiation' block is allowed in the input file. Skipping any others..." << std::endl;
29 int direct_ray_count = 100;
30 node = radiation_block.child(
"direct_ray_count");
35 const char *direct_ray_count_str = node.child_value();
36 if (!
parse_int(direct_ray_count_str, direct_ray_count)) {
38 }
else if (direct_ray_count < 0) {
39 helios_runtime_error(
"ERROR: Value given for 'direct_ray_count' must be greater than or equal to 0.");
43 int diffuse_ray_count = 1000;
44 node = radiation_block.child(
"diffuse_ray_count");
46 diffuse_ray_count = 0;
49 const char *diffuse_ray_count_str = node.child_value();
50 if (!
parse_int(diffuse_ray_count_str, diffuse_ray_count)) {
52 }
else if (diffuse_ray_count < 0) {
53 helios_runtime_error(
"ERROR: Value given for 'diffuse_ray_count' must be greater than or equal to 0.");
57 float diffuse_extinction_coeff = 0;
58 node = radiation_block.child(
"diffuse_extinction_coeff");
59 if (node.empty() && diffuse_ray_count > 0) {
60 std::cout <<
"WARNING: No value given for 'diffuse_extinction_coeff'. Assuming a uniform overcast sky." << std::endl;
63 const char *diffuse_extinction_coeff_str = node.child_value();
64 if (!
parse_float(diffuse_extinction_coeff_str, diffuse_extinction_coeff)) {
66 }
else if (diffuse_extinction_coeff < 0) {
67 helios_runtime_error(
"ERROR: Value given for 'diffuse_extinction_coeff' must be greater than or equal to 0.");
70 context_ptr->
setGlobalData(
"diffuse_extinction_coeff", diffuse_extinction_coeff);
72 int scattering_depth = 0;
73 node = radiation_block.child(
"scattering_depth");
76 const char *scattering_depth_str = node.child_value();
77 if (!
parse_int(scattering_depth_str, scattering_depth)) {
79 }
else if (scattering_depth < 0) {
80 helios_runtime_error(
"ERROR: Value given for 'scattering_depth' must be greater than or equal to 0.");
84 float air_turbidity = 0;
85 node = radiation_block.child(
"air_turbidity");
88 const char *air_turbidity_str = node.child_value();
91 if (!
parse_float(air_turbidity_str, air_turbidity)) {
99 }
else if (air_turbidity < 0) {
100 helios_runtime_error(
"ERROR: Value given for 'air_turbidity' must be greater than or equal to 0.");
106 for (pugi::xml_node p = radiation_block.child(
"load_xml_library_file"); p; p = p.next_sibling(
"load_xml_library_file")) {
108 const char *xml_library_file_str = p.child_value();
109 std::string xml_library_file =
trim_whitespace(std::string(xml_library_file_str));
111 if (xml_library_file.empty() || !std::filesystem::exists(xml_library_file)) {
112 std::cout <<
"WARNING: Could not find XML library file: " + xml_library_file <<
". Skipping..." << std::endl;
116 context_ptr->
loadXML(xml_library_file.c_str());
121 std::string solar_direct_spectrum;
122 node = radiation_block.child(
"solar_direct_spectrum");
125 const char *solar_direct_spectrum_str = node.child_value();
126 solar_direct_spectrum =
trim_whitespace(std::string(solar_direct_spectrum_str));
129 std::string leaf_reflectivity_spectrum;
130 node = radiation_block.child(
"leaf_reflectivity_spectrum");
133 const char *leaf_reflectivity_spectrum_str = node.child_value();
134 leaf_reflectivity_spectrum =
trim_whitespace(std::string(leaf_reflectivity_spectrum_str));
137 std::string leaf_transmissivity_spectrum;
138 node = radiation_block.child(
"leaf_transmissivity_spectrum");
141 const char *leaf_transmissivity_spectrum_str = node.child_value();
142 leaf_transmissivity_spectrum =
trim_whitespace(std::string(leaf_transmissivity_spectrum_str));
145 float leaf_emissivity = -1.f;
146 node = radiation_block.child(
"leaf_emissivity");
149 const char *leaf_emissivity_str = node.child_value();
150 if (!
parse_float(leaf_emissivity_str, leaf_emissivity)) {
152 }
else if (leaf_emissivity < 0 || leaf_emissivity > 1.f) {
157 std::string ground_reflectivity_spectrum;
158 node = radiation_block.child(
"ground_reflectivity_spectrum");
161 const char *ground_reflectivity_spectrum_str = node.child_value();
162 ground_reflectivity_spectrum =
trim_whitespace(std::string(ground_reflectivity_spectrum_str));
165 float ground_emissivity = -1.f;
166 node = radiation_block.child(
"ground_emissivity");
169 const char *ground_emissivity_str = node.child_value();
170 if (!
parse_float(ground_emissivity_str, ground_emissivity)) {
172 }
else if (ground_emissivity < 0 || ground_emissivity > 1.f) {
188 if (direct_ray_count > 0) {
193 if (diffuse_ray_count > 0) {
199 if (scattering_depth > 0) {
203 std::cout <<
"WARNING: No value given for 'scattering_depth'. All objects will be assumed to be black." << std::endl;
206 if (air_turbidity > 0) {
208 }
else if (air_turbidity < 0) {
211 if (air_turbidity > 0 && air_turbidity < 1) {
217 std::cout <<
"WARNING: Air turbidity could not be determined. Setting to a default value of 0.05." << std::endl;
221 if (!solar_direct_spectrum.empty()) {
223 if (solar_direct_spectrum ==
"ASTMG173" || solar_direct_spectrum ==
"solar_spectrum_direct_ASTMG173") {
224 solar_direct_spectrum =
"solar_spectrum_direct_ASTMG173";
225 context_ptr->
loadXML(
"plugins/radiation/spectral_data/solar_spectrum_ASTMG173.xml",
true);
227 helios_runtime_error(
"ERROR: The specified solar direct spectrum '" + solar_direct_spectrum +
"' could not be found in existing global data. Make sure to load the XML file containing this spectral data.");
232 std::cout <<
"WARNING: No value given for 'solar_direct_spectrum'. Using a uniform spectral distribution." << std::endl;
235 std::vector<uint> leaf_UUIDs;
240 std::cout <<
"WARNING: No leaf UUIDs found." << std::endl;
243 std::vector<uint> ground_UUIDs;
248 std::cout <<
"WARNING: No ground UUIDs found." << std::endl;
251 if (!leaf_UUIDs.empty()) {
252 if (!leaf_reflectivity_spectrum.empty()) {
253 context_ptr->
setPrimitiveData(leaf_UUIDs,
"reflectivity_spectrum", leaf_reflectivity_spectrum);
255 std::cout <<
"WARNING: No value given for 'leaf_reflectivity_spectrum'. Assuming leaves are black across all shortwave bands." << std::endl;
258 if (!leaf_transmissivity_spectrum.empty()) {
259 context_ptr->
setPrimitiveData(leaf_UUIDs,
"transmissivity_spectrum", leaf_transmissivity_spectrum);
261 std::cout <<
"WARNING: No value given for 'leaf_transmissivity_spectrum'. Assuming leaves are black across all shortwave bands." << std::endl;
264 if (leaf_emissivity >= 0.f && leaf_emissivity <= 1.f) {
267 std::cout <<
"WARNING: No value given for 'leaf_emissivity'. Assuming leaves are perfect emitters." << std::endl;
271 if (!ground_UUIDs.empty()) {
272 if (!ground_reflectivity_spectrum.empty()) {
274 context_ptr->
setPrimitiveData(ground_UUIDs,
"reflectivity_spectrum", ground_reflectivity_spectrum);
276 std::cout <<
"WARNING: The specified ground reflectivity spectrum '" + ground_reflectivity_spectrum +
"' could not be found in existing global data. Assuming the ground is black across all shortwave bands." << std::endl;
279 std::cout <<
"WARNING: No value given for 'ground_reflectivity_spectrum'. Assuming the ground is black across all shortwave bands." << std::endl;
282 if (ground_emissivity >= 0.f && ground_emissivity <= 1.f) {
283 context_ptr->
setPrimitiveData(ground_UUIDs,
"emissivity", ground_emissivity);
285 std::cout <<
"WARNING: No value given for 'ground_emissivity'. Assuming ground is a perfect emitter." << std::endl;
291 if (radiation_block_count == 0) {