feat(cpp-object-oriented-modular-refactoring): step 3 - foundation-google-style
This commit is contained in:
@@ -16,9 +16,9 @@ Status constraintFailure(
|
||||
const std::string& code,
|
||||
const std::string& identity,
|
||||
const std::string& message) {
|
||||
return Status::failure(
|
||||
FailureCategory::model,
|
||||
{{Severity::error,
|
||||
return Status::Failure(
|
||||
FailureCategory::kModel,
|
||||
{{Severity::kError,
|
||||
code,
|
||||
{{}, 0U},
|
||||
"ESSENTIAL_CONSTRAINTS",
|
||||
@@ -41,7 +41,7 @@ Status validateDofOrder(const DofManager& dofs) {
|
||||
const auto& constrainedDofs = dofs.constrainedDofs();
|
||||
if (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 constraintFailure(
|
||||
@@ -94,7 +94,7 @@ Status validateDofOrder(const DofManager& dofs) {
|
||||
std::to_string(fullCount),
|
||||
"Free and constrained DOFs must partition the complete full-DOF range.");
|
||||
}
|
||||
return Status::ok();
|
||||
return Status::Ok();
|
||||
}
|
||||
|
||||
Result<SparseMatrix> extractBlock(
|
||||
@@ -102,7 +102,7 @@ Result<SparseMatrix> extractBlock(
|
||||
const std::vector<std::size_t>& rowDofs,
|
||||
const std::vector<std::size_t>& columnDofs) {
|
||||
const std::size_t absent = (std::numeric_limits<std::size_t>::max)();
|
||||
std::vector<std::size_t> localColumn(full.columns(), absent);
|
||||
std::vector<std::size_t> localColumn(full.Columns(), absent);
|
||||
for (std::size_t column = 0U; column < columnDofs.size(); ++column) {
|
||||
localColumn[columnDofs[column]] = column;
|
||||
}
|
||||
@@ -111,16 +111,16 @@ Result<SparseMatrix> extractBlock(
|
||||
pattern.rowOffsets.reserve(rowDofs.size() + 1U);
|
||||
pattern.rowOffsets.push_back(0U);
|
||||
std::vector<CooContribution> contributions;
|
||||
contributions.reserve(full.values().size());
|
||||
contributions.reserve(full.Values().size());
|
||||
for (std::size_t localRow = 0U;
|
||||
localRow < rowDofs.size();
|
||||
++localRow) {
|
||||
const std::size_t fullRow = rowDofs[localRow];
|
||||
for (std::size_t position = full.rowOffsets()[fullRow];
|
||||
position < full.rowOffsets()[fullRow + 1U];
|
||||
for (std::size_t position = full.RowOffsets()[fullRow];
|
||||
position < full.RowOffsets()[fullRow + 1U];
|
||||
++position) {
|
||||
const std::size_t column =
|
||||
localColumn[full.columnIndices()[position]];
|
||||
localColumn[full.ColumnIndices()[position]];
|
||||
if (column == absent) {
|
||||
continue;
|
||||
}
|
||||
@@ -130,13 +130,13 @@ Result<SparseMatrix> extractBlock(
|
||||
contributions.push_back({
|
||||
localRow,
|
||||
column,
|
||||
full.values()[position],
|
||||
full.Values()[position],
|
||||
localRow,
|
||||
position});
|
||||
}
|
||||
pattern.rowOffsets.push_back(pattern.columnIndices.size());
|
||||
}
|
||||
return SparseMatrix::fromCoo(
|
||||
return SparseMatrix::FromCoo(
|
||||
rowDofs.size(),
|
||||
columnDofs.size(),
|
||||
std::move(contributions),
|
||||
@@ -144,7 +144,7 @@ Result<SparseMatrix> extractBlock(
|
||||
}
|
||||
|
||||
void requireDofOrder(const DofManager& dofs) {
|
||||
if (!validateDofOrder(dofs).isOk()) {
|
||||
if (!validateDofOrder(dofs).IsOk()) {
|
||||
throw std::invalid_argument{
|
||||
"DofManager constraint dimensions or order are invalid."};
|
||||
}
|
||||
@@ -155,53 +155,53 @@ void requireDofOrder(const DofManager& dofs) {
|
||||
Result<PartitionedStiffness> EssentialConstraints::partition(
|
||||
const SparseMatrix& full,
|
||||
const DofManager& dofs) {
|
||||
const Status matrixStatus = full.validate();
|
||||
if (!matrixStatus.isOk()) {
|
||||
return Result<PartitionedStiffness>::failure(matrixStatus);
|
||||
const Status matrixStatus = full.Validate();
|
||||
if (!matrixStatus.IsOk()) {
|
||||
return Result<PartitionedStiffness>::Failure(matrixStatus);
|
||||
}
|
||||
if (full.rows() != full.columns() ||
|
||||
full.rows() != dofs.fullDofCount()) {
|
||||
return Result<PartitionedStiffness>::failure(constraintFailure(
|
||||
if (full.Rows() != full.Columns() ||
|
||||
full.Rows() != dofs.fullDofCount()) {
|
||||
return Result<PartitionedStiffness>::Failure(constraintFailure(
|
||||
"invalid-constraint-dimensions",
|
||||
std::to_string(full.rows()) + "x" +
|
||||
std::to_string(full.columns()),
|
||||
std::to_string(full.Rows()) + "x" +
|
||||
std::to_string(full.Columns()),
|
||||
"Full stiffness must be square and match the DofManager full dimension."));
|
||||
}
|
||||
const Status dofStatus = validateDofOrder(dofs);
|
||||
if (!dofStatus.isOk()) {
|
||||
return Result<PartitionedStiffness>::failure(dofStatus);
|
||||
if (!dofStatus.IsOk()) {
|
||||
return Result<PartitionedStiffness>::Failure(dofStatus);
|
||||
}
|
||||
|
||||
auto kff = extractBlock(full, dofs.freeDofs(), dofs.freeDofs());
|
||||
if (!kff.hasValue()) {
|
||||
return Result<PartitionedStiffness>::failure(kff.status());
|
||||
if (!kff.HasValue()) {
|
||||
return Result<PartitionedStiffness>::Failure(kff.GetStatus());
|
||||
}
|
||||
auto kfc = extractBlock(full, dofs.freeDofs(), dofs.constrainedDofs());
|
||||
if (!kfc.hasValue()) {
|
||||
return Result<PartitionedStiffness>::failure(kfc.status());
|
||||
if (!kfc.HasValue()) {
|
||||
return Result<PartitionedStiffness>::Failure(kfc.GetStatus());
|
||||
}
|
||||
auto kcf = extractBlock(full, dofs.constrainedDofs(), dofs.freeDofs());
|
||||
if (!kcf.hasValue()) {
|
||||
return Result<PartitionedStiffness>::failure(kcf.status());
|
||||
if (!kcf.HasValue()) {
|
||||
return Result<PartitionedStiffness>::Failure(kcf.GetStatus());
|
||||
}
|
||||
auto kcc = extractBlock(
|
||||
full, dofs.constrainedDofs(), dofs.constrainedDofs());
|
||||
if (!kcc.hasValue()) {
|
||||
return Result<PartitionedStiffness>::failure(kcc.status());
|
||||
if (!kcc.HasValue()) {
|
||||
return Result<PartitionedStiffness>::Failure(kcc.GetStatus());
|
||||
}
|
||||
|
||||
return Result<PartitionedStiffness>::success({
|
||||
std::move(kff.value()),
|
||||
std::move(kfc.value()),
|
||||
std::move(kcf.value()),
|
||||
std::move(kcc.value())});
|
||||
return Result<PartitionedStiffness>::Success({
|
||||
std::move(kff.Value()),
|
||||
std::move(kfc.Value()),
|
||||
std::move(kcf.Value()),
|
||||
std::move(kcc.Value())});
|
||||
}
|
||||
|
||||
Vector EssentialConstraints::gatherFree(
|
||||
const Vector& full,
|
||||
const DofManager& dofs) {
|
||||
requireDofOrder(dofs);
|
||||
if (full.size() != dofs.fullDofCount()) {
|
||||
if (full.Size() != dofs.fullDofCount()) {
|
||||
throw std::invalid_argument{
|
||||
"Full vector size must match the DofManager full dimension."};
|
||||
}
|
||||
@@ -218,7 +218,7 @@ Vector EssentialConstraints::gatherConstrained(
|
||||
const Vector& full,
|
||||
const DofManager& dofs) {
|
||||
requireDofOrder(dofs);
|
||||
if (full.size() != dofs.fullDofCount()) {
|
||||
if (full.Size() != dofs.fullDofCount()) {
|
||||
throw std::invalid_argument{
|
||||
"Full vector size must match the DofManager full dimension."};
|
||||
}
|
||||
@@ -236,8 +236,8 @@ Vector EssentialConstraints::reconstructFull(
|
||||
const Vector& constrainedValues,
|
||||
const DofManager& dofs) {
|
||||
requireDofOrder(dofs);
|
||||
if (freeValues.size() != dofs.freeDofCount() ||
|
||||
constrainedValues.size() != dofs.constrainedDofCount()) {
|
||||
if (freeValues.Size() != dofs.freeDofCount() ||
|
||||
constrainedValues.Size() != dofs.constrainedDofCount()) {
|
||||
throw std::invalid_argument{
|
||||
"Reduced vector sizes must match the DofManager order."};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user