COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-ufem-ns-driven-cavity.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 
4 # parameters
5 u_lid = [2., 0.]
6 segments = 32
7 
8 # Some shortcuts
9 root = cf.Core.root()
10 env = cf.Core.environment()
11 
12 # Global confifuration
13 env.assertion_throws = False
14 env.assertion_backtrace = False
15 env.exception_backtrace = False
16 env.regist_signal_handlers = False
17 env.log_level = 4
18 
19 # setup a model
20 model = root.create_component('NavierStokes', 'cf3.solver.ModelUnsteady')
21 domain = model.create_domain()
22 physics = model.create_physics('cf3.UFEM.NavierStokesPhysics')
23 solver = model.create_solver('cf3.UFEM.Solver')
24 
25 # Add the Navier-Stokes solver as an unsteady solver
26 ns_solver = solver.add_unsteady_solver('cf3.UFEM.NavierStokesSemiImplicit')
27 ns_solver.options.theta = 0.5
28 ns_solver.options.nb_iterations = 2
29 ns_solver.PressureLSS.solution_strategy = 'cf3.math.LSS.DirectStrategy'
30 
31 ic_visc = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'navier_stokes_viscosity')
32 ic_visc.variable_name = 'EffectiveViscosity'
33 
34 # Generate mesh
35 blocks = domain.create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
36 points = blocks.create_points(dimensions = 2, nb_points = 6)
37 points[0] = [-0.5, -0.5]
38 points[1] = [0.5, -0.5]
39 points[2] = [-0.5, 0.]
40 points[3] = [0.5, 0.]
41 points[4] = [-0.5,0.5]
42 points[5] = [0.5, 0.5]
43 
44 block_nodes = blocks.create_blocks(2)
45 block_nodes[0] = [0, 1, 3, 2]
46 block_nodes[1] = [2, 3, 5, 4]
47 
48 block_subdivs = blocks.create_block_subdivisions()
49 block_subdivs[0] = [segments, segments/2]
50 block_subdivs[1] = [segments, segments/2]
51 
52 gradings = blocks.create_block_gradings()
53 gradings[0] = [1., 1., 1., 1.]
54 gradings[1] = [1., 1., 1., 1.]
55 
56 left_patch = blocks.create_patch_nb_faces(name = 'left', nb_faces = 2)
57 left_patch[0] = [2, 0]
58 left_patch[1] = [4, 2]
59 
60 bottom_patch = blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)
61 bottom_patch[0] = [0, 1]
62 
63 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)
64 top_patch[0] = [5, 4]
65 
66 right_patch = blocks.create_patch_nb_faces(name = 'right', nb_faces = 2)
67 right_patch[0] = [1, 3]
68 right_patch[1] = [3, 5]
69 
70 blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 0)
71 
72 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
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 ns_solver.regions = [mesh.topology.interior.uri()]
82 
83 #initial condition for the velocity. Unset variables (i.e. the pressure) default to zero
84 ic_u = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'navier_stokes_u_solution')
85 ic_u.variable_name = 'Velocity'
86 ic_u.regions = ns_solver.regions
87 ic_u.value = ['0']
88 
89 ic_p = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'navier_stokes_p_solution')
90 ic_p.regions = ns_solver.regions
91 ic_p.variable_name = 'Pressure'
92 ic_p.value = ['10']
93 
94 # Physical constants
95 physics.options().set('density', 1000.)
96 physics.options().set('dynamic_viscosity', 10.)
97 
98 # Boundary conditions
99 bc = ns_solver.VelocityLSS.BC
100 bc.regions = [mesh.topology.uri()]
101 bc.add_constant_bc(region_name = 'top', variable_name = 'Velocity').value = u_lid
102 bc.add_constant_bc(region_name = 'bottom', variable_name = 'Velocity').value = [0., 0.]
103 bc.add_constant_bc(region_name = 'left', variable_name = 'Velocity').value = [0., 0.]
104 bc.add_constant_bc(region_name = 'right', variable_name = 'Velocity').value = [0., 0.]
105 bc = ns_solver.PressureLSS.BC
106 bc.regions = [mesh.topology.uri()]
107 bc.add_constant_bc(region_name = 'center', variable_name = 'Pressure').value = 10.
108 
109 #linear solver parameters
110 ns_solver.VelocityLSS.LSS.SolutionStrategy.print_settings = False
111 lss = ns_solver.VelocityLSS.LSS
112 
113 lss.SolutionStrategy.preconditioner_reset = 20
114 lss.SolutionStrategy.Parameters.preconditioner_type = 'Ifpack'
115 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.convergence_tolerance = 1e-6
116 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.maximum_iterations = 2000
117 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.num_blocks = 1000
118 
119 # direct solve
120 #ns_solver.PressureLSS.LSS.SolutionStrategy.Parameters.linear_solver_type = 'Amesos'
121 #ns_solver.VelocityLSS.LSS.SolutionStrategy.Parameters.linear_solver_type = 'Amesos'
122 
123 
124 # Time setup
125 time = model.create_time()
126 time.options().set('time_step', 0.01)
127 
128 # Setup a time series write
129 final_end_time = 1.
130 save_interval = 0.1
131 iteration = 0
132 
133 while time.end_time < final_end_time:
134  time.end_time += save_interval
135  model.simulate()
136  domain.write_mesh(cf.URI('cavity-' +str(iteration) + '.pvtu'))
137  iteration += 1
138  if iteration == 1:
139  solver.options().set('disabled_actions', ['InitialConditions'])
140 
141 # print timings
142 model.print_timing_tree()
Send comments to:
COOLFluiD Web Admin