PolyFEM
Loading...
Searching...
No Matches
WeightedVolumeForm.cpp
Go to the documentation of this file.
2
3#include <polyfem/State.hpp>
4
5#include <Eigen/Core>
6
7#include <cassert>
8
9namespace polyfem::solver
10{
11 double WeightedVolumeForm::value_unweighted_with_param(const Eigen::VectorXd &x) const
12 {
13 assert(x.size() == state_->mesh->n_elements());
14
15 double val = 0;
17 for (int e = 0; e < state_->bases.size(); e++)
18 {
19 state_->ass_vals_cache.compute(e, state_->mesh->is_volume(), state_->bases[e], state_->geom_bases()[e], vals);
20 val += (vals.det.array() * vals.quadrature.weights.array()).sum() * x(e);
21 }
22 return val;
23 }
24
25 void WeightedVolumeForm::compute_partial_gradient_with_param(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const
26 {
27 assert(x.size() == state_->mesh->n_elements());
28
29 gradv.setZero(x.size());
31 for (int e = 0; e < state_->bases.size(); e++)
32 {
33 state_->ass_vals_cache.compute(e, state_->mesh->is_volume(), state_->bases[e], state_->geom_bases()[e], vals);
34 gradv(e) = (vals.det.array() * vals.quadrature.weights.array()).sum();
35 }
36 gradv *= weight();
37 }
38} // namespace polyfem::solver
double val
Definition Assembler.cpp:86
ElementAssemblyValues vals
Definition Assembler.cpp:22
int x
stores per element basis values at given quadrature points and geometric mapping
void compute(const int el_index, const bool is_volume, const Eigen::MatrixXd &pts, const basis::ElementBases &basis, const basis::ElementBases &gbasis)
computes the per element values at the local (ref el) points (pts) sets basis_values,...
virtual double weight() const
Get the form's multiplicative constant weight.
Definition Form.hpp:128
void compute_partial_gradient_with_param(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
Computes the gradient of this form wrt. x, assuming that the volume of elements doesn't depend on x.
double value_unweighted_with_param(const Eigen::VectorXd &x) const override
std::shared_ptr< const State > state_