COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
ptest-ufem-demo-assembly.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 = 64
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', 'Specialized', 'Manual', 'Virtual']:
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]
62  mesh_generator.lengths = [1.,1.]
63  mesh_generator.offsets = [0.,0.]
64  mesh_generator.execute()
65 
66  # Triangulate it
67  triangulator = domain.create_component('triangulator', 'cf3.mesh.MeshTriangulator')
68  triangulator.mesh = mesh
69  triangulator.execute()
70 
71  # Set the region over which the solver operates
72  poisson_solver.regions = [mesh.topology.uri()]
73  # No solve for the assembly benchmark
74  poisson_solver.options.disabled_actions = ['SolveLSS']
75 
76  # Boundary conditions
77  bc = poisson_solver.BoundaryConditions.add_function_bc(region_name = 'left', variable_name = 'u')
78  bc.value = ['1 + x^2 + 2*y^2']
79  bc.regions = [mesh.topology.left.uri(), mesh.topology.right.uri(), mesh.topology.top.uri(), mesh.topology.bottom.uri()]
80 
81  # Source term can be set using an initial condition
82  ic_f = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionConstant', field_tag = 'source_term')
83  ic_f.f = -6.
84  ic_f.regions = [mesh.topology.uri()]
85 
86  # run the simulation to ensure all setup is OK
87  model.simulate()
88  # Profile only the assembly
89  profiler.start('Poisson' + modelname + '-' + lss_name + '.pprof')
90  for i in range(10):
91  poisson_solver.Assembly.execute()
92  profiler.stop()
93  model.store_timings()
94 
95  try:
96  assembly_time = poisson_solver.Assembly.properties()["timer_minimum"]
97  measurement = ET.Element('DartMeasurement', name = modelname + ' ' + lss_name + ' timing', type = 'numeric/double')
98  measurement.text = str(assembly_time)
99  print ET.tostring(measurement)
100  except:
101  pass
102  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