omega_h
Reliable mesh adaptation
Omega_h_bbox.hpp
1 #ifndef OMEGA_H_BBOX_HPP
2 #define OMEGA_H_BBOX_HPP
3 
4 #include <Omega_h_affine.hpp>
5 #include <Omega_h_vector.hpp>
6 
7 namespace Omega_h {
8 
9 class Mesh;
10 
11 #ifdef OMEGA_H_USE_KOKKOS
12 
13 template <Int dim>
14 struct BBox {
15  OMEGA_H_INLINE BBox() {}
16  OMEGA_H_INLINE BBox(Vector<dim> x) : min(x), max(x) {}
17  OMEGA_H_INLINE BBox(Vector<dim> min_, Vector<dim> max_)
18  : min(min_), max(max_) {}
19  Vector<dim> min;
20  Vector<dim> max;
21  /* playing the volatile game again (see int128.hpp) */
22  OMEGA_H_INLINE void operator=(BBox<dim> const& rhs) {
23  min = rhs.min;
24  max = rhs.max;
25  }
26  OMEGA_H_INLINE BBox(BBox<dim> const& rhs) : min(rhs.min), max(rhs.max) {}
27 };
28 
29 #else
30 
31 template <Int dim>
32 struct BBox {
33  Vector<dim> min;
34  Vector<dim> max;
35  inline BBox() = default;
36  OMEGA_H_INLINE BBox(Vector<dim> x) : min(x), max(x) {}
37  OMEGA_H_INLINE BBox(Vector<dim> min_, Vector<dim> max_)
38  : min(min_), max(max_) {}
39  inline BBox(BBox const&) = default;
40  inline BBox(BBox&&) = default;
41  inline BBox& operator=(BBox const&) = default;
42  inline BBox& operator=(BBox&&) = default;
43 };
44 
45 #endif
46 
47 template <Int dim>
48 OMEGA_H_INLINE BBox<dim> unite(BBox<dim> a, BBox<dim> b) {
49  BBox<dim> c;
50  for (Int i = 0; i < dim; ++i) {
51  c.min[i] = min2(a.min[i], b.min[i]);
52  c.max[i] = max2(a.max[i], b.max[i]);
53  }
54  return c;
55 }
56 
57 template <Int dim>
58 OMEGA_H_INLINE bool are_close(BBox<dim> a, BBox<dim> b) {
59  return are_close(a.min, b.min) && are_close(a.max, b.max);
60 }
61 
62 template <Int dim>
63 OMEGA_H_INLINE BBox<dim> make_equilateral(BBox<dim> bbox) {
64  auto maxl = reduce(bbox.max - bbox.min, maximum<Real>());
65  for (Int i = 0; i < dim; ++i) bbox.max[i] = bbox.min[i] + maxl;
66  return bbox;
67 }
68 
69 template <Int dim>
70 OMEGA_H_INLINE Affine<dim> get_affine_from_bbox_into_unit(BBox<dim> bbox) {
71  Vector<dim> s;
72  for (Int i = 0; i < dim; ++i) s[i] = 1.0 / (bbox.max[i] - bbox.min[i]);
73  Affine<dim> a;
74  a.r = diagonal(s);
75  a.t = -(a.r * bbox.min);
76  return a;
77 }
78 
79 template <Int dim>
80 BBox<dim> find_bounding_box(Reals coords);
81 
82 template <Int dim>
83 BBox<dim> get_bounding_box(Mesh* mesh);
84 
85 extern template BBox<1> find_bounding_box<1>(Reals coords);
86 extern template BBox<2> find_bounding_box<2>(Reals coords);
87 extern template BBox<3> find_bounding_box<3>(Reals coords);
88 
89 extern template BBox<1> get_bounding_box<1>(Mesh* mesh);
90 extern template BBox<2> get_bounding_box<2>(Mesh* mesh);
91 extern template BBox<3> get_bounding_box<3>(Mesh* mesh);
92 
93 } // end namespace Omega_h
94 
95 #endif
Definition: Omega_h_few.hpp:61
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_bbox.hpp:32