COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-ufem-navier-stokes-periodic-channel-2d.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 
4 # Flow configuration
5 h = 0.5
6 re_tau = 50.
7 nu = 0.0001
8 a_tau = re_tau**2*nu**2/h**3
9 Uc = a_tau/nu*(h**2/2.)
10 
11 # Some shortcuts
12 root = cf.Core.root()
13 env = cf.Core.environment()
14 
15 # Global configuration
16 env.assertion_throws = False
17 env.assertion_backtrace = False
18 env.exception_backtrace = False
19 env.regist_signal_handlers = False
20 env.log_level = 4
21 
22 # setup a model
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')
27 
28 # Add the Navier-Stokes solver as an unsteady solver
29 ns_solver = solver.add_unsteady_solver('cf3.UFEM.NavierStokes')
30 
31 # Generate mesh
32 blocks = domain.create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
33 points = blocks.create_points(dimensions = 2, nb_points = 6)
34 points[0] = [0, 0.]
35 points[1] = [10., 0.]
36 points[2] = [0., h]
37 points[3] = [10., h]
38 points[4] = [0.,2.*h]
39 points[5] = [10., 2.*h]
40 
41 block_nodes = blocks.create_blocks(2)
42 block_nodes[0] = [0, 1, 3, 2]
43 block_nodes[1] = [2, 3, 5, 4]
44 
45 block_subdivs = blocks.create_block_subdivisions()
46 block_subdivs[0] = [10, 10]
47 block_subdivs[1] = [10, 10]
48 
49 grading = 1.2
50 gradings = blocks.create_block_gradings()
51 gradings[0] = [1., 1., grading, grading]
52 gradings[1] = [1., 1., 1./grading, 1./grading]
53 
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]
57 
58 bottom_patch = blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)
59 bottom_patch[0] = [0, 1]
60 
61 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)
62 top_patch[0] = [5, 4]
63 
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]
67 
68 blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 0)
69 
70 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
71 blocks.create_mesh(mesh.uri())
72 
73 partitioner = domain.create_component('Partitioner', 'cf3.mesh.actions.PeriodicMeshPartitioner')
74 partitioner.mesh = mesh
75 
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.]
80 
81 partitioner.execute()
82 
83 ns_solver.regions = [mesh.topology.interior.uri()]
84 
85 u_in = [0., 0.]
86 
87 #initial condition for the velocity. Unset variables (i.e. the pressure) default to zero
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']
93 
94 # Physical constants
95 physics.density = 1.
96 physics.dynamic_viscosity = nu
97 
98 # Boundary conditions
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.]
103 
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
110 
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
117 
118 lss = ns_solver.LSS
119 #lss.SolutionStrategy.Parameters.linear_solver_type = 'Amesos'
120 #lss.SolutionStrategy.Parameters.preconditioner_type = 'ML'
121 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name = 'ML output', value = 10)
122 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.default_values = 'NSSA'
123 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.eigen_analysis_type = 'Anorm'
124 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.aggregation_type = 'Uncoupled'
125 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_type = 'Chebyshev'
126 #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_sweeps = 6
127 
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
132 
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')
136 writer.mesh = mesh
137 writer.file = cf.URI('periodic-channel-2d-{iteration}.pvtu')
138 
139 # Time setup
140 time = model.create_time()
141 time.time_step = 1000.
142 time.end_time = 20000.
143 
144 # Create the fields, so we can easily set the writer field URI
145 solver.create_fields()
146 writer.fields = [mesh.geometry.navier_stokes_solution.uri()]
147 
148 # run the simulation
149 model.simulate()
150 
151 # print timings
152 model.print_timing_tree()
153 
154 # centerline velocity
155 u_max = 0
156 for [u,v,p] in mesh.geometry.navier_stokes_solution:
157  if u > u_max:
158  u_max = u
159 
160 print 'found u_max:',u_max
161 
162 if abs(u_max - Uc) > 0.05:
163  raise Exception('Laminar profile not reached')
common::URI uri(ComponentWrapper &self)
Send comments to:
COOLFluiD Web Admin