6 env = cf.Core.environment()
9 env.assertion_throws =
False
10 env.assertion_backtrace =
False
11 env.exception_backtrace =
False
12 env.regist_signal_handlers =
False
16 implicit = modeltype ==
'implicit'
18 model = root.create_component(
'NavierStokes'+modeltype,
'cf3.solver.ModelUnsteady')
19 domain = model.create_domain()
20 physics = model.create_physics(
'cf3.UFEM.NavierStokesPhysics')
21 solver = model.create_solver(
'cf3.UFEM.Solver')
25 ns_solver = solver.add_unsteady_solver(
'cf3.UFEM.NavierStokes')
27 ns_solver = solver.add_unsteady_solver(
'cf3.UFEM.NavierStokesSemiImplicit')
28 ns_solver.options.pressure_rcg_solve =
True
29 ns_solver.enable_body_force =
True
32 blocks = domain.create_component(
'blocks',
'cf3.mesh.BlockMesh.BlockArrays')
33 points = blocks.create_points(dimensions = 2, nb_points = 6)
37 points[3] = [10., 0.5]
41 block_nodes = blocks.create_blocks(2)
42 block_nodes[0] = [0, 1, 3, 2]
43 block_nodes[1] = [2, 3, 5, 4]
45 block_subdivs = blocks.create_block_subdivisions()
46 block_subdivs[0] = [40, 20]
47 block_subdivs[1] = [40, 20]
49 gradings = blocks.create_block_gradings()
50 gradings[0] = [1., 1., 10., 10.]
51 gradings[1] = [1., 1., 0.1, 0.1]
53 left_patch = blocks.create_patch_nb_faces(name =
'left', nb_faces = 2)
54 left_patch[0] = [2, 0]
55 left_patch[1] = [4, 2]
57 bottom_patch = blocks.create_patch_nb_faces(name =
'bottom', nb_faces = 1)
58 bottom_patch[0] = [0, 1]
60 top_patch = blocks.create_patch_nb_faces(name =
'top', nb_faces = 1)
63 right_patch = blocks.create_patch_nb_faces(name =
'right', nb_faces = 2)
64 right_patch[0] = [1, 3]
65 right_patch[1] = [3, 5]
67 blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 1)
69 mesh = domain.create_component(
'Mesh',
'cf3.mesh.Mesh')
70 blocks.create_mesh(mesh.uri())
73 link_horizontal = domain.create_component(
'LinkHorizontal',
'cf3.mesh.actions.LinkPeriodicNodes')
74 link_horizontal.mesh = mesh
75 link_horizontal.source_region = mesh.topology.right
76 link_horizontal.destination_region = mesh.topology.left
77 link_horizontal.translation_vector = [-10., 0.]
78 link_horizontal.execute()
80 ns_solver.regions = [mesh.topology.uri()]
84 lss.SolutionStrategy.Parameters.preconditioner_type =
'ML'
85 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name =
'aggregation: aux: enable', value =
True)
86 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name =
'aggregation: aux: threshold', value = 0.0001)
88 for strat
in [ns_solver.children.FirstPressureStrategy, ns_solver.children.SecondPressureStrategy]:
89 strat.MLParameters.aggregation_type =
'Uncoupled'
90 strat.MLParameters.max_levels = 4
91 strat.MLParameters.smoother_sweeps = 3
92 strat.MLParameters.coarse_type =
'Amesos-KLU'
93 strat.MLParameters.add_parameter(name =
'repartition: start level', value = 0)
94 strat.MLParameters.add_parameter(name =
'repartition: max min ratio', value = 1.1)
95 strat.MLParameters.add_parameter(name =
'aggregation: aux: enable', value =
True)
96 strat.MLParameters.add_parameter(name =
'aggregation: aux: threshold', value = 0.05)
97 lss = ns_solver.VelocityLSS.LSS
98 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.solver_type =
'Block GMRES'
99 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.convergence_tolerance = 1e-6
100 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.maximum_iterations = 300
101 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.num_blocks = 100
105 solver.create_fields()
109 solver.InitialConditions.navier_stokes_solution.Velocity = u_in
111 ic_u = solver.InitialConditions.NavierStokes.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag =
'navier_stokes_u_solution')
112 ic_u.variable_name =
'Velocity'
113 ic_u.regions = [mesh.topology.uri()]
114 ic_u.value = [
'0',
'0']
115 ic_g = solver.InitialConditions.NavierStokes.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag =
'body_force')
116 ic_g.variable_name =
'Force'
117 ic_g.regions = [mesh.topology.uri()]
118 ic_g.value = [
'2',
'0']
121 physics.options().set(
'density', 1000.)
122 physics.options().set(
'dynamic_viscosity', 10.)
126 bc_u = ns_solver.BoundaryConditions
128 bc_u.add_constant_bc(region_name =
'left', variable_name =
'Velocity').value = u_in
129 bc_p.add_constant_bc(region_name =
'right', variable_name =
'Pressure').value = 0.
131 bc_u = ns_solver.VelocityLSS.BC
132 bc_p = ns_solver.PressureLSS.BC
134 bc_u.add_constant_bc(region_name =
'bottom', variable_name =
'Velocity').value = [0., 0.]
135 bc_u.add_constant_bc(region_name =
'top', variable_name =
'Velocity').value = [0., 0.]
138 time = model.create_time()
140 time.end_time = 2.*time.time_step
143 domain.write_mesh(cf.URI(
'mlaux-{type}.pvtu'.format(type=modeltype)))
145 model.print_timing_tree()