def bochner_norm(T, space_norm2, U, mu=None, order=2):
    '''
      L^2-in-time, X-in-space
    '''
    nt = len(U)
    time_grid = OnedGrid(domain=(0., T), num_intervals=nt-1)
    assert len(U) == time_grid.size(1)
    qq = time_grid.quadrature_points(0, order=order)
    integral = 0.
    for entity in np.arange(time_grid.size(0)):
        # get quadrature
        qq_e = qq[entity] # points
        ww = time_grid.reference_element.quadrature(order)[1] # weights
        ie = time_grid.integration_elements(0)[entity] # integration element
        # create shape function evaluations
        a = time_grid.centers(1)[entity]
        b = time_grid.centers(1)[entity + 1]
        SF = np.array((1./(a - b)*qq_e[..., 0] - b/(a - b),
                       1./(b - a)*qq_e[..., 0] - a/(b - a)))
        U_a = U._list[entity]
        U_b = U._list[entity + 1]
        values = np.zeros(len(qq_e))
        for ii in np.arange(len(qq_e)):
            # compute U(t)
            U_t = U_a.copy()
            U_t.scal(SF[0][ii])
            U_t.axpy(SF[1][ii], U_b)
            # compute the X-norm of U(t)
            values[ii] = space_norm2(make_listvectorarray(U_t), mu)
        integral += np.dot(values, ww)*ie
    return np.sqrt(integral)
Example #2
0
 def __init__(self, d):
     def wrap_op(op, name=None):
         if not op.parametric() and op.num_components() == 0 and op.has_affine_part():
             wrapped_op = self._wrapper[op.affine_part()]
         else:
             wrapped_op = self._wrapper[op]
         return wrapped_op.with_(name=name) if name else wrapped_op
     self._impl = d
     operators = {'operator': wrap_op(d.get_operator())}
     functionals = {'rhs': self._wrapper[d.get_rhs()]}
     vector_operators = FrozenDict({k: VectorOperator(make_listvectorarray(self._wrapper[d.get_vector(k)]))
                                    for k in list(d.available_vectors())})
     self.operators = FrozenDict(operators)
     self.functionals = FrozenDict(functionals)
     self.vector_operators = FrozenDict(vector_operators)
     self.operator = operators['operator']
     self.rhs = functionals['rhs']
     self.products = FrozenDict({k: wrap_op(d.get_product(k), k) for k in list(d.available_products())})
     if self.products:
         for k, v in self.products.iteritems():
             setattr(self, '{}_product'.format(k), v)
             setattr(self, '{}_norm'.format(k), induced_norm(v))
     self.linear = all(op.linear for op in operators.itervalues())
     self.solution_space = self.operator.source
     self.build_parameter_type(inherits=operators.values() + functionals.values())
     assert self.parameter_type == self._wrapper[d.parameter_type()]
     self.solver_options = self._impl.solver_options()
Example #3
0
def bochner_norm(T, space_norm2, U, mu=None, order=2):
    '''
      L^2-in-time, X-in-space
    '''
    nt = len(U)
    time_grid = OnedGrid(domain=(0., T), num_intervals=nt - 1)
    assert len(U) == time_grid.size(1)
    qq = time_grid.quadrature_points(0, order=order)
    integral = 0.
    for entity in np.arange(time_grid.size(0)):
        # get quadrature
        qq_e = qq[entity]  # points
        ww = time_grid.reference_element.quadrature(order)[1]  # weights
        ie = time_grid.integration_elements(0)[entity]  # integration element
        # create shape function evaluations
        a = time_grid.centers(1)[entity]
        b = time_grid.centers(1)[entity + 1]
        SF = np.array((1. / (a - b) * qq_e[..., 0] - b / (a - b),
                       1. / (b - a) * qq_e[..., 0] - a / (b - a)))
        U_a = U._list[entity]
        U_b = U._list[entity + 1]
        values = np.zeros(len(qq_e))
        for ii in np.arange(len(qq_e)):
            # compute U(t)
            U_t = U_a.copy()
            U_t.scal(SF[0][ii])
            U_t.axpy(SF[1][ii], U_b)
            # compute the X-norm of U(t)
            values[ii] = space_norm2(make_listvectorarray(U_t), mu)
        integral += np.dot(values, ww) * ie
    return np.sqrt(integral)
Example #4
0
 def solve(self, mu=None):
     mu = self.parse_parameter(mu)
     if not self.logging_disabled:
         self.logger.info('Solving {} for {} ...'.format(self.name, mu))
     mu = self._wrapper.dune_parameter(mu)
     global_solution = self._impl.solve_and_return_ptr(mu)
     assert global_solution.valid()
     global_solution = make_listvectorarray(self._wrapper[global_solution])
     return BlockVectorArray([self.localize_vector(global_solution, ss)
                              for ss in np.arange(self._impl.num_subdomains())])
Example #5
0
 def assemble_lincomb(self, operators, coefficients, solver_options=None, name=None):
     assert not solver_options
     assert len(operators) > 0
     assert len(operators) == len(coefficients)
     vec = operators[0]._impl.as_vector()
     vec.scal(coefficients[0])
     for op, c in izip(operators[1:], coefficients[1:]):
         vec.axpy(c, op._impl.as_vector())
     op = self._wrapper[vec]
     return make_listvectorarray(op)
 def prolong(coarse_disc, coarse_U):
     time_grid_ref = OnedGrid(domain=(0., T), num_intervals=nt)
     time_grid = OnedGrid(domain=(0., T), num_intervals=(len(coarse_U) - 1))
     U_fine = [None for ii in time_grid_ref.centers(1)]
     for n in np.arange(len(time_grid_ref.centers(1))):
         t_n = time_grid_ref.centers(1)[n]
         coarse_entity = min((time_grid.centers(1) <= t_n).nonzero()[0][-1],
                             time_grid.size(0) - 1)
         a = time_grid.centers(1)[coarse_entity]
         b = time_grid.centers(1)[coarse_entity + 1]
         SF = np.array((1./(a - b)*t_n - b/(a - b),
                        1./(b - a)*t_n - a/(b - a)))
         U_t = coarse_U.copy(ind=coarse_entity)
         U_t.scal(SF[0][0])
         U_t.axpy(SF[1][0], coarse_U, x_ind=(coarse_entity + 1))
         U_fine[n] = wrapper[example.prolong(coarse_disc._impl, U_t._list[0]._impl)]
     return make_listvectorarray(U_fine)
Example #7
0
 def prolong(coarse_disc, coarse_U):
     time_grid_ref = OnedGrid(domain=(0., T), num_intervals=nt)
     time_grid = OnedGrid(domain=(0., T), num_intervals=(len(coarse_U) - 1))
     U_fine = [None for ii in time_grid_ref.centers(1)]
     for n in np.arange(len(time_grid_ref.centers(1))):
         t_n = time_grid_ref.centers(1)[n]
         coarse_entity = min((time_grid.centers(1) <= t_n).nonzero()[0][-1],
                             time_grid.size(0) - 1)
         a = time_grid.centers(1)[coarse_entity]
         b = time_grid.centers(1)[coarse_entity + 1]
         SF = np.array((1. / (a - b) * t_n - b / (a - b),
                        1. / (b - a) * t_n - a / (b - a)))
         U_t = coarse_U.copy(ind=coarse_entity)
         U_t.scal(SF[0][0])
         U_t.axpy(SF[1][0], coarse_U, x_ind=(coarse_entity + 1))
         U_fine[n] = wrapper[example.prolong(coarse_disc._impl,
                                             U_t._list[0]._impl)]
     return make_listvectorarray(U_fine)
