Commit f24c1458 authored by Abhinav Singh's avatar Abhinav Singh
Browse files

Merge branch 'develop' into FD_solver

# Conflicts:
#	.gitignore
#	CMakeLists.txt
#	openfpm_data
#	openfpm_io
#	openfpm_numerics
#	openfpm_vcluster
parents 613d8e51 4802e0d1
......@@ -127,4 +127,4 @@ projectId.sh
**/.gitignore
.gitignore
/doxygen/
/doxygen/
\ No newline at end of file
# docker_centos_build:
# stage: build
# tags:
# - docker
# image: 'ubuntu:20.04'
# artifacts:
# paths:
# - ./build/src/pdata
# - ./build/openfpm_numerics/src/numerics
# - ./openfpm_numerics/test
# script:
# - apt-get update
# - DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata
# - apt-get -y install cmake wget git g++ gfortran python2 python-is-python3
# - mkdir -p /root/openfpm_dependencies/openfpm_pdata/base
# - mkdir /root/.ssh && chmod 700 /root/.ssh
# - cp id_rsa.pub /root/.ssh/id_rsa.pub && chmod 644 /root/.ssh/id_rsa.pub
# - cp id_rsa /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa
# - ssh-keyscan -H git.mpi-cbg.de >> ~/.ssh/known_hosts
# - ./build.sh $CI_PROJECT_DIR unused pdata 0 base
# cache:
# key: $CI_COMMIT_REF_SLUG
# paths:
# - /root/openfpm_dependencies/openfpm_pdata/base
centos_build:
stage: build
tags:
......@@ -18,11 +44,13 @@ centos_run:
dependencies:
- centos_build
script:
- export OMP_NUM_THREADS=1
- ./run.sh $CI_PROJECT_DIR unused 1 pdata 0 $CI_COMMIT_REF_NAME
- ./run.sh $CI_PROJECT_DIR unused 2 pdata 0 $CI_COMMIT_REF_NAME
- ./run.sh $CI_PROJECT_DIR unused 3 pdata 0 $CI_COMMIT_REF_NAME
- ./run.sh $CI_PROJECT_DIR unused 4 pdata 0 $CI_COMMIT_REF_NAME
- ./run.sh $CI_PROJECT_DIR unused 5 pdata 0 $CI_COMMIT_REF_NAME
- export OMP_NUM_THREADS=8
- ./run.sh $CI_PROJECT_DIR unused 1 pdata 0 $CI_COMMIT_REF_NAME
- export OMP_NUM_THREADS=1
- cd openfpm_numerics
- ./run.sh $CI_PROJECT_DIR unused 1 0 0 numerics $CI_COMMIT_REF_NAME
- ./run.sh $CI_PROJECT_DIR unused 2 0 0 numerics $CI_COMMIT_REF_NAME
......@@ -74,9 +102,13 @@ ubuntu_run:
dependencies:
- ubuntu_build
script:
- export OMP_NUM_THREADS=1
- ./run.sh $CI_PROJECT_DIR unused 1 pdata 0 $CI_COMMIT_REF_NAME
- ./run.sh $CI_PROJECT_DIR unused 2 pdata 0 $CI_COMMIT_REF_NAME
- ./run.sh $CI_PROJECT_DIR unused 3 pdata 0 $CI_COMMIT_REF_NAME
- export OMP_NUM_THREADS=8
- ./run.sh $CI_PROJECT_DIR unused 1 pdata 0 $CI_COMMIT_REF_NAME
- export OMP_NUM_THREADS=1
- cd openfpm_numerics
- ./run.sh $CI_PROJECT_DIR unused 1 0 0 numerics $CI_COMMIT_REF_NAME
- ./run.sh $CI_PROJECT_DIR unused 2 0 0 numerics $CI_COMMIT_REF_NAME
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# Change Log
All notable changes to this project will be documented in this file.
## [4.1.0] (Codename Thesis)
- On a general base the code should not use CUDA_ON_CPU but if it does CUDA_ON_CPU macro now cover both SEQUENTIAL and OpenMP backend. The macros CUDIFY_USE_CUDA,CUDIFY_USE_HIP,CUDIFY_USE_OPENMP,CUDIFY_USE_SEQUENTIAL,CUDIFY_USE_NONE can be checked to control which CUDA backend is used
### Fixed
- Minors bug
## [4.0.0] September 2021 (Codename Heisenberg)
- Adding DCPSE, Level-set based numerics (Closest-point)
......
......@@ -11,7 +11,7 @@ if (POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
set(openfpm_VERSION 4.0.0)
set(openfpm_VERSION 4.1.0)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake_modules/)
......@@ -39,24 +39,12 @@ set(METIS_DIR ${METIS_ROOT})
set(PARMETIS_DIR ${PARMETIS_ROOT})
set(OPENBLAS_ROOT CACHE PATH "Root path for blas library")
set(SuiteSparse_ROOT ${SUITESPARSE_ROOT})
set(CUDA_ON_CPU CACHE BOOL "Make Cuda work on heap")
set(CPACK_RUN_INSTALL_DEPENDENCIES CACHE BOOL "Set to true if we are creating deb or RPM packages")
set(ENABLE_GARBAGE_INJECTOR CACHE BOOL "Enable the injector of garbage in the memory allocator")
set(ENABLE_VCLUSTER_GARBAGE_INJECTOR CACHE BOOL "Enable the injector of garbage in the vcluster memory buffers")
set(HIP_ENABLE CACHE BOOL "Enable HIP compiler")
set(AMD_ARCH_COMPILE "gfx900" CACHE STRING "AMD gpu architecture used to compile kernels")
# Enabling real GPU is stronger than using CUDA_ON_CPU
if (ENABLE_GPU)
set(CUDA_ON_CPU OFF)
# Test CLang
if (NOT HIP_ENABLE)
find_package(CUDA)
set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT ${CUDA_TOOLKIT_ROOT_DIR})
enable_language(CUDA)
endif()
endif()
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CUDA_STANDARD 14)
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
......@@ -74,7 +62,9 @@ set(HDF5_PREFER_PARALLEL TRUE)
set(Vc_DIR "${Vc_ROOT}/lib/cmake/Vc/")
message("Searching Vc in ${Vc_DIR}")
find_package(Boost 1.72.0 COMPONENTS unit_test_framework iostreams program_options system filesystem OPTIONAL_COMPONENTS fiber context thread)
set (ENV{BOOST_ROOT} ${BOOST_ROOT})
set (Boost_NO_BOOST_CMAKE OFF)
find_package(Boost 1.72.0 COMPONENTS unit_test_framework iostreams program_options system filesystem thread OPTIONAL_COMPONENTS fiber context thread)
find_package(MPI)
find_package(PETSc)
find_package(HDF5)
......@@ -89,7 +79,10 @@ find_package(Eigen3)
find_package(SuiteSparse OPTIONAL_COMPONENTS UMFPACK)
find_package(Vc)
find_package(OpenMP)
find_package(HIP)
if (CUDA_ON_BACKEND STREQUAL "HIP" AND NOT HIP_FOUND)
find_package(HIP)
endif()
set(CMAKE_SKIP_BUILD_RPATH TRUE)
if(HIP_FOUND)
......@@ -167,44 +160,51 @@ else()
message( FATAL_ERROR "ParMetis is required in order to install OpenFPM")
endif()
if (OPENMP_FOUND)
set(DEFINE_HAVE_OPENMP "#define HAVE_OPENMP")
endif()
file(READ ${CMAKE_SOURCE_DIR}/src/cmake/openfpmConfig-configure.cmake CMAKE_OPENFPM_CONFIG_VARS)
if(MPI_FOUND)
get_filename_component(OPENFPM_MPI_DEP "${MPI_C_INCLUDE_DIRS}" DIRECTORY)
file(READ ${CMAKE_SOURCE_DIR}/src/cmake/openfpmConfig-configure.cmake CMAKE_OPENFPM_CONFIG_VARS)
file(WRITE ${CMAKE_SOURCE_DIR}/src/cmake/openfpmConfigVars-configure.cmake "${CMAKE_OPENFPM_CONFIG_VARS}\nset(CMAKE_PREFIX_PATH ${OPENFPM_MPI_DEP}/)")
set(CMAKE_OPENFPM_CONFIG_VARS "${CMAKE_OPENFPM_CONFIG_VARS}\nset(CMAKE_PREFIX_PATH ${OPENFPM_MPI_DEP}/)")
set(DEFINE_HAVE_MPI "#define HAVE_MPI")
else()
file(WRITE error_code "200")
message( FATAL_ERROR "MPI is required in order to install OpenFPM" )
endif()
set(CMAKE_OPENFPM_CONFIG_VARS "${CMAKE_OPENFPM_CONFIG_VARS}\nmessage(STATUS \"Found OpenFPM version ${openfpm_VERSION} (\$\{CMAKE_CURRENT_LIST_FILE\})\")")
set(CMAKE_OPENFPM_CONFIG_VARS "${CMAKE_OPENFPM_CONFIG_VARS}\nset(OPENFPM_CUDA_ON_BACKEND \"${CUDA_ON_BACKEND}\")")
file(WRITE ${CMAKE_SOURCE_DIR}/src/cmake/openfpmConfig-Vars.cmake "${CMAKE_OPENFPM_CONFIG_VARS}")
if (Boost_FOUND)
set(DEFINE_HAVE_BOOST "#define HAVE_BOOST")
set(DEFINE_HAVE_BOOST_IOSTREAMS "#define HAVE_BOOST_IOSTREAMS")
set(DEFINE_HAVE_BOOST_PROGRAM_OPTIONS "#define HAVE_BOOST_PROGRAM_OPTIONS")
set(DEFINE_HAVE_BOOST_UNIT_TEST_FRAMEWORK "#define HAVE_BOOST_UNIT_TEST_FRAMEWORK")
if (Boost_CONTEXT_FOUND)
set(DEFINE_HAVE_BOOST_CONTEXT "#define HAVE_BOOST_CONTEXT")
set(OPTIONAL_BOOST_LIBS "-lboost_context")
else()
#if context is not there CUDA_ON_CPU cannot be activated
set(CUDA_ON_CPU OFF)
endif()
if (Boost_FIBER_FOUND)
set(DEFINE_HAVE_BOOST_FIBER "#define HAVE_BOOST_FIBER")
string(CONCAT OPTIONAL_BOOST_LIBS ${OPTIONAL_BOOST_LIBS} " -lboost_fiber")
endif()
file(WRITE optional_boost_libs "${OPTIONAL_BOOST_LIBS}")
if ((CUDA_ON_BACKEND STREQUAL "SEQUENTIAL" OR CUDA_ON_BACKEND STREQUAL "OpenMP") AND NOT Boost_CONTEXT_FOUND)
file(WRITE error_code "202")
message( FATAL_ERROR "BOOST is invalid reinstalling" )
endif()
# Get the library names
if (boost_context_FOUND)
file(WRITE optional_boost_libs "-L${BOOST_ROOT}/lib -lboost_context")
else()
file(WRITE optional_boost_libs " ")
endif()
else()
file(WRITE error_code "202")
message( FATAL_ERROR "BOOST is required in order to install OpenFPM" )
endif()
if(ENABLE_GPU AND CUDA_FOUND)
set(DEFINE_CUDA_GPU "#define CUDA_GPU")
if (OPENMP_FOUND)
if (NOT OpenMP_CXX_INCLUDE_DIRS STREQUAL "")
file(WRITE openmp_flags "${OpenMP_CXX_FLAGS} -I${OpenMP_CXX_INCLUDE_DIRS}")
else()
file(WRITE openmp_flags "${OpenMP_CXX_FLAGS}")
endif()
string(REPLACE ";" " " OpenMP_CXX_LIBRARIES_LIB "${OpenMP_CXX_LIBRARIES}")
file(WRITE openmp_libs ${OpenMP_CXX_LIBRARIES_LIB})
endif()
if(CUDA_ON_CPU)
if(ENABLE_GPU AND CUDA_FOUND)
set(DEFINE_CUDA_GPU "#define CUDA_GPU")
endif()
......@@ -262,20 +262,32 @@ if(TINYOBJLOADER_FOUND)
endif()
file(WRITE error_code "0")
file(WRITE mpi_include "-I${MPI_C_INCLUDE_DIRS}")
file(WRITE mpi_libs "${MPI_C_LINK_FLAGS} ${MPI_C_LIBRARIES}")
add_subdirectory (openfpm_io)
if (CUDA_ON_BACKEND STREQUAL "CUDA")
enable_language(CUDA)
find_package(CUDA)
endif()
file(WRITE cuda_lib "${CUDA_cudart_static_LIBRARY} ${CUDA_cudadevrt_LIBRARY}")
if(CUDA_ON_CPU)
file(WRITE cuda_include "-I${CUDA_INCLUDE_DIRS} -D__NVCC__ -DCUDART_VERSION=11000 -DCUDA_ON_CPU")
file(WRITE cuda_on_cpu "YES")
if(CUDA_ON_BACKEND STREQUAL "SEQUENTIAL" OR CUDA_ON_BACKEND STREQUAL "OpenMP")
file(WRITE cuda_include "-D__NVCC__ -DCUDART_VERSION=11000")
file(WRITE cuda_on_cpu "YES")
else()
file(WRITE cuda_include "-I${CUDA_INCLUDE_DIRS}")
file(WRITE cuda_on_cpu "NO")
if (NOT CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES STREQUAL "")
file(WRITE cuda_include "-I${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}")
else()
file(WRITE cuda_include " ")
endif()
file(WRITE cuda_on_cpu "NO")
endif()
file(WRITE mpi_include "-I${MPI_C_INCLUDE_DIRS}")
file(WRITE mpi_libs "${MPI_C_LINK_FLAGS} ${MPI_C_LIBRARIES}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config/config_cmake.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config/config.h)
add_subdirectory (openfpm_io)
add_subdirectory (openfpm_numerics)
file(WRITE cuda_options "${WARNING_SUPPRESSION_AND_OPTION_NVCC_TEXT}")
......
#! /bin/bash
# Make a directory in /tmp/OpenFPM_pdata
workspace=$1
hostname=$(hostname)
target=$3
......@@ -26,6 +27,7 @@ if [ x"$hostname" == x"cifarm-centos-node.mpi-cbg.de" ]; then
source /opt/rh/devtoolset-8/enable
./install_CMAKE_on_CI.sh $HOME/openfpm_dependencies/openfpm_pdata/$branch/
export PATH="$HOME/openfpm_dependencies/openfpm_pdata/$branch/CMAKE/bin:$PATH"
foward_options="--with-cuda-on-backend=OpenMP"
fi
if [ x"$hostname" == x"cifarm-ubuntu-node" ]; then
......@@ -33,16 +35,20 @@ if [ x"$hostname" == x"cifarm-ubuntu-node" ]; then
echo "Ubuntu node"
./install_MPI_mpich.sh $HOME/openfpm_dependencies/openfpm_pdata/$branch/ 4
export PATH="/opt/bin:$PATH"
foward_options="--enable-cuda-on-cpu"
foward_options="--with-cuda-on-backend=OpenMP"
fi
if [ x"$hostname" == x"cifarm-mac-node.mpi-cbg.de" ]; then
echo "Mac node"
# reinstall all deps
export PATH="/usr/local/bin:$PATH"
foward_options="--with-cuda-on-backend=SEQUENTIAL"
./install_CMAKE_on_CI.sh $HOME/openfpm_dependencies/openfpm_pdata/$branch/
export PATH="$HOME/openfpm_dependencies/openfpm_pdata/$branch/CMAKE/bin:$PATH"
# rm -rf /Users/admin/openfpm_dependencies/openfpm_pdata/$branch/
# rm -rf $HOME/openfpm_dependencies/openfpm_pdata/$branch/PETSC
#./install_CMAKE_on_CI.sh $HOME/openfpm_dependencies/openfpm_pdata/$branch/
# export PATH="$HOME/openfpm_dependencies/openfpm_pdata/$branch/CMAKE/bin:$PATH"
./install_CMAKE_on_CI.sh $HOME/openfpm_dependencies/openfpm_pdata/$branch/
export PATH="$HOME/openfpm_dependencies/openfpm_pdata/$branch/CMAKE/bin:$PATH"
fi
if [ x"$hostname" == x"falcon1" ]; then
......@@ -64,11 +70,17 @@ else
fi
if [ x"$with_gpu" == x"1" ]; then
gpu_support=-g
foward_options="$foward_options --with-cuda-on-backend=CUDA"
else
gpu_support=
fi
if [ x"$branch" == x"master_openmp" ]; then
foward_options="$foward_options --with-cuda-on-backend=OpenMP"
fi
#### If you have a dep_dir file change the branch name to the dep_dir
dep_dir=$(cat dep_dir)
......@@ -108,6 +120,8 @@ elif [ x"$comp_type" == x"garbageinjv" ]; then
foward_options="$foward_options --enable-garbageinjv"
elif [ x"$comp_type" == x"asan" ]; then
foward_options="$foward_options --enable-asan"
elif [ x"$comp_type" == x"openmp" ]; then
foward_options="$foward_options --with-cuda-on-backend=OpenMP"
fi
echo "Installing with: ./install $gpu_support -i $dependency_dir $install_options -c \"$installation_dir $foward_options \" "
......
......@@ -100,6 +100,7 @@ enable_debug
with_metis
with_hdf5
with_libhilbert
with_cuda_on_backend
enable_cuda_on_cpu
enable_scan_coverty
enable_test_performance
......@@ -123,8 +124,6 @@ with_suitesparse
with_petsc
with_eigen
with_vcdevel
enable_gpu
enable_hip
enable_asan
enable_garbageinj
enable_garbageinjv
......@@ -199,9 +198,6 @@ do
ac_useropt_orig=$ac_useropt
ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
case $ac_useropt in
gpu)
conf_options="$conf_options -DENABLE_GPU=OFF"
;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
ac_unrecognized_sep=', ';;
esac
......@@ -239,30 +235,17 @@ do
conf_options="$conf_options -DSE_CLASS3=ON"
;;
test_coverage)
conf_options="$conf_options -DTEST_COVERAGE=ON"
conf_options="$conf_options -DTEST_COVERAGE=ON -DCUDA_ON_BACKEND=SEQUENTIAL"
;;
scan_coverty)
conf_options="$conf_options -DSCAN_COVERTY=ON"
;;
cuda_on_cpu)
conf_options="$conf_options -DCUDA_ON_CPU=ON"
conf_options="$conf_options -DCUDA_ON_BACKEND=SEQUENTIAL"
;;
test_performance)
conf_options="$conf_options -DTEST_PERFORMANCE=ON"
;;
gpu)
conf_options="$conf_options -DCMAKE_CUDA_HOST_COMPILER=$(which mpic++) "
if [ x"$CXXCUDA" == x"" ]; then
conf_options="$conf_options"
else
conf_options="$conf_options -DCMAKE_CUDA_COMPILER=$(which $CXXCUDA)"
fi
conf_options="$conf_options -DENABLE_GPU=ON"
;;
hip)
conf_options="$conf_options -DHIP_ENABLE=ON -DENABLE_GPU=ON"
enable_hip_conf=1
;;
asan)
conf_options="$conf_options -DENABLE_ASAN=ON"
;;
......@@ -274,6 +257,8 @@ do
;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
ac_unrecognized_sep=', '
echo "Unrecognized option: $ac_unrecognized_opts"
exit 1
;;
esac
eval enable_$ac_useropt=\$ac_optarg ;;
......@@ -477,6 +462,19 @@ do
ac_useropt_orig=$ac_useropt
ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
case $ac_useropt in
cuda_on_backend)
conf_options="$conf_options -DCUDA_ON_BACKEND=$ac_optarg"
if [ x"$ac_optarg" != x"CUDA" ]; then
conf_options="$conf_options"
else
conf_options="$conf_options -DCMAKE_CUDA_HOST_COMPILER=$(which $CXX)"
fi
if [ x"$CXXCUDA" == x"" ]; then
conf_options="$conf_options"
else
conf_options="$conf_options -DCMAKE_CUDA_COMPILER=$(which $CXXCUDA)"
fi
;;
libhilbert)
conf_options="$conf_options -DLIBHILBERT_ROOT=$ac_optarg"
;;
......@@ -524,7 +522,10 @@ do
conf_options="$conf_options -DALPAKA_ROOT=$ac_optarg"
;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
ac_unrecognized_sep=', ';;
ac_unrecognized_sep=', '
echo "Unrecognized option: $ac_unrecognized_opts"
exit 1
;;
esac
eval with_$ac_useropt=\$ac_optarg ;;
......@@ -594,28 +595,34 @@ fi
cd build
## remove enerything
if [ x"$enable_hip_conf" != x"1" ]; then
conf_options="$conf_options -DCMAKE_C_COMPILER=mpicc -DCMAKE_CXX_COMPILER=mpic++"
fi
echo "Calling cmake ../. $conf_options"
printf "cmake ../. $conf_options" > cmake_build_options
printf "cmake ../. $conf_options" > cmake_build_options
rm ../openfpm_devices/error_code
rm ../error_code
DYLD_LIBRARY_PATH=$ld_lib_pathopt cmake ../. $conf_options
if [ $? != 0 ]; then
#ok something went wrong the install script analyze the return code to potentially fix the problem automatically
# Read the error code and exit with that
if [ -f ../error_code ]; then
ecod=$(cat ../error_code)
if [ x"$ecod" == x"0" ]; then
exit 1
else
echo "Analyze error $ecod"
exit $ecod
fi
else
exit 1
fi
#ok something went wrong the install script analyze the return code to potentially fix the problem automatically
# Read the error code and exit with that
if [ -f ../openfpm_devices/error_code ]; then
ecod=$(cat ../openfpm_devices/error_code)
if [ x"$ecod" == x"0" ]; then
exit 1
else
echo "Analyze error $ecod"
exit $ecod
fi
elif [ -f ../error_code ]; then
ecod=$(cat ../error_code)
if [ x"$ecod" == x"0" ]; then
exit 1
else
echo "Analyze error $ecod"
exit $ecod
fi
else
exit 1
fi
fi
cd ..
......
include ../../../example.mk
CC=mpic++
LDIR =
OBJ = main.o
%.o: %.cpp
$(CC) -O3 -c --std=c++14 -o $@ $< $(INCLUDE_PATH)
all: sphere_redistance
sphere_redistance: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
run: all
mpirun --oversubscribe -np 3 ./sphere_redistance
.PHONY: clean all
clean:
rm -f *.o *~ core sphere_redistance
/* Benchmark: Redistance a sphere which is only known as indicator function (using OpenFPM + Algoim)
* Date : 21 June 2021
* Author : sachin
*/
/**
* @file 0_sphere_redistancing/main.cpp
* @page Examples_ClosestPoint Redistancing Sphere
*
* @subpage example_closest_point_sphere
*
*/
/**
* @page example_closest_point_sphere Redistancing a sphere given as indicator function
*
* We are given a grid with a spherical surface implicitly represented using an
* indicator function,
* @f[ f_{ijk} = \begin{cases}
* 1, & \text{inside sphere}\\
* -1, & \text{outside sphere}
* \end{cases} @f]
*
*/
#include <cmath>
#include <iostream>
#include "Grid/grid_dist_id.hpp"
#include "data_type/aggregate.hpp"
#include "VCluster/VCluster.hpp"
#include "Vector/Vector.hpp"
#include "FiniteDifference/util/common.hpp"
#include "FiniteDifference/eq.hpp"
#include "FiniteDifference/FD_op.hpp"
#include "level_set/closest_point/closest_point.hpp"
constexpr int SIM_DIM = 3;
constexpr int POLY_ORDER = 5;
constexpr int SIM_GRID_SIZE = 64;
constexpr double PI = 3.141592653589793;
// Fields - phi, cp
using GridDist = grid_dist_id<SIM_DIM,double,aggregate<double,double[3]>>;
// Grid size on each dimension
const long int sz[SIM_DIM] = {SIM_GRID_SIZE, SIM_GRID_SIZE, SIM_GRID_SIZE};
const size_t szu[SIM_DIM] = {(size_t) sz[0], (size_t) sz[1], (size_t) sz[2]};
// 2D physical domain
Box<SIM_DIM,double> domain({-1.5,-1.5,-1.5},{1.5,1.5,1.5});
constexpr int x = 0;
constexpr int y = 1;
constexpr int z = 2;
// Alias for properties on the grid
constexpr int phi = 0;
constexpr int cp = 1;
double nb_gamma = 0.0;
constexpr int narrow_band_half_width = 8;
typedef struct EllipseParameters{
double origin[3];
double radiusA;
double radiusB;
double radiusC;
double eccentricity;
} EllipseParams;
// Generate the initial +1, -1 field for a sphere/ellipsoid
template<const unsigned int phi_field, typename grid_type>
void initializeIndicatorFunc(grid_type &gd, const EllipseParams &params)
{
// Note: Since we use a Non-periodic boundary, ghost_get does not update ghost layers of sim box.
// Therefore we are initializing the ghost layer with non-zero values.
auto it = gd.getDomainGhostIterator();
while(it.isNext())
{
auto key = it.get();
Point<grid_type::dims, double> coords = gd.getPos(key);
double posx = coords.get(x);
double posy = coords.get(y);
double posz = coords.get(z);
double phi_val = 1.0 - sqrt(((posx - params.origin[0])/params.radiusA)*((posx - params.origin[0])/params.radiusA) + ((posy - params.origin[1])/params.radiusB)*((posy - params.origin[1])/params.radiusB) + ((posz - params.origin[2])/params.radiusC)*((posz - params.origin[2])/params.radiusC));
gd.template get<phi_field>(key) = (phi_val<0)?-1.0:1.0;
++it;
}
}
// Computes the error in redistancing for a unit sphere
void estimateErrorInReinit(GridDist &gd, EllipseParams &params)
{
double max_phi_err = -1.0;
// Update the ls_phi field in ghosts
gd.template ghost_get<phi>(KEEP_PROPERTIES);
auto it = gd.getDomainIterator();
while(it.isNext())
{
auto key = it.get();