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
+62 -62
View File
@@ -25,9 +25,9 @@ Status loadFailure(
const std::string& keyword,
const std::string& identity,
const std::string& message) {
return Status::failure(
FailureCategory::model,
{{Severity::error, code, location, keyword, identity, message}});
return Status::Failure(
FailureCategory::kModel,
{{Severity::kError, code, location, keyword, identity, message}});
}
char asciiLower(const char value) {
@@ -74,7 +74,7 @@ Status validateDofOrder(
if (fullCount != expectedFullCount ||
freeDofs.size() != dofs.freeDofCount() ||
constrainedDofs.size() != dofs.constrainedDofCount() ||
dofs.prescribedValues().size() != constrainedDofs.size() ||
dofs.prescribedValues().Size() != constrainedDofs.size() ||
constrainedDofs.size() > fullCount ||
freeDofs.size() != fullCount - constrainedDofs.size()) {
return loadFailure(
@@ -139,7 +139,7 @@ Status validateDofOrder(
std::to_string(fullCount),
"Free and constrained DOFs must partition the full range.");
}
return Status::ok();
return Status::Ok();
}
Result<std::vector<EntityIndex>> resolveTarget(
@@ -156,7 +156,7 @@ Result<std::vector<EntityIndex>> resolveTarget(
std::int64_t label = 0;
if (tryPositiveInteger(load.target, label)) {
for (std::size_t index = 0U; index < domain.nodes().size(); ++index) {
if (domain.nodes()[index].sourceId.sourceLabel == label) {
if (domain.nodes()[index].sourceId.source_label == label) {
matchingNodes.push_back(static_cast<EntityIndex>(index));
}
}
@@ -164,7 +164,7 @@ Result<std::vector<EntityIndex>> resolveTarget(
if (matchingSets.size() > 1U || matchingNodes.size() > 1U ||
(!matchingSets.empty() && !matchingNodes.empty())) {
return Result<std::vector<EntityIndex>>::failure(loadFailure(
return Result<std::vector<EntityIndex>>::Failure(loadFailure(
"invalid-load-target",
load.location,
"CLOAD",
@@ -176,7 +176,7 @@ Result<std::vector<EntityIndex>> resolveTarget(
std::vector<unsigned char> seen(domain.nodes().size(), 0U);
for (const EntityIndex node : nodes) {
if (node >= domain.nodes().size() || seen[node] != 0U) {
return Result<std::vector<EntityIndex>>::failure(loadFailure(
return Result<std::vector<EntityIndex>>::Failure(loadFailure(
"invalid-load-target",
load.location,
"CLOAD",
@@ -185,13 +185,13 @@ Result<std::vector<EntityIndex>> resolveTarget(
}
seen[node] = 1U;
}
return Result<std::vector<EntityIndex>>::success(nodes);
return Result<std::vector<EntityIndex>>::Success(nodes);
}
if (!matchingNodes.empty()) {
return Result<std::vector<EntityIndex>>::success(
return Result<std::vector<EntityIndex>>::Success(
std::move(matchingNodes));
}
return Result<std::vector<EntityIndex>>::failure(loadFailure(
return Result<std::vector<EntityIndex>>::Failure(loadFailure(
"invalid-load-target",
load.location,
"CLOAD",
@@ -203,7 +203,7 @@ Status validateFiniteVector(
const Vector& values,
const SourceLocation& location,
const std::string& identity) {
for (std::size_t index = 0U; index < values.size(); ++index) {
for (std::size_t index = 0U; index < values.Size(); ++index) {
if (!std::isfinite(values[index])) {
return loadFailure(
"nonfinite-load-value",
@@ -213,14 +213,14 @@ Status validateFiniteVector(
"Load and prescribed displacement vectors must contain finite values.");
}
}
return Status::ok();
return Status::Ok();
}
Status validateShellMoments(
const Domain& domain,
const Vector& fullLoad) {
if (domain.shellElements().empty()) {
return Status::ok();
return Status::Ok();
}
std::vector<const ShellNodeInitialFrame*> frameByNode(
@@ -252,7 +252,7 @@ Status validateShellMoments(
"invalid-shell-director",
domain.nodes()[node].location,
"NODE",
domain.nodes()[node].sourceId.sourceLabelText,
domain.nodes()[node].sourceId.source_label_text,
"A loaded shell node must have an approved initial director.");
}
@@ -273,11 +273,11 @@ Status validateShellMoments(
"unsupported-drilling-load",
domain.nodes()[node].location,
"CLOAD",
domain.nodes()[node].sourceId.sourceLabelText,
domain.nodes()[node].sourceId.source_label_text,
"The aggregate nodal moment has an unsupported director-parallel component.");
}
}
return Status::ok();
return Status::Ok();
}
} // namespace
@@ -288,7 +288,7 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
const Domain& domain = model.domain();
if (domain.nodes().size() >
(std::numeric_limits<std::size_t>::max)() / dofsPerNode) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"invalid-load-dimensions",
{domain.sourcePath(), 0U},
"LOAD_ASSEMBLER",
@@ -299,8 +299,8 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
domain.nodes().size() * dofsPerNode;
const Status dofStatus = validateDofOrder(
dofs, expectedFullCount, {domain.sourcePath(), 0U});
if (!dofStatus.isOk()) {
return Result<Vector>::failure(dofStatus);
if (!dofStatus.IsOk()) {
return Result<Vector>::Failure(dofStatus);
}
for (std::size_t node = 0U; node < domain.nodes().size(); ++node) {
for (std::size_t component = 0U;
@@ -311,19 +311,19 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
static_cast<EntityIndex>(node),
static_cast<DofComponent>(component)) !=
node * dofsPerNode + component) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"invalid-load-order",
domain.nodes()[node].location,
"LOAD_ASSEMBLER",
domain.nodes()[node].sourceId.sourceLabelText,
domain.nodes()[node].sourceId.source_label_text,
"DofManager node/component identity must match full-DOF order."));
}
} catch (const std::out_of_range&) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"invalid-load-dimensions",
domain.nodes()[node].location,
"LOAD_ASSEMBLER",
domain.nodes()[node].sourceId.sourceLabelText,
domain.nodes()[node].sourceId.source_label_text,
"DofManager must provide all six DOFs for every semantic node."));
}
}
@@ -332,7 +332,7 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
const auto& activeLoads = model.activeLoads();
const auto& loads = model.step().loads;
if (activeLoads.size() != loads.size()) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"invalid-load-order",
model.step().location,
"CLOAD",
@@ -349,7 +349,7 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
const EntityIndex loadIndex = activeLoads[sourceOrder];
if (static_cast<std::size_t>(loadIndex) != sourceOrder ||
loadIndex >= loads.size()) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"invalid-load-order",
model.step().location,
"CLOAD",
@@ -358,7 +358,7 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
}
const auto& load = loads[loadIndex];
if (load.dof < 1 || load.dof > static_cast<int>(dofsPerNode)) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"invalid-load-dof",
load.location,
"CLOAD",
@@ -366,7 +366,7 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
"A nodal load component must be in the range 1 through 6."));
}
if (!std::isfinite(load.magnitude)) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"nonfinite-load-value",
load.location,
"CLOAD",
@@ -375,15 +375,15 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
}
auto target = resolveTarget(domain, load);
if (!target.hasValue()) {
return Result<Vector>::failure(target.status());
if (!target.HasValue()) {
return Result<Vector>::Failure(target.GetStatus());
}
const auto component = static_cast<DofComponent>(load.dof - 1);
for (const EntityIndex node : target.value()) {
for (const EntityIndex node : target.Value()) {
const std::size_t fullDof = dofs.fullDof(node, component);
const double accumulated = fullLoad[fullDof] + load.magnitude;
if (!std::isfinite(accumulated)) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"nonfinite-load-accumulation",
load.location,
"CLOAD",
@@ -394,10 +394,10 @@ Result<Vector> LoadAssembler::assembleFullNodalLoad(
}
}
const Status shellMomentStatus = validateShellMoments(domain, fullLoad);
if (!shellMomentStatus.isOk()) {
return Result<Vector>::failure(shellMomentStatus);
if (!shellMomentStatus.IsOk()) {
return Result<Vector>::Failure(shellMomentStatus);
}
return Result<Vector>::success(std::move(fullLoad));
return Result<Vector>::Success(std::move(fullLoad));
}
Result<Vector> LoadAssembler::effectiveFreeRhs(
@@ -407,46 +407,46 @@ Result<Vector> LoadAssembler::effectiveFreeRhs(
const DofManager& dofs) {
const SourceLocation location{{}, 0U};
const Status dofStatus =
validateDofOrder(dofs, fullLoad.size(), location);
if (!dofStatus.isOk()) {
return Result<Vector>::failure(dofStatus);
validateDofOrder(dofs, fullLoad.Size(), location);
if (!dofStatus.IsOk()) {
return Result<Vector>::Failure(dofStatus);
}
if (kfc.rows() != dofs.freeDofCount() ||
kfc.columns() != dofs.constrainedDofCount() ||
prescribedValues.size() != dofs.constrainedDofCount()) {
return Result<Vector>::failure(loadFailure(
if (kfc.Rows() != dofs.freeDofCount() ||
kfc.Columns() != dofs.constrainedDofCount() ||
prescribedValues.Size() != dofs.constrainedDofCount()) {
return Result<Vector>::Failure(loadFailure(
"invalid-load-dimensions",
location,
"LOAD_ASSEMBLER",
std::to_string(kfc.rows()) + "x" +
std::to_string(kfc.columns()),
std::to_string(kfc.Rows()) + "x" +
std::to_string(kfc.Columns()),
"Kfc rows/columns and prescribed values must match free/constrained order."));
}
const Status matrixStatus = kfc.validate();
if (!matrixStatus.isOk()) {
return Result<Vector>::failure(matrixStatus);
const Status matrixStatus = kfc.Validate();
if (!matrixStatus.IsOk()) {
return Result<Vector>::Failure(matrixStatus);
}
const Status loadStatus =
validateFiniteVector(fullLoad, location, "full-load");
if (!loadStatus.isOk()) {
return Result<Vector>::failure(loadStatus);
if (!loadStatus.IsOk()) {
return Result<Vector>::Failure(loadStatus);
}
const Status prescribedStatus = validateFiniteVector(
prescribedValues, location, "prescribed-values");
if (!prescribedStatus.isOk()) {
return Result<Vector>::failure(prescribedStatus);
if (!prescribedStatus.IsOk()) {
return Result<Vector>::Failure(prescribedStatus);
}
Vector correction{kfc.rows()};
for (std::size_t row = 0U; row < kfc.rows(); ++row) {
Vector correction{kfc.Rows()};
for (std::size_t row = 0U; row < kfc.Rows(); ++row) {
double sum = 0.0;
for (std::size_t position = kfc.rowOffsets()[row];
position < kfc.rowOffsets()[row + 1U];
for (std::size_t position = kfc.RowOffsets()[row];
position < kfc.RowOffsets()[row + 1U];
++position) {
const double product = kfc.values()[position] *
prescribedValues[kfc.columnIndices()[position]];
const double product = kfc.Values()[position] *
prescribedValues[kfc.ColumnIndices()[position]];
if (!std::isfinite(product)) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"nonfinite-load-accumulation",
location,
"LOAD_ASSEMBLER",
@@ -455,7 +455,7 @@ Result<Vector> LoadAssembler::effectiveFreeRhs(
}
sum += product;
if (!std::isfinite(sum)) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"nonfinite-load-accumulation",
location,
"LOAD_ASSEMBLER",
@@ -469,10 +469,10 @@ Result<Vector> LoadAssembler::effectiveFreeRhs(
Vector rhs = EssentialConstraints::gatherFree(fullLoad, dofs);
// The constrained vector is already in DofManager order, so this is the
// approved elimination equation rhs = Ff - Kfc*dc without reordering dc.
for (std::size_t row = 0U; row < rhs.size(); ++row) {
for (std::size_t row = 0U; row < rhs.Size(); ++row) {
const double value = rhs[row] - correction[row];
if (!std::isfinite(value)) {
return Result<Vector>::failure(loadFailure(
return Result<Vector>::Failure(loadFailure(
"nonfinite-load-accumulation",
location,
"LOAD_ASSEMBLER",
@@ -481,7 +481,7 @@ Result<Vector> LoadAssembler::effectiveFreeRhs(
}
rhs[row] = value;
}
return Result<Vector>::success(std::move(rhs));
return Result<Vector>::Success(std::move(rhs));
}
} // namespace fesa
+23 -23
View File
@@ -35,9 +35,9 @@ Result<SparseMatrix> assemblyFailure(
const SourceLocation& location,
const std::string& identity,
const std::string& message) {
return Result<SparseMatrix>::failure(Status::failure(
FailureCategory::model,
{{Severity::error,
return Result<SparseMatrix>::Failure(Status::Failure(
FailureCategory::kModel,
{{Severity::kError,
code,
location,
"*ELEMENT",
@@ -112,7 +112,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
return assemblyFailure(
"invalid-assembly-element",
element.location,
element.sourceId.sourceLabelText,
element.sourceId.source_label_text,
"Shell element references an entity outside the Domain.");
}
@@ -126,7 +126,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
return assemblyFailure(
"invalid-assembly-scatter",
element.location,
element.sourceId.sourceLabelText,
element.sourceId.source_label_text,
"DofManager does not contain the active shell scatter.");
}
for (std::size_t nodePosition = 0U;
@@ -138,7 +138,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
return assemblyFailure(
"invalid-assembly-element",
element.location,
element.sourceId.sourceLabelText,
element.sourceId.source_label_text,
"Shell element requires a valid node and initial director.");
}
input.nodes[nodePosition] = &domain.nodes()[nodeIndex];
@@ -156,7 +156,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
return assemblyFailure(
"invalid-assembly-scatter",
element.location,
element.sourceId.sourceLabelText,
element.sourceId.source_label_text,
"Shell scatter does not match the active model topology.");
}
}
@@ -175,13 +175,13 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
input.directors,
*input.section,
*input.material);
if (!shell.hasValue()) {
localFailures[elementOrder] = shell.status();
if (!shell.HasValue()) {
localFailures[elementOrder] = shell.GetStatus();
return;
}
const auto stiffness = shell.value().stiffness();
if (!stiffness.hasValue()) {
localFailures[elementOrder] = stiffness.status();
const auto stiffness = shell.Value().stiffness();
if (!stiffness.HasValue()) {
localFailures[elementOrder] = stiffness.GetStatus();
return;
}
@@ -197,7 +197,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
buffer[localOrder] = {
input.scatter[localRow],
input.scatter[localColumn],
stiffness.value().stabilizedGlobal24(
stiffness.Value().stabilizedGlobal24(
localRow, localColumn),
elementOrder,
localOrder};
@@ -209,7 +209,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
elementOrder < localFailures.size();
++elementOrder) {
if (localFailures[elementOrder]) {
return Result<SparseMatrix>::failure(
return Result<SparseMatrix>::Failure(
*localFailures[elementOrder]);
}
}
@@ -223,7 +223,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
contributions.insert(
contributions.end(), buffer.begin(), buffer.end());
}
return SparseMatrix::fromCoo(
return SparseMatrix::FromCoo(
dofs.fullDofCount(),
dofs.fullDofCount(),
std::move(contributions),
@@ -258,7 +258,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
return assemblyFailure(
"invalid-assembly-element",
element.location,
element.sourceId.sourceLabelText,
element.sourceId.source_label_text,
"Element references an entity outside the Domain.");
}
@@ -269,7 +269,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
return assemblyFailure(
"invalid-assembly-scatter",
element.location,
element.sourceId.sourceLabelText,
element.sourceId.source_label_text,
"DofManager does not contain the active element scatter.");
}
for (std::size_t endpoint = 0U; endpoint < 2U; ++endpoint) {
@@ -286,7 +286,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
return assemblyFailure(
"invalid-assembly-scatter",
element.location,
element.sourceId.sourceLabelText,
element.sourceId.source_label_text,
"Element scatter does not match the active model topology.");
}
}
@@ -307,12 +307,12 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
domain.nodes()[definition.nodeIndices[1U]],
domain.sections()[definition.sectionIndex],
domain.materials()[definition.materialIndex]);
if (!beam.hasValue()) {
localFailures[elementOrder] = beam.status();
if (!beam.HasValue()) {
localFailures[elementOrder] = beam.GetStatus();
return;
}
const Matrix stiffness = beam.value().globalStiffness();
const Matrix stiffness = beam.Value().globalStiffness();
auto& buffer = localBuffers[elementOrder];
const auto& scatter = scatters[elementOrder];
for (std::size_t localRow = 0U;
@@ -337,7 +337,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
elementOrder < localFailures.size();
++elementOrder) {
if (localFailures[elementOrder]) {
return Result<SparseMatrix>::failure(
return Result<SparseMatrix>::Failure(
*localFailures[elementOrder]);
}
}
@@ -350,7 +350,7 @@ Result<SparseMatrix> SparseAssembler::assembleStiffness(
contributions.insert(
contributions.end(), buffer.begin(), buffer.end());
}
return SparseMatrix::fromCoo(
return SparseMatrix::FromCoo(
dofs.fullDofCount(),
dofs.fullDofCount(),
std::move(contributions),