|
4 | 4 | import json
|
5 | 5 | import os
|
6 | 6 | from typing import Any
|
7 |
| -import warnings |
8 |
| - |
9 |
| -import grpc |
10 | 7 |
|
11 | 8 | from ansys.fluent.core.fluent_connection import _FluentConnection
|
12 |
| -from ansys.fluent.core.services.datamodel_tui import TUIMenu |
13 |
| -from ansys.fluent.core.session_base_meshing import _BaseMeshing |
14 |
| -from ansys.fluent.core.session_shared import _CODEGEN_MSG_DATAMODEL, _CODEGEN_MSG_TUI |
15 |
| -from ansys.fluent.core.solver.flobject import get_root as settings_get_root |
16 |
| -from ansys.fluent.core.utils.fluent_version import get_version_for_filepath |
| 9 | +from ansys.fluent.core.session_shared import ( # noqa: F401 |
| 10 | + _CODEGEN_MSG_DATAMODEL, |
| 11 | + _CODEGEN_MSG_TUI, |
| 12 | +) |
17 | 13 | from ansys.fluent.core.utils.logging import LOG
|
18 | 14 |
|
19 | 15 | try:
|
@@ -155,193 +151,6 @@ def download(self, file_name: str, local_file_path: str = None):
|
155 | 151 | return self._uploader.download(file_name, local_file_path)
|
156 | 152 |
|
157 | 153 |
|
158 |
| -class Session: |
159 |
| - """Instantiates a Fluent connection. This is a deprecated class. This has |
160 |
| - been replaced by the "_BaseSession" class to implement the new fluent |
161 |
| - launch modes. |
162 |
| -
|
163 |
| - Attributes |
164 |
| - ---------- |
165 |
| - scheme_eval: SchemeEval |
166 |
| - Instance of SchemeEval on which Fluent's scheme code can be |
167 |
| - executed. |
168 |
| -
|
169 |
| - Methods |
170 |
| - ------- |
171 |
| - create_from_server_info_file( |
172 |
| - server_info_filepath, cleanup_on_exit, start_transcript |
173 |
| - ) |
174 |
| - Create a Session instance from server-info file |
175 |
| - """ |
176 |
| - |
177 |
| - def __init__( |
178 |
| - self, |
179 |
| - ip: str = None, |
180 |
| - port: int = None, |
181 |
| - password: str = None, |
182 |
| - channel: grpc.Channel = None, |
183 |
| - cleanup_on_exit: bool = True, |
184 |
| - start_transcript: bool = True, |
185 |
| - remote_instance=None, |
186 |
| - fluent_connection=None, |
187 |
| - ): |
188 |
| - warnings.warn("Please use the new fluent launch modes", DeprecationWarning) |
189 |
| - if not fluent_connection: |
190 |
| - self.fluent_connection = _FluentConnection( |
191 |
| - ip=ip, |
192 |
| - port=port, |
193 |
| - password=password, |
194 |
| - channel=channel, |
195 |
| - cleanup_on_exit=cleanup_on_exit, |
196 |
| - start_transcript=start_transcript, |
197 |
| - remote_instance=remote_instance, |
198 |
| - ) |
199 |
| - else: |
200 |
| - self.fluent_connection = fluent_connection |
201 |
| - |
202 |
| - self.scheme_eval = self.fluent_connection.scheme_eval |
203 |
| - |
204 |
| - self.meshing = _BaseMeshing(None, self.fluent_connection) |
205 |
| - |
206 |
| - self._datamodel_service_se = self.fluent_connection.datamodel_service_se |
207 |
| - self._datamodel_service_tui = self.fluent_connection.datamodel_service_tui |
208 |
| - self._settings_service = self.fluent_connection.settings_service |
209 |
| - |
210 |
| - self.solver = Session.Solver(self.fluent_connection) |
211 |
| - |
212 |
| - self._uploader = None |
213 |
| - self._preferences = None |
214 |
| - self._solverworkflow = None |
215 |
| - |
216 |
| - @classmethod |
217 |
| - def create_from_server_info_file( |
218 |
| - cls, |
219 |
| - server_info_filepath: str, |
220 |
| - cleanup_on_exit: bool = True, |
221 |
| - start_transcript: bool = True, |
222 |
| - ) -> "Session": |
223 |
| - """Create a Session instance from server-info file. |
224 |
| -
|
225 |
| - Parameters |
226 |
| - ---------- |
227 |
| - server_info_filepath : str |
228 |
| - Path to server-info file written out by Fluent server |
229 |
| - cleanup_on_exit : bool, optional |
230 |
| - When True, the connected Fluent session will be shut down |
231 |
| - when PyFluent is exited or exit() is called on the session |
232 |
| - instance, by default True. |
233 |
| - start_transcript : bool, optional |
234 |
| - The Fluent transcript is started in the client only when |
235 |
| - start_transcript is True. It can be started and stopped |
236 |
| - subsequently via method calls on the Session object. |
237 |
| - Defaults to true. |
238 |
| -
|
239 |
| - Returns |
240 |
| - ------- |
241 |
| - Session |
242 |
| - Session instance |
243 |
| - """ |
244 |
| - ip, port, password = parse_server_info_file(server_info_filepath) |
245 |
| - session = Session( |
246 |
| - fluent_connection=_FluentConnection( |
247 |
| - ip=ip, |
248 |
| - port=port, |
249 |
| - password=password, |
250 |
| - cleanup_on_exit=cleanup_on_exit, |
251 |
| - start_transcript=start_transcript, |
252 |
| - ) |
253 |
| - ) |
254 |
| - return session |
255 |
| - |
256 |
| - def __enter__(self): |
257 |
| - """Close the Fluent connection and exit Fluent.""" |
258 |
| - return self |
259 |
| - |
260 |
| - def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any): |
261 |
| - self.fluent_connection.exit() |
262 |
| - |
263 |
| - def __getattr__(self, attr): |
264 |
| - return getattr(self.fluent_connection, attr) |
265 |
| - |
266 |
| - def __dir__(self): |
267 |
| - return sorted( |
268 |
| - set( |
269 |
| - list(self.__dict__.keys()) |
270 |
| - + dir(type(self)) |
271 |
| - + dir(self.fluent_connection) |
272 |
| - ) |
273 |
| - ) |
274 |
| - |
275 |
| - def upload(self, file_path: str, remote_file_name: str = None): |
276 |
| - """Uploads a file on the server.""" |
277 |
| - if not self._uploader: |
278 |
| - self._uploader = _Uploader(self.fluent_connection._remote_instance) |
279 |
| - return self._uploader.upload(file_path, remote_file_name) |
280 |
| - |
281 |
| - def download(self, file_name: str, local_file_path: str = None): |
282 |
| - """Downloads a file from the server.""" |
283 |
| - if not self._uploader: |
284 |
| - self._uploader = _Uploader(self.fluent_connection._remote_instance) |
285 |
| - return self._uploader.download(file_name, local_file_path) |
286 |
| - |
287 |
| - @property |
288 |
| - def preferences(self): |
289 |
| - """preferences datamodel root.""" |
290 |
| - if self._preferences is None: |
291 |
| - self._preferences = _get_preferences(self) |
292 |
| - return self._preferences |
293 |
| - |
294 |
| - @property |
295 |
| - def solverworkflow(self): |
296 |
| - """solverworkflow datamodel root.""" |
297 |
| - if self._solverworkflow is None: |
298 |
| - self._solverworkflow = _get_solverworkflow(self) |
299 |
| - return self._solverworkflow |
300 |
| - |
301 |
| - class Solver: |
302 |
| - def __init__(self, fluent_connection: _FluentConnection): |
303 |
| - self._fluent_connection = fluent_connection |
304 |
| - self._tui_service = fluent_connection.datamodel_service_tui |
305 |
| - self._settings_service = fluent_connection.settings_service |
306 |
| - self._tui = None |
307 |
| - self._settings_root = None |
308 |
| - self._version = None |
309 |
| - |
310 |
| - def get_fluent_version(self): |
311 |
| - """Gets and returns the fluent version.""" |
312 |
| - return self._fluent_connection.get_fluent_version() |
313 |
| - |
314 |
| - @property |
315 |
| - def version(self): |
316 |
| - if self._version is None: |
317 |
| - self._version = get_version_for_filepath(session=self) |
318 |
| - return self._version |
319 |
| - |
320 |
| - @property |
321 |
| - def tui(self): |
322 |
| - """Instance of ``main_menu`` on which Fluent's SolverTUI methods |
323 |
| - can be executed.""" |
324 |
| - if self._tui is None: |
325 |
| - try: |
326 |
| - tui_module = importlib.import_module( |
327 |
| - f"ansys.fluent.core.solver.tui_{self.version}" |
328 |
| - ) |
329 |
| - self._tui = tui_module.main_menu([], self._tui_service) |
330 |
| - except (ImportError, ModuleNotFoundError): |
331 |
| - LOG.warning(_CODEGEN_MSG_TUI) |
332 |
| - self._tui = TUIMenu([], self._tui_service) |
333 |
| - return self._tui |
334 |
| - |
335 |
| - @property |
336 |
| - def root(self): |
337 |
| - """root settings object.""" |
338 |
| - if self._settings_root is None: |
339 |
| - self._settings_root = settings_get_root( |
340 |
| - flproxy=self._settings_service, version=self.version |
341 |
| - ) |
342 |
| - return self._settings_root |
343 |
| - |
344 |
| - |
345 | 154 | class _Uploader:
|
346 | 155 | """Instantiates a file uploader and downloader to have a seamless file
|
347 | 156 | reading / writing in the cloud particularly in Ansys lab . Here we are
|
|
0 commit comments