Merge remote-tracking branch 'origin/development' into modernize-testing

This commit is contained in:
Martin Diehl 2020-11-01 10:06:52 +01:00
commit 946da2379b
6 changed files with 28 additions and 27 deletions

View File

@ -1 +1 @@
v3.0.0-alpha-594-g46e5023f8 v3.0.0-alpha-615-gfce116aa8

2
env/DAMASK.csh vendored
View File

@ -51,4 +51,4 @@ else
setenv PYTHONPATH $DAMASK_ROOT/python:$PYTHONPATH setenv PYTHONPATH $DAMASK_ROOT/python:$PYTHONPATH
endif endif
setenv MSC_ROOT setenv MSC_ROOT
setenv MARC_VERSION setenv MSC_VERSION

View File

@ -7,15 +7,15 @@ from pathlib import Path
import damask import damask
marc_version = float(damask.environment.options['MSC_VERSION']) msc_version = float(damask.environment.options['MSC_VERSION'])
if int(marc_version) == marc_version: if int(msc_version) == msc_version:
marc_version = int(marc_version) msc_version = int(msc_version)
msc_root = Path(damask.environment.options['MSC_ROOT']) msc_root = Path(damask.environment.options['MSC_ROOT'])
damask_root = damask.environment.root_dir damask_root = damask.environment.root_dir
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Apply DAMASK modification to MSC.Marc/Mentat', description='Apply DAMASK modification to MSC.Marc/Mentat',
epilog = f'MSC_ROOT={msc_root} and MSC_VERSION={marc_version} (from {damask_root}/env/CONFIG)') epilog = f'MSC_ROOT={msc_root} and MSC_VERSION={msc_version} (from {damask_root}/env/CONFIG)')
parser.add_argument('--editor', dest='editor', metavar='string', default='vi', parser.add_argument('--editor', dest='editor', metavar='string', default='vi',
help='Name of the editor for MSC.Mentat (executable)') help='Name of the editor for MSC.Mentat (executable)')
@ -24,7 +24,7 @@ def copy_and_replace(in_file,dst):
with open(in_file) as f: with open(in_file) as f:
content = f.read() content = f.read()
content = content.replace('%INSTALLDIR%',str(msc_root)) content = content.replace('%INSTALLDIR%',str(msc_root))
content = content.replace('%VERSION%',str(marc_version)) content = content.replace('%VERSION%',str(msc_version))
content = content.replace('%EDITOR%', parser.parse_args().editor) content = content.replace('%EDITOR%', parser.parse_args().editor)
with open(dst/Path(in_file).name,'w') as f: with open(dst/Path(in_file).name,'w') as f:
f.write(content) f.write(content)
@ -32,36 +32,36 @@ def copy_and_replace(in_file,dst):
print('adapting Marc tools...\n') print('adapting Marc tools...\n')
src = damask_root/f'installation/mods_MarcMentat/{marc_version}/Marc_tools' src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Marc_tools'
dst = msc_root/f'marc{marc_version}/tools' dst = msc_root/f'marc{msc_version}/tools'
for in_file in glob.glob(str(src/'*damask*')) + [str(src/'include_linux64')]: for in_file in glob.glob(str(src/'*damask*')) + [str(src/'include_linux64')]:
copy_and_replace(in_file,dst) copy_and_replace(in_file,dst)
print('adapting Mentat scripts and menus...\n') print('adapting Mentat scripts and menus...\n')
src = damask_root/f'installation/mods_MarcMentat/{marc_version}/Mentat_bin' src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_bin'
dst = msc_root/f'mentat{marc_version}/bin' dst = msc_root/f'mentat{msc_version}/bin'
for in_file in glob.glob(str(src/'*[!.original]')): for in_file in glob.glob(str(src/'*[!.original]')):
copy_and_replace(in_file,dst) copy_and_replace(in_file,dst)
src = damask_root/f'installation/mods_MarcMentat/{marc_version}/Mentat_menus' src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_menus'
dst = msc_root/f'mentat{marc_version}/menus' dst = msc_root/f'mentat{msc_version}/menus'
for in_file in glob.glob(str(src/'job_run.ms')): for in_file in glob.glob(str(src/'job_run.ms')):
copy_and_replace(in_file,dst) copy_and_replace(in_file,dst)
print('compiling Mentat menu binaries...') print('compiling Mentat menu binaries...')
executable = str(msc_root/f'mentat{marc_version}/bin/mentat') executable = str(msc_root/f'mentat{msc_version}/bin/mentat')
menu_file = str(msc_root/f'mentat{marc_version}/menus/linux64/main.msb') menu_file = str(msc_root/f'mentat{msc_version}/menus/linux64/main.msb')
os.system(f'xvfb-run {executable} -compile {menu_file}') os.system(f'xvfb-run {executable} -compile {menu_file}')
print('setting file access rights...\n') print('setting file access rights...\n')
for pattern in [msc_root/f'marc{marc_version}/tools/*damask*', for pattern in [msc_root/f'marc{msc_version}/tools/*damask*',
msc_root/f'mentat{marc_version}/bin/submit?', msc_root/f'mentat{msc_version}/bin/submit?',
msc_root/f'mentat{marc_version}/bin/kill?']: msc_root/f'mentat{msc_version}/bin/kill?']:
for f in glob.glob(str(pattern)): for f in glob.glob(str(pattern)):
os.chmod(f,0o755) os.chmod(f,0o755)

