Skip to content

Commit

Permalink
Merge pull request #9 from LBNL-ETA/oct_2022_refactor
Browse files Browse the repository at this point in the history
Refactor attempt to try to remove shared_ptr where possible and also trying to consolidate ProductData.
  • Loading branch information
StephenCzarnecki authored Apr 27, 2023
2 parents c1848a5 + 868691a commit e07d6b9
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 455 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.8)

project( OpticalMeasurementParser VERSION 1.4.0 LANGUAGES CXX )
project( OpticalMeasurementParser VERSION 2.0.0 LANGUAGES CXX )
set(LIB_NAME ${PROJECT_NAME})

if(NOT "${CMAKE_CXX_STANDARD}")
Expand Down
384 changes: 140 additions & 244 deletions src/Parser.cpp

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ namespace OpticsParser
class Parser
{
public:
std::shared_ptr<ProductData> parseFile(const std::string & inputFile);
std::shared_ptr<ProductData> parseJSONString(std::string const & json);
std::shared_ptr<ProductData> parseJSONFile(std::string const & fname);
ProductData parseFile(const std::string & inputFile);
ProductData parseJSONString(std::string const & json);
ProductData parseJSONFile(std::string const & fname);

private:
void parseHeaderLine(const std::string & line, std::shared_ptr<ProductData> product);
void parseMeasurementLine(const std::string & line, std::shared_ptr<ProductData> product);
void parseEmissivities(const std::string & line, std::shared_ptr<ProductData> product);
void parseUnits(const std::string & line, std::shared_ptr<ProductData> product);
void parseNFRCID(const std::string & line, std::shared_ptr<ProductData> product);
void parseAERCID(const std::string & line, std::shared_ptr<ProductData> product);
void parseHeaderLine(const std::string & line, ProductData & product);
void parseMeasurementLine(const std::string & line, ProductData & product);
void parseEmissivities(const std::string & line, ProductData & product);
void parseUnits(const std::string & line, ProductData & product);
void parseNFRCID(const std::string & line, ProductData & product);
void parseAERCID(const std::string & line, ProductData & product);

void parseBoolPropertyInsideBraces(const std::string & line,
std::string search,
Expand Down Expand Up @@ -69,9 +69,9 @@ namespace OpticsParser
}
};

std::shared_ptr<ProductData> parseOpticsFile(std::string const& fname);
std::shared_ptr<ProductData> parseJSONString(std::string const & json);
std::shared_ptr<ProductData> parseJSONFile(std::string const & fname);
std::shared_ptr<ProductData> parseBSDFXMLFile(std::string const & fname);
std::shared_ptr<ProductData> parseBSDFXMLString(std::string const & contents);
ProductData parseOpticsFile(std::string const& fname);
ProductData parseJSONString(std::string const & json);
ProductData parseJSONFile(std::string const & fname);
ProductData parseBSDFXMLFile(std::string const & fname);
ProductData parseBSDFXMLString(std::string const & contents);
} // namespace OpticsParser
6 changes: 5 additions & 1 deletion src/ProductData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ OpticsParser::ProductData::ProductData(std::string const & productName,
productSubtype(productSubtype)
{}


#if 0
std::shared_ptr<OpticsParser::ProductData> OpticsParser::ProductData::composedProduct()
{
return shared_from_this();
}


std::shared_ptr<OpticsParser::ProductData> OpticsParser::ComposedProductData::composedProduct()
{
return compositionInformation->material;
}
#endif

// Converting to json requires updating and is not currently being
// used so disabling for now.
Expand Down Expand Up @@ -169,6 +171,7 @@ void OpticsParser::to_json(nlohmann::json & j, OpticsParser::ProductData const &
}
#endif

#if 0
OpticsParser::ComposedProductData::ComposedProductData(
ProductData const & product, std::shared_ptr<CompositionInformation> composition) :
ProductData(product), compositionInformation(composition)
Expand All @@ -178,6 +181,7 @@ OpticsParser::ComposedProductData::ComposedProductData(
std::shared_ptr<CompositionInformation> composition) :
ProductData(), compositionInformation(composition)
{}
#endif

OpticsParser::VenetianGeometry::VenetianGeometry(double slatWidth,
double slatSpacing,
Expand Down
42 changes: 17 additions & 25 deletions src/ProductData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,21 @@ namespace OpticsParser
std::optional<CIEValue> cieReflectanceFront;
};

struct PVPowerProperty
{
double jsc;
double voc;
double ff;
};
struct PVPowerProperty
{
double jsc;
double voc;
double ff;
};

using PVPowerProperties = std::map<double, std::vector<PVPowerProperty>>;
using PVPowerProperties = std::map<double, std::vector<PVPowerProperty>>;

struct ProductData;
struct CompositionInformation
{
std::shared_ptr<ProductData> material;
std::shared_ptr<ProductGeometry> geometry;
};

struct ProductData : std::enable_shared_from_this<ProductData>
{
Expand All @@ -173,8 +180,6 @@ namespace OpticsParser
std::string const & productSubtype,
std::string const & manufacturer);

virtual std::shared_ptr<ProductData> composedProduct();

std::string name;
std::optional<std::string> productName;
std::string productType;
Expand Down Expand Up @@ -215,28 +220,15 @@ namespace OpticsParser
std::optional<DualBandValues> dualBandSpecular;
std::optional<DualBandValues> dualBandDiffuse;
std::optional<PrecalculatedResults> precalculatedResults;
std::optional<PVPowerProperties> pvPowerProperties;
std::optional<std::string> thicknessUnit;
std::optional<PVPowerProperties> pvPowerProperties;
std::optional<std::string> thicknessUnit;
std::optional<CompositionInformation> composition;
};

