diff options
-rw-r--r-- | SConstruct | 6 | ||||
-rw-r--r-- | c++/SConscript | 18 | ||||
-rw-r--r-- | examples/SConscript | 33 | ||||
-rw-r--r-- | examples/cavity_2d.cpp (renamed from c++/examples/cavity_2d.cpp) | 53 |
4 files changed, 84 insertions, 26 deletions
@@ -43,6 +43,11 @@ env_vars.Add('prefix', validator=isAbsolutePath ) +env_vars.Add('build_examples', + help='If examples should be built', + default="true" +) + env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], CPPDEFINES=['SAW_UNIX'], CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], @@ -58,6 +63,7 @@ env.targets = []; Export('env') SConscript('c++/SConscript') +SConscript('examples/SConscript') SConscript('tests/SConscript') env.Alias('cdb', env.cdb); diff --git a/c++/SConscript b/c++/SConscript index 772d526..57091af 100644 --- a/c++/SConscript +++ b/c++/SConscript @@ -19,21 +19,7 @@ env.sources += core_env.sources; env.headers += core_env.headers; -## Shared lib +## Static lib objects = [] core_env.add_source_files(objects, core_env.sources, shared=False); - -core_env.examples = []; -# Cavity2D -core_env.cavity_2d_source = sorted(glob.glob(dir_path + "/examples/cavity_2d.cpp")); -env.sources += core_env.cavity_2d_source; -core_env.cavity_2d = core_env.Program('#bin/cavity_2d', [core_env.cavity_2d_source, core_env.objects]); -core_env.examples += core_env.cavity_2d; - -# Set Alias -env.Alias('examples', [core_env.examples]); - -env.targets += ['examples']; - -# Install -env.Install('$prefix/bin', [core_env.examples]); +env.library_static = core_env.StaticLibrary('#build/kel-lbm', [objects]); diff --git a/examples/SConscript b/examples/SConscript new file mode 100644 index 0000000..c9d85cb --- /dev/null +++ b/examples/SConscript @@ -0,0 +1,33 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +examples_env = env.Clone(); + +examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += examples_env.sources; +env.headers += examples_env.headers; + +# Cavity2D +examples_objects = []; +examples_env.add_source_files(examples_objects, ['cavity_2d.cpp'], shared=False); +examples_env.cavity_2d = examples_env.Program('#bin/cavity_2d', [env.library_static, examples_objects]); + +# Set Alias +env.examples = [examples_env.cavity_2d]; +env.Alias('examples', env.examples); + +if env["build_examples"]: + env.targets += ['examples']; + env.Install('$prefix/bin/', env.examples); +#endif diff --git a/c++/examples/cavity_2d.cpp b/examples/cavity_2d.cpp index 00c1741..3e2e064 100644 --- a/c++/examples/cavity_2d.cpp +++ b/examples/cavity_2d.cpp @@ -1,4 +1,4 @@ -#include "../descriptor.hpp" +#include "../c++/descriptor.hpp" /** */ @@ -439,6 +439,7 @@ int main(){ std::cout<<"\n"; typename saw::native_data_type<sch::T>::type sum = 0.0; + apply_for_cells([&](auto& cell, std::size_t i, std::size_t j){ auto& dfs = cell.template get<"dfs">(); typename saw::native_data_type<sch::T>::type rho; @@ -449,47 +450,79 @@ int main(){ sum += rho; } auto angle = std::atan2(vel[1],vel[0]); + double vel_mag = vel[1] * vel[1] + vel[0] * vel[0]; auto dir_char = [&]() -> std::string_view { + /** + * Flipped y due to print order + */ constexpr auto pi = M_PI; - if((vel[1] * vel[1] + vel[0]*vel[0]) < 1e-16){ + return "■"; + if(vel_mag < 1e-4){ return "•"; } if(angle > 7.0 / 8.0 * pi){ return "←"; } if(angle > 5.0 / 8.0 * pi){ - return "↖"; + return "↙"; } if(angle > 3.0 / 8.0 * pi){ - return "↑"; + return "↓"; } if(angle > 1.0 / 8.0 * pi){ - return "↗"; + return "↘"; } if(angle > -1.0 / 8.0 * pi){ return "→"; } if(angle > -3.0 / 8.0 * pi){ - return "↘"; + return "↗"; } if(angle > -5.0 / 8.0 * pi){ - return "↓"; + return "↑"; } if(angle > -7.0 / 8.0 * pi){ - return "↙"; + return "↖"; } return "←"; }(); - std::cout<<dir_char; + + std::array<uint32_t,3u> rgb_start{64,64,255}; + std::array<uint32_t,3u> rgb_stop{255,64,64}; + std::array<uint32_t,3u> rgb_middle{255,255,255}; + + + auto col_interpol = [&](){ + std::array<uint32_t, 3u> rgb_interpol = rgb_start; + double vel_mag_cut = std::min(1.0,std::max(vel_mag/(0.07*0.07),0.0)); + + if(vel_mag_cut < 0.5){ + uint32_t vel_mag_i = static_cast<uint32_t>(2.0 * vel_mag_cut * 256); + for(uint8_t i = 0u; i < 3u; ++i){ + rgb_interpol[i] = (rgb_middle[i] * vel_mag_i + (256-vel_mag_i) * rgb_start[i]) / 256; + } + }else{ + uint32_t vel_mag_i = static_cast<uint32_t>((2.0*(vel_mag_cut-0.5)) * 256); + for(uint8_t i = 0u; i < 3u; ++i){ + rgb_interpol[i] = (rgb_stop[i] * vel_mag_i + (256-vel_mag_i) * rgb_middle[i]) / 256; + } + } + return rgb_interpol; + }; + auto rgb_interpol = col_interpol(); + + std::cout<<"\x1b[38;2;"<<rgb_interpol[0]<<";"<<rgb_interpol[1]<<";"<<rgb_interpol[2]<<"m"<<dir_char; if( (i+1) < dim_x){ std::cout<<" "; }else{ std::cout<<"\n"; } }, lattice); + std::cout<<"\x1b[38;2;255;255;255m"; - std::cout<<"Average rho: "<<(sum / ((dim_x-4)*(dim_y-4)))<<std::endl; + /// std::cout<<"Average rho: "<<(sum / ((dim_x-4)*(dim_y-4)))<<std::endl; + std::cout.flush(); std::ofstream vtk_file{"tmp/cavity_2d_"+std::to_string(file_no)+".vtk"}; |