Skip to content

Commit 02b2740

Browse files
authored
More bc (#767)
* moved the BC construction to the term_md
1 parent ea771e1 commit 02b2740

23 files changed

+993
-1335
lines changed

python/asgardrun.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ exename=$1
3131

3232
shift
3333

34-
echo $1
35-
3634
./$exename $@ -of _plt.h5
3735

3836
@Python_EXECUTABLE@ -m asgard _plt.h5 $plt_opts

src/asgard_boundary_conditions.cpp

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -198,181 +198,6 @@ std::array<unscaled_bc_parts<P>, 2> make_unscaled_bc_parts(
198198
return {left_bc_parts, right_bc_parts};
199199
}
200200

201-
// template<typename P>
202-
// bc_manager<P>::bc_manager(PDE<P> const &pde, elements::table const &table,
203-
// hierarchy_manipulator<P> const &hier, coefficient_matrices<P> &cmats,
204-
// connection_patterns const &conns,
205-
// int const start_element, int const stop_element, P const t_init)
206-
// : num_dims(pde.num_dims()), degree(hier.degree())
207-
// {
208-
// tools::time_event timing("make unscaled bc");
209-
// expect(start_element >= 0);
210-
// expect(stop_element < table.size());
211-
// expect(stop_element >= start_element);
212-
//
213-
// // count the number of boundary condition vectors that we will need
214-
// // the first vector (if present) is left unscaled, i.e., assumed 1
215-
// // the others will use corresponding functions from the p-terms
216-
// // so, we first count the number of basis that we will need
217-
// int num_pt = 0;
218-
//
219-
// for (auto const &term : pde.get_terms()) {
220-
// for (int d : indexof<int>(pde.num_dims())) {
221-
// for (auto const &pt : term[d].get_partial_terms()) {
222-
// if (not pt.left_bc_zero())
223-
// {
224-
// if (pt.left_bc_time_func())
225-
// num_pt++;
226-
// else
227-
// num_const = 1;
228-
// }
229-
// if (not pt.right_bc_zero())
230-
// {
231-
// if (pt.right_bc_time_func())
232-
// num_pt++;
233-
// else
234-
// num_const = 1;
235-
// }
236-
// }
237-
// }
238-
// }
239-
//
240-
// std::vector<dimension<P>> const &dimensions = pde.get_dimensions();
241-
// int const degree = hier.degree();
242-
//
243-
// time_funcs.reserve(num_pt);
244-
//
245-
// int64_t const vec_size = (stop_element - start_element + 1) * hier.block_size();
246-
// unscaled_bc.resize(vec_size * (num_pt + num_const));
247-
//
248-
// std::vector<P> temp;
249-
//
250-
// P *unc = unscaled_bc.data();
251-
// if (num_const > 0) {
252-
// unc += vec_size;
253-
// temp.resize(vec_size);
254-
// }
255-
//
256-
// for (int t : indexof<int>(pde.num_terms()))
257-
// {
258-
// std::vector<term<P>> const &term_md = pde.get_terms()[t];
259-
//
260-
// for (int d : indexof<int>(pde.num_dims()))
261-
// {
262-
// dimension<P> const &dim = dimensions[d];
263-
// term<P> const &term = term_md[d];
264-
//
265-
// std::vector<partial_term<P>> const &pterms = term.get_partial_terms();
266-
// for (int pt : indexof<int>(pterms.size()))
267-
// {
268-
// auto const &ptt = pterms[pt];
269-
//
270-
// if (not ptt.left_bc_zero())
271-
// {
272-
// std::vector<P> trace_bc = compute_left_boundary_condition(
273-
// ptt.g_func(), ptt.dv_func(), t_init, dim,
274-
// ptt.left_bc_funcs()[d]);
275-
//
276-
// std::vector<std::vector<P>> p_term_left_bcs = generate_partial_bcs(
277-
// dimensions, d, ptt.left_bc_funcs(), hier, cmats,
278-
// conns, t_init, term_md, term.get_partial_terms(), t, pt, std::move(trace_bc));
279-
//
280-
// if (ptt.left_bc_time_func())
281-
// num_pt++;
282-
// else
283-
// num_const = 1;
284-
// }
285-
// if (not ptt.right_bc_zero())
286-
// {
287-
// if (ptt.right_bc_time_func())
288-
// num_pt++;
289-
// else
290-
// num_const = 1;
291-
// }
292-
// }
293-
// }
294-
// }
295-
//
296-
//
297-
//
298-
// unscaled_bc_parts<P> left_bc_parts;
299-
// unscaled_bc_parts<P> right_bc_parts;
300-
//
301-
// term_set<P> const &terms_vec_vec = pde.get_terms();
302-
//
303-
// int const num_terms = static_cast<int>(terms_vec_vec.size());
304-
// int const num_dims = pde.num_dims();
305-
//
306-
//
307-
// //int const degree = dimensions.front().get_degree();
308-
//
309-
// for (int t : indexof<int>(num_terms))
310-
// {
311-
// std::vector<term<P>> const &term_md = terms_vec_vec[t];
312-
//
313-
// std::vector<std::vector<std::vector<P>>> left_dim_pvecs;
314-
// std::vector<std::vector<std::vector<P>>> right_dim_pvecs;
315-
//
316-
// for (int d : indexof<int>(num_dims))
317-
// {
318-
// dimension<P> const &dim = dimensions[d];
319-
//
320-
// term<P> const &term = term_md[d];
321-
//
322-
// std::vector<std::vector<P>> left_pvecs;
323-
// std::vector<std::vector<P>> right_pvecs;
324-
//
325-
// std::vector<partial_term<P>> const &pterms = term.get_partial_terms();
326-
// for (int pt : indexof<int>(pterms.size()))
327-
// {
328-
// partial_term<P> const &pterm = pterms[pt];
329-
//
330-
// if (not pterm.left_bc_zero())
331-
// {
332-
// std::vector<P> trace_bc = compute_left_boundary_condition(
333-
// pterm.g_func(), pterm.dv_func(), t_init, dim,
334-
// pterm.left_bc_funcs()[d]);
335-
//
336-
// std::vector<std::vector<P>> p_term_left_bcs = generate_partial_bcs(
337-
// dimensions, d, pterm.left_bc_funcs(), hier, cmats,
338-
// conns, t_init, term_md, pterms, t, pt, std::move(trace_bc));
339-
//
340-
// // std::vector<P> combined =
341-
// // combine_dimensions(degree, table, start_element,
342-
// // stop_element, p_term_left_bcs);
343-
// //
344-
// // left_pvecs.emplace_back(std::move(combined));
345-
// }
346-
//
347-
// if (not pterm.right_bc_zero())
348-
// {
349-
// std::vector<P> trace_bc = compute_right_boundary_condition(
350-
// pterm.g_func(), pterm.dv_func(), t_init, dim,
351-
// pterm.right_bc_funcs()[d]);
352-
//
353-
// std::vector<std::vector<P>> p_term_right_bcs = generate_partial_bcs(
354-
// dimensions, d, pterm.right_bc_funcs(), hier, cmats,
355-
// conns, t_init, term_md, pterms, t, pt, std::move(trace_bc));
356-
//
357-
// // std::vector<P> combined =
358-
// // combine_dimensions(degree, table, start_element,
359-
// // stop_element, p_term_right_bcs);
360-
// //
361-
// // right_pvecs.emplace_back(std::move(combined));
362-
// }
363-
// }
364-
//
365-
// left_dim_pvecs.emplace_back(std::move(left_pvecs));
366-
// right_dim_pvecs.emplace_back(std::move(right_pvecs));
367-
// }
368-
//
369-
// left_bc_parts.emplace_back(std::move(left_dim_pvecs));
370-
// right_bc_parts.emplace_back(std::move(right_dim_pvecs));
371-
// }
372-
//
373-
// //return {left_bc_parts, right_bc_parts};
374-
// }
375-
376201
template<typename P>
377202
std::vector<P> generate_scaled_bc(unscaled_bc_parts<P> const &left_bc_parts,
378203
unscaled_bc_parts<P> const &right_bc_parts,
@@ -528,8 +353,6 @@ compute_right_boundary_condition(g_func_type<P> g_func, g_func_type<P> dv_func,
528353

529354
/* explicit instantiations */
530355
#ifdef ASGARD_ENABLE_DOUBLE
531-
template class bc_manager<double>;
532-
533356
template std::array<unscaled_bc_parts<double>, 2> make_unscaled_bc_parts(
534357
PDE<double> const &pde, elements::table const &table,
535358
hierarchy_manipulator<double> const &hier, coefficient_matrices<double> &cmats,
@@ -550,8 +373,6 @@ boundary_conditions::compute_right_boundary_condition(
550373
#endif
551374

552375
#ifdef ASGARD_ENABLE_FLOAT
553-
template class bc_manager<float>;
554-
555376
template std::array<unscaled_bc_parts<float>, 2>
556377
boundary_conditions::make_unscaled_bc_parts(
557378
PDE<float> const &pde, elements::table const &table,

src/asgard_boundary_conditions.hpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,6 @@ template<typename P>
88
using unscaled_bc_parts =
99
std::vector<std::vector<std::vector<std::vector<P>>>>;
1010

11-
template<typename P>
12-
class bc_manager {
13-
public:
14-
// bc_manager(PDE<P> const &pde, elements::table const &table,
15-
// hierarchy_manipulator<P> const &hier, coefficient_matrices<P> &cmats,
16-
// connection_patterns const &conns,
17-
// int const start_element, int const stop_element, P const t_init = 0);
18-
19-
private:
20-
// struct partial_bc_data
21-
// {
22-
// int dim = 0;
23-
// int id = -1;
24-
// scalar_func<P> fleft;
25-
// scalar_func<P> fright;
26-
// std::vector<P> vals;
27-
// };
28-
//
29-
// // no product, maybe add it later at the level of terms_md
30-
// // use either fixed coefficients or recompute for each t
31-
//
32-
// // useful local vars
33-
// int num_dims = 0;
34-
// int degree = 0;
35-
//
36-
// std::vector<P> raw_bc;
37-
// std::vector<partial_bc_data> bcs;
38-
};
39-
4011
// generate all boundary conditions
4112
// add the new transformer here and the coefficient matrices
4213
template<typename P>

src/asgard_coefficients_mats.hpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void gen_tri_cmat(legendre_basis<P> const &basis, P xleft, P xright, int level,
2121
sfixed_func1d<P> const &rhs, P const rhs_const, flux_type flux,
2222
boundary_type boundary, rhs_raw_data<P> &rhs_raw, block_tri_matrix<P> &coeff)
2323
{
24-
static_assert(optype != operation_type::mass
24+
static_assert(optype != operation_type::volume
2525
and optype != operation_type::identity
2626
and optype != operation_type::chain,
2727
"identity, mass and chain operations yield diagonal matrices, "
@@ -33,19 +33,19 @@ void gen_tri_cmat(legendre_basis<P> const &basis, P xleft, P xright, int level,
3333
"cannot use spatially dependant penalty term");
3434

3535
if constexpr (optype == operation_type::grad) {
36-
// the grad operation flips the dirichlet and free boundayr conditions
36+
// the grad operation flips the fixed and free boundary conditions
3737
switch (boundary) {
38-
case boundary_type::dirichlet:
39-
boundary = boundary_type::free;
38+
case boundary_type::bothsides:
39+
boundary = boundary_type::none;
4040
break;
41-
case boundary_type::free:
42-
boundary = boundary_type::dirichlet;
41+
case boundary_type::none:
42+
boundary = boundary_type::bothsides;
4343
break;
44-
case boundary_type::left_free:
45-
boundary = boundary_type::right_free;
44+
case boundary_type::right:
45+
boundary = boundary_type::left;
4646
break;
47-
case boundary_type::right_free:
48-
boundary = boundary_type::left_free;
47+
case boundary_type::left:
48+
boundary = boundary_type::right;
4949
break;
5050
default: // periodic, do nothing since it is symmetric anyway
5151
break;
@@ -174,8 +174,8 @@ void gen_tri_cmat(legendre_basis<P> const &basis, P xleft, P xright, int level,
174174
if constexpr (optype == operation_type::penalty)
175175
{
176176
switch (boundary) {
177-
case boundary_type::dirichlet:
178-
case boundary_type::right_free: // dirichelt on the left
177+
case boundary_type::bothsides:
178+
case boundary_type::left: // dirichelt on the left
179179
smmat::axpy(nblock, escale * rhs_const, basis.to_left, coeff.diag(0));
180180
break;
181181
case boundary_type::periodic:
@@ -195,8 +195,8 @@ void gen_tri_cmat(legendre_basis<P> const &basis, P xleft, P xright, int level,
195195
}
196196

197197
switch (boundary) {
198-
case boundary_type::dirichlet:
199-
case boundary_type::left_free: // dirichelt on the right
198+
case boundary_type::bothsides:
199+
case boundary_type::right: // dirichelt on the right
200200
smmat::axpy(nblock, escale * rhs_const, basis.to_right, coeff.diag(rmost));
201201
break;
202202
case boundary_type::periodic:
@@ -211,8 +211,8 @@ void gen_tri_cmat(legendre_basis<P> const &basis, P xleft, P xright, int level,
211211
{
212212
// look at the left-boundary
213213
switch (boundary) {
214-
case boundary_type::free:
215-
case boundary_type::left_free: // free on the left
214+
case boundary_type::none:
215+
case boundary_type::right: // free on the left
216216
smmat::axpy(nblock, -escale * ((rtype == rhs_type::is_const) ? rhs_const : rhs_vals[0][0]), basis.to_left, coeff.diag(0));
217217
break;
218218
case boundary_type::periodic: {
@@ -242,8 +242,8 @@ void gen_tri_cmat(legendre_basis<P> const &basis, P xleft, P xright, int level,
242242

243243
// look at the right-boundary
244244
switch (boundary) {
245-
case boundary_type::free:
246-
case boundary_type::right_free: // free on the right
245+
case boundary_type::none:
246+
case boundary_type::left: // free on the right
247247
smmat::axpy(nblock, escale * ((rtype == rhs_type::is_const) ? rhs_const : rhs_raw.vals.back()), basis.to_right, coeff.diag(rmost));
248248
break;
249249
case boundary_type::periodic: {
@@ -278,7 +278,7 @@ template<typename P, operation_type optype>
278278
void gen_diag_cmat(legendre_basis<P> const &basis, int level,
279279
P const rhs_const, block_diag_matrix<P> &coeff)
280280
{
281-
static_assert(optype == operation_type::mass,
281+
static_assert(optype == operation_type::volume,
282282
"only mass matrices should be used to create mass terms");
283283

284284
int const num_cells = fm::ipow2(level);
@@ -331,7 +331,7 @@ void gen_diag_cmat(legendre_basis<P> const &basis, P xleft, P xright, int level,
331331
block_diag_matrix<P> &coeff)
332332
{
333333
ignore(rhs_f);
334-
static_assert(optype == operation_type::mass,
334+
static_assert(optype == operation_type::volume,
335335
"only mass matrices should be used to create mass terms");
336336

337337
int const num_cells = fm::ipow2(level);
@@ -351,7 +351,6 @@ void gen_diag_cmat(legendre_basis<P> const &basis, P xleft, P xright, int level,
351351
#pragma omp parallel for
352352
for (int i = 0; i < num_cells; i++) {
353353
P const l = xleft + i * dx; // left edge of cell i
354-
rhs_pnts[i * basis.num_quad] = l;
355354
for (int k = 0; k < basis.num_quad; k++)
356355
rhs_pnts[i * basis.num_quad + k] = (0.5 * basis.qp[k] + 0.5) * dx + l;
357356
}

src/asgard_coefficients_mats_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ TEMPLATE_TEST_CASE("simple div", "[div]", test_precs)
129129
}
130130

131131
gen_tri_cmat<P, operation_type::div, rhs_type::is_const>(
132-
basis, 0, 1, level, nullptr, 1, flux_type::central, boundary_type::free, rhs_raw, mat);
132+
basis, 0, 1, level, nullptr, 1, flux_type::central, boundary_type::none, rhs_raw, mat);
133133

134134
std::vector<P> const ref = {0, -4, 4, -4, 0, 4, -4, 0, 4, -4, 0, 4, -4, 0, 4,
135135
-4, 0, 4, -4, 0, 4, -4, 4, 0};
@@ -153,7 +153,7 @@ TEMPLATE_TEST_CASE("simple mass", "[mass]", test_precs)
153153

154154
block_diag_matrix<P> mat;
155155

156-
gen_diag_cmat<P, operation_type::mass>(basis, level, 1, mat);
156+
gen_diag_cmat<P, operation_type::volume>(basis, level, 1, mat);
157157

158158
for (int i = 0; i < 8; i++) {
159159
std::vector<P> ref = {1, 0, 0, 0, 1, 0, 0, 0, 1};
@@ -167,7 +167,7 @@ TEMPLATE_TEST_CASE("simple mass", "[mass]", test_precs)
167167
fx[i] = -3.5;
168168
};
169169

170-
gen_diag_cmat<P, operation_type::mass>(
170+
gen_diag_cmat<P, operation_type::volume>(
171171
basis, 0, 1, level, cc, nullptr, mat);
172172

173173
for (int i = 0; i < 8; i++) {

src/asgard_dimension.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class separable_func
353353
std::copy(fdomain.begin(), fdomain.end(), consts_.begin());
354354
}
355355
//! set a function that is constant throughout the domain but has a time component
356-
separable_func(std::vector<P> fdomain)
356+
separable_func(std::vector<P> const &fdomain)
357357
: ignores_time_(true)
358358
{
359359
expect(static_cast<int>(fdomain.size()) <= max_num_dimensions);

0 commit comments

Comments
 (0)