allow to compute C_pu,1 estimate in PoU grid tests

parent 167773f6
......@@ -12,16 +12,26 @@ from test_grid_dependecy_of_Q1_localized_estimate import (
expected_results_fixed_h_refined_H as expected_Q1_results_fixed_h_refined_H,
run_fixed_H_refined_h,
run_fixed_h_refined_H,
Q1_cpu1_estimate,
)
FILENAME = os.path.basename(__file__)[:-3]
H_minus_2h_overlap = lambda num_h_refs: 1 - 2/2**num_h_refs
H_minus_2h_C_pu1_estimate = lambda H, h: 1 + H/(H - 2*h)
halfH_overlap = lambda num_h_refs: 0.5
halfH_C_pu1_estimate = lambda H, h: 3
twoh_overlap = lambda num_h_refs: 2/2**num_h_refs
twoh_C_pu1_estimate = lambda H, h: 1 + H/(2*h)
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',
lambda dd: ContinuousFlatTopPartitionOfUnity(dd, overlap=1), 'FtPoU1Overlap', Q1_cpu1_estimate,
FILENAME + '.fixed_H_refined_h_same_as_Q1')
def test_fixed_H_refined_h_same_as_Q1_single_subdomain():
......@@ -33,11 +43,12 @@ def test_fixed_H_refined_h_same_as_Q1_truly_inner_subdomain():
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(
def run_fixed_H_refined_h_with_hdependent_overlap( # see the bottom for suitable defaults
num_h_refs,
num_macro_elements,
compute_overlap,
pou_id,
C_pu1_estimate,
DATASET_ID):
config = dict(base_config)
config['num_macro_elements'] = num_macro_elements
......@@ -52,7 +63,7 @@ def run_fixed_H_refined_h_with_hdependent_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)
nsd, nD, er, es = compute_on_single_refinement(cfg, make_pou, pou_id, C_pu1_estimate)
results['num_subdomains'].append(nsd)
results['num_DoFs'].append(nD)
results['error'].append(er)
......@@ -62,42 +73,46 @@ def run_fixed_H_refined_h_with_hdependent_overlap(
return results
def run_fixed_H_refined_h_with_H_minus_h_overlap(
num_h_refs=3,
num_macro_elements=[3, 3]):
def run_fixed_H_refined_h_with_H_minus_2h_overlap( # see the bottom for suitable defaults
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 - 1/2**num_h_refs,
H_minus_2h_overlap,
'FtPoUHminus2hOverlap',
FILENAME + '.fixed_H_refined_h_with_H_minus_h_overlap')
H_minus_2h_C_pu1_estimate,
FILENAME + '.fixed_H_refined_h_with_H_minus_2h_overlap')
def run_fixed_H_refined_h_with_halfH_overlap(
def run_fixed_H_refined_h_with_halfH_overlap( # see the bottom for suitable defaults
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,
halfH_overlap,
'FtPoUhalfHOverlap',
halfH_C_pu1_estimate,
FILENAME + '.fixed_H_refined_h_with_halfH_overlap')
def run_fixed_H_refined_h_with_h_overlap(
def run_fixed_H_refined_h_with_2h_overlap( # see the bottom for suitable defaults
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,
twoh_overlap,
'FtPoUHminus2hOverlap',
FILENAME + '.fixed_H_refined_h_with_h_overlap')
twoh_C_pu1_estimate,
FILENAME + '.fixed_H_refined_h_with_2h_overlap')
def run_fixed_h_refined_H_same_as_Q1(
def run_fixed_h_refined_H_same_as_Q1( # see the bottom for suitable defaults
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',
Q1_cpu1_estimate,
FILENAME + '.fixed_h_refined_H_same_as_Q1')
def test_fixed_h_refined_H_same_as_Q1():
......@@ -117,7 +132,7 @@ if __name__ == '__main__':
print(kk, vv)
print('')
print('')
r = run_fixed_H_refined_h_with_H_minus_h_overlap(3, [3, 3])
r = run_fixed_H_refined_h_with_H_minus_2h_overlap(3, [3, 3])
for kk, vv in r.items():
print(kk, vv)
print('')
......@@ -127,7 +142,7 @@ if __name__ == '__main__':
print(kk, vv)
print('')
print('')
r = run_fixed_H_refined_h_with_h_overlap(3, [3, 3])
r = run_fixed_H_refined_h_with_2h_overlap(3, [3, 3])
for kk, vv in r.items():
print(kk, vv)
......@@ -41,6 +41,8 @@ make_Q1_pou = lambda dd: ContinuousLagrangePartitionOfUnity(dd)
Q1_pou_id = 'Q1PoU'
Q1_cpu1_estimate = lambda H, h: 2
def assert_results(results, expected_results):
errors = {}
......@@ -52,7 +54,7 @@ def assert_results(results, expected_results):
assert len(errors) == 0, errors
def compute_on_single_refinement(cfg, make_pou, pou_id):
def compute_on_single_refinement(cfg, make_pou, pou_id, C_pu1_estimate):
logger = getLogger(f'{FILENAME}.compute_on_single_refinement')
def init_dd():
return DomainDecomposition(cfg['num_macro_elements'],
......@@ -60,12 +62,14 @@ def compute_on_single_refinement(cfg, make_pou, pou_id):
domain[0],
domain[1])
dd = init_dd()
H = dd.max_subdomain_diameter()
h = np.max([dd.max_element_diameter(ss) for ss in np.arange(dd.num_subdomains)])
p = make_problem()
num_subdomains = dd.num_subdomains
fom = discretize_elliptic_block_swipdg(make_problem, init_dd, cfg['local_space_type'])
fom.globalize() # We need this later on, only here to trigger the output
num_DoFs = fom.solution_space.dim
append_values(num_DoFs=num_DoFs)
append_values(num_DoFs=num_DoFs, H=H, h=h, C_pu1_estimate=C_pu1_estimate(H, h))
logger.info('reducing with initial basis (PoU) ...')
reductor = Reductor(
fom, init_dd, cfg, make_pou=make_pou, kappa_lower=init_problem()['kappa_lower'], pou_id=pou_id)
......@@ -96,6 +100,7 @@ def run_fixed_H_refined_h( # see the bottom for suitable defaults
num_macro_elements,
make_pou,
pou_id,
C_pu1_estimate,
DATASET_ID=FILENAME + '.fixed_H_refined_h'):
config = dict(base_config)
config['num_macro_elements'] = num_macro_elements
......@@ -106,7 +111,7 @@ def run_fixed_H_refined_h( # see the bottom for suitable defaults
for num_refs in np.arange(num_h_refs + 1):
cfg = dict(config)
cfg['num_refinements_per_subdomain'] = num_refs
nsd, nD, er, es = compute_on_single_refinement(cfg, make_pou, pou_id)
nsd, nD, er, es = compute_on_single_refinement(cfg, make_pou, pou_id, C_pu1_estimate)
results['num_subdomains'].append(nsd)
results['num_DoFs'].append(nD)
results['error'].append(er)
......@@ -122,6 +127,7 @@ def run_fixed_h_refined_H( # see the bottom for suitable defaults
initial_macro_grid,
make_pou,
pou_id,
C_pu1_estimate,
DATASET_ID=FILENAME + '.fixed_h_refined_H'):
config = dict(base_config)
macro_grid = list(initial_macro_grid)
......@@ -134,7 +140,7 @@ def run_fixed_h_refined_H( # see the bottom for suitable defaults
cfg = dict(config)
cfg['num_macro_elements'] = macro_grid
cfg['num_refinements_per_subdomain'] = global_grid_refines
nsd, nD, er, es = compute_on_single_refinement(cfg, make_pou, pou_id)
nsd, nD, er, es = compute_on_single_refinement(cfg, make_pou, pou_id, C_pu1_estimate)
results['num_subdomains'].append(nsd)
results['num_DoFs'].append(nD)
results['error'].append(er)
......@@ -174,17 +180,20 @@ num_H_refs_less={num_H_refs_less}, initial_macro_grid={initial_macro_grid}"""
def test_fixed_H_refined_h_single_subdomain():
kwargs = {'num_h_refs': 3, 'num_macro_elements': [1, 1], 'make_pou': make_Q1_pou, 'pou_id': Q1_pou_id}
kwargs = {'num_h_refs': 3, 'num_macro_elements': [1, 1], 'make_pou': make_Q1_pou, 'pou_id': Q1_pou_id,
'C_pu1_estimate': Q1_cpu1_estimate}
assert_results(run_fixed_H_refined_h(**kwargs), expected_results_fixed_H_refined_h(**kwargs))
def test_fixed_H_refined_h_truly_inner_subdomain():
kwargs = {'num_h_refs': 3, 'num_macro_elements': [3, 3], 'make_pou': make_Q1_pou, 'pou_id': Q1_pou_id}
kwargs = {'num_h_refs': 3, 'num_macro_elements': [3, 3], 'make_pou': make_Q1_pou, 'pou_id': Q1_pou_id,
'C_pu1_estimate': Q1_cpu1_estimate}
assert_results(run_fixed_H_refined_h(**kwargs), expected_results_fixed_H_refined_h(**kwargs))
def test_fixed_h_refined_H():
kwargs = {'global_grid_refines': 3, 'num_H_refs_less': 0, 'initial_macro_grid': [1, 1], 'make_pou': make_Q1_pou, 'pou_id': Q1_pou_id}
kwargs = {'global_grid_refines': 3, 'num_H_refs_less': 0, 'initial_macro_grid': [1, 1], 'make_pou': make_Q1_pou,
'pou_id': Q1_pou_id, 'C_pu1_estimate': Q1_cpu1_estimate}
assert_results(run_fixed_h_refined_H(**kwargs), expected_results_fixed_h_refined_H(**kwargs))
......@@ -194,6 +203,7 @@ def run_fixed_h_refined_H_with_fine_PoU_in_basis( # see the bottom for suitable
initial_macro_grid,
make_pou,
pou_id,
C_pu1_estimate,
DATASET_ID=FILENAME + '.fixed_h_refined_H_with_fine_PoU_in_basis'):
config = dict(base_config)
config['local_space_type'] = 'dg_p1'
......@@ -219,12 +229,14 @@ def run_fixed_h_refined_H_with_fine_PoU_in_basis( # see the bottom for suitable
domain[0],
domain[1])
dd = init_dd()
H = dd.max_subdomain_diameter()
h = np.max([dd.max_element_diameter(ss) for ss in np.arange(dd.num_subdomains)])
p = make_problem()
num_subdomains = dd.num_subdomains
fom = discretize_elliptic_block_swipdg(make_problem, init_dd, cfg['local_space_type'])
fom.globalize() # We need this later on, only here to trigger the output
num_DoFs = fom.solution_space.dim
append_values(num_DoFs=num_DoFs)
append_values(num_DoFs=num_DoFs, H=H, h=h, C_pu1_estimate=C_pu1_estimate(H, h))
logger.info('reducing with coarse and fine PoU ...')
reductor = Reductor(
fom, init_dd, cfg, make_pou=make_pou, kappa_lower=init_problem()['kappa_lower'], pou_id=pou_id)
......@@ -283,24 +295,25 @@ def expected_results_fixed_h_refined_H_with_fine_PoU_in_basis(global_grid_refine
def test_fixed_h_refined_H_with_fine_PoU_in_basis():
kwargs = {'global_grid_refines': 3, 'num_H_refs_less': 1, 'initial_macro_grid': [1, 1], 'make_pou': make_Q1_pou, 'pou_id': Q1_pou_id}
kwargs = {'global_grid_refines': 3, 'num_H_refs_less': 1, 'initial_macro_grid': [1, 1], 'make_pou': make_Q1_pou,
'pou_id': Q1_pou_id, 'C_pu1_estimate': Q1_cpu1_estimate}
assert_results(run_fixed_h_refined_H_with_fine_PoU_in_basis(**kwargs),
expected_results_fixed_h_refined_H_with_fine_PoU_in_basis(**kwargs))
if __name__ == '__main__':
r = run_fixed_H_refined_h(3, [3, 3], make_Q1_pou, Q1_pou_id)
r = run_fixed_H_refined_h(3, [3, 3], make_Q1_pou, Q1_pou_id, Q1_cpu1_estimate)
for kk, vv in r.items():
print(kk, vv)
print('')
print('')
r = run_fixed_h_refined_H(3, 0, [1, 1], make_Q1_pou, Q1_pou_id)
r = run_fixed_h_refined_H(3, 0, [1, 1], make_Q1_pou, Q1_pou_id, Q1_cpu1_estimate)
for kk, vv in r.items():
print(kk, vv)
print('')
print('')
r = run_fixed_h_refined_H_with_fine_PoU_in_basis(3, 0, [1, 1], make_Q1_pou, Q1_pou_id)
r = run_fixed_h_refined_H_with_fine_PoU_in_basis(3, 0, [1, 1], make_Q1_pou, Q1_pou_id, Q1_cpu1_estimate)
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