forked from hananel/myOpenFOAMscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeGroundShape3D.py
executable file
·61 lines (54 loc) · 1.61 KB
/
writeGroundShape3D.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys, math, os, re, subprocess
from os import path
from numpy import *
from pylab import *
import matplotlib.pyplot as plt
import scipy.special as sp
# reading arguments
# first is blockMeshDict location, second is hill height
sampleFile = sys.argv[1]
hillName = "MartinezBump2D"
if sampleFile:
writeSampleDict = 1 # write a sample file for acceleration h meters above hill shape
def main(sampleFile):
A = 3.1926
a = 180 # [m]
H = a/3 # [m]
X = linspace(-a,a,301) # [m]
Y = - H * 1/6.04844 * ( sp.j0(A)*sp.i0(A*X/a) - sp.i0(A)*sp.j0(A*X/a) )
X = insert(X,0,1000); X = append(X,1000)
Y = insert(Y,0,0); Y = append(Y,0)
h = 10
# interpolating for a refined line
xSample = linspace(-1000,1000,2000)
ySample = interp(xSample,X,Y)
# opening file
infile = open(sampleFile,"r")
outfile = open(sampleFile + "_t","w")
N = i = 0
value = 0.0
# reading first line
line = infile.readline()
while line:
# finding the "nonuniform" line
if line.find("points")>0 and line.find("//")<0:
outfile.write(line)
# writing new sample line shape
for x,y in zip(xSample,ySample):
sampleLine = " ( %12.10f %12.10f %12.10f )\n" % (x,value, y+h)
outfile.write(sampleLine)
line = infile.readline()
else:
outfile.write(line)
# reading new line
line = infile.readline()
# close files
infile.close()
outfile.close()
# copying original to new and viceversa
subprocess.call("cp -r " + sampleFile + " " + sampleFile + "_temp",shell=True)
subprocess.call("cp -r " + sampleFile + "_t " + sampleFile,shell=True)
if __name__ == '__main__':
main(sampleFile)