COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
ptest-ufem-demo-assembly3d.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 = 4
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 cf.env.log_level = 1
33 
34 n = 16
35 
36 measurement = ET.Element('DartMeasurement', name = 'Problem size', type = 'numeric/integer')
37 measurement.text = str(n)
38 print ET.tostring(measurement)
39 
40 profiler = Profiler()
41 
42 # We loop over all available implementations, to test them all
43 for lss_name in ['EmptyLSS', 'TrilinosCrs']:
44  for modelname in ['Proto']:
45  # Setup a model
46  model = cf.Core.root().create_component(modelname+'Model', 'cf3.solver.Model')
47  # The domain holds the mesh
48  domain = model.create_domain()
49  # Physical model keeps track of all the variables in the problem and any material properties (absent here)
50  physics = model.create_physics('cf3.physics.DynamicModel')
51  # Manager for finite element solvers
52  solver = model.create_solver('cf3.UFEM.Solver')
53  # Add a solver for the Poisson problem
54  poisson_solver = solver.add_direct_solver('cf3.UFEM.demo.Poisson'+modelname)
55  poisson_solver.matrix_builder = 'cf3.math.LSS.{name}Matrix'.format(name=lss_name)
56 
57  # Generate a unit square
58  mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
59  mesh_generator = domain.create_component("MeshGenerator","cf3.mesh.SimpleMeshGenerator")
60  mesh_generator.mesh = mesh.uri()
61  mesh_generator.nb_cells = [n,n,n]
62  mesh_generator.lengths = [1.,1.,1.]
63  mesh_generator.offsets = [0.,0.,0.]
64  mesh_generator.execute()
65 
66  # Triangulate it
67  try:
68  triangulator = domain.create_component('triangulator', 'cf3.vtk.Tetrahedralize')
69  triangulator.mesh = mesh
70  triangulator.execute()
71  except:
72  print 'Tetrahedralizer not found, running using Hexas'
73 
74  # Set the region over which the solver operates
75  poisson_solver.regions = [mesh.topology.uri()]
76  # No solve for the assembly benchmark
77  poisson_solver.options.disabled_actions = ['SolveLSS']
78 
79  # Boundary conditions
80  bc = poisson_solver.BoundaryConditions.add_function_bc(region_name = 'left', variable_name = 'u')
81  bc.value = ['1 + x^2 + 2*y^2']
82  bc.regions = [mesh.topology.left.uri(), mesh.topology.right.uri(), mesh.topology.top.uri(), mesh.topology.bottom.uri()]
83 
84  # Source term can be set using an initial condition
85  ic_f = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionConstant', field_tag = 'source_term')
86  ic_f.f = -6.
87  ic_f.regions = [mesh.topology.uri()]
88 
89  # run the simulation to ensure all setup is OK
90  model.simulate()
91  # Profile only the assembly
92  profiler.start('Poisson' + modelname + '-' + lss_name + '.pprof')
93  for i in range(10):
94  poisson_solver.Assembly.execute()
95  profiler.stop()
96  model.store_timings()
97 
98  try:
99  assembly_time = poisson_solver.Assembly.properties()["timer_mean"]
100  measurement = ET.Element('DartMeasurement', name = modelname + ' ' + lss_name + ' timing', type = 'numeric/double')
101  measurement.text = str(assembly_time)
102  print ET.tostring(measurement)
103  except:
104  pass
105  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