Skip to content

Commit

Permalink
finish cai demo
Browse files Browse the repository at this point in the history
  • Loading branch information
alfC committed Oct 10, 2024
1 parent 6961360 commit 657ff31
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/cai_1d_heat.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
///usr/bin/clang++ -std=c++23 $0 -I../include && ./a.out | gnuplot -persist; exit
#if COMPILE_RUN_INSTRUCTIONS
${CXX:-c++} -std=c++2b $0 -I../include && ./a.out | gnuplot; exit
#endif
#include <boost/multi/array.hpp>

#include <cmath> // for std::exp
Expand All @@ -12,7 +14,7 @@ void plot(auto const& x, auto const& f, std::string const& title = "") {
assert(x.size() == f.size());
std::cout << "set title '" << title << "'\n"
<< "plot '-' with linespoints\n";
for(auto i = 0; i < x.size(); ++i) {
for(auto i : x.extension()) {
std::cout << x[i] << " " << f[i] << "\n";
}
std::cout << 'e' << std::endl
Expand Down Expand Up @@ -50,8 +52,6 @@ auto main() -> int {
auto f_my_right = +append(f.dropped(1), NAN);
auto d2f = +stv::zip_transform([dx2 = dx * dx](auto r, auto m, auto l) { return (r - 2 * m + l) / dx2; }, f_my_right, f, f_my_left);

plot(x, d2f);

// dt = 0.01; D = 1;
// for k=1:100,
// f_my_left = [NaN, f(1:end-1)];
Expand All @@ -65,8 +65,8 @@ auto main() -> int {
auto dt = 0.01;
auto D = 1.0;
for(auto k = 0; k != 100; ++k) {
f_my_left({1, f.size()}) = f.taked(f.size() - 1);
f_my_right({0, f.size() - 1}) = f.dropped(1);
f_my_left({1, f.size()}) = f({0, f.size() - 1});
f_my_right({0, f.size() - 1}) = f({1, f.size()});

d2f = stv::zip_transform([dx2 = dx * dx](auto r, auto m, auto l) { return (r - 2 * m + l) / dx2; }, f_my_right, f, f_my_left);
f({1, f.size() - 1}) = stv::zip_transform([dt, D, dx2 = dx * dx](auto eff, auto d2) { return eff + D * dt * d2; }, f({1, f.size() - 1}), d2f({1, f.size() - 1}));
Expand Down

0 comments on commit 657ff31

Please sign in to comment.