Skip to content
Snippets Groups Projects
Commit d8445aca authored by Klaus Böhnlein's avatar Klaus Böhnlein
Browse files

CellScript.py: combine Cell-Problem with symMinimization for Input:Gamma

parent 016d5c36
Branches
No related tags found
No related merge requests found
......@@ -7,13 +7,14 @@ import subprocess
import fileinput
import re
import matlab.engine
import time
# from subprocess import Popen, PIPE
#import sys
print('Running Python Code')
InputFile = "/inputs/cellsolver.parset"
OutputFile = "/outputs/output.txt"
# path = os.getcwd()
......@@ -31,8 +32,9 @@ print("OutputFilepath: ", OutputFilePath)
print("Path: ", path)
#1. Define Gamma-Array..
#2. for(i=0; i<length(array)) ..compute mu_gamma..
#1. Define Inputs Gamma-Array..
#2. for(i=0; i<length(array)) ..compute Q_hom, B_eff from Cell-Problem
#3
# matrix = np.loadtxt(path + 'Qmatrix.txt', usecols=range(3))
# print(matrix)
......@@ -43,18 +45,17 @@ print("Path: ", path)
#---------------------------------------------------------------
Gamma_Values = np.linspace(0.01, 2.5, num=12)
print(Gamma_Values)
Gamma_Values = np.linspace(0.01, 2.5, num=6) # TODO variable Input Parameters...alpha,beta...
print('(Input) Gamma_Values:', Gamma_Values)
mu_gamma = []
# mu_gamma.append(1)
# np.append(mu_gamma,[[1]])
print("Values for Gamma:", mu_gamma)
# --- Options
RUN = True
# RUN = False
# make_Plot = False
make_Plot = True
if RUN:
for gamma in Gamma_Values:
......@@ -66,9 +67,15 @@ if RUN:
f = open(InputFilePath,'w')
f.write(filedata)
f.close()
# Run Cell-Problem
subprocess.run(['./build-cmake/src/dune-microstructure', './inputs/cellsolver.parset'],
# --- Run Cell-Problem
t = time.time()
subprocess.run(['./build-cmake/src/Cell-Problem', './inputs/cellsolver.parset'],
capture_output=True, text=True)
# --- Run Cell-Problem_muGama -> much faster!!!
# subprocess.run(['./build-cmake/src/Cell-Problem_muGamma', './inputs/cellsolver.parset'],
# capture_output=True, text=True)
print('elapsed time:', time.time() - t)
#Extract mu_gamma from Output-File
with open(OutputFilePath, 'r') as file:
output = file.read()
......@@ -90,100 +97,43 @@ if RUN:
##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]
Gamma_Values = np.linspace(0.01, 2.5, num=6)
mu_gamma=[2.08306, 1.95497, 1.92287, 1.91375, 1.9101, 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()
if make_Plot:
plt.figure()
plt.title(r'$\mu_\gamma(\gamma)$-Plot')
plt.plot(Gamma_Values, mu_gamma)
plt.scatter(Gamma_Values, mu_gamma)
# plt.axis([0, 6, 0, 20])
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()
# ------------- RUN Matlab symbolic minimization program
eng = matlab.engine.start_matlab()
s = eng.genpath('Matlab-Programs')
# s = eng.genpath(path + '/Matlab-Programs')
s = eng.genpath(path)
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))
# #---------------------------------------------------------------
# print('current Matlab folder:', eng.pwd(nargout=1))
eng.cd('Matlab-Programs', nargout=0) #switch to Matlab-Programs folder
# print('current Matlab folder:', eng.pwd(nargout=1))
Inp = False
print('Run symbolic Minimization...')
G, angle, type, kappa = eng.symMinimization(Inp,Inp,Inp,Inp, nargout=4) #Name of program:symMinimization
# G, angle, type, kappa = eng.symMinimization(Inp,Inp,Inp,Inp,path + "/outputs", nargout=4) #Optional: add Path
G = np.asarray(G) #cast Matlab Outout to numpy array
# --- print Output ---
print('Minimizer G:')
print(G)
print('angle:', angle)
print('type:', type )
print('curvature:', kappa)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment