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

Maps to dirichlet boundary. More...

#include <DirichletBoundaryVariableToSimulation.hpp>

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

Public Types

using StatePtrs = std::vector< std::shared_ptr< legacy::State > >
 
using DiffCachePtrs = std::vector< std::shared_ptr< DiffCache > >
 

Public Member Functions

 DirichletBoundaryVariableToSimulation (StatePtrs states, DiffCachePtrs diff_caches, CompositeParametrization parametrizations, Eigen::VectorXi active_boundary_ids, Eigen::VectorXi active_time_slices)
 Construct DirichletBoundaryVariableToSimulation.
 
std::string name () const override
 
ParameterType parameter_type () const override
 
bool affect_state (const legacy::State &target) const override
 Return true if current var2sim maps to target state.
 
void update (const Eigen::VectorXd &x) override
 Update forward simulation states from optimization variables.
 
void update_state_variables (const Eigen::VectorXd &x, Eigen::VectorXd &state_variables) const override
 Update state variables from optimization variables.
 
Eigen::VectorXd compute_adjoint_term (const Eigen::VectorXd &x) const override
 Compute adjoint contribution of objective gradient.
 
int inverse_dof () const override
 Compute optimization variables dof.
 
Eigen::VectorXd inverse_eval () const override
 Compute optimization variables from forward simulation legacy::State.
 
Eigen::VectorXd apply_parametrization_jacobian (const Eigen::VectorXd &term, const Eigen::VectorXd &x) const override
 Apply parametrization jacobian to compute the gradient w.r.t.
 
- Public Member Functions inherited from polyfem::solver::VariableToSimulation
virtual ~VariableToSimulation ()=default
 

Private Types

using BoundaryNodeMap = std::vector< std::vector< std::vector< int > > >
 boundary order in this var2sim -> component (dim) -> offset in state.boundary_nodes
 

Private Member Functions

int para_out_dof () const
 
void build_boundary_node_maps ()
 

Private Attributes

int dim_
 
int time_steps_
 
StatePtrs states_
 
DiffCachePtrs diff_caches_
 
CompositeParametrization parametrization_
 
Eigen::VectorXi active_boundary_ids_
 
Eigen::VectorXi active_time_slices_
 
std::vector< BoundaryNodeMapboundary_node_maps_
 boundary node map per state.
 

Detailed Description

Maps to dirichlet boundary.

Maps one boundary solution to all boundaries in one boundary selection.

Example 1: Suppose one boundary selection contains all vertices at x=0, this var2sim will map one solution (displacement xyz) to all vertices in the selection.

Example 2: Suppose there are two boundary selections – the left and right surface of a cube. This var2sim will map two solution, displacement to all vertices in their respective boundary seletion.

Expect optimiztion variable with layout: [ solution of boundary selection 1 at t0] [solution of boundary selection 2 at t0] ... [ solution of boundary selection 1 at t1] [solution of boundary selection 2 at t1] ...

Definition at line 29 of file DirichletBoundaryVariableToSimulation.hpp.

Member Typedef Documentation

◆ BoundaryNodeMap

using polyfem::solver::DirichletBoundaryVariableToSimulation::BoundaryNodeMap = std::vector<std::vector<std::vector<int> >>
private

boundary order in this var2sim -> component (dim) -> offset in state.boundary_nodes

Definition at line 61 of file DirichletBoundaryVariableToSimulation.hpp.

◆ DiffCachePtrs

◆ StatePtrs

Constructor & Destructor Documentation

◆ DirichletBoundaryVariableToSimulation()

polyfem::solver::DirichletBoundaryVariableToSimulation::DirichletBoundaryVariableToSimulation ( StatePtrs  states,
DiffCachePtrs  diff_caches,
CompositeParametrization  parametrizations,
Eigen::VectorXi  active_boundary_ids,
Eigen::VectorXi  active_time_slices 
)

Construct DirichletBoundaryVariableToSimulation.

