COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
ptest-ufem-demo-navier-stokes.py
Go to the documentation of this file.
1 import coolfluid as cf
2 import xml.etree.ElementTree as ET
3 
4 # Helper class to profile only if the profiler is available
5 class Profiler:
6  def __init__(self):
7  self.profiler = None
8  try:
9  self.profiler = cf.Core.root().create_component('Profiler', 'cf3.Tools.GooglePerfTools.GooglePerfProfiling')
10  print 'Profiling is on'
11  except:
12  print 'GooglePerfTools not found, not profiling'
13 
14  def start(self, filename):
15  if self.profiler == None:
16  return
17  self.profiler.file_path = cf.URI(filename)
18  self.profiler.start_profiling()
19 
20  def stop(self):
21  if self.profiler == None:
22  return
23  self.profiler.stop_profiling()
24 
25 # Global configuration
26 cf.env.log_level = 1
27 cf.env.assertion_throws = False
28 cf.env.assertion_backtrace = False
29 cf.env.exception_backtrace = False
30 cf.env.exception_outputs = False
31 cf.env.regist_signal_handlers = False
32 
33 n = 400
34 
35 measurement = ET.Element('DartMeasurement', name = 'Problem size', type = 'numeric/integer')
36 measurement.text = str(n)
37 print ET.tostring(measurement)
38 
39 profiler = Profiler()
40 
41 # We loop over all available implementations, to test them all
42 # Loop over LSS matrix implementations
43 for lss_name in ['EmptyLSS', 'TrilinosFEVbr', 'TrilinosCrs']:
44  for modelname in ['Manual', 'Specialized', 'Specialized2', 'Proto']:
45  # Setup a model
46  model = None
47  model = cf.Core.root().create_component(modelname+'Model', 'cf3.solver.ModelUnsteady')
48  # The domain holds the mesh
49  domain = model.create_domain()
50  # Physical model keeps track of all the variables in the problem and any material properties (absent here)
51  physics = model.create_physics('cf3.UFEM.NavierStokesPhysics')
52  physics.density = 1.
53  physics.dynamic_viscosity = 1.
54  # Manager for finite element solvers
55  solver = model.create_solver('cf3.UFEM.Solver')
56  ns_solver = None
57  if modelname == 'Specialized2':
58  ns_solver = solver.add_unsteady_solver('cf3.UFEM.NavierStokes')
59  ns_solver.options.use_specializations = True
60  elif modelname == 'Proto':
61  ns_solver = solver.add_unsteady_solver('cf3.UFEM.NavierStokes')
62  ns_solver.options.use_specializations = False
63  else:
64  ns_solver = solver.add_unsteady_solver('cf3.UFEM.demo.NavierStokes' + modelname)
65  ns_solver.matrix_builder = 'cf3.math.LSS.{name}Matrix'.format(name=lss_name)
66 
67  # Generate a unit square
68  mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
69  mesh_generator = domain.create_component("MeshGenerator","cf3.mesh.SimpleMeshGenerator")
70  mesh_generator.mesh = mesh.uri()
71  mesh_generator.nb_cells = [n,n]
72  mesh_generator.lengths = [10.,2.]
73  mesh_generator.offsets = [0.,0.]
74  mesh_generator.execute()
75 
76  # Triangulate it
77  triangulator = domain.create_component('triangulator', 'cf3.mesh.MeshTriangulator')
78  triangulator.mesh = mesh
79  triangulator.execute()
80 
81  # Set the region over which the solver operates
82  ns_solver.regions = [mesh.topology.uri()]
83  # No solve for the assembly benchmark
84  ns_solver.options.disabled_actions = ['SolveLSS']
85 
86  # Boundary conditions
87  # Set no-slip at the walls
88  bc_wall = ns_solver.BoundaryConditions.add_constant_bc(region_name = 'top', variable_name = 'Velocity')
89  bc_wall.value = [0., 0.]
90  bc_wall.regions = [mesh.topology.top.uri(), mesh.topology.bottom.uri()]
91  # Parabolic inlet
92  ns_solver.BoundaryConditions.add_function_bc(region_name = 'left', variable_name = 'Velocity').value = ['y*(2-y)', '0']
93  # Fix outlet pressure
94  ns_solver.BoundaryConditions.add_constant_bc(region_name = 'right', variable_name = 'Pressure').value = 0.
95 
96  # Take one time step
97  time = model.create_time()
98  time.time_step = 0.1
99  time.end_time = 10.*time.time_step
100 
101  # run the simulation to ensure all setup is OK
102  profiler.start('NS' + modelname + '-' + lss_name + '.pprof')
103  model.simulate()
104  profiler.stop()
105  ns_solver.store_timings()
106 
107  try:
108  assembly_time = ns_solver.Assembly.properties()["timer_mean"]
109  measurement = ET.Element('DartMeasurement', name = modelname + ' ' + lss_name + ' timing', type = 'numeric/double')
110  measurement.text = str(assembly_time)
111  print ET.tostring(measurement)
112  except:
113  print 'no timing info found'
114 
115  model.delete_component()
boost::python::object create_component(ComponentWrapper &self, const std::string &name, const std::string &builder_name)
Send comments to:
COOLFluiD Web Admin