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.)
16 env = cf.Core.environment()
19 env.assertion_throws =
False
20 env.assertion_backtrace =
False
21 env.exception_backtrace =
False
22 env.regist_signal_handlers =
False
24 env.only_cpu0_writes =
True
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')
33 wale = ns_solver = solver.add_unsteady_solver(
'cf3.UFEM.les.WALE')
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
56 blocks = domain.create_component(
'blocks',
'cf3.mesh.BlockMesh.BlockArrays')
57 points = blocks.create_points(dimensions = 2, nb_points = 6)
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]
65 block_nodes = blocks.create_blocks(2)
66 block_nodes[0] = [0, 1, 3, 2]
67 block_nodes[1] = [2, 3, 5, 4]
69 block_subdivs = blocks.create_block_subdivisions()
70 block_subdivs[0] = [x_segs, y_segs]
71 block_subdivs[1] = block_subdivs[0]
73 gradings = blocks.create_block_gradings()
74 gradings[0] = [1., 1., 20., 20.]
75 gradings[1] = [1., 1., 1./20., 1./20.]
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]
81 bottom_patch = blocks.create_patch_nb_faces(name =
'bottom', nb_faces = 1)
82 bottom_patch[0] = [0, 1]
84 top_patch = blocks.create_patch_nb_faces(name =
'top', nb_faces = 1)
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]
91 blocks.extrude_blocks(positions=[z_size], nb_segments=[z_segs], gradings=[1.])
93 nb_procs = cf.Core.nb_procs()
95 blocks.partition_blocks(nb_partitions = 2, direction = 0)
96 blocks.partition_blocks(nb_partitions = 2, direction = 2)
99 mesh = domain.create_component(
'Mesh',
'cf3.mesh.Mesh')
100 blocks.create_mesh(mesh.uri())
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()
118 partitioner = domain.create_component(
'Partitioner',
'cf3.mesh.actions.PeriodicMeshPartitioner')
119 partitioner.load_balance =
False
120 partitioner.mesh = mesh
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.]
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]
132 partitioner.execute()
138 physics.dynamic_viscosity = nu
140 wale.regions = [mesh.topology.uri()]
141 ns_solver.regions = [mesh.topology.uri()]
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)
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
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
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']
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.]
192 ns_solver.PressureLSS.BC.add_constant_bc(region_name =
'center', variable_name =
'Pressure').value = 0.
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. ])
201 solver.create_fields()
206 restart_writer = solver.add_restart_writer()
207 restart_writer.Writer.file = cf.URI(
'chan180-{iteration}.cf3restart')
208 restart_writer.interval = 1000
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')
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
221 time = model.create_time()
223 time.end_time = 5.*tstep
224 time.time_step = tstep
226 solver.InitialConditions.execute()
229 domain.write_mesh(cf.URI(
'les-wale.pvtu'))
230 model.print_timing_tree()