update FT grid test

parent f88eb646
import numpy as np
import os
from simdb.run import append_values, new_dataset
from dune.gdt.usercode import ContinuousFlatTopPartitionOfUnity
from test_grid_dependecy_of_Q1_localized_estimate import (
expected_results_fixed_H_refined_h,
expected_results_fixed_h_refined_H,
assert_results,
base_config,
compute_on_single_refinement,
expected_results_fixed_H_refined_h as expected_Q1_results_fixed_H_refined_h,
expected_results_fixed_h_refined_H as expected_Q1_results_fixed_h_refined_H,
run_fixed_H_refined_h,
run_fixed_h_refined_H,
)
FILENAME = os.path.basename(__file__)[:-3]
make_pou = lambda dd: ContinuousFlatTopPartitionOfUnity(dd, overlap=1)
pou_id = 'FtPoU1Overlap'
def run_fixed_H_refined_h_same_as_Q1( # see the bottom for suitable defaults
num_h_refs,
num_macro_elements):
return run_fixed_H_refined_h(num_h_refs, num_macro_elements,
lambda dd: ContinuousFlatTopPartitionOfUnity(dd, overlap=1), 'FtPoU1Overlap',
FILENAME + '.fixed_H_refined_h_same_as_Q1')
def test_fixed_H_refined_h_same_as_Q1():
results = run_fixed_H_refined_h((1, 2), make_pou, pou_id)
expected_results = expected_results_fixed_H_refined_h()
errors = {}
for kk, vv in expected_results.items():
if not np.allclose(results[kk], vv):
errors[kk] = {}
errors[kk]['expected'] = vv
errors[kk]['actual'] = results[kk]
assert len(errors) == 0, errors
def test_fixed_H_refined_h_same_as_Q1_single_subdomain():
kwargs = {'num_h_refs': 3, 'num_macro_elements': [1, 1]}
assert_results(run_fixed_H_refined_h_same_as_Q1(**kwargs), expected_Q1_results_fixed_H_refined_h(**kwargs))
def test_fixed_H_refined_h_same_as_Q1_truly_inner_subdomain():
kwargs = {'num_h_refs': 3, 'num_macro_elements': [3, 3]}
assert_results(run_fixed_H_refined_h_same_as_Q1(**kwargs), expected_Q1_results_fixed_H_refined_h(**kwargs))
def run_fixed_H_refined_h_with_hdependent_overlap(
num_h_refs,
num_macro_elements,
compute_overlap,
pou_id,
DATASET_ID):
config = dict(base_config)
config['num_macro_elements'] = num_macro_elements
config['num_h_refs'] = num_h_refs
config['pou_id'] = pou_id
new_dataset(DATASET_ID, **config)
results = {'num_subdomains': [], 'num_DoFs': [], 'error': [], 'estimate': []}
for num_refs in np.arange(2, 2 + num_h_refs + 1):
overlap = compute_overlap(num_refs)
make_pou = lambda dd: ContinuousFlatTopPartitionOfUnity(dd, overlap=overlap)
append_values(overlap=overlap)
cfg = dict(config)
cfg['num_refinements_per_subdomain'] = num_refs
nsd, nD, er, es = compute_on_single_refinement(cfg, make_pou, pou_id)
results['num_subdomains'].append(nsd)
results['num_DoFs'].append(nD)
results['error'].append(er)
results['estimate'].append(es)
print('')
return results
def run_fixed_H_refined_h_with_H_minus_h_overlap(
num_h_refs=3,
num_macro_elements=[3, 3]):
return run_fixed_H_refined_h_with_hdependent_overlap(
num_h_refs, num_macro_elements,
lambda num_h_refs: 1 - 1/2**num_h_refs,
'FtPoUHminus2hOverlap',
FILENAME + '.fixed_H_refined_h_with_H_minus_h_overlap')
def run_fixed_H_refined_h_with_halfH_overlap(
num_h_refs,
num_macro_elements):
return run_fixed_H_refined_h_with_hdependent_overlap(
num_h_refs, num_macro_elements,
lambda num_h_refs: 0.5,
'FtPoUhalfHOverlap',
FILENAME + '.fixed_H_refined_h_with_halfH_overlap')
def run_fixed_H_refined_h_with_h_overlap(
num_h_refs,
num_macro_elements):
return run_fixed_H_refined_h_with_hdependent_overlap(
num_h_refs, num_macro_elements,
lambda num_h_refs: 1/2**num_h_refs,
'FtPoUHminus2hOverlap',
FILENAME + '.fixed_H_refined_h_with_h_overlap')
def run_fixed_h_refined_H_same_as_Q1(
global_grid_refines,
num_H_refs_less,
initial_macro_grid):
return run_fixed_h_refined_H(global_grid_refines, num_H_refs_less, initial_macro_grid,
lambda dd: ContinuousFlatTopPartitionOfUnity(dd, overlap=1), 'FtPoU1Overlap',
FILENAME + '.fixed_h_refined_H_same_as_Q1')
def test_fixed_h_refined_H_same_as_Q1():
results = run_fixed_h_refined_H(2, make_pou, pou_id)
expected_results = expected_results_fixed_h_refined_H()
errors = {}
for kk, vv in expected_results.items():
if not np.allclose(results[kk], vv):
errors[kk] = {}
errors[kk]['expected'] = vv
errors[kk]['actual'] = results[kk]
assert len(errors) == 0, errors
kwargs = {'global_grid_refines': 3, 'num_H_refs_less': 0, 'initial_macro_grid': [1, 1]}
assert_results(run_fixed_h_refined_H_same_as_Q1(**kwargs), expected_Q1_results_fixed_h_refined_H(**kwargs))
if __name__ == '__main__':
run_fixed_H_refined_h((1, 2), make_pou, pou_id)
r = run_fixed_H_refined_h_same_as_Q1(5, [3, 3])
for kk, vv in r.items():
print(kk, vv)
print('')
print('')
r = run_fixed_h_refined_H_same_as_Q1(3, 0, [1, 1])
for kk, vv in r.items():
print(kk, vv)
print('')
print('')
r = run_fixed_H_refined_h_with_H_minus_h_overlap(3, [3, 3])
for kk, vv in r.items():
print(kk, vv)
print('')
print('')
r = run_fixed_H_refined_h_with_halfH_overlap(3, [3, 3])
for kk, vv in r.items():
print(kk, vv)
print('')
print('')
run_fixed_h_refined_H(2, make_pou, pou_id)
r = run_fixed_H_refined_h_with_h_overlap(3, [3, 3])
for kk, vv in r.items():
print(kk, vv)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment