Metadata-Version: 2.1
Name: compas_lmgc90
Version: 0.1.8
Summary: Binding for LMGC90.
Author-Email: Petras Vestartas <petrasvestartas@gmail.com>
Classifier: Development Status :: 3 - Alpha
Classifier: Topic :: Scientific/Engineering
Classifier: Operating System :: Unix
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: C++
Classifier: License :: OSI Approved :: MIT License
Project-URL: Homepage, https://github.com/BlockResearchGroup/compas_lmgc90
Project-URL: Repository, https://github.com/BlockResearchGroup/compas_lmgc90
Project-URL: Issues, https://github.com/BlockResearchGroup/compas_lmgc90/issues
Requires-Python: >=3.9
Requires-Dist: numpy>=1.21.0
Requires-Dist: compas>=2
Requires-Dist: compas_dem
Requires-Dist: compas_viewer
Provides-Extra: dev
Requires-Dist: attrs>=17.4; extra == "dev"
Requires-Dist: black>=22.12.0; extra == "dev"
Requires-Dist: bump-my-version; extra == "dev"
Requires-Dist: compas_invocations2; extra == "dev"
Requires-Dist: invoke>=0.14; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: sphinx_compas2_theme; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: wheel; extra == "dev"
Requires-Dist: scikit-build-core; extra == "dev"
Requires-Dist: nanobind; extra == "dev"
Requires-Dist: build; extra == "dev"
Description-Content-Type: text/markdown

# compas_lmgc90

Python bindings for LMGC90 discrete element solver.

## Installation

### Conda

With conda alreay installed, create a conda environment from the yaml file
```bash
conda env create -f environment.yml
```
Then activate it and install the module inside it:
```bash
conda activate compas_lmgc90-dev
python -m pip install .
```


### Linux

```bash
# Install dependencies
sudo apt update
sudo apt install -y gfortran libopenblas-dev liblapack-dev cmake

# Clone and install
git clone https://github.com/BlockResearchGroup/compas_lmgc90.git
cd compas_lmgc90
conda create -n lmgc90 python=3.12 -y
conda activate lmgc90
conda install -c conda-forge libstdcxx-ng=14
pip install -r requirements-dev.txt
pip install --no-build-isolation -ve .
```

**Note:** The `libstdcxx-ng=14` is required because the module is compiled with GCC 13.3+ and needs GLIBCXX_3.4.32.

### macOS

```bash
# Install dependencies
brew install gcc openblas cmake

# Clone and install
git clone https://github.com/BlockResearchGroup/compas_lmgc90.git
cd compas_lmgc90
conda create -n lmgc90 python=3.12 -y
conda activate lmgc90
pip install -r requirements-dev.txt
pip install --no-build-isolation -ve .
```

**Note:** CMake will auto-detect Homebrew GCC/gfortran. If detection fails, set compilers manually:
```bash
export FC=$(brew --prefix gcc)/bin/gfortran-14
export CC=$(brew --prefix gcc)/bin/gcc-14  
export CXX=$(brew --prefix gcc)/bin/g++-14
```

### Windows

Windows is not currently supported. The package requires Fortran compilers and POSIX-style build tools.

## Usage

```python
from compas_dem.models import BlockModel
from compas_dem.templates import ArchTemplate
from compas_lmgc90.solver import Solver

# Create model
template = ArchTemplate(rise=3, span=10, thickness=0.5, depth=0.5, n=20)
model = BlockModel.from_boxes(template.blocks())

# Run simulation
solver = Solver(model)
solver.set_supports(z_threshold=0.4)
solver.preprocess()
solver.run(nb_steps=100)
solver.finalize()
```

## Examples

```bash
python temp/dem_of_an_arch.py
python temp/dem_of_a_wall.py
python temp/dem_of_a_dome.py
python temp/contacts.py
```

## Troubleshooting

### ImportError: libmatlib.so not found

Make sure you installed the package with `pip install -e .` in the correct conda environment. The LMGC90 libraries are bundled during installation.

### GLIBCXX version error (Linux)

Install the required libstdc++:
```bash
conda install -c conda-forge libstdcxx-ng=14
```

### macOS: Compiler not found

If CMake can't find gfortran, manually set the compilers before building:
```bash
export FC=$(brew --prefix gcc)/bin/gfortran-14
export CC=$(brew --prefix gcc)/bin/gcc-14
export CXX=$(brew --prefix gcc)/bin/g++-14
pip install --no-build-isolation -ve .
```

### macOS: Compiler not found

If CMake can't find gfortran, manually set the compilers before building:
```bash
export FC=$(brew --prefix gcc)/bin/gfortran-14
export CC=$(brew --prefix gcc)/bin/gcc-14
export CXX=$(brew --prefix gcc)/bin/g++-14
pip install --no-build-isolation -ve .
```

## Contributing

### Testing a Pull Request

```bash
# Fetch the PR branch (replace PR_NUMBER with the actual number)
git fetch upstream pull/PR_NUMBER/head:pr-branch-name
git checkout pr-branch-name

# Build and test
pip install --no-build-isolation -ve .
python temp/contacts.py
```

### Pushing changes to a PR

```bash
# Add the PR author's fork as a remote
git remote add author https://github.com/AUTHOR/compas_lmgc90.git

# Push your changes to their branch
git push author branch-name
```

**Note:** This requires the PR author to have enabled "Allow edits from maintainers" on their PR.
