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

#include <StackedForm.hpp>

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

Classes

class  Block
 
struct  Term
 

Public Member Functions

std::string name () const override
 
Block add_block (const int size)
 
void add (const Block &block, std::shared_ptr< Form > form)
 
void add (const Block &a, const Block &b, std::shared_ptr< Form > form)
 
int size () const
 
void init (const Eigen::VectorXd &x) override
 Initialize the form.
 
void finish () override
 
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.
 
bool is_step_collision_free (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const override
 Checks if the step is collision free.
 
double max_step_size (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const override
 Determine the maximum step size allowable between the current and next solution.
 
void line_search_begin (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) override
 Initialize variables used during the line search.
 
void line_search_end () override
 Clear variables used during the line search.
 
void post_step (const polysolve::nonlinear::PostStepData &data) override
 Update fields after a step in the optimization.
 
void solution_changed (const Eigen::VectorXd &new_x) override
 Update cached fields upon a change in the solution.
 
void set_project_to_psd (bool val) override
 Set project to psd.
 
void update_quantities (const double t, const Eigen::VectorXd &x) override
 Update time-dependent fields.
 
void init_lagging (const Eigen::VectorXd &x) override
 Initialize lagged fields TODO: more than one step.
 
void update_lagging (const Eigen::VectorXd &x, const int iter_num) override
 Update lagged fields.
 
int max_lagging_iterations () const override
 Get the maximum number of lagging iteration allowable.
 
bool uses_lagging () const override
 Does this form require lagging?
 
- Public Member Functions inherited from polyfem::solver::Form
virtual ~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.
 
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.
 
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 &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 validate_block (const Block &block) const
 
int term_size (const Term &term) const
 
Eigen::VectorXd gather (const Eigen::VectorXd &x, const Term &term) const
 
int global_index (const Term &term, const int local_index) const
 

Private Attributes

std::vector< Blockblocks_
 
std::vector< Termterms_
 
int size_ = 0
 

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

Definition at line 10 of file StackedForm.hpp.

Member Function Documentation

◆ add() [1/2]

void polyfem::solver::StackedForm::add ( const Block a,
const Block b,
std::shared_ptr< Form form 
)

Definition at line 27 of file StackedForm.cpp.

References polyfem::solver::StackedForm::Block::id(), terms_, and validate_block().

Here is the call graph for this function:

◆ add() [2/2]

void polyfem::solver::StackedForm::add ( const Block block,
std::shared_ptr< Form form 
)

Definition at line 20 of file StackedForm.cpp.

References polyfem::solver::StackedForm::Block::id(), terms_, and validate_block().

Here is the call graph for this function:

◆ add_block()

StackedForm::Block polyfem::solver::StackedForm::add_block ( const int  size)

Definition at line 9 of file StackedForm.cpp.

References blocks_, size(), and size_.

Here is the call graph for this function:

◆ finish()

void polyfem::solver::StackedForm::finish ( )
overridevirtual

Reimplemented from polyfem::solver::Form.

Definition at line 43 of file StackedForm.cpp.

References terms_.

◆ first_derivative_unweighted()

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

References gather(), global_index(), size_, term_size(), terms_, and x.

Here is the call graph for this function:

◆ gather()

Eigen::VectorXd polyfem::solver::StackedForm::gather ( const Eigen::VectorXd &  x,
const Term term 
) const
private

Definition at line 264 of file StackedForm.cpp.

References polyfem::solver::StackedForm::Term::a, polyfem::solver::StackedForm::Term::b, blocks_, polyfem::solver::StackedForm::Term::has_second_block(), polyfem::solver::StackedForm::Block::offset(), polyfem::solver::StackedForm::Block::size(), size_, and x.

Referenced by first_derivative_unweighted(), init(), init_lagging(), is_step_collision_free(), is_step_valid(), line_search_begin(), max_step_size(), post_step(), second_derivative_unweighted(), solution_changed(), update_lagging(), update_quantities(), and value_unweighted().

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

◆ global_index()

int polyfem::solver::StackedForm::global_index ( const Term term,
const int  local_index 
) const
private

Definition at line 278 of file StackedForm.cpp.

References polyfem::solver::StackedForm::Term::a, polyfem::solver::StackedForm::Term::b, blocks_, polyfem::solver::StackedForm::Term::has_second_block(), polyfem::solver::StackedForm::Block::offset(), polyfem::solver::StackedForm::Block::size(), and term_size().

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:

◆ init()

void polyfem::solver::StackedForm::init ( const Eigen::VectorXd &  x)
overridevirtual

Initialize the form.

Parameters
xCurrent solution

Reimplemented from polyfem::solver::Form.

Definition at line 36 of file StackedForm.cpp.

References gather(), size_, terms_, and x.

Here is the call graph for this function:

◆ init_lagging()

void polyfem::solver::StackedForm::init_lagging ( const Eigen::VectorXd &  x)
overridevirtual

Initialize lagged fields TODO: more than one step.

Parameters
xCurrent solution

Reimplemented from polyfem::solver::Form.

Definition at line 147 of file StackedForm.cpp.

References gather(), size_, terms_, and x.

Here is the call graph for this function:

◆ is_step_collision_free()

bool polyfem::solver::StackedForm::is_step_collision_free ( const Eigen::VectorXd &  x0,
const Eigen::VectorXd &  x1 
) const
overridevirtual

Checks if the step is collision free.

Returns
True if the step is collision free else false

Reimplemented from polyfem::solver::Form.

Definition at line 65 of file StackedForm.cpp.

References gather(), size_, and terms_.

Here is the call graph for this function:

◆ is_step_valid()

bool polyfem::solver::StackedForm::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 49 of file StackedForm.cpp.

References gather(), size_, and terms_.

Here is the call graph for this function:

◆ line_search_begin()

void polyfem::solver::StackedForm::line_search_begin ( const Eigen::VectorXd &  x0,
const Eigen::VectorXd &  x1 
)
overridevirtual

Initialize variables used during the line search.

Parameters
x0Current solution
x1Next solution

Reimplemented from polyfem::solver::Form.

Definition at line 97 of file StackedForm.cpp.

References gather(), size_, and terms_.

Here is the call graph for this function:

◆ line_search_end()

void polyfem::solver::StackedForm::line_search_end ( )
overridevirtual

Clear variables used during the line search.

Reimplemented from polyfem::solver::Form.

Definition at line 106 of file StackedForm.cpp.

References terms_.

◆ max_lagging_iterations()

int polyfem::solver::StackedForm::max_lagging_iterations ( ) const
overridevirtual

Get the maximum number of lagging iteration allowable.

Reimplemented from polyfem::solver::Form.

Definition at line 161 of file StackedForm.cpp.

References max_lagging_iterations(), and terms_.

Referenced by max_lagging_iterations().

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

◆ max_step_size()

double polyfem::solver::StackedForm::max_step_size ( const Eigen::VectorXd &  x0,
const Eigen::VectorXd &  x1 
) const
overridevirtual

Determine the maximum step size allowable between the current and next solution.

Parameters
x0Current solution (step size = 0)
x1Next solution (step size = 1)
Returns
Maximum allowable step size

Reimplemented from polyfem::solver::Form.

Definition at line 81 of file StackedForm.cpp.

References gather(), size_, and terms_.

Here is the call graph for this function:

◆ name()

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

Implements polyfem::solver::Form.

Definition at line 31 of file StackedForm.hpp.

◆ post_step()

void polyfem::solver::StackedForm::post_step ( const polysolve::nonlinear::PostStepData &  data)
overridevirtual

Update fields after a step in the optimization.

Parameters
iter_numOptimization iteration number
xCurrent solution
dataData containing info about the current iteration

Reimplemented from polyfem::solver::Form.

Definition at line 112 of file StackedForm.cpp.

References gather(), size_, terms_, and x.

Here is the call graph for this function:

◆ second_derivative_unweighted()

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

References entries, gather(), global_index(), size_, term_size(), terms_, and x.

Here is the call graph for this function:

◆ set_project_to_psd()

void polyfem::solver::StackedForm::set_project_to_psd ( bool  val)
overridevirtual

Set project to psd.

Parameters
valIf true, the form's second derivative is projected to be positive semidefinite

Reimplemented from polyfem::solver::Form.

Definition at line 133 of file StackedForm.cpp.

References polyfem::solver::Form::set_project_to_psd(), terms_, and val.

Here is the call graph for this function:

◆ size()

int polyfem::solver::StackedForm::size ( ) const
inline

Definition at line 37 of file StackedForm.hpp.

References size_.

Referenced by add_block().

Here is the caller graph for this function:

◆ solution_changed()

void polyfem::solver::StackedForm::solution_changed ( const Eigen::VectorXd &  new_x)
overridevirtual

Update cached fields upon a change in the solution.

Parameters
new_xNew solution

Reimplemented from polyfem::solver::Form.

Definition at line 126 of file StackedForm.cpp.

References gather(), size_, and terms_.

Here is the call graph for this function:

◆ term_size()

int polyfem::solver::StackedForm::term_size ( const Term term) const
private

Definition at line 254 of file StackedForm.cpp.

References polyfem::solver::StackedForm::Term::a, polyfem::solver::StackedForm::Term::b, blocks_, polyfem::solver::StackedForm::Term::has_second_block(), and polyfem::solver::StackedForm::Block::size().

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

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

◆ update_lagging()

void polyfem::solver::StackedForm::update_lagging ( const Eigen::VectorXd &  x,
const int  iter_num 
)
overridevirtual

Update lagged fields.

Parameters
xCurrent solution

Reimplemented from polyfem::solver::Form.

Definition at line 154 of file StackedForm.cpp.

References gather(), size_, terms_, and x.

Here is the call graph for this function:

◆ update_quantities()

void polyfem::solver::StackedForm::update_quantities ( const 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 140 of file StackedForm.cpp.

References gather(), size_, terms_, and x.

Here is the call graph for this function:

◆ uses_lagging()

bool polyfem::solver::StackedForm::uses_lagging ( ) const
overridevirtual

Does this form require lagging?

Returns
True if the form requires lagging

Reimplemented from polyfem::solver::Form.

Definition at line 169 of file StackedForm.cpp.

References terms_.

◆ validate_block()

void polyfem::solver::StackedForm::validate_block ( const Block block) const
private

Definition at line 246 of file StackedForm.cpp.

References blocks_, polyfem::solver::StackedForm::Block::id(), polyfem::solver::StackedForm::Block::offset(), and polyfem::solver::StackedForm::Block::size().

Referenced by add(), and add().

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

◆ value_unweighted()

double polyfem::solver::StackedForm::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 179 of file StackedForm.cpp.

References gather(), size_, terms_, polyfem::solver::Form::value(), and x.

Here is the call graph for this function:

Member Data Documentation

◆ blocks_

std::vector<Block> polyfem::solver::StackedForm::blocks_
private

Definition at line 75 of file StackedForm.hpp.

Referenced by add_block(), gather(), global_index(), term_size(), and validate_block().

◆ size_

◆ terms_


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