Name: openfoam Version: 13 Release: 1%{?dist} Summary: Open source CFD (Computational Fluid Dynamics) toolbox License: GPL-3.0-or-later URL: https://openfoam.org/ Source0: https://github.com/OpenFOAM/OpenFOAM-%{version}/archive/refs/tags/version-%{version}.tar.gz#/OpenFOAM-%{version}.tar.gz Source1: https://github.com/OpenFOAM/ThirdParty-%{version}/archive/refs/tags/version-%{version}.tar.gz#/ThirdParty-%{version}.tar.gz BuildRequires: gcc-c++ BuildRequires: cmake BuildRequires: flex BuildRequires: zlib-devel BuildRequires: openmpi-devel BuildRequires: boost-devel BuildRequires: CGAL-devel BuildRequires: fftw-devel BuildRequires: scotch-devel BuildRequires: metis-devel BuildRequires: readline-devel BuildRequires: ncurses-devel BuildRequires: gmp-devel BuildRequires: mpfr-devel BuildRequires: python3-devel BuildRequires: perl Requires: openmpi Requires: environment-modules # Filter private libraries %global __provides_exclude_from ^%{_libdir}/openfoam/.*\\.so.*$ %global __requires_exclude ^(libOpenFOAM|libfiniteVolume|libmeshTools|libtriSurface|libfileFormats|libgenericPatchFields|liblagrangian|libconversion|libsampling|libsurfMesh).*\\.so.*$ %description OpenFOAM is a free, open source CFD software package developed by OpenFOAM Foundation. It has a large user base across most areas of engineering and science, from both commercial and academic organisations. OpenFOAM has an extensive range of features to solve anything from complex fluid flows involving chemical reactions, turbulence and heat transfer, to solid dynamics and electromagnetics. %prep # Extract in parent directory without auto-cd cd %{_builddir} rm -rf OpenFOAM-%{version} ThirdParty-%{version} tar -xzf %{SOURCE0} tar -xzf %{SOURCE1} # Rename to expected names mv OpenFOAM-%{version}-version-%{version} OpenFOAM-%{version} mv ThirdParty-%{version}-version-%{version} ThirdParty-%{version} cd OpenFOAM-%{version} %build # Change to the renamed directory cd %{_builddir}/OpenFOAM-%{version} # Source OpenFOAM environment export FOAM_INST_DIR=$(cd .. && pwd) export WM_PROJECT_DIR=$(pwd) # Don't modify etc/bashrc yet - we need to source it first for the build # We'll configure the installed version in %install # Set compiler flags export FOAM_EXTRA_CFLAGS="%{optflags}" export FOAM_EXTRA_CXXFLAGS="%{optflags}" # Set number of build processes export WM_NCOMPPROCS="%{?_smp_mflags}" # Load MPI module %_openmpi_load # Ensure MPI paths are available for ThirdParty builds export MPI_ROOT=/usr/lib64/openmpi export MPI_ARCH_PATH=$MPI_ROOT # Set CPPFLAGS and LDFLAGS so ThirdParty configure scripts can find MPI export CPPFLAGS="-I/usr/include/openmpi-x86_64 $CPPFLAGS" # OpenMPI libraries are in /usr/lib64/openmpi/lib (not lib64) export LDFLAGS="-L/usr/lib64/openmpi/lib $LDFLAGS" export LD_LIBRARY_PATH="/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH" # Explicitly tell configure where MPI libs are to prevent it from guessing lib64 export MPI_LIBS="-L/usr/lib64/openmpi/lib -lmpi" export MPI_LIBDIR="/usr/lib64/openmpi/lib" # Disable scotch and ptscotch - scotch 6.0.9 has compilation errors with GCC 14 # We'll use zoltan (parallel) + metis (system) for decomposition instead export SCOTCH_TYPE=none export PTSCOTCH_TYPE=none # Source the environment (ignore return code from bashrc's function context issues) source etc/bashrc || true # After sourcing, use ThirdParty zoltan and system METIS for decomposition export METIS_TYPE=system export PARMETIS_TYPE=none # OLD APPROACH - disabled decomposition libraries entirely: # export SCOTCH_TYPE=none # export PTSCOTCH_TYPE=none # export ZOLTAN_TYPE=none # export METIS_TYPE=system # export PARMETIS_TYPE=none # Build OpenFOAM (use verbose mode to see what's happening) ./Allwmake -j 2>&1 | tee build.log # Check if build succeeded if [ "${PIPESTATUS[0]}" -ne 0 ]; then echo "Build failed!" exit 1 fi %_openmpi_unload %install # Change to the build directory cd %{_builddir}/OpenFOAM-%{version} # Create installation directory install -dm 0755 %{buildroot}%{_libdir}/openfoam-%{version} # Copy the built files cp -a platforms %{buildroot}%{_libdir}/openfoam-%{version}/ cp -a etc %{buildroot}%{_libdir}/openfoam-%{version}/ cp -a bin %{buildroot}%{_libdir}/openfoam-%{version}/ cp -a applications %{buildroot}%{_libdir}/openfoam-%{version}/ cp -a tutorials %{buildroot}%{_libdir}/openfoam-%{version}/ # Now configure the installed bashrc for system installation sed -i "s|WM_PROJECT_INST_DIR=\$FOAM_INST_DIR|WM_PROJECT_INST_DIR=%{_libdir}|" %{buildroot}%{_libdir}/openfoam-%{version}/etc/bashrc sed -i "s|export WM_PROJECT_USER_DIR=.*|export WM_PROJECT_USER_DIR=\$HOME/OpenFOAM/\$USER-\$WM_PROJECT_VERSION|" %{buildroot}%{_libdir}/openfoam-%{version}/etc/bashrc # Create environment module file install -dm 0755 %{buildroot}%{_datadir}/modulefiles/openfoam cat > %{buildroot}%{_datadir}/modulefiles/openfoam/%{version} <<'EOF' #%%Module1.0 proc ModulesHelp { } { puts stderr "OpenFOAM %{version} - CFD Toolbox" } module-whatis "OpenFOAM %{version} - Open source CFD toolbox" module load mpi/openmpi-%{_arch} setenv FOAM_INST_DIR %{_libdir} setenv WM_PROJECT_DIR %{_libdir}/openfoam-%{version} setenv WM_PROJECT OpenFOAM setenv WM_PROJECT_VERSION %{version} prepend-path PATH %{_libdir}/openfoam-%{version}/platforms/linux64GccDPInt32Opt/bin prepend-path LD_LIBRARY_PATH %{_libdir}/openfoam-%{version}/platforms/linux64GccDPInt32Opt/lib EOF # Create wrapper script install -dm 0755 %{buildroot}%{_sysconfdir}/profile.d cat > %{buildroot}%{_sysconfdir}/profile.d/openfoam-%{version}.sh <<'EOF' #!/bin/bash # OpenFOAM %{version} environment setup export FOAM_INST_DIR=%{_libdir} export WM_PROJECT_DIR=%{_libdir}/openfoam-%{version} if [ -f $WM_PROJECT_DIR/etc/bashrc ]; then source $WM_PROJECT_DIR/etc/bashrc fi EOF %files %doc README.md %license COPYING %config(noreplace) %{_sysconfdir}/profile.d/openfoam-%{version}.sh %{_libdir}/openfoam-%{version}/ %{_datadir}/modulefiles/openfoam/%{version} %changelog * Mon Oct 27 2025 Your Name - 13-1 - Initial OpenFOAM 13 package for COPR