155 lines
6.0 KiB
C++
155 lines
6.0 KiB
C++
#include "fesa/analysis/analysis_model.hpp"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
|
|
fesa::ModelDefinition makeDefinition() {
|
|
const std::filesystem::path source{"models/analysis-model.inp"};
|
|
fesa::ModelDefinition definition{};
|
|
definition.source_path = source;
|
|
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
|
definition.nodes = {
|
|
{{"Beam-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
|
{{"Beam-1", 2, "2"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
|
{{"Beam-1", 3, "3"}, {2.0, 0.0, 0.0}, {source, 12U}},
|
|
{{"Beam-1", 4, "4"}, {3.0, 0.0, 0.0}, {source, 13U}},
|
|
{{"Beam-1", 5, "5"}, {4.0, 0.0, 0.0}, {source, 14U}}};
|
|
definition.materials = {
|
|
{"Material-0", 100.0, 0.20, {source, 20U}},
|
|
{"Material-1", 200.0, 0.25, {source, 21U}},
|
|
{"Material-2", 300.0, 0.30, {source, 22U}},
|
|
{"Unused-Material", 400.0, 0.35, {source, 23U}}};
|
|
definition.sections = {
|
|
{"Section-0", 1.0, 1.0, 0.0, 1.0, 1.0,
|
|
{0.0, 1.0, 0.0}, {}, {source, 30U}},
|
|
{"Section-1", 2.0, 2.0, 0.0, 2.0, 2.0,
|
|
{0.0, 1.0, 0.0}, {}, {source, 31U}},
|
|
{"Section-2", 3.0, 3.0, 0.0, 3.0, 3.0,
|
|
{0.0, 1.0, 0.0}, {}, {source, 32U}},
|
|
{"Unused-Section", 4.0, 4.0, 0.0, 4.0, 4.0,
|
|
{0.0, 1.0, 0.0}, {}, {source, 33U}}};
|
|
definition.elements = {
|
|
{{"Beam-1", 1, "1"}, {0U, 1U}, 2U, 2U, {source, 40U}},
|
|
{{"Beam-1", 2, "2"}, {1U, 2U}, 0U, 1U, {source, 41U}},
|
|
{{"Beam-1", 3, "3"}, {2U, 3U}, 2U, 2U, {source, 42U}},
|
|
{{"Beam-1", 4, "4"}, {3U, 4U}, 1U, 0U, {source, 43U}}};
|
|
definition.steps = {{
|
|
"Step-1",
|
|
{{"Root", 1, 3, 0.0, {source, 51U}},
|
|
{"Root", 4, 6, 0.0, {source, 52U}}},
|
|
{{"Tip", 1, 10.0, {source, 53U}},
|
|
{"Tip", 2, -20.0, {source, 54U}},
|
|
{"Tip", 6, 30.0, {source, 55U}}},
|
|
0.1,
|
|
1.0,
|
|
0.01,
|
|
1.0,
|
|
{source, 50U}}};
|
|
return definition;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(AnalysisModel, ClassifiesActiveEntitiesInStableOrder) {
|
|
auto domainResult = fesa::Domain::Create(makeDefinition());
|
|
ASSERT_TRUE(domainResult.HasValue());
|
|
|
|
auto modelResult = fesa::AnalysisModel::create(domainResult.Value());
|
|
ASSERT_TRUE(modelResult.HasValue());
|
|
const auto& model = modelResult.Value();
|
|
|
|
EXPECT_EQ(
|
|
model.activeElements(),
|
|
(std::vector<fesa::EntityIndex>{0U, 1U, 2U, 3U}));
|
|
EXPECT_EQ(
|
|
model.activeMaterials(),
|
|
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
|
EXPECT_EQ(
|
|
model.activeSections(),
|
|
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
|
EXPECT_EQ(
|
|
model.activeBoundaryConditions(),
|
|
(std::vector<fesa::EntityIndex>{0U, 1U}));
|
|
EXPECT_EQ(
|
|
model.activeLoads(),
|
|
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
|
}
|
|
|
|
TEST(AnalysisModel, ReferencesWithoutCopyingOrMutatingDomain) {
|
|
auto domainResult = fesa::Domain::Create(makeDefinition());
|
|
ASSERT_TRUE(domainResult.HasValue());
|
|
const fesa::Domain& domain = domainResult.Value();
|
|
const auto* const elementAddress = domain.Elements().data();
|
|
const auto* const materialAddress = domain.Materials().data();
|
|
const auto* const sectionAddress = domain.Sections().data();
|
|
const std::string stepName = domain.Steps()[0].name;
|
|
const double firstLoadMagnitude = domain.Steps()[0].loads[0].magnitude;
|
|
|
|
auto modelResult = fesa::AnalysisModel::create(domain);
|
|
ASSERT_TRUE(modelResult.HasValue());
|
|
const auto& model = modelResult.Value();
|
|
|
|
EXPECT_EQ(&model.domain(), &domain);
|
|
EXPECT_EQ(&model.step(), &domain.Steps()[0]);
|
|
EXPECT_EQ(model.domain().Elements().data(), elementAddress);
|
|
EXPECT_EQ(model.domain().Materials().data(), materialAddress);
|
|
EXPECT_EQ(model.domain().Sections().data(), sectionAddress);
|
|
EXPECT_EQ(
|
|
&model.domain().Elements()[model.activeElements()[1]],
|
|
&domain.Elements()[1]);
|
|
EXPECT_EQ(
|
|
&model.domain().Materials()[model.activeMaterials()[2]],
|
|
&domain.Materials()[2]);
|
|
EXPECT_EQ(
|
|
&model.domain().Sections()[model.activeSections()[1]],
|
|
&domain.Sections()[1]);
|
|
EXPECT_EQ(domain.Steps()[0].name, stepName);
|
|
EXPECT_DOUBLE_EQ(domain.Steps()[0].loads[0].magnitude, firstLoadMagnitude);
|
|
}
|
|
|
|
TEST(AnalysisModel, RejectsMissingOrMultipleStep) {
|
|
auto missingDefinition = makeDefinition();
|
|
missingDefinition.steps.clear();
|
|
auto missingDomain = fesa::Domain::Create(std::move(missingDefinition));
|
|
ASSERT_TRUE(missingDomain.HasValue());
|
|
|
|
auto missing = fesa::AnalysisModel::create(missingDomain.Value());
|
|
ASSERT_FALSE(missing.HasValue());
|
|
EXPECT_EQ(
|
|
missing.GetStatus().Category(),
|
|
fesa::FailureCategory::kInput);
|
|
ASSERT_EQ(missing.GetStatus().Diagnostics().size(), 1U);
|
|
EXPECT_EQ(
|
|
missing.GetStatus().Diagnostics()[0].code,
|
|
"invalid-model-cardinality");
|
|
EXPECT_EQ(missing.GetStatus().Diagnostics()[0].keyword, "STEP");
|
|
EXPECT_EQ(missing.GetStatus().Diagnostics()[0].entity_identity, "0");
|
|
|
|
auto multipleDefinition = makeDefinition();
|
|
auto secondStep = multipleDefinition.steps.front();
|
|
secondStep.name = "Step-2";
|
|
secondStep.location.line = 60U;
|
|
multipleDefinition.steps.push_back(std::move(secondStep));
|
|
auto multipleDomain = fesa::Domain::Create(std::move(multipleDefinition));
|
|
ASSERT_TRUE(multipleDomain.HasValue());
|
|
|
|
auto multiple = fesa::AnalysisModel::create(multipleDomain.Value());
|
|
ASSERT_FALSE(multiple.HasValue());
|
|
EXPECT_EQ(
|
|
multiple.GetStatus().Category(),
|
|
fesa::FailureCategory::kInput);
|
|
ASSERT_EQ(multiple.GetStatus().Diagnostics().size(), 1U);
|
|
EXPECT_EQ(
|
|
multiple.GetStatus().Diagnostics()[0].code,
|
|
"unsupported-multiple-step");
|
|
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].keyword, "STEP");
|
|
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].entity_identity, "Step-2");
|
|
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].location.line, 60U);
|
|
}
|