COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
ptest-navier-stokes-assembly.py
Go to the documentation of this file.
1 import math
2 import sys
3 import coolfluid as cf
4 
5 # This test compares the performance of Navier-Stokes assembly methods
6 
7 def make_square(x_segs, y_segs):
8  blocks = cf.Core.root().create_component('blocks', 'cf3.mesh.BlockMesh.BlockArrays')
9  points = blocks.create_points(dimensions = 2, nb_points = 6)
10  points[0] = [0, 0.]
11  points[1] = [1, 0.]
12  points[2] = [0., 1.]
13  points[3] = [1., 1.]
14 
15  blocks.create_blocks(1)[0] = [0, 1, 3, 2]
16  blocks.create_block_subdivisions()[0] = [x_segs,y_segs]
17  blocks.create_block_gradings()[0] = [1., 1., 1., 1.]
18 
19  blocks.create_patch_nb_faces(name = 'left', nb_faces = 1)[0] = [2, 0]
20  blocks.create_patch_nb_faces(name = 'right', nb_faces = 1)[0] = [1, 3]
21  blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)[0] = [3, 2]
22  blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)[0] = [0, 1]
23 
24  blocks.options().set('overlap', 0)
25 
26  return blocks
27 
28 class TestCase:
29  def __init__(self, modelname, segments, use_spec):
30  if len(sys.argv) == 2:
31  self.nb_procs = int(sys.argv[1])
32  else:
33  self.nb_procs = 1
34  self.model = cf.Core.root().create_component(modelname, 'cf3.solver.ModelUnsteady')
35  self.domain = self.model.create_domain()
36  self.physics = self.model.create_physics('cf3.UFEM.NavierStokesPhysics')
37  self.solver = self.model.create_solver('cf3.UFEM.Solver')
38  self.segments = segments
39  if self.nb_procs > 1:
40  m1 = self.nb_procs/int(math.floor(math.sqrt(self.nb_procs)))
41  while self.nb_procs % m1 != 0:
42  m1 += 1
43  m2 = self.nb_procs/m1
44  self.segments[0] *= m2
45  self.segments[1] *= m1
46 
47  self.physics.options().set('density', 1000.)
48  self.physics.options().set('dynamic_viscosity', 10.)
49 
50  self.ns_solver = self.solver.add_unsteady_solver('cf3.UFEM.NavierStokes')
51  self.ns_solver.options().set('use_specializations', use_spec)
52  self.ns_solver.options().set('disabled_actions', ['SolveLSS'])
53  self.use_spec = use_spec
54 
55  def grow_overlap(self):
56  if self.nb_procs > 1:
57  globconn = self.domain.create_component('GlobalConnectivity', 'cf3.mesh.actions.GlobalConnectivity')
58  globconn.options().set('mesh', self.mesh)
59  globconn.execute()
60 
61  grow = self.domain.create_component('GrowOverlap', 'cf3.mesh.actions.GrowOverlap')
62  grow.options().set('mesh', self.mesh)
63  grow.execute()
64 
65  def square_mesh_quads(self):
66  self.mesh = self.domain.create_component('Mesh', 'cf3.mesh.Mesh')
67  blocks=make_square(self.segments[0], self.segments[1])
68  blocks.partition_blocks(nb_partitions=self.nb_procs, direction=0)
69  blocks.create_mesh(self.mesh.uri())
70  self.setup_lss()
71 
72  def square_mesh_triags(self):
73  self.mesh = cf.Core.root().create_component('Mesh', 'cf3.mesh.Mesh')
74  blocks=make_square(self.segments[0], self.segments[1])
75  blocks.partition_blocks(nb_partitions=self.nb_procs, direction=0)
76  blocks.create_mesh(self.mesh.uri())
77  triangulator = self.domain.create_component('triangulator', 'cf3.mesh.MeshTriangulator')
78  triangulator.options().set('mesh', self.mesh)
79  triangulator.execute()
80  self.mesh.move_component(self.domain.uri())
81  self.mesh.raise_mesh_loaded()
82  self.setup_lss()
83 
84  def cube_mesh_hexas(self):
85  self.mesh = self.domain.create_component('Mesh', 'cf3.mesh.Mesh')
86  blocks = make_square(self.segments[0], self.segments[1])
87  blocks.extrude_blocks(positions=[1.], nb_segments=[self.segments[2]], gradings=[1.])
88  blocks.partition_blocks(nb_partitions=self.nb_procs, direction=0)
89  blocks.create_mesh(self.mesh.uri())
90  self.setup_lss()
91 
92  def cube_mesh_tetras(self):
93  self.mesh = cf.Core.root().create_component('Mesh', 'cf3.mesh.Mesh')
94  blocks = make_square(self.segments[0], self.segments[1])
95  blocks.extrude_blocks(positions=[1.], nb_segments=[self.segments[2]], gradings=[1.])
96  blocks.partition_blocks(nb_partitions=self.nb_procs, direction=0)
97  blocks.create_mesh(self.mesh.uri())
98  triangulator = self.domain.create_component('triangulator', 'cf3.mesh.MeshTriangulator')
99  triangulator.options().set('mesh', self.mesh)
100  triangulator.execute()
101  self.mesh.move_component(self.domain.uri())
102  self.mesh.raise_mesh_loaded()
103  self.setup_lss()
104 
105  def setup_lss(self):
106  self.grow_overlap()
107  self.ns_solver.options().set('regions', [self.mesh.access_component('topology').uri()])
108  self.ns_solver.create_lss('cf3.math.LSS.TrilinosFEVbrMatrix')
109 
110  def run(self):
111  time = self.model.create_time()
112  time.options().set('time_step', 1.)
113  time.options().set('end_time', 1.)
114  self.model.simulate()
115  self.ns_solver.store_timings()
116  try:
117  assembly_name = 'Assembly'
118  print '<DartMeasurement name=\"' + self.model.name() + ' time\" type=\"numeric/double\">' + str(self.ns_solver.get_child(assembly_name).properties()['timer_mean']) + '</DartMeasurement>'
119  except:
120  print 'Could not find timing info'
121 
122 # Some shortcuts
123 root = cf.Core.root()
124 env = cf.Core.environment()
125 
126 ## Global configuration
127 env.options().set('assertion_throws', False)
128 env.options().set('assertion_backtrace', False)
129 env.options().set('exception_backtrace', False)
130 env.options().set('regist_signal_handlers', False)
131 env.options().set('log_level', 0)
132 
133 # Generic assembly over quads
134 test_case = TestCase('QuadsGeneric', [150,100], False)
135 test_case.square_mesh_quads()
136 test_case.run()
137 test_case.model.delete_component()
138 
139 
140 # Generic assembly over triags
141 test_case = TestCase('TriagsGeneric', [150,100], False)
142 test_case.square_mesh_triags()
143 test_case.run()
144 test_case.model.delete_component()
145 
146 # Generic assembly over hexahedrons
147 test_case = TestCase('HexasGeneric', [20, 10, 10], False)
148 test_case.cube_mesh_hexas()
149 test_case.run()
150 test_case.model.delete_component()
151 
152 # Generic assembly over tetrahedrons
153 test_case = TestCase('TetrasGeneric', [20, 10, 10], False)
154 test_case.cube_mesh_tetras()
155 test_case.run()
156 test_case.model.delete_component()
157 
158 # Specialized assembly over triangles
159 test_case = TestCase('TriagsSpecialized', [150,100], True)
160 test_case.square_mesh_triags()
161 test_case.run()
162 test_case.model.delete_component()
163 
164 # Specialized assembly over tetrahedrons
165 test_case = TestCase('TetrasSpecialized', [20, 10, 10], True)
166 test_case.cube_mesh_tetras()
167 test_case.run()
168 test_case.model.delete_component()
boost::python::object create_component(ComponentWrapper &self, const std::string &name, const std::string &builder_name)
common::URI uri(ComponentWrapper &self)
properties()["description"]
def __init__(self, modelname, segments, use_spec)
Send comments to:
COOLFluiD Web Admin