src/dolfinx_access/function.cc

changeset 3
c3a4f4bb87f7
parent 1
a4137aedcb3a
--- a/src/dolfinx_access/function.cc	Thu Feb 26 09:32:12 2026 -0500
+++ b/src/dolfinx_access/function.cc	Wed Apr 22 22:32:00 2026 -0500
@@ -17,7 +17,6 @@
 using namespace basix::element;
 using namespace dolfinx::graph;
 using namespace dolfinx::la;
-namespace cell = basix::cell;
 
 namespace dolfinx_access {
     extern void drop_Function_f64(Function_f64* f) {
@@ -29,9 +28,9 @@
         auto el = fp->element()->basix_element();
         return FunctionInfo{
             .domain_dim = (uint32_t)fp->mesh()->geometry().dim(),
-            .codomain_dim = (uint32_t)fp->value_size(),
+            .codomain_dim = (uint32_t)fp->element()->value_size(),
             .order = (uint32_t)fp->element()->basix_element().degree(),
-            .triangular_mesh = el.cell_type() == cell::type::triangle,
+            .triangular_mesh = el.cell_type() == basix::cell::type::triangle,
         };
     }
 
@@ -41,15 +40,16 @@
         }
     }
 
-    std::map<std::weak_ptr<const mesh::Mesh<double>>, std::shared_ptr<BoundingBoxTree<double>>,
-             std::owner_less<std::weak_ptr<const mesh::Mesh<double>>>>
+    std::map<std::weak_ptr<const dolfinx::mesh::Mesh<double>>,
+             std::shared_ptr<BoundingBoxTree<double>>,
+             std::owner_less<std::weak_ptr<const dolfinx::mesh::Mesh<double>>>>
         bb_tree_cache;
 
     /// Returns the cell containg x
-    int32_t cell_Mesh_f64(std::shared_ptr<const mesh::Mesh<double>> mesh,
+    int32_t cell_Mesh_f64(std::shared_ptr<const dolfinx::mesh::Mesh<double>> mesh,
                           const std::array<double, 3>& x) {
 
-        std::weak_ptr<const mesh::Mesh<double>> mesh_weak = mesh;
+        std::weak_ptr<const dolfinx::mesh::Mesh<double>> mesh_weak = mesh;
         std::shared_ptr<BoundingBoxTree<double>> bb_tree = bb_tree_cache[mesh_weak];
         if (bb_tree == nullptr) {
             auto topo = mesh->topology();
@@ -68,7 +68,8 @@
             assert(local_cells == index_map->size_global());
             std::vector<std::int32_t> r(local_cells);
             std::iota(r.begin(), r.end(), 0);
-            bb_tree = std::make_shared<BoundingBoxTree<double>>(BoundingBoxTree(*mesh, dim, r));
+            bb_tree =
+                std::make_shared<BoundingBoxTree<double>>(BoundingBoxTree(*mesh, dim, 0.0, r));
             bb_tree_cache[mesh_weak] = bb_tree;
         }
         // Find colliding bounding boxes. This is an AdjancencyTree.
@@ -143,13 +144,13 @@
     }
 
     rust::Slice<const double> data_Function_f64(Function_f64 const* f) {
-        auto span = f->x()->array();
-        return rust::Slice(span.data(), span.size());
+        const std::vector<double>& v = f->x()->array();
+        return rust::Slice<const double>(v.data(), v.size());
     }
 
     rust::Slice<double> data_mut_Function_f64(Function_f64* f) {
-        auto span = f->x()->mutable_array();
-        return rust::Slice(span.data(), span.size());
+        std::vector<double>& v = f->x()->array();
+        return rust::Slice<double>(v.data(), v.size());
     }
 
     Function_f64* similar_Function_f64(Function_f64 const* f) {
@@ -157,7 +158,20 @@
     }
 
     Function_f64* clone_Function_f64(Function_f64 const* f) {
-        return new Function_f64(f->function_space(), std::make_shared<Vector<double>>(*f->x()));
+        // return new Function_f64(f->function_space(),
+        // std::make_shared<Vector<double>>(*f->x()));
+        auto f_copy = new Function_f64(f->function_space());
+        auto fx = f->x();
+        auto x_new = f_copy->x();
+        const std::vector<double>& a_old = fx->array();
+        std::vector<double>& a_new = x_new->array();
+        std::copy(a_old.begin(), a_old.end(), a_new.begin());
+        x_new->scatter_fwd();
+        return f_copy;
+    }
+
+    void scatter_fwd_Function_f64(Function_f64* f) {
+        f->x()->scatter_fwd();
     }
 
     // PyObject* py_similar_Function_f64(Function_f64 const* f) {

mercurial