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

Form representing body forces. More...

#include <BodyForm.hpp>

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

Public Member Functions

 BodyForm (const int ndof, const int n_pressure_bases, const std::vector< int > &boundary_nodes, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< mesh::LocalBoundary > &local_neumann_boundary, const int n_boundary_samples, const Eigen::MatrixXd &rhs, const assembler::RhsAssembler &rhs_assembler, const assembler::Density &density, const bool is_formulation_mixed, const bool is_time_dependent)
 Construct a new Body Form object.
 
std::string name () const override
 
void update_quantities (const double t, const Eigen::VectorXd &x) override
 Update time dependent quantities.
 
void force_shape_derivative (const int n_verts, const double t, const Eigen::MatrixXd &x, const Eigen::MatrixXd &adjoint, Eigen::VectorXd &term)
 Compute the derivative of the force wrt vertex positions, then multiply the resulting matrix with adjoint_sol.
 
void hessian_wrt_u_prev (const Eigen::VectorXd &u_prev, const double t, StiffnessMatrix &hessian) const
 
- Public Member Functions inherited from polyfem::solver::Form
virtual ~Form ()
 
virtual void init (const Eigen::VectorXd &x)
 Initialize the form.
 
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 bool is_step_valid (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const
 Determine if a step from solution x0 to solution x1 is allowed.
 
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?
 
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)
 

Protected Member Functions

double value_unweighted (const Eigen::VectorXd &x) const override
 Compute the value of the body force form.
 
