-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprobes.py
101 lines (82 loc) · 3.38 KB
/
probes.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import numpy as np
from dolfin import *
try:
from iufl import icompile
from ufl.corealg.traversal import traverse_unique_terminals
from iufl.operators import eigw
except ImportError:
print('iUFL can be obtained from https://github.com/MiroK/ufl-interpreter')
class DragProbe(object):
'''Integral proble of drag over the tagged mesh oriented exterior surface n.ds'''
def __init__(self, mu, n, ds, tags, flow_dir=Constant((1, 0))):
self.dim = flow_dir.ufl_shape[0]
self.mu = mu
self.n = n
self.ds = ds
self.tags = tags
self.flow_dir = flow_dir
def sample(self, u, p):
'''Eval drag given the flow state'''
# Stress
sigma = 2*Constant(self.mu)*sym(grad(u)) - p*Identity(self.dim)
# The drag form
form = sum(dot(dot(sigma, self.n), self.flow_dir)*self.ds(i) for i in self.tags)
return assemble(form)
class LiftProbe(object):
'''Integral proble of lift over the tagged mesh oriented exterior surface n.ds'''
def __init__(self, mu, n, ds, tags, flow_dir=Constant((0, 1))):
self.dim = flow_dir.ufl_shape[0]
self.mu = mu
self.n = n
self.ds = ds
self.tags = tags
self.flow_dir = flow_dir
def sample(self, u, p):
'''Eval drag given the flow state'''
# Stress
sigma = 2*Constant(self.mu)*sym(grad(u)) - p*Identity(self.dim)
# The drag form
form = sum(dot(dot(sigma, self.n), self.flow_dir)*self.ds(i) for i in self.tags)
return assemble(form)
class DragProbeANN(DragProbe):
'''Drag on the cylinder'''
def __init__(self, flow, flow_dir=Constant((1, 0))):
DragProbe.__init__(self,
mu=flow.viscosity,
n=flow.normal,
ds=flow.ext_surface_measure,
tags=flow.cylinder_surface_tags,
flow_dir=flow_dir)
class PenetratedDragProbe(object):
'''Drag on a penetrated surface
https://physics.stackexchange.com/questions/21404/strict-general-mathematical-definition-of-drag
'''
def __init__(self, rho, mu, n, ds, tags, flow_dir=Constant((1, 0))):
self.dim = flow_dir.ufl_shape[0]
self.mu = mu
self.rho = rho
self.n = n
self.ds = ds
self.tags = tags
self.flow_dir = flow_dir
def sample(self, u, p):
'''Eval drag given the flow state'''
mu, rho, n = self.mu, self.rho, self.n
# Stress
sigma = 2*Constant(mu)*sym(grad(u)) - p*Identity(self.dim)
# The drag form
form = sum(dot(-rho*dot(outer(u, u), n) + dot(sigma, n), self.flow_dir)*self.ds(i)
for i in self.tags)
return assemble(form)
class PenetratedDragProbeANN(PenetratedDragProbe):
'''Drag on a penetrated surface
https://physics.stackexchange.com/questions/21404/strict-general-mathematical-definition-of-drag
'''
def __init__(self, flow, flow_dir=Constant((1, 0))):
PenetratedDragProbe.__init__(self,
rho=flow.density,
mu=flow.viscosity,
n=flow.normal,
ds=flow.ext_surface_measure,
tags=flow.cylinder_surface_tags,
flow_dir=flow_dir)