Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions coretrace/simdata_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@

// Private

SolTrace::Data::OpticalProperties make_optics(TOpticalProperties optics_legacy, int interaction_type_int)
{
// TODO: Not using any transmissivity or reflectivity tables

// Get interaction type
SolTrace::Data::InteractionType interaction_type = SolTrace::Data::int_to_interaction(interaction_type_int);

// Get error distribution type
SolTrace::Data::DistributionType dist_type = SolTrace::Data::char_to_distribution(optics_legacy.DistributionType);

double transmissivity = optics_legacy.Transmissivity;
double reflectivity = optics_legacy.Reflectivity;
double rms_slope = optics_legacy.RMSSlopeError;
double rms_spec = optics_legacy.RMSSpecError;
double refrac_real = optics_legacy.RefractiveIndex[0]; // TODO: verify this is how refractiveindex works (there are 4 values)
double refrac_imag = optics_legacy.RefractiveIndex[1];

// Make new optical properties
SolTrace::Data::OpticalProperties optics = SolTrace::Data::OpticalProperties(interaction_type,
dist_type, transmissivity, reflectivity, rms_slope, rms_spec, refrac_real, refrac_imag);

return optics;
}

void convert_user_sun_data(const std::vector<double>& sun_shape_angle, const std::vector<double>& sun_shape_intensity,
std::vector<double>& sun_shape_angle_reduced, std::vector<double>& sun_shape_intensity_reduced)
{
Expand Down Expand Up @@ -283,10 +259,36 @@ int convert_tsystem_to_sim_data(TSystem* sys, const int seed, SolTrace::Data::Si
// Set optical properties
if (is_virtual == false)
{
SolTrace::Data::OpticalProperties optics_front = make_optics(el_legacy->Optics->Front, el_legacy->InteractionType);
SolTrace::Data::OpticalProperties optics_back = make_optics(el_legacy->Optics->Back, el_legacy->InteractionType);
element->set_front_optical_properties(optics_front);
element->set_back_optical_properties(optics_back);
// Convert legacy front/back optics into new OpticalPropertySet
auto &front = el_legacy->Optics->Front;
auto &back = el_legacy->Optics->Back;

SolTrace::Data::InteractionType interaction_type = SolTrace::Data::int_to_interaction(el_legacy->InteractionType);
double refrac_front = front.RefractiveIndex[0];
double refrac_back = back.RefractiveIndex[0];

SolTrace::Data::OpticalPropertySet optics_set(interaction_type, refrac_front, refrac_back);

// Front face
SolTrace::Data::DistributionType dist_front = SolTrace::Data::char_to_distribution(front.DistributionType);
optics_set.set_properties(SolTrace::Data::OpticalSide::Front,
dist_front,
front.Transmissivity,
front.Reflectivity,
front.RMSSlopeError,
front.RMSSpecError);

// Back face
SolTrace::Data::DistributionType dist_back = SolTrace::Data::char_to_distribution(back.DistributionType);
optics_set.set_properties(SolTrace::Data::OpticalSide::Back,
dist_back,
back.Transmissivity,
back.Reflectivity,
back.RMSSlopeError,
back.RMSSpecError);

auto ref = sd.add_optical_property_set(optics_set);
element->set_optical_property_set(ref);
}

// Set element name
Expand Down
22 changes: 16 additions & 6 deletions coretrace/simulation_data/composite_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <sstream>

#include "single_element.hpp"
#include "virtual_element.hpp"

namespace SolTrace::Data
{
Expand All @@ -15,9 +16,9 @@ namespace SolTrace::Data
return;
}

CompositeElement::CompositeElement(const nlohmann::ordered_json &jnode) : ElementBase(jnode),
number_of_elements(0),
my_elements()
CompositeElement::CompositeElement(const nlohmann::ordered_json &jnode,
const OpticalPropertySetResolver& resolve_optics)
: ElementBase(jnode), number_of_elements(0),my_elements()
{
using json = nlohmann::ordered_json;

Expand All @@ -29,12 +30,21 @@ namespace SolTrace::Data
bool is_single = jelement.at("is_single");
if (is_single)
{
element_ptr el = make_element<SingleElement>(jelement);
this->add_element(el);
if (jelement.at("virtual_flag") == true)
{
element_ptr el = make_element<VirtualElement>(jelement, resolve_optics);
this->add_element(el);
}
else
{
element_ptr el = make_element<SingleElement>(jelement, resolve_optics);
this->add_element(el);
}

}
else
{
composite_element_ptr comp = make_element<CompositeElement>(jelement);
composite_element_ptr comp = make_element<CompositeElement>(jelement, resolve_optics);
this->add_element(comp);
}
}
Expand Down
43 changes: 11 additions & 32 deletions coretrace/simulation_data/composite_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace SolTrace::Data
* @brief Default constructor for composite element
*/
CompositeElement();
CompositeElement(const nlohmann::ordered_json& jnode);
CompositeElement(const nlohmann::ordered_json& jnode,
const OpticalPropertySetResolver& resolve_optics);
virtual ~CompositeElement();

/**
Expand Down Expand Up @@ -108,53 +109,31 @@ namespace SolTrace::Data
virtual void set_surface(surface_ptr) override {}

/**
* @brief Get front optical properties (always null for composite elements)
* @return nullptr (composite elements don't have optical properties)
* @brief Get optical propertiy set id (always undefined for composite elements)
* @return unassigned id (composite elements don't have optical properties)
*/
virtual const OpticalProperties *get_front_optical_properties() const override
virtual optics_id get_optical_property_set_id() const override
{
return nullptr;
return OPTICS_ID_UNASSIGNED;
}

/**
* @brief Get front optical properties (always null for composite elements)
* @brief Get optical propertiy set pointer
* @return nullptr (composite elements don't have optical properties)
*/
virtual OpticalProperties *get_front_optical_properties() override
virtual std::shared_ptr<const OpticalPropertySet> get_optical_property_set() const
{
return nullptr;
}

/**
* @brief Set front optical properties (no-op for composite elements)
* @param op Ignored for composite elements
* @brief Set optical propertiy set id (does not apply for composite elements)
Comment thread
taylorbrown75 marked this conversation as resolved.
*/
virtual void set_front_optical_properties(const OpticalProperties &) override {}

/**
* @brief Get back optical properties (always null for composite elements)
* @return nullptr (composite elements don't have optical properties)
*/
virtual const OpticalProperties *get_back_optical_properties() const override
virtual void set_optical_property_set(const OpticalPropertySetReference&) override
{
return nullptr;
assert(false && "CompositeElement does not support optical property sets");
}

/**
* @brief Get back optical properties (always null for composite elements)
* @return nullptr (composite elements don't have optical properties)
*/
virtual OpticalProperties *get_back_optical_properties() override
{
return nullptr;
}

/**
* @brief Set back optical properties (no-op for composite elements)
* @param op Ignored for composite elements
*/
virtual void set_back_optical_properties(const OpticalProperties &) override {};

// CompositeElement accessors
/**
* @brief Add an element to this composite
Expand Down
27 changes: 27 additions & 0 deletions coretrace/simulation_data/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,38 @@ class Container
return;
}

void reset(K start = 0)
{
this->container.clear();
this->next_id = start;
}

iterator get_iterator() { return container.begin(); }
const_iterator get_const_iterator() const { return container.cbegin(); }
bool is_at_end(iterator iter) const { return iter == container.end(); }
bool is_at_end(const_iterator citer) const { return citer == container.cend(); }

bool insert_item(K id, value_pointer item)
{
typename std::map<K, value_pointer>::value_type to_insert(id, item);
auto result = this->container.insert(to_insert);
return result.second;
}

void recompute_next_id(K minimum = 0)
{
K next = minimum;
for (const auto& [id, item] : this->container)
{
if (id >= next)
{
next = id + 1;
}
}

this->next_id = next;
}

private:
std::map<K, value_pointer> container;
mutable K next_id;
Expand Down
24 changes: 3 additions & 21 deletions coretrace/simulation_data/cst_templates/heliostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ namespace SolTrace::Data
{
this->elevation_axis = {1.0, 0.0, 0.0};
this->sun_position = {0.0, 0.0, 1.0};
this->optics_mirror.set_ideal_reflection();
this->optics_back.set_ideal_absorption();
return;
}

Expand Down Expand Up @@ -178,8 +176,7 @@ namespace SolTrace::Data
0.0);

// TODO: Make back optical properties accessible to user
elem->set_front_optical_properties(this->optics_mirror);
elem->set_back_optical_properties(this->optics_back);
elem->set_optical_property_set(this->facet_optics);
elem->enable();

this->heliostat_area += panel_len_x * panel_len_y;
Expand Down Expand Up @@ -376,24 +373,9 @@ namespace SolTrace::Data
return;
}

void Heliostat::set_mirror_optics(const OpticalProperties &optics)
void Heliostat::set_optics(OpticalPropertySetReference ref)
{
this->optics_mirror = optics;
// TODO: Need to update the subelements!
return;
}

void Heliostat::set_back_optics(const OpticalProperties& optics)
{
this->optics_back = optics;
// TODO: Need to update the subelements!
return;
}

void Heliostat::set_optics(const OpticalProperties& mirror_optics, const OpticalProperties& back_optics)
{
this->optics_mirror = mirror_optics;
this->optics_back = back_optics;
this->facet_optics = ref;
// TODO: Need to update the subelements!
return;
}
Expand Down
7 changes: 2 additions & 5 deletions coretrace/simulation_data/cst_templates/heliostat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class Heliostat : public CompositeElement
void set_focal_length(double fx, double fy);
void set_gaps(double gap_x, double gap_y);
void set_number_panels(uint_fast64_t num_x, uint_fast64_t num_y);
void set_mirror_optics(const OpticalProperties& optics);
void set_back_optics(const OpticalProperties& optics);
void set_optics(const OpticalProperties& mirror_optics, const OpticalProperties& back_optics);
void set_optics(OpticalPropertySetReference ref);
// void set_onaxis_canting_distance(double dist);
// void set_offaxis_canting_sun_position(double azimuth, double zenith);
void set_canting(CantingType ct, double val1, double val2);
Expand Down Expand Up @@ -77,8 +75,7 @@ class Heliostat : public CompositeElement

uint_fast64_t num_panels_x;
uint_fast64_t num_panels_y;
OpticalProperties optics_mirror;
OpticalProperties optics_back;
OpticalPropertySetReference facet_optics;

CantingType canting_method;
double onaxis_canting_distance;
Expand Down
25 changes: 8 additions & 17 deletions coretrace/simulation_data/cst_templates/linear_fresnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ namespace SolTrace::Data
tracking_limit_lower(-180.0),
tracking_limit_upper(180.0)
{
this->optics_absorber.set_ideal_absorption();
this->optics_mirror.set_ideal_reflection();
this->optics_env_out.set_ideal_transmission();
this->optics_env_in.set_ideal_transmission();

this->tracking_origin = {1.0, 0.0, 0.0};
this->rotation_axis = {0.0, 1.0, 0.0};
this->neutral_normal = {0.0, 0.0, 1.0};
Expand Down Expand Up @@ -176,10 +171,10 @@ namespace SolTrace::Data
return;
}

void LinearFresnel::set_optics(const OpticalProperties &mirror,
const OpticalProperties &absorber,
const OpticalProperties &envelop_outer,
const OpticalProperties &envelop_inner)
void LinearFresnel::set_optics(const OpticalPropertySetReference mirror,
const OpticalPropertySetReference absorber,
const OpticalPropertySetReference envelop_outer,
const OpticalPropertySetReference envelop_inner)
{
this->optics_mirror = mirror;
this->optics_absorber = absorber;
Expand Down Expand Up @@ -358,8 +353,7 @@ namespace SolTrace::Data
}
mirror->set_surface(surf);

mirror->set_front_optical_properties(this->optics_mirror);
mirror->set_back_optical_properties(this->optics_mirror);
mirror->set_optical_property_set(optics_mirror);
mirror->enable();

std::stringstream name;
Expand Down Expand Up @@ -402,8 +396,7 @@ namespace SolTrace::Data
abs->set_aperture(make_aperture<Rectangle>(this->abs_diameter,
this->aperture_size_y));
abs->set_surface(make_surface<Cylinder>(0.5 * this->abs_diameter));
abs->set_front_optical_properties(this->optics_absorber);
abs->set_back_optical_properties(this->optics_absorber);
abs->set_optical_property_set(optics_absorber);
abs->enable();

this->absorbers.push_back(abs);
Expand All @@ -428,8 +421,7 @@ namespace SolTrace::Data
envout->set_aperture(make_aperture<Rectangle>(this->env_diameter,
this->aperture_size_y));
envout->set_surface(make_surface<Cylinder>(0.5 * this->env_diameter));
envout->set_front_optical_properties(this->optics_env_out);
envout->set_back_optical_properties(this->optics_env_out);
envout->set_optical_property_set(optics_env_out);
envout->enable();

this->envelope.push_back(envout);
Expand All @@ -454,8 +446,7 @@ namespace SolTrace::Data
double ap_y = this->aperture_size_y;
envin->set_aperture(make_aperture<Rectangle>(ap_x, ap_y));
envin->set_surface(make_surface<Cylinder>(0.5 * ap_x));
envin->set_front_optical_properties(this->optics_env_in);
envin->set_back_optical_properties(this->optics_env_in);
envin->set_optical_property_set(optics_env_in);
envin->enable();
this->envelope.push_back(envin);
sts = this->add_element(envin);
Expand Down
16 changes: 8 additions & 8 deletions coretrace/simulation_data/cst_templates/linear_fresnel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class LinearFresnel : public CompositeElement
void set_focused_panels(bool focused);
void set_gaps(double gap_x, double gap_y, double gap_center);
void set_number_panels(int_fast64_t num_x, int_fast64_t num_y);
void set_optics(const OpticalProperties &mirror,
const OpticalProperties &absorber,
const OpticalProperties &envelop_outer,
const OpticalProperties &envelop_inner);
void set_optics(const OpticalPropertySetReference mirror,
const OpticalPropertySetReference absorber,
const OpticalPropertySetReference envelop_outer,
const OpticalPropertySetReference envelop_inner);
void set_receiver_height(double height);
void set_receiver_dimensions(double absorber_diameter,
double envelop_diameter,
Expand Down Expand Up @@ -90,16 +90,16 @@ class LinearFresnel : public CompositeElement
double gap_x;
double gap_y;
double gap_center;
OpticalProperties optics_mirror;
OpticalPropertySetReference optics_mirror;

// Receiver Characteristics
double abs_diameter;
double env_diameter;
double env_thickness;
// double receiver_length;
OpticalProperties optics_absorber;
OpticalProperties optics_env_out;
OpticalProperties optics_env_in;
OpticalPropertySetReference optics_absorber;
OpticalPropertySetReference optics_env_out;
OpticalPropertySetReference optics_env_in;

// Solar Tracking
// double tracking_angle;
Expand Down
Loading
Loading