feat(cpp-object-oriented-modular-refactoring): step 5 - solver-workflow-google-style
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/analysis/analysis_model.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -9,146 +9,154 @@
|
||||
|
||||
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 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
|
||||
} // namespace
|
||||
|
||||
TEST(AnalysisModel, ClassifiesActiveEntitiesInStableOrder) {
|
||||
auto domainResult = fesa::Domain::Create(makeDefinition());
|
||||
ASSERT_TRUE(domainResult.HasValue());
|
||||
auto domain_result = fesa::Domain::Create(MakeDefinition());
|
||||
ASSERT_TRUE(domain_result.HasValue());
|
||||
|
||||
auto modelResult = fesa::AnalysisModel::create(domainResult.Value());
|
||||
ASSERT_TRUE(modelResult.HasValue());
|
||||
const auto& model = modelResult.Value();
|
||||
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}));
|
||||
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 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().data();
|
||||
const auto* const material_address = domain.Materials().data();
|
||||
const auto* const section_address = domain.Sections().data();
|
||||
const std::string step_name = domain.Steps()[0].name;
|
||||
const double first_load_magnitude = domain.Steps()[0].loads[0].magnitude;
|
||||
|
||||
auto modelResult = fesa::AnalysisModel::create(domain);
|
||||
ASSERT_TRUE(modelResult.HasValue());
|
||||
const auto& model = modelResult.Value();
|
||||
auto model_result = fesa::AnalysisModel::Create(domain);
|
||||
ASSERT_TRUE(model_result.HasValue());
|
||||
const auto& model = model_result.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);
|
||||
EXPECT_EQ(&model.GetDomain(), &domain);
|
||||
EXPECT_EQ(&model.Step(), &domain.Steps()[0]);
|
||||
EXPECT_EQ(model.GetDomain().Elements().data(), element_address);
|
||||
EXPECT_EQ(model.GetDomain().Materials().data(), material_address);
|
||||
EXPECT_EQ(model.GetDomain().Sections().data(), 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].loads[0].magnitude, first_load_magnitude);
|
||||
}
|
||||
|
||||
TEST(AnalysisModel, RejectsMissingOrMultipleStep) {
|
||||
auto missingDefinition = makeDefinition();
|
||||
missingDefinition.steps.clear();
|
||||
auto missingDomain = fesa::Domain::Create(std::move(missingDefinition));
|
||||
ASSERT_TRUE(missingDomain.HasValue());
|
||||
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(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 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 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_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(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);
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user