8 using namespace assembler;
10 using namespace utils;
14 bool read_initial_x_from_file(
15 const std::string &state_path,
16 const std::string &x_name,
18 const Eigen::VectorXi &in_node_to_node,
22 if (state_path.empty())
27 logger().debug(
"Unable to read initial {} from file ({})", x_name, state_path);
33 const int ndof = in_node_to_node.size() *
dim;
41 bool check_override_shape(
const Eigen::MatrixXd &
override,
const int ndof)
43 if (
override.rows() != ndof)
47 if (
override.cols() < 1)
63 sol.conservativeResize(Eigen::NoChange, 1);
67 const int actual_dim =
problem->is_scalar() ? 1 :
mesh->dimension();
69 pressure.resize(0, 0);
70 sol.conservativeResize(
rhs.size(), sol.cols());
73 sol(sol.size() - 1) = 0;
78 if (
problem->is_time_dependent())
87 if (ic_override && ic_override->
solution.size() != 0)
89 if (!check_override_shape(ic_override->
solution,
ndof()))
96 logger().info(
"Using runtime override for initial solution.");
101 const bool was_solution_loaded = read_initial_x_from_file(
104 mesh->dimension(), solution);
106 if (!was_solution_loaded)
108 if (
problem->is_time_dependent())
112 solution.resize(
rhs.size(), 1);
123 if (ic_override && ic_override->
velocity.size() != 0)
125 if (!check_override_shape(ic_override->
velocity,
ndof()))
132 logger().info(
"Using runtime override for initial velocity.");
137 const bool was_velocity_loaded = read_initial_x_from_file(
140 mesh->dimension(), velocity);
142 if (!was_velocity_loaded)
150 if (ic_override !=
nullptr && ic_override->
acceleration.size() != 0)
159 logger().info(
"Using runtime override for initial acceleration.");
164 const bool was_acceleration_loaded = read_initial_x_from_file(
167 mesh->dimension(), acceleration);
169 if (!was_acceleration_loaded)
#define POLYFEM_SCOPED_TIMER(...)
Runtime override for initial-condition histories.
Eigen::MatrixXd solution
ndof by H (history size) matrix where each col is solution from a time step.
Eigen::MatrixXd acceleration
ndof by H (history size) matrix where each col is acceleration from a time step.
Eigen::MatrixXd velocity
ndof by H (history size) matrix where each col is velocity from a time step.
int n_bases
number of bases
int n_pressure_bases
number of pressure bases
void sol_to_pressure(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
splits the solution in solution and pressure for mixed problems
Eigen::VectorXi in_node_to_node
Inpute nodes (including high-order) to polyfem nodes, only for isoparametric.
void initial_velocity(Eigen::MatrixXd &velocity, const InitialConditionOverride *ic_override=nullptr) const
Load or compute the initial velocity.
void save_timestep(const double time, const int t, const double t0, const double dt, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure)
saves a timestep
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
std::shared_ptr< assembler::Problem > problem
current problem, it contains rhs and bc
json args
main input arguments containing all defaults
void initial_acceleration(Eigen::MatrixXd &acceleration, const InitialConditionOverride *ic_override=nullptr) const
Load or compute the initial acceleration.
void initial_solution(Eigen::MatrixXd &solution, const InitialConditionOverride *ic_override=nullptr) const
Load or compute the initial solution.
void init_solve(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure, const InitialConditionOverride *ic_override=nullptr)
initialize solver
std::shared_ptr< assembler::RhsAssembler > build_rhs_assembler() const
build a RhsAssembler for the problem
std::string resolve_input_path(const std::string &path, const bool only_if_exists=false) const
Resolve input path relative to root_path() if the path is not absolute.
solver::SolveData solve_data
timedependent stuff cached
std::shared_ptr< assembler::MixedAssembler > mixed_assembler
Eigen::MatrixXd rhs
System right-hand side.
std::shared_ptr< assembler::RhsAssembler > rhs_assembler
bool read_matrix(const std::string &path, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &mat)
Reads a matrix from a file. Determines the file format based on the path's extension.
Eigen::MatrixXd reorder_matrix(const Eigen::MatrixXd &in, const Eigen::VectorXi &in_to_out, int out_blocks=-1, const int block_size=1)
Reorder row blocks in a matrix.
spdlog::logger & logger()
Retrieves the current logger.
void log_and_throw_adjoint_error(const std::string &msg)