33 const int n_pressure_bases,
34 const std::vector<basis::ElementBases> &bases,
35 const std::vector<basis::ElementBases> &pressure_bases,
36 const std::vector<basis::ElementBases> &gbases,
43 const std::vector<int> &boundary_nodes,
44 const bool use_avg_pressure,
45 const int problem_dim,
47 const Eigen::MatrixXd &rhs, Eigen::VectorXd &
x)
49 assert(velocity_assembler.
name() ==
"NavierStokes");
52 logger().debug(
"\tinternal solver {}", solver->name());
54 const int precond_num = problem_dim * n_bases;
60 StiffnessMatrix velocity_stiffness, mixed_stiffness, pressure_stiffness;
61 velocity_stokes_assembler.
assemble(is_volume, n_bases, bases, gbases, ass_vals_cache, 0, velocity_stiffness);
62 mixed_assembler.
assemble(is_volume, n_pressure_bases, n_bases, pressure_bases, bases, gbases, pressure_ass_vals_cache, ass_vals_cache, 0, mixed_stiffness);
63 pressure_assembler.
assemble(is_volume, n_pressure_bases, pressure_bases, gbases, pressure_ass_vals_cache, 0, pressure_stiffness);
66 velocity_stiffness, mixed_stiffness, pressure_stiffness,
70 logger().debug(
"\tStokes matrix assembly time {}s", time.getElapsedTimeInSec());
74 logger().info(
"{}...", solver->name());
76 Eigen::VectorXd b = rhs;
77 dirichlet_solve(*solver, stoke_stiffness, b, boundary_nodes,
x, precond_num,
"",
false,
true, use_avg_pressure);
81 logger().debug(
"\tStokes solve time {}s", time.getElapsedTimeInSec());
82 logger().debug(
"\tStokes solver error: {}", (stoke_stiffness *
x - b).norm());
84 std::vector<bool> zero_col(stoke_stiffness.cols(),
true);
85 for (
int k = 0; k < stoke_stiffness.outerSize(); ++k)
87 for (StiffnessMatrix::InnerIterator it(stoke_stiffness, k); it; ++it)
89 if (fabs(it.value()) > 1e-12)
90 zero_col[it.col()] =
false;
93 std::vector<int> skipping;
94 for (
int i = 0; i < zero_col.size(); ++i)
98 skipping.push_back(i);
106 double nlres_norm = 0;
119 velocity_stiffness, mixed_stiffness, pressure_stiffness, b, 1e-3, solver, nlres_norm,
x);
131 velocity_stiffness, mixed_stiffness, pressure_stiffness, b,
gradNorm, solver, nlres_norm,
x);
147 const std::vector<int> &skipping,
149 const int n_pressure_bases,
150 const std::vector<basis::ElementBases> &bases,
151 const std::vector<basis::ElementBases> &gbases,
154 const std::vector<int> &boundary_nodes,
155 const bool use_avg_pressure,
156 const int problem_dim,
157 const bool is_volume,
159 const Eigen::VectorXd &rhs,
const double grad_norm,
160 std::unique_ptr<linear::Solver> &solver,
double &nlres_norm,
165 const int precond_num = problem_dim * n_bases;
173 velocity_assembler.
assemble_hessian(is_volume, n_bases,
false, bases, gbases, ass_vals_cache, 0, 0,
x, Eigen::MatrixXd(), mat_cache, nl_matrix);
175 velocity_stiffness + nl_matrix, mixed_stiffness, pressure_stiffness,
179 logger().debug(
"\tNavier Stokes assembly time {}s", time.getElapsedTimeInSec());
181 Eigen::VectorXd nlres = -(total_matrix *
x) + rhs;
182 for (
int i : boundary_nodes)
184 for (
int i : skipping)
187 nlres_norm = nlres.norm();
188 logger().debug(
"\tInitial residula norm {}", nlres_norm);
192 while (nlres_norm > grad_norm && it <
iterations)
200 velocity_assembler.
assemble_hessian(is_volume, n_bases,
false, bases, gbases, ass_vals_cache, 0, 0,
x, Eigen::MatrixXd(), mat_cache, nl_matrix);
202 velocity_stiffness + nl_matrix, mixed_stiffness, pressure_stiffness,
205 dirichlet_solve(*solver, total_matrix, nlres, boundary_nodes, dx, precond_num,
"",
false,
true, use_avg_pressure);
210 logger().debug(
"\tinverting time {}s", time.getElapsedTimeInSec());
211 logger().debug(
"\tinverting error: {}", (total_matrix * dx - nlres).norm());
218 velocity_assembler.
assemble_hessian(is_volume, n_bases,
false, bases, gbases, ass_vals_cache, 0, 0,
x, Eigen::MatrixXd(), mat_cache, nl_matrix);
220 velocity_stiffness + nl_matrix, mixed_stiffness, pressure_stiffness,
223 logger().debug(
"\tassembly time {}s", time.getElapsedTimeInSec());
226 nlres = -(total_matrix *
x) + rhs;
227 for (
int i : boundary_nodes)
229 for (
int i : skipping)
231 nlres_norm = nlres.norm();
233 logger().debug(
"\titer: {}, ||g||_2 = {}, ||step|| = {}\n",
234 it, nlres_norm, dx.norm());
virtual void assemble(const bool is_volume, const int n_basis, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const AssemblyValsCache &cache, const double t, StiffnessMatrix &stiffness, const bool is_mass=false) const
static void merge_mixed_matrices(const int n_bases, const int n_pressure_bases, const int problem_dim, const bool add_average, const StiffnessMatrix &velocity_stiffness, const StiffnessMatrix &mixed_stiffness, const StiffnessMatrix &pressure_stiffness, StiffnessMatrix &stiffness)
utility to merge 3 blocks of mixed matrices, A=velocity_stiffness, B=mixed_stiffness,...
void assemble(const bool is_volume, const int n_psi_basis, const int n_phi_basis, const std::vector< basis::ElementBases > &psi_bases, const std::vector< basis::ElementBases > &phi_bases, const std::vector< basis::ElementBases > &gbases, const AssemblyValsCache &psi_cache, const AssemblyValsCache &phi_cache, const double t, StiffnessMatrix &stiffness) const
void minimize(const int n_bases, const int n_pressure_bases, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &pressure_bases, const std::vector< basis::ElementBases > &gbases, const assembler::Assembler &velocity_stokes_assembler, assembler::NavierStokesVelocity &velocity_assembler, const assembler::MixedAssembler &mixed_assembler, const assembler::Assembler &pressure_assembler, const assembler::AssemblyValsCache &ass_vals_cache, const assembler::AssemblyValsCache &pressure_ass_vals_cache, const std::vector< int > &boundary_nodes, const bool use_avg_pressure, const int problem_dim, const bool is_volume, const Eigen::MatrixXd &rhs, Eigen::VectorXd &x)
int minimize_aux(const bool is_picard, const std::vector< int > &skipping, const int n_bases, const int n_pressure_bases, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, assembler::NavierStokesVelocity &velocity_assembler, const assembler::AssemblyValsCache &ass_vals_cache, const std::vector< int > &boundary_nodes, const bool use_avg_pressure, const int problem_dim, const bool is_volume, const StiffnessMatrix &velocity_stiffness, const StiffnessMatrix &mixed_stiffness, const StiffnessMatrix &pressure_stiffness, const Eigen::VectorXd &rhs, const double grad_norm, std::unique_ptr< polysolve::linear::Solver > &solver, double &nlres_norm, Eigen::VectorXd &x)