Example #1
0
def _bfuns(fast: bool = False, piola: bool = False, imported: bool = False):
    __, solutions, supremizers = get_ensemble(fast, piola, imported)
    case = get_case(fast, piola)

    eig_sol = reduction.eigen(case, solutions, fields=['v', 'p'])
    rb_sol = reduction.reduced_bases(case, solutions, eig_sol, (12, 12))
    eig_sup = reduction.eigen(case, supremizers, fields=['v'])
    rb_sup = reduction.reduced_bases(case, supremizers, eig_sup, (12,))

    kw = {'piola': piola, 'imported': imported}

    for i in range(6):
        solvers.plots(
            case, case.parameter(), rb_sol['v'][i], colorbar=False, figsize=(13,8), fields=['v'],
            axes=False, xlim=(-4,9), ylim=(-4,4), density=3, lift=False,
            plot_name=util.make_filename(_bfuns, 'bfun-v-{piola}-{imported}', **kw), index=i,
        )
        solvers.plots(
            case, case.parameter(), rb_sol['p'][i], colorbar=False, figsize=(10,10), fields=['p'],
            axes=False, xlim=(-2,2), ylim=(-2,2), lift=False,
            plot_name=util.make_filename(_bfuns, 'bfun-p-{piola}-{imported}', **kw), index=i,
        )
        solvers.plots(
            case, case.parameter(), rb_sup['v'][i], colorbar=False, figsize=(10,10), fields=['v'],
            axes=False, density=2, lift=False,
            plot_name=util.make_filename(_bfuns, 'bfun-s-{piola}-{imported}', **kw), index=i,
        )
Example #2
0
def _results(fast: bool = False, piola: bool = False, block: bool = False, imported: bool = False, nred=10):
    tcase = get_case(fast=fast, piola=piola)
    tcase.ensure_shareable()

    scheme, tsol, __ = get_ensemble(piola=piola, imported=imported)
    tsol = np.array([ts/wt for ts, (__, wt) in zip(tsol, scheme)])

    # scheme = list(quadrature.full([(-25*np.pi/180, 25*np.pi/180), (2, 20)], 2))
    # ttime, tsol = ens.make_ensemble(tcase, solvers.navierstokes, scheme, parallel=True, return_time=True)

    if not piola:
        block = False

    res = []
    for nr in nred:
        rcase = get_reduced(piola=piola, imported=imported, nred=nr)
        solver = solvers.navierstokes_block if block else solvers.navierstokes
        rtime, rsol = ens.make_ensemble(rcase, solver, scheme, return_time=True)
        mu = tcase.parameter()
        verrs = ens.errors(tcase, rcase, tsol, rsol, tcase['v-h1s'](mu), scheme)
        perrs = ens.errors(tcase, rcase, tsol, rsol, tcase['p-l2'](mu), scheme)
        absf, relf = force_err(tcase, rcase, tsol, rsol, scheme)
        res.append([
            rcase.size // 3, rcase.meta['err-v'], rcase.meta['err-p'],
            *verrs, *perrs, *absf, *relf, rtime
        ])

    res = np.array(res)
    np.savetxt(
        util.make_filename(
            _results, 'airfoil-results-{piola}-{block}-{imported}.csv',
            piola=piola, block=block, imported=imported,
        ),
        res
    )
Example #3
0
def _results(num: int, nred: int):
    hcase = get_case(num)

    scheme = quadrature.uniform(hcase.ranges(), 10)
    ensemble = ens.Ensemble(scheme)
    ensemble.compute('solutions', hcase, solvers.poisson, parallel=False)

    res = []
    for nr in nred:
        rcase = get_reduced(num, nr)
        rtime = ensemble.compute('rsol',
                                 rcase,
                                 solvers.poisson,
                                 parallel=False)
        mu = hcase.parameter()
        errs = ensemble.errors(hcase, 'solutions', rcase, 'rsol',
                               hcase['u-h1s'](mu))
        res.append([rcase.size, rcase.meta['err-u'], *errs, rtime])

    np.savetxt(
        util.make_filename(
            _results,
            'poisson-results-{num}.csv',
            num=num,
            nred=nred,
        ),
        np.array(res),
    )
Example #4
0
def _divs(fast: bool = False, piola: bool = False, num=8):
    __, solutions, supremizers = get_ensemble(fast, piola, num)
    case = get_case(fast, piola)

    angles = np.linspace(-35, 35, 15) * np.pi / 180

    eig_sol = reduction.eigen(case, solutions, fields=['v', 'p'])
    rb_sol = reduction.reduced_bases(case, solutions, eig_sol, (20, 20))

    results = []
    for angle in angles:
        log.user(f'angle = {angle}')

        mu = case.parameter(angle=angle)
        geom = case.physical_geometry(mu)

        divs = []
        for i in range(10):
            vsol, = case.solution(rb_sol['v'][i], mu, ['v'], lift=True)
            div = np.sqrt(
                case.domain.integrate(vsol.div(geom)**2 * fn.J(geom),
                                      ischeme='gauss9'))
            log.user(f'{i}: {div:.2e}')
            divs.append(div)

        results.append([angle * 180 / np.pi, max(divs), np.mean(divs)])

    results = np.array(results)
    np.savetxt(
        util.make_filename(_divs, 'airfoil-divs-{piola}.csv', piola=piola),
        results)
