예제 #1
0
    def named_selection(self, named_selection):
        """Scoping containing the list of nodes or elements in the named selection.

        Parameters
        ----------
        named_selection : str
            Name of the named selection.

        Returns
        -------
        named_selection : Scoping
        """
        if server_meet_version("2.1", self._server):
            request = meshed_region_pb2.GetScopingRequest(mesh=self._message)
            request.named_selection = named_selection
            out = self._stub.GetScoping(request)
            return scoping.Scoping(scoping=out, server=self._server)
        else:
            if hasattr(self, "_stream_provider"):
                from ansys.dpf.core.dpf_operator import Operator

                op = Operator("scoping_provider_by_ns", server=self._server)
                op.connect(1, named_selection)
                op.connect(3, self._stream_provider, 0)
                return op.get_output(0, types.scoping)
            else:
                raise Exception(
                    "Getting a named selection from a meshed region is "
                    "only implemented for meshed region created from a "
                    "model for server version 2.0. Please update your server."
                )
예제 #2
0
    def load_library(self, file_path, name="", symbol="LoadOperators"):
        """Dynamically load an operators library for dpf.core.
        Code containing this library's operators is generated in
        ansys.dpf.core.operators

        Parameters
        ----------
        file_path : str or os.PathLike
            file_path of the operator library.

        name : str, optional
            Library name.  Probably optional

        Examples
        --------
        Load the mesh operators for Windows (for Linux, just use
        'libmeshOperatorsCore.so' instead of 'meshOperatorsCore.dll')

        >>> from ansys.dpf import core as dpf
        >>> base = dpf.BaseService()
        >>> # base.load_library('meshOperatorsCore.dll', 'mesh_operators')

        """
        request = base_pb2.PluginRequest()
        request.name = name
        request.dllPath = str(file_path)
        request.symbol = symbol
        try:
            self._stub.Load(request)
        except Exception as e:
            raise IOError(
                f'Unable to load library "{str(file_path)}". File may not exist or'
                f" is missing dependencies:\n{str(e)}"
            )

        # TODO: fix code generation upload posix
        import os

        if self._server().os != 'posix' or (not self._server().os and os.name != 'posix'):
            local_dir = os.path.dirname(os.path.abspath(__file__))
            LOCAL_PATH = os.path.join(local_dir, "operators")

            # send local generated code
            TARGET_PATH = self.make_tmp_dir_server()
            self.upload_files_in_folder(TARGET_PATH, LOCAL_PATH, "py")

            # generate code
            from ansys.dpf.core.dpf_operator import Operator

            code_gen = Operator("python_generator")
            code_gen.connect(1, TARGET_PATH)
            code_gen.connect(0, str(file_path))
            code_gen.connect(2, False)
            code_gen.run()

            self.download_files_in_folder(TARGET_PATH, LOCAL_PATH, "py")