Parameters
[in]statesShared ptr to all forward sim states.
[in]diff_cachesShared ptr to all diff caches.
[in]parametrizationsParametrizations.
[in]active_boundary_idsActive Dirichlet boundary ids. Empty implies all active.
[in]active_time_slicesActive time slices. Empty implies all active.
Exceptions
std::runtime_errorThrow if input is invalid.

Definition at line 24 of file DirichletBoundaryVariableToSimulation.cpp.

References active_boundary_ids_, active_time_slices_, build_boundary_node_maps(), diff_caches_, polyfem::solver::is_active_dirichlet_boundary_ids_valid(), polyfem::solver::is_active_time_slices_valid(), polyfem::log_and_throw_adjoint_error(), states_, and time_steps_.

Here is the call graph for this function:

Member Function Documentation

◆ affect_state()

bool polyfem::solver::DirichletBoundaryVariableToSimulation::affect_state ( const legacy::State target) const
overridevirtual

Return true if current var2sim maps to target state.

Implements polyfem::solver::VariableToSimulation.

Definition at line 99 of file DirichletBoundaryVariableToSimulation.cpp.

References states_.

◆ apply_parametrization_jacobian()

Eigen::VectorXd polyfem::solver::DirichletBoundaryVariableToSimulation::apply_parametrization_jacobian ( const Eigen::VectorXd &  term,
const Eigen::VectorXd &  x 
) const
overridevirtual

Apply parametrization jacobian to compute the gradient w.r.t.

to optimization variables.

Parameters
termGradient w.r.t. to full inherent dof (Ex. all vertices for shape var2sim)
xOptimization variables.

Implements polyfem::solver::VariableToSimulation.

Definition at line 243 of file DirichletBoundaryVariableToSimulation.cpp.

References polyfem::log_and_throw_adjoint_error(), and name().

Here is the call graph for this function:

◆ build_boundary_node_maps()

void polyfem::solver::DirichletBoundaryVariableToSimulation::build_boundary_node_maps ( )
private

Definition at line 254 of file DirichletBoundaryVariableToSimulation.cpp.

References active_boundary_ids_, polyfem::basis::ElementBases::bases, polyfem::legacy::State::bases, boundary_node_maps_, polyfem::legacy::State::boundary_nodes, dim_, polyfem::legacy::State::local_boundary, polyfem::basis::ElementBases::local_nodes_for_primitive(), polyfem::legacy::State::mesh, and states_.

Referenced by DirichletBoundaryVariableToSimulation().

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

◆ compute_adjoint_term()

Eigen::VectorXd polyfem::solver::DirichletBoundaryVariableToSimulation::compute_adjoint_term ( const Eigen::VectorXd &  x) const
overridevirtual

Compute adjoint contribution of objective gradient.

See arXiv:2205.13643.

Let objective function be J and optimization variable be x. This method computes all adjoint related terms in dJ/dx. For static case (E.q. 11), it's the second term. For dynamic case (E.q. 15), it's everything except ∂qJ.

Parameters
x[in]Optimization variables.
Returns
Adjoint contribution of objective gradient.

Implements polyfem::solver::VariableToSimulation.

Definition at line 145 of file DirichletBoundaryVariableToSimulation.cpp.

References active_boundary_ids_, active_time_slices_, polyfem::solver::CompositeParametrization::apply_jacobian(), boundary_node_maps_, diff_caches_, dim_, polyfem::solver::AdjointTools::dJ_dirichlet_transient_adjoint_term(), polyfem::get_adjoint_mat(), para_out_dof(), parametrization_, states_, time_steps_, and x.

Here is the call graph for this function:

◆ inverse_dof()

int polyfem::solver::DirichletBoundaryVariableToSimulation::inverse_dof ( ) const
overridevirtual

Compute optimization variables dof.

Returns
Optimization variables dof.
Exceptions
std::runtime_errorThrow if not implemented.

Implements polyfem::solver::VariableToSimulation.

Definition at line 189 of file DirichletBoundaryVariableToSimulation.cpp.

References polyfem::solver::CompositeParametrization::inverse_size(), para_out_dof(), and parametrization_.

Here is the call graph for this function:

◆ inverse_eval()

