generated from ansys/template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mohamed Koubaa <koubaa@github.com>
- Loading branch information
Showing
18 changed files
with
5,055 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Use PyDYNA to run LSDYNA locally | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Run LS-DYNA using ansys.dyna.core.run | ||
************************************* | ||
|
||
.. code:: python | ||
import os | ||
from ansys.dyna.core.run import run_dyna | ||
dynafile = "input.k" | ||
working_directory = os.path.getcwd() | ||
filepath = run_dyna(dynafile, working_directory=dynadir) | ||
...... | ||
How it works | ||
************ | ||
|
||
``run_dyna`` attempts to find an installation of the LS-DYNA solver on your machine. | ||
It uses the Python dependency ``ansys-tools-path`` to discover where LS-DYNA is installed. | ||
After installing ``ansys-tools-path``, the location of LS-DYNA can be saved by running | ||
``save-ansys-path --name dyna {path/to/dyna}`` so that subsequent usages of ``run_dyna`` | ||
will look there. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
markers = | ||
run: tests that exercise the `run` subpackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
from .local_solver import run_dyna # noqa: F401 | ||
from .options import MemoryUnit, MpiOption, Precision # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
"""Base runner class.""" | ||
|
||
from ansys.dyna.core.run.options import MemoryUnit, MpiOption, Precision | ||
|
||
|
||
class BaseRunner: | ||
def __init__(self, **kwargs): | ||
# TODO - split mpi option into precision? | ||
self.mpi_option = kwargs.get("mpi_option", MpiOption.SMP) | ||
self.ncpu = kwargs.get("ncpu", 1) | ||
self.memory = kwargs.get("memory", 20) | ||
self.memory_unit = kwargs.get("memory_unit", MemoryUnit.MB) | ||
self.precision = kwargs.get("precision", Precision.DOUBLE) | ||
|
||
def get_memory_string(self) -> str: | ||
unit = {MemoryUnit.MB: "m", MemoryUnit.GB: "G"}[self.memory_unit] | ||
return f"{self.memory}{unit}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
import os | ||
|
||
from ansys.tools.path import get_dyna_path, get_latest_ansys_installation | ||
from ansys.tools.path.path import _get_unified_install_base_for_version | ||
|
||
from ansys.dyna.core.run.base_runner import BaseRunner | ||
from ansys.dyna.core.run.options import MpiOption, Precision | ||
|
||
|
||
class LinuxRunner(BaseRunner): | ||
"""Linux implementation to Run LS-DYNA. Tested with a custom exutable | ||
and when LS-DYNA is installed as part of the unified Ansys installation | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
self.executable = kwargs.get("executable", None) | ||
version = kwargs.get("version", None) | ||
self._find_solver(version, self.executable) | ||
|
||
def set_input(self, input_file: str, working_directory: str) -> None: | ||
self.input_file = input_file | ||
self.working_directory = working_directory | ||
|
||
def _find_solver(self, version: int, executable: str) -> None: | ||
atp_dyna_path = get_dyna_path(find=False, allow_input=False) | ||
if executable is not None: | ||
# User passed in executable directly. Use that. | ||
if os.path.isfile(executable): | ||
self.solver = executable | ||
elif atp_dyna_path is not None: | ||
# User stored dyna solver in ansys-tools-path, use that | ||
self.solver = atp_dyna_path | ||
elif version is not None: | ||
# User passed in the version, compute the path to the dyna solver from the | ||
# unified installation | ||
# of that version | ||
install_loc, _ = _get_unified_install_base_for_version(version) | ||
self.solver = os.path.join(install_loc, "ansys", "bin", "linx64", self._get_exe_name()) | ||
else: | ||
# User passed nothing, find the dyna solver from the latest unified installation | ||
install_loc, _ = get_latest_ansys_installation() | ||
self.solver = os.path.join(install_loc, "ansys", "bin", "linx64", self._get_exe_name()) | ||
|
||
def _get_exe_name(self) -> str: | ||
exe_name = { | ||
(MpiOption.SMP, Precision.SINGLE): "lsdyna_sp.e", | ||
(MpiOption.SMP, Precision.DOUBLE): "lsdyna_dp.e", | ||
(MpiOption.MPP_INTEL_MPI, Precision.SINGLE): "lsdyna_sp_mpp.e", | ||
(MpiOption.MPP_INTEL_MPI, Precision.DOUBLE): "lsdyna_dp_mpp.e", | ||
}[(self.mpi_option, self.precision)] | ||
return exe_name | ||
|
||
def run(self) -> None: | ||
os.chdir(self.working_directory) | ||
if self.mpi_option == MpiOption.MPP_INTEL_MPI: | ||
os.system( | ||
f"mpirun -np {self.ncpu} {self.solver} i={self.input_file} memory={self.get_memory_string()}" # noqa: E501 | ||
) | ||
else: | ||
os.system( | ||
f"{self.solver} i={self.input_file} ncpu={self.ncpu} memory={self.get_memory_string()}" # noqa: E501 | ||
) |
Oops, something went wrong.