Skip to content
Snippets Groups Projects
Commit 2b8c6d0b authored by heappy's avatar heappy
Browse files

stops creating plots with matplot++ if plotOn = false

parent 44b68e97
No related tags found
No related merge requests found
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
#include <aircraftGeometry2/processing/transform.h> #include <aircraftGeometry2/processing/transform.h>
#include <matplot/matplot.h> #include <matplot/matplot.h>
#include <algorithm>
#include <array> #include <array>
#include <cstdlib> #include <cstdlib>
#include <deque> #include <deque>
#include <map> #include <map>
#include <utility> #include <utility>
#include <algorithm>
#include "low_t_tail_empennage_design.h" #include "low_t_tail_empennage_design.h"
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
* *
* \param surface aerodynamic surface object * \param surface aerodynamic surface object
* \param object spar or control device object * \param object spar or control device object
* \return std::tuple<std::vector<double>,std::vector<double>,std::string> coordinates and object name * \return std::tuple<std::vector<double>,std::vector<double>,std::string>
* coordinates and object name
*/ */
std::tuple<std::vector<double>, std::vector<double>, std::string> gen_polygon( std::tuple<std::vector<double>, std::vector<double>, std::string> gen_polygon(
const geom2::MultisectionSurface<geom2::AirfoilSection>& surface, const geom2::MultisectionSurface<geom2::AirfoilSection>& surface,
...@@ -42,75 +43,96 @@ std::tuple<std::vector<double>, std::vector<double>, std::string> gen_polygon( ...@@ -42,75 +43,96 @@ std::tuple<std::vector<double>, std::vector<double>, std::string> gen_polygon(
* \param a alpha value between 0 (invisible) - 1 (solid) * \param a alpha value between 0 (invisible) - 1 (solid)
* \return std::array<float,4UL> matplot++ conform color format * \return std::array<float,4UL> matplot++ conform color format
*/ */
//std::array<float, 4UL> rgba(float r, float b, float g, float a) { return {1 - a, r / 255, b / 255, g / 255}; } // std::array<float, 4UL> rgba(float r, float b, float g, float a) { return {1 -
// a, r / 255, b / 255, g / 255}; }
// //
///* */ ///* */
//std::array<float, 4UL> spar_color = rgba(99, 110, 114, 1.0); // std::array<float, 4UL> spar_color = rgba(99, 110, 114, 1.0);
// //
//std::map<std::string, std::array<float, 4UL>> control_device_colormap = {{"elevator", rgba(108, 92, 231, 1.0)}, // std::map<std::string, std::array<float, 4UL>> control_device_colormap =
// {"rudder", rgba(232, 67, 147, 1.0)}}; // {{"elevator", rgba(108, 92, 231, 1.0)},
// {"rudder",
// rgba(232,
// 67,
// 147, 1.0)}};
// //
//std::tuple<std::vector<double>, std::vector<double>, std::string> gen_polygon( // std::tuple<std::vector<double>, std::vector<double>, std::string>
// const geom2::MultisectionSurface<geom2::AirfoilSection>& surface, // gen_polygon(
// const geom2::MultisectionSurface<geom2::PolygonSection>& object) { // const geom2::MultisectionSurface<geom2::AirfoilSection>& surface,
// double half_span = surface.is_symmetric ? 0.5 * geom2::measure::span(surface) : geom2::measure::span(surface); // const geom2::MultisectionSurface<geom2::PolygonSection>& object) {
// /* Spar coordinates positive values normally*/ // double half_span = surface.is_symmetric ? 0.5 *
// double from = object.sections.at(0).origin.z() * half_span; // geom2::measure::span(surface) : geom2::measure::span(surface);
// double to = object.sections.at(1).origin.z() * half_span; // /* Spar coordinates positive values normally*/
// double from = object.sections.at(0).origin.z() * half_span;
// double to = object.sections.at(1).origin.z() * half_span;
// //
// /* Chordwise coordinates */ // /* Chordwise coordinates */
// double chord_from_fwd = object.sections.at(0).get_contour().vertex(0).x(); // double chord_from_fwd = object.sections.at(0).get_contour().vertex(0).x();
// double chord_from_aft = object.sections.at(0).get_contour().vertex(1).x(); // double chord_from_aft = object.sections.at(0).get_contour().vertex(1).x();
// double chord_to_fwd = object.sections.at(1).get_contour().vertex(0).x(); // double chord_to_fwd = object.sections.at(1).get_contour().vertex(0).x();
// double chord_to_aft = object.sections.at(1).get_contour().vertex(1).x(); // double chord_to_aft = object.sections.at(1).get_contour().vertex(1).x();
// //
// auto f_chord_fwd = [chord_from_fwd, chord_to_fwd, half_span](double span_position) { // auto f_chord_fwd = [chord_from_fwd, chord_to_fwd, half_span](double
// return std::lerp(chord_from_fwd, chord_to_fwd, fabs(span_position) / half_span); // span_position) {
// }; // return std::lerp(chord_from_fwd, chord_to_fwd, fabs(span_position) /
// auto f_chord_aft = [chord_from_aft, chord_to_aft, half_span](double span_position) { // half_span);
// return std::lerp(chord_from_aft, chord_to_aft, fabs(span_position) / half_span); // };
// }; // auto f_chord_aft = [chord_from_aft, chord_to_aft, half_span](double
// /* Add object from */ // span_position) {
// std::vector<double> spanwise_coordinates{-fabs(from)}; // return std::lerp(chord_from_aft, chord_to_aft, fabs(span_position) /
// half_span);
// };
// /* Add object from */
// std::vector<double> spanwise_coordinates{-fabs(from)};
// //
// /* Add intermediate sections */ // /* Add intermediate sections */
// for (auto& section : surface.sections) { // for (auto& section : surface.sections) {
// if (fabs(section.origin.z()) > fabs(from) && fabs(section.origin.z()) < fabs(to)) { // if (fabs(section.origin.z()) > fabs(from) && fabs(section.origin.z()) <
// spanwise_coordinates.push_back(section.origin.z()); // fabs(to)) {
// } // spanwise_coordinates.push_back(section.origin.z());
// } // }
// /* Add object to */ // }
// spanwise_coordinates.push_back(-fabs(to)); // /* Add object to */
// spanwise_coordinates.push_back(-fabs(to));
// //
// /**/ // /**/
// std::vector<double> x; // std::vector<double> x;
// std::vector<double> y; // std::vector<double> y;
// /* From in to out*/ // /* From in to out*/
// for (auto it = spanwise_coordinates.begin(); it != spanwise_coordinates.end(); ++it) { // for (auto it = spanwise_coordinates.begin(); it !=
// y.push_back(fabs(*it)); // spanwise_coordinates.end(); ++it) {
// x.push_back(geom2::measure::offset_LE(surface, *it).x() + f_chord_fwd(*it) * geom2::measure::chord(surface, *it)); // y.push_back(fabs(*it));
// } // x.push_back(geom2::measure::offset_LE(surface, *it).x() +
// /* From out to in*/ // f_chord_fwd(*it) * geom2::measure::chord(surface, *it));
// for (auto rit = spanwise_coordinates.rbegin(); rit != spanwise_coordinates.rend(); ++rit) { // }
// y.push_back(fabs(*rit)); // /* From out to in*/
// x.push_back(geom2::measure::offset_LE(surface, *rit).x() + // for (auto rit = spanwise_coordinates.rbegin(); rit !=
// f_chord_aft(*rit) * geom2::measure::chord(surface, *rit)); // spanwise_coordinates.rend(); ++rit) {
// } // y.push_back(fabs(*rit));
// x.push_back(geom2::measure::offset_LE(surface, *rit).x() +
// f_chord_aft(*rit) * geom2::measure::chord(surface, *rit));
// }
// //
// /* Close loop */ // /* Close loop */
// y.push_back(y.front()); // y.push_back(y.front());
// x.push_back(x.front()); // x.push_back(x.front());
// //
// return {x, y, object.name}; // return {x, y, object.name};
//} // }
namespace taw { namespace taw {
namespace low { namespace low {
fs::path T_Tail::plot_stabilizer_planform( fs::path T_Tail::plot_stabilizer_planform(
const geom2::MultisectionSurface<geom2::AirfoilSection>& surface, const geom2::MultisectionSurface<geom2::AirfoilSection>& surface,
const std::vector<geom2::MultisectionSurface<geom2::PolygonSection>>& spars, const std::vector<geom2::MultisectionSurface<geom2::PolygonSection>>& spars,
const std::vector<geom2::MultisectionSurface<geom2::PolygonSection>>& devices) { const std::vector<geom2::MultisectionSurface<geom2::PolygonSection>>&
auto coordinates_xy = geom2::transform::outline_2d(surface, geom2::Direction_3(0, 0, 1)); devices) {
/* Plot active */
if (!rtIO->plotOn) {
return "";
}
auto coordinates_xy =
geom2::transform::outline_2d(surface, geom2::Direction_3(0, 0, 1));
std::deque<double> spanwise; std::deque<double> spanwise;
std::deque<double> chordwise; std::deque<double> chordwise;
auto span = geom2::measure::span(surface); auto span = geom2::measure::span(surface);
...@@ -130,9 +152,10 @@ fs::path T_Tail::plot_stabilizer_planform( ...@@ -130,9 +152,10 @@ fs::path T_Tail::plot_stabilizer_planform(
} }
// /* Get mac coordinates */ // /* Get mac coordinates */
// auto mac_position_y = geom2::measure::mean_aerodynamic_chord_position(data->wing); // auto mac_position_y =
// auto mac_position = geom2::measure::offset_LE(data->wing,mac_position_y); // geom2::measure::mean_aerodynamic_chord_position(data->wing); auto
// auto mac = geom2::measure::chord(data->wing,mac_position_y); // mac_position = geom2::measure::offset_LE(data->wing,mac_position_y); auto
// mac = geom2::measure::chord(data->wing,mac_position_y);
/* Generate plot */ /* Generate plot */
std::string name = surface.name; std::string name = surface.name;
...@@ -199,7 +222,8 @@ fs::path T_Tail::plot_stabilizer_planform( ...@@ -199,7 +222,8 @@ fs::path T_Tail::plot_stabilizer_planform(
ax->legend()->box(true); ax->legend()->box(true);
ax->legend()->font_size(8); ax->legend()->font_size(8);
fs::path plot_path = rtIO->getPlotDir() + "/" + surface.name + "_planfrom.svg"; fs::path plot_path =
rtIO->getPlotDir() + "/" + surface.name + "_planfrom.svg";
matplot::save(f, plot_path.string(), "svg"); matplot::save(f, plot_path.string(), "svg");
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
system("pkill gnuplot"); system("pkill gnuplot");
...@@ -208,27 +232,36 @@ fs::path T_Tail::plot_stabilizer_planform( ...@@ -208,27 +232,36 @@ fs::path T_Tail::plot_stabilizer_planform(
fs::path T_Tail::plot_thickness_and_twist_distribution( fs::path T_Tail::plot_thickness_and_twist_distribution(
const geom2::MultisectionSurface<geom2::AirfoilSection>& surface) { const geom2::MultisectionSurface<geom2::AirfoilSection>& surface) {
/* Plot active */
if (!rtIO->plotOn) {
return "";
}
std::vector<double> eta; std::vector<double> eta;
std::vector<double> thickness_to_chord_ratio; std::vector<double> thickness_to_chord_ratio;
std::vector<double> twist; std::vector<double> twist;
double half_span = surface.is_symmetric ? geom2::measure::span(surface) * 0.5 : geom2::measure::span(surface); double half_span = surface.is_symmetric ? geom2::measure::span(surface) * 0.5
: geom2::measure::span(surface);
for (auto section : surface.sections) { for (auto section : surface.sections) {
eta.push_back(-section.origin.z() / half_span); eta.push_back(-section.origin.z() / half_span);
thickness_to_chord_ratio.push_back(geom2::measure::thickness_max(section) / section.get_chord_length()); thickness_to_chord_ratio.push_back(geom2::measure::thickness_max(section) /
section.get_chord_length());
twist.push_back(section.get_twist_angle()); twist.push_back(section.get_twist_angle());
} }
const auto [t_to_c_min,t_to_c_max] = std::ranges::minmax_element(thickness_to_chord_ratio); const auto [t_to_c_min, t_to_c_max] =
const auto [twist_min,twist_max] = std::ranges::minmax_element(twist); std::ranges::minmax_element(thickness_to_chord_ratio);
const auto [twist_min, twist_max] = std::ranges::minmax_element(twist);
auto f = matplot::figure(true); auto f = matplot::figure(true);
auto ax1 = f->add_subplot(2, 1, 0); auto ax1 = f->add_subplot(2, 1, 0);
ax1->plot(eta, thickness_to_chord_ratio, "g-")->color("black").line_width(1.5); ax1->plot(eta, thickness_to_chord_ratio, "g-")
->color("black")
.line_width(1.5);
// ax1->xlabel("\u03B7"); // ax1->xlabel("\u03B7");
ax1->x_axis().visible(true); ax1->x_axis().visible(true);
ax1->grid(true); ax1->grid(true);
ax1->ylabel("t / c [1]"); ax1->ylabel("t / c [1]");
ax1->ylim({*t_to_c_min - 0.01,*t_to_c_max + 0.01}); ax1->ylim({*t_to_c_min - 0.01, *t_to_c_max + 0.01});
auto ax2 = f->add_subplot(2, 1, 1); auto ax2 = f->add_subplot(2, 1, 1);
ax2->plot(eta, twist, "b-")->color("black").line_style("--").line_width(1.5); ax2->plot(eta, twist, "b-")->color("black").line_style("--").line_width(1.5);
...@@ -237,7 +270,8 @@ fs::path T_Tail::plot_thickness_and_twist_distribution( ...@@ -237,7 +270,8 @@ fs::path T_Tail::plot_thickness_and_twist_distribution(
ax2->grid(true); ax2->grid(true);
ax2->ylim({*twist_min - 0.01, *twist_max + 0.01}); ax2->ylim({*twist_min - 0.01, *twist_max + 0.01});
fs::path plot_path = rtIO->getPlotDir() + "/" + surface.name + "_thickness_and_twist_distribution.svg"; fs::path plot_path = rtIO->getPlotDir() + "/" + surface.name +
"_thickness_and_twist_distribution.svg";
matplot::save(f, plot_path.string(), "svg"); matplot::save(f, plot_path.string(), "svg");
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
system("pkill gnuplot"); system("pkill gnuplot");
...@@ -249,7 +283,12 @@ fs::path T_Tail::plot_thickness_and_twist_distribution( ...@@ -249,7 +283,12 @@ fs::path T_Tail::plot_thickness_and_twist_distribution(
* *
* \return fs::path * \return fs::path
*/ */
std::vector<fs::path> T_Tail::plot_airfoils(const geom2::MultisectionSurface<geom2::AirfoilSection>& surface) { std::vector<fs::path> T_Tail::plot_airfoils(
const geom2::MultisectionSurface<geom2::AirfoilSection>& surface) {
/* Plot active */
if (!rtIO->plotOn) {
return {""};
}
std::map<std::string, std::vector<geom2::Point_2>> airfoils_data{}; std::map<std::string, std::vector<geom2::Point_2>> airfoils_data{};
std::vector<fs::path> airfoil_plots_path; std::vector<fs::path> airfoil_plots_path;
...@@ -284,9 +323,11 @@ std::vector<fs::path> T_Tail::plot_airfoils(const geom2::MultisectionSurface<geo ...@@ -284,9 +323,11 @@ std::vector<fs::path> T_Tail::plot_airfoils(const geom2::MultisectionSurface<geo
ax->xlim({0, 1}); ax->xlim({0, 1});
ax->axis(matplot::equal); ax->axis(matplot::equal);
fs::path plot_path = rtIO->getPlotDir() + "/" + surface.name + "_" + airfoil_data.first + "_airfoil.svg"; fs::path plot_path = rtIO->getPlotDir() + "/" + surface.name + "_" +
airfoil_data.first + "_airfoil.svg";
matplot::save(f, plot_path.string(), "svg"); matplot::save(f, plot_path.string(), "svg");
airfoil_plots_path.push_back(fs::relative(plot_path, fs::path(rtIO->getHtmlDir()))); airfoil_plots_path.push_back(
fs::relative(plot_path, fs::path(rtIO->getHtmlDir())));
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
system("pkill gnuplot"); system("pkill gnuplot");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment