From eac3b6f5592423d8be403f7223caad41f9dc6292 Mon Sep 17 00:00:00 2001 From: wolf Date: Mon, 27 Nov 2000 09:14:48 +0000 Subject: [PATCH] Add memory_consumption functions to all remaining classes in /numerics. git-svn-id: https://svn.dealii.org/trunk@3503 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/numerics/data_out.h | 23 +++- .../deal.II/include/numerics/data_out_stack.h | 16 ++- deal.II/deal.II/include/numerics/histogram.h | 14 +++ .../include/numerics/solution_transfer.h | 12 +- .../deal.II/include/numerics/time_dependent.h | 43 +++++++- deal.II/deal.II/source/numerics/data_out.cc | 29 +++++ .../deal.II/source/numerics/data_out_stack.cc | 29 +++++ deal.II/deal.II/source/numerics/histogram.cc | 25 +++++ .../source/numerics/solution_transfer.cc | 26 +++++ .../deal.II/source/numerics/time_dependent.cc | 104 +++++++++++++++--- 10 files changed, 301 insertions(+), 20 deletions(-) diff --git a/deal.II/deal.II/include/numerics/data_out.h b/deal.II/deal.II/include/numerics/data_out.h index b067e5754a..cbb9b6c36b 100644 --- a/deal.II/deal.II/include/numerics/data_out.h +++ b/deal.II/deal.II/include/numerics/data_out.h @@ -15,6 +15,7 @@ #include +#include #include @@ -302,6 +303,13 @@ class DataOut_DoFData : public DataOutInterface */ virtual void clear (); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Exception */ @@ -351,9 +359,20 @@ class DataOut_DoFData : public DataOutInterface */ DataEntry (const Vector *data = 0, const vector &names = vector()); + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; /** - * Pointer to the data vector. + * Pointer to the data + * vector. Note that + * ownership of the vector + * pointed to remains with + * the caller of this class. */ const Vector *data; @@ -373,7 +392,7 @@ class DataOut_DoFData : public DataOutInterface /** * Pointer to the dof handler object. */ - const DoFHandler *dofs; + SmartPointer > dofs; /** * List of data elements with vectors of diff --git a/deal.II/deal.II/include/numerics/data_out_stack.h b/deal.II/deal.II/include/numerics/data_out_stack.h index b76d66bd99..a8c5b879f5 100644 --- a/deal.II/deal.II/include/numerics/data_out_stack.h +++ b/deal.II/deal.II/include/numerics/data_out_stack.h @@ -271,7 +271,14 @@ class DataOutStack : public DataOutInterface * in this object. */ void clear (); - + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Exception */ @@ -374,6 +381,13 @@ class DataOutStack : public DataOutInterface * within each such data set. */ vector names; + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this object. + */ + unsigned int memory_consumption () const; }; /** diff --git a/deal.II/deal.II/include/numerics/histogram.h b/deal.II/deal.II/include/numerics/histogram.h index 093588ae79..6fbbf38342 100644 --- a/deal.II/deal.II/include/numerics/histogram.h +++ b/deal.II/deal.II/include/numerics/histogram.h @@ -149,6 +149,13 @@ class Histogram */ static IntervalSpacing parse_interval_spacing (const string &name); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Exception. */ @@ -191,6 +198,13 @@ class Histogram Interval (const double left_point, const double right_point); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Left bound of the interval. */ diff --git a/deal.II/deal.II/include/numerics/solution_transfer.h b/deal.II/deal.II/include/numerics/solution_transfer.h index 4aa3240009..90657955f0 100644 --- a/deal.II/deal.II/include/numerics/solution_transfer.h +++ b/deal.II/deal.II/include/numerics/solution_transfer.h @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -281,6 +282,13 @@ class SolutionTransfer void interpolate (const Vector &in, Vector &out) const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Exception */ @@ -325,7 +333,7 @@ class SolutionTransfer * Pointer to the degree of freedom handler * to work with. */ - const DoFHandler *dof_handler; + SmartPointer > dof_handler; /** * Stores the number of DoFs before the @@ -383,6 +391,8 @@ class SolutionTransfer * 'multiplied' by this structure. */ struct Pointerstruct { + unsigned int memory_consumption () const; + vector *indices_ptr; vector > *dof_values_ptr; }; diff --git a/deal.II/deal.II/include/numerics/time_dependent.h b/deal.II/deal.II/include/numerics/time_dependent.h index 49d5054697..ca343f4525 100644 --- a/deal.II/deal.II/include/numerics/time_dependent.h +++ b/deal.II/deal.II/include/numerics/time_dependent.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -671,6 +672,13 @@ class TimeDependent */ virtual void end_sweep (const unsigned int n_threads = 1); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Exception. */ @@ -974,6 +982,21 @@ class TimeStepBase : public Subscriptor */ double get_forward_timestep () const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + * + * You will want to overload + * this function in derived + * classes to compute the + * amount memory used by the + * derived class, and add the + * result of this function to + * your result. + */ + virtual unsigned int memory_consumption () const; + /** * Exception */ @@ -1308,6 +1331,21 @@ class TimeStepBase_Tria : public TimeStepBase */ void save_refine_flags (); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + * + * You will want to overload + * this function in derived + * classes to compute the + * amount memory used by the + * derived class, and add the + * result of this function to + * your result. + */ + virtual unsigned int memory_consumption () const; + /** * Exception */ @@ -1338,8 +1376,9 @@ class TimeStepBase_Tria : public TimeStepBase * is set through the * constructor; ownership remains * with the owner of this - * management object. */ - const Triangulation &coarse_grid; + * management object. + */ + SmartPointer > coarse_grid; /** * Some flags about how this time level diff --git a/deal.II/deal.II/source/numerics/data_out.cc b/deal.II/deal.II/source/numerics/data_out.cc index 6db618835d..2efc611348 100644 --- a/deal.II/deal.II/source/numerics/data_out.cc +++ b/deal.II/deal.II/source/numerics/data_out.cc @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -28,6 +29,7 @@ #include + template DataOut_DoFData::DataEntry:: DataEntry (const Vector *data, @@ -38,6 +40,20 @@ DataEntry (const Vector *data, +template +unsigned int +DataOut_DoFData:: +DataEntry::memory_consumption () const +{ + return (sizeof (data) + + MemoryConsumption::memory_consumption (names) + + MemoryConsumption::memory_consumption (units)); +}; + + + + + template DataOut_DoFData::DataOut_DoFData () : dofs(0) @@ -229,6 +245,19 @@ DataOut_DoFData::get_patches () const +template +unsigned int +DataOut_DoFData::memory_consumption () const +{ + return (DataOutInterface::memory_consumption () + + MemoryConsumption::memory_consumption (dofs) + + MemoryConsumption::memory_consumption (dof_data) + + MemoryConsumption::memory_consumption (cell_data) + + MemoryConsumption::memory_consumption (patches)); +}; + + + /* ---------------------------------------------------------------------- */ diff --git a/deal.II/deal.II/source/numerics/data_out_stack.cc b/deal.II/deal.II/source/numerics/data_out_stack.cc index dd155aa13e..f3b3cbc2a5 100644 --- a/deal.II/deal.II/source/numerics/data_out_stack.cc +++ b/deal.II/deal.II/source/numerics/data_out_stack.cc @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,17 @@ #include + +template +unsigned int +DataOutStack::DataVector::memory_consumption () const +{ + return (MemoryConsumption::memory_consumption (data) + + MemoryConsumption::memory_consumption (names)); +}; + + + template DataOutStack::~DataOutStack () {}; @@ -306,6 +318,22 @@ void DataOutStack::finish_parameter_value () }; + +template +unsigned int +DataOutStack::memory_consumption () const +{ + return (DataOutInterface::memory_consumption () + + MemoryConsumption::memory_consumption (parameter) + + MemoryConsumption::memory_consumption (parameter_step) + + MemoryConsumption::memory_consumption (dof_handler) + + MemoryConsumption::memory_consumption (patches) + + MemoryConsumption::memory_consumption (dof_data) + + MemoryConsumption::memory_consumption (cell_data)); +}; + + + template const vector > & DataOutStack::get_patches () const @@ -314,6 +342,7 @@ DataOutStack::get_patches () const }; + template vector DataOutStack::get_dataset_names () const { diff --git a/deal.II/deal.II/source/numerics/histogram.cc b/deal.II/deal.II/source/numerics/histogram.cc index eac882012d..23821c2f0f 100644 --- a/deal.II/deal.II/source/numerics/histogram.cc +++ b/deal.II/deal.II/source/numerics/histogram.cc @@ -12,6 +12,7 @@ //---------------------------- histogram.cc --------------------------- +#include #include #include #include @@ -29,6 +30,7 @@ bool Histogram::logarithmic_less (const number n1, }; + Histogram::Interval::Interval (const double left_point, const double right_point) : left_point (left_point), @@ -37,6 +39,15 @@ Histogram::Interval::Interval (const double left_point, {}; + +unsigned int +Histogram::Interval::memory_consumption () const +{ + return sizeof(*this); +}; + + + template void Histogram::evaluate (const vector > &values, const vector &_y_values, @@ -212,6 +223,7 @@ void Histogram::evaluate (const vector > &values, }; + template void Histogram::evaluate (const Vector &values, const unsigned int n_intervals, @@ -223,6 +235,7 @@ void Histogram::evaluate (const Vector &values, }; + void Histogram::write_gnuplot (ostream &out) const { AssertThrow (out, ExcIO()); @@ -294,12 +307,14 @@ void Histogram::write_gnuplot (ostream &out) const }; + string Histogram::get_interval_spacing_names () { return "linear|logarithmic"; }; + Histogram::IntervalSpacing Histogram::parse_interval_spacing (const string &name) { @@ -317,6 +332,16 @@ Histogram::parse_interval_spacing (const string &name) }; + +unsigned int +Histogram::memory_consumption () const +{ + return (MemoryConsumption::memory_consumption (intervals) + + MemoryConsumption::memory_consumption (y_values)); +}; + + + // explicit instantiations for float template void Histogram::evaluate (const vector > &values, diff --git a/deal.II/deal.II/source/numerics/solution_transfer.cc b/deal.II/deal.II/source/numerics/solution_transfer.cc index c06003518e..0f8930ab09 100644 --- a/deal.II/deal.II/source/numerics/solution_transfer.cc +++ b/deal.II/deal.II/source/numerics/solution_transfer.cc @@ -12,6 +12,7 @@ //---------------------------- solution_transfer.cc --------------------------- +#include #include #include #include @@ -352,6 +353,7 @@ interpolate (const vector > &all_in, } + template void SolutionTransfer::interpolate(const Vector &in, Vector &out) const @@ -366,6 +368,30 @@ void SolutionTransfer::interpolate(const Vector &in, } + +template +unsigned int +SolutionTransfer::memory_consumption () const +{ + return (MemoryConsumption::memory_consumption (dof_handler) + + MemoryConsumption::memory_consumption (n_dofs_old) + + sizeof (prepared_for) + + MemoryConsumption::memory_consumption (indices_on_cell) + + MemoryConsumption::memory_consumption (all_pointerstructs) + + MemoryConsumption::memory_consumption (dof_values_on_cell)); +}; + + + +template +unsigned int +SolutionTransfer::Pointerstruct::memory_consumption () const +{ + return sizeof(*this); +}; + + + template class SolutionTransfer; template class SolutionTransfer; diff --git a/deal.II/deal.II/source/numerics/time_dependent.cc b/deal.II/deal.II/source/numerics/time_dependent.cc index b05e6b3781..ab3275fc88 100644 --- a/deal.II/deal.II/source/numerics/time_dependent.cc +++ b/deal.II/deal.II/source/numerics/time_dependent.cc @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -226,6 +227,7 @@ void TimeDependent::end_sweep (const unsigned int n_threads) } + void TimeDependent::end_sweep (const unsigned int begin, const unsigned int end) { @@ -234,6 +236,22 @@ void TimeDependent::end_sweep (const unsigned int begin, }; + +unsigned int TimeDependent::memory_consumption () const +{ + unsigned int mem = (MemoryConsumption::memory_consumption (timesteps) + + MemoryConsumption::memory_consumption (sweep_no) + + sizeof(timestepping_data_primal) + + sizeof(timestepping_data_dual) + + sizeof(timestepping_data_postprocess)); + for (unsigned int i=0; i TimeStepBase_Tria::TimeStepBase_Tria() : TimeStepBase (0), tria (0), - coarse_grid (*reinterpret_cast*>(0)) + coarse_grid (0) { Assert (false, ExcPureVirtualFunctionCalled()); }; + template TimeStepBase_Tria::TimeStepBase_Tria (const double time, const Triangulation &coarse_grid, @@ -383,12 +429,11 @@ TimeStepBase_Tria::TimeStepBase_Tria (const double time, const RefinementFlags &refinement_flags) : TimeStepBase (time), tria(0), - coarse_grid (coarse_grid), + coarse_grid (&coarse_grid), flags (flags), refinement_flags (refinement_flags) -{ - coarse_grid.subscribe(); -}; +{}; + template @@ -401,14 +446,16 @@ TimeStepBase_Tria::~TimeStepBase_Tria () } else Assert (tria==0, ExcInternalError()); - - coarse_grid.unsubscribe(); + + coarse_grid = 0; }; + template void -TimeStepBase_Tria::wake_up (const unsigned wakeup_level) { +TimeStepBase_Tria::wake_up (const unsigned wakeup_level) +{ TimeStepBase::wake_up (wakeup_level); if (wakeup_level == flags.wakeup_level_to_build_grid) @@ -417,6 +464,7 @@ TimeStepBase_Tria::wake_up (const unsigned wakeup_level) { }; + template void TimeStepBase_Tria::sleep (const unsigned sleep_level) @@ -437,6 +485,7 @@ TimeStepBase_Tria::sleep (const unsigned sleep_level) }; + template void TimeStepBase_Tria::save_refine_flags () { @@ -449,8 +498,10 @@ void TimeStepBase_Tria::save_refine_flags () }; + template -void TimeStepBase_Tria::restore_grid () { +void TimeStepBase_Tria::restore_grid () +{ Assert (tria == 0, ExcGridNotDeleted()); Assert (refine_flags.size() == coarsen_flags.size(), ExcInternalError()); @@ -459,7 +510,7 @@ void TimeStepBase_Tria::restore_grid () { // set it to a copy of the coarse grid tria = new Triangulation (); tria->subscribe(); - tria->copy_triangulation (coarse_grid); + tria->copy_triangulation (*coarse_grid); // for each of the previous refinement // sweeps @@ -488,10 +539,12 @@ void TimeStepBase_Tria::restore_grid () { }; + template static void mirror_refinement_flags (const Triangulation::cell_iterator &new_cell, - const Triangulation::cell_iterator &old_cell) { + const Triangulation::cell_iterator &old_cell) +{ // mirror the refinement // flags from the present time level to // the previous if the dual problem was @@ -533,10 +586,12 @@ mirror_refinement_flags (const Triangulation::cell_iterator &new_cell, }; + template static bool adapt_grids (const Triangulation::cell_iterator &cell1, - const Triangulation::cell_iterator &cell2) { + const Triangulation::cell_iterator &cell2) +{ if (cell2->has_children() && cell1->has_children()) { @@ -635,10 +690,12 @@ adapt_grids (const Triangulation::cell_iterator &cell1, }; + template static bool adapt_grids (Triangulation &tria1, - Triangulation &tria2) { + Triangulation &tria2) +{ bool grids_changed = false; Triangulation::cell_iterator cell1 = tria1.begin(), @@ -654,6 +711,7 @@ adapt_grids (Triangulation &tria1, }; + template void TimeStepBase_Tria::refine_grid (const RefinementData refinement_data) { @@ -1050,6 +1108,7 @@ void TimeStepBase_Tria::refine_grid (const RefinementData refinement_data) }; + template void TimeStepBase_Tria::init_for_refinement () { @@ -1057,12 +1116,29 @@ void TimeStepBase_Tria::init_for_refinement () }; + template -TimeStepBase_Tria::Flags::Flags () { +unsigned int +TimeStepBase_Tria::memory_consumption () const +{ + return (TimeStepBase::memory_consumption () + + sizeof(tria) + + MemoryConsumption::memory_consumption (coarse_grid) + + sizeof(flags) + sizeof(refinement_flags) + + MemoryConsumption::memory_consumption (refine_flags) + + MemoryConsumption::memory_consumption (coarsen_flags)); +}; + + + +template +TimeStepBase_Tria::Flags::Flags () +{ Assert (false, ExcInternalError()); }; + template TimeStepBase_Tria::Flags::Flags (const bool delete_and_rebuild_tria, const unsigned int wakeup_level_to_build_grid, -- 2.39.5