COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-conjugate-heat-flatplate.py
Go to the documentation of this file.
1 import sys
2 # sys.path.append('/data/scholl/coolfluid3/build/dso')
3 import coolfluid as cf
4 
5 
6 # Some shortcuts
7 root = cf.Core.root()
8 env = cf.Core.environment()
9 
10 ## Global confifuration
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 = 1
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 # Create a component to manage initial conditions
24 ic = solver.create_initial_conditions()
25 
26 # Add the scalar advection solver as an unsteady solver
27 scalaradv = solver.add_iteration_solver('cf3.UFEM.ScalarAdvection')
28 scalaradv.options().set('scalar_name', 'Temperature')
29 
30 # Add the heat conduction solver for the solid
31 heatcond = solver.add_iteration_solver('cf3.UFEM.HeatConductionSteady')
32 
33 # Add the Navier-Stokes solver as an unsteady solver
34 nstokes = solver.add_unsteady_solver('cf3.UFEM.NavierStokes')
35 
36 # Generate mesh
37 blocks = domain.create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
38 points = blocks.create_points(dimensions = 2, nb_points = 14)
39 points[0] = [0, 0.]
40 points[1] = [1, 0.]
41 points[2] = [0.,0.2]
42 points[3] = [1, 0.2]
43 points[4] = [0.,2.1]
44 points[5] = [1, 2.2]
45 
46 points[6] = [2.,0.]
47 points[7] = [2, 0.2]
48 points[8] = [2, 2.3]
49 
50 points[9] = [-1.,0.]
51 points[10] = [-1, 0.2]
52 points[11] = [-1, 2.]
53 
54 points[12] = [0, -1.]
55 points[13] = [1., -1]
56 
57 block_nodes = blocks.create_blocks(7)
58 block_nodes[0] = [0, 1, 3, 2]
59 block_nodes[1] = [2, 3, 5, 4]
60 
61 block_nodes[2] = [1, 6, 7, 3]
62 block_nodes[3] = [3, 7, 8, 5]
63 block_nodes[4] = [9, 0, 2, 10]
64 block_nodes[5] = [10, 2, 4, 11]
65 
66 block_nodes[6] = [12, 13, 1, 0]
67 
68 block_subdivs = blocks.create_block_subdivisions()
69 block_subdivs[0] = [40, 20]
70 block_subdivs[1] = [40, 20]
71 
72 block_subdivs[2] = [40, 20]
73 block_subdivs[3] = [40, 20]
74 block_subdivs[4] = [40, 20]
75 block_subdivs[5] = [40, 20]
76 block_subdivs[6] = [40, 20]
77 
78 gradings = blocks.create_block_gradings()
79 gradings[0] = [1., 1., 5., 5.]
80 gradings[1] = [1., 1., 10., 10.]
81 gradings[2] = [1., 1., 5., 5.]
82 gradings[3] = [1., 1., 10., 10.]
83 gradings[4] = [1., 1., 5., 5.]
84 gradings[5] = [1., 1., 10., 10.]
85 gradings[6] = [1., 1., 1., 1.]
86 
87 # fluid block
88 inlet_patch = blocks.create_patch_nb_faces(name = 'inlet', nb_faces = 2)
89 inlet_patch[0] = [10, 9]
90 inlet_patch[1] = [11, 10]
91 
92 bottom_patch1 = blocks.create_patch_nb_faces(name = 'solid_bottom', nb_faces = 1)
93 bottom_patch1[0] = [12, 13]
94 
95 bottom_patch1 = blocks.create_patch_nb_faces(name = 'solid_left', nb_faces = 1)
96 bottom_patch1[0] = [0, 12]
97 
98 bottom_patch1 = blocks.create_patch_nb_faces(name = 'solid_right', nb_faces = 1)
99 bottom_patch1[0] = [13, 1]
100 
101 bottom_patch2 = blocks.create_patch_nb_faces(name = 'bottom2', nb_faces = 1)
102 bottom_patch2[0] = [1, 6]
103 
104 bottom_patch3 = blocks.create_patch_nb_faces(name = 'bottom3', nb_faces = 1)
105 bottom_patch3[0] = [9, 0]
106 
107 outlet_patch = blocks.create_patch_nb_faces(name = 'outlet', nb_faces = 2)
108 outlet_patch[0] = [6, 7]
109 outlet_patch[1] = [7, 8]
110 
111 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 3)
112 top_patch[0] = [5, 4]
113 top_patch[1] = [8, 5]
114 top_patch[2] = [4, 11]
115 
116 blocks.options().set('block_regions', ['fluid', 'fluid', 'fluid', 'fluid', 'fluid', 'fluid', 'solid'])
117 
118 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
119 blocks.create_mesh(mesh.uri())
120 
121 # rename the temperature variables, so each temperature has a unique name (needed for mesh writing)
122 variables = physics.get_child('VariableManager')
123 variables.get_child('scalar_advection_solution').options().set('Temperature_variable_name', 'Tadv')
124 variables.get_child('heat_conduction_solution').options().set('Temperature_variable_name', 'Tcond')
125 
126 # For each solver, set the region in which it operates
127 nstokes.options().set('regions', [mesh.access_component('topology/fluid').uri()])
128 scalaradv.options().set('regions', [mesh.access_component('topology/fluid').uri()])
129 heatcond.options().set('regions', [mesh.access_component('topology/solid').uri()])
130 
131 u_in = [1., 0.]
132 u_wall = [0., 0.]
133 Tin = 10.
134 Twall = 0.
135 
136 #initial conditions
137 solver.InitialConditions.navier_stokes_solution.Velocity = u_in
138 solver.InitialConditions.heat_conduction_solution.Temperature = Twall
139 
140 #properties for Navier-Stokes
141 physics.density = 1.
142 physics.dynamic_viscosity = 1.e-5
143 physics.reference_temperature = Twall
144 scalaradv.pr = 1./physics.dynamic_viscosity
145 
146 # Boundary conditions for Navier-Stokes
147 bc = nstokes.get_child('BoundaryConditions')
148 bc.options().set('regions', [mesh.access_component('topology').uri()]) # needed to make the lookup work
149 bc.add_constant_bc(region_name = 'inlet', variable_name = 'Velocity').options().set('value', u_in)
150 bc.add_constant_bc(region_name = 'region_bnd_fluid_solid', variable_name = 'Velocity').options().set('value', u_wall)
151 bc.add_constant_bc(region_name = 'bottom2', variable_name = 'Velocity').options().set('value', u_wall)
152 bc.add_constant_component_bc(region_name = 'bottom3', variable_name = 'Velocity', component = 1).options().set('value', 0.)
153 bc.add_constant_bc(region_name = 'outlet', variable_name = 'Pressure').options().set('value', 1.)
154 bc.add_constant_bc(region_name = 'top', variable_name = 'Velocity').options().set('value', u_in)
155 
156 # Boundary conditions for ScalarAdvection
157 bc = scalaradv.get_child('BoundaryConditions')
158 bc.options().set('regions', [mesh.access_component('topology').uri()]) # needed to make the lookup work
159 bc.add_constant_bc(region_name = 'inlet', variable_name = 'Temperature').options().set('value', Tin)
160 bc_wall_temp = bc.create_bc_action(region_name = 'region_bnd_fluid_solid', builder_name = 'cf3.UFEM.BCHoldValue')
161 bc_wall_temp.set_tags(from_field_tag = 'heat_conduction_solution', to_field_tag = 'scalar_advection_solution', from_variable = 'Temperature', to_variable = 'Temperature')
162 bc.add_constant_bc(region_name = 'bottom2', variable_name = 'Temperature').options().set('value', Tin)
163 bc.add_constant_bc(region_name = 'bottom3', variable_name = 'Temperature').options().set('value', Tin)
164 bc.add_constant_bc(region_name = 'top', variable_name = 'Temperature').options().set('value', Tin)
165 
166 # Boundary conditions for HeatConduction
167 bc = heatcond.get_child('BoundaryConditions')
168 bc.options().set('regions', [mesh.access_component('topology').uri()]) # needed to make the lookup work
169 heat_coupling = bc.create_bc_action(region_name = 'region_bnd_fluid_solid', builder_name = 'cf3.UFEM.HeatCouplingFlux')
170 heat_coupling.options().set('gradient_region', mesh.access_component('topology/fluid'))
171 heat_coupling.options().set('temperature_field_tag', 'scalar_advection_solution')
172 bc.add_constant_bc(region_name = 'solid_bottom', variable_name = 'Temperature').options().set('value', Twall)
173 
174 # Time setup
175 time = model.create_time()
176 time.options().set('time_step', 0.01)
177 
178 # Setup a time series write
179 
180 final_end_time = 0.02
181 save_interval = 0.01
182 current_end_time = 0.
183 iteration = 0
184 solver.TimeLoop.CouplingIteration.options.max_iter = 10
185 solver.create_fields()
186 
187 # must be after create_fields
188 probe0 = solver.add_probe(name = 'Probe', parent = scalaradv, dict = mesh.children['cf3.mesh.LagrangeP0'])
189 probe0.Log.variables = ['TemperatureGradient[0]', 'TemperatureGradient[1]']
190 probe0.coordinate = [0.5, 0.5]
191 probe0.History.file = cf.URI('grad_t.tsv')
192 
193 solver.InitialConditions.execute()
194 domain.write_mesh(cf.URI('atest-conjugate-heat-flatplate_output-initial.pvtu'))
195 while current_end_time < final_end_time:
196  current_end_time += save_interval
197  time.options().set('end_time', current_end_time)
198  model.simulate()
199  domain.write_mesh(cf.URI('atest-cht-flatplate_10-iterations-' +str(iteration) + '.pvtu'))
200  iteration += 1
201  if iteration == 1:
202  solver.options().set('disabled_actions', ['InitialConditions'])
203 
204 # print timings
205 model.print_timing_tree()
common::URI uri(ComponentWrapper &self)
Send comments to:
COOLFluiD Web Admin