Skip to content

Commit 0b615ed

Browse files
committed
Replace boost::shared_ptr with std::shared_ptr. Ensure the rotation logic updates the output datastructures on chkp resume
1 parent c9ada05 commit 0b615ed

29 files changed

+1210
-1196
lines changed

docs/filterdev.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ station.
1919

2020
.. code:: cpp
2121
22-
void process(boost::shared_ptr<station> station);
22+
void process(std::shared_ptr<station> station);
2323
2424
init()
2525
~~~~~~~~~~

docs/moduledev.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ explicitly done by the module. The constructor specifies the paralle type: ``par
126126
...
127127
}
128128
129-
void run(mesh domain, boost::shared_ptr<global> global_param)
129+
void run(mesh domain, std::shared_ptr<global> global_param)
130130
{
131131
#pragma omp parallel for
132132
for (size_t i = 0; i < domain->size_faces(); i++)

src/core.cpp

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void core::config_modules(pt::ptree &value, const pt::ptree &config, std::vector
245245
SPDLOG_DEBUG("No config for {}", module_name);
246246
}
247247

248-
boost::shared_ptr<module_base> module = module_factory::create(module_name, cfg);
248+
std::shared_ptr<module_base> module = module_factory::create(module_name, cfg);
249249
//internal tracking of module initialization order
250250
module->IDnum = modnum;
251251

@@ -504,6 +504,51 @@ void core::config_checkpoint( pt::ptree& value)
504504
}
505505
}
506506
}
507+
508+
if (_checkpoint_opts.load_from_checkpoint && !_checkpoint_opts.ugrid_outputs.empty())
509+
{
510+
// Outputs are configured before we load checkpoint metadata, so apply ugrid state here.
511+
// Apply checkpoint ugrid rotation state now that outputs are configured.
512+
for (auto &out : _outputs)
513+
{
514+
if (out.mesh_output_formats != output_info::mesh_outputs::ugrid)
515+
{
516+
continue;
517+
}
518+
519+
const chkptOp::ugrid_output_state* match = nullptr;
520+
for (const auto &state : _checkpoint_opts.ugrid_outputs)
521+
{
522+
if (state.base_name == out.base_name)
523+
{
524+
match = &state;
525+
break;
526+
}
527+
}
528+
if (!match && _checkpoint_opts.ugrid_outputs.size() == 1)
529+
{
530+
match = &_checkpoint_opts.ugrid_outputs.front();
531+
}
532+
if (!match)
533+
{
534+
// Warn if the checkpoint metadata doesn't match the configured ugrid outputs.
535+
SPDLOG_WARN("No checkpoint ugrid state matches base_name={}", out.base_name);
536+
continue;
537+
}
538+
539+
if (!match->path.empty())
540+
{
541+
auto& writer = boost::get<boost::shared_ptr<ugrid_writer>>(out.writer);
542+
writer->set_store_path(match->path);
543+
SPDLOG_DEBUG("Resuming ugrid output from checkpoint file {}", match->path);
544+
}
545+
if (match->rotate_offset)
546+
{
547+
out.rotate_offset = match->rotate_offset;
548+
SPDLOG_DEBUG("Resuming ugrid rotation with offset {}", *match->rotate_offset);
549+
}
550+
}
551+
}
507552
}
508553
}
509554
void core::config_forcing(pt::ptree &value)
@@ -597,7 +642,7 @@ void core::config_forcing(pt::ptree &value)
597642
if(_use_netcdf)
598643
{
599644
std::string file = value.get<std::string>("file");
600-
std::map<std::string, boost::shared_ptr<filter_base> > netcdf_filters;
645+
std::map<std::string, std::shared_ptr<filter_base> > netcdf_filters;
601646
try
602647
{
603648
auto filter_section = value.get_child("filter");
@@ -607,7 +652,7 @@ void core::config_forcing(pt::ptree &value)
607652
auto filter_name = jtr.first.data();
608653
auto cfg = jtr.second;
609654

610-
boost::shared_ptr<filter_base> filter = filter_factory::create(filter_name,cfg);
655+
std::shared_ptr<filter_base> filter = filter_factory::create(filter_name,cfg);
611656
filter->init();
612657
netcdf_filters[filter_name] = filter;
613658
}
@@ -688,7 +733,7 @@ void core::config_forcing(pt::ptree &value)
688733
auto filter_name = jtr.first.data();
689734
auto cfg = jtr.second;
690735

691-
boost::shared_ptr<filter_base> filter = filter_factory::create(filter_name,cfg);
736+
std::shared_ptr<filter_base> filter = filter_factory::create(filter_name,cfg);
692737
filter->init();
693738

694739
//save this filter to run later
@@ -832,7 +877,7 @@ bool core::config_meshes( pt::ptree &value)
832877
{
833878
SPDLOG_DEBUG("Found meshes sections");
834879

835-
_mesh = boost::make_shared<triangulation>();
880+
_mesh = std::make_shared<triangulation>();
836881

837882
_mesh->_global = _global;
838883

@@ -1192,7 +1237,7 @@ void core::config_output(pt::ptree &value)
11921237
boost::filesystem::create_directories(f.parent_path());
11931238
out.fname = f.string();
11941239
out.mesh_output_formats = output_info::mesh_outputs::vtu;
1195-
out.writer = boost::make_shared<vtk_writer>(_mesh);
1240+
out.writer = std::make_shared<vtk_writer>(_mesh);
11961241
}
11971242
else
11981243
{
@@ -1216,15 +1261,15 @@ void core::config_output(pt::ptree &value)
12161261
out.mesh_output_formats = output_info::mesh_outputs::ugrid;
12171262
out.fname = ugrid_path.string();
12181263

1219-
out.writer = boost::make_shared<ugrid_writer>(
1264+
out.writer = std::make_shared<ugrid_writer>(
12201265
_mesh,
12211266
_global,
12221267
_mesh->write_param_to_output(),
12231268
out.fname,
12241269
use_zarr);
12251270

1226-
boost::get<boost::shared_ptr<ugrid_writer>>(out.writer)->compress = itr.second.get<bool>("compress", true);
1227-
boost::get<boost::shared_ptr<ugrid_writer>>(out.writer)->bitgroom = itr.second.get<bool>("bitgroom", true);
1271+
boost::get<std::shared_ptr<ugrid_writer>>(out.writer)->compress = itr.second.get<bool>("compress", true);
1272+
boost::get<std::shared_ptr<ugrid_writer>>(out.writer)->bitgroom = itr.second.get<bool>("bitgroom", true);
12281273

12291274
}
12301275

@@ -1239,7 +1284,7 @@ void core::config_output(pt::ptree &value)
12391284
out.write_ghost_neighbors = write_ghost;
12401285
if (out.mesh_output_formats == output_info::mesh_outputs::vtu)
12411286
{
1242-
boost::get<boost::shared_ptr<vtk_writer>>(out.writer)->set_write_ghost_neighbors(write_ghost);
1287+
boost::get<std::shared_ptr<vtk_writer>>(out.writer)->set_write_ghost_neighbors(write_ghost);
12431288
}
12441289

12451290
out.frequency = itr.second.get_optional<size_t>("frequency"); //defaults to every timestep
@@ -1284,37 +1329,6 @@ void core::config_output(pt::ptree &value)
12841329
->set_chunking_override(chunk_len_steps, chunk_target_mb);
12851330
}
12861331

1287-
if (_checkpoint_opts.load_from_checkpoint && out.mesh_output_formats == output_info::mesh_outputs::ugrid)
1288-
{
1289-
// Restore the output path and rotation offset captured in the checkpoint metadata.
1290-
const chkptOp::ugrid_output_state* match = nullptr;
1291-
for (const auto &state : _checkpoint_opts.ugrid_outputs)
1292-
{
1293-
if (state.base_name == out.base_name)
1294-
{
1295-
match = &state;
1296-
break;
1297-
}
1298-
}
1299-
if (!match && _checkpoint_opts.ugrid_outputs.size() == 1)
1300-
{
1301-
match = &_checkpoint_opts.ugrid_outputs.front();
1302-
}
1303-
if (match)
1304-
{
1305-
if (!match->path.empty())
1306-
{
1307-
auto& writer = boost::get<boost::shared_ptr<ugrid_writer>>(out.writer);
1308-
writer->set_store_path(match->path);
1309-
SPDLOG_DEBUG("Resuming ugrid output from checkpoint file {}", match->path);
1310-
}
1311-
if (match->rotate_offset)
1312-
{
1313-
out.rotate_offset = match->rotate_offset;
1314-
}
1315-
}
1316-
}
1317-
13181332
auto specific_datetime = itr.second.get_optional<std::string>("specific_datetime");
13191333
if(specific_datetime)
13201334
{
@@ -1538,7 +1552,7 @@ void core::init(int argc, char **argv)
15381552
SPDLOG_DEBUG("Logger initialized. Writing to cout and {}", log_name);
15391553

15401554

1541-
_global = boost::make_shared<global>();
1555+
_global = std::make_shared<global>();
15421556

15431557
// This needs to be set so that underflows in gsl math
15441558
// computations are not treated as errors. i.e.,
@@ -2567,7 +2581,7 @@ void core::run()
25672581
pt::ptree entry;
25682582
entry.put("base_name", out.base_name);
25692583

2570-
auto& writer = boost::get<boost::shared_ptr<ugrid_writer>>(out.writer);
2584+
auto& writer = boost::get<std::shared_ptr<ugrid_writer>>(out.writer);
25712585
entry.put("path", writer->store_path());
25722586

25732587
if (out.rotate_frequency)
@@ -2625,7 +2639,7 @@ void core::run()
26252639
{
26262640
std::string base_name = itr.fname + std::to_string(_global->posix_time_int());
26272641
boost::filesystem::path p(base_name);
2628-
auto& writer = boost::get<boost::shared_ptr<vtk_writer>>(itr.writer);
2642+
auto& writer = boost::get<std::shared_ptr<vtk_writer>>(itr.writer);
26292643
writer->set_write_ghost_neighbors(itr.write_ghost_neighbors);
26302644
writer->update_data(output);
26312645

@@ -2656,7 +2670,7 @@ void core::run()
26562670
// first, check if we need a new ugrid file
26572671
bool new_ugrid = itr.should_rotate(max_ts, current_ts, _global->_current_date);
26582672

2659-
auto& writer = boost::get<boost::shared_ptr<ugrid_writer>>(itr.writer);
2673+
auto& writer = boost::get<std::shared_ptr<ugrid_writer>>(itr.writer);
26602674
if (new_ugrid)
26612675
{
26622676
auto rotated_path = [&]() {
@@ -2775,7 +2789,7 @@ void core::run()
27752789

27762790
if (itr.mesh_output_formats == output_info::mesh_outputs::ugrid)
27772791
{
2778-
boost::get<boost::shared_ptr<ugrid_writer>>(itr.writer)->close_ugrid();
2792+
boost::get<std::shared_ptr<ugrid_writer>>(itr.writer)->close_ugrid();
27792793
}
27802794
}
27812795

src/core.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
#include <boost/graph/graph_traits.hpp>
6060
#include <boost/graph/graphviz.hpp>
6161
#include <boost/graph/topological_sort.hpp>
62-
#include <boost/make_shared.hpp>
62+
#include <memory>
6363
#include <boost/program_options.hpp>
6464
#include <boost/property_tree/json_parser.hpp>
6565
#include <boost/property_tree/ptree.hpp>
6666
#include <boost/property_tree/xml_parser.hpp>
6767
#include <boost/regex.hpp>
68-
#include <boost/shared_ptr.hpp>
68+
#include <memory>
6969
#include <boost/tokenizer.hpp>
7070
#include <boost/tuple/tuple.hpp>
7171
namespace pt = boost::property_tree;
@@ -298,7 +298,7 @@ class core
298298
std::vector< std::pair<module,size_t> > _modules;
299299
std::vector< std::vector < module> > _chunked_modules;
300300
std::vector< std::pair<std::string,std::string> > _overrides;
301-
boost::shared_ptr<global> _global;
301+
std::shared_ptr<global> _global;
302302

303303
bool _use_netcdf; // flag if we are using netcdf. If we are, it enables incremental reads of the netcdf file for speed.
304304
std::shared_ptr<metdata> _metdata; //met data loader, shared for use with boost::bind

src/factory.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
#include <vector>
2828
#include <functional>
2929

30-
#include <boost/shared_ptr.hpp>
30+
#include <memory>
3131

3232
#include "exception.hpp"
3333

3434
template <class Interface, class... ConstructorArgs>
3535
class factory {
3636
public:
3737
// Only ever hand out unique pointers
38-
static boost::shared_ptr<Interface> create(std::string name, ConstructorArgs... args);
38+
static std::shared_ptr<Interface> create(std::string name, ConstructorArgs... args);
3939
// Actual registration function
4040
static void register_factory_function(std::string name,
4141
std::function<Interface*(ConstructorArgs...)> implementation_constructor_function);
@@ -62,7 +62,7 @@ class registration_helper {
6262
};
6363

6464
template <class Interface, class... ConstructorArgs>
65-
boost::shared_ptr<Interface> factory<Interface,ConstructorArgs...>::create(std::string name, ConstructorArgs... args)
65+
std::shared_ptr<Interface> factory<Interface,ConstructorArgs...>::create(std::string name, ConstructorArgs... args)
6666
{
6767
Interface * instance = nullptr;
6868

@@ -75,7 +75,7 @@ boost::shared_ptr<Interface> factory<Interface,ConstructorArgs...>::create(std::
7575
if(instance == nullptr) {
7676
CHM_THROW_EXCEPTION(module_not_found, "Requested module not found in registry: [" + name +"]");
7777
}
78-
return boost::shared_ptr<Interface>(instance);
78+
return std::shared_ptr<Interface>(instance);
7979
}
8080

8181
template <class Interface, class... ConstructorArgs>

src/filters/filter_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#pragma once
2424

2525
#include <string>
26-
#include <boost/shared_ptr.hpp>
26+
#include <memory>
2727
#include <boost/property_tree/ptree.hpp>
2828
#include <boost/property_tree/json_parser.hpp>
2929

src/interpolation/interpolation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ void interpolation::init(interp_alg ia, size_t size,std::map<std::string,std::st
3434

3535
if (ia == interp_alg::tpspline)
3636
{
37-
base = boost::make_shared<thin_plate_spline>(size,config);
37+
base = std::make_shared<thin_plate_spline>(size,config);
3838
}
3939
else if(ia == interp_alg::idw)
4040
{
41-
base = boost::make_shared<inv_dist>();
41+
base = std::make_shared<inv_dist>();
4242
}
4343
else if(ia == interp_alg::nearest_sta)
4444
{
45-
base = boost::make_shared<nearest>();
45+
base = std::make_shared<nearest>();
4646
}
4747
else
4848
{

src/interpolation/interpolation.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
#include <vector>
3131
#include <boost/tuple/tuple.hpp>
32-
#include <boost/shared_ptr.hpp>
33-
#include <boost/make_shared.hpp>
32+
#include <memory>
33+
3434

3535
#include "logger.hpp"
3636
enum interp_alg
@@ -56,7 +56,7 @@ class interpolation
5656
void init(interp_alg ia, size_t size=0, std::map<std::string,std::string> config = std::map<std::string,std::string>());
5757

5858
double operator()(std::vector< boost::tuple<double,double,double> >& sample_points, boost::tuple<double,double,double>& query_point);
59-
boost::shared_ptr<interp_base> base;
59+
std::shared_ptr<interp_base> base;
6060
private:
6161

6262
size_t size;

src/mesh/triangulation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ void triangulation::_build_dDtree()
10671067
}
10681068

10691069
//make the search tree
1070-
dD_tree = boost::make_shared<Tree>(boost::make_zip_iterator(boost::make_tuple( center_points.begin(),_faces.begin() )),
1070+
dD_tree = std::make_shared<Tree>(boost::make_zip_iterator(boost::make_tuple( center_points.begin(),_faces.begin() )),
10711071
boost::make_zip_iterator(boost::make_tuple( center_points.end(), _faces.end() ) )
10721072
);
10731073
}
@@ -2491,9 +2491,9 @@ double triangulation::min_z()
24912491
return _min_z;
24922492
}
24932493

2494-
boost::shared_ptr<segmented_AABB> triangulation::AABB(size_t rows, size_t cols)
2494+
std::shared_ptr<segmented_AABB> triangulation::AABB(size_t rows, size_t cols)
24952495
{
2496-
boost::shared_ptr<segmented_AABB> AABB = boost::make_shared<segmented_AABB>();
2496+
std::shared_ptr<segmented_AABB> AABB = std::make_shared<segmented_AABB>();
24972497
AABB->make(this,rows,cols);
24982498
return AABB;
24992499

0 commit comments

Comments
 (0)