Example #8
0
def offline_phase(cfg, data):
    logger = getLogger('.OS2015_SISC__6_2.offline_phase')
    logger.setLevel('INFO')

    discretization = data['discretization']
    example = data['example']
    local_products = data['local_products']
    norm = data['norm']
    mu_bar_dune = data['mu_bar_dune']
    mu_hat_dune = data['mu_hat_dune']
    wrapper = data['wrapper']

    if cfg['training_sampling_strategy'] == 'random':
        training_samples = list(
            discretization.parameter_space.sample_randomly(
                cfg['num_training_samples']))
    elif cfg['training_sampling_strategy'] == 'uniform':
        training_samples = list(
            discretization.parameter_space.sample_uniformly(
                cfg['num_training_samples']))
    add_values(training_samples=training_samples)
    if cfg['compute_some_solution_norms'] and len(training_samples) > 0:
        logger.info('Computing solution norms:')
        if norm is not None:
            solution_norms = [
                norm(discretization.solve(mu)) for mu in training_samples
            ]
        else:
            solution_norms = [
                discretization.solve(mu).l2_norm()[0]
                for mu in training_samples
            ]
        logger.info('  range:              [{}, {}]'.format(
            np.amin(solution_norms), np.amax(solution_norms)))
        logger.info('  mean:                {}'.format(
            np.mean(solution_norms)))
        add_values(solution_norms=solution_norms)

    extension_algorithm = partial(gram_schmidt_block_basis_extension,
                                  product=local_products)
    initial_basis = discretization.functionals['rhs'].source.empty()._blocks
    if cfg['initialize_basis_with'] >= 0:
        logger.info('Initializing local bases of up to order {} ...'.format(
            cfg['initialize_basis_with']))
        one = make_listvectorarray(wrapper[example.project('1')])
        one = BlockVectorArray([
            discretization.localize_vector(one, ss)
            for ss in np.arange(discretization.num_subdomains)
        ])
        initial_basis, _ = extension_algorithm(initial_basis, one)
    if cfg['initialize_basis_with'] >= 1:
        xx = make_listvectorarray(wrapper[example.project('x[0]')])
        xx = BlockVectorArray([
            discretization.localize_vector(xx, ss)
            for ss in np.arange(discretization.num_subdomains)
        ])
        initial_basis, _ = extension_algorithm(initial_basis, xx)
        yy = make_listvectorarray(wrapper[example.project('x[1]')])
        yy = BlockVectorArray([
            discretization.localize_vector(yy, ss)
            for ss in np.arange(discretization.num_subdomains)
        ])
        initial_basis, _ = extension_algorithm(initial_basis, yy)
        xy = make_listvectorarray(wrapper[example.project('x[0]*x[1]')])
        xy = BlockVectorArray([
            discretization.localize_vector(xy, ss)
            for ss in np.arange(discretization.num_subdomains)
        ])
        initial_basis, _ = extension_algorithm(initial_basis, xy)
    if cfg['initialize_basis_with'] >= 2:
        logger.warn('Ignoring initialize_basis_with higher than 1: {}'.format(
            cfg['initialize_basis_with']))
    logger.info('')

    reduced_estimator = ReducedEstimator(discretization, example, wrapper,
                                         mu_hat_dune, mu_bar_dune, norm,
                                         cfg['estimator_compute'],
                                         cfg['estimator_return'])
    greedy_data = greedy(discretization,
                         partial(reduce_with_estimator,
                                 reduced_estimator=reduced_estimator),
                         training_samples,
                         initial_basis=initial_basis,
                         use_estimator=cfg['greedy_use_estimator'],
                         error_norm=norm,
                         extension_algorithm=extension_algorithm,
                         max_extensions=cfg['greedy_max_extensions'],
                         target_error=cfg['greedy_target_error'])
    add_values(time=greedy_data['time'],
               max_err_mus=greedy_data['max_err_mus'],
               extensions=greedy_data['extensions'],
               max_errs=greedy_data['max_errs'],
               offline_estimator_data=reduced_estimator.data)
    rd, rc = greedy_data['reduced_discretization'], greedy_data[
        'reconstructor']
    basis, basis_mus = greedy_data['basis'], greedy_data['max_err_mus']

    print('')
    logger.info('Offline phase finished.')
    logger.info('Basis sizes range from {} to {}.'.format(
        np.min([len(bb) for bb in basis]), np.max([len(bb) for bb in basis])))
    return {'basis': basis, 'basis_mus': basis_mus, 'rc': rc, 'rd': rd}
Example #9
0
def online_phase(cfg, detailed_data, offline_data):
    logger = getLogger('.OS2015_SISC__6_2.online_phase')
    logger.setLevel('INFO')

    def doerfler_marking(indicators, theta):
        assert 0.0 < theta <= 1.0
        indices = list(range(len(indicators)))
        indicators = [ii**2 for ii in indicators]
        indicators, indices = [list(x) for x in zip(*sorted(zip(indicators, indices),
                                                            key=lambda pair: pair[0],
                                                            reverse=True))]
        total = np.sum(indicators)
        sums = np.array([np.sum(indicators[:ii+1]) for ii in np.arange(len(indicators))])
        where = sums > theta*total
        if np.any(where):
            return indices[:np.argmax(where)+1]
        else:
            return indices

    discretization = detailed_data['discretization']
    example        = detailed_data['example']
    local_products = detailed_data['local_products']
    mu_bar_dune    = detailed_data['mu_bar_dune']
    mu_hat_dune    = detailed_data['mu_hat_dune']
    norm           = detailed_data['norm']
    wrapper        = detailed_data['wrapper']

    basis     = offline_data['basis']
    basis_mus = offline_data['basis_mus']
    rd        = offline_data['rd']
    rc        = offline_data['rc']

    reduced_estimator = ReducedEstimator(discretization, example, wrapper, mu_hat_dune, mu_bar_dune,
                                         norm, cfg['estimator_compute'], cfg['estimator_return'])
    reduced_estimator.extension_step += 1
    reduced_estimator.rc = rc
    num_test_samples = cfg['num_test_samples']
    target_error = cfg['online_target_error']

    logger.info('Started online phase for {} samples'.format(num_test_samples))
    test_samples = list(discretization.parameter_space.sample_randomly(num_test_samples))

    if cfg['estimate_some_errors'] and len(test_samples) > 0:
        logger.info('Estimating discretization errors:')
        detailed_estimator = DetailedEstimator(example, wrapper, mu_hat_dune, mu_bar_dune)
        estimates = [detailed_estimator.estimate(
                         discretization.globalize_vectors(discretization.solve(mu))._list[0]._impl,
                         wrapper.dune_parameter(mu)) for mu in test_samples]
        max_error = np.amax(estimates)
        logger.info('  range: [{}, {}]'.format(np.amin(estimates), max_error))
        logger.info('  mean:   {}'.format(np.mean(estimates)))
        add_values(estimates=estimates)
        if max_error > cfg['online_target_error']:
            logger.warn('Given target error of {} is below the worst discretization error {}!'.format(
                cfg['online_target_error'], max_error))
        print('')

    failures = 0
    successes = 0
    for mu in test_samples:
        mu_dune = wrapper.dune_parameter(mu)
        mu_in_basis = mu in basis_mus
        age = np.ones(discretization.num_subdomains)
        logger.info('Solving for {} ...'.format(mu))
        U_red = rd.solve(mu)
        logger.info('Estimating (mu is {}in the basis) ...'.format('already ' if mu_in_basis else 'not '))
        error = reduced_estimator.estimate(U_red, mu, discretization)
        if error > target_error:
            if mu_in_basis:
                logger.error(('The error ({}) is larger than the target_error ({}), '
                             + 'but {} is already in the basis: aborting!').format(
                                 error, target_error, mu))
                logger.error('This usually means that the tolerances are poorly chosen!')
                failures += 1
                print('')
            else:
                try:
                    logger.info('The error ({}) is too large, starting local enrichment phase:'.format(error))
                    num_extensions = 0

                    intermediate_basis = [bb.copy() for bb in basis]
                    if cfg['local_indicators'] == 'model_reduction_error':
                        U_h = discretization.solve(mu)
                        assert len(U_h) == 1
                    while error > target_error and num_extensions < cfg['online_max_extensions']:
                        U_red_h = rc.reconstruct(U_red)
                        assert len(U_red_h) == 1
                        U_red_global = discretization.globalize_vectors(U_red_h)
                        U_red_dune = U_red_global._list[0]._impl
                        if (cfg['uniform_enrichment_factor'] > 0
                            and error/target_error > cfg['uniform_enrichment_factor']):
                            logger.info('- Enriching on all subdomains, since error/target_error = {}'.format(
                                error/target_error))
                            marked_subdomains = range(discretization.num_subdomains)
                            if 'age' in cfg['marking_strategy']:
                                age = np.ones(discretization.num_subdomains)
                        else:
                            logger.info('- Estimating local error contributions ...')
                            # compute local error indicators
                            if cfg['local_indicators'] == 'model_reduction_error':
                                difference = U_h - U_red_h
                                local_indicators = [induced_norm(local_products[ss])(difference._blocks[ss])
                                                    for ss in np.arange(discretization.num_subdomains)]
                            elif cfg['local_indicators'] == 'eta_red':
                                local_indicators = list(example.estimate_local(U_red_dune,
                                                                               'eta_OS2014_*',
                                                                               mu_hat_dune,
                                                                               mu_bar_dune,
                                                                               mu_dune))
                            else:
                                raise ConfigurationError('Unknown local_indicators given: {}'.format(
                                    cfg['local_indicators']))
                            # mark subdomains
                            if 'doerfler' in cfg['marking_strategy']:
                                marked_subdomains = set(doerfler_marking(local_indicators,
                                                                         cfg['doerfler_marking_theta']))
                            else:
                                raise ConfigurationError('Unknown marking_strategy given: {}'.format(
                                    cfg['local_indicators']))
                            if 'neighbours' in cfg['marking_strategy']:
                                for ss in list(marked_subdomains):
                                    neighbours = (list(discretization._impl.neighbouring_subdomains(ss)))
                                    for nn in neighbours:
                                        marked_subdomains.append(nn)
                                marked_subdomains = set(marked_subdomains)
                            if 'age' in cfg['marking_strategy']:
                                only_marked = len(marked_subdomains)
                                too_old = np.where(age > cfg['marking_max_age'])[0]
                                for ss in too_old:
                                    marked_subdomains.add(ss)
                                logger.info(('  {} subdomains marked ({} bc. of age), '
                                             + 'computing local solutions ...').format(
                                                 len(marked_subdomains), len(marked_subdomains) - only_marked))
                            else:
                                logger.info('  {} subdomains marked, computing local solutions ...'.format(
                                    len(marked_subdomains)))
                            for ss in np.arange(discretization.num_subdomains):
                                if ss in marked_subdomains:
                                    age[ss] = 1
                                else:
                                    age[ss] += 1
                        # compute updated local solution
                        local_solutions = [None for ss in np.arange(discretization.num_subdomains)]
                        for subdomain in marked_subdomains:
                            local_boundary_values = cfg['local_boundary_values']
                            if not (local_boundary_values == 'dirichlet' or local_boundary_values == 'neumann'):
                                raise ConfigurationError('Unknown local_boundary_values given: {}'.format(
                                    local_boundary_values))
                            oversampled_discretization = discretization.get_oversampled_discretization(
                                    subdomain, local_boundary_values)
                            local_discretization = discretization.get_local_discretization(subdomain)
                            U_red_oversampled_dune = example.project_global_to_oversampled(U_red_dune, subdomain)
                            U_h_improved_oversampled_dune = example.solve_oversampled(
                                    subdomain, local_boundary_values, U_red_oversampled_dune, mu_dune)
                            U_h_improved_local_dune = example.project_oversampled_to_local(
                                    U_h_improved_oversampled_dune, subdomain)
                            U_h_improved_local = make_listvectorarray(wrapper[U_h_improved_local_dune])
                            local_solutions[subdomain] = U_h_improved_local
                        # extend local bases
                        logger.info('  Extending bases on {} subdomain{}...'.format(
                            len(marked_subdomains), '' if len(marked_subdomains) == 1 else 's'))
                        old_basis_size = sum([len(bb) for bb in intermediate_basis])
                        extended_bases, _ = gram_schmidt_block_basis_extension(
                                [intermediate_basis[ss] for ss in marked_subdomains],
                                [local_solutions[ss] for ss in marked_subdomains],
                                product=[local_products[ss] for ss in marked_subdomains])
                        assert len(extended_bases) == len(marked_subdomains)
                        for ii, subdomain in enumerate(marked_subdomains):
                            intermediate_basis[subdomain] = extended_bases[ii]
                        new_basis_size = sum([len(bb) for bb in intermediate_basis])
                        num_extensions += 1
                        logger.info('  Reducing ...')
                        rd, _, _ = reduce_generic_rb(discretization, intermediate_basis)
                        rc = GenericBlockRBReconstructor(intermediate_basis)
                        reduced_estimator.rc = rc
                        reduced_estimator.extension_step += 1
                        U_red = rd.solve(mu)
                        logger.info('  Estimating (total basis size: {})'.format(
                            sum(len(bb) for bb in intermediate_basis)))
                        new_error = reduced_estimator.estimate(U_red, mu, discretization)
                        order = np.log(new_error/error)/np.log(old_basis_size/new_basis_size)
                        logger.info('              {} (relative improvement: {})'.format(new_error, order))
                        if new_error > error:
                            logger.warn('The error has increased (from {} to {}) after enrichment!'.format(error,
                                                                                                           new_error))
                        elif order < 1:
                            logger.warn(('The error has decreased only slightly '
                                         + '(from {} to {}) after enrichment!').format(error, new_error))
                        if num_extensions >= cfg['online_max_extensions'] and new_error > cfg['online_target_error']:
                            basis = intermediate_basis
                            raise EnrichmentError('Reached maximum number of {} extensions!'.format(
                                cfg['online_max_extensions']))
                        error = new_error
                    logger.info('  The error ({}) is below the target error, continuing ...'.format(error))
                    successes += 1
                    basis = intermediate_basis
                    logger.info('Basis sizes range from {} to {}.'.format(np.min([len(bb) for bb in basis]),
                                                                          np.max([len(bb) for bb in basis])))
                except EnrichmentError, ee:
                    logger.critical('Enrichment stopped because: {}'.format(ee))
                    logger.info('Basis sizes range from {} to {}.'.format(np.min([len(bb) for bb in basis]),
                                                                          np.max([len(bb) for bb in basis])))
                    logger.info('Continuing with the next parameter ...')
                    failures += 1
                print('')
        else:
            logger.info('The error ({}) is below the target error, continuing ...'.format(error))
            successes += 1
            print('')
