-
Notifications
You must be signed in to change notification settings - Fork 16
Dirichlet bcond #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Dirichlet bcond #499
Changes from all commits
521b164
7e7ffc7
09fea5e
dc7459d
666ebf6
c1690c6
bed3cdd
8ab7ce0
3bac12f
38ebf3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // 2D fixed (Dirichlet) boundary conditions for libmpdata++ | ||
| // | ||
| // licensing: GNU GPL v3 | ||
| // copyright: University of Warsaw | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <libmpdata++/bcond/detail/bcond_common.hpp> | ||
|
|
||
| namespace libmpdataxx | ||
| { | ||
| namespace bcond | ||
| { | ||
| template <typename real_t, int halo, bcond_e knd, drctn_e dir, int n_dims, int d> | ||
| class bcond< real_t, halo, knd, dir, n_dims, d, | ||
| typename std::enable_if< | ||
| knd == fixed && | ||
| dir == left && | ||
| n_dims == 2 | ||
| >::type | ||
| > : public bcond<real_t, halo, open, dir, n_dims, d> // TODO: in some cases (e.g. cloud chamber) we might want to inherit from rigid? | ||
| { | ||
| using parent_t = bcond<real_t, halo, open, dir, n_dims, d>; | ||
| using arr_t = blitz::Array<real_t, 2>; | ||
| using parent_t::parent_t; // inheriting ctor | ||
|
|
||
| // holds fixed wall values (equal to initial edge values) | ||
| std::unordered_map<const arr_t*, arr_t> edge_values; | ||
|
|
||
| public: | ||
|
|
||
| void fill_halos_sclr(arr_t &a, const rng_t &j, const bool deriv = false) | ||
| { | ||
| // #if !defined(NDEBUG) | ||
| // assert(edge_values.find(&a) != edge_values.end() && "fixed bcond: edge values not saved before filling halos"); | ||
| // #endif | ||
|
|
||
| // if edge values are not saved, use open boundary (done to fix sgs eddy viscosity k_m) | ||
| if(edge_values.find(&a) == edge_values.end()) | ||
| { | ||
| parent_t::fill_halos_sclr(a, j, deriv); | ||
| return; | ||
| } | ||
|
|
||
| using namespace idxperm; | ||
| for (int i = this->left_halo_sclr.first(); i <= this->left_halo_sclr.last(); ++i) | ||
| { | ||
| a(pi<d>(i, j)) = edge_values[&a](pi<d>(0, j)); | ||
| } | ||
| } | ||
|
|
||
| void save_edge_val(const arr_t &a, const arr_t &val, const rng_t &j) | ||
| { | ||
| using namespace idxperm; | ||
| // assert(a.shape() == val.shape()); | ||
| auto s = a.shape(); | ||
| s[d] = 1; | ||
| edge_values.try_emplace(&a, arr_t(s)); | ||
| if constexpr(d == 0) edge_values[&a].reindexSelf({0, a.lbound(1)}); | ||
| else if constexpr(d == 1) edge_values[&a].reindexSelf({a.lbound(0), 0}); | ||
| edge_values[&a](pi<d>(0, j)) = val(pi<d>(this->left_edge_sclr, j)); | ||
| } | ||
| }; | ||
|
|
||
| template <typename real_t, int halo, bcond_e knd, drctn_e dir, int n_dims, int d> | ||
| class bcond< real_t, halo, knd, dir, n_dims, d, | ||
| typename std::enable_if< | ||
| knd == fixed && | ||
| dir == rght && | ||
| n_dims == 2 | ||
| >::type | ||
| > : public bcond<real_t, halo, open, dir, n_dims, d> | ||
| { | ||
| using parent_t = bcond<real_t, halo, open, dir, n_dims, d>; | ||
| using arr_t = blitz::Array<real_t, 2>; | ||
| using parent_t::parent_t; // inheriting ctor | ||
|
|
||
| // holds fixed wall values (equal to initial edge values) | ||
| std::unordered_map<const arr_t*, arr_t> edge_values; | ||
|
|
||
| public: | ||
|
|
||
| // TODO | ||
|
|
||
| // void fill_halos_sclr(arr_t &a, const rng_t &j, const bool deriv = false) | ||
| // { | ||
| // using namespace idxperm; | ||
| // for (int i = this->rght_halo_sclr.first(); i <= this->rght_halo_sclr.last(); ++i) | ||
| // { | ||
| // a(pi<d>(i, j)) = edge_values[&a](pi<d>(0, j)); | ||
| // } | ||
| // } | ||
|
|
||
| // void save_edge_val(const arr_t &a, const arr_t &val, const rng_t &j) | ||
| // { | ||
| // using namespace idxperm; | ||
| // // assert(a.shape() == val.shape()); | ||
| // auto s = a.shape(); | ||
| // s[d] = 1; | ||
| // edge_values.try_emplace(&a, arr_t(s)); | ||
| // if constexpr (d == 0) edge_values[&a].reindexSelf({0, a.lbound(1)}); | ||
| // else if constexpr(d == 1) edge_values[&a].reindexSelf({a.lbound(0), 0}); | ||
| // edge_values[&a](pi<d>(0, j)) = val(pi<d>(this->rght_edge_sclr, j)); | ||
| // } | ||
| }; | ||
| } // namespace bcond | ||
| } // namespace libmpdataxx | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,105 @@ | ||||||||||
| // 3D fixed (Dirichlet) boundary conditions for libmpdata++ | ||||||||||
| // | ||||||||||
| // licensing: GNU GPL v3 | ||||||||||
| // copyright: University of Warsaw | ||||||||||
|
|
||||||||||
| #pragma once | ||||||||||
|
|
||||||||||
| #include <libmpdata++/bcond/detail/bcond_common.hpp> | ||||||||||
|
|
||||||||||
| namespace libmpdataxx | ||||||||||
| { | ||||||||||
| namespace bcond | ||||||||||
| { | ||||||||||
| template <typename real_t, int halo, bcond_e knd, drctn_e dir, int n_dims, int d> | ||||||||||
| class bcond< real_t, halo, knd, dir, n_dims, d, | ||||||||||
| typename std::enable_if< | ||||||||||
| knd == fixed && | ||||||||||
| dir == left && | ||||||||||
| n_dims == 3 | ||||||||||
| >::type | ||||||||||
| > : public bcond<real_t, halo, open, dir, n_dims, d> // TODO: in some cases (e.g. cloud chamber) we might want to inherit from rigid? | ||||||||||
| { | ||||||||||
| using parent_t = bcond<real_t, halo, open, dir, n_dims, d>; | ||||||||||
| using arr_t = blitz::Array<real_t, 3>; | ||||||||||
| using parent_t::parent_t; // inheriting ctor | ||||||||||
|
|
||||||||||
| // holds fixed wall values (equal to initial edge values) | ||||||||||
| std::unordered_map<const arr_t*, arr_t> edge_values; | ||||||||||
|
|
||||||||||
| public: | ||||||||||
|
|
||||||||||
| void fill_halos_sclr(arr_t &a, const rng_t &j, const rng_t &k, const bool deriv = false) | ||||||||||
| { | ||||||||||
| #if !defined(NDEBUG) | ||||||||||
| assert(edge_values.find(&a) != edge_values.end() && "fixed bcond: edge values not saved before filling halos"); | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| using namespace idxperm; | ||||||||||
| for (int i = this->left_halo_sclr.first(); i <= this->left_halo_sclr.last(); ++i) | ||||||||||
| { | ||||||||||
| a(pi<d>(i, j, k)) = edge_values[&a](pi<d>(0, j, k)); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void save_edge_val(const arr_t &a, const arr_t &val, const rng_t &j, const rng_t &k) | ||||||||||
| { | ||||||||||
| using namespace idxperm; | ||||||||||
| // assert(a.shape() == val.shape()); | ||||||||||
|
||||||||||
| // assert(a.shape() == val.shape()); | |
| #if !defined(NDEBUG) | |
| assert(a.shape() == val.shape()); | |
| #endif |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out assertion should be either enabled or removed. Line 94 contains a commented assertion to verify that array shapes match. If this check is needed, it should be enabled within an #if !defined(NDEBUG) block like the assertion in the left direction implementation. If the check is not needed, the commented code should be removed to reduce clutter and improve maintainability.
| // assert(a.shape() == val.shape()); | |
| #if !defined(NDEBUG) | |
| assert(a.shape() == val.shape()); | |
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out assertion should be either enabled or removed. Line 48 contains a commented assertion to verify that array shapes match. If this check is needed, it should be enabled within an #if !defined(NDEBUG) block like the assertion on line 35. If the check is not needed, the commented code should be removed to reduce clutter and improve maintainability.