From 5189a275df37b75f1ddd31bdfa521284ddfa5c8e Mon Sep 17 00:00:00 2001 From: Fernando Bordignon Date: Tue, 29 Oct 2024 14:37:23 -0300 Subject: [PATCH] v2.4.13 --- .../pore_networks/functions_simulation.py | 34 +++++-------------- src/ltrace/ltrace/slicer/project_manager.py | 10 ++++-- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/ltrace/ltrace/pore_networks/functions_simulation.py b/src/ltrace/ltrace/pore_networks/functions_simulation.py index 28095b2..6c9b793 100644 --- a/src/ltrace/ltrace/pore_networks/functions_simulation.py +++ b/src/ltrace/ltrace/pore_networks/functions_simulation.py @@ -169,6 +169,7 @@ def set_subresolution_conductance(sub_network, subresolution_function, save_tabl sub_network["throat.cap_radius"] = throat_capilar_radius.copy() sub_network["throat.sub_conductivity"] = throat_conductivity.copy() sub_network["pore.sub_conductivity"] = pore_conductivity.copy() + sub_network["throat.conductance"] = throat_conductance.copy() sub_network["throat.manual_valvatne_conductance_former"] = throat_conductance.copy() sub_network["throat.manual_valvatne_conductance"] = throat_conductance sub_network["throat.number_of_capilaries"] = throat_number_of_capilaries @@ -287,41 +288,24 @@ def single_phase_permeability( for prop in sub_network.keys(): np.nan_to_num(sub_network[prop], copy=False) manual_valvatne_blunt(sub_network) - if is_multiscale: - pass set_subresolution_conductance(sub_network, subresolution_function, save_tables=save_tables) sub_proj = openpnm.io.network_from_porespy(sub_network) ### Network clipping if clip_check: - cond = sub_network["throat.sub_conductivity"].astype(np.float64) + cond = sub_network["throat.conductance"].astype(np.float64) min_cond = cond.min() max_cond = cond.max() cond_range = max_cond / min_cond if cond_range > clip_value: max_clip = min_cond * clip_value cond = np.clip(cond, a_min=None, a_max=max_clip) - sub_network["throat.sub_conductivity"] = cond + sub_network["throat.conductance"][:] = cond sub_proj = openpnm.io.network_from_porespy(sub_network) - elif False: - cond = sub_network["throat.sub_conductivity"].astype(np.float64) - min_cond = cond.min() - max_cond = cond.max() - cond_range = max_cond / min_cond - if cond_range > clip_value: - min_clip = max_cond / clip_value - relevant_throats = cond >= min_clip - preclipped_network = get_sub_spy(sub_network, sub_network["pore.all"], relevant_throats) - preclipped_proj = openpnm.io.network_from_porespy(preclipped_network) - connected_pores, connected_throats = get_connected_spy_network(preclipped_proj.network, in_face, out_face) - clipped_network = get_sub_spy(preclipped_network, connected_pores, connected_throats) - if clipped_network is False: - return 0, None, None - sub_proj = openpnm.io.network_from_porespy(clipped_network) water = openpnm.phase.Water(network=sub_proj.network) water.add_model_collection(openpnm.models.collections.physics.standard) - sub_proj["throat.hydraulic_conductance"] = sub_proj["throat.manual_valvatne_conductance"] + sub_proj["throat.hydraulic_conductance"] = sub_proj["throat.conductance"] sub_proj["pore.phase"][...] = 1 perm = openpnm.algorithms.StokesFlow( network=sub_proj, @@ -351,7 +335,7 @@ def single_phase_permeability( perm.network["throat.flow"] = perm.rate(throats=perm.network.throats("all"), mode="individual") elif solver == "pyflowsolver": conn = perm.network["throat.conns"].astype(np.int32) - cond = perm.network["throat.sub_conductivity"].astype(np.float64) + cond = perm.network["throat.conductance"].astype(np.float64) r = _get_sparse_system(conn, cond, inlets, outlets) sparse_val, sparse_col_idx, sparse_row_ptr, b, mid_to_total_indexes = r if preconditioner == "inverse_diagonal": @@ -386,7 +370,7 @@ def single_phase_permeability( pressure[i] = np.float64(0) elif solver == "pypardiso": conn = perm.network["throat.conns"].astype(np.int32) - cond = perm.network["throat.sub_conductivity"].astype(np.float64) + cond = perm.network["throat.conductance"].astype(np.float64) r = _get_sparse_system(conn, cond, inlets, outlets) sparse_val, sparse_col_idx, sparse_row_ptr, b, mid_to_total_indexes = r A = csr_matrix( @@ -433,8 +417,6 @@ def single_phase_permeability( output[: x.size] = x pore_dict["pore.pressure"] = pressure - throat_dict["throat.cond"] = cond - return (perm, pore_dict, throat_dict) @@ -579,7 +561,7 @@ def get_flow_rate(pn_pores, pn_throats): for throat in range(pn_throats["throat.all"].size): p0 = pn_throats["throat.conns_0"][throat] p1 = pn_throats["throat.conns_1"][throat] - c = pn_throats["throat.sub_conductivity"][throat] + c = pn_throats["throat.conductance"][throat] delta_p[throat] = np.abs(p0 - p1) flow[throat] = delta_p[throat] * c pn_throats["throat.flow"] = flow @@ -589,7 +571,7 @@ def get_flow_rate(pn_pores, pn_throats): for throat in range(pn_throats["throat.all"].size): p0 = pn_throats["throat.conns_0"][throat] p1 = pn_throats["throat.conns_1"][throat] - c = pn_throats["throat.sub_conductivity"][throat] + c = pn_throats["throat.conductance"][throat] if inlets[p0] and (not border_pore[p1]): inlet_flow_total += c * (np.float64(101325.0) - pn_pores["pore.pressure"][p1]) inlet_flow[throat] = c * (np.float64(101325.0) - pn_pores["pore.pressure"][p1]) diff --git a/src/ltrace/ltrace/slicer/project_manager.py b/src/ltrace/ltrace/slicer/project_manager.py index 49ea399..82d552b 100644 --- a/src/ltrace/ltrace/slicer/project_manager.py +++ b/src/ltrace/ltrace/slicer/project_manager.py @@ -171,18 +171,22 @@ def save_as(self, scene_path, *args, **kwargs): if scene_path.is_file(): slicer.util.errorDisplay(f'Cannot create project directory at "{scene_path}" because it is a file.') self.__set_project_modified(True) + slicer.mrmlScene.EndState(slicer.mrmlScene.SaveState) return SaveStatus.FAILED_FILE_ALREADY_EXISTS try: scene_path.mkdir(parents=True, exist_ok=True) except Exception as error: logging.error("Failed during attempt to create new project directory.") + self.__set_project_modified(True) + slicer.mrmlScene.EndState(slicer.mrmlScene.SaveState) return SaveStatus.FAILED status = self.save(str(scene_path), internal_call=True, *args, **kwargs) if status != SaveStatus.SUCCEED and status != SaveStatus.IN_PROGRESS: # CANCELLED or FAILED options self.__set_project_modified(True) + slicer.mrmlScene.EndState(slicer.mrmlScene.SaveState) return status self.__configure_project_folder(str(scene_path)) @@ -190,6 +194,7 @@ def save_as(self, scene_path, *args, **kwargs): if project_file is None: self.__set_project_modified(True) + slicer.mrmlScene.EndState(slicer.mrmlScene.SaveState) return SaveStatus.FAILED slicer.mrmlScene.EndState(slicer.mrmlScene.SaveState) @@ -523,8 +528,8 @@ def __save_nodes(self, *args, **kwargs): continue file_path = str(file_path) - node_status = slicer.util.saveNode(node, file_path) - if not node_status: + status = slicer.util.saveNode(node, file_path) + if not status: logging.error( "Failed to save {} node's file at the location: {}\n{}".format( node.GetName(), file_path, traceback.format_exc() @@ -533,7 +538,6 @@ def __save_nodes(self, *args, **kwargs): return False else: logging.debug("Node {} was saved succesfully at {}".format(node.GetName(), file_path)) - status &= node_status for file_path in files_to_delete: file_path.unlink()