14 const std::vector<std::shared_ptr<Form>> &forms,
15 const std::vector<std::shared_ptr<AugmentedLagrangianForm>> &penalty_forms,
16 const bool solve_symmetric_macro_strain)
17 :
NLProblem(full_size, state.periodic_bc, t, forms, penalty_forms),
19 only_symmetric(solve_symmetric_macro_strain),
20 macro_strain_constraint_(macro_strain_constraint)
32 for (
int i = 0, idx = 0; i < dim; i++)
34 for (
int j = i; j < dim; j++)
59 Eigen::VectorXd reduced(dof1 + dof2);
71 assert(reduced.size() == dof1 + dof2);
75 Eigen::VectorXd extended(fluctuation.size() + disp_grad.size());
76 extended << fluctuation, disp_grad;
87 Eigen::VectorXd grad(dof1 + dof2);
101 term.segment(i * dim, dim) += disp_grad.transpose() * adjoint_full.segment(i * dim, dim);
122 Eigen::VectorXd grad_extended;
133 Eigen::MatrixXd A12, A22;
135 Eigen::MatrixXd tmp = Eigen::MatrixXd(extended.rightCols(dim * dim));
140 std::vector<Eigen::Triplet<double>>
entries;
141 entries.reserve(extended.nonZeros() + A12.size() * 2 + A22.size());
144 for (StiffnessMatrix::InnerIterator it(extended, k); it; ++it)
146 entries.emplace_back(it.row(), it.col(), it.value());
148 for (
int i = 0; i < A12.rows(); i++)
150 for (
int j = 0; j < A12.cols(); j++)
157 for (
int i = 0; i < A22.rows(); i++)
158 for (
int j = 0; j < A22.cols(); j++)
185 THessian hess_extended;
198 Eigen::VectorXd fixed_mask;
199 fixed_mask.setZero(dim * dim);
200 fixed_mask(fixed_entry.array()).setOnes();
204 for (
int i = 0; i < fixed_mask.size(); i++)
205 if (abs(fixed_mask(i)) > 1e-8)
210 for (
int i = 0, j = 0; i <
fixed_mask_.size(); i++)
222 Eigen::MatrixXd A12 = full * tmp.transpose();
223 Eigen::MatrixXd A22 = tmp * A12;
225 std::vector<Eigen::Triplet<double>>
entries;
226 entries.reserve(full.nonZeros() + A12.size() * 2 + A22.size());
228 for (
int k = 0; k < full.outerSize(); ++k)
229 for (StiffnessMatrix::InnerIterator it(full, k); it; ++it)
230 entries.emplace_back(it.row(), it.col(), it.value());
232 for (
int i = 0; i < A12.rows(); i++)
233 for (
int j = 0; j < A12.cols(); j++)
235 entries.emplace_back(i, full.cols() + j, A12(i, j));
236 entries.emplace_back(full.rows() + j, i, A12(i, j));
239 for (
int i = 0; i < A22.rows(); i++)
240 for (
int j = 0; j < A22.cols(); j++)
241 entries.emplace_back(i + full.rows(), j + full.cols(), A22(i, j));
243 THessian mid(full.rows() + dof2, full.cols() + dof2);
262 reduced.setZero(dof1 + dof2);
276 reduced.setZero(dof1 + dof2);
311 mid(i) = fixed_values(i);
360 form->post_step(polysolve::nonlinear::PostStepData(
399 for (
int i = 0; i < X.rows(); i++)
400 for (
int j = 0; j < dim; j++)
401 for (
int k = 0; k < dim; k++)
402 jac(j * dim + k, i * dim + j) = X(i, k);
409 Eigen::MatrixXd result = Eigen::MatrixXd::Zero(
full_size(), 1);
std::vector< Eigen::Triplet< double > > entries
main class that contains the polyfem solver and all its state
int n_bases
number of bases
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
std::shared_ptr< polyfem::mesh::MeshNodes > mesh_nodes
Mapping from input nodes to FE nodes.
StiffnessMatrix basis_nodes_to_gbasis_nodes
Eigen::MatrixXd eval(const double t) const
static Eigen::MatrixXd generate_linear_field(const int n_bases, const std::shared_ptr< mesh::MeshNodes > mesh_nodes, const Eigen::MatrixXd &grad)
static Eigen::MatrixXd get_bases_position(const int n_bases, const std::shared_ptr< mesh::MeshNodes > mesh_nodes)
virtual void init(const TVector &x0) override
Eigen::MatrixXd reduced_to_disp_grad(const TVector &reduced, bool homogeneous=false) const
Eigen::VectorXi fixed_mask_
void gradient(const TVector &x, TVector &gradv) override
void init(const TVector &x0) override
void post_step(const polysolve::nonlinear::PostStepData &data) override
Eigen::MatrixXd macro_mid_to_reduced_
int macro_reduced_size() const
void set_fixed_entry(const Eigen::VectorXi &fixed_entry)
TVector macro_full_to_reduced(const TVector &full) const
bool is_step_valid(const TVector &x0, const TVector &x1) override
Eigen::MatrixXd constraint_values(const TVector &) const override
Eigen::MatrixXd macro_mid_to_full_
const assembler::MacroStrainValue & macro_strain_constraint_
void line_search_begin(const TVector &x0, const TVector &x1) override
void update_quantities(const double t, const TVector &x) override
Eigen::MatrixXd macro_full_to_mid_
TVector extended_to_reduced_grad(const TVector &extended) const
void hessian(const TVector &x, THessian &hessian) override
void init_lagging(const TVector &x) override
TVector reduced_to_extended(const TVector &reduced, bool homogeneous=false) const
TVector extended_to_reduced(const TVector &extended) const
NLHomoProblem(const int full_size, const assembler::MacroStrainValue ¯o_strain_constraint, const State &state, const double t, const std::vector< std::shared_ptr< Form > > &forms, const std::vector< std::shared_ptr< AugmentedLagrangianForm > > &penalty_forms, const bool solve_symmetric_macro_strain)
std::vector< std::shared_ptr< Form > > homo_forms
Eigen::MatrixXd constraint_grad() const
void full_hessian_to_reduced_hessian(const THessian &full, THessian &reduced) const override
TVector reduced_to_full_shape_derivative(const Eigen::MatrixXd &disp_grad, const TVector &adjoint_full) const
TVector reduced_to_full(const TVector &reduced) const override
Eigen::MatrixXd macro_full_to_reduced_grad(const Eigen::MatrixXd &full) const
double value(const TVector &x) override
TVector full_to_reduced(const TVector &full, const Eigen::MatrixXd &disp_grad) const
TVector full_to_reduced_grad(const TVector &full) const override
const bool only_symmetric
void solution_changed(const TVector &new_x) override
double max_step_size(const TVector &x0, const TVector &x1) override
void extended_hessian_to_reduced_hessian(const THessian &extended, THessian &reduced) const
bool is_step_collision_free(const TVector &x0, const TVector &x1) override
void update_lagging(const TVector &x, const int iter_num) override
TVector macro_reduced_to_full(const TVector &reduced, bool homogeneous=false) const
const int full_size_
Size of the full problem.
void line_search_begin(const TVector &x0, const TVector &x1) override
virtual bool is_step_valid(const TVector &x0, const TVector &x1) override
virtual void post_step(const polysolve::nonlinear::PostStepData &data) override
virtual TVector full_to_reduced_grad(const TVector &full) const
virtual TVector full_to_reduced(const TVector &full) const
virtual void update_quantities(const double t, const TVector &x)
virtual void gradient(const TVector &x, TVector &gradv) override
void init_lagging(const TVector &x) override
virtual bool is_step_collision_free(const TVector &x0, const TVector &x1) override
virtual TVector reduced_to_full(const TVector &reduced) const
void update_lagging(const TVector &x, const int iter_num) override
virtual void full_hessian_to_reduced_hessian(const THessian &full, THessian &reduced) const
virtual double value(const TVector &x) override
virtual double max_step_size(const TVector &x0, const TVector &x1) override
virtual void hessian(const TVector &x, THessian &hessian) override
void solution_changed(const TVector &new_x) override
Eigen::MatrixXd unflatten(const Eigen::VectorXd &x, int dim)
Unflatten rowwises, so every dim elements in x become a row.
Eigen::VectorXd flatten(const Eigen::MatrixXd &X)
Flatten rowwises.
void log_and_throw_error(const std::string &msg)