refactor: move solver skeleton implementations to cpp
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
#include <fesa/core/ids.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa::analysis {
|
||||
@@ -16,121 +14,30 @@ struct IterationState {
|
||||
|
||||
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))
|
||||
{
|
||||
}
|
||||
explicit AnalysisState(int total_dof_count);
|
||||
|
||||
const std::vector<double>& displacement() const
|
||||
{
|
||||
return displacement_;
|
||||
}
|
||||
const std::vector<double>& displacement() const;
|
||||
const std::vector<double>& velocity() const;
|
||||
const std::vector<double>& acceleration() const;
|
||||
const std::vector<double>& temperature() const;
|
||||
const std::vector<double>& external_force() const;
|
||||
const std::vector<double>& internal_force() const;
|
||||
const std::vector<double>& residual() const;
|
||||
|
||||
const std::vector<double>& velocity() const
|
||||
{
|
||||
return velocity_;
|
||||
}
|
||||
void set_displacement(std::vector<double> values);
|
||||
void set_external_force(std::vector<double> values);
|
||||
void set_internal_force(std::vector<double> values);
|
||||
void update_residual();
|
||||
|
||||
const std::vector<double>& acceleration() const
|
||||
{
|
||||
return acceleration_;
|
||||
}
|
||||
IterationState& iteration_state();
|
||||
const IterationState& iteration_state() const;
|
||||
|
||||
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;
|
||||
}
|
||||
void set_element_state(core::ElementId element_id, std::vector<double> state);
|
||||
const std::vector<double>* element_state(core::ElementId element_id) const;
|
||||
|
||||
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);
|
||||
}
|
||||
static std::vector<double> vector_of(int size);
|
||||
static void assign_same_size(std::vector<double>& target, std::vector<double> values);
|
||||
|
||||
std::vector<double> displacement_;
|
||||
std::vector<double> velocity_;
|
||||
|
||||
Reference in New Issue
Block a user