damask.Environment reads from os.environ; python module is packaging-ready

This commit is contained in:
Philip Eisenlohr 2020-01-13 17:26:40 -05:00
parent edbee3a419
commit 86f27df0b2
18 changed files with 119 additions and 173 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
*.hdf5
*.bak
*~
.DS_Store
bin
PRIVATE
build

View File

@ -4,7 +4,7 @@ SHELL = /bin/sh
########################################################################################
DAMASK_ROOT = $(shell python -c "import os,sys; print(os.path.normpath(os.path.realpath(os.path.expanduser('$(pwd)'))))")
.PHONY: all
all: grid mesh python processing
all: grid mesh processing
.PHONY: grid
grid: build/grid
@ -35,8 +35,3 @@ clean:
.PHONY: processing
processing:
@./installation/symlink_Processing.py ${MAKEFLAGS}
.PHONY: python
python:
@pip install --user ./python

@ -1 +1 @@
Subproject commit 036faecca39b46fd2328597ca858cbb04e37f79a
Subproject commit 12de3e01e3dfa407a724b6aeca51c78e9981b80d

View File

11
env/DAMASK.csh vendored
View File

@ -2,15 +2,14 @@
# usage: source DAMASK_env.csh
set CALLED=($_)
set DIRNAME=`dirname $CALLED[2]`
set DAMASK_ROOT=`python -c "import os,sys; print(os.path.realpath(os.path.expanduser(sys.argv[1])))" $DIRNAME"/../"`
set ENV_ROOT=`dirname $CALLED[2]`
set DAMASK_ROOT=`python -c "import os,sys; print(os.path.realpath(os.path.expanduser(sys.argv[1])))" $ENV_ROOT"/../"`
source $DAMASK_ROOT/CONFIG
source $ENV_ROOT/CONFIG
set path = ($DAMASK_ROOT/bin $path)
set SOLVER=`which DAMASK_spectral`
set PROCESSING=`which postResults`
if ( "x$DAMASK_NUM_THREADS" == "x" ) then
set DAMASK_NUM_THREADS=1
endif
@ -32,7 +31,6 @@ if ( $?prompt ) then
echo Using environment with ...
echo "DAMASK $DAMASK_ROOT"
echo "Grid Solver $SOLVER"
echo "Post Processing $PROCESSING"
if ( $?PETSC_DIR) then
echo "PETSc location $PETSC_DIR"
endif
@ -52,3 +50,6 @@ if ( ! $?PYTHONPATH ) then
else
setenv PYTHONPATH $DAMASK_ROOT/python:$PYTHONPATH
endif
setenv MSC_ROOT
setenv ABAQUS_VERSION
setenv MARC_VERSION

22
env/DAMASK.sh vendored
View File

