COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
atest-ufem-heat1d-P2.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 try:
4  import pylab as pl
5  import numpy as np
6  have_pylab = True
7 except:
8  have_pylab = False
9 
10 # Global configuration
11 cf.env.assertion_backtrace = False
12 cf.env.exception_backtrace = False
13 cf.env.regist_signal_handlers = False
14 cf.env.exception_log_level = 0
15 cf.env.log_level = 4
16 cf.env.exception_outputs = False
17 
18 k = 1./12.
19 Tb = 0.
20 
21 def run_simulation(sf_name):
22  # setup a model
23  model = cf.root.create_component(sf_name, 'cf3.solver.Model')
24  domain = model.create_domain()
25  physics = model.create_physics('cf3.UFEM.NavierStokesPhysics')
26  solver = model.create_solver('cf3.UFEM.Solver')
27  hc = solver.add_direct_solver('cf3.UFEM.HeatConductionSteady')
28  hc.options.heat_space_name = sf_name
29  hc.children.Assembly.options.k = k
30  hc.children.Update.options.relaxation_factor_hc = 1.
31 
32  ic_heat = solver.InitialConditions.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'source_terms')
33  ic_heat.variable_name = 'Heat'
34  ic_heat.options.field_space_name = sf_name
35  ic_heat.value = ['x^2']
36 
37  # Generate a 1D line mesh
38  mesh = domain.create_component('mesh','cf3.mesh.Mesh')
39  mesh_generator = cf.root.create_component("mesh_generator","cf3.mesh.SimpleMeshGenerator")
40  mesh_generator.mesh = mesh.uri()
41  mesh_generator.nb_cells = [10]
42  mesh_generator.lengths = [2.]
43  mesh_generator.offsets = [-1.]
44  mesh_generator.execute()
45 
46  # Set the region for the simulation
47  hc.regions = [mesh.topology.uri()]
48  ic_heat.regions = hc.regions
49 
50  # Boundary conditions
51  bc = hc.BoundaryConditions
52  bc.add_constant_bc(region_name = 'xneg', variable_name = 'Temperature').value = Tb
53  bc.add_constant_bc(region_name = 'xpos', variable_name = 'Temperature').value = Tb
54 
55  # run the simulation
56  model.simulate()
57 
58  return mesh
59 
60 mesh_p1 = run_simulation('cf3.mesh.LagrangeP1')
61 x_p1 = mesh_p1.geometry.coordinates
62 T_p1 = mesh_p1.geometry.heat_conduction_solution
63 
64 mesh_p2 = run_simulation('cf3.mesh.LagrangeP2')
65 x_p2 = mesh_p2.geometry.coordinates
66 T_p2 = mesh_p2.geometry.heat_conduction_solution
67 
68 if have_pylab:
69  pl.plot(x_p1, T_p1, 'ko', mfc='none', label='P1')
70  pl.plot(x_p2, T_p2, 'kx', mfc='none', label='P2')
71 
72  x_th = np.linspace(-1., 1., 500)
73  pl.plot(x_th, (-x_th**4. + 1.) + Tb, 'k-', label='Analytical')
74  pl.grid()
75  pl.legend(loc = 'lower center')
76  pl.xlabel('x')
77  pl.ylabel('T')
78  pl.savefig('heat-p1-p2.eps')
Send comments to:
COOLFluiD Web Admin