COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-ufem-demo-poisson.py
Go to the documentation of this file.
1 import coolfluid as cf
2 
3 # Global configuration
4 cf.env.log_level = 4
5 
6 # Setup a model
7 model = cf.Core.root().create_component('PoissonModel', 'cf3.solver.Model')
8 # The domain holds the mesh
9 domain = model.create_domain()
10 # Physical model keeps track of all the variables in the problem and any material properties (absent here)
11 physics = model.create_physics('cf3.physics.DynamicModel')
12 # Manager for finite element solvers
13 solver = model.create_solver('cf3.UFEM.Solver')
14 # Add a solver for the Poisson problem
15 poisson_solver = solver.add_direct_solver('cf3.UFEM.demo.PoissonProto')
16 
17 # Generate a unit square with 6x4 elements
18 mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh')
19 mesh_generator = domain.create_component("MeshGenerator","cf3.mesh.SimpleMeshGenerator")
20 mesh_generator.mesh = mesh.uri()
21 mesh_generator.nb_cells = [6,4]
22 mesh_generator.lengths = [1.,1.]
23 mesh_generator.offsets = [0.,0.]
24 mesh_generator.execute()
25 
26 # Triangulate it
27 triangulator = domain.create_component('triangulator', 'cf3.mesh.MeshTriangulator')
28 triangulator.mesh = mesh
29 triangulator.execute()
30 
31 # Set the region over which the solver operates
32 poisson_solver.regions = [mesh.topology.uri()]
33 
34 # The default solution method is Belos Block GMRES
35 # Here we choose a direct solve for a mesh this small by setting the appropriate Trilinos parameter
36 poisson_solver.LSS.SolutionStrategy.Parameters.linear_solver_type = 'Amesos'
37 poisson_solver.LSS.SolutionStrategy.print_settings = False
38 
39 # Boundary conditions
40 bc = poisson_solver.BoundaryConditions.add_function_bc(region_name = 'left', variable_name = 'u')
41 bc.value = ['1 + x^2 + 2*y^2']
42 bc.regions = [mesh.topology.left.uri(), mesh.topology.right.uri(), mesh.topology.top.uri(), mesh.topology.bottom.uri()]
43 
44 # Source term can be set using an initial condition
45 ic_f = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionConstant', field_tag = 'source_term')
46 ic_f.f = -6.
47 ic_f.regions = [mesh.topology.uri()]
48 
49 # run the simulation
50 model.simulate()
51 model.print_timing_tree()
52 
53 # Write result
54 domain.write_mesh(cf.URI('atest-ufem-demo-poisson.pvtu'))
55 
56 # Check result
57 for [x,y], [u] in zip(mesh.geometry.coordinates, mesh.geometry.poisson_solution):
58  if abs(1. + x**2 + 2.*y**2 - u) > 1e-12:
59  raise Exception('Solution is incorrect')
boost::python::object create_component(ComponentWrapper &self, const std::string &name, const std::string &builder_name)
Send comments to:
COOLFluiD Web Admin