COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-solver-actions-restart.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 
4 def copy_and_reset(source, domain):
5  nb_items = len(source)
6  destination = domain.create_component(source.name(), 'cf3.mesh.Field')
7  destination.set_row_size(1)
8  destination.resize(nb_items)
9 
10  for i in range(nb_items):
11  destination[i][0] = source[i][0]
12  source[i][0] = 0
13 
14  return destination
15 
16 env = cf.Core.environment()
17 env.log_level = 4
18 env.only_cpu0_writes = True
19 
20 root = cf.Core.root()
21 domain = root.create_component('Domain', 'cf3.mesh.Domain')
22 mesh = domain.create_component('OriginalMesh','cf3.mesh.Mesh')
23 
24 
25 blocks = root.create_component('model', 'cf3.mesh.BlockMesh.BlockArrays')
26 points = blocks.create_points(dimensions = 2, nb_points = 4)
27 points[0] = [0., 0.]
28 points[1] = [1., 0.]
29 points[2] = [1., 1.]
30 points[3] = [0., 1.]
31 block_nodes = blocks.create_blocks(1)
32 block_nodes[0] = [0, 1, 2, 3]
33 block_subdivs = blocks.create_block_subdivisions()
34 block_subdivs[0] = [16,16]
35 gradings = blocks.create_block_gradings()
36 gradings[0] = [1., 1., 1., 1.]
37 blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)[0] = [0, 1]
38 blocks.create_patch_nb_faces(name = 'right', nb_faces = 1)[0] = [1, 2]
39 blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)[0] = [2, 3]
40 blocks.create_patch_nb_faces(name = 'left', nb_faces = 1)[0] = [3, 0]
41 blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 1)
42 blocks.create_mesh(mesh.uri())
43 
44 link_horizontal = domain.create_component('LinkHorizontal', 'cf3.mesh.actions.LinkPeriodicNodes')
45 link_horizontal.mesh = mesh
46 link_horizontal.source_region = mesh.topology.right
47 link_horizontal.destination_region = mesh.topology.left
48 link_horizontal.translation_vector = [-1., 0.]
49 link_horizontal.execute()
50 
51 make_par_data = root.create_component('MakeParData', 'cf3.solver.actions.ParallelDataToFields')
52 make_par_data.mesh = mesh
53 make_par_data.execute()
54 
55 # set time
56 time = domain.create_component('Time', 'cf3.solver.Time')
57 time.current_time = 2.
58 time.time_step = 0.2
59 time.iteration = 10
60 
61 # Write a restart file containing the data generated by MakeParData
62 restart_file = cf.URI('restart-test.cf3restart')
63 writer = domain.create_component('Writer', 'cf3.solver.actions.WriteRestartFile')
64 writer.fields = [mesh.geometry.node_gids, mesh.elems_P0.element_gids]
65 writer.file = restart_file
66 writer.time = time
67 writer.execute()
68 
69 # Store reference data and destroy the original
70 ref_node_gids = copy_and_reset(mesh.geometry.node_gids, domain)
71 ref_element_gids = copy_and_reset(mesh.elems_P0.element_gids, domain)
72 time.current_time = 0.
73 time.time_step = 1.
74 time.iteration = 0
75 
76 # Read back the data
77 reader = domain.create_component('Reader', 'cf3.solver.actions.ReadRestartFile')
78 reader.mesh = mesh
79 reader.file = restart_file
80 reader.time = time
81 reader.read_time_step = False
82 reader.execute()
83 if time.time_step != 1.:
84  raise Exception('Time step read when it shouldn not have been')
85 
86 reader.read_time_step = True
87 reader.execute()
88 
89 # Check the result
90 differ = domain.create_component('Differ', 'cf3.common.ArrayDiff')
91 differ.left = ref_node_gids
92 differ.right = mesh.geometry.node_gids
93 differ.execute()
94 if not differ.properties()['arrays_equal']:
95  raise Exception('Node GIDS do not match')
96 
97 differ.left = ref_element_gids
98 differ.right = mesh.elems_P0.element_gids
99 differ.execute()
100 if not differ.properties()['arrays_equal']:
101  raise Exception('Element GIDS do not match')
102 
103 if time.current_time != 2. or time.time_step != 0.2 or time.iteration != 10:
104  raise Exception('Error in time data')
Send comments to:
COOLFluiD Web Admin