DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
CartGridField.py
Go to the documentation of this file.
1from DNDSR import DNDS, Geom
2import numpy as np
3
4
7 self, rs: int, local_shape: tuple[int, int], mpi: DNDS.MPIInfo, rs_dyn=None
8 ):
9 self._mpi = mpi
10 self._rs = rs
11 self._local_shape = local_shape
12 self._local_array_shape = local_shape + (rs,)
13 local_size = np.array(local_shape, dtype=np.int64).prod()
14 arrPair = DNDS.ArrayEigenVectorPair(rs)
15 arrPair.father = DNDS.ArrayEigenVector(rs, init_args=(mpi,))
16 arrPair.son = DNDS.ArrayEigenVector(rs, init_args=(mpi,))
17 arrPair.TransAttach()
18
19 arrPair.father.Resize(local_size)
20 self.pair = arrPair
21
22 @property
23 def main(self):
24 return self.pair.father
25
26 @property
27 def ghost(self):
28 return self.pair.son
29
30 @property
31 def trans(self):
32 return self.pair.trans
33
34 @property
35 def mdata(self):
36 return np.array(self.main.data(), copy=False).reshape(self._local_array_shape)
37
38 def set_main_data(self, data):
39 dist_field = self
40 main_mem = np.array(dist_field.main.data(), copy=False)
41 main_mem.flat = data.flat
42
43 assert (np.array(dist_field.main.data()) == data.flat).all()
44
46 dist_field = self
48 main_mem = np.array(dist_field.main.data(), copy=False)
49 main_mem.flat = data[cr[0][0] : cr[0][1], cr[1][0] : cr[1][1]].flat
50
51 assert (
52 np.array(dist_field.main.data())
53 == data[cr[0][0] : cr[0][1], cr[1][0] : cr[1][1]].flat
54 ).all()
55
56 def set_ghost_global_pull(self, pullIdx):
57 self.pair.trans.createFatherGlobalMapping()
58 self.pair.trans.createGhostMapping(pullIdx)
59 self.pair.trans.createMPITypes()
60 self.pair.trans.initPersistentPull()
61
63 self,
64 expanded_shape,
65 core_range_in_expanded,
66 grid_point_expanded_idxs_g_ijks_local,
67 ):
68 self._expanded_shape = expanded_shape
69 self._expanded_array_shape = expanded_shape + (self._rs,)
70 self._core_range_in_expanded = core_range_in_expanded
72 grid_point_expanded_idxs_g_ijks_local
73 )
74
76 mpi = self._mpi
77 data_expanded = np.ones(self._expanded_array_shape) * 1e301
79 ghost_is, ghost_js = self._grid_point_expanded_idxs_g_ijks_local
80
81 data_expanded[cr[0][0] : cr[0][1], cr[1][0] : cr[1][1]] = self.mdata
82 if ghost_is.size:
83 data_expanded[ghost_is, ghost_js] = np.array(self.ghost.data()).reshape(
84 (-1, self._rs)
85 )
86 return data_expanded
87
88
89# class CartGridIndTable:
90# def __init__(self, local_shape: tuple[int, int], mpi: DNDS.MPIInfo, rs_dyn=None):
91# self._mpi = mpi
92# self._local_shape = local_shape
93# local_size = np.array(local_shape, dtype=np.int64).prod()
94
95# arrPair = DNDS.ArrayAdjacencyPair("I")
96# arrPair.father = DNDS.ArrayAdjacency("I", init_args=(mpi,))
97# arrPair.son = DNDS.ArrayAdjacency("I", init_args=(mpi,))
98# arrPair.TransAttach()
99
100# arrPair.father.Resize(local_size)
101# self.pair = arrPair
102
103# @property
104# def main(self):
105# return self.pair.father
106
107# @property
108# def ghost(self):
109# return self.pair.son
110
111# @property
112# def trans(self):
113# return self.pair.trans
ParArray<real, N> whose operator[] returns an Eigen::Map<Vector>.
set_ghost_info(self, expanded_shape, core_range_in_expanded, grid_point_expanded_idxs_g_ijks_local)
__init__(self, int rs, tuple[int, int] local_shape, DNDS.MPIInfo mpi, rs_dyn=None)
int main()
Definition dummy.cpp:3
Convenience bundle of a father, son, and attached ArrayTransformer.
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:215
ArrayTransformer< DNDS::real, DynamicSize > trans