|
| 1 | +import os |
| 2 | +import socket |
| 3 | + |
| 4 | +from ansys.dpf.core._version import __version__ |
| 5 | + |
| 6 | +# environment variables for pyansys.com |
| 7 | +if 'jupyter' in socket.gethostname(): |
| 8 | + if 'ANSYS_PATH' not in os.environ: |
| 9 | + os.environ['ANSYS_PATH'] = '/mnt/ansys_inc/v212/' |
| 10 | + if 'DPF_PATH' not in os.environ: |
| 11 | + os.environ['DPF_PATH'] = '/mnt/ansys_inc/dpf/bin_v%s/Ans.dpf.core.Grpc.exe' % __version__ |
| 12 | + if 'AWP_UNIT_TEST_FILES' not in os.environ: |
| 13 | + os.environ['AWP_UNIT_TEST_FILES'] = '/mnt/ansys_inc/dpf/test_files/' |
| 14 | + |
| 15 | +from ansys.dpf.core.misc import module_exists, Report |
| 16 | +from ansys.dpf.core.dpf_operator import Operator, Config |
| 17 | +from ansys.dpf.core.model import Model |
| 18 | +from ansys.dpf.core.field import Field, FieldDefinition, Dimensionnality |
| 19 | +from ansys.dpf.core.fields_container import FieldsContainer |
| 20 | +from ansys.dpf.core.meshes_container import MeshesContainer |
| 21 | +from ansys.dpf.core.scopings_container import ScopingsContainer |
| 22 | +from ansys.dpf.core.server import (start_local_server, _global_server, |
| 23 | + connect_to_server) |
| 24 | +from ansys.dpf.core.data_sources import DataSources |
| 25 | +from ansys.dpf.core.scoping import Scoping |
| 26 | +from ansys.dpf.core.common import types, natures, locations, shell_layers |
| 27 | +from ansys.dpf.core.core import BaseService, load_library, download_file, upload_file, upload_file_in_tmp_folder |
| 28 | +from ansys.dpf.core.time_freq_support import TimeFreqSupport |
| 29 | +from ansys.dpf.core.operators_helper import sum, to_nodal, norm, eqv, element_dot, sqr |
| 30 | +from ansys.dpf.core.meshed_region import MeshedRegion |
| 31 | +from ansys.dpf.core.result_info import ResultInfo |
| 32 | +from ansys.dpf.core.collection import Collection |
| 33 | +from ansys.dpf.core.workflow import Workflow |
| 34 | +from ansys.dpf.core import operators |
| 35 | +from ansys.dpf.core.fields_factory import field_from_array |
| 36 | + |
| 37 | +# for matplotlib |
| 38 | +# solves "QApplication: invalid style override passed, ignoring it." |
| 39 | +os.environ['QT_STYLE_OVERRIDE'] = '' |
| 40 | + |
| 41 | +# Setup data directory |
| 42 | +USER_DATA_PATH = None |
| 43 | +EXAMPLES_PATH = None |
| 44 | +if os.environ.get('DPF_DOCKER', False): # pragma: no cover |
| 45 | + # Running DPF within docker (likely for CI) |
| 46 | + # path must be relative to DPF directory |
| 47 | + # |
| 48 | + # assumes the following docker mount: |
| 49 | + # -v /tmp:/dpf/_cache |
| 50 | + EXAMPLES_PATH = '/tmp' |
| 51 | +else: |
| 52 | + try: |
| 53 | + import appdirs |
| 54 | + USER_DATA_PATH = appdirs.user_data_dir('ansys-dpf-core') |
| 55 | + if not os.path.exists(USER_DATA_PATH): # pragma: no cover |
| 56 | + os.makedirs(USER_DATA_PATH) |
| 57 | + |
| 58 | + EXAMPLES_PATH = os.path.join(USER_DATA_PATH, 'examples') |
| 59 | + if not os.path.exists(EXAMPLES_PATH): # pragma: no cover |
| 60 | + os.makedirs(EXAMPLES_PATH) |
| 61 | + except: # pragma: no cover |
| 62 | + pass |
| 63 | + |
| 64 | + |
| 65 | +# Configure PyVista's ``rcParams`` for dpf |
| 66 | +if module_exists("pyvista"): |
| 67 | + import pyvista as pv |
| 68 | + pv.rcParams['interactive'] = True |
| 69 | + pv.rcParams["cmap"] = "jet" |
| 70 | + pv.rcParams["font"]["family"] = "courier" |
| 71 | + pv.rcParams["title"] = "DPF" |
| 72 | + |
| 73 | + |
| 74 | +SERVER = None |
| 75 | + |
| 76 | +def has_local_server(): |
| 77 | + """Returns True when a local DPF gRPC server has been created""" |
| 78 | + return SERVER is not None |
| 79 | + |
| 80 | + |
| 81 | +_server_instances = [] |
0 commit comments