Skip to content

Commit 796104f

Browse files
committed
Add CPO serialization.
1 parent 25755ff commit 796104f

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

include/aspect/postprocess/crystal_preferred_orientation.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ namespace aspect
7777
std::list<std::string>
7878
required_other_postprocessors () const override;
7979

80+
/**
81+
* Save the state of this object.
82+
*/
83+
void save (std::map<std::string, std::string> &status_strings) const override;
84+
85+
/**
86+
* Restore the state of the object.
87+
*/
88+
void load (const std::map<std::string, std::string> &status_strings) override;
89+
90+
/**
91+
* Serialize the contents of this class as far as they are not read
92+
* from input parameter files.
93+
*/
94+
template <class Archive>
95+
void serialize (Archive &ar, const unsigned int version);
96+
8097
/**
8198
* Declare the parameters this class takes through input files.
8299
*/

source/postprocess/crystal_preferred_orientation.cc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,72 @@ namespace aspect
602602
return Output::EulerAngles;
603603
return Output::not_found;
604604
}
605+
template <int dim>
606+
template <class Archive>
607+
void CrystalPreferredOrientation<dim>::serialize (Archive &ar, const unsigned int)
608+
{
609+
ar &last_output_time
610+
& output_file_number
611+
& times_and_pvtu_file_names
612+
& output_file_names_by_timestep
613+
& xdmf_entries
614+
;
615+
}
616+
617+
618+
template <int dim>
619+
void
620+
CrystalPreferredOrientation<dim>::save (std::map<std::string, std::string> &status_strings) const
621+
{
622+
for (unsigned int particle_manager = 0; particle_manager < this->n_particle_managers(); ++particle_manager)
623+
{
624+
std::string particles_output_base_name = "Particles";
625+
if (particle_manager > 0)
626+
{
627+
particles_output_base_name += "-" + Utilities::int_to_string(particle_manager+1);
628+
}
629+
630+
// Serialize into a stringstream. Put the following into a code
631+
// block of its own to ensure the destruction of the 'oa'
632+
// archive triggers a flush() on the stringstream so we can
633+
// query the completed string below.
634+
std::ostringstream os;
635+
{
636+
aspect::oarchive oa (os);
637+
638+
this->get_particle_manager(particle_manager).save(os);
639+
oa << (*this);
640+
}
605641

642+
status_strings[particles_output_base_name] = os.str();
643+
}
644+
}
645+
646+
647+
template <int dim>
648+
void
649+
CrystalPreferredOrientation<dim>::load (const std::map<std::string, std::string> &status_strings)
650+
{
651+
for (unsigned int particle_manager = 0; particle_manager < this->n_particle_managers(); ++particle_manager)
652+
{
653+
std::string particles_output_base_name = "Particles";
654+
if (particle_manager > 0)
655+
{
656+
particles_output_base_name += "-" + Utilities::int_to_string(particle_manager+1);
657+
}
658+
// see if something was saved
659+
if (status_strings.find(particles_output_base_name) != status_strings.end())
660+
{
661+
std::istringstream is (status_strings.find(particles_output_base_name)->second);
662+
aspect::iarchive ia (is);
663+
664+
// Load the particle manager
665+
this->get_particle_manager(particle_manager).load(is);
666+
667+
ia >> (*this);
668+
}
669+
}
670+
}
606671

607672

608673
template <int dim>

0 commit comments

Comments
 (0)