def _save_auxiliary_basis_functions_matrix(self, key): # Get full directory name full_directory = Folders.Folder(os.path.join(str(self._auxiliary_io_directory), self._auxiliary_io_filename)) full_directory.create() # Save auxiliary basis functions matrix auxiliary_basis_functions_matrix = self._auxiliary_basis_functions_matrix[key] full_directory_plus_key = Folders.Folder(full_directory + "/auxiliary_basis_functions/" + self._auxiliary_key_to_folder(key)) full_directory_plus_key.create() auxiliary_basis_functions_matrix.save(full_directory_plus_key, "auxiliary_basis")
def _load_auxiliary_basis_functions_matrix(self, key, auxiliary_reduced_problem, auxiliary_reduced_V): # Get full directory name full_directory = Folders.Folder(os.path.join(str(self._auxiliary_io_directory), self._auxiliary_io_filename)) full_directory.create() # Load auxiliary basis functions matrix full_directory_plus_key = Folders.Folder(full_directory + "/auxiliary_basis_functions/" + self._auxiliary_key_to_folder(key)) if not full_directory_plus_key.create(): auxiliary_basis_functions_matrix = self._init_auxiliary_basis_functions_matrix(key, auxiliary_reduced_problem, auxiliary_reduced_V) auxiliary_basis_functions_matrix.load(full_directory_plus_key, "auxiliary_basis") self._auxiliary_basis_functions_matrix[key] = auxiliary_basis_functions_matrix return True else: return False
def __init__(self, folder_prefix): # I/O self.folder_prefix = folder_prefix self.folder = Folders() # $$ OFFLINE DATA STRUCTURES $$ # # Maximum reduced order space dimension to be used for the stopping criterion in the basis selection self.Nmax = 0 # Tolerance to be used for the stopping criterion in the basis selection self.tol = 0. # Training set self.training_set = ParameterSpaceSubset() # I/O self.folder["training_set"] = os.path.join(self.folder_prefix, "training_set") # $$ ERROR ANALYSIS AND SPEEDUP ANALYSIS DATA STRUCTURES $$ # # Testing set self.testing_set = ParameterSpaceSubset() # I/O self.folder["testing_set"] = os.path.join(self.folder_prefix, "testing_set") self.folder["error_analysis"] = os.path.join(self.folder_prefix, "error_analysis") self.folder["speedup_analysis"] = os.path.join(self.folder_prefix, "speedup_analysis")
def save(self, directory, filename): # Get full directory name full_directory = Folders.Folder( os.path.join(str(directory), filename)) full_directory.create() # Save reduced mesh self._reduced_mesh.save(directory, filename)
def save(self, directory, filename): # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) full_directory.create() # Save problem corresponding to self._lhs assert self._lhs is not None LHSIO.save_file( get_reduced_problem_from_riesz_solve_inner_product( self._lhs).truth_problem.name(), full_directory, "lhs_problem_name") # Save problem corresponding to self._solution assert self._solution is not None SolutionIO.save_file( get_reduced_problem_from_riesz_solve_storage( self._solution).truth_problem.name(), full_directory, "solution_problem_name") # Save problem and operator corresponding to self._rhs assert self._rhs is not None assert isinstance(self._rhs, (AbstractParametrizedTensorFactory, DelayedProduct)) if isinstance(self._rhs, AbstractParametrizedTensorFactory): RHSIO.save_file("ParametrizedTensorFactory", full_directory, "rhs_type") rhs_arg_0 = self._rhs rhs_problem_name_0 = get_problem_from_parametrized_operator( rhs_arg_0).name() (rhs_term_0, rhs_index_0 ) = get_term_and_index_from_parametrized_operator(rhs_arg_0) RHSIO.save_file((rhs_problem_name_0, rhs_term_0, rhs_index_0), full_directory, "rhs_arg_0") elif isinstance(self._rhs, DelayedProduct): RHSIO.save_file("DelayedProduct", full_directory, "rhs_type") assert len(self._rhs._args) is 3 rhs_arg_0 = self._rhs._args[0] assert rhs_arg_0 == -1.0 RHSIO.save_file(rhs_arg_0, full_directory, "rhs_arg_0") assert isinstance(self._rhs._args[1], AbstractParametrizedTensorFactory) rhs_arg_1 = self._rhs._args[1] rhs_problem_name_1 = get_problem_from_parametrized_operator( rhs_arg_1).name() (rhs_term_1, rhs_index_1 ) = get_term_and_index_from_parametrized_operator(rhs_arg_1) RHSIO.save_file((rhs_problem_name_1, rhs_term_1, rhs_index_1), full_directory, "rhs_arg_1") rhs_arg_2 = self._rhs._args[2] rhs_problem_name_2 = rhs_problem_name_1 (rhs_component_2, rhs_index_2 ) = get_component_and_index_from_basis_function(rhs_arg_2) RHSIO.save_file((rhs_problem_name_2, rhs_component_2, rhs_index_2), full_directory, "rhs_arg_2") else: raise TypeError("Invalid rhs") # Save problem corresponding to self._bcs BCsIO.save_file( get_reduced_problem_from_riesz_solve_homogeneous_dirichlet_bc( self._bcs).truth_problem.name(), full_directory, "bcs_problem_name") # Save parameters ParametersIO.save_file(self._parameters, full_directory, "parameters")
def save(self, directory, filename): # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) full_directory.create() # Export depending on type TypeIO.save_file(self._type, full_directory, "type") assert self._type in ("basis_functions_matrix", "empty", "error_estimation_operators_11", "error_estimation_operators_21", "error_estimation_operators_22", "functions_list", "operators") if self._type in ("basis_functions_matrix", "functions_list"): # Save delayed functions delayed_functions = self._content[self._type] it = NonAffineExpansionStorageContent_Iterator(delayed_functions, flags=["c_index", "multi_index", "refs_ok"], op_flags=["readonly"]) while not it.finished: delayed_function = delayed_functions[it.multi_index] delayed_function.save(full_directory, "delayed_functions_" + str(it.index)) it.iternext() elif self._type == "empty": pass elif self._type in ("error_estimation_operators_11", "error_estimation_operators_21", "error_estimation_operators_22"): # Save delayed functions delayed_function_type = { DelayedBasisFunctionsMatrix: "DelayedBasisFunctionsMatrix", DelayedLinearSolver: "DelayedLinearSolver" } assert len(self._content["delayed_functions"]) is 2 for (index, delayed_functions) in enumerate(self._content["delayed_functions"]): it = NonAffineExpansionStorageContent_Iterator(delayed_functions, flags=["c_index", "refs_ok"], op_flags=["readonly"]) while not it.finished: delayed_function = delayed_functions[it.index] DelayedFunctionsTypeIO.save_file(delayed_function_type[type(delayed_function)], full_directory, "delayed_functions_" + str(index) + "_" + str(it.index) + "_type") DelayedFunctionsProblemNameIO.save_file(delayed_function.get_problem_name(), full_directory, "delayed_functions_" + str(index) + "_" + str(it.index) + "_problem_name") delayed_function.save(full_directory, "delayed_functions_" + str(index) + "_" + str(it.index) + "_content") it.iternext() ErrorEstimationInnerProductIO.save_file(get_reduced_problem_from_error_estimation_inner_product(self._content["inner_product_matrix"]).truth_problem.name(), full_directory, "inner_product_matrix_problem_name") elif self._type == "operators": # Save truth content it = NonAffineExpansionStorageContent_Iterator(self._content["truth_operators"], flags=["c_index", "multi_index", "refs_ok"], op_flags=["readonly"]) while not it.finished: operator = self._content["truth_operators"][it.multi_index] assert isinstance(operator, (AbstractParametrizedTensorFactory, NumericForm)) if isinstance(operator, AbstractParametrizedTensorFactory): problem_name = get_problem_from_parametrized_operator(operator).name() (term, index) = get_term_and_index_from_parametrized_operator(operator) TruthContentItemIO.save_file("ParametrizedTensorFactory", full_directory, "truth_operator_" + str(it.index) + "_type") TruthContentItemIO.save_file((problem_name, term, index), full_directory, "truth_operator_" + str(it.index)) elif isinstance(operator, NumericForm): TruthContentItemIO.save_file("NumericForm", full_directory, "truth_operator_" + str(it.index) + "_type") TruthContentItemIO.save_file(operator, full_directory, "truth_operator_" + str(it.index)) else: raise TypeError("Invalid operator type") it.iternext() assert "truth_operators_as_expansion_storage" in self._content # Save basis functions content assert len(self._content["basis_functions"]) in (0, 1, 2) BasisFunctionsContentLengthIO.save_file(len(self._content["basis_functions"]), full_directory, "basis_functions_length") for (index, basis_functions) in enumerate(self._content["basis_functions"]): BasisFunctionsProblemNameIO.save_file(get_reduced_problem_from_basis_functions(basis_functions).truth_problem.name(), full_directory, "basis_functions_" + str(index) + "_problem_name") BasisFunctionsProblemNameIO.save_file(basis_functions._components_name, full_directory, "basis_functions_" + str(index) + "_components_name") else: raise ValueError("Invalid type")
def save(self, directory, filename): # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) full_directory.create() # Save Nmax self._save_Nmax(full_directory) # Save non hierarchical content for (N, affine_expansion_N) in self._content.items(): self._save_content(N, affine_expansion_N, directory, filename)
def patched_method(self, directory, filename): # Get full directory name full_directory = Folders.Folder( os.path.join( str(directory), _OfflineOnlineExpansionStorage_Base. _current_stage)) full_directory.create() # Call original implementation return original_method(full_directory, filename)
def create_folders(): folders = list() folders.append("basis") folders.append("networks") folders.append("reduced_solve") folders.append("reduced_error") folders.append("sets") folders.append("truth_solve") for folder in folders: Folders.Folder(folder).create()
def save(self, directory, filename): # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) full_directory.create() # Save list length self._save_len(full_directory) # Save list item vector dimension self._save_item_vector_dimension(full_directory) # Save list self._save_list(full_directory)
def __init__(self, folder_prefix): # Current parameters value self.mu = tuple() # tuple of real numbers # Parameter ranges self.mu_range = list( ) # list of (min, max) pairs, such that len(self.mu) == len(self.mu_range) # self.folder_prefix = folder_prefix self.folder = Folders()
def save(self, directory, filename): self._assert_dict_lengths() # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) full_directory.create() # Nmax self._save_Nmax(directory, filename) # reduced_mesh for (index, reduced_mesh) in self.reduced_mesh.items(): mesh_filename = os.path.join(str(directory), filename, "reduced_mesh_" + str(index)) with MeshFile(self.mesh.mpi_comm(), self.mesh.geometry().dim(), mesh_filename, "w") as output_file: output_file.write(reduced_mesh) # cannot save reduced_function_spaces to file # reduced_subdomain_data if self.subdomain_data is not None: for (index, reduced_subdomain_data) in self.reduced_subdomain_data.items(): subdomain_index = 0 for (subdomain, reduced_subdomain) in reduced_subdomain_data.items(): subdomain_filename = os.path.join(str(directory), filename, "reduced_mesh_" + str(index) + "_subdomain_" + str(subdomain_index)) with MeshFunctionFile(self.mesh.mpi_comm(), self.mesh.geometry().dim(), subdomain_filename, "w") as output_file: output_file.write(reduced_subdomain) subdomain_index += 1 # reduced_mesh_markers for (index, reduced_mesh_markers) in self.reduced_mesh_markers.items(): marker_filename = os.path.join(str(directory), filename, "reduced_mesh_" + str(index) + "_markers") with MeshFunctionFile(self.mesh.mpi_comm(), self.mesh.geometry().dim(), marker_filename, "w") as output_file: output_file.write(reduced_mesh_markers) # Init self._init_for_save_if_needed() # reduced_mesh_dofs_list exportable_reduced_mesh_dofs_list = ExportableList("pickle") for reduced_mesh_dof in self.reduced_mesh_dofs_list: for (component, reduced_mesh_dof__component) in enumerate(reduced_mesh_dof): exportable_reduced_mesh_dofs_list.append(self.reduced_mesh_dofs_list__dof_map_writer_mapping[component][reduced_mesh_dof__component]) exportable_reduced_mesh_dofs_list.save(full_directory, "dofs") # reduced_mesh_reduced_dofs_list for (index, reduced_mesh_reduced_dofs_list) in self.reduced_mesh_reduced_dofs_list.items(): exportable_reduced_mesh_reduced_dofs_list = ExportableList("pickle") for reduced_mesh_reduced_dof in reduced_mesh_reduced_dofs_list: for (component, reduced_mesh_reduced_dof__component) in enumerate(reduced_mesh_reduced_dof): exportable_reduced_mesh_reduced_dofs_list.append(self.reduced_mesh_reduced_dofs_list__dof_map_writer_mapping[index][component][reduced_mesh_reduced_dof__component]) exportable_reduced_mesh_reduced_dofs_list.save(full_directory, "reduced_dofs_" + str(index)) # == Auxiliary basis functions == # # We will not save anything, because saving to file is handled by get_auxiliary_* methods. # We need howewer to store the directory and filename where to save if self._auxiliary_io_directory is None: self._auxiliary_io_directory = directory else: assert self._auxiliary_io_directory == directory if self._auxiliary_io_filename is None: self._auxiliary_io_filename = filename else: assert self._auxiliary_io_filename == filename
def load(self, directory, filename): if len(self._content) > 0: # avoid loading multiple times return False # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) # Load Nmax Nmax = self._load_Nmax(full_directory) # Load non hierarchical content for N in range(1, Nmax + 1): self._content[N] = self._load_content(N, directory, filename) # Return return True
def _save_auxiliary_reduced_function_space(self, key): # Get full directory name full_directory = Folders.Folder(os.path.join(str(self._auxiliary_io_directory), self._auxiliary_io_filename)) full_directory.create() # Init self._init_for_auxiliary_save_if_needed() # Save auxiliary dofs and reduced dofs auxiliary_dofs_to_reduced_dofs = self._auxiliary_dofs_to_reduced_dofs[key] # ... auxiliary dofs exportable_auxiliary_dofs = ExportableList("pickle") for auxiliary_dof in auxiliary_dofs_to_reduced_dofs.keys(): exportable_auxiliary_dofs.append(self._auxiliary_dofs__dof_map_writer_mapping[key[0]][auxiliary_dof]) full_directory_plus_key__dofs = Folders.Folder(full_directory + "/auxiliary_dofs/" + self._auxiliary_key_to_folder(key)) full_directory_plus_key__dofs.create() exportable_auxiliary_dofs.save(full_directory_plus_key__dofs, "auxiliary_dofs") # ... auxiliary reduced dofs exportable_auxiliary_reduced_dofs = ExportableList("pickle") for auxiliary_reduced_dof in auxiliary_dofs_to_reduced_dofs.values(): exportable_auxiliary_reduced_dofs.append(self._auxiliary_reduced_dofs__dof_map_writer_mapping[key][auxiliary_reduced_dof]) full_directory_plus_key__reduced_dofs = Folders.Folder(full_directory + "/auxiliary_reduced_dofs/" + self._auxiliary_key_to_folder(key)) full_directory_plus_key__reduced_dofs.create() exportable_auxiliary_reduced_dofs.save(full_directory_plus_key__reduced_dofs, "auxiliary_reduced_dofs")
def _load_auxiliary_reduced_function_space(self, key): # Get full directory name full_directory = Folders.Folder(os.path.join(str(self._auxiliary_io_directory), self._auxiliary_io_filename)) full_directory.create() # Init self._init_for_auxiliary_load_if_needed() # Load auxiliary dofs and reduced dofs importable_auxiliary_dofs = ExportableList("pickle") importable_auxiliary_reduced_dofs = ExportableList("pickle") full_directory_plus_key__dofs = Folders.Folder(full_directory + "/auxiliary_dofs/" + self._auxiliary_key_to_folder(key)) full_directory_plus_key__reduced_dofs = Folders.Folder(full_directory + "/auxiliary_reduced_dofs/" + self._auxiliary_key_to_folder(key)) if not full_directory_plus_key__dofs.create() and not full_directory_plus_key__reduced_dofs.create(): importable_auxiliary_dofs.load(full_directory_plus_key__dofs, "auxiliary_dofs") importable_auxiliary_reduced_dofs.load(full_directory_plus_key__reduced_dofs, "auxiliary_reduced_dofs") auxiliary_dofs_to_reduced_dofs = dict() for (dof_input, reduced_dof_input) in zip(importable_auxiliary_dofs, importable_auxiliary_reduced_dofs): dof = self._auxiliary_dofs__dof_map_reader_mapping[key[0]][dof_input[0]][dof_input[1]] reduced_dof = self._auxiliary_reduced_dofs__dof_map_reader_mapping[key][reduced_dof_input[0]][reduced_dof_input[1]] auxiliary_dofs_to_reduced_dofs[dof] = reduced_dof self._auxiliary_dofs_to_reduced_dofs[key] = auxiliary_dofs_to_reduced_dofs return True else: return False
def load(self, directory, filename): if len(self._list) > 0: # avoid loading multiple times return False else: # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) # Load list length len_ = self._load_len(full_directory) # Load list item vector dimension reference_vector = self._load_item_vector_dimension(full_directory) # Load list self._load_list(len_, reference_vector, full_directory) # Return return True
def load(self, directory, filename): if self._content is not None: # avoid loading multiple times if self._content.size > 0: it = AffineExpansionStorageContent_Iterator( self._content, flags=["multi_index", "refs_ok"], op_flags=["readonly"]) while not it.finished: if self._content[ it. multi_index] is not None: # ... but only if there is at least one element different from None if isinstance(self._content[it.multi_index], AbstractFunctionsList): if len( self._content[it.multi_index] ) > 0: # ... unless it is an empty FunctionsList return False elif isinstance(self._content[it.multi_index], AbstractBasisFunctionsMatrix): if sum( self._content[it.multi_index]. _component_name_to_basis_component_length .values() ) > 0: # ... unless it is an empty BasisFunctionsMatrix return False else: return False it.iternext() # Get full directory name full_directory = Folders.Folder( os.path.join(str(directory), filename)) # Exit in the trivial case of empty affine expansion if self._content.size is 0: return True # Load content item type and shape reference_item = self._load_content_item_type_shape(full_directory) # Initialize iterator it = AffineExpansionStorageContent_Iterator( self._content, flags=["c_index", "multi_index", "refs_ok"]) # Load content self._load_content(reference_item, it, full_directory) # Load dicts self._load_dicts(full_directory) # Reset precomputed slices self._precomputed_slices.clear() self._prepare_trivial_precomputed_slice(reference_item) # Return return True
def save(self, directory, filename): # Get full directory name full_directory = Folders.Folder( os.path.join(str(directory), filename)) full_directory.create() # Exit in the trivial case of empty affine expansion if self._content.size is 0: return # Initialize iterator it = AffineExpansionStorageContent_Iterator( self._content, flags=["c_index", "multi_index", "refs_ok"], op_flags=["readonly"]) # Save content item type and shape self._save_content_item_type_shape(self._content[it.multi_index], it, full_directory) # Save content self._save_content(self._content[it.multi_index], it, full_directory) # Save dicts self._save_dicts(full_directory)
def load(self, directory, filename): # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) # Load problem corresponding to self._lhs, and update self._lhs accordingly assert self._lhs is None assert LHSIO.exists_file(full_directory, "lhs_problem_name") lhs_problem_name = LHSIO.load_file(full_directory, "lhs_problem_name") lhs_problem = get_problem_from_problem_name(lhs_problem_name) lhs_reduced_problem = get_reduced_problem_from_problem(lhs_problem) self._lhs = lhs_reduced_problem._riesz_solve_inner_product # Load problem corresponding to self._solution, and update self._solution accordingly assert self._solution is None assert SolutionIO.exists_file(full_directory, "solution_problem_name") solution_problem_name = SolutionIO.load_file(full_directory, "solution_problem_name") solution_problem = get_problem_from_problem_name(solution_problem_name) solution_reduced_problem = get_reduced_problem_from_problem( solution_problem) self._solution = solution_reduced_problem._riesz_solve_storage # Load problem and operator corresponding to self._rhs, and update self._solution accordingly assert self._rhs is None assert RHSIO.exists_file(full_directory, "rhs_type") rhs_type = RHSIO.load_file(full_directory, "rhs_type") assert rhs_type in ("ParametrizedTensorFactory", "DelayedProduct") if rhs_type == "ParametrizedTensorFactory": assert RHSIO.exists_file(full_directory, "rhs_arg_0") (rhs_problem_name_0, rhs_term_0, rhs_index_0) = RHSIO.load_file(full_directory, "rhs_arg_0") rhs_problem_0 = get_problem_from_problem_name(rhs_problem_name_0) rhs_arg_0 = rhs_problem_0.operator[rhs_term_0][rhs_index_0] assert isinstance(rhs_arg_0, AbstractParametrizedTensorFactory) self._rhs = rhs_arg_0 elif rhs_type == "DelayedProduct": assert RHSIO.exists_file(full_directory, "rhs_arg_0") rhs_arg_0 = RHSIO.load_file(full_directory, "rhs_arg_0") assert rhs_arg_0 == -1.0 assert RHSIO.exists_file(full_directory, "rhs_arg_1") (rhs_problem_name_1, rhs_term_1, rhs_index_1) = RHSIO.load_file(full_directory, "rhs_arg_1") rhs_problem_1 = get_problem_from_problem_name(rhs_problem_name_1) rhs_arg_1 = rhs_problem_1.operator[rhs_term_1][rhs_index_1] assert isinstance(rhs_arg_1, AbstractParametrizedTensorFactory) assert RHSIO.exists_file(full_directory, "rhs_arg_2") (rhs_problem_name_2, rhs_component_2, rhs_index_2) = RHSIO.load_file(full_directory, "rhs_arg_2") rhs_problem_2 = get_problem_from_problem_name(rhs_problem_name_2) rhs_reduced_problem_2 = get_reduced_problem_from_problem( rhs_problem_2) if rhs_component_2 is not None: rhs_arg_2 = rhs_reduced_problem_2.basis_functions[ rhs_component_2][rhs_index_2] else: rhs_arg_2 = rhs_reduced_problem_2.basis_functions[rhs_index_2] rhs = DelayedProduct(rhs_arg_0) rhs *= rhs_arg_1 rhs *= rhs_arg_2 self._rhs = rhs else: raise TypeError("Invalid rhs") # Load problem corresponding to self._bcs, and update self._bcs accordingly assert self._bcs is None assert BCsIO.exists_file(full_directory, "bcs_problem_name") bcs_problem_name = BCsIO.load_file(full_directory, "bcs_problem_name") bcs_problem = get_problem_from_problem_name(bcs_problem_name) bcs_reduced_problem = get_reduced_problem_from_problem(bcs_problem) self._bcs = bcs_reduced_problem._riesz_solve_homogeneous_dirichlet_bc # Load parameters assert len(self._parameters) is 0 assert ParametersIO.exists_file(full_directory, "parameters") self._parameters = ParametersIO.load_file(full_directory, "parameters") # Return return True
def load(self, directory, filename): if self._type != "empty": # avoid loading multiple times if self._type in ("basis_functions_matrix", "functions_list"): delayed_functions = self._content[self._type] it = NonAffineExpansionStorageContent_Iterator( delayed_functions, flags=["c_index", "multi_index", "refs_ok"], op_flags=["readonly"]) while not it.finished: if isinstance(delayed_functions[it.multi_index], DelayedFunctionsList): assert self._type == "functions_list" if len( delayed_functions[it.multi_index] ) > 0: # ... unless it is an empty FunctionsList return False elif isinstance(delayed_functions[it.multi_index], DelayedBasisFunctionsMatrix): assert self._type == "basis_functions_matrix" if sum( delayed_functions[it.multi_index]. _component_name_to_basis_component_length. values() ) > 0: # ... unless it is an empty BasisFunctionsMatrix return False else: raise TypeError("Invalid delayed functions") it.iternext() else: return False # Get full directory name full_directory = Folders.Folder(os.path.join(str(directory), filename)) # Detect trivial case assert TypeIO.exists_file(full_directory, "type") imported_type = TypeIO.load_file(full_directory, "type") self._type = imported_type assert self._type in ("basis_functions_matrix", "empty", "error_estimation_operators_11", "error_estimation_operators_21", "error_estimation_operators_22", "functions_list", "operators") if self._type in ("basis_functions_matrix", "functions_list"): # Load delayed functions assert self._type in self._content delayed_functions = self._content[self._type] it = NonAffineExpansionStorageContent_Iterator( delayed_functions, flags=["c_index", "multi_index", "refs_ok"]) while not it.finished: delayed_function = delayed_functions[it.multi_index] delayed_function.load(full_directory, "delayed_functions_" + str(it.index)) it.iternext() elif self._type == "empty": pass elif self._type in ("error_estimation_operators_11", "error_estimation_operators_21", "error_estimation_operators_22"): # Load delayed functions assert "delayed_functions" not in self._content self._content["delayed_functions"] = [ NonAffineExpansionStorageContent_Base(self._shape[0], dtype=object), NonAffineExpansionStorageContent_Base(self._shape[1], dtype=object) ] for (index, delayed_functions) in enumerate( self._content["delayed_functions"]): it = NonAffineExpansionStorageContent_Iterator( delayed_functions, flags=["c_index", "refs_ok"]) while not it.finished: assert DelayedFunctionsTypeIO.exists_file( full_directory, "delayed_functions_" + str(index) + "_" + str(it.index) + "_type") delayed_function_type = DelayedFunctionsTypeIO.load_file( full_directory, "delayed_functions_" + str(index) + "_" + str(it.index) + "_type") assert DelayedFunctionsProblemNameIO.exists_file( full_directory, "delayed_functions_" + str(index) + "_" + str(it.index) + "_problem_name") delayed_function_problem_name = DelayedFunctionsProblemNameIO.load_file( full_directory, "delayed_functions_" + str(index) + "_" + str(it.index) + "_problem_name") delayed_function_problem = get_problem_from_problem_name( delayed_function_problem_name) assert delayed_function_type in ( "DelayedBasisFunctionsMatrix", "DelayedLinearSolver") if delayed_function_type == "DelayedBasisFunctionsMatrix": delayed_function = DelayedBasisFunctionsMatrix( delayed_function_problem.V) delayed_function.init( delayed_function_problem.components) elif delayed_function_type == "DelayedLinearSolver": delayed_function = DelayedLinearSolver() else: raise ValueError("Invalid delayed function") delayed_function.load( full_directory, "delayed_functions_" + str(index) + "_" + str(it.index) + "_content") delayed_functions[it.index] = delayed_function it.iternext() # Load inner product assert ErrorEstimationInnerProductIO.exists_file( full_directory, "inner_product_matrix_problem_name") inner_product_matrix_problem_name = ErrorEstimationInnerProductIO.load_file( full_directory, "inner_product_matrix_problem_name") inner_product_matrix_problem = get_problem_from_problem_name( inner_product_matrix_problem_name) inner_product_matrix_reduced_problem = get_reduced_problem_from_problem( inner_product_matrix_problem) self._content[ "inner_product_matrix"] = inner_product_matrix_reduced_problem._error_estimation_inner_product # Recompute shape assert "delayed_functions_shape" not in self._content self._content["delayed_functions_shape"] = DelayedTransposeShape( (self._content["delayed_functions"][0][0], self._content["delayed_functions"][1][0])) # Prepare precomputed slices self._precomputed_slices.clear() self._prepare_trivial_precomputed_slice() elif self._type == "empty": pass elif self._type == "operators": # Load truth content assert "truth_operators" not in self._content self._content[ "truth_operators"] = NonAffineExpansionStorageContent_Base( self._shape, dtype=object) it = NonAffineExpansionStorageContent_Iterator( self._content["truth_operators"], flags=["c_index", "multi_index", "refs_ok"]) while not it.finished: assert TruthContentItemIO.exists_file( full_directory, "truth_operator_" + str(it.index) + "_type") operator_type = TruthContentItemIO.load_file( full_directory, "truth_operator_" + str(it.index) + "_type") assert operator_type in ("NumericForm", "ParametrizedTensorFactory") if operator_type == "NumericForm": assert TruthContentItemIO.exists_file( full_directory, "truth_operator_" + str(it.index)) value = TruthContentItemIO.load_file( full_directory, "truth_operator_" + str(it.index)) self._content["truth_operators"][ it.multi_index] = NumericForm(value) elif operator_type == "ParametrizedTensorFactory": assert TruthContentItemIO.exists_file( full_directory, "truth_operator_" + str(it.index)) (problem_name, term, index) = TruthContentItemIO.load_file( full_directory, "truth_operator_" + str(it.index)) truth_problem = get_problem_from_problem_name(problem_name) self._content["truth_operators"][ it.multi_index] = truth_problem.operator[term][index] else: raise ValueError("Invalid operator type") it.iternext() assert "truth_operators_as_expansion_storage" not in self._content self._prepare_truth_operators_as_expansion_storage() # Load basis functions content assert BasisFunctionsContentLengthIO.exists_file( full_directory, "basis_functions_length") basis_functions_length = BasisFunctionsContentLengthIO.load_file( full_directory, "basis_functions_length") assert basis_functions_length in (0, 1, 2) assert "basis_functions" not in self._content self._content["basis_functions"] = list() for index in range(basis_functions_length): assert BasisFunctionsProblemNameIO.exists_file( full_directory, "basis_functions_" + str(index) + "_problem_name") basis_functions_problem_name = BasisFunctionsProblemNameIO.load_file( full_directory, "basis_functions_" + str(index) + "_problem_name") assert BasisFunctionsProblemNameIO.exists_file( full_directory, "basis_functions_" + str(index) + "_components_name") basis_functions_components_name = BasisFunctionsProblemNameIO.load_file( full_directory, "basis_functions_" + str(index) + "_components_name") basis_functions_problem = get_problem_from_problem_name( basis_functions_problem_name) basis_functions_reduced_problem = get_reduced_problem_from_problem( basis_functions_problem) basis_functions = basis_functions_reduced_problem.basis_functions if basis_functions_components_name != basis_functions_problem.components: basis_functions = basis_functions[ basis_functions_components_name] self._content["basis_functions"].append(basis_functions) # Recompute shape self._content["basis_functions_shape"] = DelayedTransposeShape( self._content["basis_functions"]) # Reset precomputed slices self._precomputed_slices.clear() self._prepare_trivial_precomputed_slice() else: raise ValueError("Invalid type") return True
def _init_offline(self): # Initialize the affine expansion in the truth problem self.truth_problem.init() # Initialize reduced order data structures in the reduced problem self.reduced_problem = ReducedProblemFactory(self.truth_problem, self, **self._init_kwargs) # Prepare folders and init reduced problem required_folders = Folders() required_folders.update(self.folder) assert self.reduced_problem is not None required_folders.update(self.truth_problem.folder) required_folders.update(self.reduced_problem.folder) optional_folders = Folders() optional_folders["cache"] = required_folders.pop("cache") # cache folder does not affect the availability of offline data optional_folders["testing_set"] = required_folders.pop("testing_set") # testing set is required only in the error/speedup analysis optional_folders["error_analysis"] = required_folders.pop( "error_analysis") # error analysis folder is required only in the error analysis optional_folders["speedup_analysis"] = required_folders.pop( "speedup_analysis") # speedup analysis folder is required only in the speedup analysis at_least_one_required_folder_created = required_folders.create() at_least_one_optional_folder_created = optional_folders.create( ) # noqa: F841 if not at_least_one_required_folder_created: return False # offline construction should be skipped, since data are already available else: self.reduced_problem.init("offline") return True # offline construction should be carried out
def _init_offline(self): # Initialize the affine expansion in the truth problem self.truth_problem.init() # Initialize reduced order data structures in the reduced problem self.reduced_problem = ReducedProblemFactory(self.truth_problem, self, **self._init_kwargs) # Prepare folders and init reduced problem all_folders = Folders() all_folders.update(self.folder) assert self.reduced_problem is not None all_folders.update(self.reduced_problem.folder) all_folders.pop( "testing_set" ) # this is required only in the error/speedup analysis all_folders.pop( "error_analysis") # this is required only in the error analysis all_folders.pop("speedup_analysis" ) # this is required only in the speedup analysis at_least_one_folder_created = all_folders.create() if not at_least_one_folder_created: return False # offline construction should be skipped, since data are already available else: self.reduced_problem.init("offline") return True # offline construction should be carried out
def _init_offline(self): # Prepare folders and init EIM approximation all_folders = Folders() all_folders.update(self.folder) all_folders.update(self.EIM_approximation.folder) all_folders.pop("testing_set") # this is required only in the error/speedup analysis all_folders.pop("error_analysis") # this is required only in the error analysis all_folders.pop("speedup_analysis") # this is required only in the speedup analysis at_least_one_folder_created = all_folders.create() if not at_least_one_folder_created: return False # offline construction should be skipped, since data are already available else: self.EIM_approximation.init("offline") return True # offline construction should be carried out
def _init_offline(self): # Prepare folders and init EIM approximation required_folders = Folders() required_folders.update(self.folder) required_folders.update(self.EIM_approximation.folder) optional_folders = Folders() optional_folders["cache"] = required_folders.pop("cache") # removing cache does not affect the availability of offline data optional_folders["testing_set"] = required_folders.pop("testing_set") # testing set is required only in the error/speedup analysis optional_folders["error_analysis"] = required_folders.pop("error_analysis") # error analysis folder is required only in the error analysis optional_folders["speedup_analysis"] = required_folders.pop("speedup_analysis") # speedup analysis folder is required only in the speedup analysis at_least_one_required_folder_created = required_folders.create() at_least_one_optional_folder_created = optional_folders.create() # noqa: F841 if not at_least_one_required_folder_created: return False # offline construction should be skipped, since data are already available else: self.EIM_approximation.init("offline") return True # offline construction should be carried out