PolyFEM
Loading...
Searching...
No Matches
GrowthElasticVarForm.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace polysolve::linear
6{
7 class Solver;
8}
9
10namespace polyfem::assembler
11{
12 class Density;
13 class GenericScalarProblem;
14 class Laplacian;
15 class MixedNLAssembler;
16} // namespace polyfem::assembler
17
18namespace polyfem::solver
19{
20 class AugmentedLagrangianForm;
21 class Form;
22 class GrowthDissipationForm;
23 class MixedAssemblerForm;
24 class NLProblem;
25 class StackedForm;
26} // namespace polyfem::solver
27
28namespace polyfem::varform
29{
47 {
48 public:
49 using NonlinearElasticVarForm::NonlinearElasticVarForm;
50 std::string name() const override { return "GrowthElastic"; }
51
52 void init(const std::string &formulation, const Units &units, const json &args, const std::string &out_path) override;
56 void validate_time_dependence() const override;
57
58 io::OutStatsData compute_errors(const Eigen::MatrixXd &solution) override;
61 void serialize_checkpoint(io::CheckpointWriter &writer, const Eigen::MatrixXd &solution, const io::CheckpointMetadata &metadata) const override;
62 void deserialize_checkpoint(const io::CheckpointReader &reader, Eigen::MatrixXd &solution) override;
63
64 void export_data(const Eigen::MatrixXd &solution) const override;
65
68 const Eigen::VectorXi &growth_activation_step() const { return growth_activation_step_; }
71 const Eigen::VectorXd &growth_shear_supply() const { return shear_supply_; }
72 const Eigen::VectorXd &growth_threshold() const { return threshold_per_element_; }
73 const Eigen::VectorXd &growth_threshold_parallel() const { return threshold_parallel_; }
74 const Eigen::VectorXd &growth_attainment() const { return attainment_; }
75 const Eigen::VectorXd &growth_lag_residual() const { return lag_residual_; }
76 const Eigen::VectorXd &growth_dissipation() const { return dissipation_; }
77 const Eigen::VectorXd &growth_shear_supply_work() const { return shear_work_; }
78
79 std::vector<io::OutputField> output_fields(
80 const io::OutputSample &sample,
81 const Eigen::MatrixXd &solution,
82 const io::OutputFieldOptions &options) const override;
83
84 private:
85 // The elastic snapshot bypasses the grown stresses, energy and growth
86 // fields in output_fields; prepare those fields before queueing the write.
88 const Eigen::MatrixXd &, const io::OutGeometryData::ExportOptions &,
89 const io::OutputSpace &, double, double) const override { return {}; }
90
91 void reset() override;
92 void load_mesh(const mesh::Mesh &mesh, const json &args) override;
93 void build_basis(mesh::Mesh &mesh, const bool iso_parametric, const json &args) override;
94 void assemble_rhs(const mesh::Mesh &mesh) override;
95 void assemble_mass_mat(const mesh::Mesh &mesh, const json &args) override;
96 void solve_problem(
97 Eigen::MatrixXd &sol,
98 const InitialConditionOverride *initial_condition_override,
99 const ForwardStepCallback &post_step) override;
100 void build_rhs_assembler() override;
101
102 void read_material_space_ids(const json &args);
104
105 // ---- stress output of the grown material ----
110 void grown_stress_at(
111 const int e, const Eigen::MatrixXd &local_pts, const double t,
112 const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &growth,
113 Eigen::MatrixXd &cauchy, Eigen::MatrixXd &pk1, Eigen::MatrixXd &pk2,
114 Eigen::MatrixXd &von_mises, Eigen::MatrixXd &energy) const;
120 const io::OutputSample &sample,
121 const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &growth,
122 std::vector<io::OutputField> &fields) const;
123
125 void build_growth_basis(mesh::Mesh &mesh, const bool iso_parametric, const json &args);
127 void build_forms(Eigen::MatrixXd &solution, const double t);
129 void make_nl_problem(const Eigen::MatrixXd &sol, const double t);
130 void solve_nonlinear_step(const int step, Eigen::MatrixXd &solution, double grad_tol_factor = 1.0);
131
132 // ---- solved growth (growth_law on the material) ----
133 void read_growth_law(const json &args);
141 void threshold_target(const Eigen::MatrixXd &solution, double t,
142 Eigen::VectorXd &par, Eigen::VectorXd &gam, Eigen::VectorXd &clamped);
144 void set_threshold(const Eigen::VectorXd &par, const Eigen::VectorXd &gam,
145 const Eigen::VectorXd &clamped, double t, double omega);
149 void evaluate_threshold_state(const Eigen::VectorXd &u, double t,
150 Eigen::VectorXd &phi_full, Eigen::VectorXd &phi_no_shear, Eigen::VectorXd &theta_tot);
152 Eigen::VectorXd element_mean_growth(const Eigen::VectorXd &theta);
154 void report_lag_residual(int step, double t, const Eigen::MatrixXd &solution);
156 void accumulate_dissipation(int step, double t, const Eigen::VectorXd &dtheta);
158 void log_kkt_residual(int step, double t, const Eigen::MatrixXd &solution,
159 const Eigen::VectorXd &mult, const std::vector<char> &pinned);
160 static double median_of(const Eigen::VectorXd &v);
161 void solve_growth_law(Eigen::MatrixXd &solution);
163 int advance_increment(int step, double t_from, double t_to, Eigen::MatrixXd &solution, int depth);
165 void commit_increment(int step, double t, Eigen::MatrixXd &solution);
169 void save_growth_increment(int step, double t, const Eigen::MatrixXd &solution);
172 int solve_growth_increment(const int step, const double t, Eigen::MatrixXd &solution);
173 void solve_with_current_pins(const int step, const double t, Eigen::MatrixXd &solution, double grad_tol_factor = 1.0);
176 Eigen::VectorXd growth_multiplier(const Eigen::MatrixXd &solution) const;
177
178 void initial_growth_solution(Eigen::MatrixXd &solution) const;
179 const Eigen::MatrixXd &prescribed_growth_field() const;
180 void split_solution(
181 const Eigen::MatrixXd &solution,
182 Eigen::MatrixXd &displacement,
183 Eigen::MatrixXd &growth) const;
184 Eigen::MatrixXd stacked_solution(
185 const Eigen::MatrixXd &displacement,
186 const Eigen::MatrixXd &growth) const;
187
188 int displacement_ndof() const { return space_.ndof(); }
189 int growth_ndof() const { return growth_space_.ndof(); }
190 int total_ndof() const { return displacement_ndof() + growth_ndof(); }
191
194 std::shared_ptr<assembler::Problem> growth_problem_;
195
198
199 std::shared_ptr<assembler::Assembler> growth_assembler_;
200 std::shared_ptr<assembler::MixedNLAssembler> growthelastic_assembler_;
201 std::shared_ptr<assembler::Mass> growth_mass_assembler_;
202 std::shared_ptr<assembler::RhsAssembler> growth_rhs_assembler_;
203 std::shared_ptr<assembler::Density> growth_rhs_density_;
204
207 Eigen::MatrixXd growth_rhs_;
208
209 std::shared_ptr<solver::MixedAssemblerForm> growth_coupling_form_;
210 std::shared_ptr<solver::StackedForm> stacked_form_;
211
218 Eigen::MatrixXd converged_solution_;
219
224 mutable Eigen::MatrixXd prescribed_growth_;
225
228 std::string elastic_formulation_ = "MaterialSum";
229
235 {
236 bool enabled = false;
237 int n_steps = 1;
238 double t_end = 1.0;
240 double active_set_tol = 1e-8;
241 double feasibility_tol = 1e-12;
242 double theta_floor_fraction = 0.5;
243 bool save_increments = false;
250 bool from_state = false;
251 double theta_crit = 0;
252 double relag_tol = 1.0;
256 double final_tol_factor = 1.0;
261
262 Eigen::VectorXd threshold_per_element_;
263 Eigen::VectorXd threshold_parallel_;
264 Eigen::VectorXd shear_supply_;
265 bool setup_logged_ = false;
266 Eigen::VectorXd threshold_clamped_;
267 Eigen::VectorXd lag_residual_;
268 Eigen::VectorXd attainment_;
269 Eigen::VectorXd dissipation_;
270 Eigen::VectorXd shear_work_;
271 Eigen::VectorXd element_volume_;
273 Eigen::VectorXd growth_node_volume_;
274 Eigen::VectorXd growth_node_vn_volume_;
275 Eigen::VectorXd growth_node_weights_;
276 Eigen::VectorXd theta_n_;
277 std::vector<int> pinned_growth_nodes_;
278 std::vector<char> growth_pinned_mask_;
279 Eigen::VectorXi growth_activation_step_;
280 std::shared_ptr<solver::GrowthDissipationForm> dissipation_form_;
281 };
282} // namespace polyfem::varform
Caches basis evaluation and geometric mapping at every element.
all stats from polyfem
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:77
A finite-element space for one scalar- or vector-valued field.
Definition FESpace.hpp:59
Variational form for the (displacement, growth) problem built on the GrowthElasticity mixed assembler...
bool setup_logged_
the setup line is logged once, not per update
std::shared_ptr< assembler::MixedNLAssembler > growthelastic_assembler_
void solve_problem(Eigen::MatrixXd &sol, const InitialConditionOverride *initial_condition_override, const ForwardStepCallback &post_step) override
void threshold_target(const Eigen::MatrixXd &solution, double t, Eigen::VectorXd &par, Eigen::VectorXd &gam, Eigen::VectorXd &clamped)
the threshold the state implies (from_state): G(x) = (PHI_PAR, f_gamma) at C_check of the state; f_ga...
Eigen::VectorXd lag_residual_
phi(converged state) - phi used, last increment [Pa]
void solve_nonlinear_step(const int step, Eigen::MatrixXd &solution, double grad_tol_factor=1.0)
std::shared_ptr< assembler::Problem > growth_problem_
std::shared_ptr< assembler::Density > growth_rhs_density_
std::vector< io::OutputField > output_fields(const io::OutputSample &sample, const Eigen::MatrixXd &solution, const io::OutputFieldOptions &options) const override
Get the output fields of the variational formulation, for output purposes.
Eigen::VectorXd element_volume_
reference element volumes (growth quadrature)
Eigen::MatrixXd stacked_solution(const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &growth) const
const Eigen::VectorXd & growth_shear_supply() const
growth_law threshold from_state: f_gamma per element used by the last increment, and the threshold ph...
Eigen::VectorXi growth_activation_step_
first increment in which a growth DOF grew (0 = never)
void set_threshold(const Eigen::VectorXd &par, const Eigen::VectorXd &gam, const Eigen::VectorXd &clamped, double t, double omega)
install a threshold (parts), rebuild the node weights, log
Eigen::VectorXd threshold_per_element_
phi_e [Pa] in use (from_state: phi_par + f_gamma)
Eigen::VectorXd growth_node_weights_
int vn phi N_a dV
void save_growth_increment(int step, double t, const Eigen::MatrixXd &solution)
growth_law.save_increments: the converged stacked state of increment step (pseudo-time t) as growth_s...
std::vector< char > growth_pinned_mask_
last solved pass: 1 = pinned at theta_n
int advance_increment(int step, double t_from, double t_to, Eigen::MatrixXd &solution, int depth)
one increment (t_from, t_to], split recursively on failure; returns passes
std::shared_ptr< solver::StackedForm > stacked_form_
void build_forms(Eigen::MatrixXd &solution, const double t)
const Eigen::VectorXd & growth_lag_residual() const
Eigen::VectorXd attainment_
vartheta^e / theta_crit at the last converged increment
Eigen::VectorXd normal_growth_per_element_
vn_e (1 when not given)
void make_nl_problem(const Eigen::MatrixXd &sol, const double t)
NLProblem over the current forms and AL forms, initialized at sol, t.
void assemble_rhs(const mesh::Mesh &mesh) override
const Eigen::VectorXd & growth_dissipation() const
void report_lag_residual(int step, double t, const Eigen::MatrixXd &solution)
lag residual phi(converged state) - phi used, and attainment, logged per increment
const Eigen::VectorXd & growth_threshold() const
void export_data(const Eigen::MatrixXd &solution) const override
std::shared_ptr< assembler::RhsAssembler > growth_rhs_assembler_
void deserialize_checkpoint(const io::CheckpointReader &reader, Eigen::MatrixXd &solution) override
void solve_growth_law(Eigen::MatrixXd &solution)
Eigen::MatrixXd prescribed_growth_
Whole-field growth prescription (boundary_conditions.growth_nodal_field): nodal theta values loaded l...
void replace_stress_fields(const io::OutputSample &sample, const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &growth, std::vector< io::OutputField > &fields) const
The elastic base evaluates von_mises, cauchy_stess_*, pk1_stess_*, pk2_stess_* (and the *_avg variant...
Eigen::MatrixXd converged_solution_
Converged stacked (u, growth) solution cached at the end of solve_problem.
int solve_growth_increment(const int step, const double t, Eigen::MatrixXd &solution)
One increment: primal-dual active-set loop on theta >= theta_n.
std::shared_ptr< solver::MixedAssemblerForm > growth_coupling_form_
Eigen::VectorXd threshold_clamped_
1 where f_par(C_check) < 0 (zero floor), when computed here
void log_kkt_residual(int step, double t, const Eigen::MatrixXd &solution, const Eigen::VectorXd &mult, const std::vector< char > &pinned)
phi - f_I per v_n-weighted nodal volume on the settled set: free and pinned
const Eigen::MatrixXd & prescribed_growth_field() const
void grown_stress_at(const int e, const Eigen::MatrixXd &local_pts, const double t, const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &growth, Eigen::MatrixXd &cauchy, Eigen::MatrixXd &pk1, Eigen::MatrixXd &pk2, Eigen::MatrixXd &von_mises, Eigen::MatrixXd &energy) const
Grown-material stresses and energy density (GrowthElasticity::grown_stresses) at local points of elem...
Eigen::VectorXd threshold_parallel_
from_state: phi_par,e of the last update [Pa]
Eigen::VectorXd element_mean_growth(const Eigen::VectorXd &theta)
element mean of a nodal growth field (growth quadrature)
Eigen::VectorXd dissipation_
cumulative D = sum v_n max(f_par,0) dtheta per element [Pa]
void split_solution(const Eigen::MatrixXd &solution, Eigen::MatrixXd &displacement, Eigen::MatrixXd &growth) const
void build_basis(mesh::Mesh &mesh, const bool iso_parametric, const json &args) override
void evaluate_threshold_state(const Eigen::VectorXd &u, double t, Eigen::VectorXd &phi_full, Eigen::VectorXd &phi_no_shear, Eigen::VectorXd &theta_tot)
The state-built threshold at C_check of displacement u, per element: f_I(Ce) (phi_full),...
std::shared_ptr< solver::GrowthDissipationForm > dissipation_form_
void validate_time_dependence() const override
Solved growth steps its own pseudo-time (growth_law.n_steps, t_end), so its displacement problem is t...
Eigen::VectorXd shear_work_
cumulative S = sum v_n f_gamma dtheta per element [Pa]
const Eigen::VectorXd & growth_attainment() const
const Eigen::VectorXd & growth_threshold_parallel() const
Eigen::VectorXd growth_multiplier(const Eigen::MatrixXd &solution) const
d Pi_inc / d theta at the solution: stacked energy gradient plus the dissipation weights (the KKT res...
Eigen::VectorXd shear_supply_
from_state: f_gamma,e of the last update [Pa]
Eigen::VectorXd theta_n_
converged growth of the previous increment
io::OutputFieldFunction snapshot_output_fields(const Eigen::MatrixXd &, const io::OutGeometryData::ExportOptions &, const io::OutputSpace &, double, double) const override
Capture mutable timestep data for deferred field evaluation.
void solve_with_current_pins(const int step, const double t, Eigen::MatrixXd &solution, double grad_tol_factor=1.0)
struct polyfem::varform::GrowthElasticVarForm::GrowthLawSettings growth_law_
const Eigen::VectorXd & growth_shear_supply_work() const
std::vector< int > pinned_growth_nodes_
member: BCLagrangianForm keeps a reference
void build_growth_basis(mesh::Mesh &mesh, const bool iso_parametric, const json &args)
assembler::AssemblyValsCache growth_ass_vals_cache_
void assemble_growth_node_weights()
w_a = sum_e vn_e phi_e int_e N_a dV from threshold_per_element_ (and the nodal volumes); called once ...
void load_mesh(const mesh::Mesh &mesh, const json &args) override
void serialize_checkpoint(io::CheckpointWriter &writer, const Eigen::MatrixXd &solution, const io::CheckpointMetadata &metadata) const override
both blocks of the stacked (displacement, growth) solution, each with its node ordering,...
std::shared_ptr< assembler::Assembler > growth_assembler_
static double median_of(const Eigen::VectorXd &v)
assembler::AssemblyValsCache growth_mass_ass_vals_cache_
void init(const std::string &formulation, const Units &units, const json &args, const std::string &out_path) override
Initialize the variational formulation with the given parameters.
std::string name() const override
Get the name of the variational formulation.
io::OutStatsData compute_errors(const Eigen::MatrixXd &solution) override
Get the error statistics of the variational formulation, for output purposes.
Eigen::VectorXd growth_node_vn_volume_
int vn N_a dV (KKT residual in Pa)
void assemble_mass_mat(const mesh::Mesh &mesh, const json &args) override
std::shared_ptr< assembler::Mass > growth_mass_assembler_
void initial_growth_solution(Eigen::MatrixXd &solution) const
const Eigen::VectorXi & growth_activation_step() const
growth_law: first increment in which each growth DOF grew (0 = never); empty before a solved run.
void commit_increment(int step, double t, Eigen::MatrixXd &solution)
D/S accumulation, theta_n update and activation marking after a converged (sub)increment.
void accumulate_dissipation(int step, double t, const Eigen::VectorXd &dtheta)
split of the increment's dissipation term (D, S), accumulated and logged
Used for test only.
std::function< std::vector< OutputField >(const OutputSample &)> OutputFieldFunction
std::function< void(int step, const Eigen::MatrixXd &solution)> ForwardStepCallback
Definition VarForm.hpp:59
nlohmann::json json
Definition Common.hpp:9
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:24
Growth law (material "growth_law"): rate-independent, per-element threshold (given,...
double t_end
pseudo-time at which DBC expressions reach their end state
int max_increment_splits
a failed increment is retried from its start as two half increments, recursively, up to this many lev...
double relag_tol
from_state: per-pass threshold iteration tolerance [Pa]
double theta_crit
C_check in-plane elastic area stretch (from_state; else optional, lag report)
bool from_state
threshold "from_state": phi_e = max(f_par, 0) + f_gamma at C_check of the current displacement,...
double final_tol_factor
< 1: after the active set settles, one confirmation pass with the nonlinear gradient tolerance multip...
double feasibility_tol
pin a free DOF if theta < theta_n - tol
double active_set_tol
release a pin if dPi/dtheta < -tol * scale_a (Pa)
double theta_floor_fraction
positivity filter: theta >= fraction * theta_n
bool save_increments
write growth_step_<k>.vtu + growth_steps.pvd per increment
Temporary compatibility wrapper for boundary data belonging to one FE space.
Definition FESpace.hpp:156