feat(cpp-object-oriented-modular-refactoring): step 3 - foundation-google-style
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "fesa/io/hdf5/hdf5_results_writer.hpp"
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/build_info.hpp"
|
||||
#include "fesa/build_info.h"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
|
||||
#include <hdf5.h>
|
||||
@@ -153,9 +153,9 @@ hid_t requireHdf5Id(const hid_t result, const char* message) {
|
||||
}
|
||||
|
||||
Status outputFailure(const std::string& code, const std::string& message) {
|
||||
return Status::failure(
|
||||
FailureCategory::output,
|
||||
{{Severity::error, code, {}, "", "", message}});
|
||||
return Status::Failure(
|
||||
FailureCategory::kOutput,
|
||||
{{Severity::kError, code, {}, "", "", message}});
|
||||
}
|
||||
|
||||
bool isFinite(const std::array<double, 3>& values) {
|
||||
@@ -217,9 +217,9 @@ bool isValidUtf8(const std::string& value) {
|
||||
}
|
||||
|
||||
bool sameIdentity(const SourceEntityId& left, const SourceEntityId& right) {
|
||||
return left.instanceName == right.instanceName &&
|
||||
left.sourceLabel == right.sourceLabel &&
|
||||
left.sourceLabelText == right.sourceLabelText;
|
||||
return left.instance_name == right.instance_name &&
|
||||
left.source_label == right.source_label &&
|
||||
left.source_label_text == right.source_label_text;
|
||||
}
|
||||
|
||||
using AxisSet = std::array<double, 9>;
|
||||
@@ -346,10 +346,10 @@ Status validateShellWriterInput(
|
||||
for (const auto& element : domain.shellElements()) {
|
||||
if ((element.sourceType != ShellSourceElementType::s4 &&
|
||||
element.sourceType != ShellSourceElementType::s4r) ||
|
||||
element.sourceId.sourceLabel <= 0 ||
|
||||
element.sourceId.sourceLabelText.empty() ||
|
||||
!isValidUtf8(element.sourceId.instanceName) ||
|
||||
!isValidUtf8(element.sourceId.sourceLabelText) ||
|
||||
element.sourceId.source_label <= 0 ||
|
||||
element.sourceId.source_label_text.empty() ||
|
||||
!isValidUtf8(element.sourceId.instance_name) ||
|
||||
!isValidUtf8(element.sourceId.source_label_text) ||
|
||||
element.materialIndex >= domain.materials().size() ||
|
||||
element.sectionIndex >= domain.shellSections().size() ||
|
||||
domain.shellSections()[element.sectionIndex].materialIndex !=
|
||||
@@ -444,7 +444,7 @@ Status validateShellWriterInput(
|
||||
"invalid-result-rows",
|
||||
"Shell energy, equilibrium, and verification metrics must be finite.");
|
||||
}
|
||||
return Status::ok();
|
||||
return Status::Ok();
|
||||
}
|
||||
|
||||
Status validateWriterInput(
|
||||
@@ -467,7 +467,7 @@ Status validateWriterInput(
|
||||
const bool shell = isShellDomain(domain);
|
||||
if (shell) {
|
||||
const Status shellValidation = validateShellWriterInput(domain, state);
|
||||
if (!shellValidation.isOk()) {
|
||||
if (!shellValidation.IsOk()) {
|
||||
return shellValidation;
|
||||
}
|
||||
} else if (!state.shellResults().empty()) {
|
||||
@@ -488,12 +488,12 @@ Status validateWriterInput(
|
||||
&state.residual(),
|
||||
&state.reaction()};
|
||||
for (const Vector* vector : vectors) {
|
||||
if (vector->size() != fullDofCount) {
|
||||
if (vector->Size() != fullDofCount) {
|
||||
return outputFailure(
|
||||
"invalid-result-state",
|
||||
"Every V0 analysis vector must have node_count*6 values.");
|
||||
}
|
||||
for (std::size_t index = 0U; index < vector->size(); ++index) {
|
||||
for (std::size_t index = 0U; index < vector->Size(); ++index) {
|
||||
if (!std::isfinite((*vector)[index])) {
|
||||
return outputFailure(
|
||||
"invalid-result-state",
|
||||
@@ -509,10 +509,10 @@ Status validateWriterInput(
|
||||
"Source path and UTF-8 content identity are required.");
|
||||
}
|
||||
for (const Node& node : domain.nodes()) {
|
||||
if (node.sourceId.sourceLabel <= 0 ||
|
||||
node.sourceId.sourceLabelText.empty() ||
|
||||
!isValidUtf8(node.sourceId.instanceName) ||
|
||||
!isValidUtf8(node.sourceId.sourceLabelText) ||
|
||||
if (node.sourceId.source_label <= 0 ||
|
||||
node.sourceId.source_label_text.empty() ||
|
||||
!isValidUtf8(node.sourceId.instance_name) ||
|
||||
!isValidUtf8(node.sourceId.source_label_text) ||
|
||||
!isFinite(node.coordinates)) {
|
||||
return outputFailure(
|
||||
"invalid-result-identity",
|
||||
@@ -524,10 +524,10 @@ Status validateWriterInput(
|
||||
modelData.beamLocalAxes.reserve(domain.elements().size());
|
||||
for (const EulerBeam3DDefinition& element : domain.elements()) {
|
||||
AxisSet axes{};
|
||||
if (element.sourceId.sourceLabel <= 0 ||
|
||||
element.sourceId.sourceLabelText.empty() ||
|
||||
!isValidUtf8(element.sourceId.instanceName) ||
|
||||
!isValidUtf8(element.sourceId.sourceLabelText) ||
|
||||
if (element.sourceId.source_label <= 0 ||
|
||||
element.sourceId.source_label_text.empty() ||
|
||||
!isValidUtf8(element.sourceId.instance_name) ||
|
||||
!isValidUtf8(element.sourceId.source_label_text) ||
|
||||
element.nodeIndices[0U] == element.nodeIndices[1U] ||
|
||||
element.materialIndex >= domain.materials().size() ||
|
||||
!computeLocalAxes(domain, element, axes)) {
|
||||
@@ -626,7 +626,7 @@ Status validateWriterInput(
|
||||
for (const Diagnostic& diagnostic : diagnostics) {
|
||||
if (!isValidUtf8(diagnostic.code) ||
|
||||
!isValidUtf8(diagnostic.keyword) ||
|
||||
!isValidUtf8(diagnostic.entityIdentity) ||
|
||||
!isValidUtf8(diagnostic.entity_identity) ||
|
||||
!isValidUtf8(diagnostic.message)) {
|
||||
return outputFailure(
|
||||
"invalid-result-diagnostic",
|
||||
@@ -636,23 +636,23 @@ Status validateWriterInput(
|
||||
|
||||
|
||||
auto analysisModelResult = AnalysisModel::create(domain);
|
||||
if (!analysisModelResult.hasValue()) {
|
||||
if (!analysisModelResult.HasValue()) {
|
||||
return outputFailure(
|
||||
"invalid-result-state",
|
||||
"The HDF5 writer could not reconstruct the active model view.");
|
||||
}
|
||||
const AnalysisModel analysisModel =
|
||||
std::move(analysisModelResult.value());
|
||||
std::move(analysisModelResult.Value());
|
||||
auto dofResult = DofManager::create(analysisModel);
|
||||
if (!dofResult.hasValue()) {
|
||||
if (!dofResult.HasValue()) {
|
||||
return outputFailure(
|
||||
"invalid-result-state",
|
||||
"The HDF5 writer could not reconstruct stable constraint identity.");
|
||||
}
|
||||
const DofManager dofs = std::move(dofResult.value());
|
||||
const DofManager dofs = std::move(dofResult.Value());
|
||||
modelData.constraintMask.assign(fullDofCount, 0U);
|
||||
modelData.prescribedDisplacement.assign(fullDofCount, 0.0);
|
||||
if (dofs.constrainedDofs().size() != dofs.prescribedValues().size()) {
|
||||
if (dofs.constrainedDofs().size() != dofs.prescribedValues().Size()) {
|
||||
return outputFailure(
|
||||
"invalid-result-state",
|
||||
"Constraint identities and prescribed values have inconsistent sizes.");
|
||||
@@ -670,7 +670,7 @@ Status validateWriterInput(
|
||||
modelData.constraintMask[fullDof] = 1U;
|
||||
modelData.prescribedDisplacement[fullDof] = prescribed;
|
||||
}
|
||||
return Status::ok();
|
||||
return Status::Ok();
|
||||
}
|
||||
|
||||
std::string normalizedPathString(const std::filesystem::path& path) {
|
||||
@@ -948,7 +948,7 @@ void writeMetadata(const hid_t file, const Domain& domain) {
|
||||
auto metadata = createGroup(file, "/metadata");
|
||||
writeUint64Attribute(metadata.get(), "schema_version", 0U);
|
||||
writeStringAttribute(
|
||||
metadata.get(), "solver_version", std::string{solverVersion()});
|
||||
metadata.get(), "solver_version", std::string{SolverVersion()});
|
||||
writeStringAttribute(
|
||||
metadata.get(), "source_input_identity", sourceInputIdentity(domain));
|
||||
writeStringAttribute(
|
||||
@@ -987,8 +987,8 @@ void writeNodes(const hid_t file, const Domain& domain) {
|
||||
const Node& node = domain.nodes()[index];
|
||||
rows.push_back({
|
||||
static_cast<std::uint64_t>(index),
|
||||
node.sourceId.instanceName.c_str(),
|
||||
node.sourceId.sourceLabelText.c_str(),
|
||||
node.sourceId.instance_name.c_str(),
|
||||
node.sourceId.source_label_text.c_str(),
|
||||
{node.coordinates[0U], node.coordinates[1U], node.coordinates[2U]}});
|
||||
}
|
||||
|
||||
@@ -1062,8 +1062,8 @@ void writeBeamElements(
|
||||
const auto& element = domain.elements()[index];
|
||||
ElementWriteRow row{
|
||||
static_cast<std::uint64_t>(index),
|
||||
element.sourceId.instanceName.c_str(),
|
||||
element.sourceId.sourceLabelText.c_str(),
|
||||
element.sourceId.instance_name.c_str(),
|
||||
element.sourceId.source_label_text.c_str(),
|
||||
{static_cast<std::uint64_t>(element.nodeIndices[0U]),
|
||||
static_cast<std::uint64_t>(element.nodeIndices[1U])},
|
||||
{}};
|
||||
@@ -1146,8 +1146,8 @@ void writeShellElements(const hid_t file, const Domain& domain) {
|
||||
const auto& element = domain.shellElements()[index];
|
||||
rows.push_back({
|
||||
static_cast<std::uint64_t>(index),
|
||||
element.sourceId.instanceName.c_str(),
|
||||
element.sourceId.sourceLabelText.c_str(),
|
||||
element.sourceId.instance_name.c_str(),
|
||||
element.sourceId.source_label_text.c_str(),
|
||||
shellSourceTypeName(element.sourceType),
|
||||
kMitc4InternalFormulation.data(),
|
||||
{static_cast<std::uint64_t>(element.nodeIndices[0U]),
|
||||
@@ -1660,7 +1660,7 @@ void writeShellResultDatasets(
|
||||
void writeDiagnostics(
|
||||
const hid_t file, const std::vector<Diagnostic>& inputDiagnostics) {
|
||||
std::vector<Diagnostic> diagnostics = inputDiagnostics;
|
||||
sortDiagnostics(diagnostics);
|
||||
SortDiagnostics(diagnostics);
|
||||
std::vector<std::string> files;
|
||||
files.reserve(diagnostics.size());
|
||||
for (const auto& diagnostic : diagnostics) {
|
||||
@@ -1671,12 +1671,12 @@ void writeDiagnostics(
|
||||
for (std::size_t index = 0U; index < diagnostics.size(); ++index) {
|
||||
const auto& diagnostic = diagnostics[index];
|
||||
rows.push_back({
|
||||
diagnostic.severity == Severity::warning ? "warning" : "error",
|
||||
diagnostic.severity == Severity::kWarning ? "warning" : "error",
|
||||
diagnostic.code.c_str(),
|
||||
files[index].c_str(),
|
||||
static_cast<std::uint64_t>(diagnostic.location.line),
|
||||
diagnostic.keyword.c_str(),
|
||||
diagnostic.entityIdentity.c_str(),
|
||||
diagnostic.entity_identity.c_str(),
|
||||
diagnostic.message.c_str()});
|
||||
}
|
||||
|
||||
@@ -1735,8 +1735,8 @@ void writeResultDatasets(
|
||||
file,
|
||||
std::string{kStepRoot} + "/nodal/displacement",
|
||||
nodalDimensions,
|
||||
state.displacement().data(),
|
||||
state.displacement().size(),
|
||||
state.displacement().Data(),
|
||||
state.displacement().Size(),
|
||||
"UX,UY,UZ,URX,URY,URZ",
|
||||
"length,length,length,radian,radian,radian",
|
||||
"global-cartesian",
|
||||
@@ -1745,8 +1745,8 @@ void writeResultDatasets(
|
||||
file,
|
||||
std::string{kStepRoot} + "/nodal/reaction",
|
||||
nodalDimensions,
|
||||
state.reaction().data(),
|
||||
state.reaction().size(),
|
||||
state.reaction().Data(),
|
||||
state.reaction().Size(),
|
||||
"RF1,RF2,RF3,RM1,RM2,RM3",
|
||||
"force,force,force,force*length,force*length,force*length",
|
||||
"global-cartesian",
|
||||
@@ -2253,7 +2253,7 @@ void selfCheckFile(
|
||||
H5Gclose};
|
||||
requireUint64Attribute(metadata.get(), "schema_version", 0U);
|
||||
requireStringAttribute(
|
||||
metadata.get(), "solver_version", std::string{solverVersion()});
|
||||
metadata.get(), "solver_version", std::string{SolverVersion()});
|
||||
requireStringAttribute(
|
||||
metadata.get(), "source_input_identity", sourceInputIdentity(domain));
|
||||
requireStringAttribute(
|
||||
@@ -2572,7 +2572,7 @@ Status Hdf5ResultsWriter::write(
|
||||
try {
|
||||
const Status validation = validateWriterInput(
|
||||
outputPath, domain, state, diagnostics, modelData);
|
||||
if (!validation.isOk()) {
|
||||
if (!validation.IsOk()) {
|
||||
return validation;
|
||||
}
|
||||
|
||||
@@ -2590,7 +2590,7 @@ Status Hdf5ResultsWriter::write(
|
||||
"The checked temporary HDF5 file could not replace the final output.");
|
||||
}
|
||||
cleanup.release();
|
||||
return Status::ok();
|
||||
return Status::Ok();
|
||||
} catch (const Hdf5Failure& failure) {
|
||||
return outputFailure("hdf5-write-failure", failure.what());
|
||||
} catch (const std::exception& failure) {
|
||||
|
||||
Reference in New Issue
Block a user