COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-ufem-particles-burgers.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 from math import pi
4 
5 env = cf.Core.environment()
6 
7 # Global configuration
8 env.assertion_throws = False
9 env.assertion_backtrace = False
10 env.exception_backtrace = False
11 env.regist_signal_handlers = False
12 env.log_level = 4
13 
14 rho_f = 0.9
15 mu = 0.19e-4 * rho_f
16 
17 r0 = 0.01
18 omega0 = 18.
19 g = 10.
20 
21 dt = 0.1
22 
23 numsteps = 5
24 write_interval = 50
25 
26 resolution = 64
27 
28 diams = [20.e-6, 40.e-6, 80.e-6]
29 volumes = [4./3.*pi*(d/2.)**3 for d in diams]
30 ref_vol = 1e-15
31 c_reduced = [1, 1., 1.]
32 zeta = [v/ref_vol*c for (v,c) in zip(volumes,c_reduced)]
33 
34 # Create the model and solvers
35 model = cf.Core.root().create_component('NavierStokes', 'cf3.solver.ModelUnsteady')
36 domain = model.create_domain()
37 physics = model.create_physics('cf3.UFEM.NavierStokesPhysics')
38 physics.options.dimension = 2
39 solver = model.create_solver('cf3.UFEM.Solver')
40 
41 polydisp = solver.add_unsteady_solver('cf3.UFEM.particles.Polydisperse')
42 polydisp.options.velocity_variable = 'Velocity'
43 polydisp.options.velocity_tag = 'navier_stokes_u_solution'
44 polydisp.options.save_collision_rate = True
45 polydisp.options.collision_kernel_type = 'DNSCollisionKernel'
46 
47 # Set up the physical constants
48 physics.density = rho_f
49 physics.dynamic_viscosity = mu
50 
51 polydisp.initial_diameters = diams
52 polydisp.reference_volume = ref_vol
53 polydisp.initial_concentrations = [x/polydisp.reference_volume for x in c_reduced]
54 polydisp.nb_phases = 3
55 
56 # Create the mesh
57 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
58 
59 x_min = -0.09
60 x_max = 0.2
61 y_min = -0.2
62 y_max = 0.2
63 x_segs = resolution
64 y_segs = resolution
65 z_segs = 2
66 
67 blocks = domain.create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
68 points = blocks.create_points(dimensions = 2, nb_points = 4)
69 points[0] = [x_min, y_min]
70 points[1] = [x_max, y_min]
71 points[2] = [x_min, y_max]
72 points[3] = [x_max, y_max]
73 
74 block_nodes = blocks.create_blocks(1)
75 block_nodes[0] = [0, 1, 3, 2]
76 
77 block_subdivs = blocks.create_block_subdivisions()
78 block_subdivs[0] = [x_segs, y_segs]
79 
80 gradings = blocks.create_block_gradings()
81 gradings[0] = [1., 1., 1., 1.]
82 
83 left_patch = blocks.create_patch_nb_faces(name = 'left', nb_faces = 1)
84 left_patch[0] = [2, 0]
85 
86 bottom_patch = blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)
87 bottom_patch[0] = [0, 1]
88 
89 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)
90 top_patch[0] = [3, 2]
91 
92 right_patch = blocks.create_patch_nb_faces(name = 'right', nb_faces = 1)
93 right_patch[0] = [1, 3]
94 
95 blocks.extrude_blocks(positions=[0.05], nb_segments=[z_segs], gradings=[1.])
96 blocks.create_mesh(mesh.uri())
97 
98 partitioner = domain.create_component('Partitioner', 'cf3.mesh.actions.PeriodicMeshPartitioner')
99 partitioner.mesh = mesh
100 partitioner.load_balance = False
101 
102 link_horizontal = partitioner.create_link_periodic_nodes()
103 link_horizontal.source_region = mesh.topology.right
104 link_horizontal.destination_region = mesh.topology.left
105 link_horizontal.translation_vector = [-0.29, 0., 0.]
106 
107 link_front_back = partitioner.create_link_periodic_nodes()
108 link_front_back.source_region = mesh.topology.back
109 link_front_back.destination_region = mesh.topology.front
110 link_front_back.translation_vector = [0., 0., -0.05]
111 
112 partitioner.execute()
113 
114 polydisp.regions = [mesh.topology.uri()]
115 
116 #polydisp.children.ConcentrationSolver.LSS.SolutionStrategy.Parameters.linear_solver_type = 'Amesos'
117 
118 series_writer = solver.TimeLoop.create_component('TimeWriter', 'cf3.solver.actions.TimeSeriesWriter')
119 writer = series_writer.create_component('Writer', 'cf3.mesh.VTKXML.Writer')
120 writer.file = cf.URI('polydisperse-burgers-{iteration}.pvtu')
121 writer.mesh = mesh
122 series_writer.interval = write_interval
123 
124 solver.create_fields()
125 writer.fields = [mesh.geometry.particle_concentration_1.uri(), mesh.geometry.weighted_particle_volume_1.uri()]
126 
127 u_arr = ['-((1 - exp(-(x^2 + y^2)/{r0}^2))*{omega0}*{r0}^2*y)/(2.*(x^2 + y^2))'.format(r0=r0,omega0=omega0), '((1 - exp(-(x^2 + y^2)/{r0}^2))*{omega0}*{r0}^2*x)/(2.*(x^2 + y^2))'.format(r0=r0,omega0=omega0), '0']
128 ic_u = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'navier_stokes_u_solution')
129 ic_u.variable_name = 'Velocity'
130 ic_u.regions = [mesh.topology.uri()]
131 ic_u.value = u_arr
132 
133 ic_lin_u = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'linearized_velocity')
134 ic_lin_u.variable_name = 'AdvectionVelocity1'
135 ic_lin_u.regions = [mesh.topology.uri()]
136 ic_lin_u.value = u_arr
137 
138 ic_g = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionConstant', field_tag = 'body_force')
139 ic_g.regions = [mesh.topology.uri()]
140 ic_g.Force = [0.,-g, 0.]
141 
142 for i in range(len(zeta)):
143  zeta_name = 'zeta_'+str(i)
144  c_name = 'c_'+str(i)
145  print str(polydisp.BC.children[c_name].regions[0])
146  polydisp.BC.children[c_name].add_constant_bc(region_name = 'top', variable_name = c_name).value = c_reduced[i]
147  polydisp.BC.children[zeta_name].add_constant_bc(region_name = 'top', variable_name = zeta_name).value = zeta[i]
148  #polydisp.BC.children[c_name].add_constant_bc(region_name = 'bottom', variable_name = c_name).value = 0.
149  #polydisp.BC.children[zeta_name].add_constant_bc(region_name = 'bottom', variable_name = zeta_name).value = 0.
150 
151 # Time setup
152 time = model.create_time()
153 time.time_step = dt
154 time.end_time = numsteps*dt
155 
156 #solver.InitialConditions.execute()
157 model.simulate()
158 
159 domain.write_mesh(cf.URI('polydisperse-burgers-end.pvtu'))
160 model.print_timing_tree()
boost::python::object create_component(ComponentWrapper &self, const std::string &name, const std::string &builder_name)
Send comments to:
COOLFluiD Web Admin