コード例 #1
0
 def solve_and_estimate_error(mu):
     self.reduced_problem.set_mu(mu)
     self.reduced_problem.solve()
     error_estimator_over_time = self.reduced_problem.estimate_error()
     error_estimator_squared_over_time = [v**2 for v in error_estimator_over_time]
     time_quadrature = TimeQuadrature((0., self.truth_problem.T), error_estimator_squared_over_time)
     error_estimator = sqrt(time_quadrature.integrate())
     log(DEBUG, "Error estimator for mu = " + str(mu) + " is " + str(error_estimator))
     return error_estimator
コード例 #2
0
 def _greedy(self):
     
     if self.reduced_problem.N > 0: # skip during initialization
         # Print some additional information related to the current value of the parameter
         error_over_time = self.reduced_problem.compute_error()
         error_squared_over_time = [v**2 for v in error_over_time]
         error_time_quadrature = TimeQuadrature((0., self.truth_problem.T), error_squared_over_time)
         error = sqrt(error_time_quadrature.integrate())
         print("absolute error for current mu =", error)
         error_estimator_over_time = self.reduced_problem.estimate_error()
         error_estimator_squared_over_time = [v**2 for v in error_estimator_over_time]
         error_estimator_time_quadrature = TimeQuadrature((0., self.truth_problem.T), error_estimator_squared_over_time)
         error_estimator = sqrt(error_estimator_time_quadrature.integrate())
         print("absolute error estimator for current mu =", error_estimator)
     
     # Carry out the actual greedy search
     def solve_and_estimate_error(mu):
         self.reduced_problem.set_mu(mu)
         self.reduced_problem.solve()
         error_estimator_over_time = self.reduced_problem.estimate_error()
         error_estimator_squared_over_time = [v**2 for v in error_estimator_over_time]
         time_quadrature = TimeQuadrature((0., self.truth_problem.T), error_estimator_squared_over_time)
         error_estimator = sqrt(time_quadrature.integrate())
         log(DEBUG, "Error estimator for mu = " + str(mu) + " is " + str(error_estimator))
         return error_estimator
         
     if self.reduced_problem.N == 0:
         print("find initial mu")
     else:
         print("find next mu")
         
     return self.training_set.max(solve_and_estimate_error)
コード例 #3
0
 def _lifting_truth_solve(self, term, i):
     assert term.startswith("dirichlet_bc")
     component = term.replace("dirichlet_bc", "").replace("_", "")
     # Since lifting solves for different values of i are associated to the same parameter
     # but with a patched call to compute_theta(), which returns the i-th component, we set
     # a custom cache_key so that they are properly differentiated when reading from cache.
     lifting_over_time = self.truth_problem.solve(
         cache_key="lifting_" + component + "_" + str(i))
     times = lifting_over_time.stored_times()
     theta_over_time = list()
     for t in times:
         self.truth_problem.set_time(t)
         theta_over_time.append(
             self.truth_problem.compute_theta(term)[i])
     # We average the time dependent solution to be used as time independent lifting.
     # Do not even bother adding the initial condition if it is zero
     if not isclose(times[0], self.truth_problem.t0,
                    self.truth_problem.dt / 2):
         has_non_homogeneous_initial_condition = True
     else:
         if component != "":
             assert component in self.truth_problem.components
             has_non_homogeneous_initial_condition = self.truth_problem.initial_condition[
                 component] and not self.truth_problem.initial_condition_is_homogeneous[
                     component]
         else:
             assert len(self.truth_problem.components) == 1
             component = None
             has_non_homogeneous_initial_condition = (
                 self.truth_problem.initial_condition and
                 not self.truth_problem.initial_condition_is_homogeneous
             )
     if has_non_homogeneous_initial_condition:
         time_interval = (times[0], times[-1])
     else:
         time_interval = (times[1], times[-1])
         lifting_over_time = lifting_over_time[1:]
         theta_over_time = theta_over_time[1:]
     # Compute the average and return
     lifting_quadrature = TimeQuadrature(time_interval,
                                         lifting_over_time)
     theta_quadrature = TimeQuadrature(time_interval, theta_over_time)
     lifting = lifting_quadrature.integrate()
     lifting /= theta_quadrature.integrate()
     return lifting
コード例 #4
0
 def output_preprocess_setitem(list_over_time):
     time_quadrature = TimeQuadrature((0., self.truth_problem.T),
                                      list_over_time)
     return time_quadrature.integrate()
コード例 #5
0
 def solution_preprocess_setitem(list_over_time):
     list_squared_over_time = [v**2 for v in list_over_time]
     time_quadrature = TimeQuadrature((0., self.truth_problem.T),
                                      list_squared_over_time)
     return sqrt(time_quadrature.integrate())
コード例 #6
0
ファイル: time_quadrature.py プロジェクト: ljnpu/RBniCS
def _TimeQuadrature(time_interval: tuple_of(Number), time_series: TimeSeries):
    from rbnics.backends import TimeQuadrature
    return TimeQuadrature(time_interval, time_series._list)