Skip to content

Commit 5c772d9

Browse files
committed
examples: enable logging for autobuild example
1 parent 0444e4d commit 5c772d9

File tree

2 files changed

+75
-44
lines changed

2 files changed

+75
-44
lines changed

examples/advection_diffusion/serial_mlsdc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ using namespace std;
1010
#include <fftw3.h>
1111

1212
#include <pfasst.hpp>
13+
#include <pfasst/logging.hpp>
14+
#include <pfasst/config.hpp>
1315
#include <pfasst/mlsdc.hpp>
1416
#include <pfasst/encap/vector.hpp>
1517
using namespace pfasst::encap;

examples/advection_diffusion/serial_mlsdc_autobuild.cpp

Lines changed: 73 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ using namespace std;
1717
#include <fftw3.h>
1818

1919
#include <pfasst.hpp>
20+
#include <pfasst/logging.hpp>
21+
#include <pfasst/config.hpp>
2022
#include <pfasst/mlsdc.hpp>
2123
#include <pfasst/encap/automagic.hpp>
2224
#include <pfasst/encap/vector.hpp>
@@ -29,49 +31,76 @@ using pfasst::examples::advection_diffusion::AdvectionDiffusionSweeper;
2931
using pfasst::examples::advection_diffusion::SpectralTransfer1D;
3032

3133

32-
int main(int /*argc*/, char** /*argv*/)
34+
namespace pfasst
3335
{
34-
MLSDC<> mlsdc;
35-
36-
const size_t nsteps = 4;
37-
const double dt = 0.01;
38-
const size_t niters = 4;
39-
40-
vector<pair<size_t, pfasst::quadrature::QuadratureType>> nodes = {
41-
{ 3, pfasst::quadrature::QuadratureType::GaussLobatto },
42-
{ 5, pfasst::quadrature::QuadratureType::GaussLobatto }
43-
};
44-
45-
vector<size_t> ndofs = { 64, 128 };
46-
47-
/*
48-
* the 'build' function is called once for each level, and returns a
49-
* tuple containing a sweeper, encapsulation factory, and transfer
50-
* routines. in this case our builder is a lambda function that
51-
* captures the 'ndofs' variable from above.
52-
*/
53-
auto build_level = [ndofs](size_t level) {
54-
auto factory = make_shared<VectorFactory<double>>(ndofs[level]);
55-
auto sweeper = make_shared<AdvectionDiffusionSweeper<>>(ndofs[level]);
56-
auto transfer = make_shared<SpectralTransfer1D<>>();
57-
58-
return AutoBuildTuple<>(sweeper, transfer, factory);
59-
};
60-
61-
/*
62-
* the 'initial' function is called once for each level to set the
63-
* intial conditions.
64-
*/
65-
auto initial = [](shared_ptr<EncapSweeper<>> sweeper, shared_ptr<Encapsulation<>> q0) {
66-
auto ad = dynamic_pointer_cast<AdvectionDiffusionSweeper<>>(sweeper);
67-
assert(ad);
68-
ad->exact(q0, 0.0);
69-
};
70-
71-
auto_build(mlsdc, nodes, build_level);
72-
auto_setup(mlsdc, initial);
73-
mlsdc.set_duration(0.0, nsteps*dt, dt, niters);
74-
mlsdc.run();
75-
76-
fftw_cleanup();
36+
namespace examples
37+
{
38+
namespace advection_diffusion
39+
{
40+
tuple<error_map, residual_map> run_serial_mlsdc_autobuild()
41+
{
42+
MLSDC<> mlsdc;
43+
44+
const size_t nsteps = config::get_value<size_t>("num_steps", 4);
45+
const double dt = config::get_value<double>("delta_step", 0.01);
46+
const size_t niters = config::get_value<size_t>("num_iter", 4);
47+
48+
vector<pair<size_t, pfasst::quadrature::QuadratureType>> nodes = {
49+
{ 3, pfasst::quadrature::QuadratureType::GaussLobatto },
50+
{ 5, pfasst::quadrature::QuadratureType::GaussLobatto }
51+
};
52+
53+
vector<size_t> ndofs = { 64, 128 };
54+
55+
/*
56+
* the 'build' function is called once for each level, and returns a
57+
* tuple containing a sweeper, encapsulation factory, and transfer
58+
* routines. in this case our builder is a lambda function that
59+
* captures the 'ndofs' variable from above.
60+
*/
61+
auto build_level = [ndofs](size_t level) {
62+
auto factory = make_shared<VectorFactory<double>>(ndofs[level]);
63+
auto sweeper = make_shared<AdvectionDiffusionSweeper<>>(ndofs[level]);
64+
auto transfer = make_shared<SpectralTransfer1D<>>();
65+
66+
return AutoBuildTuple<>(sweeper, transfer, factory);
67+
};
68+
69+
/*
70+
* the 'initial' function is called once for each level to set the
71+
* intial conditions.
72+
*/
73+
auto initial = [](shared_ptr<EncapSweeper<>> sweeper, shared_ptr<Encapsulation<>> q0) {
74+
auto ad = dynamic_pointer_cast<AdvectionDiffusionSweeper<>>(sweeper);
75+
assert(ad);
76+
ad->exact(q0, 0.0);
77+
};
78+
79+
auto_build(mlsdc, nodes, build_level);
80+
auto_setup(mlsdc, initial);
81+
mlsdc.set_duration(0.0, nsteps*dt, dt, niters);
82+
mlsdc.run();
83+
84+
fftw_cleanup();
85+
86+
tuple<error_map, residual_map> rinfo;
87+
get<0>(rinfo) = mlsdc.get_finest<AdvectionDiffusionSweeper<>>()->get_errors();
88+
for (auto l = mlsdc.coarsest(); l <= mlsdc.finest(); ++l) {
89+
get<1>(rinfo).insert(pair<size_t, error_map>(l.level, l.current<AdvectionDiffusionSweeper<>>()->get_residuals()));
90+
}
91+
return rinfo;
92+
}
93+
} // ::pfasst::examples::advection_diffusion
94+
} // ::pfasst::examples
95+
} // ::pfasst
96+
97+
#ifndef PFASST_UNIT_TESTING
98+
int main(int argc, char** argv)
99+
{
100+
pfasst::examples::advection_diffusion::AdvectionDiffusionSweeper<>::enable_config_options();
101+
pfasst::init(argc, argv);
102+
pfasst::log::add_custom_logger("Advec");
103+
104+
pfasst::examples::advection_diffusion::run_serial_mlsdc_autobuild();
77105
}
106+
#endif

0 commit comments

Comments
 (0)