COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
ptest-ufem-demo-chorin-assembly.py
Go to the documentation of this file.
1 import coolfluid as cf
2 import xml.etree.ElementTree as ET
3 
4 # Global configuration
5 cf.env.log_level = 4
6 cf.env.assertion_throws = False
7 cf.env.assertion_backtrace = False
8 cf.env.exception_backtrace = False
9 cf.env.exception_outputs = False
10 cf.env.regist_signal_handlers = False
11 
12 n = 100
13 #matrix_builder = 'cf3.math.LSS.TrilinosCrsMatrix'
14 matrix_builder = 'cf3.math.LSS.EmptyLSSMatrix'
15 
16 # Print out the problem size to the testing dashboard
17 measurement = ET.Element('DartMeasurement', name = 'Problem size', type = 'numeric/integer')
18 measurement.text = str(n)
19 print ET.tostring(measurement)
20 
21 # Setup a model
22 model = cf.Core.root().create_component('Model', 'cf3.solver.ModelUnsteady')
23 # The domain holds the mesh
24 domain = model.create_domain()
25 # Physical model keeps track of all the variables in the problem and any material properties (absent here)
26 physics = model.create_physics('cf3.UFEM.NavierStokesPhysics')
27 physics.density = 1.
28 physics.dynamic_viscosity = 1.
29 # Manager for finite element solvers
30 solver = model.create_solver('cf3.UFEM.Solver')
31 ns_solver = solver.add_unsteady_solver('cf3.UFEM.demo.NavierStokesChorin')
32 ns_solver.children.AuxiliaryLSS.matrix_builder = matrix_builder
33 ns_solver.children.PressureLSS.matrix_builder = matrix_builder
34 ns_solver.children.CorrectionLSS.matrix_builder = matrix_builder
35 
36 # Generate a 2D channel mesh
37 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
38 mesh_generator = domain.create_component("MeshGenerator","cf3.mesh.SimpleMeshGenerator")
39 mesh_generator.mesh = mesh.uri()
40 mesh_generator.nb_cells = [n,n]
41 mesh_generator.lengths = [10.,2.]
42 mesh_generator.offsets = [0.,0.]
43 mesh_generator.execute()
44 
45 # Triangulate it
46 triangulator = domain.create_component('triangulator', 'cf3.mesh.MeshTriangulator')
47 triangulator.mesh = mesh
48 triangulator.execute()
49 
50 # Set the region over which the solver operates
51 ns_solver.regions = [mesh.topology.uri()]
52 
53 # Initial conditions
54 ic_u = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'navier_stokes_u_solution')
55 ic_u.variable_name = 'Velocity'
56 ic_u.options.field_space_name = 'cf3.mesh.LagrangeP2'
57 ic_u.value = ['0', '0']
58 ic_u.regions = ns_solver.regions
59 
60 ic_p = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'navier_stokes_p_solution')
61 ic_p.variable_name = 'Pressure'
62 ic_p.value = ['20-2*x']
63 ic_p.regions = ns_solver.regions
64 
65 # Boundary conditions
66 ns_solver.VelocityBC.regions = ns_solver.regions
67 ns_solver.PressureBC.regions = ns_solver.regions
68 # Set no-slip at the walls
69 bc_wall = ns_solver.VelocityBC.create_bc_action(region_name = 'top', builder_name = 'cf3.UFEM.BCDirichletFunction')
70 bc_wall.solving_for_difference = False
71 bc_wall.variable_name = 'Velocity'
72 bc_wall.field_tag = 'navier_stokes_u_solution'
73 bc_wall.space = 'cf3.mesh.LagrangeP2'
74 bc_wall.value = ['0', '0']
75 bc_wall.regions = [mesh.topology.top.uri(), mesh.topology.bottom.uri()]
76 # Imposed pressure difference
77 bc_p_out = ns_solver.PressureBC.create_bc_action(region_name = 'right', builder_name = 'cf3.UFEM.BCDirichletFunction')
78 bc_p_out.solving_for_difference = False
79 bc_p_out.variable_name = 'Pressure'
80 bc_p_out.field_tag = 'navier_stokes_p_solution'
81 bc_p_out.value = ['0']
82 bc_p_in = ns_solver.PressureBC.create_bc_action(region_name = 'left', builder_name = 'cf3.UFEM.BCDirichletFunction')
83 bc_p_in.solving_for_difference = False
84 bc_p_in.variable_name = 'Pressure'
85 bc_p_in.field_tag = 'navier_stokes_p_solution'
86 bc_p_in.value = ['20']
87 
88 # Create the fields, to ensure LSS creation
89 solver.create_fields()
90 # LSS options
91 lss = ns_solver.children.AuxiliaryLSS.create_lss()
92 lss.SolutionStrategy.Parameters.preconditioner_type = 'ML'
93 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.default_values = 'SA'
94 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.aggregation_type = 'MIS'
95 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_type = 'symmetric block Gauss-Seidel'
96 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_sweeps = 2
97 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_pre_or_post = 'both'
98 
99 # Timestepping
100 time = model.create_time()
101 time.time_step = 0.1
102 time.end_time = 1.*time.time_step
103 
104 ns_solver.children.AuxiliaryLSS.options.disabled_actions = ['SolveLSS']
105 ns_solver.children.PressureLSS.options.disabled_actions = ['SolveLSS']
106 ns_solver.children.CorrectionLSS.options.disabled_actions = ['SolveLSS']
107 
108 # Run the simulation
109 model.simulate()
110 
111 # Benchmark assemblies
112 for i in range(9):
113  ns_solver.children.AuxiliaryLSS.children.MatrixAssembly.execute()
114  ns_solver.children.AuxiliaryLSS.children.RHSAssembly.execute()
115  ns_solver.children.PressureLSS.children.MatrixAssembly.execute()
116  ns_solver.children.PressureLSS.children.RHSAssembly.execute()
117  ns_solver.children.CorrectionLSS.children.MatrixAssembly.execute()
118  ns_solver.children.CorrectionLSS.children.RHSAssembly.execute()
119 
120 # Print timings
121 model.print_timing_tree()
122 
123 # Save result
124 domain.write_mesh(cf.URI('chorin.msh'))
boost::python::object create_component(ComponentWrapper &self, const std::string &name, const std::string &builder_name)
Send comments to:
COOLFluiD Web Admin