Python workflows for coupled electromagnetic-thermal simulations of high-field magnets using Feel++.
- Iterative solver for coupled physics (electromagnetic + thermal + hydraulic)
- Multiple heat transfer correlations (Montgomery, Dittus-Boelter, Colburn, Silverberg)
- Water cooling system simulation with pressure drop calculations
- Support for helical and bitter magnets
- MPI parallel execution via Feel++
- Feel++ >= 0.102.1 (must be installed separately)
- Python >= 3.11
- MPI implementation (OpenMPI or MPICH)
Feel installation see installation notes from official feelpp doc
- Add the Feelpp apt repository
- Install the following packages
sudo apt install python3-feelpp-toolboxes-coefficientformpdes=0.111.0~preview.11-1 \ libfeelpp-toolboxes1-coefficientformpdes=0.111.0~preview.11-1 \ libfeelpp-toolboxes1-core=0.111.0~preview.11-1 \ libfeelpp1=0.111.0~preview.11-1 \ python3-feelpp-toolboxes-core=0.111.0~preview.11-1 \ libfeelpp1=0.111.0~preview.11-1 \ python3-feelpp=0.111.0~preview.11-1 \ python3-feelpp-toolboxes-thermoelectric=0.111.0~preview.11-1 \ libfeelpp-toolboxes1-thermoelectric=0.111.0~preview.11-1 \ libfeelpp-toolboxes1-heat=0.111.0~preview.11-1 \ libfeelpp-toolboxes1-electric=0.111.0~preview.11-1 \ python3-feelpp-toolboxes-electric=0.111.0~preview.11-1 \ python3-feelpp-toolboxes-heat=0.111.0~preview.11-1 \ python3-feelpp-toolboxes-solid=0.111.0~preview.11-1 \ libfeelpp-toolboxes1-solid=0.111.0~preview.11-1 \ libstdc++-14-dev
See pyproject.toml for complete list. Major dependencies:
- numpy, scipy, pandas
- iapws (water properties)
- pint (unit management)
- feelpp and feelpp-toolboxes
For Linux/Mac Os X:
$ python3 -m venv --system-site-packages magnetworkflows-env
$ source ./magnetworkflows-env/bin/activate
$ python3 -m pip install -e ".[dev]"Use deactivate to qui the virtual environment
Note
- feelpp python packages must be installed before creating the virtual python env. see bellow for details
--system-site-packagesis mandatory since we cannot install feelpp python packages with pip
- add lncmi debian repository
- apt update
- apt install ...
# Single configuration run
python -m python_magnetworkflows.cli \
--mdata '{"M9Bitters":{"value":31000,"type":"bitter","filter":"M9Bitters_","flow":"M9Bitters-flow_params.json"}}' \
M9Bitters-cfpdes-thelec-Axi-sim.cfg \
--cooling mean \
--eps 1.e-5
> **mdata** structure
>
> mdata is a dictonnary that holds informations about the magnets configuration:
> The main keys are the name of the magnet.
> The magnet config is stored in a sub-dictionnaty with:
> * value: the current value in A
> * type: the type of xxx for magnet (helix: Insert|bitter: Bitters|supra: Supras) -- see [python_magnetgeo](https://github.com/MagnetDB/python_magnetgeo) for details
> * filter: optional,
> * flow: a json file that contains parameters for water cooling -- see [python_magnetcooling](https://github.com/MagnetDB/python_magnetcooling) for details
>
> support for type=supra not implemented
# Commissioning workflow (multiple current steps)
python -m python_magnetworkflows.commissioning \
--mdata '{"HLtest":{"value":12000,"steplist":[10000,11000,12000],"type":"helix",...}}' \
config.cfg \
--cooling gradHpython_magnetworkflows/
├── cli.py # Main CLI entry point
├── commissioning.py # Multi-step commissioning workflows
├── solver.py # Feel++ solver interface
├── oneconfig.py # Single configuration solver
├── cooling.py # Heat transfer correlations
├── waterflow.py # Hydraulic calculations
├── error.py # Convergence error calculations
└── params.py # Parameter extraction utilities
Simulations require:
- Feel++ CFG file (
.cfg) - solver configuration - JSON model file - geometry and material parameters
- Flow parameters JSON - pump curves and hydraulic data
- Mesh file (
.mshor.json)
See README.md examples section for details.
Note
To check whether or not python_magnetworkflows is installed in the container
singularity exec /home/singularity/feelpp-v0.110.2.sif \
dpkg -L python3-magnetworkflowsIn devcontainer, you shall mount your data directory to /home/vscode to run singularity container,eg:
singularity exec -B /data/M9_M19020601-cfpdes-thmagel_hcurl-nonlinear-Axi-sim/data/geometries:/home/vscode \
/home/singularity/hifimagnet-salome-9.8.4.sif \
salome -w1 -t /opt/SALOME-9.8.0-UB20.04/INSTALL/HIFIMAGNET/bin/salome/HIFIMAGNET_Cmd.py args:M9_M19020601.yaml,--axi,--air,4,6singularity exec -B /data/M9_M19020601-cfpdes-thmagel_hcurl-nonlinear-Axi-sim/data/geometries:/home/vscode \
/home/singularity/hifimagnet-salome-9.8.4.sif \
python3 -m python_magnetgeo.xao M9_M19020601-Axi_withAir.xao mesh --group CoolingChannels --geo M9_M19020601.yaml []mpirun -np 2 python -m python_magnetworkflows.workflows.cli HL-test-cfpdes-thelec-Axi-sim.cfg --eps 1.e-5python -m python_magnetworkflows.run cli \
--cfgfile M9Bitters/mean/M9Bitters-cfpdes-thmag_hcurl-nonlinear-Axi-sim.cfg
--mdata '{"M9Bitters":{"value":31000,"type":"bitter","filter":"","relax":0,"flow":"M9Bitters/M9Bitters-flow_params.json"}}'
--coolings "mean" "meanH" "grad" "gradH" "gradHZ" --hcorrelations "Montgomery" --frictions "Constant"python -m python_magnetworkflows.run commissioning \
--cfgfile M9Bitters/mean/M9Bitters-cfpdes-thmag_hcurl-nonlinear-Axi-sim.cfg \
--mdata '{"M9Bitters":{"value":31000,"step":31000,"stepmax":1,"type":"bitter","filter":"","relax":0,"flow":"M9Bitters/M9Bitters-flow_params.json"}}' \
--coolings "mean" "meanH" "grad" "gradH" "gradHZ" --hcorrelations "Montgomery" --frictions "Constant"You need a tree structure like :
M9Bitters
|_ mean/M9Bitters-cfpdes-thmag_hcurl-nonlinear-Axi-sim.cfg
|_ meanH/M9Bitters-cfpdes-thmag_hcurl-nonlinear-Axi-sim.cfg
|_ grad/M9Bitters-cfpdes-thmag_hcurl-nonlinear-Axi-sim.cfg
|_ gradH/M9Bitters-cfpdes-thmag_hcurl-nonlinear-Axi-sim.cfg
|_ gradHZ/M9Bitters-cfpdes-thmag_hcurl-nonlinear-Axi-sim.cfg
Create a setup for thelec axi sim for 'M9Bitters_HLtest' site
export MAGNETDB_API_KEY=
python -m python_magnetapi ...Edit 'tmp/M9Bitters_HLtest/M9Bitters_HLtest-cfpdes-thelec-Axi-sim.json' and modify a U_ parameter
Run the workflow:
python -m python_magnetworkflows.cli run \
'{HLtest":{"value":12000,"type":"helix","filter":"HLtest_","flow":"tmp/M9Bitters_HLtest/HLtest-flow_params.json"}, \
"M9Bitters":{"value":31000,"type":"bitter","filter":"M9Bitters_","flow":"tmp/M9Bitters_HLtest/M9Bitters-flow_params.json"}}' \
tmp/M9Bitters_HLtest/M9Bitters_HLtest-cfpdes-thelec-Axi-sim.cfg --cooling mean It must converge in 2 iterations