7 env = cf.Core.environment()
10 env.assertion_throws =
False
11 env.assertion_backtrace =
False
12 env.exception_backtrace =
False
13 env.regist_signal_handlers =
False
15 env.only_cpu0_writes =
True
18 model = root.create_component(
'NavierStokes',
'cf3.solver.ModelUnsteady')
19 domain = model.create_domain()
20 physics = model.create_physics(
'cf3.UFEM.NavierStokesPhysics')
21 solver = model.create_solver(
'cf3.UFEM.Solver')
24 p_copy = solver.add_unsteady_solver(
'cf3.solver.actions.CopyScalar')
27 ns_solver = solver.add_unsteady_solver(
'cf3.UFEM.NavierStokesSemiImplicit')
28 ns_solver.options.theta = 0.5
29 ns_solver.options.nb_iterations = 2
30 ns_solver.enable_body_force =
True
31 ns_solver.options.pressure_rcg_solve =
True
32 ns_solver.options.alpha_su = 0.
36 supg_terms = solver.add_unsteady_solver(
'cf3.UFEM.SUPGFields')
37 residuals = solver.add_unsteady_solver(
'cf3.UFEM.NSResidual')
40 blocks = domain.create_component(
'blocks',
'cf3.mesh.BlockMesh.BlockArrays')
41 points = blocks.create_points(dimensions = 2, nb_points = 6)
49 block_nodes = blocks.create_blocks(2)
50 block_nodes[0] = [0, 1, 3, 2]
51 block_nodes[1] = [2, 3, 5, 4]
53 block_subdivs = blocks.create_block_subdivisions()
54 block_subdivs[0] = [refinement_level*20, refinement_level*16]
55 block_subdivs[1] = block_subdivs[0]
57 gradings = blocks.create_block_gradings()
58 gradings[0] = [1., 1., 1., 1.]
59 gradings[1] = [1., 1., 1., 1.]
61 left_patch = blocks.create_patch_nb_faces(name =
'left', nb_faces = 2)
62 left_patch[0] = [2, 0]
63 left_patch[1] = [4, 2]
65 bottom_patch = blocks.create_patch_nb_faces(name =
'bottom', nb_faces = 1)
66 bottom_patch[0] = [0, 1]
68 top_patch = blocks.create_patch_nb_faces(name =
'top', nb_faces = 1)
71 right_patch = blocks.create_patch_nb_faces(name =
'right', nb_faces = 2)
72 right_patch[0] = [1, 3]
73 right_patch[1] = [3, 5]
75 nb_procs = cf.Core.nb_procs()
76 if block_subdivs[0][1] % nb_procs != 0:
77 raise Exception(
"Vertical slices can't be divided by the number of processors")
79 blocks.partition_blocks(nb_partitions = nb_procs, direction = 1)
81 mesh = domain.create_component(
'Mesh',
'cf3.mesh.Mesh')
82 blocks.create_mesh(mesh.uri())
84 create_point_region = domain.create_component(
'CreatePointRegion',
'cf3.mesh.actions.AddPointRegion')
85 create_point_region.coordinates = [5., 1.]
86 create_point_region.region_name =
'center'
87 create_point_region.mesh = mesh
88 create_point_region.execute()
90 link_horizontal = domain.create_component(
'LinkHorizontal',
'cf3.mesh.actions.LinkPeriodicNodes')
91 link_horizontal.mesh = mesh
92 link_horizontal.source_region = mesh.topology.right
93 link_horizontal.destination_region = mesh.topology.left
94 link_horizontal.translation_vector = [-10., 0.]
95 link_horizontal.execute()
99 physics.options().set(
'density', 1.)
100 physics.options().set(
'dynamic_viscosity', 1.)
104 ns_solver.regions = [mesh.topology.uri()]
105 supg_terms.regions = [mesh.topology.uri()]
106 residuals.regions = [mesh.topology.uri()]
107 p_copy.regions = [mesh.topology.uri()]
109 for strat
in [ns_solver.children.FirstPressureStrategy, ns_solver.children.SecondPressureStrategy]:
110 strat.MLParameters.aggregation_type =
'Uncoupled'
111 strat.MLParameters.max_levels = 4
112 strat.MLParameters.smoother_sweeps = 2
113 strat.MLParameters.coarse_type =
'Amesos-KLU'
114 strat.MLParameters.add_parameter(name =
'repartition: start level', value = 0)
115 strat.MLParameters.add_parameter(name =
'repartition: max min ratio', value = 1.1)
118 lss = ns_solver.VelocityLSS.LSS
119 lss.SolutionStrategy.preconditioner_reset = 20000000
120 lss.SolutionStrategy.Parameters.preconditioner_type =
'Ifpack'
121 lss.SolutionStrategy.Parameters.PreconditionerTypes.Ifpack.overlap = 0
122 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.solver_type =
'Block CG'
123 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockCG.convergence_tolerance = 1e-6
124 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockCG.maximum_iterations = 300
128 ic_u = solver.InitialConditions.NavierStokes.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag =
'navier_stokes_u_solution')
129 ic_u.variable_name =
'Velocity'
130 ic_u.regions = [mesh.topology.uri()]
131 ic_u.value = [
'0',
'0']
132 ic_g = solver.InitialConditions.NavierStokes.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag =
'body_force')
133 ic_g.variable_name =
'Force'
134 ic_g.regions = [mesh.topology.uri()]
135 ic_g.value = [
'2',
'0']
138 bc_u = ns_solver.VelocityLSS.BC
139 bc_u.add_constant_bc(region_name =
'bottom', variable_name =
'Velocity').value = [0., 0.]
140 bc_u.add_constant_bc(region_name =
'top', variable_name =
'Velocity').value = [0., 0.]
142 ns_solver.PressureLSS.BC.add_constant_bc(region_name =
'center', variable_name =
'Pressure').value = 10.
144 solver.create_fields()
145 supg_avg = solver.add_unsteady_solver(
'cf3.solver.actions.FieldTimeAverage')
146 supg_avg.field = mesh.geometry.supg_terms
148 res_avg = solver.add_unsteady_solver(
'cf3.solver.actions.FieldTimeAverage')
149 res_avg.field = mesh.geometry.navier_stokes_residual
152 time = model.create_time()
153 time.time_step = tstep
154 time.end_time = 50.*tstep
157 domain.write_mesh(cf.URI(
'semi-implicit-laminar-channel-2d.pvtu'))
159 for ((x, y), (u, v))
in zip(mesh.geometry.coordinates, mesh.geometry.navier_stokes_u_solution):
161 if abs(u_ref - u) > 1e-2:
162 raise Exception(
'Error in u component: {u} != {u_ref} at y = {y}'.format(u = u, u_ref = u_ref, y = y))
164 raise Exception(
'Non-zero v-component {v} at y = {y}'.format(v = v, y = y))
167 model.print_timing_tree()