PolyFEM
Loading...
Searching...
No Matches
FluidVarForm.hpp
Go to the documentation of this file.
1#pragma once
2
4
8
9namespace polysolve::linear
10{
11 class Solver;
12}
13
14namespace polyfem::solver
15{
16 class AugmentedLagrangianForm;
17 class AveragePressureForm;
18 class BodyForm;
19 class InertiaForm;
20 class Form;
21 class MixedLinearForm;
22 class NavierStokesForm;
23 class NLProblem;
24 class StackedForm;
25} // namespace polyfem::solver
26
27namespace polyfem::varform
28{
29 class FluidVarForm : public VarForm
30 {
32
33 public:
34 using VarForm::VarForm;
35 void init(const std::string &formulation, const Units &units, const json &args, const std::string &out_path) override;
36 void save_json(const Eigen::MatrixXd &solution, std::ostream &out) const override;
37 void export_data(const Eigen::MatrixXd &solution) const override;
38 io::OutputSpace output_space() const override;
39 io::OutStatsData compute_errors(const Eigen::MatrixXd &solution) override;
40 void serialize_checkpoint(io::CheckpointWriter &writer, const Eigen::MatrixXd &solution, const io::CheckpointMetadata &metadata) const override;
41 void deserialize_checkpoint(const io::CheckpointReader &reader, Eigen::MatrixXd &solution) override;
42
43 std::vector<io::OutputField> output_fields(
44 const io::OutputSample &sample,
45 const Eigen::MatrixXd &solution,
46 const io::OutputFieldOptions &options) const override;
47
48 protected:
50 const Eigen::MatrixXd &solution, const io::OutGeometryData::ExportOptions &opts,
51 const io::OutputSpace &space, double time, double dt) const override;
52
53 void reset() override;
54 void load_mesh(const mesh::Mesh &mesh, const json &args) override;
55 void build_basis(mesh::Mesh &mesh, const bool iso_parametric, const json &args) override;
56 void assemble_rhs(const mesh::Mesh &mesh) override;
57 void assemble_mass_mat(const mesh::Mesh &mesh, const json &args) override;
58
59 int primary_ndof() const;
60 int pressure_block_size() const;
61 int stacked_ndof() const;
62
63 void prepare_initial_solution(Eigen::MatrixXd &sol) const;
64 void split_solution(const Eigen::MatrixXd &stacked, Eigen::MatrixXd &primary, Eigen::MatrixXd &pressure) const;
65 void build_stiffness_mat(StiffnessMatrix &stiffness);
67 const std::unique_ptr<polysolve::linear::Solver> &solver,
69 Eigen::VectorXd &b,
70 const bool compute_spectrum,
71 Eigen::MatrixXd &sol);
72
73 void build_rhs_assembler() override;
74
79
82
87
88 std::shared_ptr<assembler::RhsAssembler> rhs_assembler_;
89
92
93 double avg_mass_ = 0;
94 Eigen::MatrixXd rhs_;
95
96 std::shared_ptr<assembler::Assembler> primary_assembler_ = nullptr;
97 std::shared_ptr<assembler::Mass> mass_assembler_ = nullptr;
98 std::shared_ptr<assembler::HRZMass> pure_mass_assembler_ = nullptr;
99 std::shared_ptr<assembler::MixedAssembler> mixed_assembler_ = nullptr;
100 std::shared_ptr<assembler::Assembler> pressure_assembler_ = nullptr;
101 bool use_avg_pressure = true;
102 double t0 = 0;
103 int time_steps = 0;
104 double dt = 0;
105 std::shared_ptr<time_integrator::ImplicitTimeIntegrator> time_integrator;
106 };
107
109 {
110 public:
111 using FluidVarForm::FluidVarForm;
112 std::string name() const override { return "Stokes"; }
113
114 private:
115 void solve_problem(
116 Eigen::MatrixXd &sol,
117 const InitialConditionOverride *initial_condition_override,
118 const ForwardStepCallback &post_step) override;
119 void solve_static_linear(Eigen::MatrixXd &sol);
120 void solve_transient_linear(Eigen::MatrixXd &sol);
121 };
122
124 {
125 public:
126 using FluidVarForm::FluidVarForm;
127 std::string name() const override { return "NavierStokes"; }
128
129 private:
130 void solve_problem(
131 Eigen::MatrixXd &sol,
132 const InitialConditionOverride *initial_condition_override,
133 const ForwardStepCallback &post_step) override;
134 void build_forms(Eigen::MatrixXd &sol, double t);
135 void solve_nonlinear_step(int step, Eigen::MatrixXd &sol);
137
138 Eigen::MatrixXd velocity_rhs_;
139 std::vector<std::shared_ptr<solver::Form>> forms_;
140 std::vector<std::shared_ptr<solver::AugmentedLagrangianForm>> al_forms_;
141 std::shared_ptr<solver::NLProblem> nl_problem_;
142 std::shared_ptr<solver::StackedForm> stacked_form_;
143 std::shared_ptr<solver::NavierStokesForm> navier_stokes_form_;
144 std::shared_ptr<solver::MixedLinearForm> mixed_form_;
145 std::shared_ptr<solver::AveragePressureForm> average_pressure_form_;
146 std::shared_ptr<solver::BodyForm> body_form_;
147 std::shared_ptr<solver::InertiaForm> inertia_form_;
148 };
149} // namespace polyfem::varform
Caches basis evaluation and geometric mapping at every element.
all stats from polyfem
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:77
A finite-element space for one scalar- or vector-valued field.
Definition FESpace.hpp:59
void assemble_rhs(const mesh::Mesh &mesh) override
io::OutputFieldFunction snapshot_output_fields(const Eigen::MatrixXd &solution, const io::OutGeometryData::ExportOptions &opts, const io::OutputSpace &space, double time, double dt) const override
Capture mutable timestep data for deferred field evaluation.
assembler::AssemblyValsCache pressure_ass_vals_cache_
void assemble_mass_mat(const mesh::Mesh &mesh, const json &args) override
void build_basis(mesh::Mesh &mesh, const bool iso_parametric, const json &args) override
void serialize_checkpoint(io::CheckpointWriter &writer, const Eigen::MatrixXd &solution, const io::CheckpointMetadata &metadata) const override
std::shared_ptr< assembler::HRZMass > pure_mass_assembler_
io::OutputSpace output_space() const override
Get the output space of the variational formulation, for output purposes.
VarFormBoundaryState pressure_boundary_
void init(const std::string &formulation, const Units &units, const json &args, const std::string &out_path) override
Initialize the variational formulation with the given parameters.
std::shared_ptr< time_integrator::ImplicitTimeIntegrator > time_integrator
assembler::AssemblyValsCache ass_vals_cache_
void split_solution(const Eigen::MatrixXd &stacked, Eigen::MatrixXd &primary, Eigen::MatrixXd &pressure) const
std::shared_ptr< assembler::Assembler > primary_assembler_
void deserialize_checkpoint(const io::CheckpointReader &reader, Eigen::MatrixXd &solution) override
assembler::AssemblyValsCache pure_mass_ass_vals_cache_
std::shared_ptr< assembler::RhsAssembler > rhs_assembler_
void export_data(const Eigen::MatrixXd &solution) const override
void prepare_initial_solution(Eigen::MatrixXd &sol) const
VarFormBoundaryState boundary_
void save_json(const Eigen::MatrixXd &solution, std::ostream &out) const override
Save the solution to a JSON file, for output purposes.
io::OutStatsData compute_errors(const Eigen::MatrixXd &solution) override
Get the error statistics of the variational formulation, for output purposes.
std::shared_ptr< assembler::Mass > mass_assembler_
friend class polyfem::test::VarFormTestAccess
void solve_linear_system(const std::unique_ptr< polysolve::linear::Solver > &solver, StiffnessMatrix &A, Eigen::VectorXd &b, const bool compute_spectrum, Eigen::MatrixXd &sol)
void build_stiffness_mat(StiffnessMatrix &stiffness)
std::vector< io::OutputField > output_fields(const io::OutputSample &sample, const Eigen::MatrixXd &solution, const io::OutputFieldOptions &options) const override
Get the output fields of the variational formulation, for output purposes.
std::shared_ptr< assembler::Assembler > pressure_assembler_
assembler::AssemblyValsCache mass_ass_vals_cache_
std::shared_ptr< assembler::MixedAssembler > mixed_assembler_
void load_mesh(const mesh::Mesh &mesh, const json &args) override
std::shared_ptr< solver::BodyForm > body_form_
void build_forms(Eigen::MatrixXd &sol, double t)
std::shared_ptr< solver::NavierStokesForm > navier_stokes_form_
std::string name() const override
Get the name of the variational formulation.
void solve_problem(Eigen::MatrixXd &sol, const InitialConditionOverride *initial_condition_override, const ForwardStepCallback &post_step) override
std::shared_ptr< solver::MixedLinearForm > mixed_form_
std::shared_ptr< solver::AveragePressureForm > average_pressure_form_
std::shared_ptr< solver::InertiaForm > inertia_form_
std::vector< std::shared_ptr< solver::Form > > forms_
void solve_nonlinear_step(int step, Eigen::MatrixXd &sol)
std::shared_ptr< solver::StackedForm > stacked_form_
std::vector< std::shared_ptr< solver::AugmentedLagrangianForm > > al_forms_
std::shared_ptr< solver::NLProblem > nl_problem_
void solve_transient_linear(Eigen::MatrixXd &sol)
void solve_static_linear(Eigen::MatrixXd &sol)
void solve_problem(Eigen::MatrixXd &sol, const InitialConditionOverride *initial_condition_override, const ForwardStepCallback &post_step) override
std::string name() const override
Get the name of the variational formulation.
VarForm(const io::ResourceIO &resources)
Definition VarForm.hpp:66
std::function< std::vector< OutputField >(const OutputSample &)> OutputFieldFunction
std::function< void(int step, const Eigen::MatrixXd &solution)> ForwardStepCallback
Definition VarForm.hpp:59
nlohmann::json json
Definition Common.hpp:9
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:24
Temporary compatibility wrapper for boundary data belonging to one FE space.
Definition FESpace.hpp:156