forked from jdavid1385/pyFEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FEM_Engine.py
112 lines (96 loc) · 5.21 KB
/
FEM_Engine.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
'''
Created on 27/06/2011
@author: poissonbreaker
'''
from Model.Solver import FE_Solver
from Model.Builder import FESpace_Builder
from Model.Assembler import FEMatrix_Assembler
from Model.Boundary_Conditions import BC_Dirichlet_Handler
# ToolChain
# ____________________________________________________________________________
# | _________ ___________ ____________ ________ |
# | | | FE[] | | [A,F] | | [A*,F*] | | |
# | | Builder |------->| Assembler |------>| BC_Handler |-------->| Solver | |
# | |_________| |___________| |____________| |________| |
# |_______^_____________________________________________________________|______|
# | ENGINE |
# |Parameters | [u,MSE]
# | |
# _______|_______ _________ _______v________
# | | / \ | |
# | Configuration |================|| APP ||================| Visualization |
# |_______________| \_________/ |________________|
# |
# | [x,u]
# _______v________
# | |
# | Visualization |
# | Engine |
# |________________|
class Engine():
params = {'p_x':0,'q_x':0,'f_x':0,'a':0,'b':0, 'Nelems':0, 'Boundary':0}
FE = []
A = []; A_bc = []
F = []; F_bc = []
u = []; MSE = 0
FE_Builder = None
FE_Assembler = None
FE_BC_Handler = None
FE_Solver = None
def __init__(self):
self.FE_Builder = FESpace_Builder()
self.FE_Assembler = FEMatrix_Assembler()
self.FE_BC_Dirichlet_Handler = BC_Dirichlet_Handler()
self.FE_Solver = FE_Solver()
def RetrieveParams(self,**AppParams):
self.params['p_x'] = AppParams['p_x']
self.params['q_x'] = AppParams['q_x']
self.params['f_x'] = AppParams['f_x']
self.params['a'] = AppParams['a']
self.params['b'] = AppParams['b']
self.params['Nelems'] = AppParams['Nelems']
self.params['Boundary']= AppParams['Boundary']
def Solve(self):
#________________________________________________
# Building the FE space with the given parameters
self.FE_Builder.SetParams(**self.params)
self.FE_Builder.BuildSpace()
# Retrieve the Finite Element Space
self.FE = self.FE_Builder.retrieve_FESpace()
#________________________________________________
# |
# | FE[]
#______________________V_________________________
# Assembling the Global Stiffness Matrix and F |
#________________________________________________|
self.FE_Assembler.Assemble(self.FE)
# Retrieve A and F. The retrieved system is in general Singular
[self.A, self.F] = self.FE_Assembler.retrieve_System()
#________________________________________________
# |
# | [A,F]
#______________________V_________________________
# Applying Dirichlet Boundary Conditions |
#________________________________________________|
self.FE_BC_Dirichlet_Handler.ApplyBoundaryConditions(self.A, self.F, self.params['Boundary'])
# Retrieve the modified system
[self.A_bc, self.F_bc] = self.FE = self.FE_BC_Dirichlet_Handler.retrieve_System()
#________________________________________________
# |
# | [A*,F*]
#______________________V_________________________
# Finally the system of equations is solved for |
#____by the solver given on it parameters _______|
self.FE_Solver.solve(self.A_bc,self.F_bc,'cg')
# Finally retrieve the solution for the given system
[self.u, self.MSE] = self.FE_Solver.retrieve_U()
#________________________________________________
# |
# V
def retrieve_Solution(self):
return [self.u, self.MSE]
def restart(self):
self.FE_Assembler.restart()
self.FE_Builder.restart()
def retrieve_Grid(self):
return self.FE_Builder.retrieve_Grid()