ddfem 0.0.0__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,161 @@
1
+ from ufl import grad, outer
2
+
3
+ from .transformer_base import transformer_base
4
+
5
+ """
6
+ Diffusion:
7
+ Paper with sigma = grad(phi u) - grad(phi)g
8
+ phi Asigma.(grad(phi v) + grad(phi)v) + 1/4 (Agrad(phi),grad(phi))(u-g)v
9
+ = phi Asigma.(phi grad(v) + 2grad(phi)v) + 1/4 (Agrad(phi),grad(phi))(u-g)v
10
+ = phi^2 Asigma.grad(v) + 2phi Asigma.grad(phi)v + 1/4 (Agrad(phi),grad(phi))(u-g)v
11
+
12
+ orig.F_v(u,Du) = A Du
13
+ orig.S_i(u,Du) = -div(ADg)
14
+
15
+ mix0.F_v = phi^2 orig.F_v(u,sigma)
16
+ mix0.S_i = phi^2 orig.S_i(u,sigma) - 2phi orig.F_v(u,sigma).grad(phi) - 1/4 F_v(u,grad(phi)(u-g)).grad(phi)
17
+
18
+ model = mix0.F_v(u,Du).grad(v) - mix0.S_i(u,Du)v
19
+ = phi^2 Asigma.grad(v) + phi^2 div(ADg)v + 2phi Asigma.grad(phi)v + 1/4 Agrad(phi)(u-g).grad(phi)
20
+ = phi Asigma.grad(phi v) - phi Asigma.grad(phi)v + phi^2 div(ADg)v + 2phi Asigma.grad(phi)v
21
+ + 1/4 Agrad(phi).grad(phi)(u-g)
22
+ = phi Asigma.(grad(phi v) + grad(phi)v) + phi^2 div(ADg)v + 1/4 Agrad(phi).grad(phi))(u-g)
23
+
24
+ Advection:
25
+ orig.F_c = bu
26
+ orig.S_e = div(bg)
27
+
28
+ mix0.F_c(u) = phi^2 orig.F_c(u)
29
+ = phi^2 bu
30
+ mix0.S_e(u) = phi^2 orig.S_e(u) - phi orig.F_c(u+g).grad(phi)
31
+ = phi^2 div(bg) + phi (u+g) b.grad(phi)
32
+
33
+ model = - mix0.F_c(u).grad(v) - mix0.S_e(u)v
34
+ = - phi^2 u b.grad(v) - phi^2 div(bg)v - phi (u+g) b.grad(phi)v
35
+ = ( div(phi u phi b) - phi (u+g) b.grad(phi) - phi^2 div(bg) )v
36
+ = ( phi b.grad(phi u) + phi u div(phi b) - phi (u+g) b.grad(phi) - phi^2 div(bg) )v
37
+ = ( phi b.(grad(phi u)-g grad(phi))
38
+ - phi u b.grad(phi) + phi^2 u div(b) + phi u b.grad(phi)
39
+ - phi^2 b.grad(g) - phi^2 g div(b) )v
40
+ = ( phi b.(phi sigma) + phi^2 div(b)(u-g) - phi^2 b.grad(g) )v
41
+ = phi^2 ( b.(sigma - grad(g)) + div(b)(u-g) ) v
42
+
43
+ paper = phi b . sigma v
44
+ = phi b . [grad(phi u) - g.grad(phi)] v
45
+ """
46
+
47
+
48
+ def Mix0DDM(OriginalModel, domainDescription):
49
+ Model = transformer_base(OriginalModel, domainDescription)
50
+
51
+ class DDModel(Model):
52
+ def sigma(t, x, U, DU=None):
53
+ if not DU:
54
+ DU = grad(U)
55
+ sigma = DU + outer(
56
+ DDModel.BT.jumpV(t, x, U), grad(DDModel.phi(x))
57
+ ) / DDModel.phi(x)
58
+ return sigma
59
+
60
+ def S_e_source(t, x, U, DU):
61
+ return DDModel.phi(x) ** 2 * Model.S_e(t, x, U, DDModel.sigma(t, x, U, DU))
62
+
63
+ def S_e_convection(t, x, U, DU):
64
+ # unsure if using Model.F_c is the right choice here - works in the linear case.
65
+ convec = (
66
+ DDModel.phi(x)
67
+ * Model.F_c(t, x, 2 * U - DDModel.BT.jumpV(t, x, U))
68
+ * grad(DDModel.phi(x))
69
+ )
70
+
71
+ convec += DDModel.phi(x) * DDModel.BT.BndFlux_cExt(t, x, U)
72
+ return convec
73
+
74
+ if hasattr(Model, "S_e") and hasattr(Model, "F_c"):
75
+ print("Mix0DDM: S_e and F_c")
76
+
77
+ def S_e(t, x, U, DU):
78
+ return DDModel.S_e_source(t, x, U, DU) + DDModel.S_e_convection(
79
+ t, x, U, DU
80
+ )
81
+
82
+ elif hasattr(Model, "S_e"):
83
+ print("Mix0DDM: S_e")
84
+
85
+ def S_e(t, x, U, DU):
86
+ return DDModel.S_e_source(t, x, U, DU)
87
+
88
+ elif hasattr(Model, "F_c"):
89
+ print("Mix0DDM: F_c")
90
+
91
+ def S_e(t, x, U, DU):
92
+ return DDModel.S_e_convection(t, x, U, DU)
93
+
94
+ def S_i_stability(t, x, U, DU):
95
+ return -Model.stabFactor * (
96
+ DDModel.BT.jumpV(t, x, U)
97
+ * (1 - DDModel.phi(x)) ** 2
98
+ / (DDModel.epsilon**2)
99
+ )
100
+
101
+ def S_i_source(t, x, U, DU):
102
+ return DDModel.phi(x) ** 2 * Model.S_i(t, x, U, DDModel.sigma(t, x, U, DU))
103
+
104
+ def S_i_diffusion(t, x, U, DU):
105
+ Fv = Model.F_v(t, x, U, DDModel.sigma(t, x, U, DU))
106
+ diffusion = 2 * DDModel.phi(x) * Fv * grad(DDModel.phi(x))
107
+
108
+ gp = grad(DDModel.phi(x))
109
+ uogp = outer((DDModel.BT.jumpV(t, x, U)), gp)
110
+ # use of F_v is probably not correct...
111
+ diffusion += (
112
+ # Model.F_v_lin_mult(t, x, U, Mix0DDM.sigma(t,x, U, DU), uogp)
113
+ Model.F_v(t, x, U, uogp)
114
+ * gp
115
+ / 4
116
+ )
117
+
118
+ diffusion += DDModel.phi(x) * DDModel.BT.jumpFv(t, x, U, DU, Fv)
119
+ return -diffusion
120
+
121
+ if hasattr(Model, "S_i") and hasattr(Model, "F_v"):
122
+ print("Mix0DDM: S_i and F_v")
123
+
124
+ def S_i(t, x, U, DU):
125
+ return (
126
+ DDModel.S_i_stability(t, x, U, DU)
127
+ + DDModel.S_i_source(t, x, U, DU)
128
+ + DDModel.S_i_diffusion(t, x, U, DU)
129
+ )
130
+
131
+ elif hasattr(Model, "F_v"):
132
+ print("Mix0DDM: F_v")
133
+
134
+ def S_i(t, x, U, DU):
135
+ return DDModel.S_i_stability(t, x, U, DU) + DDModel.S_i_diffusion(
136
+ t, x, U, DU
137
+ )
138
+
139
+ elif hasattr(Model, "S_i"):
140
+ print("Mix0DDM: S_i")
141
+
142
+ def S_i(t, x, U, DU):
143
+ return DDModel.S_i_stability(t, x, U, DU) + DDModel.S_i_source(
144
+ t, x, U, DU
145
+ )
146
+
147
+ if hasattr(Model, "F_c"):
148
+ print("Mix0DDM: F_c")
149
+
150
+ def F_c(t, x, U):
151
+ return DDModel.phi(x) ** 2 * Model.F_c(t, x, U)
152
+
153
+ if hasattr(Model, "F_v"):
154
+ print("Mix0DDM: F_v")
155
+
156
+ def F_v(t, x, U, DU):
157
+ return DDModel.phi(x) ** 2 * Model.F_v(
158
+ t, x, U, DDModel.sigma(t, x, U, DU)
159
+ )
160
+
161
+ return DDModel
@@ -0,0 +1,143 @@
1
+ from ufl import as_vector, conditional, dot, grad, sqrt, zero
2
+
3
+ from .transformer_base import transformer_base
4
+
5
+ """
6
+ Paper: using x^- = 1/2(x-|x|), x^+ = 1/2(x+|x|) so that x = x^+ + x^-, i.e., x^+ - x = - x^-
7
+ the advection b.grad(u)v is replaced with
8
+ phi b.grad(u) v + [b.grad(phi)]^+ (u-g)v
9
+ = div(phi bu)v - div(phi b) uv + [b.grad(phi)]^+ (u-g)v
10
+ = - phi u b.grad(v) - phi div(b) uv - b.grad(phi) uv + [b.grad(phi)]^+ uv - [b.grad(phi)]^+ gv
11
+ = - phi u b.grad(v) - phi div(b) uv + ([b.grad(phi)]^+ - b.grad(phi)) uv - [b.grad(phi)]^+ gv
12
+ = - phi u b.grad(v) - phi div(b) uv - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
13
+
14
+ orig.F_c = bu
15
+ orig.S_e = div(bg)
16
+
17
+ ddm2.F_c(u) = phi orig.F_c(u)
18
+ = phi bu
19
+ ddm2.S_e(u) = phi orig.S_e(u) + [b.grad(phi)]^- u
20
+ = phi div(bg) + [b.grad(phi)]^- u + [b.grad(phi)]^+ gv
21
+
22
+ model = - ddm2.F_c(u).grad(v) - ddm2.S_e(u)v
23
+ = - phi u b.grad(v) - phi div(bg)v - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
24
+ = div(phi u b)v - phi div(b)gv - phi b.grad(g) v - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
25
+ = phi b.grad(u)v + div(phi b)uv - phi div(b)gv - phi b.grad(g) v - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
26
+ = phi b.grad(u)v + phi div(b) uv + b.grad(phi)uv - [b.grad(phi)]^- uv - phi div(b)gv - phi b.grad(g) v - [b.grad(phi)]^+ gv
27
+ = phi b.(grad(u) - grad(g)) v + phi div(b) (u-g)v + b.grad(phi)uv - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
28
+ = phi b.(grad(u) - grad(g)) v + phi div(b) (u-g)v + [b.grad(phi)]^+ (u-g)v
29
+ """
30
+
31
+
32
+ def NDDM(OriginalModel, domainDescription):
33
+ Model = transformer_base(OriginalModel, domainDescription)
34
+
35
+ class DDModel(Model):
36
+ def sigma(t, x, U, DU=None):
37
+ if DU:
38
+ return DU
39
+ return grad(U)
40
+
41
+ # self.normal = grad(self.sign_dist)
42
+ # self.projection = self.x - self.sign_dist * self.normal
43
+
44
+ def S_e_source(t, x, U, DU):
45
+ return DDModel.phi(x) * Model.S_e(t, x, U, DDModel.sigma(t, x, U, DU))
46
+
47
+ def S_e_convection(t, x, U, DU):
48
+ if DDModel.BT.BndValueExt is not None:
49
+ direction = Model.F_c_lin_mult(t, x, U, -grad(DDModel.phi(x))) # fc * n
50
+ flux_u = Model.F_c(t, x, U) * -grad(DDModel.phi(x))
51
+ flux_g = Model.F_c(t, x, DDModel.BT.BndValueExt(t, x, U)) * -grad(
52
+ DDModel.phi(x)
53
+ )
54
+ convec = []
55
+ for i in range(U.ufl_shape[0]):
56
+ convec.append(
57
+ conditional(direction[i, i] > 0, flux_u[i], flux_g[i])
58
+ )
59
+ convec = -as_vector(convec)
60
+ else:
61
+ convec = zero(U.ufl_shape)
62
+
63
+ convec += DDModel.BT.BndFlux_cExt(t, x, U)
64
+ return convec
65
+
66
+ if hasattr(Model, "S_e") and hasattr(Model, "F_c"):
67
+ print("NDDM: S_e and F_c")
68
+
69
+ def S_e(t, x, U, DU):
70
+ return DDModel.S_e_source(t, x, U, DU) + DDModel.S_e_convection(
71
+ t, x, U, DU
72
+ )
73
+
74
+ elif hasattr(Model, "S_e"):
75
+ print("NDDM: S_e")
76
+
77
+ def S_e(t, x, U, DU):
78
+ return DDModel.S_e_source(t, x, U, DU)
79
+
80
+ elif hasattr(Model, "F_c"):
81
+ print("NDDM: F_c")
82
+
83
+ def S_e(t, x, U, DU):
84
+ return DDModel.S_e_convection(t, x, U, DU)
85
+
86
+ def S_i_stability(t, x, U, DU):
87
+ return -Model.stabFactor * (
88
+ DDModel.BT.jumpV(t, x, U) * (1 - DDModel.phi(x)) / (DDModel.epsilon**2)
89
+ )
90
+
91
+ def S_i_source(t, x, U, DU):
92
+ return DDModel.phi(x) * Model.S_i(t, x, U, DDModel.sigma(t, x, U, DU))
93
+
94
+ def S_i_diffusion(t, x, U, DU):
95
+ beta = 3 * (1 - DDModel.phi(x)) * Model.stabFactor / (2 * DDModel.epsilon)
96
+ diffusion = beta * (
97
+ sqrt(dot(grad(DDModel.phi(x)), grad(DDModel.phi(x))))
98
+ * DDModel.BT.jumpV(t, x, U)
99
+ )
100
+ Fv = Model.F_v(t, x, U, DDModel.sigma(t, x, U, DU))
101
+ diffusion += Fv * grad(DDModel.phi(x))
102
+ diffusion += DDModel.BT.jumpFv(t, x, U, DU, Fv)
103
+ return -diffusion
104
+
105
+ if hasattr(Model, "S_i") and hasattr(Model, "F_v"):
106
+ print("NDDM: S_i and F_v")
107
+
108
+ def S_i(t, x, U, DU):
109
+ return (
110
+ DDModel.S_i_stability(t, x, U, DU)
111
+ + DDModel.S_i_source(t, x, U, DU)
112
+ + DDModel.S_i_diffusion(t, x, U, DU)
113
+ )
114
+
115
+ elif hasattr(Model, "F_v"):
116
+ print("NDDM: F_v")
117
+
118
+ def S_i(t, x, U, DU):
119
+ return DDModel.S_i_stability(t, x, U, DU) + DDModel.S_i_diffusion(
120
+ t, x, U, DU
121
+ )
122
+
123
+ elif hasattr(Model, "S_i"):
124
+ print("NDDM: S_i")
125
+
126
+ def S_i(t, x, U, DU):
127
+ return DDModel.S_i_stability(t, x, U, DU) + DDModel.S_i_source(
128
+ t, x, U, DU
129
+ )
130
+
131
+ if hasattr(Model, "F_c"):
132
+ print("NDDM: F_c")
133
+
134
+ def F_c(t, x, U):
135
+ return DDModel.phi(x) * Model.F_c(t, x, U)
136
+
137
+ if hasattr(Model, "F_v"):
138
+ print("NDDM: F_v")
139
+
140
+ def F_v(t, x, U, DU):
141
+ return DDModel.phi(x) * Model.F_v(t, x, U, DDModel.sigma(t, x, U, DU))
142
+
143
+ return DDModel
@@ -0,0 +1,151 @@
1
+ from ufl import as_vector, conditional, dot, grad, outer, sqrt, zero
2
+
3
+ from .transformer_base import transformer_base
4
+
5
+ """
6
+ Paper: using x^- = 1/2(x-|x|), x^+ = 1/2(x+|x|) so that x = x^+ + x^-, i.e., x^+ - x = - x^-
7
+ the advection b.grad(u)v is replaced with
8
+ phi b.grad(u) v + [b.grad(phi)]^+ (u-g)v
9
+ = div(phi bu)v - div(phi b) uv + [b.grad(phi)]^+ (u-g)v
10
+ = - phi u b.grad(v) - phi div(b) uv - b.grad(phi) uv + [b.grad(phi)]^+ uv - [b.grad(phi)]^+ gv
11
+ = - phi u b.grad(v) - phi div(b) uv + ([b.grad(phi)]^+ - b.grad(phi)) uv - [b.grad(phi)]^+ gv
12
+ = - phi u b.grad(v) - phi div(b) uv - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
13
+
14
+ orig.F_c = bu
15
+ orig.S_e = div(bg)
16
+
17
+ ddm2.F_c(u) = phi orig.F_c(u)
18
+ = phi bu
19
+ ddm2.S_e(u) = phi orig.S_e(u) + [b.grad(phi)]^- u
20
+ = phi div(bg) + [b.grad(phi)]^- u + [b.grad(phi)]^+ gv
21
+
22
+ model = - ddm2.F_c(u).grad(v) - ddm2.S_e(u)v
23
+ = - phi u b.grad(v) - phi div(bg)v - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
24
+ = div(phi u b)v - phi div(b)gv - phi b.grad(g) v - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
25
+ = phi b.grad(u)v + div(phi b)uv - phi div(b)gv - phi b.grad(g) v - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
26
+ = phi b.grad(u)v + phi div(b) uv + b.grad(phi)uv - [b.grad(phi)]^- uv - phi div(b)gv - phi b.grad(g) v - [b.grad(phi)]^+ gv
27
+ = phi b.(grad(u) - grad(g)) v + phi div(b) (u-g)v + b.grad(phi)uv - [b.grad(phi)]^- uv - [b.grad(phi)]^+ gv
28
+ = phi b.(grad(u) - grad(g)) v + phi div(b) (u-g)v + [b.grad(phi)]^+ (u-g)v
29
+ """
30
+
31
+
32
+ def NSDDM(OriginalModel, domainDescription):
33
+ Model = transformer_base(OriginalModel, domainDescription)
34
+
35
+ class DDModel(Model):
36
+ def sigma(t, x, U, DU=None):
37
+ if DU:
38
+ return DU
39
+ return grad(U)
40
+
41
+ # self.normal = grad(self.sign_dist)
42
+ # self.projection = self.x - self.sign_dist * self.normal
43
+
44
+ def S_e_source(t, x, U, DU):
45
+ return DDModel.phi(x) * Model.S_e(t, x, U, DDModel.sigma(t, x, U, DU))
46
+
47
+ def S_e_convection(t, x, U, DU):
48
+ if DDModel.BT.BndValueExt is not None:
49
+ direction = Model.F_c_lin_mult(t, x, U, -grad(DDModel.phi(x))) # fc * n
50
+ flux_u = Model.F_c(t, x, U) * -grad(DDModel.phi(x))
51
+ flux_g = Model.F_c(t, x, DDModel.BT.BndValueExt(t, x, U)) * -grad(
52
+ DDModel.phi(x)
53
+ )
54
+ convec = []
55
+ for i in range(U.ufl_shape[0]):
56
+ convec.append(
57
+ conditional(direction[i, i] > 0, flux_u[i], flux_g[i])
58
+ )
59
+ convec = -as_vector(convec)
60
+ else:
61
+ convec = zero(U.ufl_shape)
62
+
63
+ convec += DDModel.BT.BndFlux_cExt(t, x, U)
64
+ return convec
65
+
66
+ if hasattr(Model, "S_e") and hasattr(Model, "F_c"):
67
+ print("NSDDM: S_e and F_c")
68
+
69
+ def S_e(t, x, U, DU):
70
+ return DDModel.S_e_source(t, x, U, DU) + DDModel.S_e_convection(
71
+ t, x, U, DU
72
+ )
73
+
74
+ elif hasattr(Model, "S_e"):
75
+ print("NSDDM: S_e")
76
+
77
+ def S_e(t, x, U, DU):
78
+ return DDModel.S_e_source(t, x, U, DU)
79
+
80
+ elif hasattr(Model, "F_c"):
81
+ print("NSDDM: F_c")
82
+
83
+ def S_e(t, x, U, DU):
84
+ return DDModel.S_e_convection(t, x, U, DU)
85
+
86
+ def S_i_stability(t, x, U, DU):
87
+ return -DDModel.stabFactor * (
88
+ DDModel.BT.jumpV(t, x, U) * (1 - DDModel.phi(x)) / (DDModel.epsilon**2)
89
+ )
90
+
91
+ def S_i_source(t, x, U, DU):
92
+ return DDModel.phi(x) * Model.S_i(t, x, U, DDModel.sigma(t, x, U, DU))
93
+
94
+ def S_i_diffusion(t, x, U, DU):
95
+ beta = 6 * (1 - DDModel.phi(x)) * Model.stabFactor / DDModel.epsilon
96
+ diffusion = beta * (
97
+ sqrt(dot(grad(DDModel.phi(x)), grad(DDModel.phi(x))))
98
+ * DDModel.BT.jumpV(t, x, U)
99
+ )
100
+ Fv = Model.F_v(t, x, U, DDModel.sigma(t, x, U, DU))
101
+ diffusion += Fv * grad(DDModel.phi(x))
102
+ diffusion += DDModel.BT.jumpFv(t, x, U, DU, Fv)
103
+ return -diffusion
104
+
105
+ if hasattr(Model, "S_i") and hasattr(Model, "F_v"):
106
+ print("NSDDM: S_i and F_v")
107
+
108
+ def S_i(t, x, U, DU):
109
+ return (
110
+ DDModel.S_i_stability(t, x, U, DU)
111
+ + DDModel.S_i_source(t, x, U, DU)
112
+ + DDModel.S_i_diffusion(t, x, U, DU)
113
+ )
114
+
115
+ elif hasattr(Model, "F_v"):
116
+ print("NSDDM: F_v")
117
+
118
+ def S_i(t, x, U, DU):
119
+ return DDModel.S_i_stability(t, x, U, DU) + DDModel.S_i_diffusion(
120
+ t, x, U, DU
121
+ )
122
+
123
+ elif hasattr(Model, "S_i"):
124
+ print("NSDDM: S_i")
125
+
126
+ def S_i(t, x, U, DU):
127
+ return DDModel.S_i_stability(t, x, U, DU) + DDModel.S_i_source(
128
+ t, x, U, DU
129
+ )
130
+
131
+ if hasattr(Model, "F_c"):
132
+ print("NSDDM: F_c")
133
+
134
+ def F_c(t, x, U):
135
+ return DDModel.phi(x) * Model.F_c(t, x, U)
136
+
137
+ if hasattr(Model, "F_v"):
138
+ print("NSDDM: F_v")
139
+
140
+ def F_v(t, x, U, DU):
141
+ diffusion = DDModel.phi(x) * Model.F_v(
142
+ t, x, U, DDModel.sigma(t, x, U, DU)
143
+ )
144
+
145
+ out = outer(DDModel.BT.jumpV(t, x, U), grad(DDModel.phi(x)))
146
+ diffusion += Model.F_v_lin_mult(
147
+ t, x, U, DDModel.sigma(t, x, U, DU), out
148
+ )
149
+ return diffusion
150
+
151
+ return DDModel
@@ -0,0 +1,5 @@
1
+ from .DDM1 import DDM1
2
+ from .Fitted import Fitted
3
+ from .Mix0 import Mix0DDM
4
+ from .NNS import NDDM
5
+ from .NS import NSDDM
@@ -0,0 +1,126 @@
1
+ from ufl import as_matrix, diff, dot, inner, replace, variable, zero
2
+ from ufl.algorithms.ad import expand_derivatives
3
+
4
+ from ..boundary import BndFlux_c, BndFlux_v, BndValue, BoundaryTerms
5
+
6
+
7
+ def transformer_base(Model, domainDescription):
8
+ class DDBase(Model):
9
+ BT = BoundaryTerms(Model, domainDescription)
10
+ boundary = BT.physical
11
+ domain = BT.domain
12
+
13
+ if BT.BndValueExt is not None:
14
+ boundary[lambda x: DDBase.domain.omega.chi(x) < 0.5] = BndValue(
15
+ BT.BndValueExt
16
+ )
17
+ else:
18
+ hasFlux_c = hasattr(Model, "F_c")
19
+ hasFlux_v = hasattr(Model, "F_v")
20
+
21
+ if hasFlux_c:
22
+ valFc = BndFlux_c(lambda t, x, U, n: -DDBase.BT.BndFlux_cExt(t, x, U))
23
+ if hasFlux_v:
24
+ valFv = BndFlux_v(
25
+ lambda t, x, U, DU, n: DDBase.BT.BndFlux_vExt(t, x, U, DU)
26
+ )
27
+ if hasFlux_c and hasFlux_v:
28
+ valN = [valFc, valFv]
29
+ elif hasFlux_c:
30
+ valN = valFc
31
+ elif hasFlux_v:
32
+ valN = valFv
33
+ boundary[lambda x: DDBase.domain.omega.chi(x) < 0.5] = valN
34
+
35
+ phi = domain.phi
36
+ epsilon = domain.omega.epsilon
37
+ ep = domain.omega.external_projection
38
+
39
+ if hasattr(Model, "S_e"):
40
+
41
+ def S_e(t, x, U, DU):
42
+ return replace(
43
+ expand_derivatives(Model.S_e(t, x, U, DU)),
44
+ {x: DDBase.ep(x)},
45
+ )
46
+
47
+ if hasattr(Model, "S_i"):
48
+
49
+ def S_i(t, x, U, DU):
50
+ return replace(
51
+ expand_derivatives(Model.S_i(t, x, U, DU)),
52
+ {x: DDBase.ep(x)},
53
+ )
54
+
55
+ if hasattr(Model, "F_c"):
56
+
57
+ def F_c(t, x, U):
58
+ return Model.F_c(t, DDBase.ep(x), U)
59
+
60
+ return replace(
61
+ expand_derivatives(Model.F_c(t, x, U)),
62
+ {x: DDBase.ep(x)},
63
+ )
64
+
65
+ if hasattr(Model, "F_v"):
66
+
67
+ def F_v(t, x, U, DU):
68
+ return Model.F_v(t, DDBase.ep(x), U, DU)
69
+
70
+ return replace(
71
+ expand_derivatives(Model.F_v(t, x, U, DU)),
72
+ {x: DDBase.ep(x)},
73
+ )
74
+
75
+ # U_t + div[F_c(x,t,U) - F_v(x,t,U,grad[U]) ] = S(x,t,U, grad[U]).
76
+
77
+ def F_c_lin(t, x, U):
78
+ U = variable(U)
79
+ d = diff(Model.F_c(t, x, U), U)
80
+ d = expand_derivatives(d)
81
+ return d
82
+
83
+ # U.ufl_shape == (1,)
84
+ # F_c(U).ufl_shape == (1, 2,)
85
+ # diff(F_c(U), U).ufl_shape == (1, 2, 1)
86
+ # n.ufl_shape == (2,)
87
+ #
88
+ # s, t = F_c(U).ufl_shape
89
+ # f_c = as_matrix([[dot(d[i, j, :], U) for j in range(t)] for i in range(s)])
90
+ #
91
+ # w, = U.ufl_shape
92
+ # convec = as_vector([dot([f_c[w, :], n) for i in range(w)]) # f_c * n
93
+ #
94
+ # switch order
95
+
96
+ def F_c_lin_mult(t, x, U, n):
97
+ G = DDBase.F_c_lin(t, x, U)
98
+ # try:
99
+ # d = dot(G, n)
100
+ # print("F_c dot")
101
+ # return d
102
+ # except:
103
+ m, d, m_ = G.ufl_shape
104
+ return as_matrix(
105
+ [[dot(G[i, :, k], n) for k in range(m_)] for i in range(m)]
106
+ )
107
+
108
+ def F_v_lin(t, x, U, DU):
109
+ DU = variable(DU)
110
+ d = diff(Model.F_v(t, x, U, DU), DU)
111
+ d = expand_derivatives(d)
112
+ return d
113
+
114
+ def F_v_lin_mult(t, x, U, DU, v):
115
+ G = DDBase.F_v_lin(t, x, U, DU)
116
+ # try:
117
+ # d = dot(G, v)
118
+ # print("F_v dot")
119
+ # return d
120
+ # except:
121
+ m, d = v.ufl_shape
122
+ return as_matrix(
123
+ [[inner(G[i, k, :, :], v) for k in range(d)] for i in range(m)]
124
+ )
125
+
126
+ return DDBase
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: ddfem
3
+ Version: 1.0.0
4
+ Summary: Diffuse domain finite element solver
5
+ Author-email: Luke Benfield <luke.benfield@warwick.ac.uk>, Andreas Dedner <a.s.dedner@warwick.ac.uk>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://...
8
+ Project-URL: Issues, https://...
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: fenics-ufl>=2022
15
+ Dynamic: license-file
16
+
17
+ # Diffuse Domain Finite Element Methods
18
+
19
+ This is a package for solving complex PDEs based on the diffuse domain idea.
20
+
21
+ Build package by running
22
+
23
+ ```bash
24
+ python3 -m build
25
+ ```
@@ -0,0 +1,27 @@
1
+ ddfem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ddfem/base_model.py,sha256=BJGMMTy-qa3CuYVJILwcZ4mtY8cVUtzFtn9NOm87IeE,6825
3
+ ddfem/boundary.py,sha256=8PQp7LXlHxA8yn4bQbF_vLljKY4XezJbPkziX9o9IvU,7196
4
+ ddfem/dune.py,sha256=oU4bKiG4AndEhMVhAi1Nnmo9cEhjceTW3X2ptv6ombU,67
5
+ ddfem/model2ufl.py,sha256=PhbaLqJ4DS9EVKdi22f-iFxFsd97qsN-IYK0AU3a2is,4094
6
+ ddfem/geometry/__init__.py,sha256=P4mAihoy07qck7_TI-4m6NlsEM0i4wvuC_Xuo7vxHCY,293
7
+ ddfem/geometry/arc.py,sha256=r8l4zQonfgWzA37B3dVXaZ5UhHgkTXL-4KedVG0PWvk,1365
8
+ ddfem/geometry/box.py,sha256=QwtqYVDmZE9CLWRUqNsmw58WqjvBtG0WBoFruuJZWVs,925
9
+ ddfem/geometry/circle.py,sha256=prlh37BuPIYRxo1v56UAxa2-Os1YJXsNbOWGOOMkWX4,1049
10
+ ddfem/geometry/domain.py,sha256=scATAs_0qkeDuIlQ6ejl2j4GSuOZt1sL3PpT_-6aBh0,1110
11
+ ddfem/geometry/domain_dune.py,sha256=eR3MXlHAE0c9swUWAsNzPEzJyqHHtU2ZMvQDPd7JiCw,2112
12
+ ddfem/geometry/helpers.py,sha256=iykom4lPPQwnInydnUux8dhL1IL5kfOzJvpjSKDGaUw,825
13
+ ddfem/geometry/pie.py,sha256=3X2gv4AdEYCrl5Po089luULQ6TYptEJm1SVAZR1VPHI,993
14
+ ddfem/geometry/primitive_base.py,sha256=d5vedYORVKfJKFQeAULAIJFalZYn5xcZncX93hPYDlc,8041
15
+ ddfem/geometry/vesica.py,sha256=NseyI7SRxGkA_wmw503P25MD524IMhkh1ZEQgUddWFA,1702
16
+ ddfem/transformers/DDM1.py,sha256=pKj0PaB7m7kyLu_iHu0ol9_KU_tHeAatxwDutqRSdks,2854
17
+ ddfem/transformers/Fitted.py,sha256=XTE1U68RVfezC9ascdvEBYmd6F1pn8KW5mHws02Wxns,2550
18
+ ddfem/transformers/Mix0.py,sha256=DUDFt7vUvhQgMlyYSptClTYkZ1jcS2mYbZXcoCy_0zs,5530
19
+ ddfem/transformers/NNS.py,sha256=yeH-sk_p6BgjHo2rThGRoiCqNETnh6Tzc5KJEFEPuqU,5310
20
+ ddfem/transformers/NS.py,sha256=LBno0zhDWc81Lv2yMvxM7YpbWqnrsVUC-t0q39_gZ0k,5604
21
+ ddfem/transformers/__init__.py,sha256=46DtyvhBUqtrWGBfinekdz4ahjoHW4pd7sPL2vdR-Xs,120
22
+ ddfem/transformers/transformer_base.py,sha256=ho7Gz_97dA4W_7Nj6UlSQLKMaAJhdBN_mOhsD1BArRU,3888
23
+ ddfem-1.0.0.dist-info/licenses/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
24
+ ddfem-1.0.0.dist-info/METADATA,sha256=vSTe1NTH9Sleq5jIEkeDVgMVNl1TKWm2392KCsL2TnA,697
25
+ ddfem-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ ddfem-1.0.0.dist-info/top_level.txt,sha256=LF2T9-5A2Bak81PqbCcsAex8d5Xrla2Wq8yrlQi-ZtY,6
27
+ ddfem-1.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -1,5 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: ddfem
3
- Version: 0.0.0
4
- Summary: Coming soon
5
- Author-email: Luke Benfield <luke.benfield@warwick.ac.uk>, Andreas Dedner <a.s.dedner@warwick.ac.uk>
@@ -1,5 +0,0 @@
1
- ddfem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- ddfem-0.0.0.dist-info/METADATA,sha256=L2owp_gZwgOsfVmOwLKaADCMA6yiPSplXAJFHUyt6-g,171
3
- ddfem-0.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
4
- ddfem-0.0.0.dist-info/top_level.txt,sha256=LF2T9-5A2Bak81PqbCcsAex8d5Xrla2Wq8yrlQi-ZtY,6
5
- ddfem-0.0.0.dist-info/RECORD,,