diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/cavity_2d.cpp | 30 | ||||
-rw-r--r-- | examples/particle_ibm.cpp | 86 |
2 files changed, 99 insertions, 17 deletions
diff --git a/examples/cavity_2d.cpp b/examples/cavity_2d.cpp index d40e06e..a10276a 100644 --- a/examples/cavity_2d.cpp +++ b/examples/cavity_2d.cpp @@ -44,6 +44,11 @@ using CellStruct = Struct< Member<CellInfo<Desc>, "info"> >; +template<typename T, uint64_t D> +using MacroStruct = Struct< + Member<FixedArray<T,D>, "velocity">, + Member<T, "pressure"> +>; using CavityFieldD2Q9 = CellField<D2Q9, CellStruct<D2Q9>>; } @@ -390,6 +395,8 @@ int main(){ uint64_t print_every = 256u; uint64_t file_no = 0u; + saw::data<sch::Array<sch::MacroStruct<sch::T,sch::D2Q9::D>,sch::D2Q9::D>> macros{dim}; + for(uint64_t step = 0; step < lattice_steps; ++step){ if(step % print_every == 0u){ @@ -481,28 +488,17 @@ int main(){ /// 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"}; - - vtk_file <<"# vtk DataFile Version 3.0\n"; - vtk_file <<"Velocity Cavity2D example\n"; - vtk_file <<"ASCII\n"; - vtk_file <<"DATASET STRUCTURED_POINTS\n"; - vtk_file <<"DIMENSIONS "<< dim_x <<" "<<dim_y<<" 1\n"; - vtk_file <<"SPACING 1.0 1.0 1.0\n"; - vtk_file <<"ORIGIN 0.0 0.0 0.0\n"; - vtk_file <<"POINT_DATA "<<(dim_x*dim_y)<<"\n"; - vtk_file <<"VECTORS Velocity float\n"; - apply_for_cells([&](auto& cell, std::size_t i, std::size_t j){ auto dfs = even_step ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - typename saw::native_data_type<sch::T>::type rho; - std::array<typename saw::native_data_type<sch::T>::type, sch::D2Q9::D> vel; + auto& rho = macros.at({{i,j}}).template get<"pressure">(); + auto& vel = macros.at({{i,j}}).template get<"velocity">(); compute_rho_u<sch::T,sch::D2Q9>(dfs,rho,vel); - - vtk_file << static_cast<float>(vel[0u]) << " " << static_cast<float>(vel[1u])<<" 0.0\n"; }, lattice); - + + std::string vtk_f_name{"tmp/cavity_2d_"}; + vtk_f_name += std::to_string(file_no) + ".vtk"; + write_vtk_file(vtk_f_name, macros); ++file_no; } diff --git a/examples/particle_ibm.cpp b/examples/particle_ibm.cpp new file mode 100644 index 0000000..a2b510e --- /dev/null +++ b/examples/particle_ibm.cpp @@ -0,0 +1,86 @@ +#include "../c++/descriptor.hpp" + +#include <forstio/codec/data.hpp> + +namespace kel { +namespace lbm { +namespace sch { +using namespace saw::schema; + +/** + * Basic distribution function + * Base type + * D + * Q + * Scalar factor + * D factor + * Q factor + */ +using T = Float32; +using D2Q5 = Descriptor<2,5>; +using D2Q9 = Descriptor<2,9>; + +template<typename Desc> +using DfCell = Cell<T, Desc, 0, 0, 1>; + +template<typename Desc> +using CellInfo = Cell<UInt8, D2Q9, 1, 0, 0>; + +/** + * Basic type for simulation + */ +template<typename Desc> +using CellStruct = Struct< + Member<DfCell<Desc>, "dfs">, + Member<DfCell<Desc>, "dfs_old">, + Member<CellInfo<Desc>, "info">, + Member<UInt8, "geometry">, + Member<UInt32, "particle"> +>; + + +using CavityFieldD2Q9 = CellField<D2Q9, CellStruct<D2Q9>>; +} +} +} + +int main(int argc, char** argv){ + using namespace kel::lbm; + + std::string_view cfg_file_name = "config.json"; + if(argc > 1){ + cfg_file_name = argv[1]; + } + + auto eo_conf = load_lbm_config<sch::Float64,sch::Descriptor<2,9>>(cfg_file_name); + if(eo_conf.is_error()){ + auto& err = eo_conf.get_error(); + std::cerr<<"[Error]: "<<err.get_category(); + auto err_msg = err.get_message(); + if(!err_msg.empty()){ + std::cerr<<" - "<<err_msg; + } + std::cerr<<std::endl; + + return err.get_id(); + } + + auto& conf = eo_conf.get_value(); + + converter<sch::Float64> conv{ + {conf.template get<"delta_x">()}, + {conf.template get<"delta_t">()} + }; + + print_lbm_meta<sch::Float64,sch::Descriptor<2,9>>(conv, {conf.template get<"kinematic_viscosity">()}); + + + saw::data<sch::FixedArray<sch::UInt64,sch::D2Q9::D>> dim{{128, 128}}; + + saw::data<sch::CavityFieldD2Q9, saw::encode::Native> lattice{dim}; + + + + + return 0; +} |