feat: add solver core skeleton

This commit is contained in:
NINI
2026-06-12 02:25:07 +09:00
parent 4e7fd1087d
commit cbd1a6c5d7
46 changed files with 1911 additions and 19 deletions
+146
View File
@@ -0,0 +1,146 @@
#pragma once
#include <fesa/core/ids.hpp>
#include <stdexcept>
#include <utility>
#include <vector>
namespace fesa::analysis {
struct IterationState {
double time = 0.0;
int increment = 0;
int iteration = 0;
};
class AnalysisState {
public:
explicit AnalysisState(int total_dof_count)
: displacement_(vector_of(total_dof_count)),
velocity_(vector_of(total_dof_count)),
acceleration_(vector_of(total_dof_count)),
temperature_(vector_of(total_dof_count)),
external_force_(vector_of(total_dof_count)),
internal_force_(vector_of(total_dof_count)),
residual_(vector_of(total_dof_count))
{
}
const std::vector<double>& displacement() const
{
return displacement_;
}
const std::vector<double>& velocity() const
{
return velocity_;
}
const std::vector<double>& acceleration() const
{
return acceleration_;
}
const std::vector<double>& temperature() const
{
return temperature_;
}
const std::vector<double>& external_force() const
{
return external_force_;
}
const std::vector<double>& internal_force() const
{
return internal_force_;
}
const std::vector<double>& residual() const
{
return residual_;
}
void set_displacement(std::vector<double> values)
{
assign_same_size(displacement_, std::move(values));
}
void set_external_force(std::vector<double> values)
{
assign_same_size(external_force_, std::move(values));
}
void set_internal_force(std::vector<double> values)
{
assign_same_size(internal_force_, std::move(values));
}
void update_residual()
{
for (std::size_t index = 0; index < residual_.size(); ++index) {
residual_[index] = external_force_[index] - internal_force_[index];
}
}
IterationState& iteration_state()
{
return iteration_state_;
}
const IterationState& iteration_state() const
{
return iteration_state_;
}
void set_element_state(core::ElementId element_id, std::vector<double> state)
{
for (auto& entry : element_states_) {
if (entry.first.value == element_id.value) {
entry.second = std::move(state);
return;
}
}
element_states_.push_back({element_id, std::move(state)});
}
const std::vector<double>* element_state(core::ElementId element_id) const
{
for (const auto& entry : element_states_) {
if (entry.first.value == element_id.value) {
return &entry.second;
}
}
return nullptr;
}
private:
static std::vector<double> vector_of(int size)
{
if (size < 0) {
throw std::invalid_argument("negative dof count");
}
return std::vector<double>(static_cast<std::size_t>(size), 0.0);
}
static void assign_same_size(std::vector<double>& target, std::vector<double> values)
{
if (target.size() != values.size()) {
throw std::invalid_argument("vector size mismatch");
}
target = std::move(values);
}
std::vector<double> displacement_;
std::vector<double> velocity_;
std::vector<double> acceleration_;
std::vector<double> temperature_;
std::vector<double> external_force_;
std::vector<double> internal_force_;
std::vector<double> residual_;
IterationState iteration_state_;
std::vector<std::pair<core::ElementId, std::vector<double>>> element_states_;
};
} // namespace fesa::analysis