8 a_tau = re_tau**2*nu**2/h**3
9 Uc = a_tau/nu*(h**2/2.)
13 env = cf.Core.environment()
16 env.assertion_throws =
False
17 env.assertion_backtrace =
False
18 env.exception_backtrace =
False
19 env.regist_signal_handlers =
False
23 model = root.create_component(
'NavierStokes',
'cf3.solver.ModelUnsteady')
24 domain = model.create_domain()
25 physics = model.create_physics(
'cf3.UFEM.NavierStokesPhysics')
26 solver = model.create_solver(
'cf3.UFEM.Solver')
29 ns_solver = solver.add_unsteady_solver(
'cf3.UFEM.NavierStokes')
32 blocks = domain.create_component(
'blocks',
'cf3.mesh.BlockMesh.BlockArrays')
33 points = blocks.create_points(dimensions = 2, nb_points = 6)
39 points[5] = [10., 2.*h]
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] = [10, 10]
47 block_subdivs[1] = [10, 10]
50 gradings = blocks.create_block_gradings()
51 gradings[0] = [1., 1., grading, grading]
52 gradings[1] = [1., 1., 1./grading, 1./grading]
54 left_patch = blocks.create_patch_nb_faces(name =
'left', nb_faces = 2)
55 left_patch[0] = [2, 0]
56 left_patch[1] = [4, 2]
58 bottom_patch = blocks.create_patch_nb_faces(name =
'bottom', nb_faces = 1)
59 bottom_patch[0] = [0, 1]
61 top_patch = blocks.create_patch_nb_faces(name =
'top', nb_faces = 1)
64 right_patch = blocks.create_patch_nb_faces(name =
'right', nb_faces = 2)
65 right_patch[0] = [1, 3]
66 right_patch[1] = [3, 5]
68 blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 0)
70 mesh = domain.create_component(
'Mesh',
'cf3.mesh.Mesh')
71 blocks.create_mesh(mesh.uri())
73 partitioner = domain.create_component(
'Partitioner',
'cf3.mesh.actions.PeriodicMeshPartitioner')
74 partitioner.mesh = mesh
76 link_horizontal = partitioner.create_link_periodic_nodes()
77 link_horizontal.source_region = mesh.topology.right
78 link_horizontal.destination_region = mesh.topology.left
79 link_horizontal.translation_vector = [-10., 0.]
83 ns_solver.regions = [mesh.topology.interior.uri()]
88 solver.InitialConditions.navier_stokes_solution.Velocity = u_in
89 ic_g = solver.InitialConditions.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag =
'body_force')
90 ic_g.variable_name =
'Force'
91 ic_g.regions = [mesh.topology.uri()]
92 ic_g.value = [str(a_tau),
'0',
'0']
96 physics.dynamic_viscosity = nu
99 bc = ns_solver.BoundaryConditions
100 bc.regions = [mesh.topology.uri()]
101 bc.add_constant_bc(region_name =
'bottom', variable_name =
'Velocity').value = [0., 0.]
102 bc.add_constant_bc(region_name =
'top', variable_name =
'Velocity').value = [0., 0.]
104 pressure_integral = solver.add_unsteady_solver(
'cf3.UFEM.SurfaceIntegral')
105 pressure_integral.set_field(variable_name =
'Pressure', field_tag =
'navier_stokes_solution')
106 pressure_integral.regions = [mesh.topology.access_component(
'bottom').
uri()]
107 pressure_integral.history = solver.create_component(
'ForceHistory',
'cf3.solver.History')
108 pressure_integral.history.file = cf.URI(
'force-implicit.tsv')
109 pressure_integral.history.dimension = 2
111 bulk_velocity = solver.add_unsteady_solver(
'cf3.UFEM.BulkVelocity')
112 bulk_velocity.set_field(variable_name =
'Velocity', field_tag =
'navier_stokes_solution')
113 bulk_velocity.regions = [mesh.topology.right.uri()]
114 bulk_velocity.history = bulk_velocity.create_component(
'History',
'cf3.solver.History')
115 bulk_velocity.history.file = cf.URI(
'bulk-velocity.tsv')
116 bulk_velocity.history.dimension = 1
128 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.solver_type =
'Block GMRES'
129 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.convergence_tolerance = 1e-5
130 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.maximum_iterations = 2000
131 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.num_blocks = 1000
133 write_manager = solver.add_unsteady_solver(
'cf3.solver.actions.TimeSeriesWriter')
134 write_manager.interval = 10
135 writer = write_manager.create_component(
'PVTUWriter',
'cf3.mesh.VTKXML.Writer')
137 writer.file = cf.URI(
'periodic-channel-2d-{iteration}.pvtu')
140 time = model.create_time()
141 time.time_step = 1000.
142 time.end_time = 20000.
145 solver.create_fields()
146 writer.fields = [mesh.geometry.navier_stokes_solution.uri()]
152 model.print_timing_tree()
156 for [u,v,p]
in mesh.geometry.navier_stokes_solution:
160 print 'found u_max:',u_max
162 if abs(u_max - Uc) > 0.05:
163 raise Exception(
'Laminar profile not reached')
common::URI uri(ComponentWrapper &self)