當前位置: 首頁>>代碼示例>>Python>>正文


Python LinearAlgebra.orthonormal_tangent_basis方法代碼示例

本文整理匯總了Python中LinearAlgebra.orthonormal_tangent_basis方法的典型用法代碼示例。如果您正苦於以下問題:Python LinearAlgebra.orthonormal_tangent_basis方法的具體用法?Python LinearAlgebra.orthonormal_tangent_basis怎麽用?Python LinearAlgebra.orthonormal_tangent_basis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在LinearAlgebra的用法示例。


在下文中一共展示了LinearAlgebra.orthonormal_tangent_basis方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: start_client

# 需要導入模塊: import LinearAlgebra [as 別名]
# 或者: from LinearAlgebra import orthonormal_tangent_basis [as 別名]
    def start_client(self):
        """Start the instance of SimulationClient and begin computing local geodesics.

        """

        # Define a flag to indicate if contact with the SimulationServer instance is possible.
        connection_made = False

        # Create a response to send to the SimulationServer indicating that this is the first time this SimulationClient
        # has attempted to get a task.
        client_response = {'status_code': comm_code('CLIENT_FIRST_CONTACT'),
                           'client_name': self.ID}

        # Attempt to connect to the SimulationServer instance.
        try:
            # Create a Client object that communicates with the listener on CURVE_ADDRESS using password AUTHKEY.
            server = Client(self.CURVE_ADDRESS, authkey=self.AUTHKEY)

            # When a connection is made send the client message.
            server.send(client_response)

            # The client assumes the server will respond with a message, either a local geodesic to compute or a message
            # asking the client to try again after DELAY seconds.
            server_response = server.recv()

            # Interpret the servers response by first extracting the status_code variable from the response.
            server_response_code = server_response['status_code']

            # Close the connection to the server at this point to allow other clients to communicate with the
            # SimulationServer.
            server.close()

            # Store in the connection_made flag that it was possible to create a connection.
            connection_made = True

        # If it isn't possible to connect to the server than a socket.error exception is raised.
        except socket.error:
            # Write an error to the log for this client indicating that the connection couldn't be made.
            logging.warning('Failed to Make Connection to SimulationServer. Shutting down client.')

            # Send a signal to the running instances of SimulationPotential that the SimulationClient would have used
            # indicating that they should also shutdown.
            shutdown_metric(self.METRIC_SERVERS, self.AUTHKEY)

        # This is the main loop of the SimulationClient - the program stops running when it is no longer possible to
        # communicate with the SimulationServer. This is decided by the connection_made flag.
        while connection_made:

            # At this point in the code a new server_response should have been received. How the SimulationClient reacts
            # depends on the communication code received.

            # If the server has indicated it is giving the SimulationClient a new geodesic to compute then...
            if server_response_code == comm_code('SERVER_GIVES_NEW_TASK'):

                # Compute the rescaled tangent direction of the curve as store as a NumPy array.
                tangent_direction = (1 / float(self.CONFIGURATION['local_number_of_nodes'] + 1)) * \
                    np.subtract(server_response['right_end_point'], server_response['left_end_point'], dtype='float64')

                # Compute the local geodesic using the BFGS method and store the NumPy array in result
                result = \
                    find_geodesic_midpoint(server_response['left_end_point'],
                                                server_response['right_end_point'],
                                                self.CONFIGURATION['local_number_of_nodes'],
                                                la.orthonormal_tangent_basis(tangent_direction,
                                                                          self.CONFIGURATION['dimension']),
                                                tangent_direction, self.CONFIGURATION['codimension'],
                                                self.METRIC_SERVERS,
                                                self.MASS_MATRIX,
                                                self.AUTHKEY)

                # If the function find_geodesic_midpoint returned a None object then it couldn't contact it's
                # SimulationPotential instances and should be restarted.
                if result is None:
                    # Tell the user via the log that the SimulationPotential instances couldn't be contacted.
                    logging.warning('Failed to Make Connection to SimulationPotential. Shutting down client.')

                    # Exit the main loop of the SimulationClient.
                    break

                # If there is a midpoint then construct a client response to tell the server which node has which new
                # position.
                client_response = {'status_code': comm_code('CLIENT_HAS_MIDPOINT_DATA'),
                                   'node_number': server_response['node_number'],
                                   'new_node_position': result,
                                   'client_name': self.ID
                                   }

            # Otherwise if the server has asked the SimulationClient to try again later...
            elif server_response_code == comm_code('SERVER_REQUEST_CALLBACK'):
                # Make the SimulationClient wait for DELAY seconds
                time.sleep(self.DELAY)

                # Create a response to tell the SimulationServer that the SimulationClient would like a new job.
                client_response = {'status_code': comm_code('CLIENT_HAS_NO_TASK'), 'client_name': self.ID}

            # Attempt to connect to the SimulationServer instance.
            try:
                # Create a Client object that communicates with the listener on CURVE_ADDRESS using password AUTHKEY.
                server = Client(self.CURVE_ADDRESS, authkey=self.AUTHKEY)

#.........這裏部分代碼省略.........
開發者ID:suttond,項目名稱:MODOI,代碼行數:103,代碼來源:SimulationClient.py


注:本文中的LinearAlgebra.orthonormal_tangent_basis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。