|
6 | 6 |
|
7 | 7 | # instantiate deal.II model |
8 | 8 | from dealii_elasticity import ElasticityExample |
| 9 | + |
9 | 10 | cpp_disc = ElasticityExample(refine_steps=7) |
10 | 11 |
|
11 | 12 |
|
|
17 | 18 |
|
18 | 19 | def run(plot_error=True): |
19 | 20 | d = StationaryModel( |
20 | | - operator=LincombOperator([DealIIMatrixOperator(cpp_disc.lambda_mat()), DealIIMatrixOperator(cpp_disc.mu_mat())], |
21 | | - [ProjectionParameterFunctional('lambda'), ProjectionParameterFunctional('mu')]), |
22 | | - |
| 21 | + operator=LincombOperator( |
| 22 | + [ |
| 23 | + DealIIMatrixOperator(cpp_disc.lambda_mat()), |
| 24 | + DealIIMatrixOperator(cpp_disc.mu_mat()), |
| 25 | + ], |
| 26 | + [ |
| 27 | + ProjectionParameterFunctional("lambda"), |
| 28 | + ProjectionParameterFunctional("mu"), |
| 29 | + ], |
| 30 | + ), |
23 | 31 | rhs=VectorOperator(DealIIVectorSpace.make_array([cpp_disc.rhs()])), |
24 | | - |
25 | | - products={'energy': DealIIMatrixOperator(cpp_disc.mu_mat())}, |
26 | | - |
27 | | - visualizer=DealIIVisualizer(cpp_disc) |
| 32 | + products={"energy": DealIIMatrixOperator(cpp_disc.mu_mat())}, |
| 33 | + visualizer=DealIIVisualizer(cpp_disc), |
28 | 34 | ) |
29 | | - parameter_space = d.parameters.space((1,10)) |
30 | | - |
| 35 | + parameter_space = d.parameters.space((1, 10)) |
31 | 36 |
|
32 | 37 | # choose reduction method |
33 | 38 | reductor = CoerciveRBReductor( |
34 | 39 | d, |
35 | 40 | product=d.energy_product, |
36 | | - coercivity_estimator=ExpressionParameterFunctional("max(mu)", d.parameters) |
| 41 | + coercivity_estimator=ExpressionParameterFunctional("max(mu)", d.parameters), |
37 | 42 | ) |
38 | 43 |
|
39 | | - |
40 | 44 | # greedy basis generation |
41 | | - greedy_data = rb_greedy(d, reductor, parameter_space.sample_uniformly(3), |
42 | | - extension_params={'method': 'gram_schmidt'}, max_extensions=5) |
43 | | - |
| 45 | + greedy_data = rb_greedy( |
| 46 | + d, |
| 47 | + reductor, |
| 48 | + parameter_space.sample_uniformly(3), |
| 49 | + extension_params={"method": "gram_schmidt"}, |
| 50 | + max_extensions=5, |
| 51 | + ) |
44 | 52 |
|
45 | 53 | # get reduced order model |
46 | | - rd = greedy_data['rom'] |
47 | | - |
| 54 | + rd = greedy_data["rom"] |
48 | 55 |
|
49 | 56 | # validate reduced order model |
50 | | - result = reduction_error_analysis(rd, d, reductor, |
51 | | - test_mus=parameter_space.sample_randomly(10), |
52 | | - basis_sizes=reductor.bases['RB'].dim + 1, |
53 | | - condition=True, error_norms=[d.energy_norm], |
54 | | - plot=plot_error) |
55 | | - |
| 57 | + result = reduction_error_analysis( |
| 58 | + rd, |
| 59 | + d, |
| 60 | + reductor, |
| 61 | + test_mus=parameter_space.sample_randomly(10), |
| 62 | + basis_sizes=reductor.bases["RB"].dim + 1, |
| 63 | + condition=True, |
| 64 | + error_norms=[d.energy_norm], |
| 65 | + plot=plot_error, |
| 66 | + ) |
56 | 67 |
|
57 | 68 | # visualize solution for parameter with maximum reduction error |
58 | | - mu_max = result['max_error_mus'][0, -1] |
| 69 | + mu_max = result["max_error_mus"][0, -1] |
59 | 70 | U = d.solve(mu_max) |
60 | 71 | U_rb = reductor.reconstruct(rd.solve(mu_max)) |
61 | 72 | return result, U, U_rb, d |
62 | 73 |
|
63 | 74 |
|
64 | | -if __name__ == '__main__': |
| 75 | +if __name__ == "__main__": |
65 | 76 | # print/plot results of validation |
66 | 77 | from matplotlib import pyplot as plt |
| 78 | + |
67 | 79 | result, U, U_rb, d = run() |
68 | | - print(result['summary']) |
| 80 | + print(result["summary"]) |
69 | 81 | ERR = U - U_rb |
70 | | - d.visualize([U, U_rb, ERR], legend=['fom', 'rom', 'error']) |
| 82 | + d.visualize([U, U_rb, ERR], legend=["fom", "rom", "error"]) |
71 | 83 | plt.show() |
0 commit comments