From 28f88e8ed2a209e6d8750157179710e7491a3516 Mon Sep 17 00:00:00 2001 From: Nicolas Aunai Date: Thu, 1 Aug 2024 11:53:44 +0200 Subject: [PATCH] add cmake config --- .gitignore | 3 +- CMakeLists.txt | 59 +++++++++++++++++++ diagnostics/alfvenwave2D/alfvenwave2D.py | 58 ++++++++++++------ pybind.cmake | 42 +++++++++++++ src/CMakeLists.txt | 51 ---------------- ...Transport.cpp => ConstrainedTransport.cpp} | 2 +- ...Transport.hpp => ConstrainedTransport.hpp} | 0 src/ModularityUtils.hpp | 4 +- src/TimeIntegrator.hpp | 4 +- 9 files changed, 148 insertions(+), 75 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 pybind.cmake delete mode 100644 src/CMakeLists.txt rename src/{ConstainedTransport.cpp => ConstrainedTransport.cpp} (99%) rename src/{ConstainedTransport.hpp => ConstrainedTransport.hpp} (100%) diff --git a/.gitignore b/.gitignore index cc3b600..60adaff 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,8 @@ whislerwaveres/ whislerwavelin/ whislerwaveHLL/ hallharrisres/ +subprojects debug/ frames/ -pyMHD/pyMHD.cpython* \ No newline at end of file +pyMHD/pyMHD.cpython* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fc75b4b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,59 @@ +cmake_minimum_required (VERSION 3.20.1) # released April 8, 2021 - https://www.kitware.com/cmake-3-20-1-available-for-download/ + +project(PHAREMHD VERSION 0.1 LANGUAGES CXX C) + +# Release mode default +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) +endif() + + +SET(PYBIND_MIN_VERSION "2.5.0") +find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED) +find_program(Git git) +include(pybind.cmake) + +set(PHAREMHD_PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) + +set(SOURCES + src/ConservativeVariables.cpp + src/ConstrainedTransport.cpp + src/EquationOfState.cpp + src/GodunovFlux.cpp + src/Interface.cpp + src/ModularityUtils.cpp + src/PhareMHD.cpp + src/PhysicalConstants.cpp + src/PrimitiveVariables.cpp + src/RiemannSolver.cpp + src/TimeIntegrator.cpp) + +set(INCLUDES + src/ConservativeVariables.hpp + src/ConstrainedTransport.hpp + src/EquationOfState.hpp + src/GodunovFlux.hpp + src/Interface.hpp + src/ModularityUtils.hpp + src/PhareMHD.hpp + src/PhysicalConstants.hpp + src/PrimitiveVariables.hpp + src/RiemannSolver.hpp + src/TimeIntegrator.hpp) + +add_library(phareMHD SHARED ${SOURCES} ${INCLUDES}) + + +pybind11_add_module(pyMHD pyMHD/pyMHD.cpp) +target_link_libraries(pyMHD PUBLIC phareMHD) + + + + diff --git a/diagnostics/alfvenwave2D/alfvenwave2D.py b/diagnostics/alfvenwave2D/alfvenwave2D.py index 546a3a6..a238e4d 100644 --- a/diagnostics/alfvenwave2D/alfvenwave2D.py +++ b/diagnostics/alfvenwave2D/alfvenwave2D.py @@ -1,5 +1,6 @@ import sys -sys.path.append('/home/caromel/Documents/PHAREMHD/pyMHD') + +# sys.path.append('/home/caromel/Documents/PHAREMHD/pyMHD') import numpy as np import pyMHD as p @@ -27,47 +28,56 @@ dumpvariables = p.dumpVariables.Conservative ############################################################################################################################################################################## -lx=nx*Dx -ly=ny*Dy +lx = nx * Dx +ly = ny * Dy alpha = np.arctan(0.5) cosalpha = np.cos(alpha) sinalpha = np.sin(alpha) -kx = 2*np.pi/(cosalpha*lx) -ky = 2*np.pi/(sinalpha*ly) +kx = 2 * np.pi / (cosalpha * lx) +ky = 2 * np.pi / (sinalpha * ly) + def rho_(x, y): return 1.0 + def vx_(x, y): - return (-1e-4 * np.sin(kx * x * cosalpha + ky * y * sinalpha)) / (2. * sinalpha) + return (-1e-4 * np.sin(kx * x * cosalpha + ky * y * sinalpha)) / (2.0 * sinalpha) + def vy_(x, y): - return (1e-4 * np.sin(kx * x * cosalpha + ky * y * sinalpha)) / (2. * cosalpha) + return (1e-4 * np.sin(kx * x * cosalpha + ky * y * sinalpha)) / (2.0 * cosalpha) + def vz_(x, y): return 0.0 + def Bx_(x, y): - return (1 - 1e-4 * np.sin(kx * x * cosalpha + ky * y * sinalpha)) / (2. * sinalpha) + return (1 - 1e-4 * np.sin(kx * x * cosalpha + ky * y * sinalpha)) / (2.0 * sinalpha) + def By_(x, y): - return (1 + 1e-4 * np.sin(kx * x * cosalpha + ky * y * sinalpha)) / (2. * cosalpha) + return (1 + 1e-4 * np.sin(kx * x * cosalpha + ky * y * sinalpha)) / (2.0 * cosalpha) + def Bz_(x, y): return 0.0 + def P_(x, y): return 0.1 + x = np.arange(nx) * Dx + 0.5 * Dx y = np.arange(ny) * Dy + 0.5 * Dy -xf = np.arange(nx+1) * Dx -yf = np.arange(ny+1) * Dy +xf = np.arange(nx + 1) * Dx +yf = np.arange(ny + 1) * Dy -xx, yy = np.meshgrid(x, y, indexing = 'ij') -xfx, yfx = np.meshgrid(xf, y, indexing = 'ij') -xfy, yfy = np.meshgrid(x, yf, indexing = 'ij') +xx, yy = np.meshgrid(x, y, indexing="ij") +xfx, yfx = np.meshgrid(xf, y, indexing="ij") +xfy, yfy = np.meshgrid(x, yf, indexing="ij") rho = np.full((nx, ny), rho_(xx, yy)).T vx = np.full((nx, ny), vx_(xx, yy)).T @@ -80,7 +90,7 @@ def P_(x, y): ############################################################################################################################################################################# -result_dir = '2Dwave/' +result_dir = "2Dwave/" if os.path.exists(result_dir): shutil.rmtree(result_dir) @@ -89,6 +99,18 @@ def P_(x, y): P0cc = p.PrimitiveVariables(nx, ny) P0cc.init(rho, vx, vy, vz, Bxf, Byf, Bz, P) -p.PhareMHD(P0cc, result_dir, nghost, - boundaryconditions, reconstruction, slopelimiter, riemannsolver, constainedtransport, timeintegrator, - Dx, Dy, FinalTime, dumpvariables = dumpvariables) \ No newline at end of file +p.PhareMHD( + P0cc, + result_dir, + nghost, + boundaryconditions, + reconstruction, + slopelimiter, + riemannsolver, + constainedtransport, + timeintegrator, + Dx, + Dy, + FinalTime, + dumpvariables=dumpvariables, +) diff --git a/pybind.cmake b/pybind.cmake new file mode 100644 index 0000000..48178e9 --- /dev/null +++ b/pybind.cmake @@ -0,0 +1,42 @@ + +SET(PYBIND_MIN_VERSION "2.5.0") + +function(get_pybind) + + # Pybind errors with clang, it is default in GCC + # https://github.com/pybind/pybind11/issues/1604 + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set (PHARE_FLAGS ${PHARE_FLAGS} -fsized-deallocation) + endif() + + message("downloading subproject pybind11") + set(PYBIND11_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/pybind11) + + if (NOT EXISTS ${PYBIND11_SRCDIR}) + message("cloning your mother ${PYBIND11_SRCDIR}") + execute_process( + COMMAND ${Git} clone https://github.com/pybind/pybind11 ${PYBIND11_SRCDIR} --depth 1 -b master + ) + else() + if(devMode) + message("downloading latest pybind11 updates") + execute_process(COMMAND ${Git} pull origin master WORKING_DIRECTORY ${PYBIND11_SRCDIR}) + endif(devMode) + endif() + + message("now adding subdir") + add_subdirectory(${PYBIND11_SRCDIR}) + +endfunction(get_pybind) + +if (forceGetPybind) + get_pybind() +else() + + find_package(pybind11 ${PYBIND_MIN_VERSION} CONFIG QUIET) + + if (NOT pybind11_FOUND) + get_pybind() + endif() + +endif(forceGetPybind) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index f064fbd..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -cmake_minimum_required(VERSION 3.10) -project(MHDProblem) - -set(SOURCES - ConservativeVariables.cpp - PrimitiveVariables.cpp - ConstainedTransport.hpp - GodunovFlux.hpp - ../diagnostics/alfvenwave/Initialisation.hpp - Interface.hpp - ReconstructedValues.hpp - RusanovRiemannSolver.hpp - TimeIntegrator.hpp - EquationOfState.cpp - AddGhostCells.hpp -) - -foreach(SOURCE_FILE ${SOURCES}) - get_filename_component(FILE_EXT ${SOURCE_FILE} EXT) - if(${FILE_EXT} STREQUAL ".cpp") - list(APPEND CPP_SOURCES ${SOURCE_FILE}) - endif() -endforeach() - -# Create object libraries for each source file -foreach(SOURCE_FILE ${SOURCES}) - get_filename_component(FILE_NAME ${SOURCE_FILE} NAME_WE) - add_library(${FILE_NAME} OBJECT ${SOURCE_FILE}) - - # Check if the file is a .cpp file and include directories if needed - list(FIND CPP_SOURCES ${SOURCE_FILE} IS_CPP) - if(IS_CPP GREATER -1) - target_include_directories(${FILE_NAME} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ) - endif() - - # Collect all object libraries - list(APPEND OBJECT_LIBRARIES ${FILE_NAME}) -endforeach() - -# Add the executable -add_executable(MHDProblem ../diagnostics/alfvenwave/MHDProblem.cpp) - -# Link all object libraries to the executable -target_link_libraries(MHDProblem ${OBJECT_LIBRARIES}) - -# Include directories if required -target_include_directories(MHDProblem PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} -) diff --git a/src/ConstainedTransport.cpp b/src/ConstrainedTransport.cpp similarity index 99% rename from src/ConstainedTransport.cpp rename to src/ConstrainedTransport.cpp index f86ea2e..d8ff868 100644 --- a/src/ConstainedTransport.cpp +++ b/src/ConstrainedTransport.cpp @@ -1,4 +1,4 @@ -#include "ConstainedTransport.hpp" +#include "ConstrainedTransport.hpp" static const PhysicalConstants& pc = PhysicalConstants::getInstance(); diff --git a/src/ConstainedTransport.hpp b/src/ConstrainedTransport.hpp similarity index 100% rename from src/ConstainedTransport.hpp rename to src/ConstrainedTransport.hpp diff --git a/src/ModularityUtils.hpp b/src/ModularityUtils.hpp index 0eb3d9d..f7b35e3 100644 --- a/src/ModularityUtils.hpp +++ b/src/ModularityUtils.hpp @@ -4,7 +4,7 @@ #include "Enums.hpp" #include "SlopeLimiter.hpp" #include "RiemannSolver.hpp" -#include "ConstainedTransport.hpp" +#include "ConstrainedTransport.hpp" #include "TimeIntegrator.hpp" class Interface; @@ -28,4 +28,4 @@ CTFunction getCT(CTMethod ct); typedef ConservativeVariables (*IntegratorFunction)(ConservativeVariables&, double, double, double, int, BoundaryConditions, Reconstruction, Slope, Riemann, CTMethod, OptionalPhysics); IntegratorFunction getIntegrator(Integrator intg); -#endif \ No newline at end of file +#endif diff --git a/src/TimeIntegrator.hpp b/src/TimeIntegrator.hpp index 352b4d7..b5d9897 100644 --- a/src/TimeIntegrator.hpp +++ b/src/TimeIntegrator.hpp @@ -9,7 +9,7 @@ #include "ModularityUtils.hpp" #include "ConservativeVariables.hpp" #include "GodunovFlux.hpp" -#include "ConstainedTransport.hpp" +#include "ConstrainedTransport.hpp" #include "AddGhostCells.hpp" #include "ComputeJ.hpp" @@ -21,4 +21,4 @@ ConservativeVariables TVDRK2(ConservativeVariables& Un, double Dx, double Dy, do ConservativeVariables TVDRK3(ConservativeVariables& Un, double Dx, double Dy, double Dt, int nghost, BoundaryConditions bc, Reconstruction rec, Slope sl, Riemann rs, CTMethod ct, OptionalPhysics OptP); -#endif // TIME_INTEGRATOR_HPP_ \ No newline at end of file +#endif // TIME_INTEGRATOR_HPP_