@ -10,14 +10,14 @@ function blink {
}
if [ "$OSTYPE" == "linux-gnu" ] || [ "$OSTYPE" == 'linux' ]; then
DAMASK_ROOT=$(dirname $BASH_SOURCE)
ENV_ROOT=$(dirname $BASH_SOURCE)
else
[[ "${BASH_SOURCE::1}" == "/" ]] && BASE="" || BASE="$(pwd)/"
STAT=$(stat "$(dirname $BASE$BASH_SOURCE)")
DAMASK_ROOT=${STAT##* }
ENV_ROOT=${STAT##* }
fi
DAMASK_ROOT=$(canonicalPath "$DAMASK_ROOT/../")
DAMASK_ROOT=$(canonicalPath "$ENV_ROOT/../")
# shorthand command to change to DAMASK_ROOT directory
@ -27,7 +27,7 @@ eval "function DAMASK_root() { cd $DAMASK_ROOT; }"
set() {
export $1$2$3
}
source $DAMASK_ROOT/CONFIG
source $ENV_ROOT/CONFIG
unset -f set
# add BRANCH if DAMASK_ROOT is a git repository
@ -38,9 +38,6 @@ PATH=${DAMASK_ROOT}/bin:$PATH
SOLVER=$(type -p DAMASK_spectral || true 2>/dev/null)
[ "x$SOLVER" == "x" ] && SOLVER=$(blink 'Not found!')
PROCESSING=$(type -p postResults || true 2>/dev/null)
[ "x$PROCESSING" == "x" ] && PROCESSING=$(blink 'Not found!')
[ "x$DAMASK_NUM_THREADS" == "x" ] && DAMASK_NUM_THREADS=1
# currently, there is no information that unlimited stack size causes problems
@ -60,7 +57,6 @@ if [ ! -z "$PS1" ]; then
echo Using environment with ...
echo "DAMASK $DAMASK_ROOT $BRANCH"
echo "Grid Solver $SOLVER"
echo "Post Processing $PROCESSING"
if [ "x$PETSC_DIR" != "x" ]; then
echo -n "PETSc location "
[ -d $PETSC_DIR ] && echo $PETSC_DIR || blink $PETSC_DIR
@ -93,12 +89,8 @@ fi
export DAMASK_NUM_THREADS
export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH
for var in BASE STAT SOLVER PROCESSING BRANCH; do
for var in BASE STAT SOLVER BRANCH; do
unset "${var}"
done
for var in DAMASK MSC; do
unset "${var}_ROOT"
done
for var in ABAQUS MARC; do
unset "${var}_VERSION"
done
unset "ENV_ROOT"
unset "DAMASK_ROOT"

17
env/DAMASK.zsh vendored
View File

@ -9,6 +9,7 @@ function blink {
echo -e "\033[2;5m$1\033[0m"
}
ENV_ROOT=$(canonicalPath "${0:a:h}")
DAMASK_ROOT=$(canonicalPath "${0:a:h}'/..")
# shorthand command to change to DAMASK_ROOT directory
@ -18,7 +19,7 @@ eval "function DAMASK_root() { cd $DAMASK_ROOT; }"
set() {
export $1$2$3
}
source $DAMASK_ROOT/CONFIG
source $ENV_ROOT/CONFIG
unset -f set
# add BRANCH if DAMASK_ROOT is a git repository
@ -29,9 +30,6 @@ PATH=${DAMASK_ROOT}/bin:$PATH
SOLVER=$(which DAMASK_spectral || true 2>/dev/null)
[[ "x$SOLVER" == "x" ]] && SOLVER=$(blink 'Not found!')
PROCESSING=$(which postResults || true 2>/dev/null)
[[ "x$PROCESSING" == "x" ]] && PROCESSING=$(blink 'Not found!')
[[ "x$DAMASK_NUM_THREADS" == "x" ]] && DAMASK_NUM_THREADS=1
# currently, there is no information that unlimited stack size causes problems
@ -51,7 +49,6 @@ if [ ! -z "$PS1" ]; then
echo "Using environment with ..."
echo "DAMASK $DAMASK_ROOT $BRANCH"
echo "Grid Solver $SOLVER"
echo "Post Processing $PROCESSING"
if [ "x$PETSC_DIR" != "x" ]; then
echo -n "PETSc location "
[ -d $PETSC_DIR ] && echo $PETSC_DIR || blink $PETSC_DIR
@ -86,12 +83,8 @@ fi
export DAMASK_NUM_THREADS
export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH
for var in SOLVER PROCESSING BRANCH; do
for var in SOLVER BRANCH; do
unset "${var}"
done
for var in DAMASK MSC; do
unset "${var}_ROOT"
done
for var in ABAQUS MARC; do
unset "${var}_VERSION"
done
unset "ENV_ROOT"
unset "DAMASK_ROOT"

View File

@ -2,11 +2,6 @@
SCRIPTLOCATION="$( cd "$( dirname "$0" )" && pwd )"
DAMASK_ROOT=$SCRIPTLOCATION/../../
# defining set() allows to source the same file for tcsh and bash, with and without space around =
set() {
export $1$2$3
}
source $DAMASK_ROOT/CONFIG
if [ "x$MSC_ROOT" != "x" ]; then
DEFAULT_DIR=$MSC_ROOT
@ -15,7 +10,7 @@ if [ "x$MARC_VERSION" != "x" ]; then
DEFAULT_VERSION=$MARC_VERSION
fi
if [ "x$DAMASK_BIN" != "x" ]; then
BIN_DIR=$DAMASK_BIN
BIN_DIR=$DAMASK_ROOT/bin
fi
while [ ! -d "$SCRIPTLOCATION/$VERSION" ] || [ -z "$VERSION" ]

View File

@ -1,3 +1,2 @@
include damask/README
include damask/VERSION
include damask/LICENSE

View File

@ -1,14 +0,0 @@
Copyright 2011-19 Max-Planck-Institut für Eisenforschung GmbH
DAMASK is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

1
python/damask/LICENSE Symbolic link
View File

@ -0,0 +1 @@
../../LICENSE

View File

@ -1,13 +0,0 @@
DAMASK - The Düsseldorf Advanced Material Simulation Kit
Visit damask.mpie.de for installation and usage instructions
CONTACT INFORMATION
Max-Planck-Institut für Eisenforschung GmbH
Max-Planck-Str. 1
40237 Düsseldorf
Germany
Email: DAMASK@mpie.de
https://damask.mpie.de
https://magit1.mpie.de

View File

@ -1 +0,0 @@
0.9.0

1
python/damask/VERSION Symbolic link
View File

@ -0,0 +1 @@
../../VERSION

View File

@ -1,5 +1,4 @@
import os
import re
class Environment():
__slots__ = [ \
@ -18,12 +17,9 @@ class Environment():
return os.path.normpath(os.path.join(os.path.realpath(__file__),'../../../'))
def get_options(self):
with open(self.relPath(self.rootDir()+'/CONFIG')) as configFile:
for line in configFile:
line = line.strip()
line = line[4:] if line.startswith('set ') else line # remove "set" (tcsh) when setting variables
if line and not line.startswith('#'):
items = re.split(r'\s*=\s*',line)
if len(items) == 2:
self.options[items[0].upper()] = \
re.sub(r'\${?DAMASK_ROOT}?',self.rootDir(),os.path.expandvars(items[1])) # expand all shell variables and DAMASK_ROOT
for item in ['DAMASK_NUM_THREADS',
'MSC_ROOT',
'MARC_VERSION',
'ABAQUS_VERSION',
]:
self.options[item] = os.environ[item] if item in os.environ else None

View File

@ -5,29 +5,35 @@ import damask
class Abaqus(Solver):
"""Wrapper to run DAMASK with Abaqus."""
"""Wrapper to run DAMASK with Abaqus."""
def __init__(self,version=int(damask.Environment().options['ABAQUS_VERSION'])):
"""
Create a Abaqus solver object.
def __init__(self,version=None):
"""
Create a Abaqus solver object.
Parameters
----------
version : integer
Abaqus version
Parameters
----------
version : integer
Abaqus version
"""
self.solver = 'Abaqus'
self.version = int(version)
"""
self.solver = 'Abaqus'
try:
self.version = int(version)
except TypeError:
try:
self.version = int(damask.Environment().options['ABAQUS_VERSION'])
except TypeError:
self.version = -1
def return_run_command(self,model):
try:
cmd = 'abq'+self.version
subprocess.check_output([cmd,'information=release'])
except OSError: # link to abqXXX not existing
cmd = 'abaqus'
process = subprocess.Popen([cmd,'information=release'],stdout = subprocess.PIPE,stderr = subprocess.PIPE)
detectedVersion = int(process.stdout.readlines()[1].split()[1].decode('utf-8'))
if self.version != detectedVersion:
raise Exception('found Abaqus version {}, but requested {}'.format(detectedVersion,self.version))
return '{} -job {} -user {}/src/DAMASK_abaqus interactive'.format(cmd,model,damask.Environment().rootDir())
def return_run_command(self,model):
try:
cmd = 'abq{}'.format(self.version)
subprocess.check_output([cmd,'information=release'])
except OSError: # link to abqXXX not existing
cmd = 'abaqus'
process = subprocess.Popen([cmd,'information=release'],stdout = subprocess.PIPE,stderr = subprocess.PIPE)
detectedVersion = int(process.stdout.readlines()[1].split()[1].decode('utf-8'))
if self.version != detectedVersion:
raise Exception('found Abaqus version {}, but requested {}'.format(detectedVersion,self.version))
return '{} -job {} -user {}/src/DAMASK_abaqus interactive'.format(cmd,model,damask.Environment().rootDir())

View File

@ -1,88 +1,94 @@
import os
import subprocess
import shlex
import string
from .solver import Solver
import damask
class Marc(Solver):
"""Wrapper to run DAMASK with MSCMarc."""
"""Wrapper to run DAMASK with MSCMarc."""
def __init__(self,version=damask.Environment().options['MARC_VERSION']):
"""
Create a Marc solver object.
def __init__(self,version=damask.Environment().options['MARC_VERSION']):
"""
Create a Marc solver object.
Parameters
----------
version : float
Marc version
Parameters
----------
version : float
Marc version
"""
self.solver = 'Marc'
self.version = damask.Environment().options['MARC_VERSION']
"""
self.solver = 'Marc'
try:
self.version = int(version)
except TypeError:
try:
self.version = int(damask.Environment().options['MARC_VERSION'])
except TypeError:
self.version = -1
#--------------------------
def libraryPath(self):
def libraryPath(self):
path_MSC = damask.Environment().options['MSC_ROOT']
path_lib = '{}/mentat{}/shlib/linux64'.format(path_MSC,self.version)
path_MSC = damask.Environment().options['MSC_ROOT']
path_lib = '{}/mentat{}/shlib/linux64'.format(path_MSC,self.version)
return path_lib if os.path.exists(path_lib) else ''
return path_lib if os.path.exists(path_lib) else ''
#--------------------------
def toolsPath(self):
def toolsPath(self):
path_MSC = damask.Environment().options['MSC_ROOT']
path_tools = '{}/marc{}/tools'.format(path_MSC,self.version)
path_MSC = damask.Environment().options['MSC_ROOT']
path_tools = '{}/marc{}/tools'.format(path_MSC,self.version)
return path_tools if os.path.exists(path_tools) else ''
return path_tools if os.path.exists(path_tools) else ''
#--------------------------
def submit_job(self,
model,
job = 'job1',
logfile = False,
compile = False,
optimization = '',
):
def submit_job(self,
model,
job = 'job1',
logfile = False,
compile = False,
optimization = '',
):
damaskEnv = damask.Environment()
damaskEnv = damask.Environment()
user = os.path.join(damaskEnv.relPath('src'),'DAMASK_marc{}.{}'.format(self.version,'f90' if compile else 'marc'))
if not os.path.isfile(user):
raise FileNotFoundError("DAMASK4Marc ({}) '{}' not found".format(('source' if compile else 'binary'),user))
user = os.path.join(damaskEnv.relPath('src'),'DAMASK_marc{}.{}'.format(self.version,'f90' if compile else 'marc'))
if not os.path.isfile(user):
raise FileNotFoundError("DAMASK4Marc ({}) '{}' not found".format(('source' if compile else 'binary'),user))
# Define options [see Marc Installation and Operation Guide, pp 23]
script = 'run_damask_{}mp'.format(optimization)
# Define options [see Marc Installation and Operation Guide, pp 23]
script = 'run_damask_{}mp'.format(optimization)
cmd = os.path.join(self.toolsPath(),script) + \
' -jid ' + model + '_' + job + \
' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
cmd = os.path.join(self.toolsPath(),script) + \
' -jid ' + model + '_' + job + \
' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
if compile: cmd += ' -u ' + user + ' -save y'
else: cmd += ' -prog ' + os.path.splitext(user)[0]
if compile: cmd += ' -u ' + user + ' -save y'
else: cmd += ' -prog ' + os.path.splitext(user)[0]
print('job submission {} compilation: {}'.format('with' if compile else 'without',user))
if logfile: log = open(logfile, 'w')
print(cmd)
process = subprocess.Popen(shlex.split(cmd),stdout = log,stderr = subprocess.STDOUT)
log.close()
process.wait()
print('job submission {} compilation: {}'.format('with' if compile else 'without',user))
if logfile: log = open(logfile, 'w')
print(cmd)
process = subprocess.Popen(shlex.split(cmd),stdout = log,stderr = subprocess.STDOUT)
log.close()
process.wait()
#--------------------------
def exit_number_from_outFile(self,outFile=None):
import string
exitnumber = -1
with open(outFile,'r') as fid_out:
for line in fid_out:
if (string.find(line,'tress iteration') != -1):
print(line)
elif (string.find(line,'Exit number') != -1):
substr = line[string.find(line,'Exit number'):len(line)]
exitnumber = int(substr[12:16])
def exit_number_from_outFile(self,outFile=None):
exitnumber = -1
with open(outFile,'r') as fid_out:
for line in fid_out:
if (string.find(line,'tress iteration') != -1):
print(line)
elif (string.find(line,'Exit number') != -1):
substr = line[string.find(line,'Exit number'):len(line)]
exitnumber = int(substr[12:16])
return exitnumber
return exitnumber

View File

@ -1,12 +0,0 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR
VERSION=$(head -n1 damask/VERSION)
read -p "updated version [${VERSION}]: " UP
echo ${UP:-$VERSION} > damask/VERSION
rm -rf dist/
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*

View File

@ -3,7 +3,7 @@ import os
import re
with open(os.path.join(os.path.dirname(__file__),'damask/VERSION')) as f:
version = re.sub(r'^v','',f.readline().strip())
version = re.sub(r'(-([^-]*)).*$',r'.\2',re.sub(r'^v(\d+\.\d+(\.\d+)?)',r'\1',f.readline().strip()))
setuptools.setup(
name="damask",