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 void init(const std::string &formulation, const Units &units, const json &args, const std::string &out_path) override;
35 void save_json(const Eigen::MatrixXd &solution, std::ostream &out) const override;
36 void export_data(const Eigen::MatrixXd &solution) const override;
37 io::OutputSpace output_space() const override;
38 io::OutStatsData compute_errors(const Eigen::MatrixXd &solution) override;
39
40 std::vector<io::OutputField> output_fields(
41 const io::OutputSample &sample,
42 const Eigen::MatrixXd &solution,
43 const io::OutputFieldOptions &options) const override;
44
45 protected:
46 void reset() override;
47 void load_mesh(const mesh::Mesh &mesh, const json &args) override;
48 void build_basis(mesh::Mesh &mesh, const bool iso_parametric, const json &args) override;
49 void assemble_rhs(const mesh::Mesh &mesh) override;
50 void assemble_mass_mat(const mesh::Mesh &mesh, const json &args) override;
51
52 int primary_ndof() const;
53 int pressure_block_size() const;
54 int stacked_ndof() const;
55
56 void prepare_initial_solution(Eigen::MatrixXd &sol) const;
57 void split_solution(const Eigen::MatrixXd &stacked, Eigen::MatrixXd &primary, Eigen::MatrixXd &pressure) const;
58 void build_stiffness_mat(StiffnessMatrix &stiffness);
60 const std::unique_ptr<polysolve::linear::Solver> &solver,
62 Eigen::VectorXd &b,
63 const bool compute_spectrum,
64 Eigen::MatrixXd &sol);
65
66 void build_rhs_assembler() override;
67
72
75
80
81 std::shared_ptr<assembler::RhsAssembler> rhs_assembler_;
82
85
86 double avg_mass_ = 0;
87 Eigen::MatrixXd rhs_;
88
89 std::shared_ptr<assembler::Assembler> primary_assembler_ = nullptr;
90 std::shared_ptr<assembler::Mass> mass_assembler_ = nullptr;
91 std::shared_ptr<assembler::HRZMass> pure_mass_assembler_ = nullptr;
92 std::shared_ptr<assembler::MixedAssembler> mixed_assembler_ = nullptr;
93 std::shared_ptr<assembler::Assembler> pressure_assembler_ = nullptr;
94 bool use_avg_pressure = true;
95 double t0 = 0;
96 int time_steps = 0;
97 double dt = 0;
98 std::shared_ptr<time_integrator::ImplicitTimeIntegrator> time_integrator;
99 };
100
102 {
103 public:
104 std::string name() const override { return "Stokes"; }
105
106 private:
107 void solve_problem(
108 Eigen::MatrixXd &sol,
109 const InitialConditionOverride *initial_condition_override,
110 const ForwardStepCallback &post_step) override;
111 void solve_static_linear(Eigen::MatrixXd &sol);
112 void solve_transient_linear(Eigen::MatrixXd &sol);
113 };
114
116 {
117 public:
118 std::string name() const override { return "NavierStokes"; }
119
120 private:
121 void solve_problem(
122 Eigen::MatrixXd &sol,
123 const InitialConditionOverride *initial_condition_override,
124 const ForwardStepCallback &post_step) override;
125 void build_forms(Eigen::MatrixXd &sol, double t);
126 void solve_nonlinear_step(int step, Eigen::MatrixXd &sol);
128
129 Eigen::MatrixXd velocity_rhs_;
130 std::vector<std::shared_ptr<solver::Form>> forms_;
131 std::vector<std::shared_ptr<solver::AugmentedLagrangianForm>> al_forms_;
132 std::shared_ptr<solver::NLProblem> nl_problem_;
133 std::shared_ptr<solver::StackedForm> stacked_form_;
134 std::shared_ptr<solver::NavierStokesForm> navier_stokes_form_;
135 std::shared_ptr<solver::MixedLinearForm> mixed_form_;
136 std::shared_ptr<solver::AveragePressureForm> average_pressure_form_;
137 std::shared_ptr<solver::BodyForm> body_form_;
138 std::shared_ptr<solver::InertiaForm> inertia_form_;
139 };
140} // 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:49
A finite-element space for one scalar- or vector-valued field.
Definition FESpace.hpp:59
void assemble_rhs(const mesh::Mesh &mesh) override
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
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_
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.
std::function< void(int step, const Eigen::MatrixXd &solution)> ForwardStepCallback
Definition VarForm.hpp:49
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:152