simplified

damask.environment does not offer any advantage over os.environ for
variables. After 'root_dir' was removed, the whole module became
obsolete
This commit is contained in:
Martin Diehl 2021-01-14 21:12:29 +01:00
parent 0e3462f3e0
commit 0f6094890a
10 changed files with 39 additions and 69 deletions

@ -1 +1 @@
Subproject commit b1a31a79cc90d458494068a96cfd3e9497aa330c
Subproject commit 7c0795bce79d0d9d223d7df5559ad6e63d6c2de0

View File

@ -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}')

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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)

View File

@ -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')