PolyFEM
Loading...
Searching...
No Matches
AssemblyValsCache.cpp
Go to the documentation of this file.
2
4
5namespace polyfem
6{
7 using namespace basis;
8
9 namespace assembler
10 {
11 void AssemblyValsCache::init(const bool is_volume, const std::vector<ElementBases> &bases, const std::vector<ElementBases> &gbases, const bool is_mass)
12 {
13 cache.clear();
15 const int n_bases = bases.size();
16 cache.resize(n_bases);
17
18 // loop over elements
19 utils::maybe_parallel_for(n_bases, [&](int start, int end, int thread_id) {
20 for (int e = start; e < end; ++e)
21 {
22 if (is_mass_)
23 {
24 auto &quadrature = cache[e].quadrature;
25 bases[e].compute_mass_quadrature(quadrature);
26 cache[e].compute(e, is_volume, quadrature.points, bases[e], gbases[e]);
27 }
28 else
29 cache[e].compute(e, is_volume, bases[e], gbases[e]);
30 }
31 });
32 }
33
34 void AssemblyValsCache::init_empty(const bool is_mass)
35 {
36 clear();
38 }
39
40 void AssemblyValsCache::update(const int e, const bool is_volume, const basis::ElementBases &basis, const basis::ElementBases &gbasis)
41 {
42 if (is_mass_)
43 {
44 auto &quadrature = cache[e].quadrature;
46 cache[e].compute(e, is_volume, quadrature.points, basis, gbasis);
47 }
48 else
49 cache[e].compute(e, is_volume, basis, gbasis);
50 }
51
52 void AssemblyValsCache::compute(const int el_index, const bool is_volume, const ElementBases &basis, const ElementBases &gbasis, ElementAssemblyValues &vals) const
53 {
54 if (cache.empty())
55 {
56 if (is_mass_)
57 {
58 auto &quadrature = vals.quadrature;
60 vals.compute(el_index, is_volume, quadrature.points, basis, gbasis);
61 }
62 else
63 vals.compute(el_index, is_volume, basis, gbasis);
64 }
65 else
66 vals = cache[el_index];
67 }
68 } // namespace assembler
69
70} // namespace polyfem
ElementAssemblyValues vals
Definition Assembler.cpp:22
Quadrature quadrature
void init(const bool is_volume, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const bool is_mass=false)
computes the basis evaluation and geometric mapping for each of the given ElementBases in bases initi...
std::vector< ElementAssemblyValues > cache
vector of basis values and geometric mapping with one entry per element
void init_empty(const bool is_mass=false)
initialize an empty cache.
void update(const int el_index, const bool is_volume, const basis::ElementBases &basis, const basis::ElementBases &gbasis)
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
Stores the basis functions for a given element in a mesh (facet in 2d, cell in 3d).
void compute_mass_quadrature(quadrature::Quadrature &quadrature) const
void maybe_parallel_for(int size, const std::function< void(int, int, int)> &partial_for)