10 env = cf.Core.environment()
13 env.assertion_throws =
False
14 env.assertion_backtrace =
False
15 env.exception_backtrace =
False
16 env.regist_signal_handlers =
False
20 model = root.create_component(
'NavierStokes',
'cf3.solver.ModelUnsteady')
21 domain = model.create_domain()
22 physics = model.create_physics(
'cf3.UFEM.NavierStokesPhysics')
23 solver = model.create_solver(
'cf3.UFEM.Solver')
26 ns_solver = solver.add_unsteady_solver(
'cf3.UFEM.NavierStokesSemiImplicit')
27 ns_solver.options.theta = 0.5
28 ns_solver.options.nb_iterations = 2
29 ns_solver.PressureLSS.solution_strategy =
'cf3.math.LSS.DirectStrategy'
31 ic_visc = solver.InitialConditions.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag =
'navier_stokes_viscosity')
32 ic_visc.variable_name =
'EffectiveViscosity'
35 blocks = domain.create_component(
'blocks',
'cf3.mesh.BlockMesh.BlockArrays')
36 points = blocks.create_points(dimensions = 2, nb_points = 6)
37 points[0] = [-0.5, -0.5]
38 points[1] = [0.5, -0.5]
39 points[2] = [-0.5, 0.]
41 points[4] = [-0.5,0.5]
42 points[5] = [0.5, 0.5]
44 block_nodes = blocks.create_blocks(2)
45 block_nodes[0] = [0, 1, 3, 2]
46 block_nodes[1] = [2, 3, 5, 4]
48 block_subdivs = blocks.create_block_subdivisions()
49 block_subdivs[0] = [segments, segments/2]
50 block_subdivs[1] = [segments, segments/2]
52 gradings = blocks.create_block_gradings()
53 gradings[0] = [1., 1., 1., 1.]
54 gradings[1] = [1., 1., 1., 1.]
56 left_patch = blocks.create_patch_nb_faces(name =
'left', nb_faces = 2)
57 left_patch[0] = [2, 0]
58 left_patch[1] = [4, 2]
60 bottom_patch = blocks.create_patch_nb_faces(name =
'bottom', nb_faces = 1)
61 bottom_patch[0] = [0, 1]
63 top_patch = blocks.create_patch_nb_faces(name =
'top', nb_faces = 1)
66 right_patch = blocks.create_patch_nb_faces(name =
'right', nb_faces = 2)
67 right_patch[0] = [1, 3]
68 right_patch[1] = [3, 5]
70 blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 0)
72 mesh = domain.create_component(
'Mesh',
'cf3.mesh.Mesh')
73 blocks.create_mesh(mesh.uri())
75 create_point_region = domain.create_component(
'CreatePointRegion',
'cf3.mesh.actions.AddPointRegion')
76 create_point_region.coordinates = [0., 0.]
77 create_point_region.region_name =
'center'
78 create_point_region.mesh = mesh
79 create_point_region.execute()
81 ns_solver.regions = [mesh.topology.interior.uri()]
84 ic_u = solver.InitialConditions.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag =
'navier_stokes_u_solution')
85 ic_u.variable_name =
'Velocity'
86 ic_u.regions = ns_solver.regions
89 ic_p = solver.InitialConditions.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag =
'navier_stokes_p_solution')
90 ic_p.regions = ns_solver.regions
91 ic_p.variable_name =
'Pressure'
95 physics.options().set(
'density', 1000.)
96 physics.options().set(
'dynamic_viscosity', 10.)
99 bc = ns_solver.VelocityLSS.BC
100 bc.regions = [mesh.topology.uri()]
101 bc.add_constant_bc(region_name =
'top', variable_name =
'Velocity').value = u_lid
102 bc.add_constant_bc(region_name =
'bottom', variable_name =
'Velocity').value = [0., 0.]
103 bc.add_constant_bc(region_name =
'left', variable_name =
'Velocity').value = [0., 0.]
104 bc.add_constant_bc(region_name =
'right', variable_name =
'Velocity').value = [0., 0.]
105 bc = ns_solver.PressureLSS.BC
106 bc.regions = [mesh.topology.uri()]
107 bc.add_constant_bc(region_name =
'center', variable_name =
'Pressure').value = 10.
110 ns_solver.VelocityLSS.LSS.SolutionStrategy.print_settings =
False
111 lss = ns_solver.VelocityLSS.LSS
113 lss.SolutionStrategy.preconditioner_reset = 20
114 lss.SolutionStrategy.Parameters.preconditioner_type =
'Ifpack'
115 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.convergence_tolerance = 1e-6
116 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.maximum_iterations = 2000
117 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.num_blocks = 1000
125 time = model.create_time()
126 time.options().set(
'time_step', 0.01)
133 while time.end_time < final_end_time:
134 time.end_time += save_interval
136 domain.write_mesh(cf.URI(
'cavity-' +str(iteration) +
'.pvtu'))
139 solver.options().set(
'disabled_actions', [
'InitialConditions'])
142 model.print_timing_tree()