diff --git a/src/underworld3/discretisation.py b/src/underworld3/discretisation.py index 0a19991f..0bcdb5cf 100644 --- a/src/underworld3/discretisation.py +++ b/src/underworld3/discretisation.py @@ -769,6 +769,9 @@ def nuke_coords_and_rebuild(self): self.dm.copyDS(self.dm_hierarchy[-1]) + # create a kd-tree to store mesh coordinates + self._mesh_kdtree = uw.kdtree.KDTree(self.data) + return @timing.routine_timer_decorator @@ -2118,12 +2121,8 @@ def rbf_interpolate(self, new_coords, meth=0, p=2, verbose=False, nnn=None, rubb with self.mesh.access(self): D = self.data.copy() - if verbose and uw.mpi.rank == 0: - print("Building K-D tree", flush=True) - - mesh_kdt = uw.kdtree.KDTree(self.coords) + mesh_kdt = self.mesh._mesh_kdtree values = mesh_kdt.rbf_interpolator_local(new_coords, D, nnn, p=p, verbose=verbose) - del mesh_kdt return values @@ -2240,10 +2239,9 @@ def write( @timing.routine_timer_decorator def read_timestep( self, - data_filename, data_name, index, - outputPath="", + outputPath:str, verbose=False, ): """ @@ -2259,8 +2257,7 @@ def read_timestep( # mesh.write_timestep( "test", meshUpdates=False, meshVars=[X], outputPath="", index=0) # swarm.write_timestep("test", "swarm", swarmVars=[var], outputPath="", index=0) - output_base_name = os.path.join(outputPath, data_filename) - data_file = output_base_name + f".mesh.{data_name}.{index:05}.h5" + data_file = outputPath + f"_step_{index:05}.h5" # check if data_file exists if os.path.isfile(os.path.abspath(data_file)): @@ -2285,7 +2282,7 @@ def field_from_checkpoint( h5f = h5py.File(data_file) D = h5f["fields"][data_name][()].reshape(-1, self.shape[1]) - X = h5f["fields"]["coordinates"][()].reshape(-1, self.mesh.dim) + X = h5f["geometry"]["vertices"][()].reshape(-1, self.mesh.dim) h5f.close() diff --git a/src/underworld3/kdtree.py b/src/underworld3/kdtree.py index 3bff6a8c..ab09a879 100644 --- a/src/underworld3/kdtree.py +++ b/src/underworld3/kdtree.py @@ -72,7 +72,7 @@ def rbf_interpolator_local_from_kdtree( # can decompose weighting vecotrs as IDW is a linear relationship # build normalise weight vectors and multiply that with known data epsilon = 1e-12 - weights = 1 / np.pow( epsilon+distance_n[:], p) + weights = 1.0 / np.power(epsilon+distance_n[:], p) n_weights = (weights.T / np.sum(weights, axis=1)).T kdata = data[closest_n[:]]