feat(cpp-object-oriented-modular-refactoring): step 19 - boundary-condition-policy
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#ifndef FESA_CONSTRAINTS_BOUNDARY_CONDITION_H_
|
||||
#define FESA_CONSTRAINTS_BOUNDARY_CONDITION_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/core/diagnostic.h"
|
||||
#include "fesa/core/status.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
class DofManager;
|
||||
class Domain;
|
||||
class SourceTargetResolver;
|
||||
|
||||
/// @brief Describes one prescribed value in stable full-DOF order.
|
||||
struct ConstraintDefinition {
|
||||
std::size_t source_order;
|
||||
std::size_t full_dof_index;
|
||||
double prescribed_value;
|
||||
};
|
||||
|
||||
/// @brief Provides immutable semantic and equation context to a boundary.
|
||||
/// @note Every referenced object must outlive a constraint request.
|
||||
struct BoundaryConditionContext {
|
||||
const Domain& domain;
|
||||
const DofManager& dof_manager;
|
||||
const SourceTargetResolver& target_resolver;
|
||||
};
|
||||
|
||||
/// @brief Produces ordered constraint definitions without equation mutation.
|
||||
class BoundaryCondition {
|
||||
public:
|
||||
virtual ~BoundaryCondition() = default;
|
||||
|
||||
/// @brief Resolves finite full-DOF definitions in stable target order.
|
||||
/// @param context Non-owning semantic and equation context for this call.
|
||||
/// @return Ordered definitions or a structured model failure.
|
||||
virtual Result<std::vector<ConstraintDefinition>> ResolveConstraints(
|
||||
const BoundaryConditionContext& context) const = 0;
|
||||
|
||||
/// @brief Returns the source location used by policy diagnostics.
|
||||
const SourceLocation& Location() const noexcept { return location_; }
|
||||
|
||||
/// @brief Returns the source target identity used by policy diagnostics.
|
||||
const std::string& TargetIdentity() const noexcept {
|
||||
return target_identity_;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// @brief Creates a boundary with optional shared diagnostic provenance.
|
||||
BoundaryCondition(std::string target_identity = {},
|
||||
SourceLocation location = {})
|
||||
: target_identity_{std::move(target_identity)},
|
||||
location_{std::move(location)} {}
|
||||
|
||||
private:
|
||||
std::string target_identity_;
|
||||
SourceLocation location_;
|
||||
};
|
||||
|
||||
/// @brief Holds non-owning boundaries in an explicitly supplied source order.
|
||||
using BoundaryConditionView =
|
||||
std::vector<std::reference_wrapper<const BoundaryCondition>>;
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_CONSTRAINTS_BOUNDARY_CONDITION_H_
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef FESA_CONSTRAINTS_ESSENTIAL_CONSTRAINT_POLICY_H_
|
||||
#define FESA_CONSTRAINTS_ESSENTIAL_CONSTRAINT_POLICY_H_
|
||||
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
#include "fesa/math/vector.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
class DofManager;
|
||||
|
||||
/// @brief Stores full-stiffness blocks in stable free/constrained order.
|
||||
struct PartitionedStiffness {
|
||||
SparseMatrix k_ff;
|
||||
SparseMatrix k_fc;
|
||||
SparseMatrix k_cf;
|
||||
SparseMatrix k_cc;
|
||||
};
|
||||
|
||||
/// @brief Applies stable prescribed-displacement elimination.
|
||||
class EssentialConstraintPolicy {
|
||||
public:
|
||||
/// @brief Partitions full stiffness into Kff, Kfc, Kcf, and Kcc.
|
||||
Result<PartitionedStiffness> Partition(const SparseMatrix& full_stiffness,
|
||||
const DofManager& dof_manager) const;
|
||||
|
||||
/// @brief Gathers a full vector in stable free-equation order.
|
||||
Vector GatherFree(const Vector& full_values,
|
||||
const DofManager& dof_manager) const;
|
||||
|
||||
/// @brief Gathers a full vector in stable constrained-DOF order.
|
||||
Vector GatherConstrained(const Vector& full_values,
|
||||
const DofManager& dof_manager) const;
|
||||
|
||||
/// @brief Reconstructs full d from stable df and exact prescribed dc.
|
||||
Vector ReconstructFull(const Vector& free_values,
|
||||
const Vector& constrained_values,
|
||||
const DofManager& dof_manager) const;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_CONSTRAINTS_ESSENTIAL_CONSTRAINT_POLICY_H_
|
||||
@@ -1,41 +0,0 @@
|
||||
#ifndef FESA_CONSTRAINTS_ESSENTIAL_CONSTRAINTS_H_
|
||||
#define FESA_CONSTRAINTS_ESSENTIAL_CONSTRAINTS_H_
|
||||
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
#include "fesa/math/vector.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
class DofManager;
|
||||
|
||||
/// @brief Stores full-stiffness blocks in stable free/constrained order.
|
||||
struct PartitionedStiffness {
|
||||
SparseMatrix kff;
|
||||
SparseMatrix kfc;
|
||||
SparseMatrix kcf;
|
||||
SparseMatrix kcc;
|
||||
};
|
||||
|
||||
/// @brief Applies stable prescribed-displacement elimination.
|
||||
class EssentialConstraints {
|
||||
public:
|
||||
/// @brief Partitions full stiffness into Kff, Kfc, Kcf, and Kcc.
|
||||
static Result<PartitionedStiffness> Partition(const SparseMatrix& full,
|
||||
const DofManager& dofs);
|
||||
|
||||
/// @brief Gathers a full vector in stable free-equation order.
|
||||
static Vector GatherFree(const Vector& full, const DofManager& dofs);
|
||||
|
||||
/// @brief Gathers a full vector in stable constrained-DOF order.
|
||||
static Vector GatherConstrained(const Vector& full, const DofManager& dofs);
|
||||
|
||||
/// @brief Reconstructs full d from stable df and exact prescribed dc.
|
||||
static Vector ReconstructFull(const Vector& free_values,
|
||||
const Vector& constrained_values,
|
||||
const DofManager& dofs);
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_CONSTRAINTS_ESSENTIAL_CONSTRAINTS_H_
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef FESA_CONSTRAINTS_PRESCRIBED_DISPLACEMENT_H_
|
||||
#define FESA_CONSTRAINTS_PRESCRIBED_DISPLACEMENT_H_
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "fesa/constraints/boundary_condition.h"
|
||||
#include "fesa/core/diagnostic.h"
|
||||
#include "fesa/elements/element.h"
|
||||
#include "fesa/model/source_target_resolver.h"
|
||||
|
||||
namespace fesa {
|
||||
|
||||
/// @brief Emits one prescribed nodal displacement component for a target.
|
||||
class PrescribedDisplacementBoundaryCondition final : public BoundaryCondition {
|
||||
public:
|
||||
/// @brief Creates one prescribed component in stable source order.
|
||||
PrescribedDisplacementBoundaryCondition(SourceTargetQuery target,
|
||||
DofComponent component,
|
||||
double prescribed_value,
|
||||
std::size_t source_order,
|
||||
SourceLocation location = {});
|
||||
|
||||
/// @brief Resolves target-major full-DOF constraint definitions.
|
||||
Result<std::vector<ConstraintDefinition>> ResolveConstraints(
|
||||
const BoundaryConditionContext& context) const override;
|
||||
|
||||
/// @brief Returns the immutable source target query.
|
||||
const SourceTargetQuery& Target() const noexcept;
|
||||
|
||||
/// @brief Returns the prescribed global DOF component.
|
||||
DofComponent Component() const noexcept;
|
||||
|
||||
/// @brief Returns the exact prescribed displacement value.
|
||||
double PrescribedValue() const noexcept;
|
||||
|
||||
/// @brief Returns the stable boundary-definition order.
|
||||
std::size_t SourceOrder() const noexcept;
|
||||
|
||||
private:
|
||||
SourceTargetQuery target_;
|
||||
DofComponent component_;
|
||||
double prescribed_value_;
|
||||
std::size_t source_order_;
|
||||
};
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
#endif // FESA_CONSTRAINTS_PRESCRIBED_DISPLACEMENT_H_
|
||||
Reference in New Issue
Block a user