Skip to content
Snippets Groups Projects
Commit c70e41cd authored by CHAMONT David's avatar CHAMONT David
Browse files

Instrumente GrayScott pour CADNA.

parent eb7ea991
No related branches found
No related tags found
No related merge requests found
# Direct CMake to use icpx rather than the default C++ compiler/linker
set(CMAKE_CXX_COMPILER icpx)
cmake_minimum_required (VERSION 3.4)
project(GrayScottBuffer CXX)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_subdirectory (src)
SHELL = /bin/bash
all: main.exe
clean:
rm -f *.exe
%.exe: ../src/%.cpp
@rm -f $@
g++ -std=c++20 -O2 -Wall -Wextra -Wfloat-equal -o $@ $^ -lcadnaC
#!/bin/bash
clear
rm -rf build
mkdir -p build
cd build
cmake ..
#!/bin/bash
time ./build/main.exe 1080 1920 5 100
time ./build/main.exe 1080 1920 50 10
echo
set(SOURCE_FILE main.cpp)
set(TARGET_NAME main.exe)
set(COMPILE_FLAGS "-Wall")
add_executable(${TARGET_NAME} ${SOURCE_FILE})
set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS}")
......@@ -4,14 +4,18 @@
#include <cassert>
#include <numeric>
constexpr float KILL_RATE { 0.062f };
constexpr float FEED_RATE { 0.03f };
constexpr float DT { 1.0f };
constexpr float DIFFUSION_RATE_U { 0.1f };
constexpr float DIFFUSION_RATE_V { 0.05f };
#include <cadna.h>
using real = double_st ;
const real KILL_RATE { 0.062f };
const real FEED_RATE { 0.03f };
const real DT { 1.0f };
const real DIFFUSION_RATE_U { 0.1f };
const real DIFFUSION_RATE_V { 0.05f };
template<typename Collection>
void drop( Collection & data, std::size_t nb_rows, std::size_t nb_cols, float value ) {
void drop( Collection & data, std::size_t nb_rows, std::size_t nb_cols, real value ) {
const std::size_t center_row { nb_rows/2ul };
const std::size_t center_col { nb_cols/2ul };
......@@ -24,19 +28,19 @@ void drop( Collection & data, std::size_t nb_rows, std::size_t nb_cols, float va
}
void process(
std::vector<float> const & iu, std::vector<float> const & iv,
std::vector<float> & ou, std::vector<float> & ov,
std::vector<real> const & iu, std::vector<real> const & iv,
std::vector<real> & ou, std::vector<real> & ov,
std::size_t nb_rows, std::size_t nb_cols ) {
for (std::size_t r = 0 ; r < (nb_rows-2); r++) {
for (std::size_t c = 0; c < (nb_cols-2); c++) {
float u = iu[(r+1)*nb_cols+c+1];
float v = iv[(r+1)*nb_cols+c+1];
float uvv = u*v*v;
real u = iu[(r+1)*nb_cols+c+1];
real v = iv[(r+1)*nb_cols+c+1];
real uvv = u*v*v;
float full_u = 0.0f;
float full_v = 0.0f;
real full_u = 0.0f;
real full_v = 0.0f;
for(std::size_t k = 0ul; k < 3ul; ++k){
for(std::size_t l = 0ul; l < 3ul; ++l){
full_u += iu[(r+k)*nb_cols+c+l] - u;
......@@ -44,8 +48,8 @@ void process(
}
}
float du = DIFFUSION_RATE_U*full_u - uvv + FEED_RATE*(1.0f - u);
float dv = DIFFUSION_RATE_V*full_v + uvv - (FEED_RATE + KILL_RATE)*v;
real du = DIFFUSION_RATE_U*full_u - uvv + FEED_RATE*(1.0f - u);
real dv = DIFFUSION_RATE_V*full_v + uvv - (FEED_RATE + KILL_RATE)*v;
ou[(r+1)*nb_cols+c+1] = u + du*DT;
ov[(r+1)*nb_cols+c+1] = v + dv*DT;
......@@ -63,19 +67,21 @@ int main( int argc, char * argv[] ) {
std::size_t nb_images {std::stoul(argv[3])};
std::size_t nb_iterations {std::stoul(argv[4])};
std::cout << std::fixed << std::setprecision(6);
std::cout << std::endl;
cadna_init(-1);
try {
// Temporary work images
std::vector<float> u1(nb_rows*nb_cols,1.f);
std::vector<float> v1(nb_rows*nb_cols,0.f);
std::vector<float> u2(nb_rows*nb_cols,1.f);
std::vector<float> v2(nb_rows*nb_cols,0.f);
std::vector<real> u1(nb_rows*nb_cols,1.f);
std::vector<real> v1(nb_rows*nb_cols,0.f);
std::vector<real> u2(nb_rows*nb_cols,1.f);
std::vector<real> v2(nb_rows*nb_cols,0.f);
drop(u1, nb_rows, nb_cols, 0.f);
drop(v1, nb_rows, nb_cols, 1.f);
// Final images sequence
std::vector<std::vector<float>> images;
std::vector<std::vector<real>> images;
images.push_back(u1);
// Iterations
......@@ -85,12 +91,19 @@ int main( int argc, char * argv[] ) {
process( u1, v1, u2, v2, nb_rows, nb_cols );
std::swap(u1,u2) ; std::swap (v1,v2) ;
}
float flag = std::inner_product(u1.begin(), u1.end(), v1.begin(),0.f);
std::cout << flag << ' ' << std::flush;
std::cout << '.' << std::flush;
images.push_back(u1);
}
std::cout << std::endl;
// Final product
std::cout << std::endl;
real product = std::inner_product(u1.begin(), u1.end(), v1.begin(),0.f);
std::cout
<< "product : " << product
<< ", with " << product.nb_significant_digit() << " significant digits"
<< std::endl;
}
catch (std::exception & e) {
std::cout << e.what() << std::endl;
......@@ -100,5 +113,7 @@ int main( int argc, char * argv[] ) {
}
// End
std::cout << std::endl;
cadna_end();
return 0;
}
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