diff --git a/blast/interfaces/dart/blDartInterface.py b/blast/interfaces/dart/blDartInterface.py index 49eac1ab388f4755b432ce99c4866eb7c95c0c98..68ea7f909f5f26e105ef6e50c2499056b33f7978 100644 --- a/blast/interfaces/dart/blDartInterface.py +++ b/blast/interfaces/dart/blDartInterface.py @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - # Dart interface # Paul Dechamps @@ -24,6 +23,9 @@ import numpy as np from fwk.coloring import ccolors from blast.interfaces.blSolversInterface import SolversInterface +dartflo_import_paths = {'local module': 'modules.dartflo.dart.api.core', + 'blaster install': 'blaster.dart.api.core'} + class DartInterface(SolversInterface): """Interface to the Dart solver. @@ -50,18 +52,30 @@ class DartInterface(SolversInterface): _cfg : dict Configuration parameters of the VII interface. """ - try: - from modules.dartflo.dart.api.core import init_dart - self.iobj = init_dart(dartCfg, task=dartCfg['task'], viscous=True) - self.solver = self.iobj.get('sol') # Solver - self.blw = [self.iobj.get('blwb'), self.iobj.get('blww')] - if dartCfg['task'] == 'optimization': - self.adjointSolver = self.iobj.get('adj') - print('Dart successfully loaded for optimization.') + # Load DART module + if 'dart_path' in dartCfg: + # First try imposed path + try: + init_dart = __import__(dartCfg['dart_path'], fromlist=['init_dart']).init_dart + print(f'DART loaded from specified path {dartCfg["dart_path"]} for {dartCfg["task"]}.') + except ImportError: + raise ImportError(f'{ccolors.ANSI_RED}Could not load DART from specified path: {dartCfg["dart_path"]}.{ccolors.ANSI_RESET}') + else: + # Load from known paths + for name, path in dartflo_import_paths.items(): + try: + init_dart = __import__(path, fromlist=['init_dart']).init_dart + print(f'DART loaded from {name} path for {dartCfg["task"]}.') + break + except ImportError: + continue else: - print('Dart successfully loaded for analysis.') - except: - raise ImportError(ccolors.ANSI_RED, 'Could not load DART.', ccolors.ANSI_RESET) + raise ImportError(f'{ccolors.ANSI_RED}Could not load DART.{ccolors.ANSI_RESET}') + + self.iobj = init_dart(dartCfg, task=dartCfg['task'], viscous=True) + self.solver = self.iobj.get('sol') # Solver + self.blw = [self.iobj.get('blwb'), self.iobj.get('blww')] + self.adjointSolver = self.iobj.get('adj') _cfg['Format'] = dartCfg['Format'] if 'iMsh' not in _cfg: