COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-interpolator.py
Go to the documentation of this file.
1 import sys
2 import coolfluid as cf
3 from math import pi
4 
5 env = cf.Core.environment()
6 env.log_level = 4
7 #env.only_cpu0_writes = False
8 
9 root = cf.Core.root()
10 source_domain = root.create_component('SourceDomain', 'cf3.mesh.Domain')
11 target_domain = root.create_component('TargetDomain', 'cf3.mesh.Domain')
12 source_mesh = source_domain.create_component('sourcemesh','cf3.mesh.Mesh')
13 
14 h = 1.
15 
16 div = 2
17 
18 blocks = root.create_component('model', 'cf3.mesh.BlockMesh.BlockArrays')
19 grading = 20.
20 y_segs = 64/div
21 x_size = 4.*pi*h
22 z_size = 2.*pi*h
23 x_segs = 32/div
24 z_segs = 32/div
25 points = blocks.create_points(dimensions = 2, nb_points = 6)
26 points[0] = [0, 0.]
27 points[1] = [x_size, 0.]
28 points[2] = [0., h]
29 points[3] = [x_size, h]
30 points[4] = [0.,2.*h]
31 points[5] = [x_size, 2.*h]
32 block_nodes = blocks.create_blocks(2)
33 block_nodes[0] = [0, 1, 3, 2]
34 block_nodes[1] = [2, 3, 5, 4]
35 block_subdivs = blocks.create_block_subdivisions()
36 block_subdivs[0] = [x_segs, y_segs]
37 block_subdivs[1] = block_subdivs[0]
38 gradings = blocks.create_block_gradings()
39 gradings[0] = [1., 1., grading, grading]
40 gradings[1] = [1., 1., 1./grading, 1./grading]
41 left_patch = blocks.create_patch_nb_faces(name = 'left', nb_faces = 2)
42 left_patch[0] = [2, 0]
43 left_patch[1] = [4, 2]
44 bottom_patch = blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)
45 bottom_patch[0] = [0, 1]
46 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)
47 top_patch[0] = [5, 4]
48 right_patch = blocks.create_patch_nb_faces(name = 'right', nb_faces = 2)
49 right_patch[0] = [1, 3]
50 right_patch[1] = [3, 5]
51 blocks.extrude_blocks(positions=[z_size], nb_segments=[z_segs], gradings=[1.])
52 blocks.partition_blocks(nb_partitions = 2, direction = 1)
53 blocks.partition_blocks(nb_partitions = 2, direction = 0)
54 blocks.partition_blocks(nb_partitions = 2, direction = 2)
55 blocks.create_mesh(source_mesh.uri())
56 
57 source_coords = source_mesh.geometry.coordinates
58 testfield = source_mesh.geometry.create_field(name = 'test', variables = 'testx,testy')
59 for i in range(len(source_coords)):
60  testfield[i][0] = 1.+2.*source_coords[i][0]
61  testfield[i][1] = 2.+3.*source_coords[i][1]
62 
63 target_mesh = target_domain.create_component('targetmesh','cf3.mesh.Mesh')
64 blocks = root.create_component('model', 'cf3.mesh.BlockMesh.BlockArrays')
65 grading = 80.
66 y_segs = 128/div
67 x_size = 4.*pi*h
68 z_size = 2.*pi*h
69 x_segs = 32/div
70 z_segs = 32/div
71 points = blocks.create_points(dimensions = 2, nb_points = 6)
72 points[0] = [0, 0.]
73 points[1] = [x_size, 0.]
74 points[2] = [0., h]
75 points[3] = [x_size, h]
76 points[4] = [0.,2.*h]
77 points[5] = [x_size, 2.*h]
78 block_nodes = blocks.create_blocks(2)
79 block_nodes[0] = [0, 1, 3, 2]
80 block_nodes[1] = [2, 3, 5, 4]
81 block_subdivs = blocks.create_block_subdivisions()
82 block_subdivs[0] = [x_segs, y_segs]
83 block_subdivs[1] = block_subdivs[0]
84 gradings = blocks.create_block_gradings()
85 gradings[0] = [1., 1., grading, grading]
86 gradings[1] = [1., 1., 1./grading, 1./grading]
87 left_patch = blocks.create_patch_nb_faces(name = 'left', nb_faces = 2)
88 left_patch[0] = [2, 0]
89 left_patch[1] = [4, 2]
90 bottom_patch = blocks.create_patch_nb_faces(name = 'bottom', nb_faces = 1)
91 bottom_patch[0] = [0, 1]
92 top_patch = blocks.create_patch_nb_faces(name = 'top', nb_faces = 1)
93 top_patch[0] = [5, 4]
94 right_patch = blocks.create_patch_nb_faces(name = 'right', nb_faces = 2)
95 right_patch[0] = [1, 3]
96 right_patch[1] = [3, 5]
97 blocks.extrude_blocks(positions=[z_size], nb_segments=[z_segs], gradings=[1.])
98 # blocks.partition_blocks(nb_partitions = 2, direction = 1)
99 blocks.partition_blocks(nb_partitions = 8, direction = 0)
100 # blocks.partition_blocks(nb_partitions = 2, direction = 2)
101 blocks.create_mesh(target_mesh.uri())
102 
103 interpolator = root.create_component('Interpolator', 'cf3.mesh.actions.MeshInterpolator')
104 interpolator.source_mesh = source_mesh
105 interpolator.target_mesh = target_mesh
106 interpolator.execute()
107 
108 source_domain.write_mesh(cf.URI('interpolator-source.pvtu'))
109 target_domain.write_mesh(cf.URI('interpolator-target.pvtu'))
Send comments to:
COOLFluiD Web Admin