Interpolator of different kind of loads and BC to APDL format
Project description
InterpCore
A Python library for interpolating physical field data (electromagnetic forces, heat flux, etc.) between different mesh representations and exporting to ANSYS APDL format.
Features
- Multiple interpolation kernels: Distance-weighted, FEM-based, K-nearest neighbors, closest point
- Flexible query methods: K-nearest neighbors or radius-based search
- Support for multiple load types:
- EM forces (3-component vector fields)
- Heat flux (scalar fields)
- Heat generation (volumetric)
- Heat Transfer Coefficient + bulk fluid temperature (convection BCs)
- Analysis tools:
- Scalar field integration for computing total heat generation, flux, etc.
- EM force resultant computation for validating force/moment conservation
- Export to ANSYS APDL: Direct export of interpolated results in APDL format
- Visualization: Built-in VTK export for ParaView or PyVista visualization
- Efficient: KDTree-based spatial queries for fast neighbor searches
Installation
pip install interpcore
Quick Start
from interpcore.interpolator import Interpolator
from interpcore.config import InterpolationConfig, QUERY_TYPE, INTERPOLATED_LOAD_TYPE
from interpcore.kernels import INTERPOLATION_KERNEL
# Configure interpolation
config = InterpolationConfig(
method=QUERY_TYPE.K, # type of neighbour search
param=5, # parameter relative to the neighbour search (K or radius)
max_distance=2.0, # filter by a max radius of search (in case of K is used)
coincidence_tolerance=0.01, # tolerance to consider two nodes coincident
kernel=INTERPOLATION_KERNEL.DISTANCE_WEIGHTED, # How to interpolate
multithread=False, # use or not multithread
interpolated_load=INTERPOLATED_LOAD_TYPE.EM_FORCE # type of load that is being interpolated
)
# Define file column indices. This gives the column index in the input files
file_idx = {"ids": 0, "dest_x": 1, "src_x": 1, "val": 4}
# Create interpolator and run
interpolator = Interpolator(
path_to_src_folder="source_data",
path_to_dest_mesh="destination_mesh.txt",
config=config,
file_idx=file_idx
)
# Interpolate all source files
interpolator.interpolate_all()
# Export to ANSYS format
interpolator.export_to_ansys("output_directory")
# Optional: Build VTK for visualization. If outdir=None they are not exported
interpolator.build_vtk_output(outdir="vtk_output")
Analysis Methods
After interpolation, InterpCore provides methods to analyze and validate results:
Scalar Integrals
For scalar fields (heat flux, heat generation), you can compute the total integral over the destination mesh:
# Requires volume or area data in the destination mesh
file_idx = {"ids": 0, "dest_x": 1, "src_x": 1, "val": 4, "vol": 4} # or "area": 5
interpolator = Interpolator(
path_to_src_folder="source_data",
path_to_dest_mesh="destination_mesh.txt",
config=config,
file_idx=file_idx
)
interpolator.interpolate_all()
# Compute integrals (e.g., total heat generation in W)
integrals = interpolator.compute_scalar_integrals()
# Returns: {"data_001": array([total_value])}
Note: The destination mesh must include volume (for 3D elements) or area (for 2D elements) data. Use the APDL scripts in apdl-scripts/ to export element centroids with volumes and areas.
EM Force Resultants
For EM force fields, you can compute force and moment resultants to verify conservation:
# After interpolation with EM_FORCE load type
resultants = interpolator.compute_EM_resultants(pole=np.array([0.0, 0.0, 0.0]))
# Returns for each source file:
# {
# "force_001": {
# "R_F_EM": [Fx, Fy, Fz], # Total force from source data
# "R_F_Mech": [Fx, Fy, Fz], # Total force from interpolated data
# "R_M_EM": [Mx, My, Mz], # Total moment from source data
# "R_M_Mech": [Mx, My, Mz], # Total moment from interpolated data
# "f_err_comp": [ex, ey, ez], # Relative force error by component
# "m_err_comp": [ex, ey, ez], # Relative moment error by component
# "Unmapped_EM_Force": float # Norm of unmapped forces
# }
# }
This is useful for validating that the interpolation preserves global force and moment equilibrium. Small errors indicate good interpolation quality.
Examples
Complete working examples with sample data are available in the doc/ folder:
- Heat Flux Example: Scalar field interpolation using the AVERAGE kernel
- Heat Generation Example: Volumetric heat generation using the CLOSEST kernel
- EM Force Example: Vector field interpolation with glyph visualization
- HTC Example: Convection boundary condition interpolation (HTC + bulk fluid temperature)
Each example includes:
- Sample mesh files
- Sample data files
- Jupyter notebook with full workflow
- Visualization with PyVista
Configuration Options
Query Methods
QUERY_TYPE.K: K-nearest neighbors (param = number of neighbors)QUERY_TYPE.RADIUS: Radius-based search (param = radius in same unit as coordinates)
Interpolation Kernels
Source-to-target
Each source point is distributed to destination neighbours:
DISTANCE_WEIGHTED: Weight by inverse distanceFEM: FEM-based interpolation
Target-to-source
A value is assigned to each destination point based on source neighbours
CLOSEST: Use closest source point valueAVERAGE: Simple average of neighborsAVERAGE_WEIGHTED: Average the neighbours values but weighting them by distance (the closer the more important).
Load Types
EM_FORCE: 3-component vector fields (Fx, Fy, Fz). If "vol" column is provided the forces are interpreted as force densities and will be multiplied by the volume.HEAT_FLUX: Scalar fields for surface heat fluxHEAT_GEN: Scalar fields for volumetric heat generationHTC: 2-component convection boundary condition — Heat Transfer Coefficient and bulk fluid (reference) temperature. Exported asSFE,,CONV,1andSFE,,CONV,2in APDL.
File Format
The file format is pretty free, header, no header, commas, tabs.... The important part is that the correct index columns are specified when creating the interpolator.
Destination mesh input files can be created using the apdl scripts included in this repository here.
Requirements
- Python ≥ 3.10
- scikit-learn
- pandas
- tqdm
- pyvista
License
Licensed under the European Union Public Licence (EUPL) 1.2
Authors
Developed by the F4E mechanical team
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file interpcore-1.1.0.tar.gz.
File metadata
- Download URL: interpcore-1.1.0.tar.gz
- Upload date:
- Size: 316.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a47d18ae9aa952822aa3701e2e1770927383834d994f43097d55f956b00c2378
|
|
| MD5 |
6f499f71a9e13a519cda7e15d1759d64
|
|
| BLAKE2b-256 |
ad4555e616acca9f176d6593c055efed0bb1198761811e03618923d137277802
|
Provenance
The following attestation bundles were made for interpcore-1.1.0.tar.gz:
Publisher:
build_publish.yml on Fusion4Energy/InterpCore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
interpcore-1.1.0.tar.gz -
Subject digest:
a47d18ae9aa952822aa3701e2e1770927383834d994f43097d55f956b00c2378 - Sigstore transparency entry: 1780558236
- Sigstore integration time:
-
Permalink:
Fusion4Energy/InterpCore@3893075bb2e80ff0b5042f3a8a2f85d8138c04a4 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/Fusion4Energy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_publish.yml@3893075bb2e80ff0b5042f3a8a2f85d8138c04a4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file interpcore-1.1.0-py3-none-any.whl.
File metadata
- Download URL: interpcore-1.1.0-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bf75cbdc55ed5a4362fae27fcaf027e2177db06016241b57a749097d2737abf
|
|
| MD5 |
f3cca0bdd46080cc47896ad925410651
|
|
| BLAKE2b-256 |
fa09cfe4ccf8ab5b311d033970f2d64100f81fc79ea31406255a70d7bb9667a6
|
Provenance
The following attestation bundles were made for interpcore-1.1.0-py3-none-any.whl:
Publisher:
build_publish.yml on Fusion4Energy/InterpCore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
interpcore-1.1.0-py3-none-any.whl -
Subject digest:
7bf75cbdc55ed5a4362fae27fcaf027e2177db06016241b57a749097d2737abf - Sigstore transparency entry: 1780558631
- Sigstore integration time:
-
Permalink:
Fusion4Energy/InterpCore@3893075bb2e80ff0b5042f3a8a2f85d8138c04a4 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/Fusion4Energy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_publish.yml@3893075bb2e80ff0b5042f3a8a2f85d8138c04a4 -
Trigger Event:
release
-
Statement type: