feat(cpp-object-oriented-modular-refactoring): step 12 - material-property-hierarchy
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
#include "fesa/materials/isotropic_linear_elastic_material.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace fesa {
|
||||
namespace {
|
||||
|
||||
Status InvalidMaterial(const SourceEntityId& source_id,
|
||||
const SourceLocation& location,
|
||||
const std::string& message) {
|
||||
return Status::Failure(FailureCategory::kModel,
|
||||
{{Severity::kError, "invalid-material", location,
|
||||
"*MATERIAL", source_id.source_label_text, message}});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Result<IsotropicLinearElasticMaterial> IsotropicLinearElasticMaterial::Create(
|
||||
SourceEntityId source_id, std::string name, double youngs_modulus,
|
||||
double poissons_ratio, SourceLocation location) {
|
||||
if (name.empty() || source_id.source_label_text.empty()) {
|
||||
return Result<IsotropicLinearElasticMaterial>::Failure(InvalidMaterial(
|
||||
source_id, location, "Material source identity must not be empty."));
|
||||
}
|
||||
|
||||
const double denominator = 2.0 * (1.0 + poissons_ratio);
|
||||
const double shear_modulus = youngs_modulus / denominator;
|
||||
if (!std::isfinite(youngs_modulus) || !(youngs_modulus > 0.0) ||
|
||||
!std::isfinite(poissons_ratio) || !std::isfinite(shear_modulus) ||
|
||||
!(shear_modulus > 0.0)) {
|
||||
return Result<IsotropicLinearElasticMaterial>::Failure(InvalidMaterial(
|
||||
source_id, location,
|
||||
"E and the derived G=E/(2*(1+nu)) must be finite and positive."));
|
||||
}
|
||||
|
||||
return Result<IsotropicLinearElasticMaterial>::Success(
|
||||
IsotropicLinearElasticMaterial{std::move(source_id), std::move(name),
|
||||
youngs_modulus, poissons_ratio,
|
||||
std::move(location)});
|
||||
}
|
||||
|
||||
IsotropicLinearElasticMaterial::IsotropicLinearElasticMaterial(
|
||||
std::string name_value, double youngs_modulus_value,
|
||||
double poissons_ratio_value, SourceLocation location_value)
|
||||
: name{std::move(name_value)},
|
||||
youngs_modulus{youngs_modulus_value},
|
||||
poisson_ratio{poissons_ratio_value},
|
||||
location{std::move(location_value)},
|
||||
source_id_{"", 0, name} {}
|
||||
|
||||
MaterialKind IsotropicLinearElasticMaterial::Kind() const noexcept {
|
||||
return MaterialKind::kIsotropicLinearElastic;
|
||||
}
|
||||
|
||||
const SourceEntityId& IsotropicLinearElasticMaterial::SourceId()
|
||||
const noexcept {
|
||||
return source_id_;
|
||||
}
|
||||
|
||||
const SourceLocation& IsotropicLinearElasticMaterial::Location()
|
||||
const noexcept {
|
||||
return location;
|
||||
}
|
||||
|
||||
const std::string& IsotropicLinearElasticMaterial::Name() const noexcept {
|
||||
return name;
|
||||
}
|
||||
|
||||
double IsotropicLinearElasticMaterial::YoungsModulus() const noexcept {
|
||||
return youngs_modulus;
|
||||
}
|
||||
|
||||
double IsotropicLinearElasticMaterial::PoissonsRatio() const noexcept {
|
||||
return poisson_ratio;
|
||||
}
|
||||
|
||||
IsotropicLinearElasticMaterial::IsotropicLinearElasticMaterial(
|
||||
SourceEntityId source_id, std::string name_value,
|
||||
double youngs_modulus_value, double poissons_ratio_value,
|
||||
SourceLocation location_value)
|
||||
: name{std::move(name_value)},
|
||||
youngs_modulus{youngs_modulus_value},
|
||||
poisson_ratio{poissons_ratio_value},
|
||||
location{std::move(location_value)},
|
||||
source_id_{std::move(source_id)} {}
|
||||
|
||||
} // namespace fesa
|
||||
Reference in New Issue
Block a user