def generate_random(self): # Generate random vectors S = FunctionsList(self.V) for _ in range(self.N): b = RandomDolfinFunction(self.V) S.enrich(b) F = RandomDolfinFunction(self.V) # Return return (S, F)
def generate_random(self): # Generate random vectors S = FunctionsList(self.V) for _ in range(self.N): b = RandomDolfinFunction(self.V) S.enrich(b) k = RandomDolfinFunction(self.V) # Generate random matrix A = assemble(self.a(k)) # Return return (S, A)
def _init_error_estimation_operators(self, current_stage="online"): """ Initialize data structures related to error estimation. """ # Initialize inner product for Riesz solve if self._riesz_solve_inner_product is None: # init was not called already self._riesz_solve_inner_product = self.truth_problem._combined_inner_product # Setup homogeneous Dirichlet BCs for Riesz solve, if any (no check if init was already called # because this variable can actually be None) self._riesz_solve_homogeneous_dirichlet_bc = self.truth_problem._combined_and_homogenized_dirichlet_bc # Initialize Riesz representation for term in self.riesz_terms: if term not in self.riesz: # init was not called already self.riesz[term] = self.RieszExpansionStorage(self.Q[term]) for q in range(self.Q[term]): assert self.terms_order[term] in (1, 2) if self.terms_order[term] > 1: riesz_term_q = BasisFunctionsMatrix( self.truth_problem.V) riesz_term_q.init(self.components) else: riesz_term_q = FunctionsList( self.truth_problem.V) # will be of size 1 self.riesz[term][q] = riesz_term_q assert current_stage in ("online", "offline") if current_stage == "online": for term in self.riesz_terms: self.riesz[term].load(self.folder["error_estimation"], "riesz_" + term) elif current_stage == "offline": pass # Nothing else to be done else: raise ValueError( "Invalid stage in _init_error_estimation_operators().") # Initialize inner product for Riesz products. This is the same as the inner product for Riesz solves # but setting to zero rows & columns associated to boundary conditions if self._error_estimation_inner_product is None: # init was not called already if self._riesz_solve_homogeneous_dirichlet_bc is not None: self._error_estimation_inner_product = ( self._riesz_solve_inner_product & ~self._riesz_solve_homogeneous_dirichlet_bc) else: self._error_estimation_inner_product = self._riesz_solve_inner_product # Initialize error estimation operators for term in self.error_estimation_terms: if term not in self.error_estimation_operator: # init was not called already self.error_estimation_operator[ term] = self.ErrorEstimationOperatorExpansionStorage( self.Q[term[0]], self.Q[term[1]]) assert current_stage in ("online", "offline") if current_stage == "online": for term in self.error_estimation_terms: self.assemble_error_estimation_operators(term, "online") elif current_stage == "offline": pass # Nothing else to be done else: raise ValueError( "Invalid stage in _init_error_estimation_operators().")