-
Notifications
You must be signed in to change notification settings - Fork 0
/
oneD.py
159 lines (106 loc) · 3.12 KB
/
oneD.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from typing import Union
import numpy as np
from typeguard import typechecked
from constants import units
class Operation(object):
def __init__(self, *operands):
self.operands = operands
def compute(self, method=None):
raise NotImplementedError
class UnaryOperation(Operation):
def __init__(self, a):
super().__init__(a)
self._a = a
@property
def a(self):
return self._a
@a.setter
def a(self, a):
self._a = a
def compute(self, method=None):
raise NotImplementedError
class BinaryOperation(Operation):
def __init__(self, a, b):
super().__init__(a, b)
self._a = a
self._b = b
@property
def a(self):
return self._a
@a.setter
def a(self, a):
self._a = a
@property
def b(self):
return self._b
@b.setter
def b(self, b):
self._b = b
def compute(self, method=None):
raise NotImplementedError
class Value(UnaryOperation):
def __init__(self, value):
super().__init__(value)
self.value = self.a
def compute(self, method=None):
return self
def __truediv__(self, other):
return Value(self.a / other)
def __rtruediv__(self, other):
return Value(other / self.a)
class Variable(Value):
def __init__(self, value):
super().__init__(value)
self.value = self.a
class Differential(Value):
def __init__(self, value: Variable):
super().__init__(value)
self.value = self.a
class Partial(BinaryOperation):
def __init__(self, of, respect: Differential):
super().__init__(of, respect)
self.of = self.a
self.respect = self.b
def compute(self, method=None):
raise NotImplementedError
class TensorField(Value):
def __init__(self, value):
super().__init__(value)
class VectorField(TensorField):
def __init__(self, value):
super().__init__(value)
class ScalarField(TensorField):
def __init__(self, value):
super().__init__(value)
class Scalar(Value):
def __init__(self, value):
super().__init__(value)
class Constant(Value):
def __init__(self, value):
super().__init__(value)
class Gradient(UnaryOperation):
@typechecked
def __init__(self, scalar: ScalarField):
super().__init__(scalar)
self.scalar = self.a
def compute(self, method=None) -> VectorField:
raise NotImplementedError
class Divergence(UnaryOperation):
@typechecked
def __init__(self, vector: VectorField):
super().__init__(vector)
self.vector = self.a
def compute(self, method=None) -> ScalarField:
raise NotImplementedError
class MaterialDerivative(BinaryOperation):
@typechecked
def __init__(self, tensor: TensorField, differential: Differential):
super().__init__(tensor, differential)
self.tensor = self.a
self.scalar = self.b
def compute(self, method=None):
raise NotImplementedError
class Equation(object):
def __init__(self, left, right):
self.left = left
self.right = right