Fri, 16 Jan 2026 19:41:32 -0500
pointsource_algs step length estimation support
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | #include <array> |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | #include <cmath> |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | #include <span> |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | #include <basix/finite-element.h> |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | #include <dolfinx/fem/Function.h> |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
7 | #include <nanobind/nanobind.h> |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
8 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
9 | #include "dolfinx_access/function.h" |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
10 | // #include "mpi_proto.h" |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
11 | #include "dolfinx/geometry/BoundingBoxTree.h" |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
12 | #include "pointsource_pde/src/dolfinx_access.rs.h" |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
13 | #include "rust/cxx.h" |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
14 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
15 | using namespace dolfinx::fem; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
16 | using namespace dolfinx::geometry; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
17 | using namespace basix::element; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | using namespace dolfinx::graph; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
19 | using namespace dolfinx::la; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
20 | namespace cell = basix::cell; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
22 | namespace dolfinx_access { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
23 | extern void drop_Function_f64(Function_f64* f) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | delete f; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
25 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | FunctionInfo info_Function_f64(Function_f64 const* f) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
28 | auto fp = f->function_space(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | auto el = fp->element()->basix_element(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
30 | return FunctionInfo{ |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | .domain_dim = (uint32_t)fp->mesh()->geometry().dim(), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | .codomain_dim = (uint32_t)fp->value_size(), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | .order = (uint32_t)fp->element()->basix_element().degree(), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | .triangular_mesh = el.cell_type() == cell::type::triangle, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | }; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
36 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
37 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | void check_compat_Function_f64(Function_f64 const* f, Function_f64 const* g) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | if (f->function_space() != g->function_space()) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | throw "Incompatible function spaces"; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
43 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | std::map<std::weak_ptr<const mesh::Mesh<double>>, std::shared_ptr<BoundingBoxTree<double>>, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | std::owner_less<std::weak_ptr<const mesh::Mesh<double>>>> |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | bb_tree_cache; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
47 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
48 | /// Returns the cell containg x |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
49 | int32_t cell_Mesh_f64(std::shared_ptr<const mesh::Mesh<double>> mesh, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
50 | const std::array<double, 3>& x) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
51 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
52 | std::weak_ptr<const mesh::Mesh<double>> mesh_weak = mesh; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
53 | std::shared_ptr<BoundingBoxTree<double>> bb_tree = bb_tree_cache[mesh_weak]; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
54 | if (bb_tree == nullptr) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
55 | auto topo = mesh->topology(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
56 | // auto dim = mesh->geometry().dim(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
57 | auto dim = topo->dim(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
58 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
59 | // This fails as it inorrectly calls mesh.topology_mutable(), so need to |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
60 | // copy-paste the implementation below, with the appropriate fix. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
61 | //*bb_tree = new BoundingBoxTree(*mesh, dim); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
62 | // And this also doesn't work due to the privacy of `range`. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
63 | //*bb_tree = new BoundingBoxTree(*mesh, dim, BoundingBoxTree::range(mesh->topology(), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
64 | // dim |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
65 | auto index_map = topo->index_map(dim); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
66 | int local_cells = index_map->size_local(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
67 | // We don't really do MPI; pointsource_algs is not designed for it. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
68 | assert(local_cells == index_map->size_global()); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
69 | std::vector<std::int32_t> r(local_cells); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
70 | std::iota(r.begin(), r.end(), 0); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
71 | bb_tree = std::make_shared<BoundingBoxTree<double>>(BoundingBoxTree(*mesh, dim, r)); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
72 | bb_tree_cache[mesh_weak] = bb_tree; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
73 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
74 | // Find colliding bounding boxes. This is an AdjancencyTree. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
75 | // |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
76 | // C++ and Dolfinx are just vomit-inducing 🤮. We need some weird const double span here, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
77 | // but then just standard x in compute_first_collding_cell below. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
78 | auto colliding_bbs_adj = compute_collisions(*bb_tree.get(), std::span<const double>(x)); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
79 | // Since we compute the collisions for just one node, the `array` of all links |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
80 | // of the adjancency list, will corresponding exactly the ccells whose bounding boxes |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
81 | // collide with the point. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
82 | auto colliding_bbs = colliding_bbs_adj.array(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
83 | // Within the colliding bounding boxes, find the first cell that actually collides. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
84 | int32_t local_cell = compute_first_colliding_cell(*mesh, colliding_bbs, x, 1e-9); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
85 | // local_cell may be -1 if it was not found by the local process, so combine |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
86 | // results with MPI_MAX. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
87 | int32_t global_cell = local_cell; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
88 | MPI_Allreduce(&local_cell, &global_cell, 1, MPI_INT32_T, MPI_MAX, mesh->comm()); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
89 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
90 | return global_cell; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
91 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
92 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
93 | int32_t cell_FunctionSpace_f64(FunctionSpace<double> const* v, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
94 | const std::array<double, 3>& x) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
95 | return cell_Mesh_f64(v->mesh(), x); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
96 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
97 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
98 | int32_t cell_Function_f64(Function_f64 const* f, const std::array<double, 3>& x) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
99 | return cell_Mesh_f64(f->function_space()->mesh(), x); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
100 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
101 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
102 | std::array<double, 3 * 3> cell_coords_Function_f64_triangle(Function_f64 const* f, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
103 | int32_t cell) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
104 | auto geom = f->function_space()->mesh()->geometry(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
105 | auto gx = geom.x(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
106 | auto geom_dofmap = geom.dofmap(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
107 | assert(geom_dofmap.extent(1) == 3); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
108 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
109 | auto j0 = geom_dofmap(cell, 0); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
110 | auto j1 = geom_dofmap(cell, 1); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
111 | auto j2 = geom_dofmap(cell, 2); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
112 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
113 | // Construct list of coordinates. Due to f->eval, we construct this as a single list |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
114 | // with all the Fenics weirdness of hard-coded 3D. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
115 | return {gx[3 * j0], gx[3 * j0 + 1], 0, /* */ |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
116 | gx[3 * j1], gx[3 * j1 + 1], 0, /* */ |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
117 | gx[3 * j2], gx[3 * j2 + 1], 0}; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
118 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
119 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
120 | // We assume `f` to be real-valued. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
121 | double eval_Function_f64_cell(Function_f64 const* f, const std::array<double, 3>& x, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
122 | int32_t cell) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
123 | if (cell < 0) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
124 | return 0.0; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
125 | } else { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
126 | std::array<double, 1> res; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
127 | f->eval(x, {1, 3}, {{cell}}, std::span(res), {1, 1}); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
128 | return res[0]; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
129 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
130 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
131 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
132 | double eval_Function_f64(Function_f64 const* f, const std::array<double, 3>& x) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
133 | return eval_Function_f64_cell(f, x, cell_Function_f64(f, x)); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
134 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
135 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
136 | std::array<double, 6> eval_Function_f64_cell_6(Function_f64 const* f, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
137 | const std::array<double, 3 * 6>& x, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
138 | int32_t cell) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
139 | std::array<double, 6> res; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
140 | auto i = cell; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
141 | f->eval(x, {6, 3}, {{i, i, i, i, i, i}}, std::span(res), {6, 1}); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
142 | return res; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
143 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
144 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
145 | rust::Slice<const double> data_Function_f64(Function_f64 const* f) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
146 | auto span = f->x()->array(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
147 | return rust::Slice(span.data(), span.size()); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
148 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
149 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
150 | rust::Slice<double> data_mut_Function_f64(Function_f64* f) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
151 | auto span = f->x()->mutable_array(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
152 | return rust::Slice(span.data(), span.size()); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
153 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
154 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
155 | Function_f64* similar_Function_f64(Function_f64 const* f) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
156 | return new Function_f64(f->function_space()); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
157 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
158 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
159 | Function_f64* clone_Function_f64(Function_f64 const* f) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
160 | return new Function_f64(f->function_space(), std::make_shared<Vector<double>>(*f->x())); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
161 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
162 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
163 | // PyObject* py_similar_Function_f64(Function_f64 const* f) { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
164 | // return nanobind::cast(Function_f64(f->function_space())).release().ptr(); |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
165 | // } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
166 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
167 | } // namespace dolfinx_access |