From a7d998dd48896fc4cd2d9c1b41589bdc9186f331 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 13 Jan 2021 12:48:20 +0100 Subject: [PATCH 1/7] standard name --- env/CONFIG | 6 +++--- env/DAMASK.csh | 8 ++++---- env/DAMASK.sh | 6 +++--- env/DAMASK.zsh | 6 +++--- python/damask/_environment.py | 5 +---- python/damask/_grid.py | 14 +++++++------- python/damask/_result.py | 3 +-- src/parallelization.f90 | 20 ++++++++++---------- 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/env/CONFIG b/env/CONFIG index 52057526a..4407f4d2b 100644 --- a/env/CONFIG +++ b/env/CONFIG @@ -1,5 +1,5 @@ # "set"-syntax needed only for tcsh (but works with bash and zsh) -set DAMASK_NUM_THREADS = 4 +set OMP_NUM_THREADS = 4 -set MSC_ROOT = /opt/msc -set MSC_VERSION = 2020 +set MSC_ROOT = /opt/msc +set MSC_VERSION = 2020 diff --git a/env/DAMASK.csh b/env/DAMASK.csh index cc61449d2..58f2a150e 100644 --- a/env/DAMASK.csh +++ b/env/DAMASK.csh @@ -10,8 +10,8 @@ source $ENV_ROOT/CONFIG set path = ($DAMASK_ROOT/bin $path) set SOLVER=`which DAMASK_grid` -if ( "x$DAMASK_NUM_THREADS" == "x" ) then - set DAMASK_NUM_THREADS=1 +if ( "x$OMP_NUM_THREADS" == "x" ) then + set OMP_NUM_THREADS=1 endif # currently, there is no information that unlimited stack size causes problems @@ -38,13 +38,13 @@ if ( $?prompt ) then echo "MSC.Marc/Mentat $MSC_ROOT" endif echo - echo "Multithreading DAMASK_NUM_THREADS=$DAMASK_NUM_THREADS" + echo "Multithreading OMP_NUM_THREADS=$OMP_NUM_THREADS" echo `limit datasize` echo `limit stacksize` echo endif -setenv DAMASK_NUM_THREADS $DAMASK_NUM_THREADS +setenv OMP_NUM_THREADS $OMP_NUM_THREADS if ( ! $?PYTHONPATH ) then setenv PYTHONPATH $DAMASK_ROOT/python else diff --git a/env/DAMASK.sh b/env/DAMASK.sh index 2151e842b..24a2c2de3 100644 --- a/env/DAMASK.sh +++ b/env/DAMASK.sh @@ -38,7 +38,7 @@ PATH=${DAMASK_ROOT}/bin:$PATH SOLVER=$(type -p DAMASK_grid || true 2>/dev/null) [ "x$SOLVER" == "x" ] && SOLVER=$(blink 'Not found!') -[ "x$DAMASK_NUM_THREADS" == "x" ] && DAMASK_NUM_THREADS=1 +[ "x$OMP_NUM_THREADS" == "x" ] && OMP_NUM_THREADS=1 # currently, there is no information that unlimited stack size causes problems # still, http://software.intel.com/en-us/forums/topic/501500 suggest to fix it @@ -66,7 +66,7 @@ if [ ! -z "$PS1" ]; then echo -n "MSC.Marc/Mentat " [ -d $MSC_ROOT ] && echo $MSC_ROOT || blink $MSC_ROOT echo - echo "Multithreading DAMASK_NUM_THREADS=$DAMASK_NUM_THREADS" + echo "Multithreading OMP_NUM_THREADS=$OMP_NUM_THREADS" echo -n "heap size " [[ "$(ulimit -d)" == "unlimited" ]] \ && echo "unlimited" \ @@ -86,7 +86,7 @@ if [ ! -z "$PS1" ]; then echo fi -export DAMASK_NUM_THREADS +export OMP_NUM_THREADS export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH for var in BASE STAT SOLVER BRANCH; do diff --git a/env/DAMASK.zsh b/env/DAMASK.zsh index 377aa5304..e12a5248a 100644 --- a/env/DAMASK.zsh +++ b/env/DAMASK.zsh @@ -30,7 +30,7 @@ PATH=${DAMASK_ROOT}/bin:$PATH SOLVER=$(which DAMASK_grid || true 2>/dev/null) [[ "x$SOLVER" == "x" ]] && SOLVER=$(blink 'Not found!') -[[ "x$DAMASK_NUM_THREADS" == "x" ]] && DAMASK_NUM_THREADS=1 +[[ "x$OMP_NUM_THREADS" == "x" ]] && OMP_NUM_THREADS=1 # currently, there is no information that unlimited stack size causes problems # still, http://software.intel.com/en-us/forums/topic/501500 suggest to fix it @@ -60,7 +60,7 @@ if [ ! -z "$PS1" ]; then echo -n "MSC.Marc/Mentat " [ -d $MSC_ROOT ] && echo $MSC_ROOT || blink $MSC_ROOT echo - echo "Multithreading DAMASK_NUM_THREADS=$DAMASK_NUM_THREADS" + echo "Multithreading OMP_NUM_THREADS=$OMP_NUM_THREADS" echo -n "heap size " [[ "$(ulimit -d)" == "unlimited" ]] \ && echo "unlimited" \ @@ -80,7 +80,7 @@ if [ ! -z "$PS1" ]; then echo fi -export DAMASK_NUM_THREADS +export OMP_NUM_THREADS export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH for var in SOLVER BRANCH; do diff --git a/python/damask/_environment.py b/python/damask/_environment.py index 7d93b83e0..30110e7ae 100644 --- a/python/damask/_environment.py +++ b/python/damask/_environment.py @@ -26,10 +26,7 @@ class Environment: @property def options(self): options = {} - for item in ['DAMASK_NUM_THREADS', - 'MSC_ROOT', - 'MSC_VERSION', - ]: + for item in ['MSC_ROOT', 'MSC_VERSION']: options[item] = os.environ[item] if item in os.environ else None return options diff --git a/python/damask/_grid.py b/python/damask/_grid.py index 0edec05f9..2d3e59b37 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -1,7 +1,7 @@ import copy import multiprocessing as mp from functools import partial -from os import path +import os import warnings import numpy as np @@ -278,14 +278,14 @@ class Grid: """ root_dir ='DataContainers' f = h5py.File(fname, 'r') - g = path.join(root_dir,base_group,'_SIMPL_GEOMETRY') - cells = f[path.join(g,'DIMENSIONS')][()] - size = f[path.join(g,'SPACING')][()] * cells - origin = f[path.join(g,'ORIGIN')][()] + g = os.path.join(root_dir,base_group,'_SIMPL_GEOMETRY') + cells = f[os.path.join(g,'DIMENSIONS')][()] + size = f[os.path.join(g,'SPACING')][()] * cells + origin = f[os.path.join(g,'ORIGIN')][()] ma = np.arange(cells.prod(),dtype=int) \ if point_data is None else \ - np.reshape(f[path.join(root_dir,base_group,point_data,material)],cells.prod()) + np.reshape(f[os.path.join(root_dir,base_group,point_data,material)],cells.prod()) return Grid(ma.reshape(cells,order='F'),size,origin,util.execution_stamp('Grid','load_DREAM3D')) @@ -355,7 +355,7 @@ class Grid: seeds_p = seeds coords = grid_filters.coordinates0_point(cells,size).reshape(-1,3) - pool = mp.Pool(processes = int(environment.options['DAMASK_NUM_THREADS'])) + pool = mp.Pool(int(os.environ.get('OMP_NUM_THREADS',1))) result = pool.map_async(partial(Grid._find_closest_seed,seeds_p,weights_p), [coord for coord in coords]) pool.close() pool.join() diff --git a/python/damask/_result.py b/python/damask/_result.py index 5e37042e0..3f788f229 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -1134,8 +1134,7 @@ class Result: """ chunk_size = 1024**2//8 - num_threads = damask.environment.options['DAMASK_NUM_THREADS'] - pool = mp.Pool(int(num_threads) if num_threads is not None else None) + pool = mp.Pool(int(os.environ.get('OMP_NUM_THREADS',1))) lock = mp.Manager().Lock() groups = self.groups_with_datasets(datasets.values()) diff --git a/src/parallelization.f90 b/src/parallelization.f90 index 11a3574ec..edf56407b 100644 --- a/src/parallelization.f90 +++ b/src/parallelization.f90 @@ -32,7 +32,7 @@ contains subroutine parallelization_init integer :: err, typeSize -!$ integer :: got_env, DAMASK_NUM_THREADS, threadLevel +!$ integer :: got_env, OMP_NUM_THREADS, threadLevel !$ character(len=6) NumThreadsString #ifdef PETSc PetscErrorCode :: petsc_err @@ -87,19 +87,19 @@ call MPI_Comm_rank(PETSC_COMM_WORLD,worldrank,err) open(OUTPUT_UNIT,file='/dev/null',status='replace') ! close() alone will leave some temp files in cwd endif -!$ call get_environment_variable(name='DAMASK_NUM_THREADS',value=NumThreadsString,STATUS=got_env) +!$ call get_environment_variable(name='OMP_NUM_THREADS',value=NumThreadsString,STATUS=got_env) !$ if(got_env /= 0) then -!$ print*, 'Could not determine value of $DAMASK_NUM_THREADS' -!$ DAMASK_NUM_THREADS = 1_pI32 +!$ print*, 'Could not determine value of $OMP_NUM_THREADS' +!$ OMP_NUM_THREADS = 1_pI32 !$ else -!$ read(NumThreadsString,'(i6)') DAMASK_NUM_THREADS -!$ if (DAMASK_NUM_THREADS < 1_pI32) then -!$ print*, 'Invalid DAMASK_NUM_THREADS: '//trim(NumThreadsString) -!$ DAMASK_NUM_THREADS = 1_pI32 +!$ read(NumThreadsString,'(i6)') OMP_NUM_THREADS +!$ if (OMP_NUM_THREADS < 1_pI32) then +!$ print*, 'Invalid OMP_NUM_THREADS: '//trim(NumThreadsString) +!$ OMP_NUM_THREADS = 1_pI32 !$ endif !$ endif -!$ print'(a,i2)', ' DAMASK_NUM_THREADS: ',DAMASK_NUM_THREADS -!$ call omp_set_num_threads(DAMASK_NUM_THREADS) +!$ print'(a,i2)', ' OMP_NUM_THREADS: ',OMP_NUM_THREADS +!$ call omp_set_num_threads(OMP_NUM_THREADS) end subroutine parallelization_init From d76543f7590f8df2376de9f828b577f07f2acf54 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 13 Jan 2021 14:57:58 +0100 Subject: [PATCH 2/7] better name --- python/damask/_result.py | 98 ++++++++++++++++++------------------- python/tests/test_Result.py | 44 ++++++++--------- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index 3f788f229..3d8368911 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -80,12 +80,12 @@ class Result: self.out_type_ho += f['/'.join([self.increments[0],'homogenization',m])].keys() self.out_type_ho = list(set(self.out_type_ho)) # make unique - self.selection = {'increments': self.increments, - 'phases': self.phases, - 'homogenizations': self.homogenizations, - 'out_type_ph': self.out_type_ph, - 'out_type_ho': self.out_type_ho - } + self.visible = {'increments': self.increments, + 'phases': self.phases, + 'homogenizations': self.homogenizations, + 'out_type_ph': self.out_type_ph, + 'out_type_ho': self.out_type_ho + } self.fname = Path(fname).absolute() @@ -94,23 +94,23 @@ class Result: def __repr__(self): """Show summary of file content.""" - all_selected_increments = self.selection['increments'] + visible_increments = self.visible['increments'] - self.pick('increments',all_selected_increments[0:1]) + self.view('increments',visible_increments[0:1]) first = self.list_data() - self.pick('increments',all_selected_increments[-1:]) - last = '' if len(all_selected_increments) < 2 else self.list_data() + self.view('increments',visible_increments[-1:]) + last = '' if len(visible_increments) < 2 else self.list_data() - self.pick('increments',all_selected_increments) + self.view('increments',visible_increments) - in_between = '' if len(all_selected_increments) < 3 else \ - ''.join([f'\n{inc}\n ...\n' for inc in all_selected_increments[1:-2]]) + in_between = '' if len(visible_increments) < 3 else \ + ''.join([f'\n{inc}\n ...\n' for inc in visible_increments[1:-2]]) return util.srepr(first + in_between + last) - def _manage_selection(self,action,what,datasets): + def _manage_view(self,action,what,datasets): """ Manages the visibility of the groups. @@ -119,7 +119,7 @@ class Result: action : str Select from 'set', 'add', and 'del'. what : str - Attribute to change (must be from self.selection). + Attribute to change (must be in self.visible). datasets : list of str or bool Name of datasets as list, supports ? and * wildcards. True is equivalent to [*], False is equivalent to [] @@ -156,18 +156,18 @@ class Result: choice.append(self.increments[idx+1]) valid = [e for e_ in [glob.fnmatch.filter(getattr(self,what),s) for s in choice] for e in e_] - existing = set(self.selection[what]) + existing = set(self.visible[what]) if action == 'set': - self.selection[what] = valid + self.visible[what] = valid elif action == 'add': add = existing.union(valid) add_sorted = sorted(add, key=natural_sort) - self.selection[what] = add_sorted + self.visible[what] = add_sorted elif action == 'del': diff = existing.difference(valid) diff_sorted = sorted(diff, key=natural_sort) - self.selection[what] = diff_sorted + self.visible[what] = diff_sorted def _get_attribute(self,path,attr): @@ -245,72 +245,72 @@ class Result: def iterate(self,what): """ - Iterate over selection items by setting each one selected. + Iterate over visible items and view them independently. Parameters ---------- what : str - Attribute to change (must be from self.selection). + Attribute to change (must be from self.visible). """ - datasets = self.selection[what] - last_selection = datasets.copy() + datasets = self.visible[what] + last_view = datasets.copy() for dataset in datasets: - if last_selection != self.selection[what]: - self._manage_selection('set',what,datasets) + if last_view != self.visible[what]: + self._manage_view('set',what,datasets) raise Exception - self._manage_selection('set',what,dataset) - last_selection = self.selection[what] + self._manage_view('set',what,dataset) + last_view = self.visible[what] yield dataset - self._manage_selection('set',what,datasets) + self._manage_view('set',what,datasets) - def pick(self,what,datasets): + def view(self,what,datasets): """ - Set selection. + Set view. Parameters ---------- what : str - attribute to change (must be from self.selection) + attribute to change (must be from self.visible) datasets : list of str or bool name of datasets as list, supports ? and * wildcards. True is equivalent to [*], False is equivalent to [] """ - self._manage_selection('set',what,datasets) + self._manage_view('set',what,datasets) - def pick_more(self,what,datasets): + def view_more(self,what,datasets): """ - Add to selection. + Add to view. Parameters ---------- what : str - attribute to change (must be from self.selection) + attribute to change (must be from self.visible) datasets : list of str or bool name of datasets as list, supports ? and * wildcards. True is equivalent to [*], False is equivalent to [] """ - self._manage_selection('add',what,datasets) + self._manage_view('add',what,datasets) - def pick_less(self,what,datasets): + def view_less(self,what,datasets): """ - Delete from selection. + Delete from view. Parameters ---------- what : str - attribute to change (must be from self.selection) + attribute to change (must be from self.visible) datasets : list of str or bool name of datasets as list, supports ? and * wildcards. True is equivalent to [*], False is equivalent to [] """ - self._manage_selection('del',what,datasets) + self._manage_view('del',what,datasets) def rename(self,name_old,name_new): @@ -1189,8 +1189,8 @@ class Result: """ Write XDMF file to directly visualize data in DADF5 file. - This works only for scalar, 3-vector and 3x3-tensor data. - Selection is not taken into account. + The view is not taken into account, i.e. the content of the + whole file will be included. """ if self.N_constituents != 1 or len(self.phases) != 1 or not self.structured: raise TypeError('XDMF output requires homogeneous grid') @@ -1319,10 +1319,10 @@ class Result: N_digits = int(np.floor(np.log10(max(1,int(self.increments[-1][3:])))))+1 - for inc in util.show_progress(self.iterate('increments'),len(self.selection['increments'])): + for inc in util.show_progress(self.iterate('increments'),len(self.visible['increments'])): - picked_backup_ho = self.selection['homogenizations'].copy() - self.pick('homogenizations',False) + viewed_backup_ho = self.visible['homogenizations'].copy() + self.view('homogenizations',False) for label in (labels if isinstance(labels,list) else [labels]): for o in self.iterate('out_type_ph'): for c in range(self.N_constituents): @@ -1342,10 +1342,10 @@ class Result: ph_name = re.compile(r'(?<=(phase\/))(.*?)(?=(mechanics))') # identify phase name dset_name = prefix+re.sub(ph_name,r'',paths[0].split('/',1)[1]) # remove phase name v.add(array,dset_name+f' / {self._get_attribute(paths[0],"Unit")}') - self.pick('homogenizations',picked_backup_ho) + self.view('homogenizations',viewed_backup_ho) - picked_backup_ph = self.selection['phases'].copy() - self.pick('phases',False) + viewed_backup_ph = self.visible['phases'].copy() + self.view('phases',False) for label in (labels if isinstance(labels,list) else [labels]): for _ in self.iterate('out_type_ho'): paths = self.get_dataset_location(label) @@ -1353,7 +1353,7 @@ class Result: continue array = self.read_dataset(paths) v.add(array,paths[0].split('/',1)[1]+f' / {self._get_attribute(paths[0],"Unit")}') - self.pick('phases',picked_backup_ph) + self.view('phases',viewed_backup_ph) u = self.read_dataset(self.get_dataset_location('u_n' if mode.lower() == 'cell' else 'u_p')) v.add(u,'u') diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index b8447b8b0..9973e7e7c 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -21,7 +21,7 @@ def default(tmp_path,ref_path): fname = '12grains6x7x8_tensionY.hdf5' shutil.copy(ref_path/fname,tmp_path) f = Result(tmp_path/fname) - f.pick('times',20.0) + f.view('times',20.0) return f @pytest.fixture @@ -43,56 +43,56 @@ class TestResult: print(default) - def test_pick_all(self,default): - default.pick('increments',True) + def test_view_all(self,default): + default.view('increments',True) a = default.get_dataset_location('F') - default.pick('increments','*') + default.view('increments','*') b = default.get_dataset_location('F') - default.pick('increments',default.incs_in_range(0,np.iinfo(int).max)) + default.view('increments',default.incs_in_range(0,np.iinfo(int).max)) c = default.get_dataset_location('F') - default.pick('times',True) + default.view('times',True) d = default.get_dataset_location('F') - default.pick('times','*') + default.view('times','*') e = default.get_dataset_location('F') - default.pick('times',default.times_in_range(0.0,np.inf)) + default.view('times',default.times_in_range(0.0,np.inf)) f = default.get_dataset_location('F') assert a == b == c == d == e ==f @pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations - def test_pick_none(self,default,what): - default.pick(what,False) + def test_view_none(self,default,what): + default.view(what,False) a = default.get_dataset_location('F') - default.pick(what,[]) + default.view(what,[]) b = default.get_dataset_location('F') assert a == b == [] @pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations - def test_pick_more(self,default,what): - default.pick(what,False) - default.pick_more(what,'*') + def test_view_more(self,default,what): + default.view(what,False) + default.view_more(what,'*') a = default.get_dataset_location('F') - default.pick(what,True) + default.view(what,True) b = default.get_dataset_location('F') assert a == b @pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations - def test_pick_less(self,default,what): - default.pick(what,True) - default.pick_less(what,'*') + def test_view_less(self,default,what): + default.view(what,True) + default.view_less(what,'*') a = default.get_dataset_location('F') - default.pick(what,False) + default.view(what,False) b = default.get_dataset_location('F') assert a == b == [] - def test_pick_invalid(self,default): + def test_view_invalid(self,default): with pytest.raises(AttributeError): - default.pick('invalid',True) + default.view('invalid',True) def test_add_absolute(self,default): default.add_absolute('F_e') @@ -307,7 +307,7 @@ class TestResult: @pytest.mark.parametrize('overwrite',['off','on']) def test_add_overwrite(self,default,overwrite): - default.pick('times',default.times_in_range(0,np.inf)[-1]) + default.view('times',default.times_in_range(0,np.inf)[-1]) default.add_stress_Cauchy() loc = default.get_dataset_location('sigma') From 2cd5d96a904adafab7fb62219cb7fa391709edcc Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 13 Jan 2021 18:42:59 +0100 Subject: [PATCH 3/7] not really used, not needed by normal users --- env/DAMASK.csh | 54 -------------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 env/DAMASK.csh diff --git a/env/DAMASK.csh b/env/DAMASK.csh deleted file mode 100644 index 58f2a150e..000000000 --- a/env/DAMASK.csh +++ /dev/null @@ -1,54 +0,0 @@ -# sets up an environment for DAMASK on tcsh -# usage: source DAMASK_env.csh - -set CALLED=($_) -set ENV_ROOT=`dirname $CALLED[2]` -set DAMASK_ROOT=`python3 -c "import os,sys; print(os.path.realpath(os.path.expanduser(sys.argv[1])))" $ENV_ROOT"/../"` - -source $ENV_ROOT/CONFIG - -set path = ($DAMASK_ROOT/bin $path) - -set SOLVER=`which DAMASK_grid` -if ( "x$OMP_NUM_THREADS" == "x" ) then - set OMP_NUM_THREADS=1 -endif - -# currently, there is no information that unlimited stack size causes problems -# still, http://software.intel.com/en-us/forums/topic/501500 suggest to fix it -# more info https://jblevins.org/log/segfault -# https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap -# http://superuser.com/questions/220059/what-parameters-has-ulimit -limit stacksize unlimited # maximum stack size (kB) - -# disable output in case of scp -if ( $?prompt ) then - echo '' - echo Düsseldorf Advanced Materials Simulation Kit --- DAMASK - echo Max-Planck-Institut für Eisenforschung GmbH, Düsseldorf - echo https://damask.mpie.de - echo - echo Using environment with ... - echo "DAMASK $DAMASK_ROOT" - echo "Grid Solver $SOLVER" - if ( $?PETSC_DIR) then - echo "PETSc location $PETSC_DIR" - endif - if ( $?MSC_ROOT) then - echo "MSC.Marc/Mentat $MSC_ROOT" - endif - echo - echo "Multithreading OMP_NUM_THREADS=$OMP_NUM_THREADS" - echo `limit datasize` - echo `limit stacksize` - echo -endif - -setenv OMP_NUM_THREADS $OMP_NUM_THREADS -if ( ! $?PYTHONPATH ) then - setenv PYTHONPATH $DAMASK_ROOT/python -else - setenv PYTHONPATH $DAMASK_ROOT/python:$PYTHONPATH -endif -setenv MSC_ROOT -setenv MSC_VERSION From 37de561938cd7c4d048a5b1b3ad6b9cd8533766d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 13 Jan 2021 18:43:20 +0100 Subject: [PATCH 4/7] shell variables are more robust they will also work if Fortran and python code are installed in different locations. --- env/DAMASK.sh | 4 +++- env/DAMASK.zsh | 4 +++- .../mods_MarcMentat/apply_DAMASK_modifications.py | 2 +- python/damask/_environment.py | 8 +------- python/damask/_test.py | 2 +- python/damask/solver/_marc.py | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/env/DAMASK.sh b/env/DAMASK.sh index 24a2c2de3..f8ccfc1e0 100644 --- a/env/DAMASK.sh +++ b/env/DAMASK.sh @@ -87,10 +87,12 @@ if [ ! -z "$PS1" ]; then fi export OMP_NUM_THREADS +export MSC_ROOT +export MSC_VERSION +export DAMASK_ROOT export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH for var in BASE STAT SOLVER BRANCH; do unset "${var}" done unset "ENV_ROOT" -unset "DAMASK_ROOT" diff --git a/env/DAMASK.zsh b/env/DAMASK.zsh index e12a5248a..2c74657fd 100644 --- a/env/DAMASK.zsh +++ b/env/DAMASK.zsh @@ -81,10 +81,12 @@ if [ ! -z "$PS1" ]; then fi export OMP_NUM_THREADS +export MSC_ROOT +export MSC_VERSION +export DAMASK_ROOT export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH for var in SOLVER BRANCH; do unset "${var}" done unset "ENV_ROOT" -unset "DAMASK_ROOT" diff --git a/installation/mods_MarcMentat/apply_DAMASK_modifications.py b/installation/mods_MarcMentat/apply_DAMASK_modifications.py index 407c33558..1b430ca75 100755 --- a/installation/mods_MarcMentat/apply_DAMASK_modifications.py +++ b/installation/mods_MarcMentat/apply_DAMASK_modifications.py @@ -11,7 +11,7 @@ msc_version = float(damask.environment.options['MSC_VERSION']) if int(msc_version) == msc_version: msc_version = int(msc_version) msc_root = Path(damask.environment.options['MSC_ROOT']) -damask_root = damask.environment.root_dir +damask_root = damask.environment.options['DAMASK_ROOT'] parser = argparse.ArgumentParser( description='Apply DAMASK modification to MSC.Marc/Mentat', diff --git a/python/damask/_environment.py b/python/damask/_environment.py index 30110e7ae..556229f63 100644 --- a/python/damask/_environment.py +++ b/python/damask/_environment.py @@ -26,13 +26,7 @@ class Environment: @property def options(self): options = {} - for item in ['MSC_ROOT', 'MSC_VERSION']: + for item in ['DAMASK_ROOT', 'MSC_ROOT', 'MSC_VERSION']: options[item] = os.environ[item] if item in os.environ else None return options - - - @property - def root_dir(self): - """Return DAMASK root path.""" - return Path(__file__).parents[2] diff --git a/python/damask/_test.py b/python/damask/_test.py index 000b76e0e..cea9b3a70 100644 --- a/python/damask/_test.py +++ b/python/damask/_test.py @@ -180,7 +180,7 @@ class Test: def fileInRoot(self,dir,file): """Path to a file in the root directory of DAMASK.""" - return str(damask.environment.root_dir/dir/file) + return str(damask.environment.options['DAMASK_ROOT']/dir/file) def fileInReference(self,file): diff --git a/python/damask/solver/_marc.py b/python/damask/solver/_marc.py index 5ddcf8898..c1dc3220d 100644 --- a/python/damask/solver/_marc.py +++ b/python/damask/solver/_marc.py @@ -54,7 +54,7 @@ class Marc: optimization = '', ): - usersub = environment.root_dir/'src/DAMASK_marc' + usersub = environment.options['DAMASK_ROOT']/'src/DAMASK_marc' usersub = usersub.parent/(usersub.name + ('.f90' if compile else '.marc')) if not usersub.is_file(): raise FileNotFoundError(f'subroutine ({"source" if compile else "binary"}) "{usersub}" not found') From 0f6094890a1a4230aaf3ab4f26057fa89fec9d6c Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 14 Jan 2021 21:12:29 +0100 Subject: [PATCH 5/7] simplified damask.environment does not offer any advantage over os.environ for variables. After 'root_dir' was removed, the whole module became obsolete --- PRIVATE | 2 +- .../apply_DAMASK_modifications.py | 16 ++++------ installation/symlink_Processing.py | 8 ++--- processing/post/DADF5_postResults.py | 8 ++--- python/damask/__init__.py | 3 -- python/damask/_environment.py | 32 ------------------- python/damask/_grid.py | 1 - python/damask/_test.py | 3 +- python/damask/_vtk.py | 20 ++++++++++-- python/damask/solver/_marc.py | 15 +++------ 10 files changed, 39 insertions(+), 69 deletions(-) delete mode 100644 python/damask/_environment.py diff --git a/PRIVATE b/PRIVATE index b1a31a79c..7c0795bce 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit b1a31a79cc90d458494068a96cfd3e9497aa330c +Subproject commit 7c0795bce79d0d9d223d7df5559ad6e63d6c2de0 diff --git a/installation/mods_MarcMentat/apply_DAMASK_modifications.py b/installation/mods_MarcMentat/apply_DAMASK_modifications.py index 1b430ca75..1cd93c47c 100755 --- a/installation/mods_MarcMentat/apply_DAMASK_modifications.py +++ b/installation/mods_MarcMentat/apply_DAMASK_modifications.py @@ -5,13 +5,9 @@ import glob import argparse from pathlib import Path -import damask - -msc_version = float(damask.environment.options['MSC_VERSION']) -if int(msc_version) == msc_version: - msc_version = int(msc_version) -msc_root = Path(damask.environment.options['MSC_ROOT']) -damask_root = damask.environment.options['DAMASK_ROOT'] +msc_version = os.environ['MSC_VERSION'] +msc_root = Path(os.environ['MSC_ROOT']) +damask_root = Path(os.environ['DAMASK_ROOT']) parser = argparse.ArgumentParser( description='Apply DAMASK modification to MSC.Marc/Mentat', @@ -24,7 +20,7 @@ def copy_and_replace(in_file,dst): with open(in_file) as f: content = f.read() content = content.replace('%INSTALLDIR%',str(msc_root)) - content = content.replace('%VERSION%',str(msc_version)) + content = content.replace('%VERSION%', msc_version) content = content.replace('%EDITOR%', parser.parse_args().editor) with open(dst/Path(in_file).name,'w') as f: f.write(content) @@ -53,8 +49,8 @@ for in_file in glob.glob(str(src/'job_run.ms')): print('compiling Mentat menu binaries...') -executable = str(msc_root/f'mentat{msc_version}/bin/mentat') -menu_file = str(msc_root/f'mentat{msc_version}/menus/linux64/main.msb') +executable = msc_root/f'mentat{msc_version}/bin/mentat' +menu_file = msc_root/f'mentat{msc_version}/menus/linux64/main.msb' os.system(f'xvfb-run {executable} -compile {menu_file}') diff --git a/installation/symlink_Processing.py b/installation/symlink_Processing.py index c9cf6e32a..ef2274028 100755 --- a/installation/symlink_Processing.py +++ b/installation/symlink_Processing.py @@ -3,11 +3,9 @@ # Makes postprocessing routines accessible from everywhere. import sys from pathlib import Path +import os -import damask - -env = damask.Environment() -bin_dir = env.root_dir/Path('bin') +bin_dir = Path(os.environ['DAMASK_ROOT'])/'bin' if not bin_dir.exists(): bin_dir.mkdir() @@ -15,7 +13,7 @@ if not bin_dir.exists(): sys.stdout.write('\nsymbolic linking...\n') for sub_dir in ['pre','post']: - the_dir = env.root_dir/Path('processing')/Path(sub_dir) + the_dir = Path(os.environ['DAMASK_ROOT'])/'processing'/sub_dir for the_file in the_dir.glob('*.py'): src = the_dir/the_file diff --git a/processing/post/DADF5_postResults.py b/processing/post/DADF5_postResults.py index a1b162e3d..81babcc57 100755 --- a/processing/post/DADF5_postResults.py +++ b/processing/post/DADF5_postResults.py @@ -41,15 +41,15 @@ for filename in options.filenames: table = damask.Table(np.ones(np.product(results.cells),dtype=int)*int(inc[3:]),{'inc':(1,)})\ .add('pos',coords.reshape(-1,3)) - results.pick('homogenizations',False) - results.pick('phases',True) + results.view('homogenizations',False) + results.view('phases',True) for label in options.con: x = results.get_dataset_location(label) if len(x) != 0: table = table.add(label,results.read_dataset(x,0,plain=True).reshape(results.cells.prod(),-1)) - results.pick('phases',False) - results.pick('homogenizations',True) + results.view('phases',False) + results.view('homogenizations',True) for label in options.mat: x = results.get_dataset_location(label) if len(x) != 0: diff --git a/python/damask/__init__.py b/python/damask/__init__.py index fa1af9f4f..e356d0bc4 100644 --- a/python/damask/__init__.py +++ b/python/damask/__init__.py @@ -16,8 +16,6 @@ with open(_Path(__file__).parent/_Path('VERSION')) as _f: __version__ = version # make classes directly accessible as damask.Class -from ._environment import Environment as _ # noqa -environment = _() from . import util # noqa from . import seeds # noqa from . import tensor # noqa @@ -38,7 +36,6 @@ from ._result import Result # noqa # deprecated -Environment = _ from ._asciitable import ASCIItable # noqa from ._test import Test # noqa from .util import extendableOption # noqa diff --git a/python/damask/_environment.py b/python/damask/_environment.py deleted file mode 100644 index 556229f63..000000000 --- a/python/damask/_environment.py +++ /dev/null @@ -1,32 +0,0 @@ -import os -from pathlib import Path - -class Environment: - - @property - def screen_size(self): - try: - import wx - _ = wx.App(False) # noqa - width, height = wx.GetDisplaySize() - except ImportError: - try: - import tkinter - tk = tkinter.Tk() - width = tk.winfo_screenwidth() - height = tk.winfo_screenheight() - tk.destroy() - except Exception as e: - width = 1024 - height = 768 - - return (width,height) - - - @property - def options(self): - options = {} - for item in ['DAMASK_ROOT', 'MSC_ROOT', 'MSC_VERSION']: - options[item] = os.environ[item] if item in os.environ else None - - return options diff --git a/python/damask/_grid.py b/python/damask/_grid.py index 2d3e59b37..103538349 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -10,7 +10,6 @@ import h5py from scipy import ndimage, spatial from vtk.util.numpy_support import vtk_to_numpy as vtk_to_np -from . import environment from . import VTK from . import util from . import grid_filters diff --git a/python/damask/_test.py b/python/damask/_test.py index cea9b3a70..2f5dbde1f 100644 --- a/python/damask/_test.py +++ b/python/damask/_test.py @@ -5,6 +5,7 @@ import logging import logging.config from collections.abc import Iterable from optparse import OptionParser +from pathlib import Path import numpy as np @@ -180,7 +181,7 @@ class Test: def fileInRoot(self,dir,file): """Path to a file in the root directory of DAMASK.""" - return str(damask.environment.options['DAMASK_ROOT']/dir/file) + return str(Path(os.environ['DAMASK_ROOT'])/dir/file) def fileInReference(self,file): diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index 224412f7c..ad017ee1e 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -10,7 +10,6 @@ from vtk.util.numpy_support import numpy_to_vtkIdTypeArray as np_to_vtkIdTypeArr from vtk.util.numpy_support import vtk_to_numpy as vtk_to_np from . import util -from . import environment from . import Table @@ -348,6 +347,23 @@ class VTK: See http://compilatrix.com/article/vtk-1 for further ideas. """ + def screen_size(): + try: + import wx + _ = wx.App(False) # noqa + width, height = wx.GetDisplaySize() + except ImportError: + try: + import tkinter + tk = tkinter.Tk() + width = tk.winfo_screenwidth() + height = tk.winfo_screenheight() + tk.destroy() + except Exception as e: + width = 1024 + height = 768 + + return (width,height) mapper = vtk.vtkDataSetMapper() mapper.SetInputData(self.vtk_data) actor = vtk.vtkActor() @@ -361,7 +377,7 @@ class VTK: ren.AddActor(actor) ren.SetBackground(0.2,0.2,0.2) - window.SetSize(environment.screen_size[0],environment.screen_size[1]) + window.SetSize(screen_size[0],screen_size[1]) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(window) diff --git a/python/damask/solver/_marc.py b/python/damask/solver/_marc.py index c1dc3220d..d4aadb7ff 100644 --- a/python/damask/solver/_marc.py +++ b/python/damask/solver/_marc.py @@ -2,14 +2,13 @@ import subprocess import shlex import re import io +import os from pathlib import Path -from .. import environment - class Marc: """Wrapper to run DAMASK with MSCMarc.""" - def __init__(self,version=environment.options['MSC_VERSION']): + def __init__(self,version=os.environ['MSC_VERSION']): """ Create a Marc solver object. @@ -25,9 +24,7 @@ class Marc: @property def library_path(self): - path_MSC = environment.options['MSC_ROOT'] - path_lib = Path(f'{path_MSC}/mentat{self.version}/shlib/linux64') - + path_lib = Path(f'{os.environ["MSC_ROOT"]}/mentat{self.version}/shlib/linux64') if not path_lib.is_dir(): raise FileNotFoundError(f'library path "{path_lib}" not found') @@ -37,9 +34,7 @@ class Marc: @property def tools_path(self): - path_MSC = environment.options['MSC_ROOT'] - path_tools = Path(f'{path_MSC}/marc{self.version}/tools') - + path_tools = Path(f'{os.environ["MSC_ROOT"]}/marc{self.version}/tools') if not path_tools.is_dir(): raise FileNotFoundError(f'tools path "{path_tools}" not found') @@ -54,7 +49,7 @@ class Marc: optimization = '', ): - usersub = environment.options['DAMASK_ROOT']/'src/DAMASK_marc' + usersub = Path(os.environ['DAMASK_ROOT'])/'src/DAMASK_marc' usersub = usersub.parent/(usersub.name + ('.f90' if compile else '.marc')) if not usersub.is_file(): raise FileNotFoundError(f'subroutine ({"source" if compile else "binary"}) "{usersub}" not found') From d1eb650f541c508b4e87290a9b0059ed26be48e6 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 15 Jan 2021 21:04:09 +0100 Subject: [PATCH 6/7] polished tests --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 7c0795bce..9e8011876 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 7c0795bce79d0d9d223d7df5559ad6e63d6c2de0 +Subproject commit 9e8011876b16896a18902737790eba8018e94f85 From 7a7c0c2dfb160cebef943e07729c36732072fb74 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 18 Jan 2021 15:18:27 +0100 Subject: [PATCH 7/7] polished PRIVATE --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 9e8011876..3ab1053b8 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 9e8011876b16896a18902737790eba8018e94f85 +Subproject commit 3ab1053b8c83248dc8654a22a3caea815c0813db