From ce5914c895c7e1fb741bc89cb88342d5d2d76a66 Mon Sep 17 00:00:00 2001 From: Serhii Yaskovets <yaskovet@mpi-cbg.de> Date: Wed, 28 Jun 2023 18:30:01 +0200 Subject: [PATCH] Add missing files to SparseGrid examples (Heat conduct, Porous Diff) --- .../Makefile | 68 ++++++++++ .../include/RemoveLines.hpp | 128 ++++++++++++++++++ .../Makefile | 68 ++++++++++ .../include/RemoveLines.hpp | 128 ++++++++++++++++++ 4 files changed, 392 insertions(+) create mode 100644 example/SparseGrid/10_heat_conduction_reticulate_porous_ceramics/Makefile create mode 100755 example/SparseGrid/10_heat_conduction_reticulate_porous_ceramics/include/RemoveLines.hpp create mode 100644 example/SparseGrid/9_inhomogeneous_diffusion_porous_catalyst_CaCO3/Makefile create mode 100755 example/SparseGrid/9_inhomogeneous_diffusion_porous_catalyst_CaCO3/include/RemoveLines.hpp diff --git a/example/SparseGrid/10_heat_conduction_reticulate_porous_ceramics/Makefile b/example/SparseGrid/10_heat_conduction_reticulate_porous_ceramics/Makefile new file mode 100644 index 000000000..f0dfe8b92 --- /dev/null +++ b/example/SparseGrid/10_heat_conduction_reticulate_porous_ceramics/Makefile @@ -0,0 +1,68 @@ +include ../../example.mk + +### This is a trick to avoid "Command not found if you no not have NVCC compiler". In practice the normal C++ compiler is used +### internally the example disable with the preprocessor its code if not compiled with nvcc +CUDA_CC= +CUDA_CC_LINK= +ifdef CUDA_ON_CPU + CUDA_CC=mpic++ -x c++ $(INCLUDE_PATH) + INCLUDE_PATH_NVCC= + CUDA_CC_LINK=mpic++ + CUDA_OPTIONS= + LIBS_SELECT=$(LIBS) +else + ifeq (, $(shell which nvcc)) + CUDA_CC=mpic++ -x c++ $(INCLUDE_PATH) + INCLUDE_PATH_NVCC= + CUDA_CC_LINK=mpic++ + CUDA_OPTIONS= + LIBS_SELECT=$(LIBS) + else + CUDA_CC=nvcc -ccbin=mpic++ + CUDA_CC_LINK=nvcc -ccbin=mpic++ + CUDA_OPTIONS=-use_fast_math -arch=sm_61 -lineinfo + LIBS_SELECT=$(LIBS_NVCC) + endif +endif + +ifeq ($(PROFILE),ON) + CUDA_CC=scorep --nocompiler --cuda --mpp=mpi nvcc -ccbin=mpic++ + CUDA_CC_LINK=scorep --nocompiler --cuda --mpp=mpi nvcc -ccbin=mpic++ +else + CUDA_CC:=$(CUDA_CC) + CUDA_CC_LINK:=$(CUDA_CC_LINK) +endif + +LDIR = +OPT= + +INCLUDE_PATH_NVCC:=$(INCLUDE_PATH_NVCC) -I./include + +OBJ = main.o + +heat_ceram: +heat_ceram_test: OPT += -DTEST_RUN +heat_ceram_test: heat_ceram + +%.o: %.cu + $(CUDA_CC) -O3 $(OPT) $(CUDA_OPTIONS) --extended-lambda --expt-relaxed-constexpr -g -c --std=c++14 -o $@ $< $(INCLUDE_PATH_NVCC) + +%.o: %.cpp + $(CC) -O3 $(OPT) -g -c --std=c++14 -o $@ $< $(INCLUDE_PATH) + +heat_ceram: $(OBJ) + $(CUDA_CC_LINK) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS_SELECT) + +heat_ceram2: $(OBJ) + $(CUDA_CC_LINK) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS_SELECT) + +all: heat_ceram + +run: heat_ceram_test + mpirun --oversubscribe -np 1 ./heat_ceram + +.PHONY: clean all run + +clean: + rm -f *.o *~ core heat_ceram + diff --git a/example/SparseGrid/10_heat_conduction_reticulate_porous_ceramics/include/RemoveLines.hpp b/example/SparseGrid/10_heat_conduction_reticulate_porous_ceramics/include/RemoveLines.hpp new file mode 100755 index 000000000..520438b26 --- /dev/null +++ b/example/SparseGrid/10_heat_conduction_reticulate_porous_ceramics/include/RemoveLines.hpp @@ -0,0 +1,128 @@ +// +// Created by jstark on 07.10.21. +// + +#ifndef SUSSMAN_REDISTANCING_REMOVELINES_HPP +#define SUSSMAN_REDISTANCING_REMOVELINES_HPP + +/**@brief Checks for thin lines and removes them by setting the value of the indicator function accordingly. + * + * @tparam grid_type Template type of OpenFPM grid. + * @tparam Phi_0_grid Property that contains the indicator or level-set function. + * @tparam sign_inside Sign that indicates that a node lies inside the object. Set to +1 or -1 depending on the + * convention you use. + * @param grid Grid that stores the indicator or level-set function. + */ +template <size_t Phi_0_grid, int sign_inside, typename grid_type> +void removeLines(grid_type & grid) +{ + if(sign_inside == 0) + { + std::cout << "sign_inside was set to 0. However, it must be set to +1 or -1 depending on the level-set " + "convention used. Aborting..." << std::endl; + abort(); + } + for(int repeat = 0; repeat < 2; ++repeat) + { + grid.template ghost_get<Phi_0_grid>(KEEP_PROPERTIES); + if (sign_inside > 0) + { + auto dom = grid.getDomainIterator(); + while(dom.isNext()) + { + auto key = dom.get(); + if (grid.template getProp<Phi_0_grid>(key) > 0) + { + for (int d = 0; d < grid_type::dims; ++d) + { + if (grid.template getProp<Phi_0_grid>(key.move(d, -1)) < 0 + && grid.template getProp<Phi_0_grid>(key.move(d, +1)) < 0) + { + grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1)); + break; + } + } + } + ++dom; + } + } + if (sign_inside < 0) + { + auto dom = grid.getDomainIterator(); + while(dom.isNext()) + { + auto key = dom.get(); + if (grid.template getProp<Phi_0_grid>(key) < 0) + { + for (int d = 0; d < grid_type::dims; ++d) + { + if (grid.template getProp<Phi_0_grid>(key.move(d, -1)) > 0 + && grid.template getProp<Phi_0_grid>(key.move(d, +1)) > 0) + { + grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1)); + break; + } + } + } + ++dom; + } + } + + } +} + +template <typename T> +bool is_inside(T phi) +{ + return phi >= 0 - std::numeric_limits<T>::epsilon(); +} + +template <typename T> +bool is_outside(T phi) +{ + return phi < 0 + std::numeric_limits<T>::epsilon(); +} + +/**@brief Checks for thin lines and thin spaces in between surfaces of 1dx thickness and removes them by setting the + * value of the indicator function equal accordingly. + * + * @tparam grid_type Template type of OpenFPM grid. + * @tparam Phi_0_grid Property that contains the indicator or level-set function. + * @param grid Grid that stores the indicator or level-set function. + */ +template <size_t Phi_0_grid, typename grid_type> +void removeLinesAndThinSpaces(grid_type & grid, int repeat=3) +{ + for(int k = 0; k < repeat; ++k) + { + grid.template ghost_get<Phi_0_grid>(KEEP_PROPERTIES); + auto dom = grid.getDomainIterator(); + while(dom.isNext()) + { + auto key = dom.get(); + for (int d = 0; d < grid_type::dims; ++d) + { + if (is_inside(grid.template getProp<Phi_0_grid>(key))) // If inside but neighbors are outside + { + if (is_outside(grid.template getProp<Phi_0_grid>(key.move(d, -1))) + && is_outside(grid.template getProp<Phi_0_grid>(key.move(d, +1)))) + { + grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1)); + break; + } + } + else if (is_outside(grid.template getProp<Phi_0_grid>(key))) // If outside but neighbors are inside + { + if (is_inside(grid.template getProp<Phi_0_grid>(key.move(d, -1))) + && is_inside(grid.template getProp<Phi_0_grid>(key.move(d, +1)))) + { + grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1)); + break; + } + } + } + ++dom; + } + } +} +#endif //SUSSMAN_REDISTANCING_REMOVELINES_HPP diff --git a/example/SparseGrid/9_inhomogeneous_diffusion_porous_catalyst_CaCO3/Makefile b/example/SparseGrid/9_inhomogeneous_diffusion_porous_catalyst_CaCO3/Makefile new file mode 100644 index 000000000..ec2f1f90d --- /dev/null +++ b/example/SparseGrid/9_inhomogeneous_diffusion_porous_catalyst_CaCO3/Makefile @@ -0,0 +1,68 @@ +include ../../example.mk + +### This is a trick to avoid "Command not found if you no not have NVCC compiler". In practice the normal C++ compiler is used +### internally the example disable with the preprocessor its code if not compiled with nvcc +CUDA_CC= +CUDA_CC_LINK= +ifdef CUDA_ON_CPU + CUDA_CC=mpic++ -x c++ $(INCLUDE_PATH) + INCLUDE_PATH_NVCC= + CUDA_CC_LINK=mpic++ + CUDA_OPTIONS= + LIBS_SELECT=$(LIBS) +else + ifeq (, $(shell which nvcc)) + CUDA_CC=mpic++ -x c++ $(INCLUDE_PATH) + INCLUDE_PATH_NVCC= + CUDA_CC_LINK=mpic++ + CUDA_OPTIONS= + LIBS_SELECT=$(LIBS) + else + CUDA_CC=nvcc -ccbin=mpic++ + CUDA_CC_LINK=nvcc -ccbin=mpic++ + CUDA_OPTIONS=-use_fast_math -arch=sm_61 -lineinfo + LIBS_SELECT=$(LIBS_NVCC) + endif +endif + +ifeq ($(PROFILE),ON) + CUDA_CC=scorep --nocompiler --cuda --mpp=mpi nvcc -ccbin=mpic++ + CUDA_CC_LINK=scorep --nocompiler --cuda --mpp=mpi nvcc -ccbin=mpic++ +else + CUDA_CC:=$(CUDA_CC) + CUDA_CC_LINK:=$(CUDA_CC_LINK) +endif + +LDIR = +OPT= + +INCLUDE_PATH_NVCC:=$(INCLUDE_PATH_NVCC) -I./include + +OBJ = main.o + +diff_CaCO3: +diff_CaCO3_test: OPT += -DTEST_RUN +diff_CaCO3_test: diff_CaCO3 + +%.o: %.cu + $(CUDA_CC) -O3 $(OPT) $(CUDA_OPTIONS) --extended-lambda --expt-relaxed-constexpr -g -c --std=c++14 -o $@ $< $(INCLUDE_PATH_NVCC) + +%.o: %.cpp + $(CC) -O3 $(OPT) -g -c --std=c++14 -o $@ $< $(INCLUDE_PATH) + +diff_CaCO3: $(OBJ) + $(CUDA_CC_LINK) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS_SELECT) + +diff_CaCO32: $(OBJ) + $(CUDA_CC_LINK) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS_SELECT) + +all: diff_CaCO3 + +run: diff_CaCO3_test + mpirun --oversubscribe -np 1 ./diff_CaCO3 + +.PHONY: clean all run + +clean: + rm -f *.o *~ core diff_CaCO3 + diff --git a/example/SparseGrid/9_inhomogeneous_diffusion_porous_catalyst_CaCO3/include/RemoveLines.hpp b/example/SparseGrid/9_inhomogeneous_diffusion_porous_catalyst_CaCO3/include/RemoveLines.hpp new file mode 100755 index 000000000..520438b26 --- /dev/null +++ b/example/SparseGrid/9_inhomogeneous_diffusion_porous_catalyst_CaCO3/include/RemoveLines.hpp @@ -0,0 +1,128 @@ +// +// Created by jstark on 07.10.21. +// + +#ifndef SUSSMAN_REDISTANCING_REMOVELINES_HPP +#define SUSSMAN_REDISTANCING_REMOVELINES_HPP + +/**@brief Checks for thin lines and removes them by setting the value of the indicator function accordingly. + * + * @tparam grid_type Template type of OpenFPM grid. + * @tparam Phi_0_grid Property that contains the indicator or level-set function. + * @tparam sign_inside Sign that indicates that a node lies inside the object. Set to +1 or -1 depending on the + * convention you use. + * @param grid Grid that stores the indicator or level-set function. + */ +template <size_t Phi_0_grid, int sign_inside, typename grid_type> +void removeLines(grid_type & grid) +{ + if(sign_inside == 0) + { + std::cout << "sign_inside was set to 0. However, it must be set to +1 or -1 depending on the level-set " + "convention used. Aborting..." << std::endl; + abort(); + } + for(int repeat = 0; repeat < 2; ++repeat) + { + grid.template ghost_get<Phi_0_grid>(KEEP_PROPERTIES); + if (sign_inside > 0) + { + auto dom = grid.getDomainIterator(); + while(dom.isNext()) + { + auto key = dom.get(); + if (grid.template getProp<Phi_0_grid>(key) > 0) + { + for (int d = 0; d < grid_type::dims; ++d) + { + if (grid.template getProp<Phi_0_grid>(key.move(d, -1)) < 0 + && grid.template getProp<Phi_0_grid>(key.move(d, +1)) < 0) + { + grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1)); + break; + } + } + } + ++dom; + } + } + if (sign_inside < 0) + { + auto dom = grid.getDomainIterator(); + while(dom.isNext()) + { + auto key = dom.get(); + if (grid.template getProp<Phi_0_grid>(key) < 0) + { + for (int d = 0; d < grid_type::dims; ++d) + { + if (grid.template getProp<Phi_0_grid>(key.move(d, -1)) > 0 + && grid.template getProp<Phi_0_grid>(key.move(d, +1)) > 0) + { + grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1)); + break; + } + } + } + ++dom; + } + } + + } +} + +template <typename T> +bool is_inside(T phi) +{ + return phi >= 0 - std::numeric_limits<T>::epsilon(); +} + +template <typename T> +bool is_outside(T phi) +{ + return phi < 0 + std::numeric_limits<T>::epsilon(); +} + +/**@brief Checks for thin lines and thin spaces in between surfaces of 1dx thickness and removes them by setting the + * value of the indicator function equal accordingly. + * + * @tparam grid_type Template type of OpenFPM grid. + * @tparam Phi_0_grid Property that contains the indicator or level-set function. + * @param grid Grid that stores the indicator or level-set function. + */ +template <size_t Phi_0_grid, typename grid_type> +void removeLinesAndThinSpaces(grid_type & grid, int repeat=3) +{ + for(int k = 0; k < repeat; ++k) + { + grid.template ghost_get<Phi_0_grid>(KEEP_PROPERTIES); + auto dom = grid.getDomainIterator(); + while(dom.isNext()) + { + auto key = dom.get(); + for (int d = 0; d < grid_type::dims; ++d) + { + if (is_inside(grid.template getProp<Phi_0_grid>(key))) // If inside but neighbors are outside + { + if (is_outside(grid.template getProp<Phi_0_grid>(key.move(d, -1))) + && is_outside(grid.template getProp<Phi_0_grid>(key.move(d, +1)))) + { + grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1)); + break; + } + } + else if (is_outside(grid.template getProp<Phi_0_grid>(key))) // If outside but neighbors are inside + { + if (is_inside(grid.template getProp<Phi_0_grid>(key.move(d, -1))) + && is_inside(grid.template getProp<Phi_0_grid>(key.move(d, +1)))) + { + grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1)); + break; + } + } + } + ++dom; + } + } +} +#endif //SUSSMAN_REDISTANCING_REMOVELINES_HPP -- GitLab