Skip to content
Snippets Groups Projects
Commit 5cdf96a9 authored by yaskovet's avatar yaskovet
Browse files

Add missing files to SparseGrid examples (Heat conduct, Porous Diff)

parent bf1a5025
No related branches found
No related tags found
No related merge requests found
Pipeline #5840 failed
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
//
// 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
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
//
// 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment