8 env = cf.Core.environment()
10 env.only_cpu0_writes =
True
13 domain = root.create_component(
'Domain',
'cf3.mesh.Domain')
14 mesh = domain.create_component(
'OriginalMesh',
'cf3.mesh.Mesh')
16 blocks = root.create_component(
'model',
'cf3.mesh.BlockMesh.BlockArrays')
17 points = blocks.create_points(dimensions = 2, nb_points = 4)
22 block_nodes = blocks.create_blocks(1)
23 block_nodes[0] = [0, 1, 2, 3]
24 block_subdivs = blocks.create_block_subdivisions()
25 block_subdivs[0] = [64,64]
26 gradings = blocks.create_block_gradings()
27 gradings[0] = [1., 1., 1., 1.]
28 blocks.create_patch_nb_faces(name =
'bottom', nb_faces = 1)[0] = [0, 1]
29 blocks.create_patch_nb_faces(name =
'right', nb_faces = 1)[0] = [1, 2]
30 blocks.create_patch_nb_faces(name =
'top', nb_faces = 1)[0] = [2, 3]
31 blocks.create_patch_nb_faces(name =
'left', nb_faces = 1)[0] = [3, 0]
32 blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 0)
33 blocks.create_mesh(mesh.uri())
35 periodic_partitioner = domain.create_component(
'Partitioner',
'cf3.mesh.actions.PeriodicMeshPartitioner')
36 periodic_partitioner.mesh = mesh
37 periodic_partitioner.load_balance =
False
39 link_horizontal = periodic_partitioner.create_link_periodic_nodes()
40 link_horizontal.source_region = mesh.topology.right
41 link_horizontal.destination_region = mesh.topology.left
42 link_horizontal.translation_vector = [-1., 0.]
44 link_vertical = periodic_partitioner.create_link_periodic_nodes()
45 link_vertical.source_region = mesh.topology.top
46 link_vertical.destination_region = mesh.topology.bottom
47 link_vertical.translation_vector = [0., -1.]
49 periodic_partitioner.execute()
52 velocity = mesh.geometry.create_field(name =
'velocity', variables=
'Velocity[vector]')
55 for i
in range(len(velocity)):
56 y = mesh.geometry.coordinates[i][1]
57 velocity[i][0] = 4.*Uc*y*(1.-y)
60 randomizer = domain.create_component(
'Randomizer',
'cf3.solver.actions.RandomizeField')
61 randomizer.field = velocity
62 randomizer.variable_name =
'Velocity'
63 randomizer.maximum_variations = [0.3, 0.3]
64 randomizer.maximum_values = [Uc, Uc/3.]
65 randomizer.minimum_values = [-Uc, -Uc/3.]
66 randomizer.options.seed = 1
69 writer = domain.create_component(
'PVWriter',
'cf3.mesh.VTKXML.Writer')
70 writer.fields = [velocity.uri()]
72 writer.file = cf.URI(
'randomize.pvtu')