23 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
24 RegionLayout<T, Dim, Mesh, Properties...>::RegionLayout()
25 : dLocalRegions_m(
"local regions (device)", 0)
26 , hLocalRegions_m(Kokkos::create_mirror_view(dLocalRegions_m)) {
27 indexOffset_m.fill(0);
28 centerOffset_m.fill(0);
32 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
33 RegionLayout<T, Dim, Mesh, Properties...>::RegionLayout(
const FieldLayout<Dim>& fl,
34 const Mesh& mesh,
bool node)
37 changeDomain(fl, mesh);
40 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
41 void RegionLayout<T, Dim, Mesh, Properties...>::changeDomain(
const FieldLayout<Dim>& fl,
44 for (
unsigned int d = 0; d < Dim; ++d) {
45 indexOffset_m[d] = fl.getDomain()[d].first();
46 centerOffset_m[d] = 1;
49 region_m = convertNDIndex(fl.getDomain(), mesh);
51 fillRegions(fl, mesh);
54 for (
unsigned int d = 0; d < Dim; d++) {
55 T firstCoord = region_m[d].min();
56 T lastCoord = region_m[d].max() - mesh.getMeshSpacing()[d];
57 region_m[d] = PRegion<T>(firstCoord, lastCoord);
68 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
69 typename RegionLayout<T, Dim, Mesh, Properties...>::NDRegion_t
70 RegionLayout<T, Dim, Mesh, Properties...>::convertNDIndex(
const NDIndex<Dim>& ni,
71 const Mesh& mesh)
const {
73 NDIndex<Dim> firstPoint, lastPoint;
74 for (
unsigned int d = 0; d < Dim; d++) {
75 int first = ni[d].first() - indexOffset_m[d];
76 int last = ni[d].last() - indexOffset_m[d] + centerOffset_m[d];
77 firstPoint[d] = Index(first, first);
78 lastPoint[d] = Index(last, last);
86 for (
unsigned int d = 0; d < Dim; d++) {
87 if (lastCoord[d] == region_m[d].max()) {
88 lastCoord[d] -= mesh.getMeshSpacing()[d];
94 for (
unsigned int d = 0; d < Dim; d++) {
95 ndregion[d] = PRegion<T>(firstCoord(d), lastCoord(d));
100 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
101 void RegionLayout<T, Dim, Mesh, Properties...>::fillRegions(
const FieldLayout<Dim>& fl,
103 using domain_type =
typename FieldLayout<Dim>::host_mirror_type;
104 const domain_type& ldomains = fl.getHostLocalDomains();
106 Kokkos::resize(hLocalRegions_m, ldomains.size());
107 Kokkos::resize(dLocalRegions_m, ldomains.size());
109 using size_type =
typename domain_type::size_type;
110 for (size_type i = 0; i < ldomains.size(); ++i) {
111 hLocalRegions_m(i) = convertNDIndex(ldomains(i), mesh);
114 Kokkos::deep_copy(dLocalRegions_m, hLocalRegions_m);
117 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
118 void RegionLayout<T, Dim, Mesh, Properties...>::write(std::ostream& out)
const {
119 if (Comm->rank() > 0) {
123 out <<
"Total region = " << region_m <<
"\n"
124 <<
"Total number of subregions = " << hLocalRegions_m.size() <<
"\n";
126 using size_type =
typename host_mirror_type::size_type;
127 for (size_type i = 0; i < hLocalRegions_m.size(); ++i) {
128 out <<
" subregion " << i <<
" " << hLocalRegions_m(i) <<
"\n";
132 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
133 const typename RegionLayout<T, Dim, Mesh, Properties...>::view_type
134 RegionLayout<T, Dim, Mesh, Properties...>::getdLocalRegions()
const {
135 return dLocalRegions_m;
138 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
139 const typename RegionLayout<T, Dim, Mesh, Properties...>::host_mirror_type
140 RegionLayout<T, Dim, Mesh, Properties...>::gethLocalRegions()
const {
141 return hLocalRegions_m;
144 template <
typename T,
unsigned Dim,
class Mesh,
class... Properties>
145 std::ostream& operator<<(std::ostream& out,
const RegionLayout<T, Dim, Mesh>& rl) {