Skip to content

Commit 36182aa

Browse files
author
Matthew Emmett
committed
quadrature: Add pfasst::augment_nodes and handle is_proper flags appropriately.
1 parent 024b40f commit 36182aa

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

include/pfasst/encap/encap_sweeper.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace pfasst
2525
{
2626
//! @{
2727
vector<time> nodes;
28+
vector<bool> is_proper;
2829
shared_ptr<EncapFactory<time>> factory;
2930
//! @}
3031

@@ -69,14 +70,21 @@ namespace pfasst
6970
//! @{
7071
void set_nodes(vector<time> nodes)
7172
{
72-
this->nodes = nodes;
73+
auto augmented = pfasst::augment_nodes(nodes);
74+
this->nodes = get<0>(augmented);
75+
this->is_proper = get<1>(augmented);
7376
}
7477

7578
const vector<time> get_nodes() const
7679
{
7780
return nodes;
7881
}
7982

83+
const vector<bool> get_is_proper() const
84+
{
85+
return is_proper;
86+
}
87+
8088
void set_factory(shared_ptr<EncapFactory<time>> factory)
8189
{
8290
this->factory = shared_ptr<EncapFactory<time>>(factory);

include/pfasst/encap/imex_sweeper.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace pfasst
3030
* explicitly and the stiff part implicitly.
3131
* Therefore, we define the splitting \\( F(t,u) = F_{expl}(t,u) + F_{impl}(t,u) \\).
3232
*
33-
* This sweeper requires three interfaces to be implement for such ODEs: two routines to
34-
* evaluate the explicit \\( F_{\\rm expl} \\) and implicit \\( F_{\\rm impl} \\) pieces for a
35-
* given state, and one that solves (perhaps with an external solver) the backward-Euler
33+
* This sweeper requires three interfaces to be implement for such ODEs: two routines to
34+
* evaluate the explicit \\( F_{\\rm expl} \\) and implicit \\( F_{\\rm impl} \\) pieces for a
35+
* given state, and one that solves (perhaps with an external solver) the backward-Euler
3636
* equation \\( U^{n+1} - \\Delta t F_{\\rm impl}(U^{n+1}) = RHS \\) for \\( U^{n+1} \\).
3737
*
3838
* @tparam time precision type of the time dimension
@@ -173,9 +173,10 @@ namespace pfasst
173173
virtual void setup(bool coarse) override
174174
{
175175
auto nodes = this->get_nodes();
176+
auto is_proper = this->get_is_proper();
176177
assert(nodes.size() >= 1);
177178

178-
this->s_mat = compute_quadrature(nodes, nodes, 's');
179+
this->s_mat = compute_quadrature(nodes, nodes, is_proper, 's');
179180

180181
this->s_mat_expl = this->s_mat;
181182
this->s_mat_impl = this->s_mat;

include/pfasst/quadrature.hpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,27 @@ namespace pfasst
210210
return nodes;
211211
}
212212

213+
template<typename node>
214+
auto augment_nodes(vector<node> const orig) -> pair<vector<node>,vector<bool>>
215+
{
216+
vector<node> nodes = orig;
217+
218+
bool left = nodes.front() == node(0.0);
219+
bool right = nodes.back() == node(1.0);
220+
221+
if (!left) { nodes.insert(nodes.begin(), node(0.0)); }
222+
if (!right) { nodes.insert(nodes.end(), node(1.0)); }
223+
224+
vector<bool> is_proper(nodes.size(), true);
225+
is_proper.front() = left;
226+
is_proper.back() = right;
227+
228+
return pair<vector<node>,vector<bool>>(nodes, is_proper);
229+
}
230+
231+
213232
template<typename node = time_precision>
214-
matrix<node> compute_quadrature(vector<node> dst, vector<node> src, char type)
233+
matrix<node> compute_quadrature(vector<node> dst, vector<node> src, vector<bool> is_proper, char type)
215234
{
216235
const size_t ndst = dst.size();
217236
const size_t nsrc = src.size();
@@ -222,11 +241,13 @@ namespace pfasst
222241
Polynomial<node> p(nsrc + 1), p1(nsrc + 1);
223242

224243
for (size_t i = 0; i < nsrc; i++) {
244+
if (!is_proper[i]) { continue; }
245+
225246
// construct interpolating polynomial coefficients
226247
p[0] = 1.0;
227248
for (size_t j = 1; j < nsrc + 1; j++) { p[j] = 0.0; }
228249
for (size_t m = 0; m < nsrc; m++) {
229-
if (m == i) { continue; }
250+
if ((!is_proper[m]) || (m == i)) { continue; }
230251

231252
// p_{m+1}(x) = (x - x_j) * p_m(x)
232253
p1[0] = 0.0;

tests/test_quadrature.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ TEST(NodesTest, UniformNodes)
222222
TEST(QuadratureTest, GaussLobattoNodes)
223223
{
224224
auto l3 = pfasst::compute_nodes<long double>(3, "gauss-lobatto");
225-
auto s3 = pfasst::compute_quadrature(l3, l3, 's');
225+
auto a3 = pfasst::augment_nodes(l3);
226+
auto s3 = pfasst::compute_quadrature(get<0>(a3), get<0>(a3), get<1>(a3), 's');
226227
const long double s3e[6] = { 0.20833333333333333,
227228
0.33333333333333333,
228229
-0.04166666666666666,
@@ -234,7 +235,8 @@ TEST(QuadratureTest, GaussLobattoNodes)
234235
EXPECT_THAT(s3.data(), testing::Pointwise(DoubleNear(), s3e));
235236

236237
auto l5 = pfasst::compute_nodes<long double>(5, "gauss-lobatto");
237-
auto s5 = pfasst::compute_quadrature(l5, l5, 's');
238+
auto a5 = pfasst::augment_nodes(l5);
239+
auto s5 = pfasst::compute_quadrature(get<0>(a5), get<0>(a5), get<1>(a5), 's');
238240
const long double s5e[] = { 0.067728432186156897969267419174073482,
239241
0.11974476934341168251615379970493965,
240242
-0.021735721866558113665511351745074292,
@@ -262,7 +264,8 @@ TEST(QuadratureTest, GaussLobattoNodes)
262264
TEST(QuadratureTest, ClenshawCurtisNodes)
263265
{
264266
auto c4 = pfasst::compute_nodes<long double>(4, "clenshaw-curtis");
265-
auto s4 = pfasst::compute_quadrature(c4, c4, 's');
267+
auto a4 = pfasst::augment_nodes(c4);
268+
auto s4 = pfasst::compute_quadrature(get<0>(a4), get<0>(a4), get<1>(a4), 's');
266269
const long double s4e[] = { 0.10243055555555555555555555555555556,
267270
0.16319444444444444444444444444444444,
268271
-0.024305555555555555555555555555555556,

0 commit comments

Comments
 (0)