Skip to content
Draft
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.19)

Project(soltrace_ui VERSION 1.0.0)

include(cmake/CPM.cmake)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

Expand Down
24 changes: 24 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.42.1)
set(CPM_HASH_SUM "f3a6dcc6a04ce9e7f51a127307fa4f699fb2bade357a8eb4c5b45df76e1dc6a5")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
33 changes: 21 additions & 12 deletions coretrace/simulation_data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ include_directories(.)
include_directories(cst_templates)
include_directories(solar_position_calculators)

include(FetchContent)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(nlohmann_json)
CPMAddPackage(
GITHUB_REPOSITORY "nlohmann/json"
GIT_TAG "v3.11.3"
GIT_SHALLOW TRUE
OPTIONS "JSON_BuildTests OFF"
)

CPMAddPackage(
GITHUB_REPOSITORY "g-truc/glm"
GIT_TAG "1.0.3"
GIT_SHALLOW TRUE
OPTIONS
"GLM_ENABLE_CXX_17 ON"
)

set(SIMDATA_SRC
aperture.cpp
Expand All @@ -26,7 +32,6 @@ set(SIMDATA_SRC
sun.cpp
surface.cpp
virtual_element.cpp
vector3d.cpp
cst_templates/arclength.cpp
cst_templates/heliostat.cpp
cst_templates/linear_fresnel.cpp
Expand Down Expand Up @@ -60,7 +65,7 @@ set(SIMDATA_HDRS
stage_element.hpp
sun.hpp
surface.hpp
vector3d.hpp
vector_utility.hpp
# virtual_element.hpp
cst_templates/arclength.hpp
cst_templates/heliostat.hpp
Expand Down Expand Up @@ -90,8 +95,12 @@ set_target_properties(simdata
PREFIX ""
)

# Link JSON (propagates its include directory)
target_link_libraries(simdata PUBLIC nlohmann_json::nlohmann_json)
# Link dependencies
target_link_libraries(simdata
PUBLIC
nlohmann_json::nlohmann_json
glm::glm
)

if (NOT APPLE AND ENABLE_COVERAGE)
# SET(CMAKE_CXX_FLAGS "-O0 -coverage -fkeep-inline-functions")
Expand Down
54 changes: 24 additions & 30 deletions coretrace/simulation_data/aperture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// #include <iostream>

#include "constants.hpp"
#include "vector_utility.hpp"

namespace SolTrace::Data {

Expand Down Expand Up @@ -668,33 +669,32 @@ void IrregularQuadrilateral::write_json(nlohmann::ordered_json& jnode) const
}

Rectangle::Rectangle(double xlen, double ylen)
: Aperture(ApertureType::RECTANGLE),
x_length(xlen),
y_length(ylen)
: Aperture(ApertureType::RECTANGLE)
, m_length(xlen, ylen)
{
// Default to rectangle centered at the origin.
this->x_coord = -0.5 * this->x_length;
this->y_coord = -0.5 * this->y_length;
return;
m_coord = -0.5 * m_length;
update_cached();
}

Rectangle::Rectangle(const nlohmann::ordered_json& jnode)
: Aperture(ApertureType::RECTANGLE)
{
this->x_length = jnode.at("x_length");
this->y_length = jnode.at("y_length");
this->x_coord = jnode.at("x_coord");
this->y_coord = jnode.at("y_coord");
this->m_length.x = jnode.at("x_length");
this->m_length.y = jnode.at("y_length");
this->m_coord.x = jnode.at("x_coord");
this->m_coord.y = jnode.at("y_coord");
update_cached();
}

double Rectangle::aperture_area() const
{
return this->x_length * this->y_length;
return glm::compMul(m_length);
}

double Rectangle::diameter_circumscribed_circle() const
{
return sqrt(x_length * x_length + y_length * y_length);
return glm::length(m_length);
}

aperture_ptr Rectangle::make_copy() const
Expand All @@ -705,30 +705,25 @@ aperture_ptr Rectangle::make_copy() const

bool Rectangle::is_in(double x, double y) const
{
double xl = this->x_coord;
double yl = this->y_coord;
double xu = xl + this->x_length;
double yu = yl + this->y_length;
return (xl <= x && x <= xu && yl <= y && y <= yu);
return (m_coord.x <= x && x <= m_cached_range.x && m_coord.y <= y && y <= m_cached_range.y);
}

Rectangle::Rectangle(double xlen, double ylen, double xl, double yl)
: Aperture(ApertureType::RECTANGLE),
x_length(xlen),
y_length(ylen),
x_coord(xl),
y_coord(yl)
: Aperture(ApertureType::RECTANGLE)
, m_length(xlen, ylen)
, m_coord(xl, yl)
{
update_cached();
}

void Rectangle::write_json(nlohmann::ordered_json& jnode) const
{
ApertureType type = ApertureType::RECTANGLE;
jnode["aperture_type"] = ApertureTypeMap.at(type);
jnode["x_length"] = this->x_length;
jnode["y_length"] = this->y_length;
jnode["x_coord"] = this->x_coord;
jnode["y_coord"] = this->y_coord;
jnode["x_length"] = this->m_length.x;
jnode["y_length"] = this->m_length.y;
jnode["x_coord"] = this->m_coord.x;
jnode["y_coord"] = this->m_coord.y;
}


Expand All @@ -739,10 +734,9 @@ Rectangle::triangulation() const {
std::vector<int> indices;
for (int i = 0; i <= segments; ++i) {
for (int j = 0; j <= segments; ++j) {
const double x = i * x_length / segments + x_coord;
const double y = j * y_length / segments + y_coord;
verts.push_back(x);
verts.push_back(y);
auto p = glm::dvec2(i, j) * m_length / double(segments) + m_coord;
verts.push_back(p.x);
verts.push_back(p.y);
}
}
for (int i = 0; i < segments; ++i) {
Expand Down
43 changes: 36 additions & 7 deletions coretrace/simulation_data/aperture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <cmath>
#include <memory>
#include <vector>

#include <glm/vec2.hpp>
#include <nlohmann/json.hpp>

#include "constants.hpp"
Expand Down Expand Up @@ -299,8 +301,6 @@ namespace SolTrace::Data
{
double diameter;

// Circle() : Aperture(CIRCLE), diameter(0.0) {}

/**
* @brief Constructor for circular aperture
* @param d Diameter of the circle
Expand Down Expand Up @@ -483,15 +483,18 @@ namespace SolTrace::Data
triangulation() const override;
};

struct Rectangle : public Aperture
class Rectangle : public Aperture
{
double x_length;
double y_length;
glm::dvec2 m_length;
// NOTE: The point (x_coord, y_coord) gives the location of the
// lower left hand corner of the rectangle in the xy-plane.
double x_coord;
double y_coord;
glm::dvec2 m_coord;

glm::dvec2 m_cached_range;

void update_cached() { m_cached_range = m_coord + m_length; }

public:
/**
* @brief Constructor for centered rectangular aperture
* @param xlen Length in x direction
Expand All @@ -516,6 +519,32 @@ namespace SolTrace::Data

virtual ~Rectangle() {}

double x_length() const { return m_length.x; }
double y_length() const { return m_length.y; }
double x_coord() const { return m_coord.x; }
double y_coord() const { return m_coord.y; }

void set_x_length(double x_length)
{
m_length.x = x_length;
update_cached();
}
void set_y_length(double y_length)
{
m_length.y = y_length;
update_cached();
}
void set_x_coord(double x_coord)
{
m_coord.x = x_coord;
update_cached();
}
void set_y_coord(double y_coord)
{
m_coord.y = y_coord;
update_cached();
}

/**
* @brief Calculate rectangular aperture area
* @return Area of the rectangular aperture
Expand Down
Loading
Loading