ForCAD: A parallel Fortran library for geometric modeling using NURBS (Non-Uniform Rational B-Splines).
ForCAD supports B-Spline, NURBS, Bezier and Rational Bezier curves, surfaces and volumes.
do concurrent
.Below are some sample outputs from the examples
directory:
Fortran compiler:
ifx
)nvfortran
)flang
)Note: Latest compiler versions are required to ensure compatibility.
Clone the ForCAD repository from GitHub:
git clone https://github.com/gha3mi/forcad.git
cd forcad
To install PyVista, run the following command:
pip install pyvista
By default PyVista visualization is enabled. To disable it, define the preprocessor flag NOSHOW_PYVISTA
in the fpm.toml
file or pass it as a compiler flag.
fpm run --example <file name excluding the .f90 extension> --compiler gfortran --profile release --flag "-ftree-parallelize-loops=8 -march=native"
After executing the examples, .vtk
files will be generated in the vtk
directory. To visualize these files, a show()
method is provided which utilizes PyVista. Alternatively, other visualization tools like ParaView can also be used.
If you want to use ForCAD as a dependency in your own fpm project,
you can easily include it by adding the following line to your fpm.toml
file:
[dependencies]
forcad = {git="https://github.com/gha3mi/forcad.git"}
cmake -S . -B build/cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=. -G Ninja
cmake --build build/cmake --config Release
cmake --install build/cmake --config Release --verbose
cmake --build build/cmake --target uninstall
find_package(forcad REQUIRED)
add_executable(app main.f90)
target_link_libraries(app PRIVATE forcad::forcad)
Compiler flags for enabling do concurrent
parallelism:
Compiler | Flag(s) |
---|---|
gfortran |
-fopenmp -ftree-parallelize-loops=n |
ifx |
-qopenmp -fopenmp-target-do-concurrent |
nvfortran |
-stdpar=multicore,gpu -Minfo=stdpar,accel |
flang-new |
? |
lfortran |
? |
Compiler flags can be passed to fpm using the --flag
option, for example:
fpm build --flag "-stdpar=multicore,gpu -Minfo=stdpar,accel"
Alternatively, flags can be added to a fpm.rsp
file in the root directory of the project.
The library uses double precision (real64
) by default for all real-valued computations. To change the precision, you can define one of the following preprocessor flags during compilation:
Preprocessor Flag | Fortran Kind | Description |
---|---|---|
REAL32 |
selected_real_kind(6) |
Single precision |
REAL64 (default) |
selected_real_kind(15) |
Double precision |
REALXDP |
selected_real_kind(18) |
Extended double precision |
REAL128 |
selected_real_kind(33) |
Quadruple precision |
Note: The examples example_ppm1.f90
, example_ppm2.f90
and example_ppm3.f90
use the ForColormap
library, which only supports REAL64
precision.
Example: Building with double precision
fpm build --profile release --flag "-DREAL64"
Compiler | macos | ubuntu | windows |
---|---|---|---|
flang-new |
- | fpm ✅ cmake ✅ | fpm ✅ cmake ❌ |
gfortran |
fpm ✅ cmake ✅ | fpm ✅ cmake ✅ | fpm ✅ cmake ✅ |
ifx |
- | fpm ✅ cmake ✅ | fpm ✅ cmake ❌ |
lfortran |
fpm ❌ cmake ❌ | fpm ❌ cmake ❌ | fpm ❌ cmake ❌ |
nvfortran |
- | fpm ✅ cmake ✅ | - |
This table is automatically generated by the CI workflow using setup-fortran-conda.
The most up-to-date API documentation for the master branch is available here. To generate the API documentation for ForCAD using ford run the following command:
ford README.md
To contribute to ForCAD, please review the CONTRIBUTING.md.
If you use ForCAD in your research, please cite it as follows:
@software{seyed_ali_ghasemi_2025_10904447,
author = {Ghasemi, S. A.},
title = {gha3mi/ForCAD},
year = {2025},
publisher = {Zenodo},
doi = {10.5281/zenodo.10904447},
url = {https://doi.org/10.5281/zenodo.10904447}
}
Piegl, L., & Tiller, W. (1995). The NURBS Book. In Monographs in Visual Communications. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-97385-7
An Introduction to NURBS. (2001). Elsevier. https://doi.org/10.1016/b978-1-55860-669-2.x5000-3
Sullivan et al., (2019). PyVista: 3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK). Journal of Open Source Software, 4(37), 1450, https://doi.org/10.21105/joss.01450
Ahrens, James, Geveci, Berk, Law, Charles, ParaView: An End-User Tool for Large Data Visualization, Visualization Handbook, Elsevier, 2005, ISBN-13: 9780123875822