feat(cpp-object-oriented-modular-refactoring): step 3 - foundation-google-style
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/math/vector.hpp"
|
||||
#include "fesa/math/vector.h"
|
||||
#include "fesa/results/result_records.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/analysis/analysis_state.hpp"
|
||||
#include "fesa/constraints/essential_constraints.hpp"
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/math/sparse_matrix.hpp"
|
||||
#include "fesa/math/vector.hpp"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
#include "fesa/math/vector.h"
|
||||
#include "fesa/model/domain.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/math/sparse_matrix.hpp"
|
||||
#include "fesa/math/vector.hpp"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
#include "fesa/math/vector.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/math/sparse_matrix.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef FESA_BUILD_INFO_H_
|
||||
#define FESA_BUILD_INFO_H_
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
/// @brief Returns the stable solver version written to result metadata.
|
||||
std::string_view SolverVersion() noexcept;
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_BUILD_INFO_H_
|
||||
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
// Returns the stable solver version written to externally visible result metadata.
|
||||
std::string_view solverVersion() noexcept;
|
||||
|
||||
} // namespace fesa
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/math/sparse_matrix.hpp"
|
||||
#include "fesa/math/vector.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
#include "fesa/math/vector.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef FESA_CORE_DIAGNOSTIC_H_
|
||||
#define FESA_CORE_DIAGNOSTIC_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/core/source_identity.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
/// @brief Distinguishes recoverable warnings from operation-stopping errors.
|
||||
enum class Severity { kWarning, kError };
|
||||
|
||||
/// @brief Carries a structured, backend-independent diagnostic record.
|
||||
struct Diagnostic {
|
||||
Severity severity;
|
||||
std::string code;
|
||||
SourceLocation location;
|
||||
std::string keyword;
|
||||
std::string entity_identity;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
/// @brief Orders diagnostics by their externally visible source tuple.
|
||||
/// @param diagnostics Records to reorder in place.
|
||||
/// @note Records with identical keys retain their discovery order.
|
||||
void SortDiagnostics(std::vector<Diagnostic>& diagnostics);
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_CORE_DIAGNOSTIC_H_
|
||||
@@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/source_identity.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
// Distinguishes recoverable warnings from errors that stop the current operation.
|
||||
enum class Severity {
|
||||
warning,
|
||||
error
|
||||
};
|
||||
|
||||
// Carries a structured, backend-independent diagnostic record.
|
||||
struct Diagnostic {
|
||||
Severity severity;
|
||||
std::string code;
|
||||
SourceLocation location;
|
||||
std::string keyword;
|
||||
std::string entityIdentity;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
// Orders diagnostics by their externally visible source tuple while retaining
|
||||
// discovery order for records with identical keys.
|
||||
void sortDiagnostics(std::vector<Diagnostic>& diagnostics);
|
||||
|
||||
} // namespace fesa
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef FESA_CORE_SOURCE_IDENTITY_H_
|
||||
#define FESA_CORE_SOURCE_IDENTITY_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
/// @brief Identifies the input location that produced an item or diagnostic.
|
||||
struct SourceLocation {
|
||||
std::filesystem::path file;
|
||||
std::size_t line;
|
||||
};
|
||||
|
||||
/// @brief Preserves semantic and raw-text forms of a source entity identity.
|
||||
struct SourceEntityId {
|
||||
std::string instance_name;
|
||||
std::int64_t source_label;
|
||||
std::string source_label_text;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_CORE_SOURCE_IDENTITY_H_
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
// Identifies the physical input location that produced a model item or diagnostic.
|
||||
struct SourceLocation {
|
||||
std::filesystem::path file;
|
||||
std::size_t line;
|
||||
};
|
||||
|
||||
// Preserves both semantic and raw-text forms of an input entity identity.
|
||||
struct SourceEntityId {
|
||||
std::string instanceName;
|
||||
std::int64_t sourceLabel;
|
||||
std::string sourceLabelText;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
@@ -0,0 +1,114 @@
|
||||
#ifndef FESA_CORE_STATUS_H_
|
||||
#define FESA_CORE_STATUS_H_
|
||||
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/core/diagnostic.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
/// @brief Maps failures to the stable command-line exit-code categories.
|
||||
enum class FailureCategory { kInput, kModel, kSolver, kOutput };
|
||||
|
||||
/// @brief Transports success or structured failure diagnostics.
|
||||
class Status {
|
||||
public:
|
||||
/// @brief Creates a successful status.
|
||||
/// @return A status with no failure category or diagnostics.
|
||||
static Status Ok();
|
||||
|
||||
/// @brief Creates an uncategorized failed status.
|
||||
/// @param diagnostics Structured diagnostics owned by the returned status.
|
||||
/// @return A failed status with diagnostics in deterministic source order.
|
||||
static Status Failure(std::vector<Diagnostic> diagnostics);
|
||||
|
||||
/// @brief Creates a categorized failed status.
|
||||
/// @param category Stable external failure category.
|
||||
/// @param diagnostics Structured diagnostics owned by the returned status.
|
||||
/// @return A failed status with diagnostics in deterministic source order.
|
||||
static Status Failure(FailureCategory category,
|
||||
std::vector<Diagnostic> diagnostics);
|
||||
|
||||
/// @brief Reports whether the operation succeeded.
|
||||
bool IsOk() const noexcept;
|
||||
|
||||
/// @brief Returns the optional stable failure category.
|
||||
std::optional<FailureCategory> Category() const noexcept;
|
||||
|
||||
/// @brief Returns the deterministically ordered diagnostic records.
|
||||
const std::vector<Diagnostic>& Diagnostics() const noexcept;
|
||||
|
||||
private:
|
||||
/// @brief Constructs a status from its validated invariant fields.
|
||||
Status(bool is_ok, std::optional<FailureCategory> category,
|
||||
std::vector<Diagnostic> diagnostics);
|
||||
|
||||
bool is_ok_;
|
||||
std::optional<FailureCategory> category_;
|
||||
std::vector<Diagnostic> diagnostics_;
|
||||
};
|
||||
|
||||
/// @brief Owns exactly one successful value or one failed Status.
|
||||
template <class T>
|
||||
class Result {
|
||||
public:
|
||||
/// @brief Creates a successful result that owns the supplied value.
|
||||
static Result Success(T value) {
|
||||
return Result{SuccessTag{}, std::move(value)};
|
||||
}
|
||||
|
||||
/// @brief Creates a failed result that owns a failed status.
|
||||
/// @throws std::invalid_argument if status represents success.
|
||||
static Result Failure(Status status) {
|
||||
if (status.IsOk()) {
|
||||
throw std::invalid_argument{"A failed Result requires a failed Status."};
|
||||
}
|
||||
return Result{FailureTag{}, std::move(status)};
|
||||
}
|
||||
|
||||
/// @brief Reports whether this result owns a successful value.
|
||||
bool HasValue() const noexcept { return value_.has_value(); }
|
||||
|
||||
/// @brief Returns the owned successful value.
|
||||
/// @throws std::logic_error if this result represents failure.
|
||||
T& Value() {
|
||||
if (!value_) {
|
||||
throw std::logic_error{"Result has no value."};
|
||||
}
|
||||
return *value_;
|
||||
}
|
||||
|
||||
/// @brief Returns the owned successful value.
|
||||
/// @throws std::logic_error if this result represents failure.
|
||||
const T& Value() const {
|
||||
if (!value_) {
|
||||
throw std::logic_error{"Result has no value."};
|
||||
}
|
||||
return *value_;
|
||||
}
|
||||
|
||||
/// @brief Returns the success or failure status.
|
||||
const Status& GetStatus() const noexcept { return status_; }
|
||||
|
||||
private:
|
||||
struct SuccessTag {};
|
||||
struct FailureTag {};
|
||||
|
||||
/// @brief Constructs the successful value alternative.
|
||||
Result(SuccessTag, T value)
|
||||
: value_{std::move(value)}, status_{Status::Ok()} {}
|
||||
|
||||
/// @brief Constructs the failed status alternative.
|
||||
Result(FailureTag, Status status)
|
||||
: value_{std::nullopt}, status_{std::move(status)} {}
|
||||
|
||||
std::optional<T> value_;
|
||||
Status status_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_CORE_STATUS_H_
|
||||
@@ -1,94 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/diagnostic.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
// Maps a failure to the stable command-line exit-code classes defined by V0.
|
||||
enum class FailureCategory {
|
||||
input,
|
||||
model,
|
||||
solver,
|
||||
output
|
||||
};
|
||||
|
||||
// Transports success or structured diagnostics without exposing backend errors.
|
||||
class Status {
|
||||
public:
|
||||
static Status ok();
|
||||
static Status failure(std::vector<Diagnostic> diagnostics);
|
||||
static Status failure(
|
||||
FailureCategory category, std::vector<Diagnostic> diagnostics);
|
||||
|
||||
bool isOk() const noexcept;
|
||||
std::optional<FailureCategory> failureCategory() const noexcept;
|
||||
const std::vector<Diagnostic>& diagnostics() const noexcept;
|
||||
|
||||
private:
|
||||
Status(
|
||||
bool isOk,
|
||||
std::optional<FailureCategory> category,
|
||||
std::vector<Diagnostic> diagnostics);
|
||||
|
||||
bool isOk_;
|
||||
std::optional<FailureCategory> category_;
|
||||
std::vector<Diagnostic> diagnostics_;
|
||||
};
|
||||
|
||||
// Owns exactly one successful value or one failed Status.
|
||||
template<class T>
|
||||
class Result {
|
||||
public:
|
||||
static Result success(T value) {
|
||||
return Result{SuccessTag{}, std::move(value)};
|
||||
}
|
||||
|
||||
static Result failure(Status status) {
|
||||
if (status.isOk()) {
|
||||
throw std::invalid_argument{"A failed Result requires a failed Status."};
|
||||
}
|
||||
return Result{FailureTag{}, std::move(status)};
|
||||
}
|
||||
|
||||
bool hasValue() const noexcept {
|
||||
return value_.has_value();
|
||||
}
|
||||
|
||||
T& value() {
|
||||
if (!value_) {
|
||||
throw std::logic_error{"Result has no value."};
|
||||
}
|
||||
return *value_;
|
||||
}
|
||||
|
||||
const T& value() const {
|
||||
if (!value_) {
|
||||
throw std::logic_error{"Result has no value."};
|
||||
}
|
||||
return *value_;
|
||||
}
|
||||
|
||||
const Status& status() const noexcept {
|
||||
return status_;
|
||||
}
|
||||
|
||||
private:
|
||||
struct SuccessTag {};
|
||||
struct FailureTag {};
|
||||
|
||||
Result(SuccessTag, T value)
|
||||
: value_{std::move(value)}, status_{Status::ok()} {}
|
||||
|
||||
Result(FailureTag, Status status)
|
||||
: value_{std::nullopt}, status_{std::move(status)} {}
|
||||
|
||||
std::optional<T> value_;
|
||||
Status status_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/math/matrix.hpp"
|
||||
#include "fesa/math/vector.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/math/matrix.h"
|
||||
#include "fesa/math/vector.h"
|
||||
#include "fesa/model/model_types.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/math/matrix.hpp"
|
||||
#include "fesa/math/vector.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/math/matrix.h"
|
||||
#include "fesa/math/vector.h"
|
||||
#include "fesa/model/model_types.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/math/vector.hpp"
|
||||
#include "fesa/math/vector.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/io/abaqus/input_syntax.hpp"
|
||||
#include "fesa/model/domain.hpp"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/io/abaqus/input_syntax.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/source_identity.hpp"
|
||||
#include "fesa/core/source_identity.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#ifndef FESA_MATH_MATRIX_H_
|
||||
#define FESA_MATH_MATRIX_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/math/vector.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
/// @brief Owns row-major contiguous storage independently of sparse matrices.
|
||||
class Matrix {
|
||||
public:
|
||||
/// @brief Constructs a row-major matrix initialized to one value.
|
||||
Matrix(std::size_t rows, std::size_t columns, double value = 0.0);
|
||||
|
||||
/// @brief Copies matrix values into independent contiguous storage.
|
||||
Matrix(const Matrix& other);
|
||||
|
||||
/// @brief Moves matrix storage and resets other to a zero-by-zero shape.
|
||||
Matrix(Matrix&& other) noexcept;
|
||||
|
||||
/// @brief Copies matrix values into independent contiguous storage.
|
||||
Matrix& operator=(const Matrix& other);
|
||||
|
||||
/// @brief Moves matrix storage and resets other to a zero-by-zero shape.
|
||||
Matrix& operator=(Matrix&& other) noexcept;
|
||||
|
||||
/// @brief Returns the row count.
|
||||
std::size_t Rows() const noexcept;
|
||||
|
||||
/// @brief Returns the column count.
|
||||
std::size_t Columns() const noexcept;
|
||||
|
||||
/// @brief Returns a bounds-checked mutable entry.
|
||||
/// @throws std::out_of_range if the index is outside the matrix.
|
||||
double& operator()(std::size_t row, std::size_t column);
|
||||
|
||||
/// @brief Returns a bounds-checked immutable entry.
|
||||
/// @throws std::out_of_range if the index is outside the matrix.
|
||||
const double& operator()(std::size_t row, std::size_t column) const;
|
||||
|
||||
/// @brief Multiplies this row-major matrix by a dense vector.
|
||||
/// @throws std::invalid_argument if the dimensions are incompatible.
|
||||
Vector Multiply(const Vector& rhs) const;
|
||||
|
||||
/// @brief Multiplies this row-major matrix by another dense matrix.
|
||||
/// @throws std::invalid_argument if the dimensions are incompatible.
|
||||
Matrix Multiply(const Matrix& rhs) const;
|
||||
|
||||
private:
|
||||
std::size_t rows_;
|
||||
std::size_t columns_;
|
||||
std::vector<double> values_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_MATH_MATRIX_H_
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/math/vector.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
// Owns row-major contiguous dense storage independently of sparse matrices.
|
||||
class Matrix {
|
||||
public:
|
||||
Matrix(std::size_t rows, std::size_t columns, double value = 0.0);
|
||||
Matrix(const Matrix& other);
|
||||
Matrix(Matrix&& other) noexcept;
|
||||
Matrix& operator=(const Matrix& other);
|
||||
Matrix& operator=(Matrix&& other) noexcept;
|
||||
|
||||
std::size_t rows() const noexcept;
|
||||
std::size_t columns() const noexcept;
|
||||
double& operator()(std::size_t row, std::size_t column);
|
||||
const double& operator()(std::size_t row, std::size_t column) const;
|
||||
Vector multiply(const Vector& rhs) const;
|
||||
Matrix multiply(const Matrix& rhs) const;
|
||||
|
||||
private:
|
||||
std::size_t rows_;
|
||||
std::size_t columns_;
|
||||
std::vector<double> values_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
@@ -0,0 +1,73 @@
|
||||
#ifndef FESA_MATH_SPARSE_MATRIX_H_
|
||||
#define FESA_MATH_SPARSE_MATRIX_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/math/vector.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
struct SparsePattern;
|
||||
|
||||
/// @brief Carries one deterministic element-local COO contribution.
|
||||
struct CooContribution {
|
||||
std::size_t row;
|
||||
std::size_t column;
|
||||
double value;
|
||||
std::size_t element_order;
|
||||
std::size_t local_order;
|
||||
};
|
||||
|
||||
/// @brief Owns canonical 0-based CSR independently of the dense Matrix type.
|
||||
class SparseMatrix {
|
||||
public:
|
||||
/// @brief Reduces ordered COO contributions into an expected CSR pattern.
|
||||
/// @return A validated matrix or a structured model failure.
|
||||
/// @note Duplicate sums use stable element and local contribution order.
|
||||
static Result<SparseMatrix> FromCoo(
|
||||
std::size_t rows, std::size_t columns,
|
||||
std::vector<CooContribution> contributions,
|
||||
const SparsePattern& expected_pattern);
|
||||
|
||||
/// @brief Returns the row count.
|
||||
std::size_t Rows() const noexcept;
|
||||
|
||||
/// @brief Returns the column count.
|
||||
std::size_t Columns() const noexcept;
|
||||
|
||||
/// @brief Returns the canonical 0-based CSR row offsets.
|
||||
const std::vector<std::size_t>& RowOffsets() const noexcept;
|
||||
|
||||
/// @brief Returns sorted unique 0-based CSR column indices.
|
||||
const std::vector<std::size_t>& ColumnIndices() const noexcept;
|
||||
|
||||
/// @brief Returns CSR values including preserved structural zeros.
|
||||
const std::vector<double>& Values() const noexcept;
|
||||
|
||||
/// @brief Multiplies this matrix by a dense vector in stable CSR order.
|
||||
/// @throws std::invalid_argument if the dimensions are incompatible.
|
||||
Vector Multiply(const Vector& rhs) const;
|
||||
|
||||
/// @brief Validates shape, indices, ordering, and finite CSR values.
|
||||
/// @return Success or a structured model failure.
|
||||
Status Validate() const;
|
||||
|
||||
private:
|
||||
/// @brief Constructs CSR storage after boundary validation.
|
||||
SparseMatrix(std::size_t rows, std::size_t columns,
|
||||
std::vector<std::size_t> row_offsets,
|
||||
std::vector<std::size_t> column_indices,
|
||||
std::vector<double> values);
|
||||
|
||||
std::size_t rows_;
|
||||
std::size_t columns_;
|
||||
std::vector<std::size_t> row_offsets_;
|
||||
std::vector<std::size_t> column_indices_;
|
||||
std::vector<double> values_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_MATH_SPARSE_MATRIX_H_
|
||||
@@ -1,53 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/math/vector.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
struct SparsePattern;
|
||||
|
||||
struct CooContribution {
|
||||
std::size_t row;
|
||||
std::size_t column;
|
||||
double value;
|
||||
std::size_t elementOrder;
|
||||
std::size_t localOrder;
|
||||
};
|
||||
|
||||
// Owns canonical 0-based CSR data independently of the dense Matrix adapter.
|
||||
class SparseMatrix {
|
||||
public:
|
||||
static Result<SparseMatrix> fromCoo(
|
||||
std::size_t rows,
|
||||
std::size_t columns,
|
||||
std::vector<CooContribution> contributions,
|
||||
const SparsePattern& expectedPattern);
|
||||
|
||||
std::size_t rows() const noexcept;
|
||||
std::size_t columns() const noexcept;
|
||||
const std::vector<std::size_t>& rowOffsets() const noexcept;
|
||||
const std::vector<std::size_t>& columnIndices() const noexcept;
|
||||
const std::vector<double>& values() const noexcept;
|
||||
Vector multiply(const Vector& rhs) const;
|
||||
Status validate() const;
|
||||
|
||||
private:
|
||||
SparseMatrix(
|
||||
std::size_t rows,
|
||||
std::size_t columns,
|
||||
std::vector<std::size_t> rowOffsets,
|
||||
std::vector<std::size_t> columnIndices,
|
||||
std::vector<double> values);
|
||||
|
||||
std::size_t rows_;
|
||||
std::size_t columns_;
|
||||
std::vector<std::size_t> rowOffsets_;
|
||||
std::vector<std::size_t> columnIndices_;
|
||||
std::vector<double> values_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
@@ -0,0 +1,64 @@
|
||||
#ifndef FESA_MATH_VECTOR_H_
|
||||
#define FESA_MATH_VECTOR_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
/// @brief Owns a contiguous dense vector while keeping MKL private.
|
||||
class Vector {
|
||||
public:
|
||||
/// @brief Constructs a vector with all entries initialized to one value.
|
||||
explicit Vector(std::size_t size, double value = 0.0);
|
||||
|
||||
/// @brief Copies vector values into independent contiguous storage.
|
||||
Vector(const Vector& other);
|
||||
|
||||
/// @brief Moves vector storage and leaves other empty.
|
||||
Vector(Vector&& other) noexcept;
|
||||
|
||||
/// @brief Copies vector values into independent contiguous storage.
|
||||
Vector& operator=(const Vector& other);
|
||||
|
||||
/// @brief Moves vector storage and leaves other empty.
|
||||
Vector& operator=(Vector&& other) noexcept;
|
||||
|
||||
/// @brief Returns the number of entries.
|
||||
std::size_t Size() const noexcept;
|
||||
|
||||
/// @brief Returns mutable contiguous storage.
|
||||
double* Data() noexcept;
|
||||
|
||||
/// @brief Returns immutable contiguous storage.
|
||||
const double* Data() const noexcept;
|
||||
|
||||
/// @brief Returns a bounds-checked mutable entry.
|
||||
/// @throws std::out_of_range if index is outside the vector.
|
||||
double& operator[](std::size_t index);
|
||||
|
||||
/// @brief Returns a bounds-checked immutable entry.
|
||||
/// @throws std::out_of_range if index is outside the vector.
|
||||
const double& operator[](std::size_t index) const;
|
||||
|
||||
/// @brief Computes the Euclidean dot product with rhs.
|
||||
/// @throws std::invalid_argument if the vector sizes differ.
|
||||
double Dot(const Vector& rhs) const;
|
||||
|
||||
/// @brief Computes the Euclidean norm.
|
||||
double Norm() const;
|
||||
|
||||
/// @brief Scales each entry by alpha through the dense backend.
|
||||
void Scale(double alpha);
|
||||
|
||||
/// @brief Accumulates alpha times x into this vector.
|
||||
/// @throws std::invalid_argument if the vector sizes differ.
|
||||
void Axpy(double alpha, const Vector& x);
|
||||
|
||||
private:
|
||||
std::vector<double> values_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_MATH_VECTOR_H_
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
// Owns a contiguous dense vector while keeping the MKL backend private.
|
||||
class Vector {
|
||||
public:
|
||||
explicit Vector(std::size_t size, double value = 0.0);
|
||||
Vector(const Vector& other);
|
||||
Vector(Vector&& other) noexcept;
|
||||
Vector& operator=(const Vector& other);
|
||||
Vector& operator=(Vector&& other) noexcept;
|
||||
|
||||
std::size_t size() const noexcept;
|
||||
double* data() noexcept;
|
||||
const double* data() const noexcept;
|
||||
double& operator[](std::size_t index);
|
||||
const double& operator[](std::size_t index) const;
|
||||
double dot(const Vector& rhs) const;
|
||||
double norm() const;
|
||||
void scale(double alpha);
|
||||
void axpy(double alpha, const Vector& x);
|
||||
|
||||
private:
|
||||
std::vector<double> values_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/model/model_types.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/diagnostic.hpp"
|
||||
#include "fesa/core/source_identity.hpp"
|
||||
#include "fesa/core/diagnostic.h"
|
||||
#include "fesa/core/source_identity.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/model/model_types.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/analysis/analysis_state.hpp"
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/math/sparse_matrix.hpp"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/analysis/analysis_state.hpp"
|
||||
#include "fesa/core/diagnostic.hpp"
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/diagnostic.h"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/model/domain.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef FESA_SOLVERS_LINEAR_LINEAR_SOLVER_H_
|
||||
#define FESA_SOLVERS_LINEAR_LINEAR_SOLVER_H_
|
||||
|
||||
#include "fesa/core/status.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
class SparseMatrix;
|
||||
class Vector;
|
||||
|
||||
/// @brief Separates reusable factorization from RHS substitution.
|
||||
class LinearSolver {
|
||||
public:
|
||||
/// @brief Destroys a backend-neutral linear solver.
|
||||
virtual ~LinearSolver() = default;
|
||||
|
||||
/// @brief Factorizes a validated free-equation matrix for reuse.
|
||||
/// @return Success or a structured solver failure.
|
||||
virtual Status Factorize(const SparseMatrix& matrix) = 0;
|
||||
|
||||
/// @brief Substitutes one right-hand side using retained factorization.
|
||||
/// @param rhs Immutable right-hand side in free-equation order.
|
||||
/// @param solution Updated only after successful finite substitution.
|
||||
/// @return Success or a structured solver failure.
|
||||
virtual Status Solve(const Vector& rhs, Vector& solution) const = 0;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_SOLVERS_LINEAR_LINEAR_SOLVER_H_
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/core/status.hpp"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
class SparseMatrix;
|
||||
class Vector;
|
||||
|
||||
// Separates reusable matrix factorization from right-hand-side substitution.
|
||||
class LinearSolver {
|
||||
public:
|
||||
virtual ~LinearSolver() = default;
|
||||
virtual Status factorize(const SparseMatrix& matrix) = 0;
|
||||
virtual Status solve(const Vector& rhs, Vector& solution) const = 0;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef FESA_SOLVERS_LINEAR_MKL_PARDISO_SOLVER_H_
|
||||
#define FESA_SOLVERS_LINEAR_MKL_PARDISO_SOLVER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "fesa/solvers/linear/linear_solver.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
/// @brief Adapts retained oneMKL PARDISO state behind LinearSolver.
|
||||
class MklPardisoSolver final : public LinearSolver {
|
||||
public:
|
||||
/// @brief Constructs an empty, unfactorized PARDISO adapter.
|
||||
MklPardisoSolver();
|
||||
|
||||
/// @brief Releases retained PARDISO backend state.
|
||||
~MklPardisoSolver() override;
|
||||
|
||||
/// @brief Validates and factorizes a symmetric free-equation matrix.
|
||||
Status Factorize(const SparseMatrix& matrix) override;
|
||||
|
||||
/// @brief Substitutes one right-hand side without refactorization.
|
||||
Status Solve(const Vector& rhs, Vector& solution) const override;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_SOLVERS_LINEAR_MKL_PARDISO_SOLVER_H_
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/solvers/linear/linear_solver.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
// Keeps every oneMKL type and the retained factorization in the private Impl.
|
||||
class MklPardisoSolver final : public LinearSolver {
|
||||
public:
|
||||
MklPardisoSolver();
|
||||
~MklPardisoSolver() override;
|
||||
|
||||
Status factorize(const SparseMatrix& matrix) override;
|
||||
Status solve(const Vector& rhs, Vector& solution) const override;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
Reference in New Issue
Block a user