207 lines
8.5 KiB
C++
207 lines
8.5 KiB
C++
#include "fesa/analysis/analysis_model.h"
|
|
|
|
#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;
|
|
}
|
|
|
|
fesa::ModelDefinition MakeMixedDefinition() {
|
|
auto definition = MakeDefinition();
|
|
const auto source = definition.source_path;
|
|
definition.shell_sections = {{"ShellSection", 0.01, 1U, {source, 35U}}};
|
|
definition.shell_elements = {{{"Shell-1", 5, "5"},
|
|
fesa::ShellSourceElementType::kS4,
|
|
{0U, 1U, 2U, 3U},
|
|
1U,
|
|
0U,
|
|
{source, 45U}}};
|
|
return definition;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(AnalysisModel, ClassifiesActiveEntitiesInStableOrder) {
|
|
auto domain_result = fesa::Domain::Create(MakeDefinition());
|
|
ASSERT_TRUE(domain_result.HasValue());
|
|
|
|
auto model_result = fesa::AnalysisModel::Create(domain_result.Value());
|
|
ASSERT_TRUE(model_result.HasValue());
|
|
const auto& model = model_result.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}));
|
|
ASSERT_EQ(model.Step().Loads().size(), 3U);
|
|
EXPECT_EQ(&model.Step().Loads()[0U].get(),
|
|
&domain_result.Value().Steps()[0U].Loads()[0U].get());
|
|
}
|
|
|
|
TEST(AnalysisModel, ReferencesWithoutCopyingOrMutatingDomain) {
|
|
auto domain_result = fesa::Domain::Create(MakeDefinition());
|
|
ASSERT_TRUE(domain_result.HasValue());
|
|
const fesa::Domain& domain = domain_result.Value();
|
|
const auto* const element_address = &domain.Elements()[0U];
|
|
const auto* const material_address = &domain.Materials()[0U];
|
|
const auto* const section_address = &domain.Sections()[0U];
|
|
const std::string step_name = domain.Steps()[0].Name();
|
|
const double first_load_magnitude =
|
|
domain.Steps()[0].ConcentratedLoads()[0U].GlobalComponents()[0U];
|
|
|
|
auto model_result = fesa::AnalysisModel::Create(domain);
|
|
ASSERT_TRUE(model_result.HasValue());
|
|
const auto& model = model_result.Value();
|
|
|
|
EXPECT_EQ(&model.GetDomain(), &domain);
|
|
EXPECT_EQ(&model.Step(), &domain.Steps()[0]);
|
|
EXPECT_EQ(&model.GetDomain().Elements()[0U], element_address);
|
|
EXPECT_EQ(&model.GetDomain().Materials()[0U], material_address);
|
|
EXPECT_EQ(&model.GetDomain().Sections()[0U], section_address);
|
|
EXPECT_EQ(&model.GetDomain().Elements()[model.ActiveElements()[1]],
|
|
&domain.Elements()[1]);
|
|
EXPECT_EQ(&model.GetDomain().Materials()[model.ActiveMaterials()[2]],
|
|
&domain.Materials()[2]);
|
|
EXPECT_EQ(&model.GetDomain().Sections()[model.ActiveSections()[1]],
|
|
&domain.Sections()[1]);
|
|
EXPECT_EQ(domain.Steps()[0].Name(), step_name);
|
|
EXPECT_DOUBLE_EQ(
|
|
domain.Steps()[0].ConcentratedLoads()[0U].GlobalComponents()[0U],
|
|
first_load_magnitude);
|
|
}
|
|
|
|
// C-MODEL-002
|
|
TEST(AnalysisModel, KeepsNonOwningMixedDefinitionAndPropertyIndices) {
|
|
auto domain_result = fesa::Domain::Create(MakeMixedDefinition());
|
|
ASSERT_TRUE(domain_result.HasValue());
|
|
const fesa::Domain& domain = domain_result.Value();
|
|
|
|
auto model_result = fesa::AnalysisModel::Create(domain);
|
|
ASSERT_TRUE(model_result.HasValue());
|
|
const fesa::AnalysisModel& model = model_result.Value();
|
|
|
|
EXPECT_EQ(&model.GetDomain(), &domain);
|
|
EXPECT_EQ(model.ActiveElements(),
|
|
(std::vector<fesa::EntityIndex>{0U, 1U, 2U, 3U, 4U}));
|
|
EXPECT_EQ(model.ActiveMaterials(),
|
|
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
|
EXPECT_EQ(model.ActiveProperties(),
|
|
(std::vector<fesa::EntityIndex>{0U, 1U, 2U, 4U}));
|
|
EXPECT_EQ(&model.GetDomain().Elements()[model.ActiveElements()[4U]],
|
|
&domain.Elements()[4U]);
|
|
EXPECT_EQ(&model.GetDomain().Materials()[model.ActiveMaterials()[1U]],
|
|
&domain.Materials()[1U]);
|
|
EXPECT_EQ(&model.GetDomain().Properties()[model.ActiveProperties()[3U]],
|
|
&domain.Properties()[4U]);
|
|
}
|
|
|
|
TEST(AnalysisModel, RejectsMissingOrMultipleStep) {
|
|
auto missing_definition = MakeDefinition();
|
|
missing_definition.steps.clear();
|
|
auto missing_domain = fesa::Domain::Create(std::move(missing_definition));
|
|
ASSERT_TRUE(missing_domain.HasValue());
|
|
|
|
auto missing = fesa::AnalysisModel::Create(missing_domain.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 multiple_definition = MakeDefinition();
|
|
auto second_step = multiple_definition.steps.front();
|
|
second_step.name = "Step-2";
|
|
second_step.location.line = 60U;
|
|
multiple_definition.steps.push_back(std::move(second_step));
|
|
auto multiple_domain = fesa::Domain::Create(std::move(multiple_definition));
|
|
ASSERT_TRUE(multiple_domain.HasValue());
|
|
|
|
auto multiple = fesa::AnalysisModel::Create(multiple_domain.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);
|
|
}
|