@@ -22,94 +22,123 @@ def correct_left(self,padded_face,ori_field,delta):
22
22
pass
23
23
24
24
class DirichletBoundary (Boundary ):
25
+ '''
26
+ DirichletBoundary is a boundary condition that the value of the field is fixed at the boundary.
27
+ '''
25
28
26
- def __init__ (self ,boundary_value ) -> None :
29
+ def __init__ (self ,boundary_value : float ) -> None :
27
30
super ().__init__ ()
28
- self .boundary_value = boundary_value
29
- self .face_calculator = DirichletFace (boundary_value )
31
+ self .boundary_face = DirichletFace (boundary_value )
30
32
31
33
def correct_top (self ,padded_face ,ori_field ,delta ):
32
- padded_face [...,0 ,:]= self .face_calculator .correct_outward_padding (ori_field [...,0 ,:])
34
+ padded_face [...,0 ,:]= self .boundary_face .correct_outward_padding (ori_field [...,0 ,:])
33
35
return padded_face
34
36
35
37
def correct_right (self ,padded_face ,ori_field ,delta ):
36
- padded_face [...,:,- 1 ]= self .face_calculator .correct_outward_padding (ori_field [...,:,- 1 ])
38
+ padded_face [...,:,- 1 ]= self .boundary_face .correct_outward_padding (ori_field [...,:,- 1 ])
37
39
return padded_face
38
40
39
41
def correct_bottom (self ,padded_face ,ori_field ,delta ):
40
- padded_face [...,- 1 ,:]= self .face_calculator .correct_inward_padding (ori_field [...,- 1 ,:])
42
+ padded_face [...,- 1 ,:]= self .boundary_face .correct_inward_padding (ori_field [...,- 1 ,:])
41
43
return padded_face
42
44
43
45
def correct_left (self ,padded_face ,ori_field ,delta ):
44
- padded_face [...,:,0 ]= self .face_calculator .correct_inward_padding (ori_field [...,:,0 ])
46
+ padded_face [...,:,0 ]= self .boundary_face .correct_inward_padding (ori_field [...,:,0 ])
45
47
return padded_face
46
48
47
49
# + :
48
50
def __add__ (self , other ):
49
51
if isinstance (other ,DirichletBoundary ):
50
52
# Dirichlet+Dirichlet=Dirichlet
51
- return DirichletBoundary (self .boundary_value + other .boundary_value )
53
+ return DirichletBoundary (self .boundary_face . face_value + other .boundary_face . face_value )
52
54
elif isinstance (other ,Boundary ):
53
55
# Dirichlet+otherboundary=uncontrainedBoundary
54
56
return UnConstrainedBoundary ()
55
57
else :
56
58
try :
57
59
# Dirichlet+number=Dirichlet
58
- return DirichletBoundary (self .boundary_value + other )
59
- except TypeError :
60
+ return DirichletBoundary (self .boundary_face . face_value + other )
61
+ except Exception :
60
62
return NotImplemented
61
63
62
64
# *
63
65
def __mul__ (self ,other ):
64
66
if isinstance (other ,DirichletBoundary ):
65
67
# Dirichlet*Dirichlet=Dirichlet
66
- return DirichletBoundary (self .boundary_value * other .boundary_value )
68
+ return DirichletBoundary (self .boundary_face . face_value * other .boundary_face . face_value )
67
69
elif isinstance (other ,Boundary ):
68
70
# Dirichlet*otherboundary=uncontrainedBoundary
69
71
return UnConstrainedBoundary ()
70
72
else :
71
73
try :
72
74
# Dirichlet*number=Dirichlet
73
- return DirichletBoundary (self .boundary_value * other )
74
- except TypeError :
75
+ return DirichletBoundary (self .boundary_face . face_value * other )
76
+ except Exception :
75
77
return NotImplemented
78
+
79
+ def __truediv__ (self , other ):
80
+ if isinstance (other ,DirichletBoundary ):
81
+ return DirichletBoundary (self .boundary_face .face_value / other .boundary_face .face_value )
82
+ elif isinstance (other ,Boundary ):
83
+ return UnConstrainedBoundary ()
84
+ else :
85
+ try :
86
+ return DirichletBoundary (self .boundary_face .face_value / other )
87
+ except Exception :
88
+ return NotImplemented
89
+
90
+ def __rtruediv__ (self , other ):
91
+ if isinstance (other ,DirichletBoundary ):
92
+ return DirichletBoundary (other .boundary_face .face_value / self .boundary_face .face_value )
93
+ elif isinstance (other ,Boundary ):
94
+ return UnConstrainedBoundary ()
95
+ else :
96
+ try :
97
+ return DirichletBoundary (other / self .boundary_face .face_value )
98
+ except Exception :
99
+ return NotImplemented
100
+
101
+ def __pow__ (self , other ):
102
+ return DirichletBoundary (self .boundary_face .face_value ** other )
76
103
77
104
class NeumannBoundary (Boundary ):
105
+ '''
106
+ NeumannBoundary is a boundary condition that the gradient of the field is fixed at the boundary.
107
+ '''
78
108
79
- def __init__ (self ,face_gradient ) -> None :
109
+ def __init__ (self ,face_gradient : float ) -> None :
80
110
super ().__init__ ()
81
- self .face_gradient = face_gradient
82
- self .face_calculator = NeumannFace (face_gradient )
111
+ self .boundary_face = NeumannFace (face_gradient )
83
112
84
113
def correct_top (self ,padded_face ,ori_field ,delta ):
85
- padded_face [...,0 ,:]= self .face_calculator .correct_outward_padding (ori_field [...,0 ,:],delta )
114
+ padded_face [...,0 ,:]= self .boundary_face .correct_outward_padding (ori_field [...,0 ,:],delta )
86
115
return padded_face
87
116
88
117
def correct_right (self ,padded_face ,ori_field ,delta ):
89
- padded_face [...,:,- 1 ]= self .face_calculator .correct_outward_padding (ori_field [...,:,- 1 ],delta )
118
+ padded_face [...,:,- 1 ]= self .boundary_face .correct_outward_padding (ori_field [...,:,- 1 ],delta )
90
119
return padded_face
91
120
92
121
def correct_bottom (self ,padded_face ,ori_field ,delta ):
93
- padded_face [...,- 1 ,:]= self .face_calculator .correct_inward_padding (ori_field [...,- 1 ,:],delta )
122
+ padded_face [...,- 1 ,:]= self .boundary_face .correct_inward_padding (ori_field [...,- 1 ,:],delta )
94
123
return padded_face
95
124
96
125
def correct_left (self ,padded_face ,ori_field ,delta ):
97
- padded_face [...,:,0 ]= self .face_calculator .correct_inward_padding (ori_field [...,:,0 ],delta )
126
+ padded_face [...,:,0 ]= self .boundary_face .correct_inward_padding (ori_field [...,:,0 ],delta )
98
127
return padded_face
99
128
100
129
# + :
101
130
def __add__ (self , other ):
102
131
if isinstance (other ,NeumannBoundary ):
103
132
# Neumann+Neumann=Dirichlet
104
- return NeumannBoundary (self .face_gradient + other .face_gradient )
133
+ return NeumannBoundary (self .boundary_face . face_gradient + other . boundary_face .face_gradient )
105
134
elif isinstance (other ,Boundary ):
106
- # Dirichlet +otherboundary=uncontrainedBoundary
135
+ # Neumann +otherboundary=uncontrainedBoundary
107
136
return UnConstrainedBoundary ()
108
137
else :
109
138
try :
110
- # Neumann+number=NeumannBoundary
111
- return NeumannBoundary (self .face_gradient )
112
- except TypeError :
139
+ # Neumann+number=Neumann
140
+ return NeumannBoundary (self .boundary_face . face_gradient )
141
+ except Exception :
113
142
return NotImplemented
114
143
115
144
# *
@@ -119,32 +148,58 @@ def __mul__(self,other):
119
148
return UnConstrainedBoundary ()
120
149
else :
121
150
try :
122
- # Neumann*number=Neumann
123
- return DirichletBoundary (self .boundary_value * other )
124
- except TypeError :
151
+ # Neumann*number=Neumann*number
152
+ return DirichletBoundary (self .boundary_face . face_value * other )
153
+ except Exception :
125
154
return NotImplemented
126
155
156
+ def __truediv__ (self , other ):
157
+ if isinstance (other ,Boundary ):
158
+ return UnConstrainedBoundary ()
159
+ else :
160
+ try :
161
+ return DirichletBoundary (self .boundary_face .face_value / other )
162
+ except Exception :
163
+ return NotImplemented
164
+
165
+ def __rtruediv__ (self , other ):
166
+ if isinstance (other ,Boundary ):
167
+ return UnConstrainedBoundary ()
168
+ else :
169
+ try :
170
+ return DirichletBoundary (other / self .boundary_face .face_value )
171
+ except Exception :
172
+ return NotImplemented
173
+
174
+ def __pow__ (self , other ):
175
+ return UnConstrainedBoundary ()
176
+
127
177
128
178
class UnConstrainedBoundary (Boundary ):
179
+ '''
180
+ UnConstrainedBoundary is a boundary condition that the value at the boundary is calculated by the value of the neighbour cells.
181
+ If you are not sure about the boundary condition, you can use UnConstrainedBoundary.
182
+ The
183
+ '''
129
184
130
185
def __init__ (self ) -> None :
131
186
super ().__init__ ()
132
- self .face_calculator = UnConstrainedFace ()
187
+ self .boundary_face = UnConstrainedFace ()
133
188
134
189
def correct_top (self ,padded_face ,ori_field ,delta ):
135
- padded_face [...,0 ,:]= self .face_calculator .correct_outward_padding (ori_field [...,0 ,:],ori_field [...,1 ,:],ori_field [...,2 ,:])
190
+ padded_face [...,0 ,:]= self .boundary_face .correct_outward_padding (ori_field [...,0 ,:],ori_field [...,1 ,:],ori_field [...,2 ,:])
136
191
return padded_face
137
192
138
193
def correct_right (self ,padded_face ,ori_field ,delta ):
139
- padded_face [...,:,- 1 ]= self .face_calculator .correct_outward_padding (ori_field [...,:,- 1 ],ori_field [...,:,- 2 ],ori_field [...,:,- 3 ])
194
+ padded_face [...,:,- 1 ]= self .boundary_face .correct_outward_padding (ori_field [...,:,- 1 ],ori_field [...,:,- 2 ],ori_field [...,:,- 3 ])
140
195
return padded_face
141
196
142
197
def correct_bottom (self ,padded_face ,ori_field ,delta ):
143
- padded_face [...,- 1 ,:]= self .face_calculator .correct_outward_padding (ori_field [...,- 1 ,:],ori_field [...,- 2 ,:],ori_field [...,- 3 ,:])
198
+ padded_face [...,- 1 ,:]= self .boundary_face .correct_outward_padding (ori_field [...,- 1 ,:],ori_field [...,- 2 ,:],ori_field [...,- 3 ,:])
144
199
return padded_face
145
200
146
201
def correct_left (self ,padded_face ,ori_field ,delta ):
147
- padded_face [...,:,0 ]= self .face_calculator .correct_outward_padding (ori_field [...,:,0 ],ori_field [...,:,1 ],ori_field [...,:,2 ])
202
+ padded_face [...,:,0 ]= self .boundary_face .correct_outward_padding (ori_field [...,:,0 ],ori_field [...,:,1 ],ori_field [...,:,2 ])
148
203
return padded_face
149
204
150
205
# + :
@@ -153,9 +208,20 @@ def __add__(self, other):
153
208
# *
154
209
def __mul__ (self ,other ):
155
210
return UnConstrainedBoundary ()
211
+
212
+ def __pow__ (self , other ):
213
+ return UnConstrainedBoundary ()
214
+
215
+ def __truediv__ (self , other ):
216
+ return UnConstrainedBoundary ()
156
217
218
+ def __rtruediv__ (self , other ):
219
+ return UnConstrainedBoundary ()
157
220
158
221
class PeriodicBoundary (Boundary ):
222
+ '''
223
+ Periodic boundary conditions.
224
+ '''
159
225
160
226
def __init__ (self ) -> None :
161
227
super ().__init__ ()
@@ -197,3 +263,18 @@ def __mul__(self,other):
197
263
return UnConstrainedBoundary ()
198
264
else :
199
265
return PeriodicBoundary ()
266
+
267
+ def __pow__ (self , other ):
268
+ return PeriodicBoundary ()
269
+
270
+ def __truediv__ (self , other ):
271
+ if isinstance (other ,PeriodicBoundary ):
272
+ return PeriodicBoundary ()
273
+ else :
274
+ return UnConstrainedBoundary ()
275
+
276
+ def __rtruediv__ (self , other ):
277
+ if isinstance (other ,PeriodicBoundary ):
278
+ return PeriodicBoundary ()
279
+ else :
280
+ return UnConstrainedBoundary ()
0 commit comments