Example #10
0
             for mu in (config['mu_min'], config['mu_max'])]
logger.info('  range: {} to {}'.format(np.min(estimates), np.max(estimates)))
if np.max(estimates) > config['target_error']:
    logger.warn(('target error for greedy ({}) is below max estimated discretization error ({}), '
                 + 'greedy will most likely fail!').format(config['target_error'], np.max(estimates)))

if config['initial_basis'] < 0:
    config['initial_basis'] = 0
elif config['initial_basis'] > 1:
    config['initial_basis'] = 1
logger.info('initializing local reduced bases of order up to {} ...'.format(config['initial_basis']))
local_products = [elliptic_disc.local_product(ss, config['extension_product'])
                  for ss in np.arange(elliptic_disc.num_subdomains)]
initial_basis = elliptic_disc.solution_space.empty()._blocks
for basis in (('1',) if config['initial_basis'] == 0 else ('1', 'x[0]', 'x[1]', 'x[0]*x[1]')):
    vec = make_listvectorarray(wrapper[example.project(basis)])
    vec = BlockVectorArray([elliptic_disc.localize_vector(vec, ss)
                            for ss in np.arange(elliptic_disc.num_subdomains)])
    initial_basis, _ = gram_schmidt_block_basis_extension(initial_basis, vec, product=local_products)
f_h = elliptic_disc.rhs.as_vector(1.)
f_h = elliptic_disc.l2_product.apply_inverse(f_h)
initial_basis, _ = gram_schmidt_block_basis_extension(initial_basis, f_h, product=local_products)
detailed_data['initial_basis'] = initial_basis

greedy_data = reduce_pod_greedy(config, detailed_data, training_samples)

add_values(greedy_max_err_mus=greedy_data['max_err_mus'],
           greedy_max_errs=greedy_data['max_errs'],
           greedy_extensions=greedy_data['extensions'],
           greedy_basis_sizes=[len(local_RB) for local_RB in greedy_data['basis']],
           training_samples=training_samples)
Example #11
0
                                                  np.max(estimates)))

if config['initial_basis'] < 0:
    config['initial_basis'] = 0
elif config['initial_basis'] > 1:
    config['initial_basis'] = 1
logger.info('initializing local reduced bases of order up to {} ...'.format(
    config['initial_basis']))
local_products = [
    elliptic_disc.local_product(ss, config['extension_product'])
    for ss in np.arange(elliptic_disc.num_subdomains)
]
initial_basis = elliptic_disc.solution_space.empty()._blocks
for basis in (('1', ) if config['initial_basis'] == 0 else
              ('1', 'x[0]', 'x[1]', 'x[0]*x[1]')):
    vec = make_listvectorarray(wrapper[example.project(basis)])
    vec = BlockVectorArray([
        elliptic_disc.localize_vector(vec, ss)
        for ss in np.arange(elliptic_disc.num_subdomains)
    ])
    initial_basis, _ = gram_schmidt_block_basis_extension(
        initial_basis, vec, product=local_products)
f_h = elliptic_disc.rhs.as_vector(1.)
f_h = elliptic_disc.l2_product.apply_inverse(f_h)
initial_basis, _ = gram_schmidt_block_basis_extension(initial_basis,
                                                      f_h,
                                                      product=local_products)
detailed_data['initial_basis'] = initial_basis

greedy_data = reduce_pod_greedy(config, detailed_data, training_samples)
Example #12
0
 def localize_vector(self, global_vector, subdomain):
     assert subdomain < self.num_subdomains
     return make_listvectorarray([self._wrapper[self._impl.localize_vector(global_vector._list[ii]._impl,
                                                                           subdomain)]
                                  for ii in np.arange(len(global_vector))])
Example #13
0
example = Example(logger_cfg, grid_cfg, boundary_cfg, problem_cfg)
stat_blocked_disc = wrapper[example.discretization()]
stat_nonblocked_disc = stat_blocked_disc.as_nonblocked()
logger.info('  grid has {} subdomains'.format(
    stat_blocked_disc.num_subdomains))
logger.info('  discretization has {} DoFs'.format(
    stat_nonblocked_disc.solution_space.dim))
logger.info('  parameter type is {}'.format(
    stat_nonblocked_disc.parameter_type))
# logger.info('visualizing grid and data functions ...')
# example.visualize(problem_cfg.get_str('type'))

