Tue, 12 May 2026 20:44:45 -0500
README arXiv link
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | # |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | # Laser and mirrors convection-diffusion experiment with unknown diffusivity and convectivity; |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | # Includes `generic_setup` for the known case as well. |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | # |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | import numpy as np |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
7 | from dolfinx import fem |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
8 | from measures import DiscreteMeasure_2_f64 |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
9 | from numpy.linalg import norm |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
10 | from pointsource_pde import Problem, RegTerm |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
11 | from pointsource_pde.compose import ( |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
12 | ComposeFnWithOperator, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
13 | SumOfSeparableFunctions, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
14 | ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
15 | from pointsource_pde.convection_diffusion import ( |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
16 | BoxedQuadraticRegularisation, |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
17 | ConvectionDiffusion, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | PlotFactory, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
19 | XBound, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
20 | ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | from pointsource_pde.laser_sampling import LaserSampling |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
22 | from pointsource_pde.quadratic_dataterm import QuadraticDataTerm |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
23 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | # Give name to the problem |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
25 | name = "laser_and_mirrors_aux" |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | # Fine-tune algorithms |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
28 | alg_finetune = { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | "tau0": 0.99, |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
30 | "theta0": 100, |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | "inner_method": "PP", |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | "inner_pdps_τσ0": (19.8, 0.05), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | "inner_pp_τ": [1000.0, 1000.0], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | "merge": True, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | "fitness_merging": True, |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
36 | "merge_radius": 0.1, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
37 | "merge_interp": False, |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | algorithm_overrides = { |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | "RadonFB": alg_finetune, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | "RadonSlidingFB": alg_finetune, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
43 | "RadonPDPS": alg_finetune, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | "RadonSlidingPDPS": alg_finetune, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | } |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
47 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
48 | # Setup shared between experiment with known/unknown conductivity and diffusivity |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
49 | def generic_setup( |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
50 | prefix, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
51 | simple=True, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
52 | rng=None, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
53 | μ_true=DiscreteMeasure_2_f64( |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
54 | [([0.1, 0.3], 0.08), ([0.4, 0.25], 0.05), ([0.25, 0.13], 0.06)] |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
55 | ), |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
56 | k=0.01, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
57 | r=0.5, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
58 | θ=30 * np.pi / 180, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
59 | ): |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
60 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
61 | # Create convection-diffusion PDE |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
62 | pde = ConvectionDiffusion( |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
63 | u0=lambda x: 0.0 * x[1], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
64 | g=lambda x: 0.0 * x[1], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
65 | domain_size=[0, 0.5, 0, 0.5], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
66 | num_steps=50, |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
67 | # override_lipschitz=4.0, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
68 | # override_lipschitz_pair=(4.0, 40.0), |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
69 | ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
70 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
71 | # Set up lasers and mirrors |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
72 | lasers = [ |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
73 | np.array([0.1, 0.1]), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
74 | np.array([0.1, 0.4]), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
75 | np.array([0.4, 0.1]), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
76 | np.array([0.4, 0.1]), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
77 | ] |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
78 | mirrors_per_side = 10 |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
79 | x0, x1, y0, y1 = ( |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
80 | pde.domain_size[0], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
81 | pde.domain_size[1], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
82 | pde.domain_size[2], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
83 | pde.domain_size[3], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
84 | ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
85 | beams = [ |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
86 | (src, np.array(dst)) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
87 | for src in lasers |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
88 | for i in range(0, mirrors_per_side) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
89 | for z in [(i + 1) / (mirrors_per_side + 1)] |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
90 | for dst in [ |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
91 | [z * (x1 - x0) + x0, y0], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
92 | [z * (x1 - x0) + x0, y1], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
93 | [x0, z * (y1 - y0) + y0], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
94 | [x1, z * (y1 - y0) + y0], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
95 | ] |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
96 | ] |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
97 | L_i = LaserSampling(pde.V, pde.domain, pde.nx, pde.ny, beams) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
98 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
99 | v0 = 1.0 |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
100 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
101 | if simple: |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
102 | # Scalar convectivity and diffusivity |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
103 | c1 = r * np.cos(θ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
104 | c2 = r * np.sin(θ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
105 | # k = 0.001 # high wind |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
106 | print("True aux variables: k = %f, c1 = %f, c2 = %f" % (k, c1, c2)) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
107 | else: |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
108 | # Convectivity and diffusivity fields |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
109 | def velocity_x(x): |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
110 | r = np.sqrt(x[0] ** 2 + x[1] ** 2 + 1e-10) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
111 | return v0 * x[0] / r |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
112 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
113 | def velocity_y(x): |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
114 | r = np.sqrt(x[0] ** 2 + x[1] ** 2 + 1e-10) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
115 | return v0 * x[1] / r |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
116 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
117 | c1 = fem.Function(pde.V) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
118 | c1.interpolate(velocity_x) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
119 | c2 = fem.Function(pde.V) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
120 | c2.interpolate(velocity_y) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
121 | k = fem.Function(pde.V) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
122 | k0 = 1.0 |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
123 | k.interpolate(lambda x: k0 + 0.2 * np.sin(5 * x[0]) * np.cos(5 * x[1])) # k is |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
124 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
125 | auxtrue = (k, (c1, c2)) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
126 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
127 | # Simulate measurements |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
128 | u_n_list = pde.apply((μ_true, (k, (c1, c2)))) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
129 | b_true = [L_i.apply(u) for u in u_n_list] |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
130 | b = [ |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
131 | b_i + L_i.noise(0.01 * norm(b_i) / np.sqrt(np.size(b_i)), rng) for b_i in b_true |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
132 | ] |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
133 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
134 | # Estimate bounds on domains and values |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
135 | dat_bound = 2 * max([norm(b_i) for b_i in b]) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
136 | μ_bound = 1.3 * sum([alpha for _point, alpha in μ_true.iter_padded()]) |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
137 | pde.xbound = XBound(mu_dual=μ_bound, k_min=k * 0.9, k_max=k * 1.1, c_Linf=r * 0.9) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
138 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
139 | # Create data term |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
140 | dat = ComposeFnWithOperator( |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
141 | SumOfSeparableFunctions( |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
142 | [ |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
143 | QuadraticDataTerm( |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
144 | L_i, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
145 | data, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
146 | xbound=dat_bound, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
147 | b_norm=norm(b), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
148 | λ=pde.dt / len(beams), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
149 | ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
150 | for data in b |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
151 | ], |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
152 | ), |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
153 | pde, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
154 | ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
155 | |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
156 | # Save true and initial data |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
157 | plot_factory = PlotFactory(pde) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
158 | plotter = plot_factory.produce(prefix) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
159 | ω, _ = dat.diff((DiscreteMeasure_2_f64([]), auxtrue)) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
160 | ω_true, _ = dat.diff((μ_true, auxtrue)) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
161 | np.savez_compressed( |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
162 | "%s/omega_0.npz" % prefix, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
163 | true_mu=[[point[0], point[1], alpha] for point, alpha in μ_true.iter_padded()], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
164 | omega0=ω.x.array, |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
165 | true_omega=ω_true.x.array, |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
166 | k=k, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
167 | c1=c1, |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
168 | c2=c2, |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
169 | true_u_n_list_array=[u_n_list[i].x.array for i in plotter.plot_frames], |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
170 | ) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
171 | |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
172 | return dat, auxtrue, μ_bound, μ_true, plot_factory, pde |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
173 | |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
174 | |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
175 | def relnoise(v, σ, rng, level=None): |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
176 | if level is None: |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
177 | level = abs(v) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
178 | return float(rng.normal(v, σ * level)) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
179 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
180 | |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
181 | # Setup the problem |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
182 | def setup(prefix): |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
183 | rng = np.random.default_rng(seed=31337) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
184 | |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
185 | dat, auxtrue, _μ_bound, μ_true, plot_factory, pde = generic_setup(prefix, rng=rng) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
186 | |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
187 | # Override Lipschitz parameter |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
188 | pde.override_lipschitz = (4.0,) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
189 | pde.override_lipschitz_pair = (4.0, 4.0) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
190 | # print("diff_chain_lipschitz_factor (modified)", pde.diff_chain_lipschitz_factor()) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
191 | # l1, l2 = pde.diff_chain_lipschitz_factor_pair() |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
192 | # print("diff_chain_lipschitz_factor_pair (modified) ", l1, ", ", l2) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
193 | |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
194 | reg = RegTerm.NonnegRadon(1.5e-6) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
195 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
196 | μ0 = DiscreteMeasure_2_f64([]) |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
197 | (k, (c1, c2)) = auxtrue |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
198 | aux0 = ( |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
199 | max(0.001, relnoise(k, 0.02, rng)), |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
200 | ( |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
201 | relnoise(c1, 0.2, rng), |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
202 | relnoise(c2, 0.2, rng), |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
203 | ), |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
204 | ) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
205 | print("aux init ", aux0) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
206 | aux = BoxedQuadraticRegularisation((0.001, -1.0), (1.0, 1.0), (3.0, 0.0005), aux0) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
207 | ax = aux.apply(aux0) |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
208 | inival = dat.apply((μ0, aux0)) |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
209 | print("Initial data term value:", inival + ax) |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
210 | print("Data term value at true μ:", dat.apply((μ_true, auxtrue)) + ax) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
211 | |
|
3
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
212 | # No curvature bound given: θ is aboslute. |
|
c3a4f4bb87f7
Dolfin update, fixes, additional experiment, build instructions.
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
213 | dat.curvature_bound_components = lambda: (None, None) |
|
1
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
214 | |
|
a4137aedcb3a
Initial working version for known convectivity and diffusivity
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
215 | return Problem(dat, reg, aux, aux0, μ0, plot_factory=plot_factory) |