COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-flatplate2d-scalar-neumann.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 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 = 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 # Create a component to manage initial conditions
24 ic = solver.create_initial_conditions()
25 
26 # Add the Navier-Stokes solver as an unsteady solver
27 nstokes = solver.add_unsteady_solver('cf3.UFEM.NavierStokes')
28 scalaradv = solver.add_unsteady_solver('cf3.UFEM.ScalarAdvection')
29 
30 # Generate mesh
31 blocks = domain.create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
32 points = blocks.create_points(dimensions = 2, nb_points = 12)
33 points[0] = [0, 0.]
34 points[1] = [1, 0.]
35 points[2] = [0.,0.2]
36 points[3] = [1, 0.2]
37 points[4] = [0.,1.1]
38 points[5] = [1, 1.2]
39 
40 points[6] = [2.,0.]
41 points[7] = [2, 0.2]
42 points[8] = [2, 1.3]
43 
44 points[9] = [-1.,0.]
45 points[10] = [-1, 0.2]
46 points[11] = [-1, 1.]
47 
48 block_nodes = blocks.create_blocks(6)
49 block_nodes[0] = [0, 1, 3, 2]
50 block_nodes[1] = [2, 3, 5, 4]
51 
52 block_nodes[2] = [1, 6, 7, 3]
53 block_nodes[3] = [3, 7, 8, 5]
54 block_nodes[4] = [9, 0, 2, 10]
55 block_nodes[5] = [10, 2, 4, 11]
56 
57 block_subdivs = blocks.create_block_subdivisions()
58 block_subdivs[0] = [40, 20]
59 block_subdivs[1] = [40, 20]
60 block_subdivs[2] = [40, 20]
61 block_subdivs[3] = [40, 20]
62 block_subdivs[4] = [40, 20]
63 block_subdivs[5] = [40, 20]
64 
65 gradings = blocks.create_block_gradings()
66 gradings[0] = [1., 1., 5., 5.]
67 gradings[1] = [1., 1., 10., 10.]
68 gradings[2] = [1., 1., 5., 5.]
69 gradings[3] = [1., 1., 10., 10.]
70 gradings[4] = [1., 1., 5., 5.]
71 gradings[5] = [1., 1., 10., 10.]
72 
73 # fluid block
74 inlet_patch = blocks.create_patch_nb_faces(name = 'inlet', nb_faces = 2)
75 inlet_patch[0] = [10, 9]
76 inlet_patch[1] = [11, 10]
77 
78 bottom_patch1 = blocks.create_patch_nb_faces(name = 'bottom1', nb_faces = 1)
79 bottom_patch1[0] = [0, 1]
80 
81 bottom_patch2 = blocks.create_patch_nb_faces(name = 'bottom2', nb_faces = 1)
82 bottom_patch2[0] = [1, 6]
83 
84 bottom_patch3 = blocks.create_patch_nb_faces(name = 'bottom3', nb_faces = 1)
85 bottom_patch3[0] = [9, 0]
86 
87 outlet_patch = blocks.create_patch_nb_faces(name = 'outlet', nb_faces = 2)
88 outlet_patch[0] = [6, 7]
89 outlet_patch[1] = [7, 8]
90 
91 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 3)
92 top_patch[0] = [5, 4]
93 top_patch[1] = [8, 5]
94 top_patch[2] = [4, 11]
95 
96 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
97 blocks.create_mesh(mesh.uri())
98 nstokes.options().set('regions', [mesh.access_component('topology').uri()])
99 scalaradv.options().set('regions', [mesh.access_component('topology').uri()])
100 
101 u_in = [1., 0.]
102 u_wall = [0., 0.]
103 phi_in = 100
104 phi_wall = 200
105 
106 #initial conditions
107 ic.navier_stokes_solution.Velocity = u_in
108 ic.scalar_advection_solution.Scalar = phi_in
109 
110 #properties for Navier-Stokes
111 physics.options().set('density', 1.2)
112 physics.options().set('dynamic_viscosity', 1.7894e-5)
113 scalaradv.pr = 1./physics.kinematic_viscosity
114 
115 # Boundary conditions for Navier-Stokes
116 bc = nstokes.get_child('BoundaryConditions')
117 bc.add_constant_bc(region_name = 'inlet', variable_name = 'Velocity').options().set('value', u_in)
118 bc.add_constant_bc(region_name = 'bottom1', variable_name = 'Velocity').options().set('value', u_wall)
119 bc.add_constant_bc(region_name = 'bottom2', variable_name = 'Velocity').options().set('value', u_wall)
120 bc.add_constant_component_bc(region_name = 'bottom3', variable_name = 'Velocity', component = 1).options().set('value', 0.)
121 bc.add_constant_bc(region_name = 'outlet', variable_name = 'Pressure').options().set('value', 1.)
122 bc.add_constant_bc(region_name = 'top', variable_name = 'Velocity').options().set('value', u_in)
123 
124 # Boundary conditions for ScalarAdvection
125 bc = scalaradv.get_child('BoundaryConditions')
126 bc.options().set('regions', [mesh.access_component('topology').uri()]) # needed to make the lookup work
127 bc.add_constant_bc(region_name = 'bottom2', variable_name = 'Scalar').options().set('value', phi_in)
128 bc.add_constant_bc(region_name = 'bottom3', variable_name = 'Scalar').options().set('value', phi_in)
129 bc.add_constant_bc(region_name = 'top', variable_name = 'Scalar').options().set('value', phi_in)
130 bc.add_constant_bc(region_name = 'inlet', variable_name = 'Scalar').options().set('value', phi_in)
131 bc_wall_flux = bc.create_bc_action(region_name = 'bottom1', builder_name = 'cf3.UFEM.BCNeumannConstant')
132 bc_wall_flux.set_tags(neumann_field = 'scalar_advection_solution', neumann_variable = 'Scalar')
133 
134 
135 # Time setup
136 time = model.create_time()
137 time.options().set('time_step', 0.01)
138 
139 # Setup a time series write
140 final_end_time = 0.1
141 save_interval = 0.01
142 current_end_time = 0.
143 iteration = 0
144 while current_end_time < final_end_time:
145  current_end_time += save_interval
146  time.options().set('end_time', current_end_time)
147  model.simulate()
148  domain.write_mesh(cf.URI('atest-flatplate2d-scalar-' +str(iteration) + '.pvtu'))
149  iteration += 1
150  if iteration == 1:
151  solver.options().set('disabled_actions', ['InitialConditions'])
152 
153 # print timings
154 model.print_timing_tree()
common::URI uri(ComponentWrapper &self)
Send comments to:
COOLFluiD Web Admin