Example #5
0
def _results(fast: bool = False,
             piola: bool = False,
             sups: bool = False,
             block: bool = False,
             nred=[10]):
    tcase = get_case(fast=fast, piola=piola)
    tcase.ensure_shareable()

    ensemble = get_ensemble(fast=fast, piola=piola, num=15)

    if not piola:
        block = False

    res = []
    for nr in nred:
        rcase = get_reduced(piola=piola, sups=sups, nred=nr)
        solver = solvers.navierstokes_block if block else solvers.navierstokes
        rtime = ensemble.compute('rsol', rcase, solver, parallel=False)
        mu = tcase.parameter()
        verrs = ensemble.errors(tcase, 'solutions', rcase, 'rsol',
                                tcase['v-h1s'](mu))
        perrs = ensemble.errors(tcase, 'solutions', rcase, 'rsol',
                                tcase['p-l2'](mu))
        res.append([
            rcase.size // 3, rcase.meta['err-v'], rcase.meta['err-p'], *verrs,
            *perrs, rtime
        ])

    # Case size, exp v, exp p,
    # mean abs v, mean rel v, max abs v, max rel v,
    # mean abs p, mean rel p, max abs p, max rel p,
    # mean time usage
    res = np.array(res)
    np.savetxt(
        util.make_filename(
            _results,
            'airfoil-results-{piola}-{sups}-{block}.csv',
            piola=piola,
            sups=sups,
            block=block,
        ), res)
Example #6
0

@util.pickle_cache('airfoil-{piola}-{imported}-{nred}.rcase')
def get_reduced(piola: bool = False, nred: int = 10, imported: bool = False, fast: bool = False):
    case = get_case(fast, piola)
    scheme, solutions, supremizers = get_ensemble(fast, piola, imported)

    eig_sol = reduction.eigen(case, solutions, fields=['v', 'p'])
    rb_sol, meta = reduction.reduced_bases(case, solutions, eig_sol, (nred, nred), meta=True)
    eig_sup = reduction.eigen(case, supremizers, fields=['v'])
    rb_sup = reduction.reduced_bases(case, supremizers, eig_sup, (nred,))

    reduction.plot_spectrum(
        [('solutions', eig_sol), ('supremizers', eig_sup)],
        plot_name=util.make_filename(
            get_reduced, 'airfoil-spectrum-{piola}-{imported}', piola=piola, imported=imported
        ),
        formats=['png', 'csv'],
    )

    projcase = reduction.make_reduced(case, rb_sol, rb_sup, meta=meta)

    if piola:
        with log.context('block project'):
            with log.context('convection'):
                projcase['convection-vvv'] = case['convection'].project(rb_sol['v'])
                projcase['convection-svv'] = case['convection'].project((rb_sup['v'], rb_sol['v'], rb_sol['v']))
            with log.context('laplacian'):
                projcase['laplacian-vv'] = case['laplacian'].project(rb_sol['v'])
                projcase['laplacian-sv'] = case['laplacian'].project((rb_sup['v'], rb_sol['v']))
            with log.context('divergence'):
Example #7
0
@util.filecache('poisson-{num}-{nred}.rcase')
def get_reduced(num: int, nred: int):
    case = get_case(num)
    ens = get_ensemble(num)

    reducer = reduction.EigenReducer(case, ens)
    reducer.add_basis('u',
                      parent='u',
                      ensemble='solutions',
                      ndofs=nred,
                      norm='h1s')

    reducer.plot_spectra(
        util.make_filename(get_reduced,
                           'poisson-spectrum-{num}',
                           num=num,
                           nred=nred))
    return reducer(tol=1e-5, nrules=4)


@main.command()
@click.option('--xcenter', '-x', default=0.5)
@click.option('--ycenter', '-y', default=0.5)
@click.option('--num', '-n', default=8)
@util.common_args
def solve(xcenter, ycenter, num):
    case = get_case(num)
    mu = case.parameter(xcenter=xcenter, ycenter=ycenter)
    with util.time():
        lhs = solvers.poisson(case, mu)
Example #8
0
                          ndofs=nred,
                          norm='h1s')
    reducer.add_basis('p',
                      parent='p',
                      ensemble='solutions',
                      ndofs=nred,
                      norm='l2')

    if sups and piola:
        reducer.override('convection', 'vvv', 'svv', soft=True)
        reducer.override('laplacian', 'vv', 'sv', soft=True)
        reducer.override('divergence', 'sp', soft=True)

    reducer.plot_spectra(
        util.make_filename(get_reduced,
                           'airfoil-spectrum-{piola}',
                           piola=piola))
    return reducer(tol=1e-6, nrules=4)


def force_err(hicase, locase, hifi, lofi, scheme):
    abs_err, rel_err = np.zeros(2), np.zeros(2)
    max_abs_err, max_rel_err = np.zeros(2), np.zeros(2)
    for hilhs, lolhs, (mu, weight) in zip(hifi, lofi, scheme):
        mu = locase.parameter(*mu)
        hiforce = hicase['force'](mu, cont=(hilhs, None))
        loforce = locase['force'](mu, cont=(lolhs, None))
        aerr = np.abs(hiforce - loforce)
        rerr = aerr / np.abs(hiforce)
        max_abs_err = np.maximum(max_abs_err, aerr)
        max_rel_err = np.maximum(max_rel_err, rerr)