forked from SabininGV/anisotropy_nn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tam_files_1frac_sys_Thomsen_dry_full_formulae.py
132 lines (110 loc) · 5.33 KB
/
tam_files_1frac_sys_Thomsen_dry_full_formulae.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from shutil import copyfile
import os
from random import random as rand
import numpy as np
import pandas as pd
from subprocess import call
import time
import datetime
def anisotropic_parameters(eps,delta,gamma,alpha=5.0):
return "lh= '0 (base)' ls= 65536 lac= {0:.6f} las= {1:.6f} laa= 0.000000 lab=0.000000 tf={3:.6f} tg={2:.6f} tf1=0.000000 tf2=0.000000 tf3=0.000000 tdn1=0.000000 tdn2=0.000000 tdn3=0.000000 tdt1=0.000000 tdt2=0.000000 tdt3=0.000000 tfb=0\n".format(eps,delta,gamma, alpha)
def copy_files(dir):
# tgr, tgr.cr0, tgr.cr2 files
for word in ['Gath','Snap']:
for form in ['tgr','tgr.cr0','tgr.cr2']:
str = 'model+{0}NP.{1}'.format(word,form)
file = os.path.join(dir,str)
temp_file = os.path.join(cwd,str)
copyfile(temp_file, file)
os.remove(temp_file)
# SEGY files
for ch in ['C','X','Z']:
str = 'model+GathNP-{}.sgy'.format(ch)
file = os.path.join(dir,str)
temp_file = os.path.join(cwd,str)
copyfile(temp_file, file)
os.remove(temp_file)
# the rest of the files
#file = os.path.join(dir,'model+GathNP-Z.sgy.cr0')
#copyfile(os.path.join(cwd,'model+GathNP-Z.sgy.cr0'), file)
file = os.path.join(dir,'model+WaveNP-1.tgr')
copyfile(os.path.join(cwd,'model+WaveNP-1.tgr'), file)
os.remove(os.path.join(cwd,'model+WaveNP-1.tgr'))
print('Enter the number of generated models:', end=' ')
N = int(input())
print('Enter the first model number:',end=' ')
K = int(input())
start_time = datetime.datetime.now()
cwd = os.getcwd()
pattern = os.path.join(cwd,'pattern\\pattern.tam')
runtask_original = os.path.join(cwd,'runtask_original.ini')
runtask = os.path.join(cwd,'runtask.ini')
copyfile(runtask_original, runtask)
data = np.empty([5]) # массив, в к-м будут храниться данные по всем моделям
######################################
# добавить чтение data из файла .csv #
######################################
for i in range(K,N+1):
dir = os.path.join(cwd,"model_"+str(i))
if not os.path.exists(dir):
os.mkdir(dir)
#model = os.path.join(dir,'model1.tam')
model = os.path.join(cwd,'model1.tam')
copyfile(pattern, model)
# записываем случайные параметры в файл
f = open(model, 'r') # pass an appropriate path of the required file
lines = f.readlines()
n = 46
# dn, dt generation from Bakulin Grechka Tsvankin article "Estimation of fracture parameters from reflection seismic data -- Part I"
Vs = 2750
Vp = 5000
g = (Vs**2)/(Vp**2)
e = 0.1*rand()
# dry
dn = 4*e/(3*g*(1-g))
dt = 16*e/(3*(3-2*g))
eps = -2*g*(1-g)*dn/(1-dn*(1-2*g)**2)
delta = -2*g*((1-2*g)*dn + dt)*(1-(1-2*g)*dn)/( (1-dn*(1-2*g)**2)*(1+(g*dt - dn*(1-2*g)**2)/(1-g)) )
gamma = -1*dt/2
alpha = 5.0
lines[n-1] = anisotropic_parameters(eps,delta,gamma, alpha) # n is the line number you want to edit; subtract 1 as indexing of list starts from 0
f.close() # close the file and reopen in write mode to enable writing to file; you can also open in append mode and use "seek", but you will have some unwanted old data if the new data is shorter in length.
f = open(model, 'w')
f.writelines(lines)
# do the remaining operations on the file
f.close()
copyfile(model, os.path.join(dir,'model1.tam'))
frac_params = np.array([eps,delta,gamma,e, alpha])
data = np.vstack((data,frac_params)) # записываем осреднённые параметры в массив
"""
# указываем путь к tam-файлу в runtask.ini:
f = open(runtask, 'r') # pass an appropriate path of the required file
lines_runtask = f.readlines()
#for line in lines_runtask:
# print(line)
n = 4
#"Model Name=model_" + str(i) + "\\model.tam\n"
lines_runtask[n-1] = "Model Name=model.tam\n" # n is the line number you want to edit; subtract 1 as indexing of list starts from 0
f.close() # close the file and reopen in write mode to enable writing to file; you can also open in append mode and use "seek", but you will have some unwanted old data if the new data is shorter in length.
#for line in lines_runtask:
# print(line)
f = open(runtask, 'w')
f.writelines(lines_runtask)
# do the remaining operations on the file
f.close()
"""
# запускаем вычислительный модуль
log_file = open(os.path.join(dir,'log.txt'),'w')
call([os.path.join(cwd,"Tesseral2D_Win64.exe")], universal_newlines=True, stdout=log_file)
log_file.close()
# копируем выходные файлы в папку соответствующей модели
copy_files(dir)
# удаляем model1.tam (на всякий пожарный)
os.remove(os.path.join(cwd,'model1.tam'))
# записываем параметры в csv-файл
df = pd.DataFrame(data[1:])
df.to_csv(str(cwd) + '\\frac_params_Thomsen_dry_full_formulae.csv',index=None, header=['eps','delta','gamma','e', 'alpha'])
# прошедшее время
sec = (datetime.datetime.now() - start_time).total_seconds()
print(sec,'sec')
print('Time elapsed:',int(sec/60),'min',sec%60,'sec')