PolyFEM
Loading...
Searching...
No Matches
polyfem::solver::NavierStokesFSIForm Class Reference

Global residual form for ALE Navier–Stokes on velocity, pressure, and mesh-displacement spaces. More...

#include <NavierStokesFSIForm.hpp>

Inheritance diagram for polyfem::solver::NavierStokesFSIForm:
[legend]
Collaboration diagram for polyfem::solver::NavierStokesFSIForm:
[legend]

Public Types

using BodyForceEvaluator = assembler::NavierStokesFSIAssemblerData::BodyForceEvaluator
 
using VelocityTildeUpdater = std::function< void(double time, const Eigen::VectorXd &current_velocity, Eigen::VectorXd &velocity_tilde)>
 

Public Member Functions

 NavierStokesFSIForm (int total_size, int n_velocity_bases, int n_pressure_bases, int n_mesh_displacement_bases, const std::vector< basis::ElementBases > &velocity_bases, const std::vector< basis::ElementBases > &pressure_bases, const std::vector< basis::ElementBases > &mesh_displacement_bases, const std::vector< basis::ElementBases > &geom_bases, const assembler::AssemblyValsCache &velocity_cache, const assembler::AssemblyValsCache &pressure_cache, const assembler::AssemblyValsCache &mesh_displacement_cache, std::vector< std::shared_ptr< assembler::MultiSpacesNLAssembler > > assemblers, const time_integrator::ImplicitTimeIntegrator *velocity_time_integrator, const time_integrator::ImplicitTimeIntegrator *mesh_displacement_time_integrator, double t, double dt, bool is_volume, BodyForceEvaluator body_force_evaluator={})
 
std::string name () const override
 
void update_quantities (double t, const Eigen::VectorXd &x) override
 Update time-dependent fields.
 
void set_velocity_tilde_updater (VelocityTildeUpdater updater)
 