nonblocked_disc = InstationaryDiscretization(
    T=config['end_time'],
    initial_data=make_listvectorarray(
        wrapper[stat_nonblocked_disc._impl.create_vector()]),
    operator=stat_nonblocked_disc.operator,
    rhs=stat_nonblocked_disc.rhs,
    mass=stat_nonblocked_disc.products['l2'],
    time_stepper=ImplicitEulerTimeStepper(
        config['nt'], invert_options=solver_options.get_str('type')),
    products=stat_nonblocked_disc.products,
    operators=stat_nonblocked_disc.operators,
    functionals=stat_nonblocked_disc.functionals,
    vector_operators=stat_nonblocked_disc.vector_operators,
    visualizer=InstationaryDuneVisualizer(
        stat_nonblocked_disc,
        problem_cfg.get_str('type') + '.solution'),
    parameter_space=CubicParameterSpace(stat_nonblocked_disc.parameter_type,
                                        0.1, 10),
    cache_region='disk',
def discretize(num_elements, num_partitions, T, nt, initial_data, parameter_range, name='detailed discretization'):
    Example = examples[2]['aluconformgrid']['fem']['istl']

    logger_cfg = Example.logger_options()
    logger_cfg.set('info', -1, True)
    logger_cfg.set('info_color', 'blue', True)

    grid_cfg = Example.grid_options('grid.multiscale.provider.cube')
    grid_cfg.set('lower_left',     '[0 0]', True)
    grid_cfg.set('upper_right',    '[5 1]', True)
    grid_cfg.set('num_elements',   num_elements, True)
    grid_cfg.set('num_partitions', num_partitions, True)

    boundary_cfg = Example.boundary_options('stuff.grid.boundaryinfo.alldirichlet')

    problem_cfg = Example.problem_options('hdd.linearelliptic.problem.OS2015.spe10model1')
    problem_cfg.set('parametric_channel', 'true', True)
    problem_cfg.set('channel_boundary_layer', '0', True)
    problem_cfg.set('filename', 'perm_case1.dat', True)
    problem_cfg.set('lower_left', '[0 0]', True)
    problem_cfg.set('upper_right', '[5 1]', True)
    problem_cfg.set('num_elements', '[100 20]', True)
    problem_cfg.set('forces.0.domain', '[0.95 1.10; 0.30 0.45]', True)
    problem_cfg.set('forces.0.value', '2000', True)
    problem_cfg.set('forces.1.domain', '[3.00 3.15; 0.75 0.90]', True)
    problem_cfg.set('forces.1.value', '-1000', True)
    problem_cfg.set('forces.2.domain', '[4.25 4.40; 0.25 0.40]', True)
    problem_cfg.set('forces.2.value', '-1000', True)
    problem_cfg.set('channel.0.value', '-1.07763239495', True)
    problem_cfg.set('channel.1.value', '-1.07699512772', True)
    problem_cfg.set('channel.2.value', '-1.07356156439', True)
    problem_cfg.set('channel.3.value', '-1.06602281736', True)
    problem_cfg.set('channel.4.value', '-1.06503683743', True)
    problem_cfg.set('channel.5.value', '-1.07974870426', True)
    problem_cfg.set('channel.6.value', '-1.05665895923', True)
    problem_cfg.set('channel.7.value', '-1.08310334837', True)
    problem_cfg.set('channel.8.value', '-1.05865484973', True)
    problem_cfg.set('channel.9.value', '-1.05871039535', True)
    problem_cfg.set('channel.10.value', '-1.08136695901', True)
    problem_cfg.set('channel.11.value', '-1.08490172721', True)
    problem_cfg.set('channel.12.value', '-1.06641120758', True)
    problem_cfg.set('channel.13.value', '-1.06812773298', True)
    problem_cfg.set('channel.14.value', '-1.07695652049', True)
    problem_cfg.set('channel.15.value', '-1.08630079205', True)
    problem_cfg.set('channel.16.value', '-1.08273722112', True)
    problem_cfg.set('channel.17.value', '-1.07500402155', True)
    problem_cfg.set('channel.18.value', '-1.08607142562', True)
    problem_cfg.set('channel.19.value', '-1.07268761799', True)
    problem_cfg.set('channel.20.value', '-1.08537037362', True)
    problem_cfg.set('channel.21.value', '-1.08466927273', True)
    problem_cfg.set('channel.22.value', '-1.08444661815', True)
    problem_cfg.set('channel.23.value', '-1.08957037967', True)
    problem_cfg.set('channel.24.value', '-1.08047394052', True)
    problem_cfg.set('channel.25.value', '-1.08221229083', True)
    problem_cfg.set('channel.26.value', '-1.08568599863', True)
    problem_cfg.set('channel.27.value', '-1.08428347872', True)
    problem_cfg.set('channel.28.value', '-1.09104098734', True)
    problem_cfg.set('channel.29.value', '-1.09492700673', True)
    problem_cfg.set('channel.30.value', '-1.09760440537', True)
    problem_cfg.set('channel.31.value', '-1.09644989453', True)
    problem_cfg.set('channel.32.value', '-1.09441681025', True)
    problem_cfg.set('channel.33.value', '-1.09533290654', True)
    problem_cfg.set('channel.34.value', '-1.1001430808', True)
    problem_cfg.set('channel.35.value', '-1.10065627621', True)
    problem_cfg.set('channel.36.value', '-1.10125877186', True)
    problem_cfg.set('channel.37.value', '-1.10057485893', True)
    problem_cfg.set('channel.38.value', '-1.10002261906', True)
    problem_cfg.set('channel.39.value', '-1.10219154209', True)
    problem_cfg.set('channel.40.value', '-1.09994463801', True)
    problem_cfg.set('channel.41.value', '-1.10265630533', True)
    problem_cfg.set('channel.42.value', '-1.10448566526', True)
    problem_cfg.set('channel.43.value', '-1.10735820121', True)
    problem_cfg.set('channel.44.value', '-1.1070022367', True)
    problem_cfg.set('channel.45.value', '-1.10777650387', True)
    problem_cfg.set('channel.46.value', '-1.10892785562', True)
    problem_cfg.set('channel.0.domain', '[1.7 1.75; 0.5 0.55]', True)
    problem_cfg.set('channel.1.domain', '[1.75 1.8; 0.5 0.55]', True)
    problem_cfg.set('channel.2.domain', '[1.8 1.85; 0.5 0.55]', True)
    problem_cfg.set('channel.3.domain', '[1.85 1.9; 0.5 0.55]', True)
    problem_cfg.set('channel.4.domain', '[1.9 1.95; 0.5 0.55]', True)
    problem_cfg.set('channel.5.domain', '[1.95 2.0; 0.5 0.55]', True)
    problem_cfg.set('channel.6.domain', '[2.0 2.05; 0.5 0.55]', True)
    problem_cfg.set('channel.7.domain', '[2.05 2.1; 0.5 0.55]', True)
    problem_cfg.set('channel.8.domain', '[2.1 2.15; 0.5 0.55]', True)
    problem_cfg.set('channel.9.domain', '[2.15 2.2; 0.5 0.55]', True)
    problem_cfg.set('channel.10.domain', '[2.2 2.25; 0.5 0.55]', True)
    problem_cfg.set('channel.11.domain', '[2.25 2.3; 0.5 0.55]', True)
    problem_cfg.set('channel.12.domain', '[2.3 2.35; 0.5 0.55]', True)
    problem_cfg.set('channel.13.domain', '[2.35 2.4; 0.5 0.55]', True)
    problem_cfg.set('channel.14.domain', '[2.4 2.45; 0.5 0.55]', True)
    problem_cfg.set('channel.15.domain', '[2.45 2.5; 0.5 0.55]', True)
    problem_cfg.set('channel.16.domain', '[2.5 2.55; 0.5 0.55]', True)
    problem_cfg.set('channel.17.domain', '[2.55 2.6; 0.5 0.55]', True)
    problem_cfg.set('channel.18.domain', '[2.6 2.65; 0.5 0.55]', True)
    problem_cfg.set('channel.19.domain', '[2.65 2.7; 0.5 0.55]', True)
    problem_cfg.set('channel.20.domain', '[2.7 2.75; 0.5 0.55]', True)
    problem_cfg.set('channel.21.domain', '[2.75 2.8; 0.5 0.55]', True)
    problem_cfg.set('channel.22.domain', '[2.8 2.85; 0.5 0.55]', True)
    problem_cfg.set('channel.23.domain', '[2.85 2.9; 0.5 0.55]', True)
    problem_cfg.set('channel.24.domain', '[2.9 2.95; 0.5 0.55]', True)
    problem_cfg.set('channel.25.domain', '[2.95 3.0; 0.5 0.55]', True)
    problem_cfg.set('channel.26.domain', '[3.0 3.05; 0.5 0.55]', True)
    problem_cfg.set('channel.27.domain', '[3.05 3.1; 0.5 0.55]', True)
    problem_cfg.set('channel.28.domain', '[3.1 3.15; 0.5 0.55]', True)
    problem_cfg.set('channel.29.domain', '[3.15 3.2; 0.5 0.55]', True)
    problem_cfg.set('channel.30.domain', '[3.2 3.25; 0.5 0.55]', True)
    problem_cfg.set('channel.31.domain', '[3.25 3.3; 0.5 0.55]', True)
    problem_cfg.set('channel.32.domain', '[3.3 3.35; 0.5 0.55]', True)
    problem_cfg.set('channel.33.domain', '[3.35 3.4; 0.5 0.55]', True)
    problem_cfg.set('channel.34.domain', '[3.4 3.45; 0.5 0.55]', True)
    problem_cfg.set('channel.35.domain', '[3.45 3.5; 0.5 0.55]', True)
    problem_cfg.set('channel.36.domain', '[3.5 3.55; 0.5 0.55]', True)
    problem_cfg.set('channel.37.domain', '[3.55 3.6; 0.5 0.55]', True)
    problem_cfg.set('channel.38.domain', '[3.6 3.65; 0.5 0.55]', True)
    problem_cfg.set('channel.39.domain', '[3.65 3.7; 0.5 0.55]', True)
    problem_cfg.set('channel.40.domain', '[3.7 3.75; 0.5 0.55]', True)
    problem_cfg.set('channel.41.domain', '[3.75 3.8; 0.5 0.55]', True)
    problem_cfg.set('channel.42.domain', '[3.8 3.85; 0.5 0.55]', True)
    problem_cfg.set('channel.43.domain', '[3.85 3.9; 0.5 0.55]', True)
    problem_cfg.set('channel.44.domain', '[3.9 3.95; 0.5 0.55]', True)
    problem_cfg.set('channel.45.domain', '[3.95 4.0; 0.5 0.55]', True)
    problem_cfg.set('channel.46.domain', '[4.0 4.05; 0.5 0.55]', True)
    problem_cfg.set('channel.47.value', '-1.10372589211', True)
    problem_cfg.set('channel.48.value', '-1.1020889988', True)
    problem_cfg.set('channel.49.value', '-1.09806955069', True)
    problem_cfg.set('channel.50.value', '-1.10000902421', True)
    problem_cfg.set('channel.51.value', '-1.08797468724', True)
    problem_cfg.set('channel.52.value', '-1.08827472176', True)
    problem_cfg.set('channel.53.value', '-1.08692237109', True)
    problem_cfg.set('channel.54.value', '-1.07893190093', True)
    problem_cfg.set('channel.55.value', '-1.08748373853', True)
    problem_cfg.set('channel.56.value', '-1.07445197324', True)
    problem_cfg.set('channel.57.value', '-1.08246613163', True)
    problem_cfg.set('channel.58.value', '-1.06726790504', True)
    problem_cfg.set('channel.59.value', '-1.07891217847', True)
    problem_cfg.set('channel.60.value', '-1.07260827126', True)
    problem_cfg.set('channel.61.value', '-1.07094062748', True)
    problem_cfg.set('channel.62.value', '-1.0692399429', True)
    problem_cfg.set('channel.63.value', '-1.00099885701', True)
    problem_cfg.set('channel.64.value', '-1.00109544002', True)
    problem_cfg.set('channel.65.value', '-0.966491003242', True)
    problem_cfg.set('channel.66.value', '-0.802284684014', True)
    problem_cfg.set('channel.67.value', '-0.980790923021', True)
    problem_cfg.set('channel.68.value', '-0.614478271687', True)
    problem_cfg.set('channel.69.value', '-0.288129858959', True)
    problem_cfg.set('channel.70.value', '-0.929509396842', True)
    problem_cfg.set('channel.71.value', '-0.992376505995', True)
    problem_cfg.set('channel.72.value', '-0.968162494855', True)
    problem_cfg.set('channel.73.value', '-0.397316938901', True)
    problem_cfg.set('channel.74.value', '-0.970934956609', True)
    problem_cfg.set('channel.75.value', '-0.784344730096', True)
    problem_cfg.set('channel.76.value', '-0.539725422323', True)
    problem_cfg.set('channel.77.value', '-0.915632282372', True)
    problem_cfg.set('channel.78.value', '-0.275089177273', True)
    problem_cfg.set('channel.79.value', '-0.949684959286', True)
    problem_cfg.set('channel.80.value', '-0.936132529794', True)
    problem_cfg.set('channel.47.domain', '[2.6 2.65; 0.45 0.50]', True)
    problem_cfg.set('channel.48.domain', '[2.65 2.7; 0.45 0.50]', True)
    problem_cfg.set('channel.49.domain', '[2.7 2.75; 0.45 0.50]', True)
    problem_cfg.set('channel.50.domain', '[2.75 2.8; 0.45 0.50]', True)
    problem_cfg.set('channel.51.domain', '[2.8 2.85; 0.45 0.50]', True)
    problem_cfg.set('channel.52.domain', '[2.85 2.9; 0.45 0.50]', True)
    problem_cfg.set('channel.53.domain', '[2.9 2.95; 0.45 0.50]', True)
    problem_cfg.set('channel.54.domain', '[2.95 3.0; 0.45 0.50]', True)
    problem_cfg.set('channel.55.domain', '[3.0 3.05; 0.45 0.50]', True)
    problem_cfg.set('channel.56.domain', '[3.05 3.1; 0.45 0.50]', True)
    problem_cfg.set('channel.57.domain', '[3.1 3.15; 0.45 0.50]', True)
    problem_cfg.set('channel.58.domain', '[3.15 3.2; 0.45 0.50]', True)
    problem_cfg.set('channel.59.domain', '[3.2 3.25; 0.45 0.50]', True)
    problem_cfg.set('channel.60.domain', '[3.25 3.3; 0.45 0.50]', True)
    problem_cfg.set('channel.61.domain', '[3.3 3.35; 0.45 0.50]', True)
    problem_cfg.set('channel.62.domain', '[3.35 3.4; 0.45 0.50]', True)
    problem_cfg.set('channel.63.domain', '[3.4 3.45; 0.45 0.50]', True)
    problem_cfg.set('channel.64.domain', '[3.45 3.5; 0.45 0.50]', True)
    problem_cfg.set('channel.65.domain', '[3.5 3.55; 0.45 0.50]', True)
    problem_cfg.set('channel.66.domain', '[3.55 3.6; 0.45 0.50]', True)
    problem_cfg.set('channel.67.domain', '[3.6 3.65; 0.45 0.50]', True)
    problem_cfg.set('channel.68.domain', '[3.65 3.7; 0.45 0.50]', True)
    problem_cfg.set('channel.69.domain', '[3.7 3.75; 0.45 0.50]', True)
    problem_cfg.set('channel.70.domain', '[3.75 3.8; 0.45 0.50]', True)
    problem_cfg.set('channel.71.domain', '[3.8 3.85; 0.45 0.50]', True)
    problem_cfg.set('channel.72.domain', '[3.85 3.9; 0.45 0.50]', True)
    problem_cfg.set('channel.73.domain', '[3.9 3.95; 0.45 0.50]', True)
    problem_cfg.set('channel.74.domain', '[3.95 4.0; 0.45 0.50]', True)
    problem_cfg.set('channel.75.domain', '[4.0 4.05; 0.45 0.50]', True)
    problem_cfg.set('channel.76.domain', '[4.05 4.1; 0.45 0.50]', True)
    problem_cfg.set('channel.77.domain', '[4.1 4.15; 0.45 0.50]', True)
    problem_cfg.set('channel.78.domain', '[4.15 4.2; 0.45 0.50]', True)
    problem_cfg.set('channel.79.domain', '[4.2 4.25; 0.45 0.50]', True)
    problem_cfg.set('channel.80.domain', '[4.25 4.3; 0.45 0.50]', True)
    problem_cfg.set('channel.81.value', '-1.10923642795', True)
    problem_cfg.set('channel.82.value', '-1.10685618623', True)
    problem_cfg.set('channel.83.value', '-1.1057800376', True)
    problem_cfg.set('channel.84.value', '-1.10187723629', True)
    problem_cfg.set('channel.85.value', '-1.10351710464', True)
    problem_cfg.set('channel.86.value', '-1.10037551137', True)
    problem_cfg.set('channel.87.value', '-1.09724407076', True)
    problem_cfg.set('channel.88.value', '-1.09604600208', True)
    problem_cfg.set('channel.89.value', '-1.09354469656', True)
    problem_cfg.set('channel.90.value', '-1.08934455354', True)
    problem_cfg.set('channel.91.value', '-1.08155476586', True)
    problem_cfg.set('channel.92.value', '-1.07815397899', True)
    problem_cfg.set('channel.93.value', '-1.09174062023', True)
    problem_cfg.set('channel.94.value', '-1.07433616068', True)
    problem_cfg.set('channel.95.value', '-1.08030587701', True)
    problem_cfg.set('channel.81.domain', '[1.95 2.0; 0.40 0.45]', True)
    problem_cfg.set('channel.82.domain', '[2.0 2.05; 0.40 0.45]', True)
    problem_cfg.set('channel.83.domain', '[2.05 2.1; 0.40 0.45]', True)
    problem_cfg.set('channel.84.domain', '[2.1 2.15; 0.40 0.45]', True)
    problem_cfg.set('channel.85.domain', '[2.15 2.2; 0.40 0.45]', True)
    problem_cfg.set('channel.86.domain', '[2.2 2.25; 0.40 0.45]', True)
    problem_cfg.set('channel.87.domain', '[2.25 2.3; 0.40 0.45]', True)
    problem_cfg.set('channel.88.domain', '[2.3 2.35; 0.40 0.45]', True)
    problem_cfg.set('channel.89.domain', '[2.35 2.4; 0.40 0.45]', True)
    problem_cfg.set('channel.90.domain', '[2.4 2.45; 0.40 0.45]', True)
    problem_cfg.set('channel.91.domain', '[2.45 2.5; 0.40 0.45]', True)
    problem_cfg.set('channel.92.domain', '[2.5 2.55; 0.40 0.45]', True)
    problem_cfg.set('channel.93.domain', '[2.55 2.6; 0.40 0.45]', True)
    problem_cfg.set('channel.94.domain', '[2.6 2.65; 0.40 0.45]', True)
    problem_cfg.set('channel.95.domain', '[2.65 2.7; 0.40 0.45]', True)
    problem_cfg.set('channel.96.value', '-1.00032869407', True)
    problem_cfg.set('channel.97.value', '-1.01175908905', True)
    problem_cfg.set('channel.98.value', '-1.04954395793', True)
    problem_cfg.set('channel.99.value', '-1.017967697', True)
    problem_cfg.set('channel.100.value', '-1.04647184091', True)
    problem_cfg.set('channel.101.value', '-1.01911894831', True)
    problem_cfg.set('channel.102.value', '-1.00699340158', True)
    problem_cfg.set('channel.103.value', '-0.995492960025', True)
    problem_cfg.set('channel.104.value', '-1.0373059007', True)
    problem_cfg.set('channel.96.domain', '[2.25 2.3; 0.35 0.40]', True)
    problem_cfg.set('channel.97.domain', '[2.3 2.35; 0.35 0.40]', True)
    problem_cfg.set('channel.98.domain', '[2.35 2.4; 0.35 0.40]', True)
    problem_cfg.set('channel.99.domain', '[2.4 2.45; 0.35 0.40]', True)
    problem_cfg.set('channel.100.domain', '[2.45 2.5; 0.35 0.40]', True)
    problem_cfg.set('channel.101.domain', '[2.5 2.55; 0.35 0.40]', True)
    problem_cfg.set('channel.102.domain', '[2.55 2.6; 0.35 0.40]', True)
    problem_cfg.set('channel.103.domain', '[2.6 2.65; 0.35 0.40]', True)
    problem_cfg.set('channel.104.domain', '[2.65 2.7; 0.35 0.4]', True)

    example = Example(logger_cfg, grid_cfg, boundary_cfg, problem_cfg, ['l2', 'h1', 'elliptic_penalty'])

    elliptic_LRBMS_disc = wrapper[example.discretization()]
    parameter_space = CubicParameterSpace(elliptic_LRBMS_disc.parameter_type, parameter_range[0], parameter_range[1])
    elliptic_LRBMS_disc = elliptic_LRBMS_disc.with_(parameter_space=parameter_space)
    elliptic_disc = elliptic_LRBMS_disc.as_nonblocked().with_(parameter_space=parameter_space)

    def prolong(coarse_disc, coarse_U):
        time_grid_ref = OnedGrid(domain=(0., T), num_intervals=nt)
        time_grid = OnedGrid(domain=(0., T), num_intervals=(len(coarse_U) - 1))
        U_fine = [None for ii in time_grid_ref.centers(1)]
        for n in np.arange(len(time_grid_ref.centers(1))):
            t_n = time_grid_ref.centers(1)[n]
            coarse_entity = min((time_grid.centers(1) <= t_n).nonzero()[0][-1],
                                time_grid.size(0) - 1)
            a = time_grid.centers(1)[coarse_entity]
            b = time_grid.centers(1)[coarse_entity + 1]
            SF = np.array((1./(a - b)*t_n - b/(a - b),
                           1./(b - a)*t_n - a/(b - a)))
            U_t = coarse_U.copy(ind=coarse_entity)
            U_t.scal(SF[0][0])
            U_t.axpy(SF[1][0], coarse_U, x_ind=(coarse_entity + 1))
            U_fine[n] = wrapper[example.prolong(coarse_disc._impl, U_t._list[0]._impl)]
        return make_listvectorarray(U_fine)

    if isinstance(initial_data, str):
        initial_data = make_listvectorarray(wrapper[example.project(initial_data)])
        # initial_data = elliptic_disc.operator.apply_inverse(initial_data, mu=(1, 1))
    else:
        coarse_disc = initial_data[0]
        initial_data = initial_data[1]
        assert len(initial_data) == 1
        initial_data = example.prolong(coarse_disc._impl, initial_data._list[0]._impl)
        initial_data = make_listvectorarray(wrapper[initial_data])

    parabolic_disc = InstationaryDiscretization(T=T,
                                                initial_data=initial_data,
                                                operator=elliptic_disc.operator,
                                                rhs=elliptic_disc.rhs,
                                                mass=elliptic_disc.products['l2'],
                                                time_stepper=ImplicitEulerTimeStepper(nt, solver_options='operator'),
                                                products=elliptic_disc.products,
                                                operators=elliptic_disc.operators,
                                                functionals=elliptic_disc.functionals,
                                                vector_operators=elliptic_disc.vector_operators,
                                                visualizer=InstationaryDuneVisualizer(elliptic_disc, 'dune_discretization.solution'),
                                                parameter_space=parameter_space,
                                                cache_region='disk',
                                                name='{} ({} DoFs)'.format(name, elliptic_disc.solution_space.dim))

    return {'example': example,
            'initial_data': initial_data,
            'wrapper': wrapper,
            'elliptic_LRBMS_disc': elliptic_LRBMS_disc,
            'elliptic_disc': elliptic_disc,
            'parabolic_disc': parabolic_disc,
            'prolongator': prolong}
Example #15
0
def discretize(num_elements,
               num_partitions,
               T,
               nt,
               initial_data,
               parameter_range,
               name='detailed discretization'):
    Example = examples[2]['aluconformgrid']['fem']['istl']

    logger_cfg = Example.logger_options()
    logger_cfg.set('info', -1, True)
    logger_cfg.set('info_color', 'blue', True)

    grid_cfg = Example.grid_options('grid.multiscale.provider.cube')
    grid_cfg.set('lower_left', '[0 0]', True)
    grid_cfg.set('upper_right', '[5 1]', True)
    grid_cfg.set('num_elements', num_elements, True)
    grid_cfg.set('num_partitions', num_partitions, True)

    boundary_cfg = Example.boundary_options(
        'stuff.grid.boundaryinfo.alldirichlet')

    problem_cfg = Example.problem_options(
        'hdd.linearelliptic.problem.OS2015.spe10model1')
    problem_cfg.set('parametric_channel', 'true', True)
    problem_cfg.set('channel_boundary_layer', '0', True)
    problem_cfg.set('filename', 'perm_case1.dat', True)
    problem_cfg.set('lower_left', '[0 0]', True)
    problem_cfg.set('upper_right', '[5 1]', True)
    problem_cfg.set('num_elements', '[100 20]', True)
    problem_cfg.set('forces.0.domain', '[0.95 1.10; 0.30 0.45]', True)
    problem_cfg.set('forces.0.value', '2000', True)
    problem_cfg.set('forces.1.domain', '[3.00 3.15; 0.75 0.90]', True)
    problem_cfg.set('forces.1.value', '-1000', True)
    problem_cfg.set('forces.2.domain', '[4.25 4.40; 0.25 0.40]', True)
    problem_cfg.set('forces.2.value', '-1000', True)
    problem_cfg.set('channel.0.value', '-1.07763239495', True)
    problem_cfg.set('channel.1.value', '-1.07699512772', True)
    problem_cfg.set('channel.2.value', '-1.07356156439', True)
    problem_cfg.set('channel.3.value', '-1.06602281736', True)
    problem_cfg.set('channel.4.value', '-1.06503683743', True)
    problem_cfg.set('channel.5.value', '-1.07974870426', True)
    problem_cfg.set('channel.6.value', '-1.05665895923', True)
    problem_cfg.set('channel.7.value', '-1.08310334837', True)
    problem_cfg.set('channel.8.value', '-1.05865484973', True)
    problem_cfg.set('channel.9.value', '-1.05871039535', True)
    problem_cfg.set('channel.10.value', '-1.08136695901', True)
    problem_cfg.set('channel.11.value', '-1.08490172721', True)
    problem_cfg.set('channel.12.value', '-1.06641120758', True)
    problem_cfg.set('channel.13.value', '-1.06812773298', True)
    problem_cfg.set('channel.14.value', '-1.07695652049', True)
    problem_cfg.set('channel.15.value', '-1.08630079205', True)
    problem_cfg.set('channel.16.value', '-1.08273722112', True)
    problem_cfg.set('channel.17.value', '-1.07500402155', True)
    problem_cfg.set('channel.18.value', '-1.08607142562', True)
    problem_cfg.set('channel.19.value', '-1.07268761799', True)
    problem_cfg.set('channel.20.value', '-1.08537037362', True)
    problem_cfg.set('channel.21.value', '-1.08466927273', True)
    problem_cfg.set('channel.22.value', '-1.08444661815', True)
    problem_cfg.set('channel.23.value', '-1.08957037967', True)
    problem_cfg.set('channel.24.value', '-1.08047394052', True)
    problem_cfg.set('channel.25.value', '-1.08221229083', True)
    problem_cfg.set('channel.26.value', '-1.08568599863', True)
    problem_cfg.set('channel.27.value', '-1.08428347872', True)
    problem_cfg.set('channel.28.value', '-1.09104098734', True)
    problem_cfg.set('channel.29.value', '-1.09492700673', True)
    problem_cfg.set('channel.30.value', '-1.09760440537', True)
    problem_cfg.set('channel.31.value', '-1.09644989453', True)
    problem_cfg.set('channel.32.value', '-1.09441681025', True)
    problem_cfg.set('channel.33.value', '-1.09533290654', True)
    problem_cfg.set('channel.34.value', '-1.1001430808', True)
    problem_cfg.set('channel.35.value', '-1.10065627621', True)
    problem_cfg.set('channel.36.value', '-1.10125877186', True)
    problem_cfg.set('channel.37.value', '-1.10057485893', True)
    problem_cfg.set('channel.38.value', '-1.10002261906', True)
    problem_cfg.set('channel.39.value', '-1.10219154209', True)
    problem_cfg.set('channel.40.value', '-1.09994463801', True)
    problem_cfg.set('channel.41.value', '-1.10265630533', True)
    problem_cfg.set('channel.42.value', '-1.10448566526', True)
    problem_cfg.set('channel.43.value', '-1.10735820121', True)
    problem_cfg.set('channel.44.value', '-1.1070022367', True)
    problem_cfg.set('channel.45.value', '-1.10777650387', True)
    problem_cfg.set('channel.46.value', '-1.10892785562', True)
    problem_cfg.set('channel.0.domain', '[1.7 1.75; 0.5 0.55]', True)
    problem_cfg.set('channel.1.domain', '[1.75 1.8; 0.5 0.55]', True)
    problem_cfg.set('channel.2.domain', '[1.8 1.85; 0.5 0.55]', True)
    problem_cfg.set('channel.3.domain', '[1.85 1.9; 0.5 0.55]', True)
    problem_cfg.set('channel.4.domain', '[1.9 1.95; 0.5 0.55]', True)
    problem_cfg.set('channel.5.domain', '[1.95 2.0; 0.5 0.55]', True)
    problem_cfg.set('channel.6.domain', '[2.0 2.05; 0.5 0.55]', True)
    problem_cfg.set('channel.7.domain', '[2.05 2.1; 0.5 0.55]', True)
    problem_cfg.set('channel.8.domain', '[2.1 2.15; 0.5 0.55]', True)
    problem_cfg.set('channel.9.domain', '[2.15 2.2; 0.5 0.55]', True)
    problem_cfg.set('channel.10.domain', '[2.2 2.25; 0.5 0.55]', True)
    problem_cfg.set('channel.11.domain', '[2.25 2.3; 0.5 0.55]', True)
    problem_cfg.set('channel.12.domain', '[2.3 2.35; 0.5 0.55]', True)
    problem_cfg.set('channel.13.domain', '[2.35 2.4; 0.5 0.55]', True)
    problem_cfg.set('channel.14.domain', '[2.4 2.45; 0.5 0.55]', True)
    problem_cfg.set('channel.15.domain', '[2.45 2.5; 0.5 0.55]', True)
    problem_cfg.set('channel.16.domain', '[2.5 2.55; 0.5 0.55]', True)
    problem_cfg.set('channel.17.domain', '[2.55 2.6; 0.5 0.55]', True)
    problem_cfg.set('channel.18.domain', '[2.6 2.65; 0.5 0.55]', True)
    problem_cfg.set('channel.19.domain', '[2.65 2.7; 0.5 0.55]', True)
    problem_cfg.set('channel.20.domain', '[2.7 2.75; 0.5 0.55]', True)
    problem_cfg.set('channel.21.domain', '[2.75 2.8; 0.5 0.55]', True)
    problem_cfg.set('channel.22.domain', '[2.8 2.85; 0.5 0.55]', True)
    problem_cfg.set('channel.23.domain', '[2.85 2.9; 0.5 0.55]', True)
    problem_cfg.set('channel.24.domain', '[2.9 2.95; 0.5 0.55]', True)
    problem_cfg.set('channel.25.domain', '[2.95 3.0; 0.5 0.55]', True)
    problem_cfg.set('channel.26.domain', '[3.0 3.05; 0.5 0.55]', True)
    problem_cfg.set('channel.27.domain', '[3.05 3.1; 0.5 0.55]', True)
    problem_cfg.set('channel.28.domain', '[3.1 3.15; 0.5 0.55]', True)
    problem_cfg.set('channel.29.domain', '[3.15 3.2; 0.5 0.55]', True)
    problem_cfg.set('channel.30.domain', '[3.2 3.25; 0.5 0.55]', True)
    problem_cfg.set('channel.31.domain', '[3.25 3.3; 0.5 0.55]', True)
    problem_cfg.set('channel.32.domain', '[3.3 3.35; 0.5 0.55]', True)
    problem_cfg.set('channel.33.domain', '[3.35 3.4; 0.5 0.55]', True)
    problem_cfg.set('channel.34.domain', '[3.4 3.45; 0.5 0.55]', True)
    problem_cfg.set('channel.35.domain', '[3.45 3.5; 0.5 0.55]', True)
    problem_cfg.set('channel.36.domain', '[3.5 3.55; 0.5 0.55]', True)
    problem_cfg.set('channel.37.domain', '[3.55 3.6; 0.5 0.55]', True)
    problem_cfg.set('channel.38.domain', '[3.6 3.65; 0.5 0.55]', True)
    problem_cfg.set('channel.39.domain', '[3.65 3.7; 0.5 0.55]', True)
    problem_cfg.set('channel.40.domain', '[3.7 3.75; 0.5 0.55]', True)
    problem_cfg.set('channel.41.domain', '[3.75 3.8; 0.5 0.55]', True)
    problem_cfg.set('channel.42.domain', '[3.8 3.85; 0.5 0.55]', True)
    problem_cfg.set('channel.43.domain', '[3.85 3.9; 0.5 0.55]', True)
    problem_cfg.set('channel.44.domain', '[3.9 3.95; 0.5 0.55]', True)
    problem_cfg.set('channel.45.domain', '[3.95 4.0; 0.5 0.55]', True)
    problem_cfg.set('channel.46.domain', '[4.0 4.05; 0.5 0.55]', True)
    problem_cfg.set('channel.47.value', '-1.10372589211', True)
    problem_cfg.set('channel.48.value', '-1.1020889988', True)
    problem_cfg.set('channel.49.value', '-1.09806955069', True)
    problem_cfg.set('channel.50.value', '-1.10000902421', True)
    problem_cfg.set('channel.51.value', '-1.08797468724', True)
    problem_cfg.set('channel.52.value', '-1.08827472176', True)
    problem_cfg.set('channel.53.value', '-1.08692237109', True)
    problem_cfg.set('channel.54.value', '-1.07893190093', True)
    problem_cfg.set('channel.55.value', '-1.08748373853', True)
    problem_cfg.set('channel.56.value', '-1.07445197324', True)
    problem_cfg.set('channel.57.value', '-1.08246613163', True)
    problem_cfg.set('channel.58.value', '-1.06726790504', True)
    problem_cfg.set('channel.59.value', '-1.07891217847', True)
    problem_cfg.set('channel.60.value', '-1.07260827126', True)
    problem_cfg.set('channel.61.value', '-1.07094062748', True)
    problem_cfg.set('channel.62.value', '-1.0692399429', True)
    problem_cfg.set('channel.63.value', '-1.00099885701', True)
    problem_cfg.set('channel.64.value', '-1.00109544002', True)
    problem_cfg.set('channel.65.value', '-0.966491003242', True)
    problem_cfg.set('channel.66.value', '-0.802284684014', True)
    problem_cfg.set('channel.67.value', '-0.980790923021', True)
    problem_cfg.set('channel.68.value', '-0.614478271687', True)
    problem_cfg.set('channel.69.value', '-0.288129858959', True)
    problem_cfg.set('channel.70.value', '-0.929509396842', True)
    problem_cfg.set('channel.71.value', '-0.992376505995', True)
    problem_cfg.set('channel.72.value', '-0.968162494855', True)
    problem_cfg.set('channel.73.value', '-0.397316938901', True)
    problem_cfg.set('channel.74.value', '-0.970934956609', True)
    problem_cfg.set('channel.75.value', '-0.784344730096', True)
    problem_cfg.set('channel.76.value', '-0.539725422323', True)
    problem_cfg.set('channel.77.value', '-0.915632282372', True)
    problem_cfg.set('channel.78.value', '-0.275089177273', True)
    problem_cfg.set('channel.79.value', '-0.949684959286', True)
    problem_cfg.set('channel.80.value', '-0.936132529794', True)
    problem_cfg.set('channel.47.domain', '[2.6 2.65; 0.45 0.50]', True)
    problem_cfg.set('channel.48.domain', '[2.65 2.7; 0.45 0.50]', True)
    problem_cfg.set('channel.49.domain', '[2.7 2.75; 0.45 0.50]', True)
    problem_cfg.set('channel.50.domain', '[2.75 2.8; 0.45 0.50]', True)
    problem_cfg.set('channel.51.domain', '[2.8 2.85; 0.45 0.50]', True)
    problem_cfg.set('channel.52.domain', '[2.85 2.9; 0.45 0.50]', True)
    problem_cfg.set('channel.53.domain', '[2.9 2.95; 0.45 0.50]', True)
    problem_cfg.set('channel.54.domain', '[2.95 3.0; 0.45 0.50]', True)
    problem_cfg.set('channel.55.domain', '[3.0 3.05; 0.45 0.50]', True)
    problem_cfg.set('channel.56.domain', '[3.05 3.1; 0.45 0.50]', True)
    problem_cfg.set('channel.57.domain', '[3.1 3.15; 0.45 0.50]', True)
    problem_cfg.set('channel.58.domain', '[3.15 3.2; 0.45 0.50]', True)
    problem_cfg.set('channel.59.domain', '[3.2 3.25; 0.45 0.50]', True)
    problem_cfg.set('channel.60.domain', '[3.25 3.3; 0.45 0.50]', True)
    problem_cfg.set('channel.61.domain', '[3.3 3.35; 0.45 0.50]', True)
    problem_cfg.set('channel.62.domain', '[3.35 3.4; 0.45 0.50]', True)
    problem_cfg.set('channel.63.domain', '[3.4 3.45; 0.45 0.50]', True)
    problem_cfg.set('channel.64.domain', '[3.45 3.5; 0.45 0.50]', True)
    problem_cfg.set('channel.65.domain', '[3.5 3.55; 0.45 0.50]', True)
    problem_cfg.set('channel.66.domain', '[3.55 3.6; 0.45 0.50]', True)
    problem_cfg.set('channel.67.domain', '[3.6 3.65; 0.45 0.50]', True)
    problem_cfg.set('channel.68.domain', '[3.65 3.7; 0.45 0.50]', True)
    problem_cfg.set('channel.69.domain', '[3.7 3.75; 0.45 0.50]', True)
    problem_cfg.set('channel.70.domain', '[3.75 3.8; 0.45 0.50]', True)
    problem_cfg.set('channel.71.domain', '[3.8 3.85; 0.45 0.50]', True)
    problem_cfg.set('channel.72.domain', '[3.85 3.9; 0.45 0.50]', True)
    problem_cfg.set('channel.73.domain', '[3.9 3.95; 0.45 0.50]', True)
    problem_cfg.set('channel.74.domain', '[3.95 4.0; 0.45 0.50]', True)
    problem_cfg.set('channel.75.domain', '[4.0 4.05; 0.45 0.50]', True)
    problem_cfg.set('channel.76.domain', '[4.05 4.1; 0.45 0.50]', True)
    problem_cfg.set('channel.77.domain', '[4.1 4.15; 0.45 0.50]', True)
    problem_cfg.set('channel.78.domain', '[4.15 4.2; 0.45 0.50]', True)
    problem_cfg.set('channel.79.domain', '[4.2 4.25; 0.45 0.50]', True)
    problem_cfg.set('channel.80.domain', '[4.25 4.3; 0.45 0.50]', True)
    problem_cfg.set('channel.81.value', '-1.10923642795', True)
    problem_cfg.set('channel.82.value', '-1.10685618623', True)
    problem_cfg.set('channel.83.value', '-1.1057800376', True)
    problem_cfg.set('channel.84.value', '-1.10187723629', True)
    problem_cfg.set('channel.85.value', '-1.10351710464', True)
    problem_cfg.set('channel.86.value', '-1.10037551137', True)
    problem_cfg.set('channel.87.value', '-1.09724407076', True)
    problem_cfg.set('channel.88.value', '-1.09604600208', True)
    problem_cfg.set('channel.89.value', '-1.09354469656', True)
    problem_cfg.set('channel.90.value', '-1.08934455354', True)
    problem_cfg.set('channel.91.value', '-1.08155476586', True)
    problem_cfg.set('channel.92.value', '-1.07815397899', True)
    problem_cfg.set('channel.93.value', '-1.09174062023', True)
    problem_cfg.set('channel.94.value', '-1.07433616068', True)
    problem_cfg.set('channel.95.value', '-1.08030587701', True)
    problem_cfg.set('channel.81.domain', '[1.95 2.0; 0.40 0.45]', True)
    problem_cfg.set('channel.82.domain', '[2.0 2.05; 0.40 0.45]', True)
    problem_cfg.set('channel.83.domain', '[2.05 2.1; 0.40 0.45]', True)
    problem_cfg.set('channel.84.domain', '[2.1 2.15; 0.40 0.45]', True)
    problem_cfg.set('channel.85.domain', '[2.15 2.2; 0.40 0.45]', True)
    problem_cfg.set('channel.86.domain', '[2.2 2.25; 0.40 0.45]', True)
    problem_cfg.set('channel.87.domain', '[2.25 2.3; 0.40 0.45]', True)
    problem_cfg.set('channel.88.domain', '[2.3 2.35; 0.40 0.45]', True)
    problem_cfg.set('channel.89.domain', '[2.35 2.4; 0.40 0.45]', True)
    problem_cfg.set('channel.90.domain', '[2.4 2.45; 0.40 0.45]', True)
    problem_cfg.set('channel.91.domain', '[2.45 2.5; 0.40 0.45]', True)
    problem_cfg.set('channel.92.domain', '[2.5 2.55; 0.40 0.45]', True)
    problem_cfg.set('channel.93.domain', '[2.55 2.6; 0.40 0.45]', True)
    problem_cfg.set('channel.94.domain', '[2.6 2.65; 0.40 0.45]', True)
    problem_cfg.set('channel.95.domain', '[2.65 2.7; 0.40 0.45]', True)
    problem_cfg.set('channel.96.value', '-1.00032869407', True)
    problem_cfg.set('channel.97.value', '-1.01175908905', True)
    problem_cfg.set('channel.98.value', '-1.04954395793', True)
    problem_cfg.set('channel.99.value', '-1.017967697', True)
    problem_cfg.set('channel.100.value', '-1.04647184091', True)
    problem_cfg.set('channel.101.value', '-1.01911894831', True)
    problem_cfg.set('channel.102.value', '-1.00699340158', True)
    problem_cfg.set('channel.103.value', '-0.995492960025', True)
    problem_cfg.set('channel.104.value', '-1.0373059007', True)
    problem_cfg.set('channel.96.domain', '[2.25 2.3; 0.35 0.40]', True)
    problem_cfg.set('channel.97.domain', '[2.3 2.35; 0.35 0.40]', True)
    problem_cfg.set('channel.98.domain', '[2.35 2.4; 0.35 0.40]', True)
    problem_cfg.set('channel.99.domain', '[2.4 2.45; 0.35 0.40]', True)
    problem_cfg.set('channel.100.domain', '[2.45 2.5; 0.35 0.40]', True)
    problem_cfg.set('channel.101.domain', '[2.5 2.55; 0.35 0.40]', True)
    problem_cfg.set('channel.102.domain', '[2.55 2.6; 0.35 0.40]', True)
    problem_cfg.set('channel.103.domain', '[2.6 2.65; 0.35 0.40]', True)
    problem_cfg.set('channel.104.domain', '[2.65 2.7; 0.35 0.4]', True)

    example = Example(logger_cfg, grid_cfg, boundary_cfg, problem_cfg,
                      ['l2', 'h1', 'elliptic_penalty'])

    elliptic_LRBMS_disc = wrapper[example.discretization()]
    parameter_space = CubicParameterSpace(elliptic_LRBMS_disc.parameter_type,
                                          parameter_range[0],
                                          parameter_range[1])
    elliptic_LRBMS_disc = elliptic_LRBMS_disc.with_(
        parameter_space=parameter_space)
    elliptic_disc = elliptic_LRBMS_disc.as_nonblocked().with_(
        parameter_space=parameter_space)

    def prolong(coarse_disc, coarse_U):
        time_grid_ref = OnedGrid(domain=(0., T), num_intervals=nt)
        time_grid = OnedGrid(domain=(0., T), num_intervals=(len(coarse_U) - 1))
        U_fine = [None for ii in time_grid_ref.centers(1)]
        for n in np.arange(len(time_grid_ref.centers(1))):
            t_n = time_grid_ref.centers(1)[n]
            coarse_entity = min((time_grid.centers(1) <= t_n).nonzero()[0][-1],
                                time_grid.size(0) - 1)
            a = time_grid.centers(1)[coarse_entity]
            b = time_grid.centers(1)[coarse_entity + 1]
            SF = np.array((1. / (a - b) * t_n - b / (a - b),
                           1. / (b - a) * t_n - a / (b - a)))
            U_t = coarse_U.copy(ind=coarse_entity)
            U_t.scal(SF[0][0])
            U_t.axpy(SF[1][0], coarse_U, x_ind=(coarse_entity + 1))
            U_fine[n] = wrapper[example.prolong(coarse_disc._impl,
                                                U_t._list[0]._impl)]
        return make_listvectorarray(U_fine)

    if isinstance(initial_data, str):
        initial_data = make_listvectorarray(
            wrapper[example.project(initial_data)])
        # initial_data = elliptic_disc.operator.apply_inverse(initial_data, mu=(1, 1))
    else:
        coarse_disc = initial_data[0]
        initial_data = initial_data[1]
        assert len(initial_data) == 1
        initial_data = example.prolong(coarse_disc._impl,
                                       initial_data._list[0]._impl)
        initial_data = make_listvectorarray(wrapper[initial_data])

    parabolic_disc = InstationaryDiscretization(
        T=T,
        initial_data=initial_data,
        operator=elliptic_disc.operator,
        rhs=elliptic_disc.rhs,
        mass=elliptic_disc.products['l2'],
        time_stepper=ImplicitEulerTimeStepper(nt, solver_options='operator'),
        products=elliptic_disc.products,
        operators=elliptic_disc.operators,
        functionals=elliptic_disc.functionals,
        vector_operators=elliptic_disc.vector_operators,
        visualizer=InstationaryDuneVisualizer(elliptic_disc,
                                              'dune_discretization.solution'),
        parameter_space=parameter_space,
        cache_region='disk',
        name='{} ({} DoFs)'.format(name, elliptic_disc.solution_space.dim))

    return {
        'example': example,
        'initial_data': initial_data,
        'wrapper': wrapper,
        'elliptic_LRBMS_disc': elliptic_LRBMS_disc,
        'elliptic_disc': elliptic_disc,
        'parabolic_disc': parabolic_disc,
        'prolongator': prolong
    }