Forked from
Klaus Böhnlein / dune-microstructure
474 commits behind, 263 commits ahead of the upstream repository.
-
Klaus Böhnlein authoredKlaus Böhnlein authored
microstructure_testsuite.py 5.79 KiB
import subprocess
import re
import os
import numpy as np
import matplotlib.pyplot as plt
import math
import fileinput
import time
import matplotlib.ticker as tickers
import matplotlib as mpl
from matplotlib.ticker import MultipleLocator,FormatStrFormatter,MaxNLocator
import codecs
import sys
from helper_functions import *
import threading
#-------------------------------------------------------------------------------------------------------
########################
#### SET PARAMETERS ####
########################
# ----- Setup Paths -----
# outputPath = ' ../outputs'
outputPath = os.path.dirname(os.getcwd()) + '/outputs'
QFilePath = os.path.dirname(os.getcwd()) + '/outputs/QMatrix.txt'
BFilePath = os.path.dirname(os.getcwd())+ '/outputs/BMatrix.txt'
ParsetFilePath = os.path.dirname(os.getcwd()) +"/inputs/cellsolver.parset"
parset = ' ../inputs/cellsolver.parset'
executable = ' ../build-cmake/src/Cell-Problem'
print('outputPath:', outputPath)
# ----- Define Input parameters --------------------
phases = 2 # number of phases
# --- Setup Material & Prestrain parameters:
mu_ = np.array([1.0, 3.0]) # Vector of [mu1, mu2 , ....]
lambda_ = np.array([1.0, 3.0]) # Vector of [lambda1, lambda2 , ....]
rho_ = np.array([1.0, 8.0]) # Vector of [rho1, rho2 , ....]
assert phases == np.size(mu_)== np.size(lambda_) == np.size(rho_) , "Number of Phases must align with number of material and prestrain parameters!"
gamma=1.0 #scale ratio
# ---------------------------------------------------
# --- Choose grid-Level for computation:
gridLevel = 2
#############################################
# Choose preferred Geometry/Prestrain/Material //TODO: Add Option for more Phases
#############################################
if phases == 1:
material_prestrain_imp= "homogeneous"
elif phases == 2:
material_prestrain_imp= "two_phase_material_1" #read as a python-function
# material_prestrain_imp= "two_phase_material_2" #read as a python-function
# material_prestrain_imp= "two_phase_material_3" #read as a python-function
# elif phases== 3: #//TODO:
# material_prestrain_imp= "three_phase_material" #read as a python-function
#############################################
# Solver Type: #1: CG - SOLVER (default), #2: GMRES - SOLVER, #3: QR - SOLVER
#############################################
Solvertype = 1 #(default = 1)
Solver_verbosity = 0 #(default = 2) degree of information for solver output
set_IntegralZero = True
#############################################
# Output-Options
#############################################
write_materialFunctions = True
write_prestrainFunctions = True
write_VTK = False
write_L2Error = False
write_IntegralMean = False
# write_LOG = False # writes Cell-Problem output-LOG in "Cell-Problem_output.log"
write_LOG = True # writes Cell-Problem output-LOG in "Cell-Problem_output.log"
#---- Some of the old Material definitions use the following input parameters: (not needed when using "two_phase_material_x"): --------
mu1 = mu_[0]
mu2 = mu_[1]
lambda1 = lambda_[0]
lambda2 = lambda_[1]
rho1 = rho_[0]
rho2 = rho_[1]
beta = mu_[1]/mu_[0] #ratio between material parameters
alpha= rho_[1]/rho_[0] #prestrain-contrast
theta = 1.0/4.0 #(volume fraction) needed for some of the older material definitions. Doesn't matter when using a indicatorFunction
# ---------------------------------------------------
print('---- Input parameters: -----')
print('mu1: ', mu1)
print('mu2: ', mu2)
print('lambda1: ', lambda1)
print('lambda2: ', lambda2)
print('rho1: ', rho1)
print('rho2: ', rho2)
print('alpha: ', alpha)
print('beta: ', beta)
print('theta: ', theta)
print('gamma:', gamma)
print('material_prestrain_imp: ', material_prestrain_imp)
print('gridLevel: ', gridLevel)
print('---------------------------------------------------------')
###########################################################################################################
#Set Parameters
SetParametersCellProblem(mu_,lambda_,rho_,alpha,beta,theta,gamma,gridLevel, ParsetFilePath, outputPath)
#Run Cell-Problem
thread = threading.Thread(target=run_CellProblem(executable,
parset,
gridLevel,
gamma,
mu1,
lambda1,
rho1,
alpha,
beta,
theta,
material_prestrain_imp,
outputPath,
write_materialFunctions,
write_prestrainFunctions,
write_VTK,
write_L2Error,
write_IntegralMean,
write_LOG
)
)
thread.start()
# wait here for the result to be available before continuing
thread.join()
print('---------------------------------------------------------')
#Read effective quantities
print('Read effective quantities...')
Q, B = ReadEffectiveQuantities(QFilePath,BFilePath)
# Q, B = ReadEffectiveQuantities()
print('Q:', Q)
print('---------------------------------------------------------')
print('B:', B)
print('---------------------------------------------------------')
print('access entries')
print('Q[1][1]',Q[1][1])
print('B[2]',B[2])