Esempio n. 1
0
        def _init_offline(self):
            # Call parent to initialize inner product and reduced problem
            output = DifferentialProblemReductionMethod_DerivedClass._init_offline(
                self)

            # Declare a new POD for each basis component
            if len(self.truth_problem.components) > 1:
                self.POD = dict()
                for component in self.truth_problem.components:
                    assert len(
                        self.truth_problem.inner_product[component]) == 1
                    # the affine expansion storage contains only the inner product matrix
                    inner_product = self.truth_problem.inner_product[
                        component][0]
                    self.POD[component] = ProperOrthogonalDecomposition(
                        self.truth_problem.V, inner_product)
            else:
                assert len(self.truth_problem.inner_product) == 1
                # the affine expansion storage contains only the inner product matrix
                inner_product = self.truth_problem.inner_product[0]
                self.POD = ProperOrthogonalDecomposition(
                    self.truth_problem.V, inner_product)

            # Return
            return output
        def _init_offline(self):
            # Call parent to initialize inner product
            output = DifferentialProblemReductionMethod_DerivedClass._init_offline(
                self)

            if self.nested_POD:
                # Declare new POD object(s)
                if len(self.truth_problem.components) > 1:
                    self.POD_time_trajectory = dict()
                    for component in self.truth_problem.components:
                        assert len(
                            self.truth_problem.inner_product[component]
                        ) == 1  # the affine expansion storage contains only the inner product matrix
                        inner_product = self.truth_problem.inner_product[
                            component][0]
                        self.POD_time_trajectory[
                            component] = ProperOrthogonalDecomposition(
                                self.truth_problem.V, inner_product)
                else:
                    assert len(
                        self.truth_problem.inner_product
                    ) == 1  # the affine expansion storage contains only the inner product matrix
                    inner_product = self.truth_problem.inner_product[0]
                    self.POD_time_trajectory = ProperOrthogonalDecomposition(
                        self.truth_problem.V, inner_product)

            # Return
            return output
 def _init_offline(self):
     # Call parent to initialize inner product
     output = DifferentialProblemReductionMethod_DerivedClass._init_offline(self)
     
     # Check admissible values of POD_greedy_basis_extension
     assert self.POD_greedy_basis_extension in ("orthogonal", "POD")
     
     # Declare new POD object(s)
     if len(self.truth_problem.components) > 1:
         self.POD_time_trajectory = dict()
         if self.POD_greedy_basis_extension == "POD":
             self.POD_basis = dict()
         for component in self.truth_problem.components:
             assert len(self.truth_problem.inner_product[component]) == 1 # the affine expansion storage contains only the inner product matrix
             inner_product = self.truth_problem.inner_product[component][0]
             self.POD_time_trajectory[component] = ProperOrthogonalDecomposition(self.truth_problem.V, inner_product)
             if self.POD_greedy_basis_extension == "POD":
                 self.POD_basis[component] = ProperOrthogonalDecomposition(self.truth_problem.V, inner_product)
     else:
         assert len(self.truth_problem.inner_product) == 1 # the affine expansion storage contains only the inner product matrix
         inner_product = self.truth_problem.inner_product[0]
         self.POD_time_trajectory = ProperOrthogonalDecomposition(self.truth_problem.V, inner_product)
         if self.POD_greedy_basis_extension == "POD":
             self.POD_basis = ProperOrthogonalDecomposition(self.truth_problem.V, inner_product)
     
     # Return
     return output
    def _init_offline(self):
        # We cannot use the standard initialization provided by PODGalerkinReduction because
        # supremizer POD requires a custom initialization. We thus duplicate here part of its code

        # Call parent of parent (!) to initialize inner product and reduced problem
        output = StokesOptimalControlPODGalerkinReduction_Base._init_offline(self)

        # Declare a new POD for each basis component
        self.POD = dict()
        for component in ("v", "p", "u", "w", "q"):
            inner_product = self.truth_problem.inner_product[component][0]
            self.POD[component] = ProperOrthogonalDecomposition(
                self.truth_problem.V, inner_product)
        for component in ("s", "r"):
            inner_product = self.truth_problem.inner_product[component][0]
            self.POD[component] = ProperOrthogonalDecomposition(
                self.truth_problem.V, inner_product, component=component)

        # Return
        return output
        def _init_offline(self):
            # Call parent to initialize
            output = AbstractCFDUnsteadyPODGalerkinReduction_Base._init_offline(
                self)

            if self.nested_POD:
                # Declare new POD object(s)
                self.POD_time_trajectory = dict()
                for component in ("u", "p"):
                    inner_product = self.truth_problem.inner_product[
                        component][0]
                    self.POD_time_trajectory[
                        component] = ProperOrthogonalDecomposition(
                            self.truth_problem.V, inner_product)
                for component in ("s", ):
                    inner_product = self.truth_problem.inner_product[
                        component][0]
                    self.POD_time_trajectory[
                        component] = ProperOrthogonalDecomposition(
                            self.truth_problem.V, inner_product, component="s")

            # Return
            return output
Esempio n. 6
0
def perform_POD(N):
    # export mesh - instead of generating mesh everytime
    (mesh, _, _, restrictions) = read_mesh()
    W = generate_block_function_space(mesh, restrictions)

    # POD objects
    X = get_inner_products(W, "POD")
    POD = {c: ProperOrthogonalDecomposition(W, X[c]) for c in components}

    # Solution storage
    solution = BlockFunction(W)

    # Training set
    training_set = get_set("training_set")

    # Read in snapshots
    for mu in training_set:
        print("Appending solution for mu =", mu, "to snapshots matrix")
        read_solution(mu, "truth_solve", solution)
        for c in components:
            POD[c].store_snapshot(solution, component=c)

    # Compress component by component
    basis_functions_component = dict()
    for c in components:
        _, _, basis_functions_component[c], N_c = POD[c].apply(N, tol=0.)
        assert N_c == N
        print("Eigenvalues for component", c)
        POD[c].print_eigenvalues(N)
        POD[c].save_eigenvalues_file("basis", "eigenvalues_" + c)

    # Collect all components and save to file
    basis_functions = BasisFunctionsMatrix(W)
    basis_functions.init(components)
    for c in components:
        basis_functions.enrich(basis_functions_component[c], component=c)
    basis_functions.save("basis", "basis")
    # Also save components to file, for the sake of the ParaView plugin
    with open(os.path.join("basis", "components"), "w") as file_:
        for c in components:
            file_.write(c + "\n")