View File

@ -69,8 +69,8 @@ class ConfigMaterial(Config):
_,idx = np.unique(np.hstack(list({**constituents_,**kwargs_}.values())),return_index=True,axis=0) _,idx = np.unique(np.hstack(list({**constituents_,**kwargs_}.values())),return_index=True,axis=0)
idx = np.sort(idx) idx = np.sort(idx)
constituents_ = {k:v[idx].squeeze() for k,v in constituents_.items()} constituents_ = {k:np.atleast_1d(v[idx].squeeze()) for k,v in constituents_.items()}
kwargs_ = {k:v[idx].squeeze() for k,v in kwargs_.items()} kwargs_ = {k:np.atleast_1d(v[idx].squeeze()) for k,v in kwargs_.items()}
return ConfigMaterial().material_add(constituents_,**kwargs_) return ConfigMaterial().material_add(constituents_,**kwargs_)
@ -268,6 +268,7 @@ class ConfigMaterial(Config):
@staticmethod @staticmethod
def _constituents(N=1,**kwargs): def _constituents(N=1,**kwargs):
"""Construct list of constituents.""" """Construct list of constituents."""
N_material=1
for v in kwargs.values(): for v in kwargs.values():
if hasattr(v,'__len__') and not isinstance(v,str): N_material = len(v) if hasattr(v,'__len__') and not isinstance(v,str): N_material = len(v)

View File

@ -266,13 +266,9 @@ class Geom:
labels_ = [labels] if isinstance(labels,str) else labels labels_ = [labels] if isinstance(labels,str) else labels
unique,unique_inverse = np.unique(np.hstack([table.get(l) for l in labels_]),return_inverse=True,axis=0) unique,unique_inverse = np.unique(np.hstack([table.get(l) for l in labels_]),return_inverse=True,axis=0)
if len(unique) == grid.prod():
ma = np.arange(grid.prod()) ma = np.arange(grid.prod()) if len(unique) == grid.prod() else \
else: np.arange(unique.size)[np.argsort(pd.unique(unique_inverse))][unique_inverse]
from_ma = pd.unique(unique_inverse)
sort_idx = np.argsort(from_ma)
idx = np.searchsorted(from_ma,unique_inverse,sorter = sort_idx)
ma = np.arange(from_ma.size)[sort_idx][idx]
return Geom(ma.reshape(grid,order='F'),size,origin,util.execution_stamp('Geom','from_table')) return Geom(ma.reshape(grid,order='F'),size,origin,util.execution_stamp('Geom','from_table'))

View File

@ -87,3 +87,7 @@ class TestConfigMaterial:
c = m['constituents'][0] c = m['constituents'][0]
assert m['c'] == 1 and c['b'] == 0 and c['a'] == [i,1] assert m['c'] == 1 and c['b'] == 0 and c['a'] == [i,1]
def test__constituents(self):
c = ConfigMaterial._constituents(c=1,v=[2,3])
assert c[0][0]['c'] == c[1][0]['c'] == 1
assert c[0][0]['v'] == c[1][0]['v'] -1 ==2