Exemple #1
0
 def _prolong_onto_reference(self, level):
     if level in self._solution_as_reference:
         return
     # reconstruct, if reduced
     if 'reductor' in self._d_data[level]:
         assert False  # not yet implemented
         reconstructed_soluion = self._d_data[level][
             'reductor'].reconstruct(self._solution[level])
     else:
         reconstructed_soluion = self._solution[level]
     if 'block_space' in self._d_data[level]:
         coarse_solution = tuple(
             make_discrete_function(self._d_data[level]['block_space'],
                                    vec.impl) for vec in self._d_data[level]
             ['unblock'](reconstructed_soluion)._list)
     else:
         coarse_solution = tuple(
             make_discrete_function(self._d_data[level]['space'], vec.impl)
             for vec in reconstructed_soluion._list)
     # prolong in space
     coarse_in_time_fine_in_space = tuple(
         make_discrete_function(self._d_data[-1]['space'])
         for nt in range(len(coarse_solution)))
     for coarse, fine in zip(coarse_solution, coarse_in_time_fine_in_space):
         prolong(coarse, fine)
     # prolong in time
     T = self._T
     coarse_time_grid = OnedGrid(domain=(0., T),
                                 num_intervals=(len(self._solution[level]) -
                                                1))
     fine_time_grid = OnedGrid(domain=(0., T),
                               num_intervals=len(self._solution[-1]) - 1)
     self._solution_as_reference[level] = [
         None for ii in fine_time_grid.centers(1)
     ]
     for n in np.arange(len(fine_time_grid.centers(1))):
         t_n = fine_time_grid.centers(1)[n]
         coarse_entity = min(
             (coarse_time_grid.centers(1) <= t_n).nonzero()[0][-1],
             coarse_time_grid.size(0) - 1)
         a = coarse_time_grid.centers(1)[coarse_entity]
         b = coarse_time_grid.centers(1)[coarse_entity + 1]
         SF = np.array((
             1. / (a - b) * t_n - b / (a - b),  # P1 in tim
             1. / (b - a) * t_n - a / (b - a)))
         U_t = coarse_in_time_fine_in_space[coarse_entity].vector_copy()
         U_t.scal(SF[0][0])
         U_t.axpy(
             SF[1][0],
             coarse_in_time_fine_in_space[coarse_entity + 1].vector_copy())
         self._solution_as_reference[level][n] = make_discrete_function(
             self._d_data[-1]['space'], U_t)
Exemple #2
0
 def _prolong_onto_reference(self, level):
     if level in self._solution_as_reference:
         return
     if 'reductor' in self._d_data[level]:
         reconstructed_soluion = self._d_data[level][
             'reductor'].reconstruct(self._solution[level])
     else:
         reconstructed_soluion = self._solution[level]
     if 'block_space' in self._d_data[level]:
         coarse_solution = make_discrete_function(
             self._d_data[level]['block_space'], self._d_data[level]
             ['unblock'](reconstructed_soluion)._list[0].impl)
     else:
         coarse_solution = make_discrete_function(
             self._d_data[level]['space'],
             reconstructed_soluion._list[0].impl)
     self._solution_as_reference[level] = make_discrete_function(
         self._d_data[-1]['space'])
     prolong(coarse_solution, self._solution_as_reference[level])
Exemple #3
0
def _vis(U, global_space, name):
    assert len(U) == 1
    dd = U.data
    ud = make_discrete_function(global_space, name)
    print('vec size {} | space {} | df {}'.format(len(dd[0]),
                                                  global_space.size(),
                                                  len(ud)))
    for ii in range(global_space.size()):
        ud.setitem(ii, dd[0][ii])
    ud.visualize(name)
Exemple #4
0
 def _compute_reference_solution(self):
     if -1 in self._solution:
         return
     self._grid_and_problem_data[-1] = self._grid_and_problem_initializer(
         self._config[-1])
     self._d[-1], self._d_data[-1] = discretize_elliptic_swipdg(
         self._grid_and_problem_data[-1], self.p_ref)
     space = self._d_data[-1]['space']
     self._solution[-1] = self._d[-1].solve(self._d[-1].parse_parameter(
         self.mu))._list[0].impl
     self._solution[-1] = make_discrete_function(space, self._solution[-1])
     # prepare error products
     self._l2_product = self._d[-1].operators['l2'].matrix
     self._elliptic_mu_bar_product = self._d[-1].operators[
         'elliptic_mu_bar'].matrix
Exemple #5
0
 def _compute_reference_solution(self):
     if -1 in self._solution:
         return
     self._grid_and_problem_data[-1] = self._grid_and_problem_initializer(
         self._config[-1])
     dt = self._config[-1]['dt']
     self._d[-1], self._d_data[-1] = discretize_parabolic_swipdg(
         self._grid_and_problem_data[-1], self._T,
         int(self._T / dt) + 1, self.p_ref)
     space = self._d_data[-1]['space']
     self._solution[-1] = self._d[-1].solve(self._d[-1].parse_parameter(
         self.mu))
     self._solution[-1] = tuple(
         make_discrete_function(space, vec.impl)
         for vec in self._solution[-1]._list)
     # prepare error products
     self._l2_product = self._d[-1].operators['l2'].matrix
     self._elliptic_mu_bar_product = self._d[-1].operators[
         'elliptic_mu_bar'].matrix