Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cmake config #5

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ whislerwaveres/
whislerwavelin/
whislerwaveHLL/
hallharrisres/
subprojects

debug/
frames/
pyMHD/pyMHD.cpython*
pyMHD/pyMHD.cpython*
59 changes: 59 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)




58 changes: 40 additions & 18 deletions diagnostics/alfvenwave2D/alfvenwave2D.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -80,7 +90,7 @@ def P_(x, y):

#############################################################################################################################################################################

result_dir = '2Dwave/'
result_dir = "2Dwave/"
if os.path.exists(result_dir):
shutil.rmtree(result_dir)

Expand All @@ -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)
p.PhareMHD(
P0cc,
result_dir,
nghost,
boundaryconditions,
reconstruction,
slopelimiter,
riemannsolver,
constainedtransport,
timeintegrator,
Dx,
Dy,
FinalTime,
dumpvariables=dumpvariables,
)
42 changes: 42 additions & 0 deletions pybind.cmake
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 0 additions & 51 deletions src/CMakeLists.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ConstainedTransport.hpp"
#include "ConstrainedTransport.hpp"

static const PhysicalConstants& pc = PhysicalConstants::getInstance();

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/ModularityUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Enums.hpp"
#include "SlopeLimiter.hpp"
#include "RiemannSolver.hpp"
#include "ConstainedTransport.hpp"
#include "ConstrainedTransport.hpp"
#include "TimeIntegrator.hpp"

class Interface;
Expand All @@ -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
#endif
4 changes: 2 additions & 2 deletions src/TimeIntegrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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_
#endif // TIME_INTEGRATOR_HPP_
Loading