COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-solver-actions-turbulence-statistics.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 = 1
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] = [40,40]
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 = 1)
33 blocks.create_mesh(mesh.uri())
34 
35 # Create a field
36 velocity = mesh.geometry.create_field(name = 'velocity', variables='Velocity[vector]')
37 pressure = mesh.geometry.create_field(name = 'pressure', variables='Pressure')
38 
39 # Action to initialize it
40 init_field = domain.create_component('InitField', 'cf3.mesh.actions.InitFieldFunction')
41 init_field.field = velocity
42 init_field.functions = ['4.*{Uc}*y*(1.-y)'.format(Uc=Uc), '0']
43 
44 # Randomize
45 randomizer = domain.create_component('Randomizer', 'cf3.solver.actions.RandomizeField')
46 randomizer.field = velocity
47 randomizer.variable_name = 'Velocity'
48 randomizer.maximum_variations = [0.3, 0.3]
49 randomizer.maximum_values = [Uc*1.3, Uc/3.]
50 randomizer.minimum_values = [-Uc, -Uc/3.]
51 
52 stats = domain.create_component('Statistics', 'cf3.solver.actions.TurbulenceStatistics')
53 stats.region = mesh.topology
54 stats.file = cf.URI('turbulence-statistics.txt')
55 stats.rolling_window = 10
56 stats.add_probe([1., 0.5 ])
57 stats.add_probe([1., 0.15])
58 stats.setup()
59 
60 avg = domain.create_component('Average', 'cf3.solver.actions.FieldTimeAverage')
61 avg.field = velocity
62 
63 dir_avg = domain.create_component('DirectionalAverage', 'cf3.solver.actions.DirectionalAverage')
64 dir_avg.direction = 1
65 dir_avg.field = mesh.geometry.turbulence_statistics
66 dir_avg.file = cf.URI('turbulence-statistics-profile.txt')
67 
68 for i in range(1000):
69  init_field.execute()
70  randomizer.options.seed = i
71  randomizer.execute()
72  stats.execute()
73  avg.execute()
74 
75 dir_avg.execute()
76 
77 writer = domain.create_component('PVWriter', 'cf3.mesh.VTKXML.Writer')
78 writer.fields = [velocity.uri(), mesh.geometry.coordinates.uri(), mesh.geometry.turbulence_statistics.uri(), mesh.geometry.average_velocity.uri()]
79 writer.mesh = mesh
80 writer.file = cf.URI('turbulence-statistics.pvtu')
81 writer.execute()
Send comments to:
COOLFluiD Web Admin