bool is_step_valid (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const override
 Determine if a step from solution x0 to solution x1 is allowed.
 
int velocity_ndof () const
 
int pressure_ndof () const
 
int mesh_displacement_ndof () const
 
- Public Member Functions inherited from polyfem::solver::Form
virtual ~Form ()
 
virtual void init (const Eigen::VectorXd &x)
 Initialize the form.
 
virtual void finish ()
 
virtual double value (const Eigen::VectorXd &x) const
 Compute the value of the form multiplied with the weigth.
 
Eigen::VectorXd value_per_element (const Eigen::VectorXd &x) const
 Compute the value of the form multiplied with the weigth.
 
virtual void first_derivative (const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const
 Compute the first derivative of the value wrt x multiplied with the weigth.
 
void second_derivative (const Eigen::VectorXd &x, StiffnessMatrix &hessian) const
 Compute the second derivative of the value wrt x multiplied with the weigth.
 
virtual double max_step_size (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const
 Determine the maximum step size allowable between the current and next solution.
 
virtual void line_search_begin (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1)
 Initialize variables used during the line search.
 
virtual void line_search_end ()
 Clear variables used during the line search.
 
virtual void post_step (const polysolve::nonlinear::PostStepData &data)
 Update fields after a step in the optimization.
 
virtual void solution_changed (const Eigen::VectorXd &new_x)
 Update cached fields upon a change in the solution.
 
virtual void init_lagging (const Eigen::VectorXd &x)
 Initialize lagged fields TODO: more than one step.
 
virtual void update_lagging (const Eigen::VectorXd &x, const int iter_num)
 Update lagged fields.
 
virtual int max_lagging_iterations () const
 Get the maximum number of lagging iteration allowable.
 
virtual bool uses_lagging () const
 Does this form require lagging?
 
virtual void set_project_to_psd (bool val)
 Set project to psd.
 
bool is_project_to_psd () const
 Get if the form's second derivative is projected to psd.
 
void enable ()
 Enable the form.
 
void disable ()
 Disable the form.
 
void set_enabled (const bool enabled)
 Set if the form is enabled.
 
bool enabled () const
 Determine if the form is enabled.
 
virtual double weight () const
 Get the form's multiplicative constant weight.
 
void set_weight (const double weight)
 Set the form's multiplicative constant weight.
 
virtual bool is_step_collision_free (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const
 Checks if the step is collision free.
 
void set_output_dir (const std::string &output_dir)
 
virtual void set_scale (const double scale)
 sets the scale for the form
 

Protected Member Functions

double value_unweighted (const Eigen::VectorXd &x) const override
 Compute the value of the form.
 
void first_derivative_unweighted (const Eigen::VectorXd &x, Eigen::VectorXd &residual) const override
 Compute the first derivative of the value wrt x.
 
void second_derivative_unweighted (const Eigen::VectorXd &x, StiffnessMatrix &jacobian) const override
 Compute the second derivative of the value wrt x.
 
- Protected Member Functions inherited from polyfem::solver::Form
std::string resolve_output_path (const std::string &path) const
 
virtual Eigen::VectorXd value_per_element_unweighted (const Eigen::VectorXd &x) const
 Compute the value of the form multiplied per element.
 

Private Types

using SpaceValues = std::array< assembler::ElementAssemblyValues, 3 >
 
using LocalCoefficients = std::array< Eigen::VectorXd, 3 >
 

Private Member Functions

void compute_element_values (int element, SpaceValues &vals, QuadratureVector &da) const
 
Eigen::VectorXd gather (const Eigen::VectorXd &x, const assembler::ElementAssemblyValues &vals, int components, int global_offset) const
 
void scatter_local_residual (const SpaceValues &vals, const Eigen::VectorXd &local, Eigen::VectorXd &global) const
 
void scatter_local_block (const SpaceValues &vals, int row_space, int col_space, const Eigen::MatrixXd &local, std::vector< Eigen::Triplet< double > > &entries) const
 
assembler::NavierStokesFSIAssemblerData make_data (const SpaceValues &vals, const LocalCoefficients &x, const LocalCoefficients &x_prev, const QuadratureVector &da, const Eigen::VectorXd &velocity_tilde, const Eigen::VectorXd &mesh_velocity) const
 
bool has_valid_ale_mapping (const Eigen::VectorXd &x) const
 

Private Attributes

const int total_size_
 
const int dim_
 
const std::array< int, 3 > n_bases_
 
const std::array< int, 3 > components_
 
const std::array< int, 3 > global_offsets_
 
const std::array< int, 3 > global_sizes_
 
const std::array< std::reference_wrapper< const std::vector< basis::ElementBases > >, 3 > bases_
 
const std::vector< basis::ElementBases > & geom_bases_
 
const std::array< std::reference_wrapper< const assembler::AssemblyValsCache >, 3 > caches_
 
const std::vector< std::shared_ptr< assembler::MultiSpacesNLAssembler > > assemblers_
 
const time_integrator::ImplicitTimeIntegratorvelocity_time_integrator_
 
const time_integrator::ImplicitTimeIntegratormesh_displacement_time_integrator_
 
double t_
 
const double dt_
 
const bool is_volume_
 
const BodyForceEvaluator body_force_evaluator_
 
VelocityTildeUpdater velocity_tilde_updater_
 
Eigen::VectorXd x_prev_
 

Additional Inherited Members

- Protected Attributes inherited from polyfem::solver::Form
bool project_to_psd_ = false
 If true, the form's second derivative is projected to be positive semidefinite.
 
double weight_ = 1
 weight of the form (e.g., AL penalty weight or Δt²)
 
bool enabled_ = true
 If true, the form is enabled.
 
std::string output_dir_
 

Detailed Description

Global residual form for ALE Navier–Stokes on velocity, pressure, and mesh-displacement spaces.

This form owns all element gather/scatter; MultiSpacesNLAssembler implementations remain strictly local.

Definition at line 67 of file NavierStokesFSIForm.hpp.

Member Typedef Documentation

◆ BodyForceEvaluator

◆ LocalCoefficients

using polyfem::solver::NavierStokesFSIForm::LocalCoefficients = std::array<Eigen::VectorXd, 3>
private

Definition at line 112 of file NavierStokesFSIForm.hpp.

◆ SpaceValues

◆ VelocityTildeUpdater

using polyfem::solver::NavierStokesFSIForm::VelocityTildeUpdater = std::function<void( double time, const Eigen::VectorXd &current_velocity, Eigen::VectorXd &velocity_tilde)>

Definition at line 71 of file NavierStokesFSIForm.hpp.

Constructor & Destructor Documentation

◆ NavierStokesFSIForm()

polyfem::solver::NavierStokesFSIForm::NavierStokesFSIForm ( int  total_size,
int  n_velocity_bases,
int  n_pressure_bases,
int  n_mesh_displacement_bases,
const std::vector< basis::ElementBases > &  velocity_bases,
const std::vector< basis::ElementBases > &  pressure_bases,
const std::vector< basis::ElementBases > &  mesh_displacement_bases,
const std::vector< basis::ElementBases > &  geom_bases,
const assembler::AssemblyValsCache velocity_cache,
const assembler::AssemblyValsCache pressure_cache,
const assembler::AssemblyValsCache mesh_displacement_cache,
std::vector< std::shared_ptr< assembler::MultiSpacesNLAssembler > >  assemblers,
const time_integrator::ImplicitTimeIntegrator velocity_time_integrator,
const time_integrator::ImplicitTimeIntegrator mesh_displacement_time_integrator,
double  t,
double  dt,
bool  is_volume,
BodyForceEvaluator  body_force_evaluator = {} 
)

Definition at line 201 of file NavierStokesFSIForm.cpp.

Member Function Documentation

◆ compute_element_values()

void polyfem::solver::NavierStokesFSIForm::compute_element_values ( int  element,
SpaceValues vals,
QuadratureVector da 
) const
private

Definition at line 246 of file NavierStokesFSIForm.cpp.

References bases_, caches_, da, geom_bases_, is_volume_, quadrature, and vals.

Referenced by first_derivative_unweighted(), has_valid_ale_mapping(), and second_derivative_unweighted().

Here is the caller graph for this function:

◆ first_derivative_unweighted()

void polyfem::solver::NavierStokesFSIForm::first_derivative_unweighted ( const Eigen::VectorXd &  x,
Eigen::VectorXd &  gradv 
) const
overrideprotectedvirtual

Compute the first derivative of the value wrt x.

Parameters
[in]xCurrent solution
[out]gradvOutput gradient of the value wrt x

Implements polyfem::solver::Form.

Definition at line 345 of file NavierStokesFSIForm.cpp.

References assemblers_, components_, compute_element_values(), polyfem::time_integrator::ImplicitTimeIntegrator::compute_velocity(), da, dim_, gather(), geom_bases_, global_offsets_, global_sizes_, make_data(), mesh_displacement_ndof(), mesh_displacement_time_integrator_, scatter_local_residual(), t_, total_size_, vals, velocity_ndof(), velocity_tilde_updater_, velocity_time_integrator_, x, x_prev_, and polyfem::time_integrator::ImplicitTimeIntegrator::x_tilde().

Referenced by value_unweighted().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gather()

Eigen::VectorXd polyfem::solver::NavierStokesFSIForm::gather ( const Eigen::VectorXd &  x,
const assembler::ElementAssemblyValues vals,
int  components,
int  global_offset 
) const
private

Definition at line 268 of file NavierStokesFSIForm.cpp.

References vals, and x.

Referenced by first_derivative_unweighted(), has_valid_ale_mapping(), and second_derivative_unweighted().

Here is the caller graph for this function:

◆ has_valid_ale_mapping()

bool polyfem::solver::NavierStokesFSIForm::has_valid_ale_mapping ( const Eigen::VectorXd &  x) const
private

Definition at line 447 of file NavierStokesFSIForm.cpp.

References compute_element_values(), da, dim_, polyfem::F, gather(), geom_bases_, global_offsets_, vals, and x.

Referenced by is_step_valid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_step_valid()

bool polyfem::solver::NavierStokesFSIForm::is_step_valid ( const Eigen::VectorXd &  x0,
const Eigen::VectorXd &  x1 
) const
overridevirtual

Determine if a step from solution x0 to solution x1 is allowed.

Parameters
x0Current solution
x1Proposed next solution
Returns
True if the step is allowed

Reimplemented from polyfem::solver::Form.

Definition at line 471 of file NavierStokesFSIForm.cpp.

References has_valid_ale_mapping().

Here is the call graph for this function:

◆ make_data()

assembler::NavierStokesFSIAssemblerData polyfem::solver::NavierStokesFSIForm::make_data ( const SpaceValues vals,
const LocalCoefficients x,
const LocalCoefficients x_prev,
const QuadratureVector da,
const Eigen::VectorXd &  velocity_tilde,
const Eigen::VectorXd &  mesh_velocity 
) const
private

Definition at line 282 of file NavierStokesFSIForm.cpp.

References polyfem::time_integrator::ImplicitTimeIntegrator::acceleration_scaling(), body_force_evaluator_, da, dt_, polyfem::time_integrator::ImplicitTimeIntegrator::dv_dx(), mesh_displacement_time_integrator_, polyfem::solver::Form::project_to_psd_, t_, vals, velocity_time_integrator_, and x.

Referenced by first_derivative_unweighted(), and second_derivative_unweighted().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mesh_displacement_ndof()

int polyfem::solver::NavierStokesFSIForm::mesh_displacement_ndof ( ) const
inline

Definition at line 103 of file NavierStokesFSIForm.hpp.

References global_sizes_.

Referenced by first_derivative_unweighted(), and second_derivative_unweighted().

Here is the caller graph for this function:

◆ name()

std::string polyfem::solver::NavierStokesFSIForm::name ( ) const
inlineoverridevirtual

Implements polyfem::solver::Form.

Definition at line 96 of file NavierStokesFSIForm.hpp.

◆ pressure_ndof()

int polyfem::solver::NavierStokesFSIForm::pressure_ndof ( ) const
inline

Definition at line 102 of file NavierStokesFSIForm.hpp.

References global_sizes_.

◆ scatter_local_block()

void polyfem::solver::NavierStokesFSIForm::scatter_local_block ( const SpaceValues vals,
int  row_space,
int  col_space,
const Eigen::MatrixXd &  local,
std::vector< Eigen::Triplet< double > > &  entries 
) const
private

Definition at line 317 of file NavierStokesFSIForm.cpp.

References components_, entries, global_offsets_, vals, and polyfem::solver::Form::value().

Referenced by second_derivative_unweighted().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scatter_local_residual()

void polyfem::solver::NavierStokesFSIForm::scatter_local_residual ( const SpaceValues vals,
const Eigen::VectorXd &  local,
Eigen::VectorXd &  global 
) const
private

Definition at line 303 of file NavierStokesFSIForm.cpp.

References components_, global_offsets_, and vals.

Referenced by first_derivative_unweighted().

Here is the caller graph for this function:

◆ second_derivative_unweighted()

void polyfem::solver::NavierStokesFSIForm::second_derivative_unweighted ( const Eigen::VectorXd &  x,
StiffnessMatrix hessian 
) const
overrideprotectedvirtual

Compute the second derivative of the value wrt x.

Parameters
[in]xCurrent solution
[out]hessianOutput Hessian of the value wrt x

Implements polyfem::solver::Form.

Definition at line 392 of file NavierStokesFSIForm.cpp.

References assemblers_, components_, compute_element_values(), polyfem::time_integrator::ImplicitTimeIntegrator::compute_velocity(), da, dim_, entries, gather(), geom_bases_, global_offsets_, global_sizes_, make_data(), mesh_displacement_ndof(), mesh_displacement_time_integrator_, scatter_local_block(), t_, total_size_, vals, velocity_ndof(), velocity_tilde_updater_, velocity_time_integrator_, x, x_prev_, and polyfem::time_integrator::ImplicitTimeIntegrator::x_tilde().

Here is the call graph for this function:

◆ set_velocity_tilde_updater()

void polyfem::solver::NavierStokesFSIForm::set_velocity_tilde_updater ( VelocityTildeUpdater  updater)
inline

Definition at line 98 of file NavierStokesFSIForm.hpp.

References velocity_tilde_updater_.

◆ update_quantities()

void polyfem::solver::NavierStokesFSIForm::update_quantities ( double  t,
const Eigen::VectorXd &  x 
)
overridevirtual

Update time-dependent fields.

Parameters
tCurrent time
xCurrent solution at time t

Reimplemented from polyfem::solver::Form.

Definition at line 440 of file NavierStokesFSIForm.cpp.

References t_, total_size_, x, and x_prev_.

◆ value_unweighted()

double polyfem::solver::NavierStokesFSIForm::value_unweighted ( const Eigen::VectorXd &  x) const
overrideprotectedvirtual

Compute the value of the form.

Parameters
xCurrent solution
Returns
Computed value

Implements polyfem::solver::Form.

Definition at line 385 of file NavierStokesFSIForm.cpp.

References first_derivative_unweighted(), and x.

Here is the call graph for this function:

◆ velocity_ndof()

int polyfem::solver::NavierStokesFSIForm::velocity_ndof ( ) const
inline

Definition at line 101 of file NavierStokesFSIForm.hpp.

References global_sizes_.

Referenced by first_derivative_unweighted(), and second_derivative_unweighted().

Here is the caller graph for this function:

Member Data Documentation

◆ assemblers_

const std::vector<std::shared_ptr<assembler::MultiSpacesNLAssembler> > polyfem::solver::NavierStokesFSIForm::assemblers_
private

◆ bases_

const std::array<std::reference_wrapper<const std::vector<basis::ElementBases> >, 3> polyfem::solver::NavierStokesFSIForm::bases_
private

Definition at line 138 of file NavierStokesFSIForm.hpp.

Referenced by compute_element_values().

◆ body_force_evaluator_

const BodyForceEvaluator polyfem::solver::NavierStokesFSIForm::body_force_evaluator_
private

Definition at line 147 of file NavierStokesFSIForm.hpp.

Referenced by make_data().

◆ caches_

const std::array<std::reference_wrapper<const assembler::AssemblyValsCache>, 3> polyfem::solver::NavierStokesFSIForm::caches_
private

Definition at line 140 of file NavierStokesFSIForm.hpp.

Referenced by compute_element_values().

◆ components_

const std::array<int, 3> polyfem::solver::NavierStokesFSIForm::components_
private

◆ dim_

const int polyfem::solver::NavierStokesFSIForm::dim_
private

◆ dt_

const double polyfem::solver::NavierStokesFSIForm::dt_
private

Definition at line 145 of file NavierStokesFSIForm.hpp.

Referenced by make_data().

◆ geom_bases_

const std::vector<basis::ElementBases>& polyfem::solver::NavierStokesFSIForm::geom_bases_
private

◆ global_offsets_

const std::array<int, 3> polyfem::solver::NavierStokesFSIForm::global_offsets_
private

◆ global_sizes_

const std::array<int, 3> polyfem::solver::NavierStokesFSIForm::global_sizes_
private

◆ is_volume_

const bool polyfem::solver::NavierStokesFSIForm::is_volume_
private

Definition at line 146 of file NavierStokesFSIForm.hpp.

Referenced by compute_element_values().

◆ mesh_displacement_time_integrator_

const time_integrator::ImplicitTimeIntegrator* polyfem::solver::NavierStokesFSIForm::mesh_displacement_time_integrator_
private

◆ n_bases_

const std::array<int, 3> polyfem::solver::NavierStokesFSIForm::n_bases_
private

Definition at line 134 of file NavierStokesFSIForm.hpp.

◆ t_

double polyfem::solver::NavierStokesFSIForm::t_
private

◆ total_size_

const int polyfem::solver::NavierStokesFSIForm::total_size_
private

◆ velocity_tilde_updater_

VelocityTildeUpdater polyfem::solver::NavierStokesFSIForm::velocity_tilde_updater_
private

◆ velocity_time_integrator_

const time_integrator::ImplicitTimeIntegrator* polyfem::solver::NavierStokesFSIForm::velocity_time_integrator_
private

◆ x_prev_

Eigen::VectorXd polyfem::solver::NavierStokesFSIForm::x_prev_
private

The documentation for this class was generated from the following files: