Files
FESADev/src/fesa/properties/general_beam_section.cpp
T

141 lines
5.2 KiB
C++

#include "fesa/properties/general_beam_section.h"
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
namespace fesa {
namespace {
Status InvalidBeamSection(const std::string& code,
const SourceEntityId& source_id,
const SourceLocation& location,
const std::string& message) {
return Status::Failure(
FailureCategory::kModel,
{{Severity::kError, code, location, "*BEAM GENERAL SECTION",
source_id.source_label_text, message}});
}
bool IsFinitePoint(const std::array<double, 2>& point) {
return std::isfinite(point[0]) && std::isfinite(point[1]);
}
} // namespace
Result<GeneralBeamSection> GeneralBeamSection::Create(
SourceEntityId source_id, std::string name, double area, double i11,
double i12, double i22, double torsional_constant,
std::array<double, 3> first_axis,
std::vector<std::array<double, 2>> section_points,
SourceLocation location) {
if (name.empty() || source_id.source_label_text.empty()) {
return Result<GeneralBeamSection>::Failure(
InvalidBeamSection("invalid-beam-property", source_id, location,
"Beam section source identity must not be empty."));
}
if (!std::isfinite(i12) || i12 != 0.0) {
return Result<GeneralBeamSection>::Failure(InvalidBeamSection(
std::isfinite(i12) ? "unsupported-coupled-section"
: "invalid-beam-property",
source_id, location,
"The general beam section requires finite exact I12=0."));
}
const std::array<double, 4> positive_properties = {area, i11, i22,
torsional_constant};
if (std::any_of(positive_properties.begin(), positive_properties.end(),
[](double property) {
return !std::isfinite(property) || !(property > 0.0);
}) ||
std::any_of(first_axis.begin(), first_axis.end(),
[](double component) { return !std::isfinite(component); })) {
return Result<GeneralBeamSection>::Failure(InvalidBeamSection(
"invalid-beam-property", source_id, location,
"A, I11, I22, J, and first-axis components must be finite; section "
"magnitudes must be positive."));
}
if (std::any_of(section_points.begin(), section_points.end(),
[](const auto& point) { return !IsFinitePoint(point); })) {
return Result<GeneralBeamSection>::Failure(
InvalidBeamSection("invalid-section-point", source_id, location,
"Section-point coordinates must be finite."));
}
return Result<GeneralBeamSection>::Success(
GeneralBeamSection{std::move(source_id), std::move(name), area, i11, i12,
i22, torsional_constant, first_axis,
std::move(section_points), std::move(location)});
}
GeneralBeamSection::GeneralBeamSection(
std::string name_value, double area_value, double i11_value,
double i12_value, double i22_value, double torsional_constant_value,
std::array<double, 3> first_axis_value,
std::vector<std::array<double, 2>> section_points_value,
SourceLocation location_value)
: name{std::move(name_value)},
area{area_value},
i11{i11_value},
i12{i12_value},
i22{i22_value},
torsional_constant{torsional_constant_value},
first_axis{first_axis_value},
section_points{std::move(section_points_value)},
location{std::move(location_value)},
source_id_{"", 0, name} {}
ElementPropertyKind GeneralBeamSection::Kind() const noexcept {
return ElementPropertyKind::kGeneralBeamSection;
}
const SourceEntityId& GeneralBeamSection::SourceId() const noexcept {
return source_id_;
}
const SourceLocation& GeneralBeamSection::Location() const noexcept {
return location;
}
const std::string& GeneralBeamSection::Name() const noexcept { return name; }
double GeneralBeamSection::Area() const noexcept { return area; }
double GeneralBeamSection::I11() const noexcept { return i11; }
double GeneralBeamSection::I12() const noexcept { return i12; }
double GeneralBeamSection::I22() const noexcept { return i22; }
double GeneralBeamSection::TorsionalConstant() const noexcept {
return torsional_constant;
}
const std::array<double, 3>& GeneralBeamSection::FirstAxis() const noexcept {
return first_axis;
}
const std::vector<std::array<double, 2>>& GeneralBeamSection::SectionPoints()
const noexcept {
return section_points;
}
GeneralBeamSection::GeneralBeamSection(
SourceEntityId source_id, std::string name_value, double area_value,
double i11_value, double i12_value, double i22_value,
double torsional_constant_value, std::array<double, 3> first_axis_value,
std::vector<std::array<double, 2>> section_points_value,
SourceLocation location_value)
: name{std::move(name_value)},
area{area_value},
i11{i11_value},
i12{i12_value},
i22{i22_value},
torsional_constant{torsional_constant_value},
first_axis{first_axis_value},
section_points{std::move(section_points_value)},
location{std::move(location_value)},
source_id_{std::move(source_id)} {}
} // namespace fesa