Eigen::VectorXd polyfem::solver::DirichletBoundaryVariableToSimulation::inverse_eval ( ) const
overridevirtual

Compute optimization variables from forward simulation legacy::State.

Returns
Optimization variables.
Exceptions
std::runtime_errorThrow if not implemented.

Implements polyfem::solver::VariableToSimulation.

Definition at line 194 of file DirichletBoundaryVariableToSimulation.cpp.

References active_boundary_ids_, active_time_slices_, dim_, polyfem::solver::CompositeParametrization::inverse_eval(), polyfem::utils::json_as_array(), polyfem::log_and_throw_adjoint_error(), polyfem::logger(), para_out_dof(), parametrization_, states_, time_steps_, and y.

Here is the call graph for this function:

◆ name()

std::string polyfem::solver::DirichletBoundaryVariableToSimulation::name ( ) const
overridevirtual

Implements polyfem::solver::VariableToSimulation.

Definition at line 89 of file DirichletBoundaryVariableToSimulation.cpp.

Referenced by apply_parametrization_jacobian().

Here is the caller graph for this function:

◆ para_out_dof()

int polyfem::solver::DirichletBoundaryVariableToSimulation::para_out_dof ( ) const
private

Definition at line 249 of file DirichletBoundaryVariableToSimulation.cpp.

References active_boundary_ids_, active_time_slices_, and dim_.

Referenced by compute_adjoint_term(), inverse_dof(), inverse_eval(), and update().

Here is the caller graph for this function:

◆ parameter_type()

ParameterType polyfem::solver::DirichletBoundaryVariableToSimulation::parameter_type ( ) const
overridevirtual

◆ update()

void polyfem::solver::DirichletBoundaryVariableToSimulation::update ( const Eigen::VectorXd &  x)
overridevirtual

Update forward simulation states from optimization variables.

Parameters
[in]xOptimization variables.

Implements polyfem::solver::VariableToSimulation.

Definition at line 111 of file DirichletBoundaryVariableToSimulation.cpp.

References active_boundary_ids_, active_time_slices_, dim_, polyfem::solver::CompositeParametrization::eval(), polyfem::log_and_throw_adjoint_error(), para_out_dof(), parametrization_, states_, x, and y.

Here is the call graph for this function:

◆ update_state_variables()

void polyfem::solver::DirichletBoundaryVariableToSimulation::update_state_variables ( const Eigen::VectorXd &  x,
Eigen::VectorXd &  state_variables 
) const
overridevirtual

Update state variables from optimization variables.

Compared to update() this method update abstract state variables instead of writing directly to state.

Parameters
[in]xOptimization variables.
[out]state_variablesAbstract state variables update dst.

Implements polyfem::solver::VariableToSimulation.

Definition at line 139 of file DirichletBoundaryVariableToSimulation.cpp.

References polyfem::log_and_throw_adjoint_error().

Here is the call graph for this function:

Member Data Documentation

◆ active_boundary_ids_

Eigen::VectorXi polyfem::solver::DirichletBoundaryVariableToSimulation::active_boundary_ids_
private

◆ active_time_slices_

Eigen::VectorXi polyfem::solver::DirichletBoundaryVariableToSimulation::active_time_slices_
private

◆ boundary_node_maps_

std::vector<BoundaryNodeMap> polyfem::solver::DirichletBoundaryVariableToSimulation::boundary_node_maps_
private

boundary node map per state.

Definition at line 74 of file DirichletBoundaryVariableToSimulation.hpp.

Referenced by build_boundary_node_maps(), and compute_adjoint_term().

◆ diff_caches_

DiffCachePtrs polyfem::solver::DirichletBoundaryVariableToSimulation::diff_caches_
private

◆ dim_

int polyfem::solver::DirichletBoundaryVariableToSimulation::dim_
private

◆ parametrization_

CompositeParametrization polyfem::solver::DirichletBoundaryVariableToSimulation::parametrization_
private

◆ states_

StatePtrs polyfem::solver::DirichletBoundaryVariableToSimulation::states_
private

◆ time_steps_

int polyfem::solver::DirichletBoundaryVariableToSimulation::time_steps_
private

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