// Converting to json requires updating and is not currently being
// used so disabling for now.
// void to_json(nlohmann::json & j, WLData const & wl);
// void to_json(nlohmann::json & j, ProductData const & wl);

struct CompositionInformation
{
std::shared_ptr<ProductData> material;
std::shared_ptr<ProductGeometry> geometry;
};

struct ComposedProductData : ProductData
{
ComposedProductData(ProductData const & product,
std::shared_ptr<CompositionInformation> composition);
ComposedProductData(std::shared_ptr<CompositionInformation> composition);

std::shared_ptr<ProductData> composedProduct() override;
std::shared_ptr<CompositionInformation> compositionInformation;
};
} // namespace OpticsParser
22 changes: 11 additions & 11 deletions test/InputDifferentEmissivities.unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ TEST_F(TestDifferentEmissivities, Test1)
{
const std::string inputFile = R"(InputDifferentEmissivities.dat)";
OpticsParser::Parser parser;
std::shared_ptr<OpticsParser::ProductData> product = parser.parseFile(inputFile);
auto product = parser.parseFile(inputFile);

EXPECT_NEAR(3.048, product->thickness.value(), 1e-6);
EXPECT_NEAR(1, product->conductivity.value(), 1e-6);
EXPECT_NEAR(0, product->IRTransmittance.value(), 1e-6);
EXPECT_NEAR(0.5, product->frontEmissivity.value(), 1e-6);
EXPECT_NEAR(0.84, product->backEmissivity.value(), 1e-6);
EXPECT_EQ(102, product->nfrcid.value());
EXPECT_EQ("Generic Clear Glass", product->productName);
EXPECT_EQ("glazing", product->productType);
EXPECT_EQ("Monolithic", product->productSubtype);
EXPECT_NEAR(3.048, product.thickness.value(), 1e-6);
EXPECT_NEAR(1, product.conductivity.value(), 1e-6);
EXPECT_NEAR(0, product.IRTransmittance.value(), 1e-6);
EXPECT_NEAR(0.5, product.frontEmissivity.value(), 1e-6);
EXPECT_NEAR(0.84, product.backEmissivity.value(), 1e-6);
EXPECT_EQ(102, product.nfrcid.value());
EXPECT_EQ("Generic Clear Glass", product.productName);
EXPECT_EQ("glazing", product.productType);
EXPECT_EQ("Monolithic", product.productSubtype);

std::vector<OpticsParser::WLData> correctResults{{0.300, 0.0020, 0.0470, 0.0480},
{0.305, 0.0030, 0.0470, 0.0480},
Expand All @@ -68,7 +68,7 @@ TEST_F(TestDifferentEmissivities, Test1)
{0.325, 0.2180, 0.0490, 0.0500}};

auto & givenResults =
std::get<std::vector<OpticsParser::WLData>>(product->measurements.value());
std::get<std::vector<OpticsParser::WLData>>(product.measurements.value());
EXPECT_EQ(correctResults.size(), givenResults.size());
for(auto i = 0u; i < correctResults.size(); ++i)
{
Expand Down
44 changes: 22 additions & 22 deletions test/InputFile1.unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ TEST_F(TestFile1, Test1)
{
const std::string inputFile = R"(InputFile1.dat)";
OpticsParser::Parser parser;
std::shared_ptr<OpticsParser::ProductData> product = parser.parseFile(inputFile);
auto product = parser.parseFile(inputFile);

EXPECT_NEAR(3.048, product->thickness.value(), 1e-6);
EXPECT_NEAR(1, product->conductivity.value(), 1e-6);
EXPECT_NEAR(0, product->IRTransmittance.value(), 1e-6);
EXPECT_NEAR(0.84, product->frontEmissivity.value(), 1e-6);
EXPECT_NEAR(0.84, product->backEmissivity.value(), 1e-6);
EXPECT_EQ(102, product->nfrcid.value());
EXPECT_EQ("Generic Clear Glass", product->productName);
EXPECT_EQ("glazing", product->productType);
EXPECT_EQ("Monolithic", product->productSubtype);
EXPECT_NEAR(3.048, product.thickness.value(), 1e-6);
EXPECT_NEAR(1, product.conductivity.value(), 1e-6);
EXPECT_NEAR(0, product.IRTransmittance.value(), 1e-6);
EXPECT_NEAR(0.84, product.frontEmissivity.value(), 1e-6);
EXPECT_NEAR(0.84, product.backEmissivity.value(), 1e-6);
EXPECT_EQ(102, product.nfrcid.value());
EXPECT_EQ("Generic Clear Glass", product.productName);
EXPECT_EQ("glazing", product.productType);
EXPECT_EQ("Monolithic", product.productSubtype);


std::vector<OpticsParser::WLData> correctResults{{0.300, 0.0020, 0.0470, 0.0480},
Expand All @@ -69,7 +69,7 @@ TEST_F(TestFile1, Test1)
{0.325, 0.2180, 0.0490, 0.0500}};

auto & givenResults =
std::get<std::vector<OpticsParser::WLData>>(product->measurements.value());
std::get<std::vector<OpticsParser::WLData>>(product.measurements.value());
EXPECT_EQ(correctResults.size(), givenResults.size());
for(auto i = 0u; i < correctResults.size(); ++i)
{
Expand All @@ -88,17 +88,17 @@ TEST_F(TestFile1, TestParseFile)
{
const std::string inputFile = R"(InputFile1.dat)";
OpticsParser::Parser parser;
std::shared_ptr<OpticsParser::ProductData> productData = parser.parseFile(inputFile);
auto productData = parser.parseFile(inputFile);

EXPECT_NEAR(3.048, productData->thickness.value(), 1e-6);
EXPECT_NEAR(1, productData->conductivity.value(), 1e-6);
EXPECT_NEAR(0, productData->IRTransmittance.value(), 1e-6);
EXPECT_NEAR(0.84, productData->frontEmissivity.value(), 1e-6);
EXPECT_NEAR(0.84, productData->backEmissivity.value(), 1e-6);
EXPECT_EQ(102, productData->nfrcid.value());
EXPECT_EQ("Generic Clear Glass", productData->productName);
EXPECT_EQ("glazing", productData->productType);
EXPECT_EQ("Monolithic", productData->productSubtype);
EXPECT_NEAR(3.048, productData.thickness.value(), 1e-6);
EXPECT_NEAR(1, productData.conductivity.value(), 1e-6);
EXPECT_NEAR(0, productData.IRTransmittance.value(), 1e-6);
EXPECT_NEAR(0.84, productData.frontEmissivity.value(), 1e-6);
EXPECT_NEAR(0.84, productData.backEmissivity.value(), 1e-6);
EXPECT_EQ(102, productData.nfrcid.value());
EXPECT_EQ("Generic Clear Glass", productData.productName);
EXPECT_EQ("glazing", productData.productType);
EXPECT_EQ("Monolithic", productData.productSubtype);
std::vector<OpticsParser::WLData> correctResults{{0.300, 0.0020, 0.0470, 0.0480},
{0.305, 0.0030, 0.0470, 0.0480},
{0.310, 0.0090, 0.0470, 0.0480},
Expand All @@ -107,7 +107,7 @@ TEST_F(TestFile1, TestParseFile)
{0.325, 0.2180, 0.0490, 0.0500}};

auto & givenResults =
std::get<std::vector<OpticsParser::WLData>>(productData->measurements.value());
std::get<std::vector<OpticsParser::WLData>>(productData.measurements.value());
EXPECT_EQ(correctResults.size(), givenResults.size());
for(auto i = 0u; i < correctResults.size(); ++i)
{
Expand Down
22 changes: 11 additions & 11 deletions test/InputInvertedEmissivities.unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ TEST_F(TestInvertedEmissivities, Test1)
{
const std::string inputFile = R"(InputInvertedEmissivites.dat)";
OpticsParser::Parser parser;
std::shared_ptr<OpticsParser::ProductData> product = parser.parseFile(inputFile);
auto product = parser.parseFile(inputFile);

EXPECT_NEAR(3.048, product->thickness.value(), 1e-6);
EXPECT_NEAR(1, product->conductivity.value(), 1e-6);
EXPECT_NEAR(0, product->IRTransmittance.value(), 1e-6);
EXPECT_NEAR(0.84, product->frontEmissivity.value(), 1e-6);
EXPECT_NEAR(0.5, product->backEmissivity.value(), 1e-6);
EXPECT_EQ(102, product->nfrcid.value());
EXPECT_EQ("", product->productName);
EXPECT_EQ("glazing", product->productType);
EXPECT_EQ("Monolithic", product->productSubtype);
EXPECT_NEAR(3.048, product.thickness.value(), 1e-6);
EXPECT_NEAR(1, product.conductivity.value(), 1e-6);
EXPECT_NEAR(0, product.IRTransmittance.value(), 1e-6);
EXPECT_NEAR(0.84, product.frontEmissivity.value(), 1e-6);
EXPECT_NEAR(0.5, product.backEmissivity.value(), 1e-6);
EXPECT_EQ(102, product.nfrcid.value());
EXPECT_EQ("", product.productName);
EXPECT_EQ("glazing", product.productType);
EXPECT_EQ("Monolithic", product.productSubtype);

std::vector<OpticsParser::WLData> correctResults{{0.300, 0.0020, 0.0470, 0.0480},
{0.305, 0.0030, 0.0470, 0.0480},
Expand All @@ -68,7 +68,7 @@ TEST_F(TestInvertedEmissivities, Test1)
{0.325, 0.2180, 0.0490, 0.0500}};

auto & givenResults =
std::get<std::vector<OpticsParser::WLData>>(product->measurements.value());
std::get<std::vector<OpticsParser::WLData>>(product.measurements.value());
EXPECT_EQ(correctResults.size(), givenResults.size());
for(auto i = 0u; i < correctResults.size(); ++i)
{
Expand Down
6 changes: 3 additions & 3 deletions test/convert_optics_to_json.unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST_F(TestConvertOpticsFile, TestConvertClear3)
clear_3_path += "/CLEAR_3.DAT";

OpticsParser::Parser parser;
std::shared_ptr<OpticsParser::ProductData> product = parser.parseFile(clear_3_path);
auto product = parser.parseFile(clear_3_path);
nlohmann::json product_json = *product;

EXPECT_EQ(product_json.at("nfrc_id").get<int>(), 102);
Expand Down Expand Up @@ -66,8 +66,8 @@ TEST_F(TestConvertOpticsFile, TestConvertClear3)
EXPECT_EQ(measurements[110].at("rb").get<double>(), 0.068);

/*
EXPECT_EQ(product->frontEmissivitySource.value(), "Material");
EXPECT_EQ(product->backEmissivitySource.value(), "Material");
EXPECT_EQ(product.frontEmissivitySource.value(), "Material");
EXPECT_EQ(product.backEmissivitySource.value(), "Material");
*/

EXPECT_EQ(product_json.at("manufacturer").get<std::string>(), "Generic");
Expand Down
26 changes: 13 additions & 13 deletions test/read_bsdf_xml_file.unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ TEST_F(TestLoadBSDFXMLFromDisk, TestLoad2011SA1)
product_path /= "products";
product_path /= "2011-SA1.XML";

std::shared_ptr<OpticsParser::ProductData> product =
auto product =
OpticsParser::parseBSDFXMLFile(product_path.string());

// EXPECT_EQ(product->nfrcid.value(), 102);
EXPECT_EQ(product->productName, "Satine 5500 5%, White Pearl");
EXPECT_EQ(product->productType, "");
EXPECT_EQ(product->manufacturer, "Nysan");
EXPECT_EQ(product->thickness, 1);
EXPECT_EQ(product->conductivity, .15);
EXPECT_EQ(product->IRTransmittance, 0.10916);
EXPECT_EQ(product->frontEmissivity, 0.79626);
EXPECT_EQ(product->backEmissivity, 0.79626);
EXPECT_TRUE(product->measurements.has_value());
EXPECT_TRUE(std::holds_alternative<OpticsParser::DualBandBSDF>(product->measurements.value()));
auto & measurements = std::get<OpticsParser::DualBandBSDF>(product->measurements.value());
// EXPECT_EQ(product.nfrcid.value(), 102);
EXPECT_EQ(product.productName, "Satine 5500 5%, White Pearl");
EXPECT_EQ(product.productType, "");
EXPECT_EQ(product.manufacturer, "Nysan");
EXPECT_EQ(product.thickness, 1);
EXPECT_EQ(product.conductivity, .15);
EXPECT_EQ(product.IRTransmittance, 0.10916);
EXPECT_EQ(product.frontEmissivity, 0.79626);
EXPECT_EQ(product.backEmissivity, 0.79626);
EXPECT_TRUE(product.measurements.has_value());
EXPECT_TRUE(std::holds_alternative<OpticsParser::DualBandBSDF>(product.measurements.value()));
auto & measurements = std::get<OpticsParser::DualBandBSDF>(product.measurements.value());
auto & solar = measurements.solar;
auto & visible = measurements.visible;
EXPECT_EQ(solar.tf.rowAngleBasisName, "LBNL/Klems Full");
Expand Down
Loading

0 comments on commit e07d6b9

Please sign in to comment.