PyXMake Developer Guide: src/PyXMake/VTL/abaqus.py Source File

| PyXMake Developer Guide 1.0 PyXMake

Loading...
Searching...
No Matches
abaqus.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % PyXMake - Build environment for PyXMake %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Triple-use minimum working example for PyXMake. This script can be
7executed in three different ways in varying levels of accessibility
8
9@note: Compile MCODAC for ABAQUS Standard & Explicit
10 on Windows. Can be combined with self-written code alike.
11Created on 25.06.2018
12
13@version: 1.0
14----------------------------------------------------------------------------------------------
15@requires:
16 - PyXMake
17
18@change:
19 -
20
21@author: garb_ma [DLR-FA,STM Braunschweig]
22----------------------------------------------------------------------------------------------
23"""
24import os, sys
25import argparse
26import tempfile
27
28try:
29 import PyXMake as _
30except ImportError:
31 # Script is executed as a plug-in
32 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
33finally:
34 from PyXMake.Build.Make import Custom, AllowDefaultMakeOption #@UnresolvedImport
35 from PyXMake.Tools import Utility #@UnresolvedImport
36 from PyXMake import VTL #@UnresolvedImport
37
38# Predefined script local variables
39__arch = "x64"
40
41# Select a installation of ABAQUS. Always use latest found.
42os.environ["pyx_abaqus"] = os.getenv("pyx_abaqus","abaqus")
43
44try:
45 # Import PyCODAC to build library locally during setup.
46 from PyCODAC.Tools.Utility import GetPyCODACPath
47 # Import and set local path to PyCODAC
48 __mcd_core_path = os.path.join(GetPyCODACPath(),"Core")
49except ImportError:
50 # This script is not executed as plug-in
51 __mcd_core_path = ""
52except:
53 # Something else went wrong.
54 from PyXMake.Tools import ErrorHandling
55 ErrorHandling.InputError(20)
56
57 def main(
58 BuildID,
59 # Build MCODAC for ABAQUS Standard by default
60 files="mcd_astandard",
61 command = VTL.GetBuildCommand(6),
62 libs = ['mcd_corex64'] + VTL.GetLinkDependency(0),
63 # Resource paths
64 source=os.path.join(__mcd_core_path,"solver"),
65 include=list(Utility.ArbitraryFlattening([[os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch)],
66 [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, __arch)]])),
67 dependency=os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch),
68 output=os.path.join(__mcd_core_path,"bin",Utility.GetPlatform(),__arch),
69 # Verbose and scratch directory
70 scratch=VTL.Scratch, verbosity=2,
71 # Additional keyword arguments
72 **kwargs):
73 """
74 Main function to execute the script.
75 """
76 # Execute each call in a unique, isolated environment
77 with Utility.TemporaryEnvironment():
78 # Set default preprocessor command
79 Preprocessing = VTL.GetPreprocessingCommand(0)
80 # Use alternative FOSS implementation in Docker container.
81 if Utility.IsDockerContainer and Utility.GetPlatform() in ["linux"]: Preprocessing= VTL.GetPreprocessingCommand(1)
82 # Build a shared library for ABAQUS using the Intel Fortran Compiler
83 ABQBuild = Custom(BuildID, files, scratch=scratch, msvsc="vs2015", arch=__arch, verbose=verbosity, **kwargs)
84 ABQBuild.SourcePath(source)
85 ABQBuild.AddIncludePath(include)
86 ABQBuild.AddDependencyPath(dependency)
87 ABQBuild.OutputPath(output, files=["standardU.dll","explicitU-D.dll"])
88 ABQBuild.Preprocessing(Preprocessing, inend='.f', outend='.f')
89 ABQBuild.UseLibraries(libs)
90 ABQBuild.Build(command)
91 ABQBuild.create()
92
93if __name__ == "__main__":
94# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95# % Access command line inputs %
96# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 # Process all known arguments
98 parser = argparse.ArgumentParser(description='CLI wrapper options for ABAQUS make command.', parents=[Custom.__parser__()])
99 parser.add_argument('-l', '--libs', nargs='+', default=[], help="List of all libraries used to resolve symbols. The libraries are evaluated in the given order.")
100 parser.add_argument('-d', '--dependency', nargs='+', default=[], help="Additional search paths to resolve library dependencies.")
101 # Check all options or run unit tests in default mode
102 try:
103 # Check CLI options
104 _ = sys.argv[1]
105 args, _ = parser.parse_known_args()
106 # Project name is mandatory
107 project = args.name[0]
108 # Specification of source directory is mandatory
109 source = args.source[0]
110 # Optional non-default output directory
111 try: files = args.files
112 except: files = []
113 # Optional non-default additional libraries
114 try:
115 libs = args.libs
116 # Sanitize the given library names.
117 libs = [Custom.sanitize(x) for x in libs]
118 except: libs = []
119 # Optional non-default output directory
120 try: output = Custom.sanitize(args.output[0])
121 except: output = os.path.abspath(os.getcwd())
122 # Optional non-default scratch directory
123 try: scratch = args.scratch[0]
124 except: scratch = tempfile.mkdtemp()
125 # Create a dictionary combining all settings
126 settings = {"source":source, "output":output, "files":files, "scratch": scratch, "libs": libs}
127 # Loop over options requiring paths to be sanitized
128 for option in ["include", "dependency"]:
129 # Optional non-default definition of additional include directories
130 try:
131 _ = getattr(args,option)[0]
132 # Collect all given paths. Get system independent format
133 path = list(Utility.ArbitraryFlattening(getattr(args,option)));
134 path = [Custom.sanitize(x) for x in path]
135 sanitized = Utility.GetSanitizedDataFromCommand(path)
136 # No extra search paths have been given
137 except: sanitized = []
138 # Add all sanitized search paths to settings
139 settings.update({option: sanitized})
140 # Use an exception to allow help message to be printed.
141 except Exception as _:
142 pass
143 # Build all supported features
144 if AllowDefaultMakeOption:
145 # Temporary ID during the build process.
146 BuildID = 'mcd_abaqus'
147 main(BuildID,"mcd_astandard"); main(BuildID,"mcd_aexplicit")
148 # Execute valid CLI command
149 else: main(project, **settings)
150 # Finish
151 print('==================================')
152 print('Finished build for ABAQUS')
153 print('==================================')
154 sys.exit()
PyXMake.Build.Make.Custom
Base class for all custom build events inherited from Make.
PyXMake.Tools.ErrorHandling.InputError
Base class for all input errors.
PyXMake.Build.Make
Create a make object to define the building environment.
Definition Make.py:1
PyXMake.Tools
Module containing basic functionalities defined for convenience.
Definition __init__.py:1
PyXMake.VTL.abaqus.main
main(BuildID, files="mcd_astandard", command=VTL.GetBuildCommand(6), libs=['mcd_corex64']+VTL.GetLinkDependency(0), source=os.path.join(__mcd_core_path,"solver"), include=list(Utility.ArbitraryFlattening([[os.path.join(__mcd_core_path,"include", Utility.GetPlatform(), __arch)], [os.path.join(__mcd_core_path,"include", Utility.GetPlatform(), __arch, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, __arch)]])), dependency=os.path.join(__mcd_core_path,"lib", Utility.GetPlatform(), __arch), output=os.path.join(__mcd_core_path,"bin", Utility.GetPlatform(), __arch), scratch=VTL.Scratch, verbosity=2, **kwargs)
Definition abaqus.py:72