-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDEs.py
72 lines (58 loc) · 1.87 KB
/
PDEs.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
import numpy as np
class Pde:
def __init__(self,dim,range,solution):
self.dimension = dim
self.range = range
self.equation = solution
self.IC = None
self.BC = None
'''
dim: int
IC: array
BC: array
range: array
'''
def set_initial_condition(self,initial_condition):
self.IC = initial_condition
def set_boundary_condition(self,boundary_condition):
self.BC = boundary_condition
def boundary_condition(self):
if self.BC is not None:
return self.BC
else:
raise Exception('You should set boundary condition first')
def initial_condition(self):
if self.IC is not None:
return self.IC
else:
raise Exception('You should set initial condition first')
def solution(self,points):
if len(points) != self.dimension:
Exception('dimension does not match')
else:
return self.equation(points)
def solutions(self,points):
if type(points[0]) is int or type(points[0]) is float:
return self.solution(points)
else:
result = list()
for i in points:
result.append(self.solution(i))
return np.array(result)
class transport_eq(Pde):
def __init__(self,c,RHS):
self.c = c
self.auxiliary_condition = RHS
def solution(self,points):
if len(points) != self.dimension:
Exception('dimension does not match')
else:
return self.equation(points)
def solutions(self,points):
if type(points[0]) is int or type(points[0]) is float:
return self.solution(points)
else:
result = list()
for i in points:
result.append(self.solution(i))
return np.array(result)