def project(self, snapshot, on_dirichlet_bc=True, N=None, **kwargs): N, kwargs = self._online_size_from_kwargs(N, **kwargs) N += self.N_bc # Get truth and reduced inner product matrices for projection inner_product = self.truth_problem._combined_projection_inner_product inner_product_N = self._combined_projection_inner_product[:N, :N] # Get basis basis_functions = self.basis_functions[:N] # Define storage for projected solution projected_snapshot_N = OnlineFunction(N) # Project on reduced basis if on_dirichlet_bc: solver = OnlineLinearSolver( inner_product_N, projected_snapshot_N, transpose(basis_functions) * inner_product * snapshot) else: solver = OnlineLinearSolver( inner_product_N, projected_snapshot_N, transpose(basis_functions) * inner_product * snapshot, self._combined_and_homogenized_dirichlet_bc) solver.set_parameters(self._linear_solver_parameters) solver.solve() return projected_snapshot_N
def _solve_supremizer(self, solution): N_us = self._supremizer.N N_usp = solution.N assert len( self.inner_product["s"] ) == 1 # the affine expansion storage contains only the inner product matrix assembled_operator_lhs = self.inner_product["s"][0][:N_us, :N_us] assembled_operator_bt = sum( product(self.compute_theta("bt_restricted"), self.operator["bt_restricted"][:N_us, :N_usp])) assembled_operator_rhs = assembled_operator_bt * solution if self.dirichlet_bc[ "u"] and not self.dirichlet_bc_are_homogeneous["u"]: assembled_dirichlet_bc = dict() assert self.dirichlet_bc["s"] assert self.dirichlet_bc_are_homogeneous["s"] assembled_dirichlet_bc["u"] = self.compute_theta( "dirichlet_bc_s") else: assembled_dirichlet_bc = None solver = OnlineLinearSolver(assembled_operator_lhs, self._supremizer, assembled_operator_rhs, assembled_dirichlet_bc) solver.set_parameters(self._linear_solver_parameters) solver.solve()
def ic_eval(self): problem = self.problem N = self.N if len(problem.components) > 1: all_initial_conditions = list() all_initial_conditions_thetas = list() for component in problem.components: if problem.initial_condition[component] and not problem.initial_condition_is_homogeneous[component]: all_initial_conditions.extend(problem.initial_condition[component][:N]) all_initial_conditions_thetas.extend(problem.compute_theta("initial_condition_" + component)) if len(all_initial_conditions) > 0: all_initial_conditions = tuple(all_initial_conditions) all_initial_conditions = OnlineAffineExpansionStorage(all_initial_conditions) all_initial_conditions_thetas = tuple(all_initial_conditions_thetas) else: all_initial_conditions = None all_initial_conditions_thetas = None else: if problem.initial_condition and not problem.initial_condition_is_homogeneous: all_initial_conditions = problem.initial_condition[:N] all_initial_conditions_thetas = problem.compute_theta("initial_condition") else: all_initial_conditions = None all_initial_conditions_thetas = None assert (all_initial_conditions is None) == (all_initial_conditions_thetas is None) if all_initial_conditions is not None: inner_product_N = problem._combined_projection_inner_product[:N, :N] projected_initial_condition = OnlineFunction(N) solver = OnlineLinearSolver(inner_product_N, projected_initial_condition, sum(product(all_initial_conditions_thetas, all_initial_conditions))) solver.set_parameters(problem._linear_solver_parameters) solver.solve() return projected_initial_condition else: return None