PolyFEM
Loading...
Searching...
No Matches
WeightedVolumeForm.cpp
Go to the documentation of this file.
2#include <polyfem/State.hpp>
3
4namespace polyfem::solver
5{
6 double WeightedVolumeForm::value_unweighted_with_param(const Eigen::VectorXd &x) const
7 {
8 assert(x.size() == state_.mesh->n_elements());
9
10 double val = 0;
12 for (int e = 0; e < state_.bases.size(); e++)
13 {
15 val += (vals.det.array() * vals.quadrature.weights.array()).sum() * x(e);
16 }
17 return val;
18 }
19
20 void WeightedVolumeForm::compute_partial_gradient_with_param(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const
21 {
22 assert(x.size() == state_.mesh->n_elements());
23
24 gradv.setZero(x.size());
26 for (int e = 0; e < state_.bases.size(); e++)
27 {
29 gradv(e) = (vals.det.array() * vals.quadrature.weights.array()).sum();
30 }
31 gradv *= weight();
32 }
33} // namespace polyfem::solver
double val
Definition Assembler.cpp:86
ElementAssemblyValues vals
Definition Assembler.cpp:22
int x
assembler::AssemblyValsCache ass_vals_cache
used to store assembly values for small problems
Definition State.hpp:196
const std::vector< basis::ElementBases > & geom_bases() const
Get a constant reference to the geometry mapping bases.
Definition State.hpp:223
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
Definition State.hpp:466
std::vector< basis::ElementBases > bases
FE bases, the size is #elements.
Definition State.hpp:171
void compute(const int el_index, const bool is_volume, const basis::ElementBases &basis, const basis::ElementBases &gbasis, ElementAssemblyValues &vals) const
retrieves cached basis evaluation and geometric for the given element if it doesn't exist,...
stores per element basis values at given quadrature points and geometric mapping
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