Metadata-Version: 2.4
Name: py-crane
Version: 0.3.1
Summary: Basic crane simulation model including publication as FMU, for usage in the SEACo project.
Project-URL: Homepage, https://github.com/dnv-opensource/py-crane
Project-URL: Documentation, https://dnv-opensource.github.io/py-crane/README.html
Project-URL: Repository, https://github.com/dnv-opensource/py-crane.git
Project-URL: Issues, https://github.com/dnv-opensource/py-crane/issues
Project-URL: Changelog, https://github.com/dnv-opensource/py-crane/blob/main/CHANGELOG.md
Author-email: Siegfried Eisinger <siegfried.eisinger@dnv.com>, Jorge Luis Mendez <jorge.luis.mendez@dnv.com>
Maintainer-email: Claas Rostock <claas.rostock@dnv.com>
License: MIT License
        
        Copyright (c) 2025 [DNV](https://www.dnv.com) [open source](https://github.com/dnv-opensource)
        
        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.
License-File: LICENSE
Keywords: FMI,OSP,crane,model,simulation,tight coupling
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Requires-Dist: component-model>=0.4.0
Requires-Dist: numpy>=2.3
Requires-Dist: pythonfmu>=0.7.0
Requires-Dist: scipy>=1.17.0
Provides-Extra: rest
Requires-Dist: docutils>=0.22.4; extra == 'rest'
Provides-Extra: test
Requires-Dist: fmpy>=0.3.21; extra == 'test'
Requires-Dist: libcosimpy>=0.0.5; extra == 'test'
Requires-Dist: matplotlib>=3.10; extra == 'test'
Requires-Dist: plotly>=6.5; extra == 'test'
Description-Content-Type: text/x-rst

|pypi| |versions| |license| |ci| |docs|

Introduction
============
The package extends the `component_model` package to provide the means to construct cranes.
The package can be used to define concrete cranes and simulate their usage, see `tests/resources/mobile-crane.py` as example.

Getting Started
---------------
A concrete crane model should consist of an extension of the Crane object,

* defining general model variables like `name`, `author`, `version`, etc.
* defining the anticipated set of booms
* if there is a wish to keep parameters configurable, these can be kept as parameters of the extended model.
* In a separate script, instantiate the concrete crane, test it and run `Model.build(...)` to make the FMU.

See the file `tests/resources/mobile_crane.py` and related test files
as an example on how a concrete crane can be defined and used.


Installation
------------

.. code:: sh

   pip install py-crane


Usage Example
-------------
This is a simple mobile crane, like they are used on e.g. building sites with

* a short pedestal, which can be turn around,
* one boom with variable length and which can be lifted
* one rope, where loads can be attached.

.. code-block:: Python

    from py_crane.crane import Crane

    class MobileCrane(Crane):
        """Simple mobile crane for FMU testing purposes.
        The crane has a short pedestal, one variable-length stiff boom and a rope.
        The size and weight of the various parts can be configured.

        Args:
            name (str) : name of the crane type
            description (str) : short description
            author (str)
            version (str)
            pedestalMass (str) : mass of the pedestal - quantity and unit as string
            pedestalHeight (str) : height (fixed) of the pedestal, with units
            boomMass (str) : mass of the single boom, with units
            boomLength0 (str) : minimum length of the boom, with units
            boomLength1 (str) : maximum length of the boom, with units
        """

        def __init__(
            self,
            name: str = "mobile_crane",
            description: str = "Simple mobile crane (for FMU testing) with short pedestal, one variable-length elevation boom and a rope",
            author: str = "DNV, SEACo project",
            version: str = "0.2",
            pedestalMass: str = "10000.0 kg",
            pedestalHeight: str = "3.0 m",
            boomMass: str = "1000.0 kg",
            boomLength0: str = "8 m",
            boomLength1: str = "50 m",
            rope_mass_range: tuple = ("50kg", "2000 kg"),
            **kwargs,
        ):
            super().__init__(name=name, description=description, author=author, version=version, **kwargs)
            _ = self.add_boom(
                name="pedestal",
                description="The crane base, on one side fixed to the vessel and on the other side the first crane boom is fixed to it. The mass should include all additional items fixed to it, like the operator's cab",
                mass=pedestalMass,
                massCenter=(0.5, -1.0, 0.8),
                boom=(pedestalHeight, "0deg", "0deg"),
                boom_rng=(None, None, ("0deg", "360deg")),
            )
            _ = self.add_boom(
                name="boom",
                description="The boom. Can be lifted and length can change within the given range",
                mass=boomMass,
                massCenter=(0.5, 0, 0),
                boom=(boomLength0, "90deg", "0deg"),
                boom_rng=((boomLength0, boomLength1), (0, "90deg"), None),
            )
            _ = self.add_boom(
                name="rope",
                description="The rope fixed to the last boom. Flexible connection",
                mass="50.0 kg",  # so far basically the hook
                massCenter=0.95,
                mass_rng=rope_mass_range,
                boom=("1e-6 m", "180deg", "0 deg"),
                boom_rng=(
                    ("1e-6 m", boomLength1),
                    ("90deg", "270deg"),
                    ("-180deg", "180deg"),
                ),
                damping=50.0,
                animationLW=2,
            )
            # make sure that _comSub is calculated for all booms:
            self.calc_statics_dynamics(None)

        def do_step(self, currentTime, stepSize):
            status = super().do_step(currentTime, stepSize)
            # print(f"Time {currentTime}, {self.rope_tip}")
            # print(f"MobileCrane.do_step. Status {status}")
            return status



Testing and usage of the `MobileCrane.fmu` is demonstrated as part of related `test_***` files.


Development Setup
-----------------

1. Install uv
^^^^^^^^^^^^^
This project uses `uv` as package manager.

If you haven't already, install `uv <https://docs.astral.sh/uv/>`_, preferably using it's `"Standalone installer" <https://docs.astral.sh/uv/getting-started/installation/#__tabbed_1_2/>`_ method:

..on Windows:

.. code:: sh

   powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

..on MacOS and Linux:

.. code:: sh

   curl -LsSf https://astral.sh/uv/install.sh | sh

(see `docs.astral.sh/uv <https://docs.astral.sh/uv/getting-started/installation//>`_ for all / alternative installation methods.)

Once installed, you can update `uv` to its latest version, anytime, by running:

``uv self update``

2. Install Python
^^^^^^^^^^^^^^^^^
This project requires Python 3.11 or later.

If you don't already have a compatible version installed on your machine, the probably most comfortable way to install Python is through ``uv``:

.. code:: sh

   uv python install

This will install the latest stable version of Python into the uv Python directory, i.e. as a uv-managed version of Python.

Alternatively, and if you want a standalone version of Python on your machine, you can install Python either via ``winget``:

.. code:: sh

   winget install --id Python.Python

or you can download and install Python from the `python.org <https://www.python.org/downloads//>`_ website.

3. Clone the repository
^^^^^^^^^^^^^^^^^^^^^^^
Clone the py-crane repository into your local development directory:

.. code:: sh

   git clone https://github.com/dnv-opensource/py-crane path/to/your/dev/py-crane

Change into the project directory after cloning:

.. code:: sh

   cd py-crane

4. Install dependencies
^^^^^^^^^^^^^^^^^^^^^^^
Run ``uv sync -U`` to create a virtual environment and install all project dependencies into it:

.. code:: sh

   uv sync -U

..

   **Note**: Using ``--no-dev`` will omit installing development
   dependencies.

   **Explanation**: The ``-U`` option stands for ``--update``. It forces
   ``uv`` to fetch and install the latest versions of all dependencies,
   ensuring that your environment is up-to-date.

..

   **Note**: ``uv`` will create a new virtual environment called
   ``.venv`` in the project root directory when running ``uv sync -U``
   the first time. Optionally, you can create your own virtual
   environment using e.g. ``uv venv``, before running ``uv sync -U``.

5. (Optional) Activate the virtual environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When using ``uv``, there is in almost all cases no longer a need to manually activate the virtual environment.

``uv`` will find the ``.venv`` virtual environment in the working directory or any parent directory, and activate it on the fly whenever you run a command via `uv` inside your project folder structure:

.. code:: sh

   uv run <command>

However, you still *can* manually activate the virtual environment if needed.
When developing in an IDE, for instance, this can in some cases be necessary depending on your IDE settings.
To manually activate the virtual environment, run one of the "known" legacy commands:

..on Windows:

.. code:: sh

   .venv\Scripts\activate.bat

..on Linux:

.. code:: sh

   source .venv/bin/activate

6. Install pre-commit hooks
^^^^^^^^^^^^^^^^^^^^^^^^^^^
The ``.pre-commit-config.yaml`` file in the project root directory contains a configuration for pre-commit hooks.
To install the pre-commit hooks defined therein in your local git repository, run:

.. code:: sh

   uv run pre-commit install

All pre-commit hooks configured in ``.pre-commit-config.yam`` will now run each time you commit changes.

pre-commit can also manually be invoked, at anytime, using:

.. code:: sh

   uv run pre-commit run --all-files

To skip the pre-commit validation on commits (e.g. when intentionally
committing broken code), run:

.. code:: sh

   uv run git commit -m <MSG> --no-verify

To update the hooks configured in ``.pre-commit-config.yaml`` to their
newest versions, run:

.. code:: sh

   uv run pre-commit autoupdate

7. Test that the installation works
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To test that the installation works, run pytest in the project root folder:

.. code:: sh

   uv run pytest

Meta
----
Copyright (c) 2025 `DNV <https://www.dnv.com/>`_ AS. All rights reserved.

Siegfried Eisinger -
`@LinkedIn <https://www.linkedin.com/in/siegfried-eisinger-a337638b>`__
- siegfried.eisinger@dnv.com

Jorge Luis Mendez - `@LinkedIn <https://www.linkedin.com/in/jorgelmh>`__
- jorge.luis.mendez@dnv.com

Distributed under the MIT license. See `LICENSE <LICENSE.md/>`_ for more information.

`https://github.com/dnv-opensource/py-crane <https://github.com/dnv-opensource/py-crane/>`_

Contributing
------------
Anybody in the FMU, OSPand SEACo community is especially welcome to contribute to this code, to make it better,
and especially including other features from model assurance and from SEACo issues.

To contribute, follow these steps:

1. Fork it `<https://github.com/dnv-opensource/py-crane/fork/>`_
2. Create an issue in your GitHub repo
3. Create your branch based on the issue number and type (``git checkout -b issue-name``)
4. Evaluate and stage the changes you want to commit (``git add -i``)
5. Commit your changes (``git commit -am 'place a descriptive commit message here'``)
6. Push to the branch (``git push origin issue-name``)
7. Create a new Pull Request in GitHub

For your contribution, please make sure you follow the `STYLEGUIDE <STYLEGUIDE.md/>`_ before creating the Pull Request.

.. |pypi| image:: https://img.shields.io/pypi/v/py-crane.svg?color=blue
   :target: https://pypi.python.org/pypi/py-crane
.. |versions| image:: https://img.shields.io/pypi/pyversions/py-crane.svg?color=blue
   :target: https://pypi.python.org/pypi/py-crane
.. |license| image:: https://img.shields.io/pypi/l/py-crane.svg
   :target: https://github.com/dnv-opensource/py-crane/blob/main/LICENSE
.. |ci| image:: https://img.shields.io/github/actions/workflow/status/dnv-opensource/py-crane/.github%2Fworkflows%2Fnightly_build.yml?label=ci
.. |docs| image:: https://img.shields.io/github/actions/workflow/status/dnv-opensource/py-crane/.github%2Fworkflows%2Fpush_to_release.yml?label=docs
   :target: https://dnv-opensource.github.io/py-crane/README.html
