2010-10-26 20:32:20 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2011-11-09 23:34:51 +05:30
|
|
|
# Makes postprocessing routines acessible from everywhere.
|
2010-10-26 20:32:20 +05:30
|
|
|
|
2012-11-14 00:42:00 +05:30
|
|
|
import os,sys,glob,string,subprocess
|
2012-01-04 16:36:24 +05:30
|
|
|
from damask import Environment
|
2011-12-06 22:28:17 +05:30
|
|
|
from optparse import OptionParser, Option
|
2010-10-26 20:32:20 +05:30
|
|
|
|
2011-11-09 21:50:52 +05:30
|
|
|
|
2011-12-06 22:28:17 +05:30
|
|
|
# -----------------------------
|
|
|
|
class extendableOption(Option):
|
|
|
|
# -----------------------------
|
|
|
|
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
|
|
|
# taken from online tutorial http://docs.python.org/library/optparse.html
|
|
|
|
|
|
|
|
ACTIONS = Option.ACTIONS + ("extend",)
|
|
|
|
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
|
|
|
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
|
|
|
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
|
|
|
|
|
|
|
def take_action(self, action, dest, opt, value, values, parser):
|
|
|
|
if action == "extend":
|
|
|
|
lvalue = value.split(",")
|
|
|
|
values.ensure_value(dest, []).extend(lvalue)
|
|
|
|
else:
|
|
|
|
Option.take_action(self, action, dest, opt, value, values, parser)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
########################################################
|
|
|
|
# MAIN
|
|
|
|
########################################################
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=extendableOption, usage='%prog options', description = """
|
|
|
|
Sets up the pre and post processing tools of DAMASK
|
|
|
|
|
2012-01-12 01:48:47 +05:30
|
|
|
""" + string.replace('$Id$','\n','\\n')
|
2011-12-06 22:28:17 +05:30
|
|
|
)
|
|
|
|
|
2011-12-22 16:06:59 +05:30
|
|
|
compilers = ['intel','ifort','intel32','gfortran','gnu95']
|
|
|
|
|
2012-01-20 02:11:08 +05:30
|
|
|
parser.add_option('--F90', '--f90', dest='compiler', type='string', \
|
2011-12-22 16:06:59 +05:30
|
|
|
help='name of F90 compiler')
|
2012-11-14 00:42:00 +05:30
|
|
|
parser.set_defaults(compiler = {True:'ifort',False:'gfortran'}[\
|
|
|
|
subprocess.call(['which', 'ifort'],\
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0])
|
2011-12-06 22:28:17 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2011-12-22 16:06:59 +05:30
|
|
|
if options.compiler not in compilers:
|
2012-01-04 16:36:24 +05:30
|
|
|
parser.error('compiler switch "--F90" has to be one out of: %s'%(', '.join(compilers)))
|
2011-12-07 00:08:03 +05:30
|
|
|
|
2011-12-22 16:06:59 +05:30
|
|
|
f2py_compiler = {
|
2012-09-13 17:50:00 +05:30
|
|
|
'gfortran': 'gnu95 --f90flags="-fno-range-check -xf95-cpp-input -std=f2008 -fall-intrinsics -DSpectral -fdefault-real-8 -fdefault-double-8 -DFLOAT=8 -DINT=4 -I${DAMASK_ROOT}/lib"',
|
|
|
|
'gnu95': 'gnu95 --f90flags="-fno-range-check -xf95-cpp-input -std=f2008 -fall-intrinsics -DSpectral -fdefault-real-8 -fdefault-double-8 -DFLOAT=8 -DINT=4 -I${DAMASK_ROOT}/lib"',
|
2012-08-28 21:38:17 +05:30
|
|
|
'intel32': 'intel --f90flags="-fpp -stand f03 -diag-disable 5268 -assume byterecl -DSpectral -real-size 64 -integer-size 32 -DFLOAT=8 -DINT=4 -I${DAMASK_ROOT}/lib"',
|
|
|
|
'intel': 'intelem --f90flags="-fpp -stand f03 -diag-disable 5268 -assume byterecl -DSpectral -real-size 64 -integer-size 32 -DFLOAT=8 -DINT=4 -I${DAMASK_ROOT}/lib"',
|
|
|
|
'ifort': 'intelem --f90flags="-fpp -stand f03 -diag-disable 5268 -assume byterecl -DSpectral -real-size 64 -integer-size 32 -DFLOAT=8 -DINT=4 -I${DAMASK_ROOT}/lib"',
|
2011-12-22 16:06:59 +05:30
|
|
|
}[options.compiler]
|
2012-01-06 15:30:22 +05:30
|
|
|
compiler = {
|
|
|
|
'gfortran': 'gfortran',
|
|
|
|
'gnu95': 'gfortran',
|
|
|
|
'intel32': 'ifort',
|
|
|
|
'intel': 'ifort',
|
|
|
|
'ifort': 'ifort',
|
|
|
|
}[options.compiler]
|
2011-12-06 22:28:17 +05:30
|
|
|
|
2012-01-04 16:36:24 +05:30
|
|
|
damaskEnv = Environment()
|
2011-12-15 14:23:18 +05:30
|
|
|
baseDir = damaskEnv.relPath('processing/')
|
|
|
|
codeDir = damaskEnv.relPath('code/')
|
2011-12-06 22:28:17 +05:30
|
|
|
|
2011-12-22 16:06:59 +05:30
|
|
|
if 'ikml' in damaskEnv.pathInfo and damaskEnv.pathInfo['ikml'] != '':
|
|
|
|
lib_lapack = '' # TODO!!
|
|
|
|
elif 'acml' in damaskEnv.pathInfo and damaskEnv.pathInfo['acml'] != '':
|
2012-01-06 16:11:01 +05:30
|
|
|
lib_lapack = '-L%s/%s64/lib -lacml'%(os.path.join(damaskEnv.pathInfo['acml']),compiler) # can we use linker flag?
|
2011-12-22 16:06:59 +05:30
|
|
|
elif 'lapack' in damaskEnv.pathInfo and damaskEnv.pathInfo['lapack'] != '':
|
|
|
|
lib_lapack = '-L%s -llapack'%(damaskEnv.pathInfo['lapack']) # see http://cens.ioc.ee/pipermail/f2py-users/2003-December/000621.html
|
|
|
|
|
2011-12-06 22:28:17 +05:30
|
|
|
#define ToDo list
|
2011-01-26 20:47:03 +05:30
|
|
|
bin_link = { \
|
2011-11-09 23:21:00 +05:30
|
|
|
'pre' : [
|
|
|
|
'marc_addUserOutput.py',
|
|
|
|
'mentat_pbcOnBoxMesh.py',
|
|
|
|
'mentat_spectralBox.py',
|
2012-09-13 17:50:00 +05:30
|
|
|
'OIMang_hex2cub.py',
|
2011-11-09 23:21:00 +05:30
|
|
|
'patchFromReconstructedBoundaries.py',
|
2012-11-07 22:22:10 +05:30
|
|
|
'randomSeeding.py',
|
2012-11-08 21:59:26 +05:30
|
|
|
'geom_fromAng.py',
|
2012-11-07 22:22:10 +05:30
|
|
|
'geom_fromMinimalSurface.py',
|
|
|
|
'geom_fromVoronoiTessellation.py',
|
2012-11-06 02:49:12 +05:30
|
|
|
'geom_canvas.py',
|
|
|
|
'geom_check.py',
|
|
|
|
'geom_rescale.py',
|
|
|
|
'geom_pack.py',
|
|
|
|
'geom_unpack.py',
|
|
|
|
'geom_translate.py',
|
|
|
|
'geom_vicinityOffset.py',
|
2012-11-30 03:27:07 +05:30
|
|
|
'geom_euclideanDistance'
|
2011-11-09 23:21:00 +05:30
|
|
|
],
|
|
|
|
'post' : [
|
|
|
|
'3Dvisualize.py',
|
|
|
|
'addCauchy.py',
|
2011-12-02 20:45:36 +05:30
|
|
|
'addCalculation.py',
|
2011-11-09 23:21:00 +05:30
|
|
|
'addDeterminant.py',
|
2012-11-14 16:16:51 +05:30
|
|
|
'addDeviator.py',
|
2012-11-24 03:19:30 +05:30
|
|
|
'addSpectralDecomposition.py',
|
2011-11-09 23:21:00 +05:30
|
|
|
'addDivergence.py',
|
2011-12-21 22:55:31 +05:30
|
|
|
'addCurl.py',
|
2011-11-09 23:21:00 +05:30
|
|
|
'addMises.py',
|
|
|
|
'addNorm.py',
|
2012-06-12 19:39:16 +05:30
|
|
|
'addPK2.py',
|
2011-11-09 23:21:00 +05:30
|
|
|
'addStrainTensors.py',
|
|
|
|
'addCompatibilityMismatch.py',
|
2012-04-18 17:12:57 +05:30
|
|
|
'addDeformedConfiguration.py',
|
2011-11-09 23:21:00 +05:30
|
|
|
'averageDown.py',
|
2012-05-08 00:39:11 +05:30
|
|
|
'binXY.py',
|
2012-02-14 17:34:37 +05:30
|
|
|
'deleteColumn.py',
|
2012-02-23 19:26:50 +05:30
|
|
|
'deleteInfo.py',
|
2012-11-30 13:56:13 +05:30
|
|
|
'showTable.py',
|
2012-02-16 14:06:35 +05:30
|
|
|
'filterTable.py',
|
2011-11-09 23:21:00 +05:30
|
|
|
'mentat_colorMap.py',
|
|
|
|
'postResults.py',
|
2012-02-16 20:45:43 +05:30
|
|
|
'spectral_parseLog.py',
|
2012-08-30 22:31:46 +05:30
|
|
|
'nodesFromCentroids.py',
|
2012-02-24 14:23:19 +05:30
|
|
|
'tagLabel.py',
|
2012-08-30 22:31:46 +05:30
|
|
|
'table2ang',
|
2011-11-09 23:21:00 +05:30
|
|
|
],
|
|
|
|
}
|
2010-10-26 20:32:20 +05:30
|
|
|
|
2011-01-26 20:47:03 +05:30
|
|
|
compile = { \
|
2011-11-09 23:21:00 +05:30
|
|
|
'pre' : [
|
|
|
|
],
|
|
|
|
'post' : [
|
|
|
|
],
|
|
|
|
}
|
2011-12-06 22:28:17 +05:30
|
|
|
|
2011-01-26 20:47:03 +05:30
|
|
|
|
2011-03-11 14:50:37 +05:30
|
|
|
execute = { \
|
2012-07-17 18:53:39 +05:30
|
|
|
'coreModule' : [
|
2011-12-22 16:06:59 +05:30
|
|
|
'make tidy',
|
2012-07-17 18:53:39 +05:30
|
|
|
# The following command is used to compile the fortran files and make the functions defined
|
|
|
|
# in damask.core.pyf available for python in the module core.so
|
2011-12-06 22:28:17 +05:30
|
|
|
# It uses the fortran wrapper f2py that is included in the numpy package to construct the
|
2012-06-25 14:36:09 +05:30
|
|
|
# module core.so out of the fortran code in the f90 files
|
2012-07-17 18:53:39 +05:30
|
|
|
# For the generation of the pyf file use the following lines:
|
|
|
|
###########################################################################
|
|
|
|
#'f2py -h damask.core.pyf' +\
|
|
|
|
#' --overwrite-signature --no-lower prec.f90 DAMASK_spectral_interface.f90 math.f90 mesh.f90',
|
|
|
|
###########################################################################
|
2012-10-25 13:25:27 +05:30
|
|
|
'rm `readlink -f %s`' %(os.path.join(damaskEnv.relPath('lib/damask'),'core.so')),
|
2012-07-17 18:53:39 +05:30
|
|
|
'f2py damask.core.pyf' +\
|
2012-07-18 18:01:07 +05:30
|
|
|
' --build-dir ./' +\
|
2012-06-25 14:36:09 +05:30
|
|
|
' -c --no-lower --fcompiler=%s'%(f2py_compiler) +\
|
2012-07-17 18:53:39 +05:30
|
|
|
' %s'%'prec.f90'+\
|
|
|
|
' %s'%'DAMASK_spectral_interface.f90'+\
|
|
|
|
' %s'%'IO.f90'+\
|
|
|
|
' %s'%'numerics.f90'+\
|
|
|
|
' %s'%'debug.f90'+\
|
|
|
|
' %s'%'math.f90'+\
|
|
|
|
' %s'%'FEsolving.f90'+\
|
|
|
|
' %s'%'mesh.f90'+\
|
|
|
|
' %s'%'spectral_quit.f90'+\
|
2012-01-06 16:11:01 +05:30
|
|
|
' -L%s/lib -lfftw3'%(damaskEnv.pathInfo['fftw'])+\
|
2011-12-22 16:06:59 +05:30
|
|
|
' %s'%lib_lapack,
|
2012-01-20 02:11:08 +05:30
|
|
|
'mv %s `readlink -f %s`' %(os.path.join(codeDir,'core.so'),os.path.join(damaskEnv.relPath('lib/damask'),'core.so')),
|
2011-12-06 22:28:17 +05:30
|
|
|
]
|
2011-11-09 23:21:00 +05:30
|
|
|
}
|
2011-03-11 14:50:37 +05:30
|
|
|
|
2011-11-09 21:07:45 +05:30
|
|
|
|
2012-10-25 13:25:27 +05:30
|
|
|
for dir in compile: #there is nothing to compile at the moment
|
2011-12-06 22:28:17 +05:30
|
|
|
for file in compile[dir]:
|
|
|
|
src = os.path.abspath(os.path.join(baseDir,dir,file))
|
|
|
|
if os.path.isfile(src):
|
|
|
|
try:
|
|
|
|
os.system('rm %s.exe'%(os.path.splitext(src)[0]))
|
|
|
|
print 'removing %s.exe '%(os.path.splitext(src)[0])
|
|
|
|
except:
|
|
|
|
pass
|
2012-01-06 15:30:22 +05:30
|
|
|
print 'compiling ',src,'using',compiler
|
2012-01-12 19:16:35 +05:30
|
|
|
os.system('%s -O2 -o %s.exe %s'%(compiler,os.path.splitext(src)[0],src))
|
2011-12-06 22:28:17 +05:30
|
|
|
|
|
|
|
os.chdir(codeDir) # needed for compilation with gfortran and f2py
|
|
|
|
for tasks in execute:
|
|
|
|
for cmd in execute[tasks]:
|
2011-12-22 16:06:59 +05:30
|
|
|
try:
|
|
|
|
print 'executing...:',cmd
|
|
|
|
os.system(cmd)
|
|
|
|
except:
|
|
|
|
print 'failed..!'
|
|
|
|
pass
|
2011-12-06 22:28:17 +05:30
|
|
|
|
2011-12-22 16:06:59 +05:30
|
|
|
os.chdir(damaskEnv.relPath('processing/setup/'))
|
2011-12-06 22:28:17 +05:30
|
|
|
modules = glob.glob('*.mod')
|
|
|
|
for module in modules:
|
|
|
|
print 'removing', module
|
|
|
|
os.remove(module)
|
|
|
|
|
2011-01-26 20:47:03 +05:30
|
|
|
for dir in bin_link:
|
|
|
|
for file in bin_link[dir]:
|
2011-12-06 22:28:17 +05:30
|
|
|
src = os.path.abspath(os.path.join(baseDir,dir,file))
|
2010-10-26 20:32:20 +05:30
|
|
|
if (file == ''):
|
2011-12-15 14:23:18 +05:30
|
|
|
sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),dir))
|
2010-10-26 20:32:20 +05:30
|
|
|
else:
|
2011-12-15 14:23:18 +05:30
|
|
|
sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),os.path.splitext(file)[0]))
|
2011-11-09 21:50:52 +05:30
|
|
|
print sym_link,'-->',src
|
|
|
|
if os.path.lexists(sym_link):
|
|
|
|
os.remove(sym_link)
|
|
|
|
os.symlink(src,sym_link)
|
2012-10-25 13:25:27 +05:30
|
|
|
|
|
|
|
#check if compilation of core module was successful
|
|
|
|
try:
|
|
|
|
with open(damaskEnv.relPath('lib/damask/core.so')) as f: pass
|
|
|
|
except IOError as e:
|
|
|
|
print '*********\n* core.so not found, compilation of core modules was not successful\n*********'
|
|
|
|
sys.exit()
|
|
|
|
f.close
|