void first_derivative_unweighted (const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
 Compute the first derivative of the value wrt x.
 
void second_derivative_unweighted (const Eigen::VectorXd &x, StiffnessMatrix &hessian) 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 Member Functions

void update_current_rhs (const Eigen::VectorXd &x)
 Update current_rhs.
 

Private Attributes

double t_
 Current time.
 
const int ndof_
 Number of degrees of freedom.
 
const int n_pressure_bases_
 
Eigen::MatrixXd x_prev_
 Cached previous solution.
 
const std::vector< int > & boundary_nodes_
 
const std::vector< mesh::LocalBoundary > & local_boundary_
 
const std::vector< mesh::LocalBoundary > & local_neumann_boundary_
 
const int n_boundary_samples_
 
const Eigen::MatrixXd & rhs_
 static RHS for the current time
 
const assembler::RhsAssemblerrhs_assembler_
 Reference to the RHS assembler.
 
const assembler::Densitydensity_
 
bool is_formulation_mixed_
 True if the formulation is mixed.
 
Eigen::MatrixXd current_rhs_
 Cached RHS for the current time.
 

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

Form representing body forces.

Definition at line 14 of file BodyForm.hpp.

Constructor & Destructor Documentation

◆ BodyForm()

polyfem::solver::BodyForm::BodyForm ( const int  ndof,
const int  n_pressure_bases,
const std::vector< int > &  boundary_nodes,
const std::vector< mesh::LocalBoundary > &  local_boundary,
const std::vector< mesh::LocalBoundary > &  local_neumann_boundary,
const int  n_boundary_samples,
const Eigen::MatrixXd &  rhs,
const assembler::RhsAssembler rhs_assembler,
const assembler::Density density,
const bool  is_formulation_mixed,
const bool  is_time_dependent 
)

Construct a new Body Form object.

Parameters
stateReference to the simulation state
rhs_assemblerReference to the right hand side assembler

Definition at line 35 of file BodyForm.cpp.

References t_, and update_current_rhs().

Here is the call graph for this function:

Member Function Documentation

◆ first_derivative_unweighted()

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

Compute the first derivative of the value wrt x.

Parameters
[in]xVector containing the current solution
[out]gradvOutput gradient of the value wrt x

Implements polyfem::solver::Form.

Definition at line 67 of file BodyForm.cpp.

References current_rhs_.

◆ force_shape_derivative()

void polyfem::solver::BodyForm::force_shape_derivative ( const int  n_verts,
const double  t,
const Eigen::MatrixXd &  x,
const Eigen::MatrixXd &  adjoint,
Eigen::VectorXd &  term 
)

Compute the derivative of the force wrt vertex positions, then multiply the resulting matrix with adjoint_sol.

Parameters
[in]n_vertsNumber of vertices
[in]xCurrent solution
[in]adjointCurrent adjoint solution
[out]termDerivative of force multiplied by the adjoint

Definition at line 106 of file BodyForm.cpp.

References polyfem::assembler::RhsAssembler::ass_vals_cache(), polyfem::assembler::RhsAssembler::assembler(), polyfem::assembler::RhsAssembler::bases(), boundary_nodes_, polyfem::assembler::AssemblyValsCache::compute(), polyfem::utils::create_thread_storage(), density_, polyfem::mesh::Mesh::dimension(), polyfem::assembler::RhsAssembler::gbases(), polyfem::utils::get_local_thread_storage(), gvals, polyfem::io::Evaluator::interpolate_at_local_vals(), polyfem::assembler::Problem::is_scalar(), polyfem::mesh::Mesh::is_volume(), local_neumann_boundary_, polyfem::utils::maybe_parallel_for(), polyfem::assembler::RhsAssembler::mesh(), polyfem::assembler::RhsAssembler::problem(), quadrature, polyfem::assembler::Problem::rhs(), rhs_assembler_, vals, and polyfem::solver::Form::value().

Here is the call graph for this function:

◆ hessian_wrt_u_prev()

void polyfem::solver::BodyForm::hessian_wrt_u_prev ( const Eigen::VectorXd &  u_prev,
const double  t,
StiffnessMatrix hessian 
) const

Definition at line 332 of file BodyForm.cpp.

References boundary_nodes_, polyfem::assembler::RhsAssembler::compute_energy_hess(), local_neumann_boundary_, n_boundary_samples_, and rhs_assembler_.

Here is the call graph for this function:

◆ name()

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

Implements polyfem::solver::Form.

Definition at line 32 of file BodyForm.hpp.

◆ second_derivative_unweighted()

void polyfem::solver::BodyForm::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 73 of file BodyForm.cpp.

References x.

◆ update_current_rhs()

void polyfem::solver::BodyForm::update_current_rhs ( const Eigen::VectorXd &  x)
private

Update current_rhs.

Definition at line 85 of file BodyForm.cpp.

References boundary_nodes_, polyfem::assembler::RhsAssembler::compute_energy_grad(), current_rhs_, density_, is_formulation_mixed_, local_boundary_, local_neumann_boundary_, n_boundary_samples_, n_pressure_bases_, ndof_, rhs_, rhs_assembler_, polyfem::assembler::RhsAssembler::set_bc(), t_, and x.

Referenced by BodyForm(), and update_quantities().

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

◆ update_quantities()

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

Update time dependent quantities.

Parameters
tNew time
xSolution at time t

Reimplemented from polyfem::solver::Form.

Definition at line 78 of file BodyForm.cpp.

References t_, update_current_rhs(), x, and x_prev_.

Here is the call graph for this function:

◆ value_unweighted()

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

Compute the value of the body force form.

Parameters
xCurrent solution
Returns
Value of the body force form

Implements polyfem::solver::Form.

Definition at line 62 of file BodyForm.cpp.

References polyfem::assembler::RhsAssembler::compute_energy(), density_, local_neumann_boundary_, n_boundary_samples_, rhs_assembler_, t_, x, and x_prev_.

Here is the call graph for this function:

Member Data Documentation

◆ boundary_nodes_

const std::vector<int>& polyfem::solver::BodyForm::boundary_nodes_
private

Definition at line 80 of file BodyForm.hpp.

Referenced by force_shape_derivative(), hessian_wrt_u_prev(), and update_current_rhs().

◆ current_rhs_

Eigen::MatrixXd polyfem::solver::BodyForm::current_rhs_
private

Cached RHS for the current time.

Definition at line 91 of file BodyForm.hpp.

Referenced by first_derivative_unweighted(), and update_current_rhs().

◆ density_

const assembler::Density& polyfem::solver::BodyForm::density_
private

Definition at line 87 of file BodyForm.hpp.

Referenced by force_shape_derivative(), update_current_rhs(), and value_unweighted().

◆ is_formulation_mixed_

bool polyfem::solver::BodyForm::is_formulation_mixed_
private

True if the formulation is mixed.

Definition at line 89 of file BodyForm.hpp.

Referenced by update_current_rhs().

◆ local_boundary_

const std::vector<mesh::LocalBoundary>& polyfem::solver::BodyForm::local_boundary_
private

Definition at line 81 of file BodyForm.hpp.

Referenced by update_current_rhs().

◆ local_neumann_boundary_

const std::vector<mesh::LocalBoundary>& polyfem::solver::BodyForm::local_neumann_boundary_
private

◆ n_boundary_samples_

const int polyfem::solver::BodyForm::n_boundary_samples_
private

Definition at line 83 of file BodyForm.hpp.

Referenced by hessian_wrt_u_prev(), update_current_rhs(), and value_unweighted().

◆ n_pressure_bases_

const int polyfem::solver::BodyForm::n_pressure_bases_
private

Definition at line 76 of file BodyForm.hpp.

Referenced by update_current_rhs().

◆ ndof_

const int polyfem::solver::BodyForm::ndof_
private

Number of degrees of freedom.

Definition at line 75 of file BodyForm.hpp.

Referenced by update_current_rhs().

◆ rhs_

const Eigen::MatrixXd& polyfem::solver::BodyForm::rhs_
private

static RHS for the current time

Definition at line 85 of file BodyForm.hpp.

Referenced by update_current_rhs().

◆ rhs_assembler_

const assembler::RhsAssembler& polyfem::solver::BodyForm::rhs_assembler_
private

Reference to the RHS assembler.

Definition at line 86 of file BodyForm.hpp.

Referenced by force_shape_derivative(), hessian_wrt_u_prev(), update_current_rhs(), and value_unweighted().

◆ t_

double polyfem::solver::BodyForm::t_
private

Current time.

Definition at line 74 of file BodyForm.hpp.

Referenced by BodyForm(), update_current_rhs(), update_quantities(), and value_unweighted().

◆ x_prev_

Eigen::MatrixXd polyfem::solver::BodyForm::x_prev_
private

Cached previous solution.

Definition at line 78 of file BodyForm.hpp.

Referenced by update_quantities(), and value_unweighted().


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