Skip to content

Commit dbf46b8

Browse files
committed
bug fix: non-constant coefficients in spline-based assembly loops
1 parent cb3770e commit dbf46b8

File tree

4 files changed

+16
-30
lines changed

4 files changed

+16
-30
lines changed

fdaPDE/src/splines/sp_assembler_base.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ struct sp_assembler_base {
162162
eval_shape_dxx(BasisType__&& basis, const std::vector<int>& active_dofs, IteratorType cell, DstMdArray& dst) const {
163163
eval_shape_derivative(basis, active_dofs, cell, dst, 2);
164164
}
165-
void distribute_quadrature_nodes(
166-
std::unordered_map<const void*, Eigen::Matrix<double, Dynamic, Dynamic>>& sp_map_buff, dof_iterator begin,
167-
dof_iterator end) {
165+
void distribute_quadrature_nodes(dof_iterator begin, dof_iterator end) {
168166
Eigen::Matrix<double, Dynamic, Dynamic> quad_nodes;
169167
quad_nodes.resize(n_quadrature_nodes_ * (end_.index() - begin_.index()), embed_dim);
170168
int local_cell_id = 0;
@@ -182,8 +180,8 @@ struct sp_assembler_base {
182180
return;
183181
}),
184182
decltype([]<typename Xpr_>() {
185-
return requires(Xpr_ xpr) { xpr.init(sp_map_buff, quad_nodes, begin, end); };
186-
})>(form_, sp_map_buff, quad_nodes, begin, end);
183+
return requires(Xpr_ xpr) { xpr.init(quad_nodes, begin, end); };
184+
})>(form_, quad_nodes, begin, end);
187185
return;
188186
}
189187

fdaPDE/src/splines/sp_bilinear_form_assembler.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ class sp_bilinear_form_assembly_loop :
9595
MdArray<double, MdExtents<Dynamic, Dynamic>> test_shape_dx (n1, q), trial_shape_dx (n2, q);
9696
MdArray<double, MdExtents<Dynamic, Dynamic>> test_shape_dxx (n1, q), trial_shape_dxx (n2, q);
9797

98-
std::unordered_map<const void*, Eigen::Matrix<double, Dynamic, Dynamic>> sp_map_buff;
9998
if constexpr (Form::XprBits & int(sp_assembler_flags::compute_physical_quad_nodes)) {
100-
Base::distribute_quadrature_nodes(
101-
sp_map_buff, begin, end); // distribute quadrature nodes on physical mesh (if required)
99+
Base::distribute_quadrature_nodes(begin, end);
102100
}
103101
// start assembly loop
104102
internals::sp_assembler_packet<local_dim> sp_packet {};

fdaPDE/src/splines/sp_linear_form_assembler.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ class sp_linear_form_assembly_loop :
5959
int q = Base::n_quadrature_nodes_;
6060
MdArray<double, MdExtents<Dynamic, Dynamic>> shape_values(n, q);
6161

62-
std::unordered_map<const void*, Eigen::Matrix<double, Dynamic, Dynamic>> sp_map_buff;
6362
if constexpr (Form::XprBits & int(sp_assembler_flags::compute_physical_quad_nodes)) {
64-
Base::distribute_quadrature_nodes(
65-
sp_map_buff, begin, end); // distribute quadrature nodes on physical mesh (if required)
63+
Base::distribute_quadrature_nodes(begin, end);
6664
}
6765
// start assembly loop
6866
internals::sp_assembler_packet<local_dim> sp_packet {};

fdaPDE/src/splines/sp_objects.h

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ template <typename SpSpace_> class BsFunction : public ScalarFieldBase<SpSpace_:
270270
if (e_id == -1) return std::numeric_limits<Scalar>::quiet_NaN(); // return NaN if point lies outside domain
271271
// map p to reference interval [-1, 1]
272272
double a = sp_space_->triangulation().range()[0], b = sp_space_->triangulation().range()[1];
273-
double ref_p;
273+
double p_;
274274
if constexpr (internals::is_subscriptable<InputType, int>) {
275-
ref_p = p[0];
275+
p_ = p[0];
276276
} else {
277-
ref_p = p;
277+
p_ = p;
278278
}
279-
ref_p = (ref_p - (b - a) / 2) * 2 / (b + a);
279+
double ref_p = 2 * (p_ - a) / (b - a) - 1;
280280
// get active dofs
281281
typename DofHandlerType::CellType cell = sp_space_->dof_handler().cell(e_id);
282282
std::vector<int> active_dofs = cell.dofs();
@@ -327,7 +327,6 @@ template <typename Derived_> struct SpMap : public ScalarFieldBase<Derived_::Sta
327327
private:
328328
using OutputType = decltype(std::declval<Derived_>().operator()(std::declval<typename Derived_::InputType>()));
329329
using Derived = std::decay_t<Derived_>;
330-
using MatrixType = Eigen::Matrix<double, Dynamic, Dynamic>;
331330
public:
332331
using InputType = internals::sp_assembler_packet<Derived::StaticInputSize>;
333332
using Scalar = double;
@@ -340,32 +339,25 @@ template <typename Derived_> struct SpMap : public ScalarFieldBase<Derived_::Sta
340339
static constexpr int Cols = 1;
341340

342341
constexpr SpMap() = default;
343-
constexpr SpMap(const Derived_& xpr) : xpr_(&xpr) { }
342+
constexpr SpMap(const Derived_& xpr) : xpr_(xpr) { }
344343
template <typename CellIterator>
345344
void init(
346-
std::unordered_map<const void*, MatrixType>& buff, const MatrixType& nodes, [[maybe_unused]] CellIterator begin,
345+
const Eigen::Matrix<double, Dynamic, Dynamic>& nodes, [[maybe_unused]] CellIterator begin,
347346
[[maybe_unused]] CellIterator end) const {
348-
const void* ptr = reinterpret_cast<const void*>(xpr_);
349-
if (buff.find(ptr) == buff.end()) {
350-
Eigen::Matrix<double, Dynamic, Dynamic> mapped(nodes.rows(), Rows * Cols);
351-
for (int i = 0, n = nodes.rows(); i < n; ++i) { mapped(i, 0) = xpr_->operator()(nodes.row(i)); }
352-
buff[ptr] = mapped;
353-
map_ = &buff[ptr];
354-
} else {
355-
map_ = &buff[ptr];
356-
}
347+
map_.resize(nodes.rows(), Rows * Cols);
348+
for (int i = 0, n = nodes.rows(); i < n; ++i) { map_(i, 0) = xpr_(nodes.row(i)); }
357349
}
358350
// bs assembler evaluation
359351
constexpr OutputType operator()(const InputType& sp_packet) const {
360-
return map_->operator()(sp_packet.quad_node_id, 0);
352+
return map_(sp_packet.quad_node_id, 0);
361353
}
362354
constexpr const Derived& derived() const { return xpr_; }
363355
constexpr int input_size() const { return StaticInputSize; }
364356
constexpr int rows() const { return Rows; }
365357
constexpr int cols() const { return Cols; }
366358
private:
367-
const Derived* xpr_;
368-
mutable const MatrixType* map_;
359+
Derived xpr_;
360+
mutable Eigen::Matrix<double, Dynamic, Dynamic> map_;
369361
};
370362

371363
} // namespace fdapde

0 commit comments

Comments
 (0)