Newer
Older
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import numpy as np
import matplotlib.pyplot as plt
import sympy as sym
import math
import os
import subprocess
import fileinput
import re
import matlab.engine
# from subprocess import Popen, PIPE
#import sys
print('Running Python Code')
InputFile = "/inputs/cellsolver.parset"
OutputFile = "/outputs/output.txt"
# path = os.getcwd()
# InputFilePath = os.getcwd()+InputFile
# OutputFilePath = os.getcwd()+OutputFile
# --------- Run from src folder:
path_parent = os.path.dirname(os.getcwd())
os.chdir(path_parent)
path = os.getcwd()
print(path)
InputFilePath = os.getcwd()+InputFile
OutputFilePath = os.getcwd()+OutputFile
print("InputFilepath: ", InputFilePath)
print("OutputFilepath: ", OutputFilePath)
print("Path: ", path)
#1. Define Gamma-Array..
#2. for(i=0; i<length(array)) ..compute mu_gamma..
# matrix = np.loadtxt(path + 'Qmatrix.txt', usecols=range(3))
# print(matrix)
# Use Shell Commands:
# subprocess.run('ls', shell=True)
#---------------------------------------------------------------
Gamma_Values = np.linspace(0.01, 2.5, num=12)
print(Gamma_Values)
mu_gamma = []
# mu_gamma.append(1)
# np.append(mu_gamma,[[1]])
print("Values for Gamma:", mu_gamma)
RUN = True
# RUN = False
if RUN:
for gamma in Gamma_Values:
print("Run Cell-Problem for Gamma = ", gamma)
# print('gamma='+str(gamma))
with open(InputFilePath, 'r') as file:
filedata = file.read()
filedata = re.sub('(?m)^gamma=.*','gamma='+str(gamma),filedata)
f = open(InputFilePath,'w')
f.write(filedata)
f.close()
# Run Cell-Problem
subprocess.run(['./build-cmake/src/dune-microstructure', './inputs/cellsolver.parset'],
capture_output=True, text=True)
#Extract mu_gamma from Output-File
with open(OutputFilePath, 'r') as file:
output = file.read()
tmp = re.search(r'(?m)^mu_gamma=.*',output).group()
s = re.findall(r"[-+]?\d*\.\d+|\d+", tmp)
mu_gammaValue = float(s[0])
print("mu_gamma:", mu_gammaValue)
mu_gamma.append(mu_gammaValue)
# ------------end of for-loop -----------------
print("(Output) Values of mu_gamma: ", mu_gamma)
# ----------------end of if-statement -------------
# mu_gamma=[2.06099, 1.90567, 1.905]
# mu_gamma=[2.08306, 1.905, 1.90482, 1.90479, 1.90478, 1.90477]
##Gamma_Values = np.linspace(0.01, 20, num=12) :
#mu_gamma= [2.08306, 1.91108, 1.90648, 1.90554, 1.90521, 1.90505, 1.90496, 1.90491, 1.90487, 1.90485, 1.90483, 1.90482]
##Gamma_Values = np.linspace(0.01, 2.5, num=12)
# mu_gamma=[2.08306, 2.01137, 1.96113, 1.93772, 1.92592, 1.91937, 1.91541, 1.91286, 1.91112, 1.90988, 1.90897, 1.90828]
# Make Plot
plt.figure()
plt.title(r'$\mu_\gamma(\gamma)$-Plot') # USE MATHEMATICAL EXPRESSIONS IN TITLE
# plt.plot(Gamma_Values, mu_gamma, 'r--')
plt.plot(Gamma_Values, mu_gamma)
plt.scatter(Gamma_Values, mu_gamma)
# plt.axis([0, 6, 0, 20])
# # Plot q1, q2 "points"
# plt.plot(0,2.08333,'o-')
# plt.plot(Gamma_Values[-1],1.90476,'o-')
# plt.annotate('$q_1$', (0,2.08333))
# plt.annotate('$q_2$', (Gamma_Values[-1],1.90476))
# # plt.plot(0,2.08333,'bs')
# # plt.plot(Gamma_Values[-1],1.90476,'g^')
# plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5), #location beeing annotated and the location of the text
# arrowprops=dict(facecolor='black', shrink=0.05),
# )
plt.axhline(y = 1.90476, color = 'b', linestyle = ':', label='$q_1$')
plt.axhline(y = 2.08333, color = 'r', linestyle = 'dashed', label='$q_2$')
plt.xlabel("$\gamma$")
plt.ylabel("$\mu_\gamma$")
plt.legend()
plt.show()
# SubPlot Diagram ----
# Gamma_Values1 = np.linspace(0.01, 20, num=12)
# Gamma_Values2 = np.linspace(0.01, 2.5, num=12)
# mu_gamma1 = [2.08306, 1.91108, 1.90648, 1.90554, 1.90521, 1.90505, 1.90496, 1.90491, 1.90487, 1.90485, 1.90483, 1.90482]
# mu_gamma2 = [2.08306, 2.01137, 1.96113, 1.93772, 1.92592, 1.91937, 1.91541, 1.91286, 1.91112, 1.90988, 1.90897, 1.90828]
#
# plt.figure()
#
# plt.subplot(211)
# plt.title(r'$\mu_\gamma$')
# plt.plot(Gamma_Values1 , mu_gamma1)
# plt.plot(0,2.08333,'o-')
# plt.plot(Gamma_Values1[-1],1.90476,'o-')
# plt.annotate('$q_1$', (0,2.08333))
# plt.annotate('$q_2$', (Gamma_Values1[-1],1.90476))
#
# plt.subplot(212)
# plt.title(r'$\mu_\gamma$')
# plt.plot(Gamma_Values2 , mu_gamma2)
# plt.plot(0,2.08333,'o-')
# plt.plot(Gamma_Values2[-1],1.90476,'o-')
# plt.annotate('$q_1$', (0,2.08333))
# plt.annotate('$q_2$', (Gamma_Values2[-1],1.90476))
# plt.show()
# ------------- RUN Matlab symbolic minimization program
eng = matlab.engine.start_matlab()
s = eng.genpath('Matlab-Programs')
eng.addpath(s, nargout=0)
eng.Minimization_Script(nargout=0) #Name of program:Minimization_Script
#
# #---------------------------------------------------------------
# CellProblem_Output = subprocess.run(['./build-cmake/src/dune-microstructure', './inputs/cellsolver.parset'],
# capture_output=True, text=True)
#
# print("--------- first run ------- \n", CellProblem_Output.stdout) # Print Cell-Problem Output
# # -----------CHANGE VALUES IN THE PARSET : -----------------
# with open(InputFilePath, 'r') as file:
# filedata = file.read()
# print(filedata)
# filedata=re.sub('(?m)^gamma=.*','gamma=51.0',filedata)
# f = open(InputFilePath,'w')
# f.write(filedata)
# print(filedata)
# f.close()
# # # ---------------------------------------------------------
# CellProblem_Output = subprocess.run(['./build-cmake/src/dune-microstructure', './inputs/cellsolver.parset'], capture_output=True, text=True)
#
# print("--------- second run ------- \n", CellProblem_Output.stdout) # Print Cell-Problem Output
#
# # --- Output
# with open(OutputFilePath, 'r') as file:
# output = file.read()
# print(output)
# print("TESTING SEARCH MU_GAMMA: \n")
# tmp = re.search(r'(?m)^mu_gamma=.*',output).group()
# print(tmp)
# s = re.findall(r"[-+]?\d*\.\d+|\d+", tmp)
# # print(s)
# # print(s[0])
# mu_gamma = float(s[0])
# # print(type(mu_gamma))
# #---------------------------------------------------------------