-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyl_classes.py
71 lines (59 loc) · 2.53 KB
/
cyl_classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import festim as F
import numpy as np
import fenics as f
class AverageVolumeCylindrical(F.VolumeQuantity):
def __init__(self, field, volume: int) -> None:
super().__init__(field, volume)
self.title = "Average {} volume {}".format(self.field, self.volume)
def compute(self):
mesh = self.function.function_space().mesh() # get the mesh from the function
rthetaz = f.SpatialCoordinate(mesh) # get the coordinates from the mesh
r = rthetaz[0] # only care about r here
return f.assemble(r * self.function * self.dx(self.volume)) / f.assemble(
r * self.dx(self.volume)
)
class SurfaceFluxCylindrical(F.SurfaceFlux): # Inherets from class SurfaceFlux
def __init__(self, field, surface) -> None:
super().__init__(field, surface)
self.r = None
def compute(self, soret=False):
field_to_prop = {
"0": self.D,
"solute": self.D,
0: self.D,
"T": self.thermal_cond,
}
self.prop = field_to_prop[self.field]
if soret:
raise NotImplementedError(
"Soret effect not implemented for cylindrical coordinates"
)
if self.r is None:
mesh = (
self.function.function_space().mesh()
) # get the mesh from the function
rthetaz = f.SpatialCoordinate(mesh) # get the coordinates from the mesh
self.r = rthetaz[0] # only care about r here
# dS_z = r dr dtheta , assuming axisymmetry dS_z = theta r dr
# dS_r = r dz dtheta , assuming axisymmetry dS_r = theta r dz
# in both cases the expression with self.ds is the same
# we assume full cylinder theta = 2 pi
flux = f.assemble(
self.prop
* self.r
* f.dot(f.grad(self.function), self.n)
* self.ds(self.surface)
)
theta = 2 * np.pi
flux *= theta
return flux
class TotalVolumeCylindrical(F.VolumeQuantity):
def __init__(self, field, volume) -> None:
super().__init__(field, volume=volume)
self.title = "Total {} volume {}".format(self.field, self.volume)
def compute(self):
mesh = self.function.function_space().mesh() # get the mesh from the function
rthetaz = f.SpatialCoordinate(mesh) # get the coordinates from the mesh
r = rthetaz[0] # only care about r here
theta = 2 * np.pi # assume 2 pi rotation
return theta * f.assemble(self.function * r * self.dx(self.volume))