1
- __author__ = ' Mikael Mortensen <[email protected] >'
2
- __date__ = ' 2014-04-04'
3
- __copyright__ = ' Copyright (C) 2014 ' + __author__
4
- __license__ = ' GNU Lesser GPL version 3 or any later version'
1
+ __author__ = " Mikael Mortensen <[email protected] >"
2
+ __date__ = " 2014-04-04"
3
+ __copyright__ = " Copyright (C) 2014 " + __author__
4
+ __license__ = " GNU Lesser GPL version 3 or any later version"
5
5
6
6
import importlib
7
7
27
27
commandline_kwargs = parse_command_line ()
28
28
29
29
# Find the problem module
30
- default_problem = 'DrivenCavity'
31
- problemname = commandline_kwargs .get ('problem' , default_problem )
32
- problemspec = importlib .util .find_spec ('.' .join (('oasismove.problems.NSCoupled' , problemname )))
30
+ default_problem = "DrivenCavity"
31
+ problemname = commandline_kwargs .get ("problem" , default_problem )
32
+ problemspec = importlib .util .find_spec (
33
+ "." .join (("oasismove.problems.NSCoupled" , problemname ))
34
+ )
33
35
if problemspec is None :
34
36
problemspec = importlib .util .find_spec (problemname )
35
37
if problemspec is None :
36
- raise RuntimeError (problemname + ' not found' )
38
+ raise RuntimeError (problemname + " not found" )
37
39
38
40
# Import the problem module
39
- print (' Importing problem module ' + problemname + ' :\n ' + problemspec .origin )
41
+ print (" Importing problem module " + problemname + " :\n " + problemspec .origin )
40
42
problemmod = importlib .util .module_from_spec (problemspec )
41
43
problemspec .loader .exec_module (problemmod )
42
44
49
51
vars ().update (post_import_problem (** vars ()))
50
52
51
53
# Import chosen functionality from solvers
52
- solver = importlib .import_module ('.' .join ((' oasismove.solvers.NSCoupled' , solver )))
54
+ solver = importlib .import_module ("." .join ((" oasismove.solvers.NSCoupled" , solver )))
53
55
vars ().update ({name : solver .__dict__ [name ] for name in solver .__all__ })
54
56
55
57
# Create lists of components solved for
56
- u_components = ['u' ]
57
- sys_comp = ['up' ] + scalar_components
58
+ u_components = ["u" ]
59
+ sys_comp = ["up" ] + scalar_components
58
60
59
61
# Get the chosen mixed elment
60
- element = commandline_kwargs .get (' element' , ' TaylorHood' )
62
+ element = commandline_kwargs .get (" element" , " TaylorHood" )
61
63
vars ().update (elements [element ])
62
64
63
65
# TaylorHood may overload degree of elements
64
- if element == ' TaylorHood' :
65
- degree ['u' ] = commandline_kwargs .get (' velocity_degree' , degree ['u' ])
66
- degree ['p' ] = commandline_kwargs .get (' pressure_degree' , degree ['p' ])
66
+ if element == " TaylorHood" :
67
+ degree ["u" ] = commandline_kwargs .get (" velocity_degree" , degree ["u" ])
68
+ degree ["p" ] = commandline_kwargs .get (" pressure_degree" , degree ["p" ])
67
69
# Should assert that degree['p'] = degree['u']-1 ??
68
70
69
71
# Declare Elements
70
- V = VectorElement (family ['u' ], mesh .ufl_cell (), degree ['u' ])
71
- Q = FiniteElement (family ['p' ], mesh .ufl_cell (), degree ['p' ])
72
+ V = VectorElement (family ["u" ], mesh .ufl_cell (), degree ["u" ])
73
+ Q = FiniteElement (family ["p" ], mesh .ufl_cell (), degree ["p" ])
72
74
73
75
# Create Mixed space
74
76
# MINI element has bubble, add to V
75
77
if bubble :
76
78
B = VectorElement ("Bubble" , mesh .ufl_cell (), mesh .geometry ().dim () + 1 )
77
- VQ = FunctionSpace (mesh , MixedElement (V + B , Q ),
78
- constrained_domain = constrained_domain )
79
+ VQ = FunctionSpace (
80
+ mesh , MixedElement (V + B , Q ), constrained_domain = constrained_domain
81
+ )
79
82
80
83
else :
81
84
VQ = FunctionSpace (mesh , V * Q , constrained_domain = constrained_domain )
86
89
v , q = TestFunctions (VQ )
87
90
88
91
# For scalars use CG space
89
- CG = FunctionSpace (mesh , 'CG' , 1 , constrained_domain = constrained_domain )
92
+ CG = FunctionSpace (mesh , "CG" , 1 , constrained_domain = constrained_domain )
90
93
c = TrialFunction (CG )
91
94
ct = TestFunction (CG )
92
95
95
98
96
99
# Create dictionaries for the solutions at two timesteps
97
100
q_ = dict ((ui , Function (VV [ui ], name = ui )) for ui in sys_comp )
98
- q_1 = dict ((ui , Function (VV [ui ], name = ui + '_1' )) for ui in sys_comp )
101
+ q_1 = dict ((ui , Function (VV [ui ], name = ui + "_1" )) for ui in sys_comp )
99
102
100
103
# Short forms
101
- up_ = q_ ['up' ] # Solution at next iteration
102
- up_1 = q_1 ['up' ] # Solution at previous iteration
104
+ up_ = q_ ["up" ] # Solution at next iteration
105
+ up_1 = q_1 ["up" ] # Solution at previous iteration
103
106
u_ , p_ = split (up_ )
104
107
u_1 , p_1 = split (up_1 )
105
108
106
109
# Create short forms for accessing the solution vectors
107
110
x_ = dict ((ui , q_ [ui ].vector ()) for ui in sys_comp ) # Solution vectors
108
- x_1 = dict ((ui , q_1 [ui ].vector ()) for ui in sys_comp ) # Solution vectors previous iteration
111
+ x_1 = dict (
112
+ (ui , q_1 [ui ].vector ()) for ui in sys_comp
113
+ ) # Solution vectors previous iteration
109
114
110
115
# Create vectors to hold rhs of equations
111
116
b = dict ((ui , Vector (x_ [ui ])) for ui in sys_comp )
@@ -154,7 +159,7 @@ def iterate(iters=max_iter):
154
159
x_1 [ui ].zero ()
155
160
x_1 [ui ].axpy (1.0 , x_ [ui ])
156
161
157
- error = b ['up' ].norm ('l2' )
162
+ error = b ["up" ].norm ("l2" )
158
163
print_velocity_pressure_info (** locals ())
159
164
160
165
iter += 1
@@ -171,25 +176,25 @@ def iterate_scalar(iters=max_iter, errors=max_error):
171
176
scalar_assemble (** globals ())
172
177
scalar_hook (** globals ())
173
178
scalar_solve (** globals ())
174
- err [ci ] = b [ci ].norm ('l2' )
179
+ err [ci ] = b [ci ].norm ("l2" )
175
180
if MPI .rank (MPI .comm_world ) == 0 :
176
- print (' Iter {}, Error {} = {}' .format (citer , ci , err [ci ]))
181
+ print (" Iter {}, Error {} = {}" .format (citer , ci , err [ci ]))
177
182
citer += 1
178
183
179
184
180
- timer = OasisTimer (' Start Newton iterations flow' , True )
185
+ timer = OasisTimer (" Start Newton iterations flow" , True )
181
186
# Assemble rhs once, before entering iterations (velocity components)
182
- b ['up' ] = assemble (Fs ['up' ], tensor = b ['up' ])
183
- for bc in bcs ['up' ]:
184
- bc .apply (b ['up' ], x_ ['up' ])
187
+ b ["up" ] = assemble (Fs ["up" ], tensor = b ["up" ])
188
+ for bc in bcs ["up" ]:
189
+ bc .apply (b ["up" ], x_ ["up" ])
185
190
186
191
iterate (max_iter )
187
192
timer .stop ()
188
193
189
194
# Assuming there is no feedback to the flow solver from the scalar field,
190
195
# we solve the scalar only after converging the flow
191
196
if len (scalar_components ) > 0 :
192
- scalar_timer = OasisTimer (' Start Newton iterations scalars' , True )
197
+ scalar_timer = OasisTimer (" Start Newton iterations scalars" , True )
193
198
# Assemble rhs once, before entering iterations (velocity components)
194
199
for scalar in scalar_components :
195
200
b [scalar ] = assemble (Fs [scalar ], tensor = b [scalar ])
@@ -200,13 +205,17 @@ def iterate_scalar(iters=max_iter, errors=max_error):
200
205
scalar_timer .stop ()
201
206
202
207
list_timings (TimingClear .keep , [TimingType .wall ])
203
- info_red (' Total computing time = {0:f}' .format (timer .elapsed ()[0 ]))
204
- oasis_memory (' Final memory use ' )
208
+ info_red (" Total computing time = {0:f}" .format (timer .elapsed ()[0 ]))
209
+ oasis_memory (" Final memory use " )
205
210
total_initial_dolfin_memory = MPI .sum (MPI .comm_world , initial_memory_use )
206
- info_red ('Memory use for importing dolfin = {} MB (RSS)' .format (
207
- total_initial_dolfin_memory ))
208
- info_red ('Total memory use of solver = ' +
209
- str (oasis_memory .memory - total_initial_dolfin_memory ) + ' MB (RSS)' )
211
+ info_red (
212
+ "Memory use for importing dolfin = {} MB (RSS)" .format (total_initial_dolfin_memory )
213
+ )
214
+ info_red (
215
+ "Total memory use of solver = "
216
+ + str (oasis_memory .memory - total_initial_dolfin_memory )
217
+ + " MB (RSS)"
218
+ )
210
219
211
220
# Final hook
212
221
theend_hook (** vars ())
0 commit comments