COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-solver-actions-timeseries.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 import os
4 
5 def copy_and_reset(source, domain):
6  nb_items = len(source)
7  destination = domain.create_component(source.name(), 'cf3.mesh.Field')
8  destination.set_row_size(1)
9  destination.resize(nb_items)
10 
11  for i in range(nb_items):
12  destination[i][0] = source[i][0]
13  source[i][0] = 0
14 
15  return destination
16 
17 env = cf.Core.environment()
18 env.log_level = 4
19 env.only_cpu0_writes = True
20 
21 root = cf.Core.root()
22 domain = root.create_component('Domain', 'cf3.mesh.Domain')
23 mesh = domain.create_component('OriginalMesh','cf3.mesh.Mesh')
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 time = domain.create_component('Time', 'cf3.solver.Time')
45 time.time_step = 0.1
46 time.end_time = 1.
47 
48 series_writer = domain.create_component('SeriesWriter', 'cf3.solver.actions.TimeSeriesWriter')
49 series_writer.time = time
50 series_writer.interval = 5
51 
52 writer = series_writer.create_component('Writer', 'cf3.mesh.cf3mesh.Writer')
53 file_template = 'timeseries-{iteration}-{time}.cf3mesh'
54 writer.file = cf.URI(file_template)
55 writer.mesh = mesh
56 
57 advance_time = domain.create_component('AdvanceTime', 'cf3.solver.actions.AdvanceTime')
58 advance_time.time = time
59 
60 # Write the time series
61 for i in range(10):
62  series_writer.execute()
63  advance_time.execute()
64 
65 # Check that only the expected files exist, and if they do read and compare to reference mesh
66 reader = domain.create_component('Reader', 'cf3.mesh.cf3mesh.Reader')
67 meshdiff = domain.create_component('MeshDiff', 'cf3.mesh.actions.MeshDiff')
68 meshdiff.left = mesh
69 for i in range(10):
70  if i != 0:
71  filename = file_template.format(time = float(i)*time.time_step, iteration = i)
72  else:
73  filename = file_template.format(time = 0, iteration = 0)
74  if i % series_writer.interval != 0:
75  if os.path.isfile(filename):
76  raise Exception('File ' + filename + ' is not supposed to exist')
77  else:
78  reader.mesh = domain.create_component('ReadMesh', 'cf3.mesh.Mesh')
79  reader.file = cf.URI(filename)
80  reader.execute()
81  meshdiff.right = reader.mesh
82  meshdiff.execute()
83  if not meshdiff.properties()['mesh_equal']:
84  raise Exception('Error in read mesh')
Send comments to:
COOLFluiD Web Admin