11 : from_(from), to_(to)
20 Eigen::VectorXd res =
y;
25 return y.array().log();
32 Eigen::VectorXd
y =
x;
37 return x.array().exp();
44 Eigen::VectorXd res = grad.array();
49 return x.array().exp() * grad.array();
53 : from_(from), to_(to), scale_(scale)
63 Eigen::VectorXd res =
y;
75 Eigen::VectorXd
y =
x;
87 Eigen::VectorXd res = grad.array();
92 return scale_ * grad.array();
99 Eigen::VectorXd res =
y;
104 return y.array().pow(1. /
power_);
111 Eigen::VectorXd
y =
x;
123 Eigen::VectorXd res = grad;
132 : is_volume_(is_volume)
138 const int size =
y.size() / 2;
139 assert(
size * 2 ==
y.size());
141 Eigen::VectorXd
x(
y.size());
142 for (
int i = 0; i <
size; i++)
153 const int size =
x.size() / 2;
154 assert(
size * 2 ==
x.size());
158 for (
int i = 0; i <
size; i++)
169 const int size = grad.size() / 2;
170 assert(
size * 2 == grad.size());
171 assert(
size * 2 ==
x.size());
173 Eigen::VectorXd grad_E_nu;
174 grad_E_nu.setZero(grad.size());
175 for (
int i = 0; i <
size; i++)
178 grad_E_nu(i) = grad(i) * jacobian(0, 0) + grad(i +
size) * jacobian(1, 0);
179 grad_E_nu(i +
size) = grad(i) * jacobian(0, 1) + grad(i +
size) * jacobian(1, 1);
188 std::map<int, int> body_id_map;
192 if (!body_id_map.count(body_id))
202 for (
int e = 0; e < bases.size(); e++)
205 const int id = body_id_map.at(body_id);
206 for (
const auto &bs : bases[e].bases)
208 for (
const auto &g : bs.global())
222 y.setZero(
size(
x.size()));
227 for (
int d = 0; d < dim; d++)
244 assert(grad.size() ==
size(
x.size()));
245 Eigen::VectorXd grad_body;
246 grad_body.setZero(
x.size());
251 for (
int d = 0; d < dim; d++)
278 y.setZero(
size(
x.size()));
299 assert(grad.size() ==
size(
x.size()));
300 Eigen::VectorXd grad_body;
301 grad_body.setZero(
x.size());
314 SliceMap::SliceMap(
const int from,
const int to,
const int total) : from_(from), to_(to), total_(total)
326 if (
y.size() !=
size(0))
341 Eigen::VectorXd grad_full;
342 grad_full.setZero(
x.size());
360 return x_size +
values_.size();
367 Eigen::VectorXd
x(
y.size() -
values_.size());
374 return y.head(
y.size() -
values_.size());
380 y.setZero(
size(
x.size()));
395 assert(
x.size() == grad.size() -
values_.size());
396 Eigen::VectorXd reduced_grad(grad.size() -
values_.size());
404 reduced_grad = grad.head(grad.size() -
values_.size());
411 std::vector<Eigen::Triplet<double>> tt_adjacency_list;
413 Eigen::MatrixXd barycenters;
422 for (
int i = 0; i < barycenters.rows(); i++)
424 auto center_i = barycenters.row(i);
425 for (
int j = 0; j <= i; j++)
427 auto center_j = barycenters.row(j);
429 dist = (center_i - center_j).norm();
432 tt_adjacency_list.emplace_back(i, j, radius - dist);
434 tt_adjacency_list.emplace_back(j, i, radius - dist);
461 x.setZero(
size(
y.size()));
463 for (
int i = 1; i <
x.size(); ++i)
464 x(i) = (
y(i) -
y(i - 1)) /
dt_;
471 y.setZero(
size(
x.size()));
473 for (
int i = 1; i <
x.size(); ++i)
474 y(i) =
y(i - 1) +
dt_ *
x(i);
480 assert(
x.size() == grad.size());
482 Eigen::MatrixXd hess;
483 hess.setZero(
x.size(),
size(
x.size()));
484 for (
int i = 0; i < hess.rows(); ++i)
485 for (
int j = 0; j <= i; ++j)
488 return hess.transpose() * grad;
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
int n_elements() const
utitlity to return the number of elements, cells or faces in 3d and 2d
virtual int get_body_id(const int primitive) const
Get the volume selection of an element (cell in 3d, face in 2d)
void cell_barycenters(Eigen::MatrixXd &barycenters) const
all cells barycenters
virtual void bounding_box(RowVectorNd &min, RowVectorNd &max) const =0
computes the bbox of the mesh
void face_barycenters(Eigen::MatrixXd &barycenters) const
all face barycenters
virtual bool is_volume() const =0
checks if mesh is volume
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
int size(const int x_size) const override
Compute DOF of y given DOF of x.
ENu2LambdaMu(const bool is_volume)
Eigen::VectorXd inverse_eval(const Eigen::VectorXd &y) override
Eval x = f^-1 (y).
ExponentialMap(const int from=-1, const int to=-1)
Eigen::VectorXd inverse_eval(const Eigen::VectorXd &y) override
Eval x = f^-1 (y).
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
int size(const int x_size) const override
Compute DOF of y given DOF of x.
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
InsertConstantMap(const int size=-1, const double val=0, const int start_index=-1)
Eigen::VectorXd inverse_eval(const Eigen::VectorXd &y) override
Eval x = f^-1 (y).
Eigen::SparseMatrix< double > tt_radius_adjacency
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
Eigen::VectorXd tt_radius_adjacency_row_sum
LinearFilter(const mesh::Mesh &mesh, const double radius)
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
PerBody2PerElem(const mesh::Mesh &mesh)
int size(const int x_size) const override
Compute DOF of y given DOF of x.
std::map< int, std::array< int, 2 > > body_id_map_
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
int size(const int x_size) const override
Compute DOF of y given DOF of x.
Eigen::VectorXi node_id_to_body_id_
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
PerBody2PerNode(const mesh::Mesh &mesh, const std::vector< basis::ElementBases > &bases, const int n_bases)
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
Eigen::VectorXd inverse_eval(const Eigen::VectorXd &y) override
Eval x = f^-1 (y).
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
int size(const int x_size) const override
Compute DOF of y given DOF of x.
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
Eigen::VectorXd inverse_eval(const Eigen::VectorXd &y) override
Eval x = f^-1 (y).
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
Scaling(const double scale, const int from=-1, const int to=-1)
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
Eigen::VectorXd inverse_eval(const Eigen::VectorXd &y) override
Eval x = f^-1 (y).
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
SliceMap(const int from=-1, const int to=-1, const int total=-1)
Eigen::VectorXd inverse_eval(const Eigen::VectorXd &y) override
Eval x = f^-1 (y).
int size(const int x_size) const override
Compute DOF of y given DOF of x.
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
spdlog::logger & logger()
Retrieves the current logger.
double convert_to_E(const bool is_volume, const double lambda, const double mu)
double convert_to_mu(const double E, const double nu)
void log_and_throw_adjoint_error(const std::string &msg)
double convert_to_nu(const bool is_volume, const double lambda, const double mu)
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
double convert_to_lambda(const bool is_volume, const double E, const double nu)
Eigen::Matrix2d d_lambda_mu_d_E_nu(const bool is_volume, const double E, const double nu)