COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-ufem-particles-taylor-green.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 import numpy as np
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 nu = 1./5000.
15 
16 segs = 32
17 D = 0.5
18 Vs = 1./(1.5*np.pi)
19 Ua = 0.
20 Va = 0.
21 
22 tau = 0.25
23 beta = 3.
24 
25 dt = 0.1
26 
27 numsteps = 100
28 write_interval = 50
29 
30 
31 def create_mesh(domain, segments):
32  blocks = domain.create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
33  points = blocks.create_points(dimensions = 2, nb_points = 6)
34  points[0] = [-0.5, -0.5]
35  points[1] = [0.5, -0.5]
36  points[2] = [-0.5, 0.]
37  points[3] = [0.5, 0.]
38  points[4] = [-0.5,0.5]
39  points[5] = [0.5, 0.5]
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] = [segments, segments/2]
47  block_subdivs[1] = [segments, segments/2]
48 
49  gradings = blocks.create_block_gradings()
50  #gradings[0] = [1., 1., 10., 10.]
51  #gradings[1] = [1., 1., 0.1, 0.1]
52  gradings[0] = [1., 1., 1., 1.]
53  gradings[1] = [1., 1., 1., 1.]
54 
55  left_patch = blocks.create_patch_nb_faces(name = 'left', nb_faces = 2)
56  left_patch[0] = [2, 0]
57  left_patch[1] = [4, 2]
58 
59  bottom_patch = blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)
60  bottom_patch[0] = [0, 1]
61 
62  top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)
63  top_patch[0] = [5, 4]
64 
65  right_patch = blocks.create_patch_nb_faces(name = 'right', nb_faces = 2)
66  right_patch[0] = [1, 3]
67  right_patch[1] = [3, 5]
68 
69  blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 0)
70 
71  mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
72 
73  blocks.create_mesh(mesh.uri())
74 
75  create_point_region = domain.create_component('CreatePointRegion', 'cf3.mesh.actions.AddPointRegion')
76  create_point_region.coordinates = [0., 0.]
77  create_point_region.region_name = 'center'
78  create_point_region.mesh = mesh
79  create_point_region.execute()
80 
81  partitioner = domain.create_component('Partitioner', 'cf3.mesh.actions.PeriodicMeshPartitioner')
82  partitioner.mesh = mesh
83 
84  link_horizontal = partitioner.create_link_periodic_nodes()
85  link_horizontal.source_region = mesh.topology.right
86  link_horizontal.destination_region = mesh.topology.left
87  link_horizontal.translation_vector = [-1., 0.]
88 
89  link_vertical = partitioner.create_link_periodic_nodes()
90  link_vertical.source_region = mesh.topology.top
91  link_vertical.destination_region = mesh.topology.bottom
92  link_vertical.translation_vector = [0., -1.]
93 
94  partitioner.execute()
95 
96  return mesh
97 
98 # Create the model and solvers
99 model = cf.Core.root().create_component('NavierStokes', 'cf3.solver.ModelUnsteady')
100 domain = model.create_domain()
101 physics = model.create_physics('cf3.UFEM.NavierStokesPhysics')
102 physics.options.dimension = 2
103 solver = model.create_solver('cf3.UFEM.Solver')
104 tg_solver = solver.add_unsteady_solver('cf3.UFEM.particles.TaylorGreen')
105 tg_solver.options.ua = Ua
106 tg_solver.options.va = Va
107 tg_solver.options.tau = tau
108 tg_solver.options.beta = beta
109 tg_solver.options.vs = Vs
110 
111 eq_euler = solver.add_unsteady_solver('cf3.UFEM.particles.EquilibriumEuler')
112 eq_euler.options.velocity_variable = 'FluidVelocityTG'
113 eq_euler.options.velocity_tag = 'taylor_green'
114 eq_euler.beta = beta
115 
116 conv = solver.add_unsteady_solver('cf3.UFEM.particles.EquilibriumEulerConvergence')
117 conv.tau = tau
118 
119 particle_c = solver.add_unsteady_solver('cf3.UFEM.particles.ParticleConcentration')
120 particle_c.options.supg_type = 'metric'
121 #particle_c.options.c1 = 0.
122 #particle_c.options.c2 = 0.
123 #particle_c.options.alpha_su = 30.
124 particle_c.options.c0 = 2.
125 particle_c.options.d0 = 0.05
126 
127 
128 # Set up the physical constants
129 physics.density = 1.
130 physics.dynamic_viscosity = nu
131 
132 # Create the mesh
133 mesh = create_mesh(domain, segs)
134 tg_solver.regions = [mesh.topology.interior.uri()]
135 eq_euler.regions = [mesh.topology.interior.uri()]
136 particle_c.regions = [mesh.topology.interior.uri()]
137 conv.regions = [mesh.topology.interior.uri()]
138 
139 if eq_euler.name() == 'EquilibriumEulerFEM':
140  lss = eq_euler.LSS
141  lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.solver_type = 'Block CG'
142  lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockCG.convergence_tolerance = 1e-12
143  lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockCG.maximum_iterations = 300
144 
145 particle_c.LSS.SolutionStrategy.Parameters.linear_solver_type = 'Amesos'
146 
147 ic_c = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionConstant', field_tag = 'particle_concentration')
148 ic_c.c = 1.
149 ic_c.regions = particle_c.regions
150 
151 ic_tau = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionConstant', field_tag = 'ufem_particle_relaxation_time')
152 ic_tau.tau = tau
153 ic_tau.regions = eq_euler.regions
154 
155 series_writer = solver.TimeLoop.create_component('TimeWriter', 'cf3.solver.actions.TimeSeriesWriter')
156 writer = series_writer.create_component('Writer', 'cf3.mesh.VTKXML.Writer')
157 writer.file = cf.URI('taylor-green-{iteration}.pvtu')
158 writer.mesh = mesh
159 series_writer.interval = write_interval
160 
161 solver.create_fields()
162 writer.fields = [mesh.geometry.taylor_green.uri(), mesh.geometry.ufem_particle_velocity.uri(), mesh.geometry.particle_concentration.uri()]
163 
164 # Time setup
165 time = model.create_time()
166 time.time_step = dt
167 time.end_time = numsteps*dt
168 
169 model.simulate()
170 model.print_timing_tree()
171 
172 
173 ufem_velocity = np.array(mesh.geometry.ufem_particle_velocity)
174 tg_particle_velocity = np.array(mesh.geometry.taylor_green)
175 err_array = np.abs(ufem_velocity-tg_particle_velocity[:,2:4])
176 print 'Maximum error:',np.max(err_array)
177 
178 error_fd = mesh.geometry.create_field(name = 'error_field', variables = 'VelocityError[vector]')
179 for i in range(len(error_fd)):
180  err_row = error_fd[i]
181  err_row[0] = err_array[i][0]
182  err_row[1] = err_array[i][1]
183 
184 domain.write_mesh(cf.URI('taylor-green-end.pvtu'))
185 
186 
187 
boost::python::object create_component(ComponentWrapper &self, const std::string &name, const std::string &builder_name)
Send comments to:
COOLFluiD Web Admin