Debian Codegraph @

examples/simulations/heatTransfer/write/HeatTransfer.h

raw
1 /*
2 * SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifndef HEATTRANSFER_H_
8 #define HEATTRANSFER_H_
9
10 #include <mpi.h>
11
12 #include <memory>
13 #include <vector>
14
15 #include "Settings.h"
16
17 class HeatTransfer
18 {
19 public:
20 HeatTransfer(const Settings &settings); // Create two 2D arrays with ghost
21 // cells to compute
22 ~HeatTransfer() = default;
23 void init(bool init_with_rank); // set up array values with either rank or
24 // real demo values
25 void iterate(); // one local calculation step
26 void heatEdges(); // reset the heat values at the global edge
27 void exchange(MPI_Comm comm); // send updates to neighbors
28
29 // return a single value at index i,j. 0 <= i <= ndx+2, 0 <= j <= ndy+2
30 double T(int i, int j) const { return m_TCurrent[i][j]; };
31 // return (1D) pointer to current T data, ndx+2 * ndy+2 elements
32 double *data() const { return m_TCurrent[0]; };
33 // return (1D) pointer to current T data without ghost cells, ndx*ndy
34 // elements
35 std::vector<double> data_noghost() const;
36
37 void printT(std::string message,
38 MPI_Comm comm) const; // debug: print local TCurrent on stdout
39
40 private:
41 const Settings &m_s;
42
43 const double edgetemp = 3.0; // temperature at the edges of the global plate
44 const double omega = 0.8; // weight for current temp is (1-omega) in iteration
45
46 // 2D data arrays (ndx+2) * (ndy+2) size, including ghost cells
47 std::unique_ptr<double[]> m_T1Buf;
48 std::unique_ptr<double[]> m_T2Buf;
49
50 // Double indexable view into the data arrays to allow for m_T1[i][j]
51 std::unique_ptr<double *[]> m_T1;
52 std::unique_ptr<double *[]> m_T2;
53
54 // Track which data array is active
55 double **m_TCurrent;
56 double **m_TNext;
57 };
58
59 #endif /* HEATTRANSFER_H_ */