-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_sampleDict.py
73 lines (60 loc) · 1.55 KB
/
create_sampleDict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 17 10:41:36 2024
# This codecreatess random points in the domain
and generates a sampleDict for postPricessin by OPENFoam 2012.
@author: Amirreza
"""
import numpy as np
import os
from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
from PyFoam.Execution.BasicRunner import BasicRunner
# Specify the case directory
case_dir = r"E:\FOAM_PINN\cavHeat\twoD_lamin_over_box"
folder_name = "2D_FoamCase"
# Sampling bounds (define the domain limits)
x_min, x_max = 0.0, 10.0
y_min, y_max = 0.0, 5.0
z_min, z_max = 0.0, 0.0
# Number of random points
num_points = 50
# Generate random points
random_points = np.column_stack((
np.random.uniform(x_min, x_max, num_points),
np.random.uniform(y_min, y_max, num_points),
np.random.uniform(z_min, z_max, num_points),
))
# Create the sampleDict file
sample_dict_content = f"""
FoamFile
{{
version 2.0;
format ascii;
class dictionary;
location "system";
object sampleDict;
}}
type sets;
interpolationScheme cellPoint;
setFormat csv;
sets
(
randomPoints
{{
type cloud;
axis xyz;
points
(
"""
for point in random_points:
sample_dict_content += f" ({point[0]} {point[1]} {point[2]})\n"
sample_dict_content += """
);
}
);
fields (U T p); // Add more fields if needed
"""
# Write sampleDict to the case directory
sample_dict_path = os.path.join(case_dir, folder_name ,"system", "sampleDict")
with open(sample_dict_path, "w") as f:
f.write(sample_dict_content)