Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .fz/calculators/Modelica.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# if directory as input, cd into it
if [ -d "$1" ]; then
cd "$1"
MO_FILE=`ls *.mo | head -n 1`
shift
# if $* are files, find the .mo file
elif [ $# -gt 1 ]; then
MO_FILE=""
for f in "$@"; do
if [ `echo $f | grep -c '\.mo$'` -eq 1 ]; then
MO_FILE="$f"
break
fi
done
if [ -z "$MO_FILE" ]; then
echo "No .mo file found in input files. Exiting."
exit 1
fi
shift $#
else
MO_FILE="$1"
fi

# Check if the file is a .mos script or a .mo model
if [ ! "${MO_FILE: -4}" == ".mos" ]; then
model=`grep "model" $MO_FILE | awk '{print $2}'`
cat > $MO_FILE.mos <<- EOM
loadModel(Modelica);
loadFile("$MO_FILE");
simulate($model, stopTime=1,tolerance=0.001,outputFormat="csv");
EOM
omc $MO_FILE.mos > $MO_FILE.moo 2>&1 &
else
omc $MO_FILE > $MO_FILE.moo 2>&1 &
fi

PID_OMC=$!
echo $PID_OMC >> PID #this will allow fz to kill process if needed

wait $PID_OMC

rm -f PID

ERROR=`cat *.moo | grep "Failed"`
if [ ! "$ERROR" == "" ]; then
echo $ERROR >&2
exit 1
fi
6 changes: 6 additions & 0 deletions .fz/calculators/localhost.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"uri": "sh://",
"models": {
"Modelica":"bash .fz/calculators/Modelica.sh"
}
}
10 changes: 10 additions & 0 deletions .fz/models/Modelica.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "Modelica",
"varprefix": "$",
"formulaprefix": "@",
"delim": "{}",
"commentline": "//",
"output": {
"res": "python -c 'import pandas;import glob;import json;print(json.dumps({f.split(\"_res.csv\")[0]:pandas.read_csv(f).to_dict() for f in glob.glob(\"*_res.csv\")}))'"
}
}
40 changes: 40 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Verify Plugin Structure

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

permissions:
contents: read

jobs:
verify:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Run verification script
run: |
python3 tests/verify_installation.py

- name: Validate JSON files
run: |
echo "Validating JSON files..."
python3 -m json.tool .fz/models/Modelica.json > /dev/null
python3 -m json.tool .fz/calculators/localhost.json > /dev/null
echo "✓ All JSON files are valid"

- name: Check shell script syntax
run: |
echo "Checking shell script syntax..."
bash -n .fz/calculators/Modelica.sh
echo "✓ Shell script syntax is valid"
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
.venv
pip-log.txt
pip-delete-this-directory.txt
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Modelica/OpenModelica
*.moo
*.mos
*.exe
*.dll
*.o
*.so
*.c
*.h
*.makefile
*.log
*.libs
*_info.json
*_init.xml
*.mat
*.fmtmp/

# Results and output directories
results/
results_*/
output/
.fz/tmp/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store

# OS
Thumbs.db
.directory
134 changes: 134 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Contributing to fz-modelica

Thank you for your interest in contributing to fz-modelica!

## How to Contribute

### Reporting Issues

If you encounter any bugs or have feature requests:

1. Check if the issue already exists in the [issue tracker](https://github.com/Funz/fz-modelica/issues)
2. If not, create a new issue with:
- A clear, descriptive title
- Detailed description of the problem or feature
- Steps to reproduce (for bugs)
- Expected vs actual behavior
- Your environment (OS, Python version, OpenModelica version)

### Submitting Changes

1. Fork the repository
2. Create a new branch for your changes:
```bash
git checkout -b feature/your-feature-name
```
3. Make your changes
4. Test your changes thoroughly
5. Commit with clear, descriptive messages
6. Push to your fork
7. Submit a pull request

## Development Setup

### Prerequisites

- Python 3.7+
- OpenModelica (omc)
- Git

### Setting up Development Environment

1. Clone your fork:
```bash
git clone https://github.com/YOUR_USERNAME/fz-modelica.git
cd fz-modelica
```

2. Install fz framework:
```bash
pip install funz-fz
# or for development:
pip install -e git+https://github.com/Funz/fz.git
```

3. Install dependencies:
```bash
pip install pandas matplotlib
```

4. Test the examples:
```bash
python examples/run_single.py
```

## Testing

Before submitting a pull request:

1. Test with the provided examples:
```bash
cd examples
python run_single.py
python run_parametric.py
python run_with_cache.py
```

2. Test with your own Modelica models if applicable

3. Ensure the calculator script works correctly:
```bash
cd samples
bash ../.fz/calculators/Modelica.sh NewtonCooling.mo
# Should generate output files
```

## Code Style

- Follow Python PEP 8 style guide for Python code
- Use clear, descriptive variable names
- Add comments for complex logic
- Keep functions focused and modular

## Adding New Features

When adding new features:

1. **New Modelica Models**: Add to `samples/` directory with documentation
2. **Enhanced Calculator Script**: Maintain backward compatibility
3. **Configuration Changes**: Update both `.fz/` files and documentation
4. **Examples**: Add example scripts to `examples/` directory

## Documentation

When making changes:

1. Update README.md if user-facing functionality changes
2. Add inline comments for complex code
3. Update examples if the API changes
4. Include usage examples in pull request description

## Pull Request Guidelines

A good pull request:

- Addresses a single concern
- Includes clear description of changes
- References related issues (if any)
- Includes examples or tests
- Updates documentation as needed
- Follows existing code style

## Questions?

If you have questions:

- Check the [fz documentation](https://github.com/Funz/fz)
- Review existing issues and pull requests
- Create a new issue with the "question" label

## License

By contributing, you agree that your contributions will be licensed under the same BSD 3-Clause License that covers the project.

Thank you for contributing! 🎉
Loading