COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-flatplate2d-spalartallmaras.py
Go to the documentation of this file.
1 import sys
2 #sys.path.append('/data/scholl/coolfluid3/build/dso')
3 #sys.path.append('/home/sebastian/coolfluid3/build/dso')
4 import coolfluid as cf
5 
6 # Some shortcuts
7 root = cf.Core.root()
8 env = cf.Core.environment()
9 
10 ## Global configuration
11 env.assertion_throws = False
12 env.assertion_backtrace = False
13 env.exception_backtrace = False
14 env.regist_signal_handlers = False
15 env.log_level = 4
16 
17 # setup a model
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')
22 
23 # Add the Navier-Stokes solver as an unsteady solver
24 nstokes = solver.add_unsteady_solver('cf3.UFEM.NavierStokes')
25 
26 # Add the SpalartAllmaras turbulence model solver(satm)
27 satm = solver.add_unsteady_solver('cf3.UFEM.SpalartAllmaras')
28 
29 # Generate mesh
30 blocks = domain.create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
31 points = blocks.create_points(dimensions = 2, nb_points = 12)
32 points[0] = [0, 0.]
33 points[1] = [1, 0.]
34 points[2] = [0.,0.2]
35 points[3] = [1, 0.2]
36 points[4] = [0.,1.1]
37 points[5] = [1, 1.2]
38 
39 points[6] = [2.,0.]
40 points[7] = [2, 0.2]
41 points[8] = [2, 1.3]
42 
43 points[9] = [-1.,0.]
44 points[10] = [-1, 0.2]
45 points[11] = [-1, 1.]
46 
47 block_nodes = blocks.create_blocks(6)
48 block_nodes[0] = [0, 1, 3, 2]
49 block_nodes[1] = [2, 3, 5, 4]
50 
51 block_nodes[2] = [1, 6, 7, 3]
52 block_nodes[3] = [3, 7, 8, 5]
53 block_nodes[4] = [9, 0, 2, 10]
54 block_nodes[5] = [10, 2, 4, 11]
55 
56 block_subdivs = blocks.create_block_subdivisions()
57 block_subdivs[0] = [80, 40]
58 block_subdivs[1] = [80, 40]
59 block_subdivs[2] = [80, 40]
60 block_subdivs[3] = [80, 40]
61 block_subdivs[4] = [80, 40]
62 block_subdivs[5] = [80, 40]
63 
64 gradings = blocks.create_block_gradings()
65 gradings[0] = [1., 1., 5., 5.]
66 gradings[1] = [1., 1., 10., 10.]
67 gradings[2] = [1., 1., 5., 5.]
68 gradings[3] = [1., 1., 10., 10.]
69 gradings[4] = [1., 1., 5., 5.]
70 gradings[5] = [1., 1., 10., 10.]
71 
72 # fluid block
73 inlet_patch = blocks.create_patch_nb_faces(name = 'inlet', nb_faces = 2)
74 inlet_patch[0] = [10, 9]
75 inlet_patch[1] = [11, 10]
76 
77 bottom_patch1 = blocks.create_patch_nb_faces(name = 'bottom1', nb_faces = 1)
78 bottom_patch1[0] = [0, 1]
79 
80 bottom_patch2 = blocks.create_patch_nb_faces(name = 'bottom2', nb_faces = 1)
81 bottom_patch2[0] = [1, 6]
82 
83 bottom_patch3 = blocks.create_patch_nb_faces(name = 'bottom3', nb_faces = 1)
84 bottom_patch3[0] = [9, 0]
85 
86 outlet_patch = blocks.create_patch_nb_faces(name = 'outlet', nb_faces = 2)
87 outlet_patch[0] = [6, 7]
88 outlet_patch[1] = [7, 8]
89 
90 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 3)
91 top_patch[0] = [5, 4]
92 top_patch[1] = [8, 5]
93 top_patch[2] = [4, 11]
94 
95 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
96 blocks.create_mesh(mesh.uri())
97 
98 # Because of multi-region support, solvers do not automatically have a region assigned, so we must manually set the solvers to work on the whole mesh
99 nstokes.regions = [mesh.topology.uri()]
100 satm.regions = [mesh.topology.uri()]
101 
102 u_in = [1., 0.]
103 u_wall = [0., 0.]
104 NU_in = 0.001
105 NU_wall = 0.
106 
107 #initial conditions
108 solver.InitialConditions.navier_stokes_solution.Velocity = u_in
109 solver.InitialConditions.spalart_allmaras_solution.SAViscosity = NU_in
110 
111 #properties for Navier-Stokes
112 physics.density = 1.2
113 physics.dynamic_viscosity = 1.7894e-5
114 
115 # Compute the wall distance
116 wall_distance = domain.create_component('WallDistance', 'cf3.mesh.actions.WallDistance')
117 wall_distance.mesh = mesh
118 wall_distance.regions = [mesh.topology.bottom1, mesh.topology.bottom2]
119 wall_distance.execute()
120 
121 # Boundary conditions for Navier-Stokes
122 bc = nstokes.get_child('BoundaryConditions')
123 bc.add_constant_bc(region_name = 'inlet', variable_name = 'Velocity').options().set('value', u_in)
124 bc.add_constant_bc(region_name = 'bottom1', variable_name = 'Velocity').options().set('value', u_wall)
125 bc.add_constant_bc(region_name = 'bottom2', variable_name = 'Velocity').options().set('value', u_wall)
126 bc.add_constant_component_bc(region_name = 'bottom3', variable_name = 'Velocity', component = 1).options().set('value', 0.)
127 bc.add_constant_bc(region_name = 'outlet', variable_name = 'Pressure').options().set('value', 1.)
128 bc.add_constant_bc(region_name = 'top', variable_name = 'Velocity').options().set('value', u_in)
129 
130 # Boundary conditions for Spalart-Allmaras
131 bc = satm.get_child('BoundaryConditions')
132 bc.add_constant_bc(region_name = 'inlet', variable_name = 'SAViscosity').options().set('value', NU_in)
133 bc.add_constant_bc(region_name = 'bottom1', variable_name = 'SAViscosity').options().set('value', NU_wall)
134 bc.add_constant_bc(region_name = 'bottom2', variable_name = 'SAViscosity').options().set('value', NU_wall)
135 bc.add_constant_bc(region_name = 'bottom3', variable_name = 'SAViscosity').options().set('value', NU_in)
136 bc.add_constant_bc(region_name = 'top', variable_name = 'SAViscosity').options().set('value', NU_in)
137 
138 # Time setup
139 time = model.create_time()
140 time.time_step = 0.1
141 time.end_time = 0.
142 
143 # Setup a time series write
144 final_end_time = 0.5
145 save_interval = 0.1
146 iteration = 0
147 
148 while time.end_time < final_end_time:
149  time.end_time += save_interval
150  model.simulate()
151  domain.write_mesh(cf.URI('atest-flatplate2d-spalartallmaras-' +str(iteration) + '.pvtu'))
152  iteration += 1
153  if iteration == 1:
154  solver.options().set('disabled_actions', ['InitialConditions'])
155 
156 # print timings
157 model.print_timing_tree()
Send comments to:
COOLFluiD Web Admin