feat(cpp-object-oriented-modular-refactoring): step 3 - foundation-google-style

This commit is contained in:
KOKO\Mimi
2026-08-16 04:26:14 +09:00
parent 2628ed3488
commit 042edadffb
93 changed files with 3144 additions and 3175 deletions
@@ -34,12 +34,12 @@ fesa::DofManager makeDofs(
{source, 10U}}};
auto domain = fesa::Domain::create(std::move(definition));
EXPECT_TRUE(domain.hasValue());
auto model = fesa::AnalysisModel::create(domain.value());
EXPECT_TRUE(model.hasValue());
auto dofs = fesa::DofManager::create(model.value());
EXPECT_TRUE(dofs.hasValue());
return std::move(dofs.value());
EXPECT_TRUE(domain.HasValue());
auto model = fesa::AnalysisModel::create(domain.Value());
EXPECT_TRUE(model.HasValue());
auto dofs = fesa::DofManager::create(model.Value());
EXPECT_TRUE(dofs.HasValue());
return std::move(dofs.Value());
}
fesa::DofManager makeShellSizedDofs(
@@ -75,12 +75,12 @@ fesa::DofManager makeShellSizedDofs(
{source, 10U}}};
auto domain = fesa::Domain::create(std::move(definition));
EXPECT_TRUE(domain.hasValue());
auto model = fesa::AnalysisModel::create(domain.value());
EXPECT_TRUE(model.hasValue());
auto dofs = fesa::DofManager::create(model.value());
EXPECT_TRUE(dofs.hasValue());
return std::move(dofs.value());
EXPECT_TRUE(domain.HasValue());
auto model = fesa::AnalysisModel::create(domain.Value());
EXPECT_TRUE(model.HasValue());
auto dofs = fesa::DofManager::create(model.Value());
EXPECT_TRUE(dofs.HasValue());
return std::move(dofs.Value());
}
fesa::SparseMatrix makeMatrix(
@@ -105,10 +105,10 @@ fesa::SparseMatrix makeMatrix(
pattern.rowOffsets.push_back(pattern.columnIndices.size());
}
auto matrix = fesa::SparseMatrix::fromCoo(
auto matrix = fesa::SparseMatrix::FromCoo(
rows, columns, std::move(contributions), pattern);
EXPECT_TRUE(matrix.hasValue());
return std::move(matrix.value());
EXPECT_TRUE(matrix.HasValue());
return std::move(matrix.Value());
}
std::vector<double> sequentialDense(const std::size_t size) {
@@ -126,9 +126,9 @@ void expectShape(
const fesa::SparseMatrix& matrix,
const std::size_t rows,
const std::size_t columns) {
EXPECT_EQ(matrix.rows(), rows);
EXPECT_EQ(matrix.columns(), columns);
EXPECT_TRUE(matrix.validate().isOk());
EXPECT_EQ(matrix.Rows(), rows);
EXPECT_EQ(matrix.Columns(), columns);
EXPECT_TRUE(matrix.Validate().IsOk());
}
} // namespace
@@ -142,45 +142,45 @@ TEST(EssentialConstraints, ExtractsHandComputedBlocksInStableOrder) {
const auto full = makeMatrix(6U, 6U, fullValues);
auto result = fesa::EssentialConstraints::partition(full, dofs);
ASSERT_TRUE(result.hasValue());
const auto& blocks = result.value();
ASSERT_TRUE(result.HasValue());
const auto& blocks = result.Value();
EXPECT_EQ(blocks.kff.rowOffsets(), (std::vector<std::size_t>{0U, 4U, 8U, 12U, 16U}));
EXPECT_EQ(blocks.kff.RowOffsets(), (std::vector<std::size_t>{0U, 4U, 8U, 12U, 16U}));
EXPECT_EQ(
blocks.kff.columnIndices(),
blocks.kff.ColumnIndices(),
(std::vector<std::size_t>{
0U, 1U, 2U, 3U, 0U, 1U, 2U, 3U,
0U, 1U, 2U, 3U, 0U, 1U, 2U, 3U}));
EXPECT_EQ(
blocks.kff.values(),
blocks.kff.Values(),
(std::vector<double>{
1.0, 3.0, 4.0, 6.0,
21.0, 23.0, 24.0, 26.0,
31.0, 33.0, 34.0, 36.0,
51.0, 53.0, 54.0, 56.0}));
EXPECT_EQ(blocks.kfc.rowOffsets(), (std::vector<std::size_t>{0U, 2U, 4U, 6U, 8U}));
EXPECT_EQ(blocks.kfc.RowOffsets(), (std::vector<std::size_t>{0U, 2U, 4U, 6U, 8U}));
EXPECT_EQ(
blocks.kfc.columnIndices(),
blocks.kfc.ColumnIndices(),
(std::vector<std::size_t>{0U, 1U, 0U, 1U, 0U, 1U, 0U, 1U}));
EXPECT_EQ(
blocks.kfc.values(),
blocks.kfc.Values(),
(std::vector<double>{2.0, 5.0, 22.0, 0.0, 32.0, 35.0, 52.0, 55.0}));
EXPECT_EQ(blocks.kcf.rowOffsets(), (std::vector<std::size_t>{0U, 4U, 8U}));
EXPECT_EQ(blocks.kcf.RowOffsets(), (std::vector<std::size_t>{0U, 4U, 8U}));
EXPECT_EQ(
blocks.kcf.columnIndices(),
blocks.kcf.ColumnIndices(),
(std::vector<std::size_t>{0U, 1U, 2U, 3U, 0U, 1U, 2U, 3U}));
EXPECT_EQ(
blocks.kcf.values(),
blocks.kcf.Values(),
(std::vector<double>{11.0, 13.0, 14.0, 16.0, 41.0, 43.0, 44.0, 46.0}));
EXPECT_EQ(blocks.kcc.rowOffsets(), (std::vector<std::size_t>{0U, 2U, 4U}));
EXPECT_EQ(blocks.kcc.columnIndices(), (std::vector<std::size_t>{0U, 1U, 0U, 1U}));
EXPECT_EQ(blocks.kcc.values(), (std::vector<double>{12.0, 15.0, 42.0, 45.0}));
EXPECT_EQ(blocks.kcc.RowOffsets(), (std::vector<std::size_t>{0U, 2U, 4U}));
EXPECT_EQ(blocks.kcc.ColumnIndices(), (std::vector<std::size_t>{0U, 1U, 0U, 1U}));
EXPECT_EQ(blocks.kcc.Values(), (std::vector<double>{12.0, 15.0, 42.0, 45.0}));
EXPECT_EQ(blocks.kfc.values()[3U], 0.0);
EXPECT_TRUE(blocks.kff.validate().isOk());
EXPECT_TRUE(blocks.kfc.validate().isOk());
EXPECT_TRUE(blocks.kcf.validate().isOk());
EXPECT_TRUE(blocks.kcc.validate().isOk());
EXPECT_EQ(blocks.kfc.Values()[3U], 0.0);
EXPECT_TRUE(blocks.kff.Validate().IsOk());
EXPECT_TRUE(blocks.kfc.Validate().IsOk());
EXPECT_TRUE(blocks.kcf.Validate().IsOk());
EXPECT_TRUE(blocks.kcc.Validate().IsOk());
}
TEST(EssentialConstraints, HandlesNoAllAndMixedConstraints) {
@@ -188,29 +188,29 @@ TEST(EssentialConstraints, HandlesNoAllAndMixedConstraints) {
const auto noConstraints = makeDofs({});
auto none = fesa::EssentialConstraints::partition(full, noConstraints);
ASSERT_TRUE(none.hasValue());
expectShape(none.value().kff, 6U, 6U);
expectShape(none.value().kfc, 6U, 0U);
expectShape(none.value().kcf, 0U, 6U);
expectShape(none.value().kcc, 0U, 0U);
EXPECT_EQ(none.value().kff.values(), full.values());
ASSERT_TRUE(none.HasValue());
expectShape(none.Value().kff, 6U, 6U);
expectShape(none.Value().kfc, 6U, 0U);
expectShape(none.Value().kcf, 0U, 6U);
expectShape(none.Value().kcc, 0U, 0U);
EXPECT_EQ(none.Value().kff.Values(), full.Values());
const auto allConstraints = makeDofs({{"1", 1, 6, 1.0, {{}, 12U}}});
auto all = fesa::EssentialConstraints::partition(full, allConstraints);
ASSERT_TRUE(all.hasValue());
expectShape(all.value().kff, 0U, 0U);
expectShape(all.value().kfc, 0U, 6U);
expectShape(all.value().kcf, 6U, 0U);
expectShape(all.value().kcc, 6U, 6U);
EXPECT_EQ(all.value().kcc.values(), full.values());
ASSERT_TRUE(all.HasValue());
expectShape(all.Value().kff, 0U, 0U);
expectShape(all.Value().kfc, 0U, 6U);
expectShape(all.Value().kcf, 6U, 0U);
expectShape(all.Value().kcc, 6U, 6U);
EXPECT_EQ(all.Value().kcc.Values(), full.Values());
const auto mixedConstraints = makeDofs({{"1", 3, 4, 0.0, {{}, 12U}}});
auto mixed = fesa::EssentialConstraints::partition(full, mixedConstraints);
ASSERT_TRUE(mixed.hasValue());
expectShape(mixed.value().kff, 4U, 4U);
expectShape(mixed.value().kfc, 4U, 2U);
expectShape(mixed.value().kcf, 2U, 4U);
expectShape(mixed.value().kcc, 2U, 2U);
ASSERT_TRUE(mixed.HasValue());
expectShape(mixed.Value().kff, 4U, 4U);
expectShape(mixed.Value().kfc, 4U, 2U);
expectShape(mixed.Value().kcf, 2U, 4U);
expectShape(mixed.Value().kcc, 2U, 2U);
}
// MITC4-DOF-003
@@ -219,24 +219,24 @@ TEST(EssentialConstraints, PreservesShellSizedNoMixedAndAllConstraintRoundTrips)
const auto noConstraints = makeShellSizedDofs({});
auto none = fesa::EssentialConstraints::partition(full, noConstraints);
ASSERT_TRUE(none.hasValue());
expectShape(none.value().kff, 24U, 24U);
expectShape(none.value().kfc, 24U, 0U);
expectShape(none.value().kcf, 0U, 24U);
expectShape(none.value().kcc, 0U, 0U);
ASSERT_TRUE(none.HasValue());
expectShape(none.Value().kff, 24U, 24U);
expectShape(none.Value().kfc, 24U, 0U);
expectShape(none.Value().kcf, 0U, 24U);
expectShape(none.Value().kcc, 0U, 0U);
const auto mixedConstraints = makeShellSizedDofs({
{"1", 1, 6, 0.0, {{}, 12U}},
{"4", 2, 2, 2.5, {{}, 13U}}});
auto mixed = fesa::EssentialConstraints::partition(full, mixedConstraints);
ASSERT_TRUE(mixed.hasValue());
expectShape(mixed.value().kff, 17U, 17U);
expectShape(mixed.value().kfc, 17U, 7U);
expectShape(mixed.value().kcf, 7U, 17U);
expectShape(mixed.value().kcc, 7U, 7U);
ASSERT_TRUE(mixed.HasValue());
expectShape(mixed.Value().kff, 17U, 17U);
expectShape(mixed.Value().kfc, 17U, 7U);
expectShape(mixed.Value().kcf, 7U, 17U);
expectShape(mixed.Value().kcc, 7U, 7U);
fesa::Vector mixedFull{24U};
for (std::size_t index = 0U; index < mixedFull.size(); ++index) {
for (std::size_t index = 0U; index < mixedFull.Size(); ++index) {
mixedFull[index] = static_cast<double>(index) + 0.5;
}
for (std::size_t index = 0U;
@@ -250,8 +250,8 @@ TEST(EssentialConstraints, PreservesShellSizedNoMixedAndAllConstraintRoundTrips)
const auto mixedReconstructed =
fesa::EssentialConstraints::reconstructFull(
mixedFree, mixedConstraints.prescribedValues(), mixedConstraints);
ASSERT_EQ(mixedReconstructed.size(), mixedFull.size());
for (std::size_t index = 0U; index < mixedFull.size(); ++index) {
ASSERT_EQ(mixedReconstructed.Size(), mixedFull.Size());
for (std::size_t index = 0U; index < mixedFull.Size(); ++index) {
EXPECT_DOUBLE_EQ(mixedReconstructed[index], mixedFull[index]);
}
@@ -261,18 +261,18 @@ TEST(EssentialConstraints, PreservesShellSizedNoMixedAndAllConstraintRoundTrips)
{"3", 1, 6, 3.0, {{}, 16U}},
{"4", 1, 6, 4.0, {{}, 17U}}});
auto all = fesa::EssentialConstraints::partition(full, allConstraints);
ASSERT_TRUE(all.hasValue());
expectShape(all.value().kff, 0U, 0U);
expectShape(all.value().kfc, 0U, 24U);
expectShape(all.value().kcf, 24U, 0U);
expectShape(all.value().kcc, 24U, 24U);
ASSERT_TRUE(all.HasValue());
expectShape(all.Value().kff, 0U, 0U);
expectShape(all.Value().kfc, 0U, 24U);
expectShape(all.Value().kcf, 24U, 0U);
expectShape(all.Value().kcc, 24U, 24U);
const auto allReconstructed =
fesa::EssentialConstraints::reconstructFull(
fesa::Vector{0U},
allConstraints.prescribedValues(),
allConstraints);
ASSERT_EQ(allReconstructed.size(), 24U);
ASSERT_EQ(allReconstructed.Size(), 24U);
for (std::size_t node = 0U; node < 4U; ++node) {
for (std::size_t component = 0U; component < 6U; ++component) {
EXPECT_DOUBLE_EQ(allReconstructed[node * 6U + component], node + 1.0);
@@ -295,12 +295,12 @@ TEST(EssentialConstraints, ReconstructsNonzeroPrescribedValues) {
const auto free = fesa::EssentialConstraints::gatherFree(full, dofs);
const auto constrained =
fesa::EssentialConstraints::gatherConstrained(full, dofs);
EXPECT_EQ(free.size(), 4U);
EXPECT_EQ(free.Size(), 4U);
EXPECT_DOUBLE_EQ(free[0U], 10.0);
EXPECT_DOUBLE_EQ(free[1U], 20.0);
EXPECT_DOUBLE_EQ(free[2U], 30.0);
EXPECT_DOUBLE_EQ(free[3U], 40.0);
EXPECT_EQ(constrained.size(), 2U);
EXPECT_EQ(constrained.Size(), 2U);
EXPECT_DOUBLE_EQ(constrained[0U], 2.5);
EXPECT_DOUBLE_EQ(constrained[1U], -3.25);
EXPECT_EQ(constrained[0U], dofs.prescribedValues()[0U]);
@@ -308,8 +308,8 @@ TEST(EssentialConstraints, ReconstructsNonzeroPrescribedValues) {
const auto reconstructed = fesa::EssentialConstraints::reconstructFull(
free, dofs.prescribedValues(), dofs);
ASSERT_EQ(reconstructed.size(), full.size());
for (std::size_t index = 0U; index < full.size(); ++index) {
ASSERT_EQ(reconstructed.Size(), full.Size());
for (std::size_t index = 0U; index < full.Size(); ++index) {
EXPECT_DOUBLE_EQ(reconstructed[index], full[index]);
}
}
@@ -319,21 +319,21 @@ TEST(EssentialConstraints, RejectsDimensionOrOrderMismatch) {
const auto wrongSquare = makeMatrix(5U, 5U, sequentialDense(5U));
auto wrongDimension =
fesa::EssentialConstraints::partition(wrongSquare, dofs);
ASSERT_FALSE(wrongDimension.hasValue());
ASSERT_FALSE(wrongDimension.HasValue());
EXPECT_EQ(
wrongDimension.status().failureCategory(),
fesa::FailureCategory::model);
ASSERT_EQ(wrongDimension.status().diagnostics().size(), 1U);
wrongDimension.GetStatus().Category(),
fesa::FailureCategory::kModel);
ASSERT_EQ(wrongDimension.GetStatus().Diagnostics().size(), 1U);
EXPECT_EQ(
wrongDimension.status().diagnostics()[0U].code,
wrongDimension.GetStatus().Diagnostics()[0U].code,
"invalid-constraint-dimensions");
const auto rectangular = makeMatrix(
6U, 5U, std::vector<double>(30U, 0.0));
auto wrongOrder = fesa::EssentialConstraints::partition(rectangular, dofs);
ASSERT_FALSE(wrongOrder.hasValue());
ASSERT_FALSE(wrongOrder.HasValue());
EXPECT_EQ(
wrongOrder.status().diagnostics()[0U].code,
wrongOrder.GetStatus().Diagnostics()[0U].code,
"invalid-constraint-dimensions");
EXPECT_THROW(