Ejemplo n.º 1
0
 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")
Ejemplo n.º 2
0
 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")