COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-solver-actions-randomize.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 import os
4 
5 #Centerline velocity
6 Uc = 3.
7 
8 env = cf.Core.environment()
9 env.log_level = 4
10 env.only_cpu0_writes = True
11 
12 root = cf.Core.root()
13 domain = root.create_component('Domain', 'cf3.mesh.Domain')
14 mesh = domain.create_component('OriginalMesh','cf3.mesh.Mesh')
15 
16 blocks = root.create_component('model', 'cf3.mesh.BlockMesh.BlockArrays')
17 points = blocks.create_points(dimensions = 2, nb_points = 4)
18 points[0] = [0., 0.]
19 points[1] = [1., 0.]
20 points[2] = [1., 1.]
21 points[3] = [0., 1.]
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())
34 
35 periodic_partitioner = domain.create_component('Partitioner', 'cf3.mesh.actions.PeriodicMeshPartitioner')
36 periodic_partitioner.mesh = mesh
37 periodic_partitioner.load_balance = False
38 
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.]
43 
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.]
48 
49 periodic_partitioner.execute()
50 
51 # Create a field
52 velocity = mesh.geometry.create_field(name = 'velocity', variables='Velocity[vector]')
53 
54 # Set the X velocity to a parabolic profile
55 for i in range(len(velocity)):
56  y = mesh.geometry.coordinates[i][1]
57  velocity[i][0] = 4.*Uc*y*(1.-y)
58 
59 # Randomize
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
67 randomizer.execute()
68 
69 writer = domain.create_component('PVWriter', 'cf3.mesh.VTKXML.Writer')
70 writer.fields = [velocity.uri()]
71 writer.mesh = mesh
72 writer.file = cf.URI('randomize.pvtu')
73 writer.execute()
Send comments to:
COOLFluiD Web Admin