83 long long step,
double time,
double zPlane,
const FieldType& field,
84 const std::string& solveTag) {
85 const auto lDom = field.getLayout().getLocalNDIndex();
86 const int nghost = field.getNghost();
87 const auto spacing = field.get_mesh().getMeshSpacing();
88 const auto origin = field.get_mesh().getOrigin();
90 if (spacing[0] <= 0.0 || spacing[1] <= 0.0 || spacing[2] <= 0.0) {
92 "DirichletPlaneWriter::dumpInterpolatedPlane",
93 "Mesh spacing must be positive in all dimensions.");
96 const int nxOwned = lDom[0].length();
97 const int nyOwned = lDom[1].length();
98 const int nzOwned = lDom[2].length();
99 if (nxOwned <= 0 || nyOwned <= 0 || nzOwned <= 0) {
103 const std::size_t nx =
static_cast<std::size_t
>(nxOwned);
104 const std::size_t ny =
static_cast<std::size_t
>(nyOwned);
106 const int kMinGlobal = lDom[2].first();
107 const int kMaxGlobal = lDom[2].last();
109 const double kFloatRaw = (zPlane - origin[2]) / spacing[2] - 0.5;
110 const double kFloat = std::min(
111 std::max(kFloatRaw,
static_cast<double>(kMinGlobal)),
static_cast<double>(kMaxGlobal));
113 int k0Global =
static_cast<int>(std::floor(kFloat));
114 int k1Global = k0Global + 1;
115 k0Global = std::max(kMinGlobal, std::min(k0Global, kMaxGlobal));
116 k1Global = std::max(kMinGlobal, std::min(k1Global, kMaxGlobal));
118 const double alpha = (k1Global == k0Global) ? 0.0 : (kFloat -
static_cast<double>(k0Global));
120 const int k0Local = k0Global - lDom[2].first() + nghost;
121 const int k1Local = k1Global - lDom[2].first() + nghost;
123 using exec_space =
typename FieldType::execution_space;
124 using mem_space =
typename FieldType::view_type::memory_space;
126 const std::size_t nxy = nx * ny;
127 Kokkos::View<double**, mem_space> planeDevice(
"dirichlet_plane", nx, ny);
128 auto fieldView = field.getView();
130 Kokkos::parallel_for(
131 "DirichletPlaneWriter::interpolatePlane", Kokkos::RangePolicy<exec_space>(0, nxy),
132 KOKKOS_LAMBDA(
const std::size_t idx) {
133 const std::size_t ii = idx / ny;
134 const std::size_t jj = idx - ii * ny;
136 const int iLocal =
static_cast<int>(ii) + nghost;
137 const int jLocal =
static_cast<int>(jj) + nghost;
139 const double phi0 = fieldView(iLocal, jLocal, k0Local);
140 const double phi1 = fieldView(iLocal, jLocal, k1Local);
141 planeDevice(ii, jj) = (1.0 - alpha) * phi0 + alpha * phi1;
145 Kokkos::parallel_reduce(
146 "DirichletPlaneWriter::sumPlane", Kokkos::RangePolicy<exec_space>(0, nxy),
147 KOKKOS_LAMBDA(
const std::size_t idx,
double& acc) {
148 const std::size_t ii = idx / ny;
149 const std::size_t jj = idx - ii * ny;
150 acc += planeDevice(ii, jj);
155 Kokkos::parallel_reduce(
156 "DirichletPlaneWriter::sumSqPlane", Kokkos::RangePolicy<exec_space>(0, nxy),
157 KOKKOS_LAMBDA(
const std::size_t idx,
double& acc) {
158 const std::size_t ii = idx / ny;
159 const std::size_t jj = idx - ii * ny;
160 const double v = planeDevice(ii, jj);
165 auto planeHost = Kokkos::create_mirror_view(planeDevice);
166 Kokkos::deep_copy(planeHost, planeDevice);
168 std::vector<double> xCoords(nx, 0.0);
169 std::vector<double> yCoords(ny, 0.0);
170 std::vector<double> phiValues(nxy, 0.0);
172 for (std::size_t i = 0; i < nx; ++i) {
173 const int iGlobal = lDom[0].first() +
static_cast<int>(i);
174 xCoords[i] = origin[0] + (
static_cast<double>(iGlobal) + 0.5) * spacing[0];
176 for (std::size_t j = 0; j < ny; ++j) {
177 const int jGlobal = lDom[1].first() +
static_cast<int>(j);
178 yCoords[j] = origin[1] + (
static_cast<double>(jGlobal) + 0.5) * spacing[1];
181 for (std::size_t i = 0; i < nx; ++i) {
182 for (std::size_t j = 0; j < ny; ++j) {
183 phiValues[i * ny + j] = planeHost(i, j);
187 writePlane(step, time, zPlane, xCoords, yCoords, phiValues, nx, ny, solveTag);
191 diagnostics.
mean = sum /
static_cast<double>(nxy);
192 diagnostics.
variance = sumSq /
static_cast<double>(nxy) - diagnostics.
mean * diagnostics.
mean;
void writePlane(long long step, double time, double zPlane, const std::vector< double > &xCoords, const std::vector< double > &yCoords, const std::vector< double > &phiValues, std::size_t nx, std::size_t ny, const std::string &solveTag)
Write one plane snapshot.