Skip to content

Commit

Permalink
v2.2.4 Added checks and error messages around places where optional v…
Browse files Browse the repository at this point in the history
…alues are used. This should improve error messages in pywincalc as well.
  • Loading branch information
StephenCzarnecki committed Jul 12, 2022
1 parent f13ea42 commit 93645ee
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project( wincalc VERSION 2.2.3 LANGUAGES CXX )
project( wincalc VERSION 2.2.4 LANGUAGES CXX )
set(LIB_NAME ${PROJECT_NAME})

if(NOT "${CMAKE_CXX_STANDARD}")
Expand Down
56 changes: 48 additions & 8 deletions src/create_wce_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ namespace wincalc

SpectralAveraging::MeasuredRow convert(OpticsParser::WLData const & data)
{
if(!data.directComponent.has_value())
{
throw std::runtime_error("Missing wavelength direct component");
}
SpectralAveraging::MeasuredRow converted(data.wavelength,
data.directComponent.value().tf,
data.directComponent.value().rf,
Expand Down Expand Up @@ -349,8 +353,8 @@ namespace wincalc
int number_visible_bands,
int number_solar_bands)
{
auto wavelength_set = wavelength_range_factory(
product.wavelengths(), optical_method, type, number_visible_bands, number_solar_bands);
auto wavelength_set = wavelength_range_factory(
product.wavelengths(), optical_method, type, number_visible_bands, number_solar_bands);
std::shared_ptr<SingleLayerOptics::CMaterial> material;
if(number_of_layers == 1 && to_lower(optical_method.name) == "solar")
{
Expand Down Expand Up @@ -386,7 +390,7 @@ namespace wincalc
product.bsdf_hemisphere,
0.49); // TODO, replace 0.49 ratio
}
material->setBandWavelengths(wavelength_set);
material->setBandWavelengths(wavelength_set);
return material;
}

Expand Down Expand Up @@ -591,8 +595,25 @@ namespace wincalc
// Since this is a single band material it doesn't matter what the max lambda
// is so long as it is greater than min lambda. So define max_lambda =
// min_lambda + 1

if(!product_data->ir_transmittance_front.has_value())
{
throw std::runtime_error("Missing IR transmittance front");
}
if(!product_data->ir_transmittance_back.has_value())
{
throw std::runtime_error("Missing IR transmittance back");
}
double tf = product_data->ir_transmittance_front.value();
double tb = product_data->ir_transmittance_back.value();
if(!product_data->emissivity_front.has_value())
{
throw std::runtime_error("Missing emissivity front");
}
if(!product_data->emissivity_back.has_value())
{
throw std::runtime_error("Missing emissivity back");
}
double rf = 1.0 - tf - product_data->emissivity_front.value();
double rb = 1.0 - tb - product_data->emissivity_back.value();
material = SingleLayerOptics::Material::singleBandMaterial(
Expand Down Expand Up @@ -676,8 +697,24 @@ namespace wincalc
// Since this is a single band material it doesn't matter what the max lambda
// is so long as it is greater than min lambda. So define max_lambda =
// min_lambda + 1
if(!product_data->ir_transmittance_front.has_value())
{
throw std::runtime_error("Missing IR transmittance front");
}
if(!product_data->ir_transmittance_back.has_value())
{
throw std::runtime_error("Missing IR transmittance back");
}
double tf = product_data->ir_transmittance_front.value();
double tb = product_data->ir_transmittance_back.value();
if(!product_data->emissivity_front.has_value())
{
throw std::runtime_error("Missing emissivity front");
}
if(!product_data->emissivity_back.has_value())
{
throw std::runtime_error("Missing emissivity back");
}
double rf = 1.0 - tf - product_data->emissivity_front.value();
double rb = 1.0 - tb - product_data->emissivity_back.value();
material = SingleLayerOptics::Material::singleBandMaterial(
Expand Down Expand Up @@ -1174,10 +1211,10 @@ namespace wincalc

for(auto const & layer : layers)
{
if(!layer.thermal_data->conductivity.has_value())
{
throw std::runtime_error("Missing conductivity");
}
if(!layer.thermal_data->conductivity.has_value())
{
throw std::runtime_error("Missing conductivity");
}
auto ir_results = calc_thermal_ir(standard, layer);

auto effective_thermal_values =
Expand All @@ -1197,7 +1234,10 @@ namespace wincalc
ir_results.emissivity_back_hemispheric,
ir_results.transmittance_back_diffuse_diffuse);
tarcog_layer = Tarcog::ISO15099::Layers::updateMaterialData(
tarcog_layer, layer.thermal_data->density.value_or(Tarcog::MaterialConstants::GLASSDENSITY), layer.thermal_data->youngs_modulus.value_or(Tarcog::DeflectionConstants::YOUNGSMODULUS));
tarcog_layer,
layer.thermal_data->density.value_or(Tarcog::MaterialConstants::GLASSDENSITY),
layer.thermal_data->youngs_modulus.value_or(
Tarcog::DeflectionConstants::YOUNGSMODULUS));
tarcog_solid_layers.push_back(tarcog_layer);
}

Expand Down
18 changes: 8 additions & 10 deletions src/thermal_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,15 @@ wincalc::ThermalIRResults
auto ir_layer = SingleLayerOptics::CScatteringLayerIR(layer);
auto emissivity_front_hemispheric =
ir_layer.emissivity(FenestrationCommon::Side::Front, polynomial_front);
auto emissivity_back_hemispheric =
auto emissivity_back_hemispheric =
ir_layer.emissivity(FenestrationCommon::Side::Back, polynomial_back);

if(product_data.optical_data->flipped)
{
std::swap(tf, tb);
std::swap(emissivity_front_hemispheric, emissivity_back_hemispheric);
}
if(product_data.optical_data->flipped)
{
std::swap(tf, tb);
std::swap(emissivity_front_hemispheric, emissivity_back_hemispheric);
}

return wincalc::ThermalIRResults{tf,
tb,
emissivity_front_hemispheric,
emissivity_back_hemispheric};
return wincalc::ThermalIRResults{
tf, tb, emissivity_front_hemispheric, emissivity_back_hemispheric};
}

0 comments on commit 93645ee

Please sign in to comment.