COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-ufem-demo-all.py
Go to the documentation of this file.
1 import coolfluid as cf
2 
3 # Global configuration
4 cf.env.log_level = 4
5 cf.env.assertion_throws = False
6 cf.env.assertion_backtrace = False
7 cf.env.exception_backtrace = False
8 cf.env.exception_outputs = False
9 cf.env.regist_signal_handlers = False
10 cf.env.log_level = 1
11 
12 n = 10
13 
14 # We loop over all available implementations, to test them all
15 for modelname in ['PoissonProto', 'PoissonSpecialized', 'PoissonManual', 'PoissonVirtual']:
16 
17  print '#################################'
18  print ' ',modelname
19  print '#################################'
20 
21  # Setup a model
22  model = cf.Core.root().create_component(modelname+'Model', 'cf3.solver.Model')
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.physics.DynamicModel')
27  # Manager for finite element solvers
28  solver = model.create_solver('cf3.UFEM.Solver')
29  # Add a solver for the Poisson problem
30  poisson_solver = solver.add_direct_solver('cf3.UFEM.demo.'+modelname)
31 
32  # Generate a unit square with 6x4 cells
33  mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
34  mesh_generator = domain.create_component("MeshGenerator","cf3.mesh.SimpleMeshGenerator")
35  mesh_generator.mesh = mesh.uri()
36  mesh_generator.nb_cells = [n,n]
37  mesh_generator.lengths = [1.,1.]
38  mesh_generator.offsets = [0.,0.]
39  mesh_generator.execute()
40 
41  # Triangulate it
42  triangulator = domain.create_component('triangulator', 'cf3.mesh.MeshTriangulator')
43  triangulator.mesh = mesh
44  triangulator.execute()
45 
46  # Set the region over which the solver operates
47  poisson_solver.regions = [mesh.topology.uri()]
48  poisson_solver.LSS.SolutionStrategy.Parameters.linear_solver_type = 'Amesos'
49  poisson_solver.LSS.SolutionStrategy.print_settings = False
50 
51  # Boundary conditions
52  bc = poisson_solver.BoundaryConditions.add_function_bc(region_name = 'left', variable_name = 'u')
53  bc.value = ['1 + x^2 + 2*y^2']
54  bc.regions = [mesh.topology.left.uri(), mesh.topology.right.uri(), mesh.topology.top.uri(), mesh.topology.bottom.uri()]
55 
56  # Source term can be set using an initial condition
57  ic_f = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionConstant', field_tag = 'source_term')
58  ic_f.f = -6.
59  ic_f.regions = [mesh.topology.uri()]
60 
61  # run the simulation
62  model.simulate()
63  model.store_timings()
64 
65  for [x,y], [u] in zip(mesh.geometry.coordinates, mesh.geometry.poisson_solution):
66  if abs(1. + x**2 + 2.*y**2 - u) > 1e-8:
67  raise Exception('Solution is incorrect')
68 
69  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