COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-ufem-les-wale.py
Go to the documentation of this file.
1 import coolfluid as cf
2 from math import pi
3 import numpy as np
4 
5 # Flow properties
6 h = 1.
7 nu = 0.0001
8 re_tau = 180.
9 u_tau = re_tau * nu / h
10 a_tau = re_tau**2*nu**2/h**3
11 Uc = a_tau/nu*(h**2/2.)
12 u_ref = 0.5*Uc
13 
14 # Some shortcuts
15 root = cf.Core.root()
16 env = cf.Core.environment()
17 
18 # Global configuration
19 env.assertion_throws = False
20 env.assertion_backtrace = False
21 env.exception_backtrace = False
22 env.regist_signal_handlers = False
23 env.log_level = 4
24 env.only_cpu0_writes = True
25 
26 # setup a model
27 model = root.create_component('NavierStokes', 'cf3.solver.ModelUnsteady')
28 domain = model.create_domain()
29 physics = model.create_physics('cf3.UFEM.NavierStokesPhysics')
30 solver = model.create_solver('cf3.UFEM.Solver')
31 
32 # Add the turbulence model
33 wale = ns_solver = solver.add_unsteady_solver('cf3.UFEM.les.WALE')
34 
35 # Add the Navier-Stokes solver as an unsteady solver
36 ns_solver = solver.add_unsteady_solver('cf3.UFEM.NavierStokesSemiImplicit')
37 ns_solver.options.theta = 0.5
38 ns_solver.options.nb_iterations = 1
39 ns_solver.enable_body_force = True
40 ns_solver.options.pressure_rcg_solve = True
41 ns_solver.VelocityLSS.Assembly.interval = 100
42 
43 tstep = 0.025
44 
45 y_segs = 32
46 
47 x_size = 4.*pi*h
48 z_size = 4./3.*pi*h
49 
50 x_segs = 32
51 z_segs = 32
52 
53 ungraded_h = h#float(y_segs)
54 
55 # Generate mesh
56 blocks = domain.create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
57 points = blocks.create_points(dimensions = 2, nb_points = 6)
58 points[0] = [0, 0.]
59 points[1] = [x_size, 0.]
60 points[2] = [0., ungraded_h]
61 points[3] = [x_size, ungraded_h]
62 points[4] = [0.,2.*ungraded_h]
63 points[5] = [x_size, 2.*ungraded_h]
64 
65 block_nodes = blocks.create_blocks(2)
66 block_nodes[0] = [0, 1, 3, 2]
67 block_nodes[1] = [2, 3, 5, 4]
68 
69 block_subdivs = blocks.create_block_subdivisions()
70 block_subdivs[0] = [x_segs, y_segs]
71 block_subdivs[1] = block_subdivs[0]
72 
73 gradings = blocks.create_block_gradings()
74 gradings[0] = [1., 1., 20., 20.]
75 gradings[1] = [1., 1., 1./20., 1./20.]
76 
77 left_patch = blocks.create_patch_nb_faces(name = 'left', nb_faces = 2)
78 left_patch[0] = [2, 0]
79 left_patch[1] = [4, 2]
80 
81 bottom_patch = blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)
82 bottom_patch[0] = [0, 1]
83 
84 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)
85 top_patch[0] = [5, 4]
86 
87 right_patch = blocks.create_patch_nb_faces(name = 'right', nb_faces = 2)
88 right_patch[0] = [1, 3]
89 right_patch[1] = [3, 5]
90 
91 blocks.extrude_blocks(positions=[z_size], nb_segments=[z_segs], gradings=[1.])
92 
93 nb_procs = cf.Core.nb_procs()
94 
95 blocks.partition_blocks(nb_partitions = 2, direction = 0)
96 blocks.partition_blocks(nb_partitions = 2, direction = 2)
97 # blocks.partition_blocks(nb_partitions = 2, direction = 2)
98 
99 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
100 blocks.create_mesh(mesh.uri())
101 
102 # coordmap = {}
103 # b = 0.955
104 # xi = np.linspace(-h, h, y_segs*2+1)
105 # y_graded = h/b * np.tanh(xi*np.arctanh(b))
106 #
107 # for i in range(len(mesh.geometry.coordinates)):
108 # if i % 100 == 0:
109 # y_key = int(mesh.geometry.coordinates[i][1])
110 # mesh.geometry.coordinates[i][1] = y_graded[y_key]
111 
112 create_point_region = domain.create_component('CreatePointRegion', 'cf3.mesh.actions.AddPointRegion')
113 create_point_region.coordinates = [x_size/2., h, z_size/2.]
114 create_point_region.region_name = 'center'
115 create_point_region.mesh = mesh
116 create_point_region.execute()
117 
118 partitioner = domain.create_component('Partitioner', 'cf3.mesh.actions.PeriodicMeshPartitioner')
119 partitioner.load_balance = False
120 partitioner.mesh = mesh
121 
122 link_horizontal = partitioner.create_link_periodic_nodes()
123 link_horizontal.source_region = mesh.topology.right
124 link_horizontal.destination_region = mesh.topology.left
125 link_horizontal.translation_vector = [-x_size, 0., 0.]
126 
127 link_spanwise = partitioner.create_link_periodic_nodes()
128 link_spanwise.source_region = mesh.topology.back
129 link_spanwise.destination_region = mesh.topology.front
130 link_spanwise.translation_vector = [0., 0., -z_size]
131 
132 partitioner.execute()
133 
134 #domain.write_mesh(cf.URI('chan180-init.cf3mesh'))
135 
136 # Physical constants
137 physics.density = 1.
138 physics.dynamic_viscosity = nu
139 
140 wale.regions = [mesh.topology.uri()]
141 ns_solver.regions = [mesh.topology.uri()]
142 
143 #lss = ns_solver.PressureLSS.LSS
144 #lss.SolutionStrategy.solver_type = 'Amesos_Mumps'
145 
146 for strat in [ns_solver.children.FirstPressureStrategy, ns_solver.children.SecondPressureStrategy]:
147  strat.MLParameters.aggregation_type = 'Uncoupled'
148  strat.MLParameters.max_levels = 4
149  strat.MLParameters.smoother_sweeps = 3
150  strat.MLParameters.coarse_type = 'Amesos-KLU'
151  strat.MLParameters.add_parameter(name = 'repartition: start level', value = 0)
152  strat.MLParameters.add_parameter(name = 'repartition: max min ratio', value = 1.1)
153  strat.MLParameters.add_parameter(name = 'aggregation: aux: enable', value = True)
154  strat.MLParameters.add_parameter(name = 'aggregation: aux: threshold', value = 0.005)
155 
156 lss = ns_solver.VelocityLSS.LSS
157 lss.SolutionStrategy.preconditioner_reset = 100
158 lss.SolutionStrategy.Parameters.preconditioner_type = 'Ifpack'
159 lss.SolutionStrategy.Parameters.PreconditionerTypes.Ifpack.overlap = 1
160 #lss.SolutionStrategy.Parameters.PreconditionerTypes.Ifpack.create_parameter_list('Ifpack Settings')
161 #lss.SolutionStrategy.Parameters.PreconditionerTypes.Ifpack.IfpackSettings.add_parameter(name = 'fact: level-of-fill', value = 1)
162 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.aggregation_type = 'Uncoupled'
163 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name = 'PDE equations', value = 3)
164 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.max_levels = 4
165 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_sweeps = 2
166 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.coarse_type = 'Amesos-KLU'
167 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name = 'repartition: start level', value = 0)
168 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name = 'repartition: max min ratio', value = 1.1)
169 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name = 'aggregation: aux: enable', value = True)
170 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name = 'aggregation: aux: threshold', value = 0.0005)
171 
172 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.solver_type = 'Block CG'
173 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockCG.convergence_tolerance = 1e-6
174 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockCG.maximum_iterations = 300
175 #lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.num_blocks = 100
176 
177 # Initial conditions
178 ic_u = solver.InitialConditions.NavierStokes.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'navier_stokes_u_solution')
179 ic_u.variable_name = 'Velocity'
180 ic_u.regions = [mesh.topology.uri()]
181 ic_u.value = ['{Uc}/({h}*{h})*y*(2*{h} - y)'.format(h = h, Uc = Uc), '0', '0']
182 ic_g = solver.InitialConditions.NavierStokes.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'body_force')
183 ic_g.variable_name = 'Force'
184 ic_g.regions = [mesh.topology.uri()]
185 ic_g.value = [str(a_tau), '0', '0']
186 
187 # Boundary conditions
188 bc_u = ns_solver.VelocityLSS.BC
189 bc_u.add_constant_bc(region_name = 'bottom', variable_name = 'Velocity').value = [0., 0., 0.]
190 bc_u.add_constant_bc(region_name = 'top', variable_name = 'Velocity').value = [0., 0., 0.]
191 # Pressure BC
192 ns_solver.PressureLSS.BC.add_constant_bc(region_name = 'center', variable_name = 'Pressure').value = 0.
193 
194 #statistics
195 stats = solver.add_unsteady_solver('cf3.solver.actions.TurbulenceStatistics')
196 stats.region = mesh.topology
197 stats.file = cf.URI('turbulence-statistics.txt')
198 stats.rolling_window = 1000
199 stats.add_probe([0., 0., 0. ])
200 
201 solver.create_fields()
202 stats.setup()
203 #domain.write_mesh(cf.URI('chan180-mkmfields.cf3mesh'))
204 
205 # Restarter
206 restart_writer = solver.add_restart_writer()
207 restart_writer.Writer.file = cf.URI('chan180-{iteration}.cf3restart')
208 restart_writer.interval = 1000
209 
210 dir_avg = solver.TimeLoop.children.WriteRestartManager.create_component('DirectionalAverage', 'cf3.solver.actions.DirectionalAverage')
211 dir_avg.direction = 1
212 dir_avg.field = mesh.geometry.turbulence_statistics
213 dir_avg.file = cf.URI('turbulence-statistics-profile-{iteration}.txt')
214 
215 skip_director = solver.add_unsteady_solver('cf3.solver.ActionDirectorWithSkip')
216 skip_director.interval = 100
217 print_timings = skip_director.create_component('PrintTimingTree', 'cf3.common.PrintTimingTree')
218 print_timings.root = model
219 
220 # Time setup
221 time = model.create_time()
222 tstep = 0.02
223 time.end_time = 5.*tstep
224 time.time_step = tstep
225 
226 solver.InitialConditions.execute()
227 
228 model.simulate()
229 domain.write_mesh(cf.URI('les-wale.pvtu'))
230 model.print_timing_tree()
Send comments to:
COOLFluiD Web Admin