コード例 #1
0
    def __init__(self, name, config=None, server=None):
        """Initialize the operator with its name by connecting to a stub."""
        if server is None:
            server = serverlib._global_server()

        self._server = server

        self.name = name
        self._stub = self._connect()

        self._message = None
        self._description = None
        self._inputs = None
        self._outputs = None

        self.__send_init_request(config)

        self.__fill_spec()

        # add dynamic inputs
        if len(self._spec.inputs) > 0 and self._inputs == None:
            self._inputs = Inputs(self._spec.inputs, self)
        if len(self._spec.outputs) != 0 and self._outputs == None:
            self._outputs = Outputs(self._spec.outputs, self)

        self._description = self._spec.description
        self._progress_bar = False
コード例 #2
0
    def __init__(self, server=None, load_operators=True, timeout=5):
        """Initialize base service"""

        if server is None:
            server = serverlib._global_server()

        self._server = weakref.ref(server)
        self._stub = self._connect(timeout)
コード例 #3
0
 def operator_specification(op_name, server=None):
     """Put the grpc spec message in self._spec"""
     if server is None:
         server = serverlib._global_server()
     request = operator_pb2.Operator()
     request.name = op_name
     out = operator_pb2_grpc.OperatorServiceStub(
         server.channel).List(request)
     return OperatorSpecification._fill_from_message(op_name, out.spec)
コード例 #4
0
ファイル: path_utilities.py プロジェクト: pyansys/DPF-Core
def to_server_os(path, server=None):
    path = str(path)
    if not server:
        server = server_module._global_server()
    if not server:
        return path
    if server.os == 'posix':
        return path.replace("\\", "/")
    else:
        return path.replace("/", "\\")
コード例 #5
0
ファイル: path_utilities.py プロジェクト: pyansys/DPF-Core
def downloaded_example_path(server=None):
    on_docker = server_module.RUNNING_DOCKER["use_docker"]
    if not server:
        server = server_module._global_server()
    if server:
        on_docker = server.on_docker
    if on_docker:  # pragma: no cover
        return "/tmp/downloaded_examples"
    else:
        from ansys.dpf.core import LOCAL_DOWNLOADED_EXAMPLES_PATH
        return LOCAL_DOWNLOADED_EXAMPLES_PATH
コード例 #6
0
ファイル: path_utilities.py プロジェクト: pyansys/DPF-Core
def join(*args, **kwargs):
    """Join two strings to form a path, following the server
    architecture.
    Using a server version below 3.0, please ensure that the
    python client and the server's os are similar before
    using this method.

    Parameters
    ----------
    args : str, os.PathLike, DPFServer
        Path to join and optionally a server.

    kwargs : DPFServer
        server=.

    server : Server
        Specific server to use.

    Returns
    -------
    concatenated_file_path : str
        left_path + right_path concatenated into a single string value.

    """
    server = None
    parts = []
    for a in args:
        if isinstance(a, (str, Path)) and Path(a) != Path(""):
            parts.append(str(a))
        elif isinstance(a, server_module.DpfServer):
            server = a
    if "server" in kwargs:
        server = kwargs["server"]
    if not server:
        server = server_module._global_server()
    if not server:
        if server_module.RUNNING_DOCKER["use_docker"]:
            current_os = "posix"
        else:
            return os.path.join(*args)
    else:
        current_os = server.os

    if len(parts) == 0:
        return ""
    separator = "\\"
    if current_os == 'posix':
        separator = "/"
    path_to_return = parts[0]
    for ipath in range(1, len(parts)):
        path_to_return += separator + parts[ipath]
    return path_to_return
コード例 #7
0
ファイル: field_base.py プロジェクト: pyansys/DPF-Core
    def __init__(
            self,
            nentities=0,
            nature=natures.vector,
            location=locations.nodal,
            is_property_field=False,
            field=None,
            server=None,
    ):
        """Initialize the field either with an optional field message or by connecting to a stub."""
        if server is None:
            server = serverlib._global_server()

        self._server = server
        self._stub = self._connect()

        if field is None:
            request = field_pb2.FieldRequest()
            if hasattr(nature, "name"):
                snature = nature.name
            else:
                snature = nature
            request.nature = base_pb2.Nature.Value(snature.upper())
            request.location.location = location
            request.size.scoping_size = nentities
            if snature == natures.vector.name:
                elem_data_size = 3
            elif snature == natures.symmatrix.name:
                elem_data_size = 6
            else:
                elem_data_size = 1
            request.size.data_size = nentities * elem_data_size
            if is_property_field:
                request.datatype = "int"
            self._message = self._stub.Create(request)
        else:
            from ansys.dpf.core import field as field_module
            from ansys.dpf.core import property_field

            if isinstance(field, field_module.Field):
                self._message = field._message
            elif isinstance(field, property_field.PropertyField):
                self._message = field._message
            elif isinstance(field, field_pb2.Field):
                self._message = field
            else:
                raise TypeError(f'Cannot create a field from a "{type(field)}" object')
コード例 #8
0
ファイル: scoping.py プロジェクト: pyansys/DPF-Core
    def __init__(self, scoping=None, server=None, ids=None, location=None):
        """Initializes the scoping with an optional scoping message or
        by connecting to a stub.
        """
        if server is None:
            import ansys.dpf.core.server as serverlib

            server = serverlib._global_server()

        self._server = server
        self._stub = self._connect()

        if scoping is None:
            request = base_pb2.Empty()
            self._message = self._stub.Create(request)
        else:
            self._message = scoping

        if ids:
            self.ids = ids
        if location:
            self.location = location
コード例 #9
0
def available_operator_names(server=None):
    """Returns the list of operator names available in the server.

    Parameters
    ----------
    server : server.DPFServer, optional
        Server with channel connected to the remote or local instance. When
        ``None``, attempts to use the the global server.

    Returns
    -------
    list

    """
    if server is None:
        server = serverlib._global_server()
    service = operator_pb2_grpc.OperatorServiceStub(
        server.channel).ListAllOperators(
            operator_pb2.ListAllOperatorsRequest())
    arr = []
    for chunk in service:
        arr.extend(re.split(r'[\x00-\x08]', chunk.array.decode('utf-8')))
    return arr