PyXMake Developer Guide  1.0
PyXMake
D:/03_Workspaces/01_Eclipse/pyx_core/PyXMake/VTL/__init__.py
1 # -*- coding: utf-8 -*-
2 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 # % VTL Module - Classes and Functions %
4 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 """
6 Module containing virtual testing & benchmark scripts.
7 
8 @note: PyXMake module
9 Created on 20.03.2018
10 
11 @version: 1.0
12 ----------------------------------------------------------------------------------------------
13 @requires:
14  -
15 
16 @change:
17  -
18 
19 @author: garb_ma [DLR-FA,STM Braunschweig]
20 ----------------------------------------------------------------------------------------------
21 """
22 
23 ## @package PyXMake.VTL
24 # Module containing virtual testing & benchmark scripts.
25 ## @author
26 # Marc Garbade
27 ## @date
28 # 18.03.2019
29 ## @par Notes/Changes
30 # - Added documentation // mg 18.03.2019
31 # - Renamed VTC with VTL // mg 04.04.2019
32 
33 import os, sys, platform
34 import posixpath
35 
36 from ..Tools import Utility
37 
38 # Define global path definitions before loading subsequent verification example files.
39 Scratch = os.path.join(os.path.dirname(os.path.abspath(__file__)),"scratch")
40 
41 def GetSourceCode(key_opt=0):
42  """
43  Get a list of source codes files associated with the build of MCODAC, BoxBeam or BEOS.
44 
45  @param: key_opt: An integer value representing the source code files.
46  @type: key_opt: integer
47  """
48  ## Source code files of MCODAC in the correct build order (excluding interface source code file).
49  mcd_src_files = ["mcd_data", "mcd_error", "mcd_plugins", "mcd_tools", "mcd_contact", "mcd_material",
50  "mcd_load", "mcd_element", "mcd_subbuckling", "mcd_dmginitiation",
51  "mcd_dmgevolution", "mcd_fracture", "mcd_dmginfluence", "mcd_degradation",
52  "mcd_dg8", "mcd_iostream", "mcd_fatigue", "mcd_prony", "mcd_wrapper",
53  "mcd_toplevel", "mcd_main"]
54 
55  ## Source code files of BoxBeam in the correct build order (excluding interface source code file).
56  box_src_files = ["box_data", "box_tools", "box_main"]
57 
58  ## Source code files of BEOS in the correct build order (excluding interface source code file).
59  beos_src_files = ["Main.f90", "BEOSMain.for", "A11xst.for", "A11yst.for", "A21ast.for", "A22ast.for", "ABDetc.for",
60  "BmtstN.for", "BuVi.for", "Chneig.for", "Chodec.for", "Chosol.for", "Cktype.for", "Cmpa11.for", "Cmpa21.for",
61  "Cmpa22.for", "Cmpbmt.for", "Cmpmmt.for", "Cntr.for", "CripplingO.for", "CripplingT.for", "EIGVPR.FOR",
62  "F01kbf.for", "F01KTF.FOR", "GlBuck.for", "Incs2.for", "Incs3N.for", "Iuoriv3.for", "JACOB2.FOR", "Kuorkv2.for",
63  "Lqfit95.for", "MKLVBD.F90", "Mmtst.for", "Modes.for", "Phi.for", "Plotmesh.for", "PPROBTM95.for", "Prtout.for",
64  "Prtvib.for", "PRTYPE.FOR", "RddataN-Ak.for", "Rdtype.for", "Redfkq.for", "Setkey_2.for", "SIMVT2003.FOR",
65  "TCZINC.FOR", "Tfmstf.for", "TMINC.FOR", "Trnpsi.for", "Vibs2.for", "Vibs3NN.for","#PRAMS"]
66 
67  ## Source code files of MUESLI in the correct build order (excluding interface source code file).
68  muesli_src_files = ["material.cpp", "tensor.cpp", "brownmiller.cpp", "jcfailure.cpp", "arrheniustype.cpp", "arrudaboyce.cpp",
69  "finitestrain.cpp", "fisotropic.cpp", "fplastic.cpp", "johnsoncook.cpp", "mooney.cpp", "neohook.cpp", "reducedfinitestrain.cpp",
70  "svk.cpp", "yeoh.cpp", "zerilliarmstrong.cpp", "fluid.cpp", "newtonian.cpp", "thermofinitestrain.cpp",
71  "fmechmass.cpp", "interface_abaqus.cpp", "interface_lsdyna.cpp", "mtensor.cpp", "mmatrix.cpp",
72  "mrealvector.cpp","smallstrain.cpp", "elastic.cpp", "reducedsmallstrain.cpp", "sdamage.cpp", "splastic.cpp",
73  "viscoelastic.cpp", "viscoplastic.cpp", "smallthermo.cpp", "conductor.cpp", "utils.cpp"]
74 
75  # Source code files of CompDam (NASA's material library) in correct build order (excluding interface source code files).
76  compdam_src_files = ["vumatArgs.for","version.for.nogit","forlog.for","matrixUtil.for","matProp.for","stateVar.for","parameters.for", "schapery.for",
77  "stress.for","strain.for","schaefer.for","plasticity.for","fiberDamage.for","friction.for","cohesive.for","DGD.for"]
78  #"vucharlength.for","vexternaldb.for","CompDam_DGD.for","vumatWrapper.for","UMAT.for"
79 
80  # Source code files of DispModule
81  dispmod_src_files = ["dispmodule.f90","disp_i1mod.f90","disp_i2mod.f90","disp_i4mod.f90","disp_i8mod.f90","disp_l1mod.f90","disp_r16mod.f90"]
82 
83  # Source code files of TOMS
84  toms_src_files = ["toms790.f","toms661.f90"]
85 
86  # Source code files of various other libraries
87  misc_src_files =["nms.f90","pchip.f90","slatec.f90","interp.f90"]
88 
89  # Source code for PyCODAC application
90  pyc_src_files = ["__exe__.py"]
91 
92  # Select correct files for output
93  if key_opt==0:
94  source = mcd_src_files
95  elif key_opt==1:
96  source = box_src_files
97  elif key_opt==2:
98  source = beos_src_files
99  elif key_opt==3:
100  source = muesli_src_files
101  elif key_opt==4:
102  source = compdam_src_files
103  elif key_opt==5:
104  source = dispmod_src_files
105  elif key_opt==6:
106  source = toms_src_files
107  elif key_opt==7:
108  source = misc_src_files
109  elif key_opt==8:
110  source = pyc_src_files
111  else:
112  raise NotImplementedError
113  # Return list of source code files in correct order.
114  return source
115 
116 def GetBuildCommand(make_opt=0, _format="fixed", _arch=Utility.GetArchitecture()):
117  """
118  Return the recommended command line during the build process for selected make operations.
119 
120  @param: make_opt: An integer value representing the make operation.
121  @type: make_opt: integer
122  """
123  ## Build command for Java applications under Windows
124  win_java_command = "-nologo -O3 -Qopenmp -Qauto_scalar -Qparallel -Qmkl:parallel -Qopt-matmul -fpp -recursive \
125  -reentrancy:threaded -"+_format+" -extend_source:132 -fpe:0 -heap-arrays1 -iface:cref -libs:static -threads -MT -W1"
126 
127  ## Build command for Fortran applications under Windows
128  win_fortran_command = "-nologo -O3 -QxSSE3 -Qopenmp -Qauto_scalar -Qparallel -Qmkl:parallel -Qopt-matmul -fpp -recursive \
129  -reentrancy:threaded -"+_format+" -extend_source:132 -fpe:0 -traceback -heap-arrays1 -iface:cref -libs:dll -threads -MD -W1"
130 
131  ## Build command for C++ applications under Windows
132  win_cxx_command = "-nologo -Os -W0 -MD -TP -EHsc -Qpar -clr:nostdlib -fp:precise -std:c++latest "
133  win_cxx_command +="-FI pyx_muesli_def.h "
134  win_cxx_command +="-FI algorithm -FI ctime "
135  win_cxx_command +="-FI pyx_muesli_undef.h "
136 
137  ## Build command for Python applications under Windows
138  win_pyd_command = ' -DNO_APPEND_FORTRAN '
139  win_pyd_command += ' --f90flags="-'+_format+' -fpe:0 -fp:precise -threads -recursive -Qauto-scalar -Qopenmp -Qmkl:parallel -heap-arrays:1" '
140  win_pyd_command += ' --opt="-O2" --arch="-QaxSSE3 /assume:nounderscore" --quiet --compiler=msvc '
141 
142  ## Build command for Python applications under Linux
143  lin_pyd_command = '--quiet --fcompiler=intelem --opt="-O2" --f90flags="-'+_format+' -fp-model precise -fpe0 -recursive -parallel -auto -qopenmp -qopt-matmul -mkl:parallel"'
144 
145  ## Build command for Fortran applications under Linux
146  lin_fortran_command = "-fpp -qopenmp -DCLUSTER -DDEBUG -DUSE_MUESLI -fPIC -auto -mkl:parallel -extend_source -O2 -"+_format+" -parallel -fpe0 -traceback -recursive"
147 
148  # Build command for ABAQUS applications under windows
149  win_abq_command = "ECHO import os >> %ABQ_ENV_FILE% "
150  win_abq_command += "&& ECHO usub_lib_dir=os.getcwd() >> %ABQ_ENV_FILE% "
151  win_abq_command += "&& ( "
152  win_abq_command += "ECHO compile_fortran=['ifort', "
153  win_abq_command += "'/c','/DABQ_WIN86_64', '/extend-source', '/fpp', "
154  win_abq_command += "'/iface:cref', '/recursive', "
155  win_abq_command += "'/QxSSE3', '/QaxAVX', '/heap-arrays:1', "
156  win_abq_command += "'/O3', " #<-- Optimization level
157  win_abq_command += "'/MD', " # <-- Multithreading CRT library
158  win_abq_command += "'/Qparallel', " # <-- Use multithreading standard libraries
159  win_abq_command += "'/fpe:0', " # <-- Floating point exception handling / Prevents division through zero
160  win_abq_command += "'/traceback', " # <-- Traceback errors
161  win_abq_command += "'/Qmkl:parallel', " # <-- Use MKL libraries
162  win_abq_command += "'/Qopt-matmul', "
163  win_abq_command += "'/libs:dll', "
164  win_abq_command += "'/threads', "
165  win_abq_command += "'/reentrancy:threaded', "
166  win_abq_command += "'/Qopenmp', " # <-- Use OpenMP library
167 
168  if sys.getwindowsversion() >= (10, 0, 0):
169  # Windows 10
170  win_abq_command += "'/DABQ_FORTRAN', "
171  win_abq_command += "'/Qauto', " # <-- important for thread-safety of parallel user subroutines
172  win_abq_command += "'/align:array64byte', "
173  win_abq_command += "'/Qpc64', " # set FPU precision to 53 bit significand
174  win_abq_command += "'/Qprec-div', '/Qprec-sqrt', " # improve precision of FP divides and sqrt
175  win_abq_command += "'/Qfma-', " # disable floating point fused multiply-add
176  win_abq_command += "'/fp:precise', " # floating point model: precise
177  win_abq_command += "'/Qimf-arch-consistency:true', " # math library consistent results
178  win_abq_command += "'/Qfp-speculation:safe', " # floating point speculations only when safe
179  win_abq_command += "'/Qprotect-parens', " # honor parenthesis during expression evaluation
180  win_abq_command += "'/Qfp-stack-check', " # enable stack overflow protection checks
181  else:
182  # Windows 7
183  win_abq_command += "'/Qauto-scalar', "
184 
185  # win_abq_command += "'/warn:all', "
186  # win_abq_command += "'/warn:nousage', "
187  # win_abq_command += "'/warn:interfaces', "
188  # win_abq_command += "'/check:pointer', "
189  # win_abq_command += "'/check:uninit', "
190  # win_abq_command += "'/check:format', "
191  # win_abq_command += "'/check:output_conversion', "
192  # win_abq_command += "'/check:arg_temp_created', "
193  # win_abq_command += "'/check:bounds', " # <-- Array boundary check
194  # win_abq_command += "'/debug:extended', " # <-- Debug function information
195  # win_abq_command += "'/debug-parameters:all', " # <-- Debug parameter information
196  # win_abq_command += "'/Ob0', " # <-- Function inlining
197  # win_abq_command += "'/Zi', " # <-- Debugging # CompLine += "'/watch:all', "
198  # win_abq_command += "'/DCLUSTER', " # <-- Conditional compilation on Cluster
199  win_abq_command += "'/include:%I'] ) >> %ABQ_ENV_FILE% "
200  win_abq_command += "&& ( "
201  win_abq_command += "ECHO link_sl=['LINK', '/nologo', '/NOENTRY', '/INCREMENTAL:NO', '/subsystem:console', '/machine:AMD64', "
202  win_abq_command += "'/NODEFAULTLIB:LIBC.LIB', '/NODEFAULTLIB:LIBCMT.LIB', "
203  win_abq_command += "'/DEFAULTLIB:OLDNAMES.LIB', '/DEFAULTLIB:LIBIFCOREMD.LIB', '/DEFAULTLIB:LIBIFPORTMD.LIB', '/DEFAULTLIB:LIBMMD.LIB', "
204  win_abq_command += "'/DEFAULTLIB:kernel32.lib', '/DEFAULTLIB:user32.lib', '/DEFAULTLIB:advapi32.lib', "
205  win_abq_command += "'/FIXED:NO', '/dll', "
206  # win_abq_command+= "'/DEBUG', " # <-- Debugging
207  # win_abq_command += "'/VERBOSE', " # <-- Show commands
208  win_abq_command += "'/def:%E', '/out:%U', '%F', '%A', '%L', '%B', "
209  # Overwrite CRT section in ABQ, since its implementation is flawed (or at least is not modifiable enough for our purposes).
210  win_abq_command += "r'/def:"+os.getenv("pyx_abaqus_def","%E")+"', '/INCLUDE:_DllMainCRTStartup', '/FORCE', "
211  win_abq_command += "'oldnames.lib', 'user32.lib', 'ws2_32.lib', 'netapi32.lib', 'advapi32.lib', "
212  win_abq_command += "%pyx_libs%] ) >> %ABQ_ENV_FILE% "
213  win_abq_command += '&& %pyx_abaqus% make -library %pyx_file%'
214 
215  # Architecture dependencies are related to the PYTHON version used in the build process, thus the check is made here.
216  if ('x86' in _arch):
217  # Custom compiler commands for f2py.
218  win_pyd_command += " --fcompiler=intelv"
219 
220  elif ('x64' in _arch):
221  # Custom compiler commands for f2py.
222  win_pyd_command += " --fcompiler=intelvem"
223 
224  if make_opt==0:
225  command = win_pyd_command
226  elif make_opt==1:
227  command = win_java_command
228  elif make_opt==2:
229  command = win_fortran_command
230  elif make_opt==3:
231  command = win_cxx_command
232  elif make_opt==4:
233  command = lin_pyd_command
234  elif make_opt==5:
235  command = lin_fortran_command
236  # In dependence of 3rd party FE software
237  elif make_opt==6:
238  command = win_abq_command
239  else:
240  raise NotImplementedError
241 
242  return command
243 
244 def GetIncludeDirectory(base_path, key_opt=0, make_opt=0, architecture="x64"):
245  """
246  Return all mandatory include directories for the requested make operation in dependence of key_opt.
247 
248  @param: key_opt, make_opt: [An integer value representing the source code file (e.g. MCODAC, BoxBeam, BEOS),
249  An integer value representing the make operation.]
250  @type: key_opt, make_opt: integer
251  """
252  ## Source code files of MCODAC in the correct build order (excluding interface source code file).
253  if key_opt == 0 and make_opt in range(6):
254  try:
255  inc = list(Utility.PathWalk(os.path.join(base_path,"include",Utility.GetPlatform(),architecture),True, startswith=(".", "__")))[0][1]
256  except IndexError:
257  inc = ""
258  elif key_opt == 8:
259  ## Add base path to overall search path (if valid and existing)
260  if os.path.exists(base_path):
261  sys.path.append(base_path)
262  ## Access required packages
263  try:
264  # Import PyCODAC to build library locally during setup.
265  import OCC
266  import PyCODAC
267  # Get qualified package names
268  __occ_name = OCC.__name__
269  __pyc_name = PyCODAC.__name__
270  # Get absolute package paths
271  __occ_src_path = OCC.__path__[0]
272  __pyc_src_path = PyCODAC.PyCODACPath
273  except ImportError:
274  # This script is not executed as plug-in for PyCODAC
275  __occ_name = ""; __occ_src_path = ""
276  __pyc_name = ""; __pyc_src_path = ""
277  pass
278  ## Add dependencies
279  inc = ["six.py", "ipykernel_launcher.py",
280  # Added OCC module explicitly
281  os.path.pathsep.join([__occ_src_path,os.path.join(__occ_name,".")]),
282  # Add PyCODAC packages
283  os.path.join(__pyc_name,"__init__.py"),
284  os.path.join(__pyc_name,"Paths.log"),
285  os.path.join(__pyc_name,"Tools","__init__.py"),
286  os.path.join(__pyc_name,"Tools","Utility.py"),
287  os.path.join(__pyc_name,"Core","cmd"),
288  # Add compiled binaries
289  os.path.join(__pyc_name,"Core","bin",Utility.GetPlatform(),architecture),
290  os.path.join(__pyc_name,"Study","bin",architecture),
291  os.path.join(__pyc_name,"Study","cmd",Utility.GetPlatform()),
292  # Add JupyterLab configuration and application files
293  os.path.join(__pyc_name,"Plugin","JupyterLab","bin", Utility.GetPlatform()),
294  os.path.pathsep.join([os.path.join(__pyc_src_path,"Plugin","JupyterLab","config","jupyter_notebook_utils.py"),"."]),
295  os.path.pathsep.join([os.path.join(__pyc_src_path,"Plugin","JupyterLab","config"),os.path.join(__pyc_name,"Plugin","JupyterLab","config",".")]),
296  # Add configuration file for Smetana
297  os.path.join(__pyc_name,"Plugin","Smetana","config","pyc_smetana.config"),
298  os.path.pathsep.join([os.path.join(__pyc_src_path,"Plugin","Smetana","src","smetana","static","abaqus_msa_reports.py"),os.path.join("static",".")]),
299  # Add images directly to executable
300  os.path.pathsep.join([os.path.join(__pyc_src_path, "GUI","res","pyc_lab_icon.png"), os.path.join(__pyc_name, "GUI", "res",".")]),
301  os.path.pathsep.join([os.path.join(__pyc_src_path, "GUI","res","pyc_dic_analysis.png"),os.path.join(__pyc_name, "GUI", "res",".")]),
302  os.path.pathsep.join([os.path.join(__pyc_src_path, "GUI","res","stm_lab_icon.png"), os.path.join(__pyc_name, "GUI", "res",".")]),
303  os.path.pathsep.join([os.path.join(__pyc_src_path, "GUI","res","stm_main.png"),os.path.join(__pyc_name, "GUI", "res",".")]),
304  os.path.pathsep.join([os.path.join(__pyc_src_path, "GUI","res","stm_lightweight.png"),os.path.join(__pyc_name, "GUI", "res",".")]),
305  os.path.pathsep.join([os.path.join(__pyc_src_path, "GUI","res","stm_vph.png"), os.path.join(__pyc_name, "GUI", "res",".")])]
306  else:
307  inc = []
308  return inc
309 
310 def GetLinkDependency(key_opt=0, make_opt=0, architecture="x64"):
311  """
312  Return all mandatory external libraries for the requested make operation in dependence of key_opt.
313 
314  @param: key_opt, make_opt: [An integer value representing the source code file (e.g. MCODAC, BoxBeam, BEOS),
315  An integer value representing the make operation.]
316  @type: key_opt, make_opt: integer
317  """
318  ## Source code files of MCODAC in the correct build order (excluding interface source code file).
319  if key_opt == 0 and make_opt in range(6):
320  lib = [x + architecture for x in ["interp", "pchip", "bbeam","muesli","dispmodule", "toms"]]
321  elif key_opt == 8:
322  ## Access required packages
323  try:
324  # Import PyCODAC to build library locally during setup.
325  import PyCODAC
326  # Get absolute package paths
327  __pyc_src_path = PyCODAC.PyCODACPath
328  except ImportError:
329  # This script is not executed as plug-in for PyCODAC
330  __pyc_src_path = ""
331  pass
332  ## Add additional libraries
333  lib = [os.path.join(__pyc_src_path,"Plugin","DELiS","src"),os.path.join(__pyc_src_path,"Plugin","Smetana"),
334  os.path.join(__pyc_src_path,"Plugin","Smetana","src","smetana")]
335  else:
336  lib = []
337  return lib
338 
339 def GetEnvironment(env_opt=0):
340  """
341  Return predefined source environment to initiate a build process.
342 
343  @param: env_opt An integer value representing a predefined environment
344  @type: env_opt: integer
345  """
346  if env_opt == 0:
347  ## Return Intel Fortran environment (DLR institute cluster)
348  env = [posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","slurm","etc","env.d","ifort2016.sh")]
349  elif env_opt == 1:
350  ## Return Intel Fortran environment & PYTHON 2.7 (DLR institute cluster)
351  env = [posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","slurm","etc","env.d","ifort2016.sh"),
352  posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","python2.7","env.sh")],
353  elif env_opt ==2:
354  ## Return Intel Fortran environment & PYTHON 3.5 (DLR institute cluster)
355  env = [posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","slurm","etc","env.d","ifort2016.sh"),
356  posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","python3.5","env.sh")],
357  elif env_opt ==3:
358  ## Return Intel Fortran environment & PYTHON 3.x (DLR institute cluster)
359  env = [posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","slurm","etc","env.d","ifort2016.sh"),
360  posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","mcodac","anaconda","envs","Conda36","env.sh")],
361  else:
362  raise NotImplementedError
363  return env
364 
365 # Create useful names for import. Each script acts also as a minimum working example.
366 try:
367  # Build documentation
368  from .doxygen import main as doxygen
369  from .sphinx import main as sphinx
370  # API builds
371  if sys.version_info >= (3,6):
372  from .api import main as api
373  # Bundle builds
374  from .app import main as app
375  from .bundle import main as bundle
376  # Host builds
377  from .abaqus import main as abaqus
378  from .ifort import main as ifort
379  from .java import main as java
380  from .py2x import main as py2x
381  from .cxx import main as cxx
382  # Remote builds
383  from .ssh_ifort import main as ssh_ifort
384  from .ssh_f2py import main as ssh_f2py
385  from .ssh_make import main as ssh_make
386 except:
387  pass
388 
389 if __name__ == '__main__':
390  pass
def GetBuildCommand(make_opt=0, _format="fixed", _arch=Utility.GetArchitecture())
Definition: __init__.py:116
def GetSourceCode(key_opt=0)
Definition: __init__.py:41
def GetEnvironment(env_opt=0)
Definition: __init__.py:339
def GetIncludeDirectory(base_path, key_opt=0, make_opt=0, architecture="x64")
Definition: __init__.py:244
def GetLinkDependency(key_opt=0, make_opt=0, architecture="x64")
Definition: __init__.py:310