PolyFEM
Loading...
Searching...
No Matches
CompositeForms.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "CompositeForm.hpp"
4
5namespace polyfem::solver
6{
8 {
9 public:
12
13 private:
14 double compose(const Eigen::VectorXd &inputs) const override;
15 Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override;
16 };
17
19 {
20 public:
21 NegativeCompositeForm(const std::shared_ptr<AdjointForm> &form) : CompositeForm({form}) {}
23
24 private:
25 double compose(const Eigen::VectorXd &inputs) const override { assert(inputs.size() == 1); return -inputs(0); }
26 Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override { assert(inputs.size() == 1); return Eigen::VectorXd::Constant(1, 1, -1.); }
27 };
28
30 {
31 public:
32 PlusConstCompositeForm(const std::shared_ptr<AdjointForm> &form, const double alpha) : CompositeForm({form}), alpha_(alpha) {}
34
35 private:
36 const double alpha_;
37
38 double compose(const Eigen::VectorXd &inputs) const override { assert(inputs.size() == 1); return alpha_ + inputs(0); }
39 Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override { assert(inputs.size() == 1); return Eigen::VectorXd::Constant(1, 1, 1.); }
40 };
41
43 {
44 public:
45 InequalityConstraintForm(const std::vector<std::shared_ptr<AdjointForm>> &forms, const Eigen::Vector2d &bounds, const double power = 2);
47
48 private:
49 double compose(const Eigen::VectorXd &inputs) const override;
50 Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override;
51
52 const double power_;
53 const Eigen::Vector2d bounds_;
54 };
55
56 class PowerForm : public CompositeForm
57 {
58 public:
59 PowerForm(const std::shared_ptr<AdjointForm> &form, const double power): CompositeForm({form}), power_(power) { }
61
62 private:
63 double compose(const Eigen::VectorXd &inputs) const override { return pow(inputs(0), power_); }
64 Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override { Eigen::VectorXd x(1); x(0) = power_ * pow(inputs(0), power_ - 1); return x; }
65
66 const double power_;
67 };
68
70 {
71 public:
72 DivideForm(const std::vector<std::shared_ptr<AdjointForm>> &forms): CompositeForm(forms) { assert(forms.size() == 2); }
74
75 private:
76 double compose(const Eigen::VectorXd &inputs) const override { return inputs(0) / inputs(1); }
77 Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override { Eigen::VectorXd x(2); x << 1. / inputs(1), -inputs(0) / pow(inputs(1), 2); return x; }
78 };
79}
int x
CompositeForm(const VariableToSimulationGroup &variable_to_simulations, const std::vector< std::shared_ptr< AdjointForm > > &forms)
double compose(const Eigen::VectorXd &inputs) const override
DivideForm(const std::vector< std::shared_ptr< AdjointForm > > &forms)
Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override
Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override
double compose(const Eigen::VectorXd &inputs) const override
double compose(const Eigen::VectorXd &inputs) const override
Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override
double compose(const Eigen::VectorXd &inputs) const override
NegativeCompositeForm(const std::shared_ptr< AdjointForm > &form)
Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override
Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override
double compose(const Eigen::VectorXd &inputs) const override
PlusConstCompositeForm(const std::shared_ptr< AdjointForm > &form, const double alpha)
Eigen::VectorXd compose_grad(const Eigen::VectorXd &inputs) const override
double compose(const Eigen::VectorXd &inputs) const override
PowerForm(const std::shared_ptr< AdjointForm > &form, const double power)