From: wolf Date: Sun, 26 Nov 2000 21:40:40 +0000 (+0000) Subject: Implement memory consumption monitors to most classes. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f0adbc5469a5ce9b08f3eeddf697f081858e579;p=dealii-svn.git Implement memory consumption monitors to most classes. git-svn-id: https://svn.dealii.org/trunk@3502 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/data_out_base.h b/deal.II/base/include/base/data_out_base.h index da9b67032f..71ca79938e 100644 --- a/deal.II/base/include/base/data_out_base.h +++ b/deal.II/base/include/base/data_out_base.h @@ -418,6 +418,24 @@ class DataOutBase */ Patch (); + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; + /** * Exception */ @@ -471,6 +489,24 @@ class DataOutBase * all previous contents of this object. */ void parse_parameters (ParameterHandler &prm); + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; }; /** @@ -509,6 +545,24 @@ class DataOutBase * all previous contents of this object. */ void parse_parameters (ParameterHandler &prm); + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; }; /** @@ -520,39 +574,39 @@ class DataOutBase */ struct PovrayFlags { - /** - * Normal vector interpolation, - * if set to true - * - * default = false - */ - bool smooth; - - /** - * Use bicubic patches (b-splines) - * instead of triangles. - * - * default = false - */ - bool bicubic_patch; - - /** - * include external "data.inc" - * with camera, light and - * texture definition for the - * scene. - * - * default = false - */ - bool external_data; - - /** - * Constructor. - */ - PovrayFlags (const bool smooth = false, - const bool bicubic_patch = false, - const bool external_data = false); + /** + * Normal vector interpolation, + * if set to true + * + * default = false + */ + bool smooth; + + /** + * Use bicubic patches (b-splines) + * instead of triangles. + * + * default = false + */ + bool bicubic_patch; + /** + * include external "data.inc" + * with camera, light and + * texture definition for the + * scene. + * + * default = false + */ + bool external_data; + + /** + * Constructor. + */ + PovrayFlags (const bool smooth = false, + const bool bicubic_patch = false, + const bool external_data = false); + /** * Declare all flags with name * and type as offered by this @@ -570,6 +624,24 @@ class DataOutBase * all previous contents of this object. */ void parse_parameters (ParameterHandler &prm); + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; }; @@ -847,6 +919,24 @@ class DataOutBase * all previous contents of this object. */ void parse_parameters (ParameterHandler &prm); + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; }; /** @@ -885,6 +975,24 @@ class DataOutBase * all previous contents of this object. */ void parse_parameters (ParameterHandler &prm); + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; }; /** @@ -952,6 +1060,23 @@ class DataOutBase const GmvFlags &flags, ostream &out); + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + static unsigned int memory_consumption (); /** * Exception @@ -1353,6 +1478,24 @@ class DataOutInterface : private DataOutBase */ void parse_parameters (ParameterHandler &prm); + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; + /** * Exception */ diff --git a/deal.II/base/include/base/function.h b/deal.II/base/include/base/function.h index 3b5404ec91..69ef98668a 100644 --- a/deal.II/base/include/base/function.h +++ b/deal.II/base/include/base/function.h @@ -255,6 +255,24 @@ class Function : public FunctionTime, */ virtual void vector_laplacian_list (const vector > &points, vector > &values) const; + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; }; @@ -455,6 +473,24 @@ class ConstantFunction : public ZeroFunction virtual void vector_value_list (const vector > &points, vector > &values) const; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; + protected: /** * Store the constant function value. @@ -505,6 +541,24 @@ class ComponentSelectFunction : public ConstantFunction virtual void vector_value_list (const vector > &points, vector > &values) const; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; + protected: const unsigned int selected; }; diff --git a/deal.II/base/include/base/function_derivative.h b/deal.II/base/include/base/function_derivative.h index 2d0f7aca93..9400f0fff5 100644 --- a/deal.II/base/include/base/function_derivative.h +++ b/deal.II/base/include/base/function_derivative.h @@ -16,16 +16,6 @@ #include #include -/** - * Names of difference formulas. - */ -enum DifferenceFormula -{ - Euler, - UpwindEuler, - FourthOrder -}; - /** * Derivative of a function object. The value access functions of @@ -45,77 +35,105 @@ enum DifferenceFormula template class FunctionDerivative : public Function { -public: - /** - * Constructor. Provided are the - * function to compute derivatives - * of and the direction vector of - * the differentiation. - */ - FunctionDerivative (const Function& f, - const Point& direction); + public: + /** + * Names of difference formulas. + */ + enum DifferenceFormula + { + Euler, + UpwindEuler, + FourthOrder + }; - /** - * Set step size of the difference - * formula. This is set to the - * default in the constructor. - */ - void set_h (double h_new = 1.e-6); - - /** - * Choose the difference formula. - * This is set to the default in - * the constructor. - * - * Formulas implemented right now - * are first order backward Euler - * (@p{UpwindEuler}), second order - * symmetric Euler (@p{Euler}) and - * a symmetric fourth order formula - * (@p{FourthOrder}). - */ - void set_formula (DifferenceFormula formula = Euler); - - /** - * Function value at one point. - */ - virtual double value (const Point &p, - const unsigned int component = 0) const; - - /** - * Function values at multiple points. - */ - virtual void value_list (const vector > &points, - vector &values, - const unsigned int component = 0) const; + /** + * Constructor. Provided are the + * function to compute derivatives + * of and the direction vector of + * the differentiation. + */ + FunctionDerivative (const Function& f, + const Point& direction); + + /** + * Set step size of the difference + * formula. This is set to the + * default in the constructor. + */ + void set_h (double h_new = 1.e-6); + + /** + * Choose the difference formula. + * This is set to the default in + * the constructor. + * + * Formulas implemented right now + * are first order backward Euler + * (@p{UpwindEuler}), second order + * symmetric Euler (@p{Euler}) and + * a symmetric fourth order formula + * (@p{FourthOrder}). + */ + void set_formula (DifferenceFormula formula = Euler); + + /** + * Function value at one point. + */ + virtual double value (const Point &p, + const unsigned int component = 0) const; + + /** + * Function values at multiple points. + */ + virtual void value_list (const vector > &points, + vector &values, + const unsigned int component = 0) const; - DeclException0(ExcInvalidFormula); - -private: - /** - * Function for differentiation. - */ - const Function& f; - /** - * Differentiation vector. - */ - Point direction; - - /** - * Step size of the difference formula. - */ - double h; - /** - * Difference formula. - */ - DifferenceFormula formula; - /** - * Helper object. Contains the - * increment vector for the - * formula. - */ - Point incr; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; + + DeclException0(ExcInvalidFormula); + + private: + /** + * Function for differentiation. + */ + const Function& f; + /** + * Differentiation vector. + */ + Point direction; + + /** + * Step size of the difference formula. + */ + double h; + /** + * Difference formula. + */ + DifferenceFormula formula; + /** + * Helper object. Contains the + * increment vector for the + * formula. + */ + Point incr; }; #endif diff --git a/deal.II/base/include/base/function_lib.h b/deal.II/base/include/base/function_lib.h index 299a9beb8c..19f43e7ab0 100644 --- a/deal.II/base/include/base/function_lib.h +++ b/deal.II/base/include/base/function_lib.h @@ -406,11 +406,30 @@ class JumpFunction : public Function vector &values, const unsigned int component = 0) const; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; + protected: /** * Advection vector. */ const Point direction; + /** * Steepness (maximal derivative) * of the slope. diff --git a/deal.II/base/include/base/logstream.h b/deal.II/base/include/base/logstream.h index 370d3df0a7..b73a7ed0d1 100644 --- a/deal.II/base/include/base/logstream.h +++ b/deal.II/base/include/base/logstream.h @@ -32,15 +32,15 @@ * * The usual usage of this class is through the pregenerated object * @p{deallog}. Typical steps are - *
    - *
  1. @p{deallog.attach(ostream)}: write logging information into a file. - *
  2. @p{deallog.depth_console(n)}: restrict output on screen to outer loops. - *
  3. Before entering a new phase of your program, e.g. a new loop, - * @p{deallog.push("loopname")}. - *
  4. @p{deallog << anything << endl;} to write logging information - * (Usage of @p{endl} is mandatory!). - *
  5. @p{deallog.pop()} when leaving that stage entered with @p{push}. - *
+ * @begin{itemize} + * @item @p{deallog.attach(ostream)}: write logging information into a file. + * @item @p{deallog.depth_console(n)}: restrict output on screen to outer loops. + * @item Before entering a new phase of your program, e.g. a new loop, + * @p{deallog.push("loopname")}. + * @item @p{deallog << anything << endl;} to write logging information + * (Usage of @p{endl} is mandatory!). + * @item @p{deallog.pop()} when leaving that stage entered with @p{push}. + * @end{itemize} * * @author Guido Kanschat, Wolfgang Bangerth, 1999 */ @@ -213,10 +213,24 @@ class LogStream */ LogStream & operator << (void (f)(LogStream &)); + /** - * Declare this function as a friend. + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. */ - friend void endl (LogStream &); + unsigned int memory_consumption () const; /** * Exception @@ -230,6 +244,11 @@ class LogStream * the contents of the prefix stack. */ void print_line_head(); + + /** + * Declare this function as a friend. + */ + friend void endl (LogStream &); }; diff --git a/deal.II/base/include/base/memory_consumption.h b/deal.II/base/include/base/memory_consumption.h new file mode 100644 index 0000000000..2eb08c9d22 --- /dev/null +++ b/deal.II/base/include/base/memory_consumption.h @@ -0,0 +1,423 @@ +//---------------------------- memory_consumption.h --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- memory_consumption.h --------------------------- +#ifndef __deal2__memory_consumption_h +#define __deal2__memory_consumption_h + + +#include +#include +#include + + + +/** + * Basic types, vectors of basic types, strings, vectors of composed types + * + * @author Wolfgang Bangerth, 2000 + */ +namespace MemoryConsumption +{ + /** + * Determine the amount of memory + * in bytes consumed by a @p{bool} + * variable. + */ + inline + unsigned int memory_consumption (const bool) + { + return sizeof(bool); + }; + + /** + * Determine the amount of memory + * in bytes consumed by a @p{char} + * variable. + */ + inline + unsigned int memory_consumption (const char) + { + return sizeof(char); + }; + + /** + * Determine the amount of memory + * in bytes consumed by a + * @p{short int} variable. + */ + inline + unsigned int memory_consumption (const short int) + { + return sizeof(short int); + }; + + + /** + * Determine the amount of memory + * in bytes consumed by a + * @p{short unsigned int} variable. + */ + inline + unsigned int memory_consumption (const short unsigned int) + { + return sizeof(short unsigned int); + }; + + + + /** + * Determine the amount of memory + * in bytes consumed by a @p{int} + * variable. + */ + inline + unsigned int memory_consumption (const int) + { + return sizeof(int); + }; + + + /** + * Determine the amount of memory + * in bytes consumed by a @p{unsigned int} + * variable. + */ + inline + unsigned int memory_consumption (const unsigned int) + { + return sizeof(unsigned int); + }; + + + /** + * Determine the amount of memory + * in bytes consumed by a @p{float} + * variable. + */ + inline + unsigned int memory_consumption (const float) + { + return sizeof(float); + }; + + + + /** + * Determine the amount of memory + * in bytes consumed by a @p{double} + * variable. + */ + inline + unsigned int memory_consumption (const double) + { + return sizeof(double); + }; + + /** + * Determine an estimate of the + * amount of memory in bytes + * consumed by a @p{string} + * variable. + */ + unsigned int memory_consumption (const string &s); + + /** + * Determine an estimate of the + * amount of memory in bytes + * consumed by a @p{vector} of + * certain elements. It does so by + * looping over all elements of the + * vector and determining their + * sizes using the + * @p{memory_consumption} + * functions. If the elements are + * of constant size, there might be + * another global function + * @p{memory_consumption} for this + * data type or if there is a + * member function of that class of + * that names that returns a + * constant value and the compiler + * will unroll this loop so that + * the operation is fast. If the + * size of the data elements is + * variable, for example if they do + * memory allocation themselves, + * then the operation will + * necessarily be more expensive. + * + * Using the algorithm, in + * particular the loop over all + * elements, it is possible to also + * compute the memory consumption + * of vectors of vectors, vectors + * of strings, etc, where the + * individual elements may have + * vastly different sizes. + * + * Note that this algorithm also + * takes into account the size of + * elements that are allocated by + * this vector but not currently + * used. + * + * For the most commonly used + * vectors, there are special + * functions that compute the size + * without a loop. This also + * applies for the special case of + * vectors of bools. + */ + template + unsigned int memory_consumption (const vector &v) + { + unsigned int mem = sizeof(vector); + const unsigned int n = v.size(); + for (unsigned int i=0; i + unsigned int memory_consumption (const T (&v)[N]) + { + unsigned int mem = 0; + for (unsigned int i=0; i &v) + { + return v.capacity() / 8 + sizeof(v); + }; + + + /** + * Specialization of the + * determination of the memory + * consumption of a vector, here + * for a vector of @p{int}s. + */ + inline + unsigned int memory_consumption (const vector &v) + { + return (v.capacity() * sizeof(int) + + sizeof(v)); + }; + + + /** + * Specialization of the + * determination of the memory + * consumption of a vector, here + * for a vector of @p{double}s. + */ + inline + unsigned int memory_consumption (const vector &v) + { + return (v.capacity() * sizeof(double) + + sizeof(v)); + }; + + + /** + * Specialization of the + * determination of the memory + * consumption of a vector, here + * for a vector of @p{float}s. + */ + inline + unsigned int memory_consumption (const vector &v) + { + return (v.capacity() * sizeof(float) + + sizeof(v)); + }; + + + /** + * Specialization of the + * determination of the memory + * consumption of a vector, here + * for a vector of @p{char}s. + */ + inline + unsigned int memory_consumption (const vector &v) + { + return (v.capacity() * sizeof(char) + + sizeof(v)); + }; + + + + /** + * Specialization of the + * determination of the memory + * consumption of a vector, here + * for a vector of @p{unsigned char}s. + */ + inline + unsigned int memory_consumption (const vector &v) + { + return (v.capacity() * sizeof(unsigned char) + + sizeof(v)); + }; + + + + + /** + * Specialization of the + * determination of the memory + * consumption of a vector, here + * for a vector of pointers. + */ + template + inline + unsigned int memory_consumption (const vector &v) + { + return (v.capacity() * sizeof(T *) + + sizeof(v)); + }; + + + /** + * Determine an estimate of the + * amount of memory in bytes + * consumed by a pair of values. + */ + template + inline + unsigned int memory_consumption (const pair &p) + { + return (memory_consumption(p.first) + + memory_consumption(p.second)); + }; + + /** + * Return the amount of memory + * used by a pointer. Make sure + * that you are really interested + * in this, and not the amount of + * memory required by the object + * pointed to. + */ + template + inline + unsigned int + memory_consumption (const T * const) + { + return sizeof(T*); + }; + + + + /** + * Return the amount of memory + * used by a pointer. Make sure + * that you are really interested + * in this, and not the amount of + * memory required by the object + * pointed to. + * + * This function is the same as + * above, but for non-const + * pointers + */ + template + inline + unsigned int + memory_consumption (T * const) + { + return sizeof(T*); + }; + + + + /** + * Return the amount of memory + * used by a void pointer. Make + * sure that you are really + * interested in this, and not + * the amount of memory required + * by the object pointed to. + * + * Note that we needed this + * function since @p{void} is no + * type and a @p{void*} is thus + * not caught by the general + * @p{T*} template function + * above. + */ + inline + unsigned int + memory_consumption (void * const) + { + return sizeof(void*); + }; + + + /** + * For all other types which are + * not explicitely listed: try if + * there is a member function + * called + * @p{memory_consumption}. If + * this is not the case, then the + * compiler will in any case + * complain that this last exit + * does not work. + */ + template + inline + unsigned int + memory_consumption (const T &t) + { + return t.memory_consumption(); + }; +} + + + +#endif + diff --git a/deal.II/base/include/base/multithread_info.h b/deal.II/base/include/base/multithread_info.h index c9f5a54d06..e2f277d5ef 100644 --- a/deal.II/base/include/base/multithread_info.h +++ b/deal.II/base/include/base/multithread_info.h @@ -65,6 +65,24 @@ class MultithreadInfo */ unsigned int n_default_threads; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + static unsigned int memory_consumption (); + /** * Exception */ diff --git a/deal.II/base/include/base/parameter_handler.h b/deal.II/base/include/base/parameter_handler.h index a17c5291fd..c58c12948c 100644 --- a/deal.II/base/include/base/parameter_handler.h +++ b/deal.II/base/include/base/parameter_handler.h @@ -86,6 +86,45 @@ namespace Patterns * this function. */ virtual PatternBase * clone () const = 0; + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this object. To + * avoid unnecessary + * overhead, we do not force + * derivd classes to provide + * this function as a virtual + * overloaded one, but rather + * try to cast the present + * object to one of the known + * derived classes and if + * that fails then take the + * size of this base class + * instead and add 32 byte + * (this value is arbitrary, + * it should account for + * virtual function tables, + * and some possible data + * elements). Since there are + * usually not many thousands + * of objects of this type + * around, and since the + * @p{memory_consumption} + * mechanism is used to find + * out where memory in the + * range of many megabytes + * is, this seems like a + * reasonable approximation. + * + * On the other hand, if you + * know that your class + * deviates from this + * assumption significantly, + * you can still overload + * this function. + */ + virtual unsigned int memory_consumption () const; }; /** @@ -361,6 +400,13 @@ namespace Patterns */ virtual PatternBase * clone () const; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this object. + */ + unsigned int memory_consumption () const; + private: /** * List of valid strings as @@ -434,6 +480,13 @@ namespace Patterns */ virtual PatternBase * clone () const; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this object. + */ + unsigned int memory_consumption () const; + /** * Exception. */ @@ -1007,7 +1060,7 @@ class ParameterHandler * Return status of this object: * @p{true}=clean or @p{false}=error occured. */ - bool ok() const; + bool ok () const; /** * clear status bit and contents. @@ -1107,14 +1160,22 @@ class ParameterHandler */ void log_parameters (LogStream& out); - /** - * Log parameters in - * subsection. The subsection is - * determined by the - * @p{subsection_path} member * - * variable. - */ - void log_parameters_section (LogStream& out); + /** + * Log parameters in + * subsection. The subsection is + * determined by the + * @p{subsection_path} member * + * variable. + */ + void log_parameters_section (LogStream& out); + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. + */ + unsigned int memory_consumption () const; /** * Exception @@ -1158,55 +1219,85 @@ class ParameterHandler * entry content and regexp, and * list of subsections. */ - struct Section { + struct Section + { ~Section (); typedef map > EntryType; EntryType entries; map subsections; + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. Since sometimes + * the size of objects can + * not be determined exactly + * (for example: what is the + * memory consumption of an + * STL @p{map} type with a + * certain number of + * elements?), this is only + * an estimate. however often + * quite close to the true + * value. + */ + unsigned int memory_consumption () const; }; /** - * Path of presently selected subsections; - * empty list means top level + * Path of presently selected + * subsections; empty list means + * top level */ vector subsection_path; /** - * List of default values organized as a - * tree of subsections + * List of default values + * organized as a tree of + * subsections */ Section defaults; /** - * Analogue list of changed entries. The - * tree of subsections is there even if there - * are no changed entry values in a - * subsection; therefore @p{enter_subsection} - * has to create the tree in both @p{Defaults} - * and @p{changed_entries}. + * Analogue list of changed + * entries. The tree of + * subsections is there even if + * there are no changed entry + * values in a subsection; + * therefore @p{enter_subsection} + * has to create the tree in both + * @p{Defaults} and + * @p{changed_entries}. */ Section changed_entries; /** * Scan one line of input. - * @p{lineno} is the number of the line presently - * scanned (for the logs if there are messages). - * @return @p{false} if line contained stuff - * that could not be understood, the uppermost - * subsection was to be left by an @p{END} or - * @p{end} statement, a value for a non-declared - * entry was given or teh entry value did not - * match the regular expression. @p{true} - * otherwise + * @p{lineno} is the number of + * the line presently scanned + * (for the logs if there are + * messages). @return @p{false} + * if line contained stuff that + * could not be understood, the + * uppermost subsection was to be + * left by an @p{END} or @p{end} + * statement, a value for a + * non-declared entry was given + * or teh entry value did not + * match the regular + * expression. @p{true} otherwise */ bool scan_line (string line, const unsigned int lineno); /** - * Get a pointer to the @p{Section} structure - * in the @p{Defaults} tree - * for the subsection we are presently in. + * Get a pointer to the + * @p{Section} structure in the + * @p{Defaults} tree for the + * subsection we are presently + * in. */ Section* get_present_defaults_subsection (); @@ -1231,6 +1322,7 @@ class ParameterHandler }; + /** * The class @p{MultipleParameterLoop} offers an easy possibility to test several * parameter sets during one run of the program. For this it uses the @@ -1455,7 +1547,8 @@ class MultipleParameterLoop : public ParameterHandler * This is the class the helper class or the * problem class has to be derived of. */ - class UserClass { + class UserClass + { public: /** * @p{create_new} must provide a clean @@ -1515,13 +1608,24 @@ class MultipleParameterLoop : public ParameterHandler */ void loop (UserClass &uc); + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. + */ + unsigned int memory_consumption () const; + private: /** - * Declare what a multiple entry is: a variant - * entry (in curly braces @p{{}}) or an - * array (in double curly braces @p{{{}}}). + * Declare what a multiple entry + * is: a variant * entry (in + * curly braces @p{{}}) or an + * array (in double curly braces + * @p{{{}}}). */ - enum MultipleEntryType { + enum MultipleEntryType + { variant, array }; @@ -1529,7 +1633,8 @@ class MultipleParameterLoop : public ParameterHandler * An object in the list of entries with * multiple values. */ - class Entry { + class Entry + { public: /** * Constructor @@ -1577,6 +1682,14 @@ class MultipleParameterLoop : public ParameterHandler * entry or an array. */ MultipleEntryType type; + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. + */ + unsigned int memory_consumption () const; }; /** diff --git a/deal.II/base/include/base/quadrature.h b/deal.II/base/include/base/quadrature.h index ddfd70c2a2..b786abf8c1 100644 --- a/deal.II/base/include/base/quadrature.h +++ b/deal.II/base/include/base/quadrature.h @@ -125,6 +125,14 @@ class Quadrature : public Subscriptor */ const vector & get_weights () const; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. + */ + unsigned int memory_consumption () const; + protected: /** * List of quadrature points. To be filled diff --git a/deal.II/base/include/base/smartpointer.h b/deal.II/base/include/base/smartpointer.h index 7a810d08c0..a87be47f23 100644 --- a/deal.II/base/include/base/smartpointer.h +++ b/deal.II/base/include/base/smartpointer.h @@ -154,6 +154,17 @@ class SmartPointer * variable which we are given. */ void swap (T *&tt); + + /** + * Return an estimate of the + * amount of memory (in bytes) + * used by this class. Note in + * particular, that this only + * includes the amount of memory + * used by @it{this} object, not + * by the object pointed to. + */ + unsigned int memory_consumption () const; private: /** @@ -295,6 +306,16 @@ void SmartPointer::swap (T *&tt) +template +inline +unsigned int SmartPointer::memory_consumption () const +{ + return sizeof(SmartPointer); +}; + + + + /** * Global function to swap the contents of two smart pointers. As both * objects to which the pointers point retain to be subscribed to, we diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index 98e6576fb7..750bfc1b0a 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -162,6 +162,14 @@ class Tensor */ void clear (); + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. + */ + static unsigned int memory_consumption (); + // /** // * Exception // */ @@ -196,9 +204,7 @@ class Tensor /*--------------------------- Inline functions -----------------------------*/ -// in the following, declarations of operators look rather weird because they are -// split over several lines. this is necessary, however, because otherwise doc++ -// gets really confused about this all... :-( + template @@ -368,6 +374,16 @@ void Tensor::clear () }; + +template +inline +unsigned int +Tensor::memory_consumption () +{ + return sizeof(Tensor); +}; + + /* ----------------- Non-member functions operating on tensors. ------------ */ diff --git a/deal.II/base/include/base/tensor_base.h b/deal.II/base/include/base/tensor_base.h index 123f16d6a2..8eb3d210c8 100644 --- a/deal.II/base/include/base/tensor_base.h +++ b/deal.II/base/include/base/tensor_base.h @@ -213,6 +213,14 @@ class Tensor<1,dim> */ void unroll (Vector &result) const; + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. + */ + static unsigned int memory_consumption (); + protected: /** * Help function for unroll. @@ -452,6 +460,16 @@ void Tensor<1,dim>::clear () +template +inline +unsigned int +Tensor<1,dim>::memory_consumption () +{ + return sizeof(Tensor<1,dim>); +}; + + + /** * Output operator for tensors of rank 1. Print the elements * consecutively, with a space in between. diff --git a/deal.II/base/source/data_out_base.all_dimensions.cc b/deal.II/base/source/data_out_base.all_dimensions.cc index 2fcad5f315..d6dc2f4d65 100644 --- a/deal.II/base/source/data_out_base.all_dimensions.cc +++ b/deal.II/base/source/data_out_base.all_dimensions.cc @@ -14,6 +14,7 @@ #include #include +#include DataOutBase::UcdFlags::UcdFlags (const bool write_preamble) : @@ -45,6 +46,15 @@ void DataOutBase::UcdFlags::parse_parameters (ParameterHandler &prm) }; +unsigned int +DataOutBase::UcdFlags::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + void DataOutBase::GnuplotFlags::declare_parameters (ParameterHandler &/*prm*/) {}; @@ -56,6 +66,17 @@ void DataOutBase::GnuplotFlags::parse_parameters (ParameterHandler &/*prm*/) +unsigned int +DataOutBase::GnuplotFlags::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + + + void DataOutBase::PovrayFlags::declare_parameters (ParameterHandler &prm) { prm.declare_entry ("Use smooth triangles", "false", @@ -77,6 +98,16 @@ void DataOutBase::PovrayFlags::parse_parameters (ParameterHandler &prm) +unsigned int +DataOutBase::PovrayFlags::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + + DataOutBase::EpsFlags::EpsFlags (const unsigned int height_vector, const unsigned int color_vector, const SizeType size_type, @@ -267,6 +298,16 @@ void DataOutBase::EpsFlags::parse_parameters (ParameterHandler &prm) +unsigned int +DataOutBase::EpsFlags::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + + void DataOutBase::GmvFlags::declare_parameters (ParameterHandler &/*prm*/) {}; @@ -274,3 +315,21 @@ void DataOutBase::GmvFlags::declare_parameters (ParameterHandler &/*prm*/) void DataOutBase::GmvFlags::parse_parameters (ParameterHandler &/*prm*/) {}; + + +unsigned int +DataOutBase::GmvFlags::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + + +unsigned int DataOutBase::memory_consumption () +{ + return 0; +}; + + diff --git a/deal.II/base/source/data_out_base.cc b/deal.II/base/source/data_out_base.cc index 32238b275d..ea55db556b 100644 --- a/deal.II/base/source/data_out_base.cc +++ b/deal.II/base/source/data_out_base.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,20 @@ DataOutBase::Patch::Patch () : +template +unsigned int +DataOutBase::Patch::memory_consumption () const +{ + return (sizeof(vertices) / sizeof(vertices[0]) * + MemoryConsumption::memory_consumption(vertices[0]) + + + MemoryConsumption::memory_consumption(n_subdivisions) + + + MemoryConsumption::memory_consumption(data)); +}; + + + template void DataOutBase::write_ucd (const vector > &patches, const vector &data_names, @@ -1774,7 +1789,6 @@ DataOutBase::write_gmv_reorder_data_vectors (const vector > - /* --------------------------- class DataOutInterface ---------------------- */ @@ -2031,6 +2045,21 @@ void DataOutInterface::parse_parameters (ParameterHandler &prm) } +template +unsigned int +DataOutInterface::memory_consumption () const +{ + return (sizeof (default_fmt) + + MemoryConsumption::memory_consumption (ucd_flags) + + MemoryConsumption::memory_consumption (gnuplot_flags) + + MemoryConsumption::memory_consumption (povray_flags) + + MemoryConsumption::memory_consumption (eps_flags) + + MemoryConsumption::memory_consumption (gmv_flags)); +}; + + + + // explicit instantiations. functions in DataOutBase are instantiated by // the respective functions in DataOut_Interface template class DataOutInterface; diff --git a/deal.II/base/source/function.cc b/deal.II/base/source/function.cc index aa19b5436e..3444ced4eb 100644 --- a/deal.II/base/source/function.cc +++ b/deal.II/base/source/function.cc @@ -175,6 +175,18 @@ void Function::vector_laplacian_list (const vector > &points, this->vector_laplacian (points[i], laplacians[i]); } + + +template +unsigned int +Function::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + //------------------------------------------------------------// template @@ -341,6 +353,17 @@ void ConstantFunction::vector_value_list (const vector > &points }; }; + + +template +unsigned int +ConstantFunction::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + //------------------------------------------------------------// template @@ -383,6 +406,17 @@ void ComponentSelectFunction::vector_value_list (const vector > } + +template +unsigned int +ComponentSelectFunction::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + // explicit instantiations template class Function<1>; diff --git a/deal.II/base/source/function_derivative.cc b/deal.II/base/source/function_derivative.cc index e6d8ed0978..f1abe317c3 100644 --- a/deal.II/base/source/function_derivative.cc +++ b/deal.II/base/source/function_derivative.cc @@ -20,10 +20,10 @@ template FunctionDerivative::FunctionDerivative (const Function& f, const Point& dir) - : - Function (f.n_components, f.get_time()), - f(f), - direction(dir) + : + Function (f.n_components, f.get_time()), + f(f), + direction(dir) { set_h(); set_formula(); @@ -57,15 +57,15 @@ FunctionDerivative::value (const Point &p, { switch (formula) { - case Euler: - return (f.value(p+incr, component)-f.value(p-incr, component))/(2*h); - case UpwindEuler: - return (f.value(p, component)-f.value(p-incr, component))/h; - case FourthOrder: - return (-f.value(p+2*incr, component) + 8*f.value(p+incr, component) - -8*f.value(p-incr, component) + f.value(p-2*incr, component))/(12*h); - default: - Assert(false, ExcInvalidFormula()); + case Euler: + return (f.value(p+incr, component)-f.value(p-incr, component))/(2*h); + case UpwindEuler: + return (f.value(p, component)-f.value(p-incr, component))/h; + case FourthOrder: + return (-f.value(p+2*incr, component) + 8*f.value(p+incr, component) + -8*f.value(p-incr, component) + f.value(p-2*incr, component))/(12*h); + default: + Assert(false, ExcInvalidFormula()); } return 0.; } @@ -147,6 +147,17 @@ FunctionDerivative::value_list (const vector > &points, } + +template +unsigned int +FunctionDerivative::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + template FunctionDerivative<1>; template FunctionDerivative<2>; template FunctionDerivative<3>; diff --git a/deal.II/base/source/function_lib.cc b/deal.II/base/source/function_lib.cc index b27e0e391f..66df13b319 100644 --- a/deal.II/base/source/function_lib.cc +++ b/deal.II/base/source/function_lib.cc @@ -888,6 +888,17 @@ JumpFunction::gradient_list (const vector > &p, } + +template +unsigned int +JumpFunction::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + template SquareFunction<1>; template SquareFunction<2>; template SquareFunction<3>; diff --git a/deal.II/base/source/log.cc b/deal.II/base/source/log.cc index a799ae2b1e..88c4c2494b 100644 --- a/deal.II/base/source/log.cc +++ b/deal.II/base/source/log.cc @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -141,3 +142,21 @@ LogStream::operator << (void (f)(LogStream &)) } + +unsigned int +LogStream::memory_consumption () const +{ + unsigned int mem = sizeof(*this); + // to determine size of stack + // elements, we have to copy the + // stack since we can't access + // elements from further below + stack tmp; + while (tmp.size() > 0) + { + mem += MemoryConsumption::memory_consumption (tmp.top()); + tmp.pop (); + }; + + return mem; +}; diff --git a/deal.II/base/source/memory_consumption.cc b/deal.II/base/source/memory_consumption.cc new file mode 100644 index 0000000000..62a2177a87 --- /dev/null +++ b/deal.II/base/source/memory_consumption.cc @@ -0,0 +1,36 @@ +//---------------------------- function.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- function.cc --------------------------- + + +#include + + +namespace MemoryConsumption +{ + unsigned int memory_consumption (const string &s) + { + return sizeof(s) + s.length(); + }; + + + + unsigned int memory_consumption (const vector &v) + { + unsigned int mem = sizeof(v); + for (unsigned int i=0; i #include +#include #include #include #include @@ -30,6 +31,23 @@ namespace Patterns {}; + unsigned int + PatternBase::memory_consumption () const + { + if (dynamic_cast(this) != 0) + return sizeof(Integer); + else if (dynamic_cast(this) != 0) + return sizeof(Double); + else if (dynamic_cast(this) != 0) + return sizeof(Bool); + else if (dynamic_cast(this) != 0) + return sizeof(Anything); + else + return sizeof(*this) + 32; + }; + + + Integer::Integer (const int lower_bound, const int upper_bound) : @@ -195,6 +213,13 @@ namespace Patterns }; + unsigned int + Selection::memory_consumption () const + { + return (sizeof(PatternBase) + + MemoryConsumption::memory_consumption(sequence)); + }; + MultipleSelection::MultipleSelection (const string &seq) { @@ -287,6 +312,14 @@ namespace Patterns }; + unsigned int + MultipleSelection::memory_consumption () const + { + return (sizeof(PatternBase) + + MemoryConsumption::memory_consumption(sequence)); + }; + + Bool::Bool () : Selection ("true|false") @@ -767,7 +800,7 @@ void ParameterHandler::print_parameters_section (ostream &out, -void ParameterHandler::log_parameters_section (LogStream &out) +void ParameterHandler::log_parameters_section (LogStream &out) { Section *pd = get_present_defaults_subsection (); Section *pc = get_present_changed_subsection (); @@ -1002,7 +1035,20 @@ const ParameterHandler::Section* ParameterHandler::get_present_changed_subsectio }; -ParameterHandler::Section::~Section () { + +unsigned int +ParameterHandler::memory_consumption () const +{ + return (MemoryConsumption::memory_consumption (status) + + MemoryConsumption::memory_consumption (subsection_path) + + MemoryConsumption::memory_consumption (defaults) + + MemoryConsumption::memory_consumption (changed_entries)); +}; + + + +ParameterHandler::Section::~Section () +{ entries.clear (); map::iterator p; @@ -1010,12 +1056,28 @@ ParameterHandler::Section::~Section () { for (p=subsections.begin(); p!=subsections.end(); ++p) delete p->second; + subsections.clear (); +}; + + -subsections.clear (); +unsigned int +ParameterHandler::Section::memory_consumption () const +{ + unsigned int mem = 0; + for (EntryType::const_iterator i=entries.begin(); i!=entries.end(); ++i) + mem += (MemoryConsumption::memory_consumption (i->first) + + MemoryConsumption::memory_consumption (i->second.first) + + MemoryConsumption::memory_consumption (*i->second.second)); + for (map::const_iterator i=subsections.begin(); i!=subsections.end(); ++i) + mem += (MemoryConsumption::memory_consumption (i->first) + + MemoryConsumption::memory_consumption (*(i->second))); + return mem; }; + MultipleParameterLoop::MultipleParameterLoop() : n_branches(0) {}; @@ -1224,6 +1286,19 @@ void MultipleParameterLoop::fill_entry_values (const unsigned int run_no) + +unsigned int +MultipleParameterLoop::memory_consumption () const +{ + unsigned int mem = ParameterHandler::memory_consumption (); + for (unsigned int i=0; i &ssp, const string& Name, const string& Value) : @@ -1279,3 +1354,13 @@ void MultipleParameterLoop::Entry::split_different_values () }; +unsigned int +MultipleParameterLoop::Entry::memory_consumption () const +{ + return (MemoryConsumption::memory_consumption (subsection_path) + + MemoryConsumption::memory_consumption (entry_name) + + MemoryConsumption::memory_consumption (entry_value) + + MemoryConsumption::memory_consumption (different_values) + + sizeof (type)); +}; + diff --git a/deal.II/base/source/quadrature.cc b/deal.II/base/source/quadrature.cc index e95a9adedf..4009ab68ba 100644 --- a/deal.II/base/source/quadrature.cc +++ b/deal.II/base/source/quadrature.cc @@ -14,6 +14,7 @@ #include #include +#include #include @@ -179,6 +180,16 @@ const vector & Quadrature<0>::get_weights () const +template +unsigned int +Quadrature::memory_consumption () const +{ + return (MemoryConsumption::memory_consumption (quadrature_points) + + MemoryConsumption::memory_consumption (weights)); +}; + + + template <> void QProjector<2>::project_to_face (const Quadrature<1> &quadrature, const unsigned int face_no, diff --git a/deal.II/deal.II/include/dofs/dof_constraints.h b/deal.II/deal.II/include/dofs/dof_constraints.h index 526304a923..62999bfb9e 100644 --- a/deal.II/deal.II/include/dofs/dof_constraints.h +++ b/deal.II/deal.II/include/dofs/dof_constraints.h @@ -386,6 +386,13 @@ class ConstraintMatrix : public Subscriptor */ void print (ostream &) const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Exception diff --git a/deal.II/deal.II/include/dofs/dof_handler.h b/deal.II/deal.II/include/dofs/dof_handler.h index a63945377e..4fcd1af23d 100644 --- a/deal.II/deal.II/include/dofs/dof_handler.h +++ b/deal.II/deal.II/include/dofs/dof_handler.h @@ -1000,6 +1000,20 @@ class DoFHandler : public Subscriptor, */ const Triangulation & get_tria () const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + * + * This function is made virtual, + * since a dof handler object + * might be accessed through a + * pointers to thisr base class, + * although the actual object + * might be a derived class. + */ + virtual unsigned int memory_consumption () const; + /** * Exception */ diff --git a/deal.II/deal.II/include/dofs/dof_levels.h b/deal.II/deal.II/include/dofs/dof_levels.h index a5c11806ea..931a76de10 100644 --- a/deal.II/deal.II/include/dofs/dof_levels.h +++ b/deal.II/deal.II/include/dofs/dof_levels.h @@ -91,6 +91,13 @@ class DoFLevel<1> * detailed information. */ vector line_dofs; + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; }; @@ -111,6 +118,13 @@ class DoFLevel<2> : public DoFLevel<1> * detailed information. */ vector quad_dofs; + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; }; @@ -131,6 +145,13 @@ class DoFLevel<3> : public DoFLevel<2> * detailed information. */ vector hex_dofs; + + /** + * 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/fe/fe.h b/deal.II/deal.II/include/fe/fe.h index ebd8319e3a..e76da58d47 100644 --- a/deal.II/deal.II/include/fe/fe.h +++ b/deal.II/deal.II/include/fe/fe.h @@ -349,6 +349,19 @@ class FiniteElementBase : public Subscriptor, */ bool restriction_is_additive (const unsigned int component) const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + * + * This function is made virtual, + * since finite element objects + * are usually accessed through + * pointers to their base class, + * rather than the class itself. + */ + virtual unsigned int memory_consumption () const; + /** * Exception */ diff --git a/deal.II/deal.II/include/fe/fe_lib.criss_cross.h b/deal.II/deal.II/include/fe/fe_lib.criss_cross.h index d927390925..3a0a8eca4c 100644 --- a/deal.II/deal.II/include/fe/fe_lib.criss_cross.h +++ b/deal.II/deal.II/include/fe/fe_lib.criss_cross.h @@ -172,7 +172,8 @@ * @author Wolfgang Bangerth, 1998 */ template -class FECrissCross : public FiniteElement { +class FECrissCross : public FiniteElement +{ public: /** * Constructor @@ -348,6 +349,7 @@ class FECrissCross : public FiniteElement { }; + /** * Quadrature formula for the criss-cross element. This quadrature * formula uses one point at the barycenter of each of the four subtriangles. @@ -356,7 +358,8 @@ class FECrissCross : public FiniteElement { * formula is not implemented for one space dimension. */ template -class QCrissCross1 : public Quadrature { +class QCrissCross1 : public Quadrature +{ public: QCrissCross1 (); diff --git a/deal.II/deal.II/include/fe/fe_system.h b/deal.II/deal.II/include/fe/fe_system.h index 74cbf06841..de52dd70b6 100644 --- a/deal.II/deal.II/include/fe/fe_system.h +++ b/deal.II/deal.II/include/fe/fe_system.h @@ -430,6 +430,19 @@ class FESystem : public FiniteElement */ virtual const FiniteElement& base_element(unsigned int index) const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + * + * This function is made virtual, + * since finite element objects + * are usually accessed through + * pointers to their base class, + * rather than the class itself. + */ + virtual unsigned int memory_consumption () const; + private: /** @@ -449,7 +462,7 @@ class FESystem : public FiniteElement * created by the constructor and * constant afterwards. */ - vector< ElementPair > base_elements; + vector base_elements; /** diff --git a/deal.II/deal.II/include/fe/fe_values.h b/deal.II/deal.II/include/fe/fe_values.h index e32fdc8ba6..60721f32f1 100644 --- a/deal.II/deal.II/include/fe/fe_values.h +++ b/deal.II/deal.II/include/fe/fe_values.h @@ -584,6 +584,13 @@ class FEValuesBase */ const DoFHandler::cell_iterator & get_cell() const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Exception */ @@ -787,6 +794,7 @@ class FEValuesBase }; + /** * Represent a finite element evaluated with a specific quadrature rule on * a cell. @@ -852,6 +860,13 @@ class FEValues : public FEValuesBase */ void reinit (const typename DoFHandler::cell_iterator &); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + private: /** * Store the gradients of the shape @@ -1009,6 +1024,13 @@ class FEFaceValuesBase : public FEValuesBase */ DoFHandler::face_iterator get_face() const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + protected: /** @@ -1090,6 +1112,7 @@ class FEFaceValuesBase : public FEValuesBase }; + /** * Represent a finite element evaluated with a specific quadrature rule on * the face of a cell. diff --git a/deal.II/deal.II/include/grid/grid_out.h b/deal.II/deal.II/include/grid/grid_out.h index d0f0c30a3f..c7e7780576 100644 --- a/deal.II/deal.II/include/grid/grid_out.h +++ b/deal.II/deal.II/include/grid/grid_out.h @@ -548,6 +548,12 @@ class GridOut */ static string get_output_format_names (); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; /** * Exception diff --git a/deal.II/deal.II/include/grid/intergrid_map.h b/deal.II/deal.II/include/grid/intergrid_map.h index 527e6a0579..d654f2ff3c 100644 --- a/deal.II/deal.II/include/grid/intergrid_map.h +++ b/deal.II/deal.II/include/grid/intergrid_map.h @@ -175,6 +175,13 @@ class InterGridMap * destination grid. */ const GridClass & get_destination_grid () const; + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; /** * Exception diff --git a/deal.II/deal.II/include/grid/persistent_tria.h b/deal.II/deal.II/include/grid/persistent_tria.h index 82c83753c5..61558aef80 100644 --- a/deal.II/deal.II/include/grid/persistent_tria.h +++ b/deal.II/deal.II/include/grid/persistent_tria.h @@ -200,6 +200,13 @@ class PersistentTriangulation : public Triangulation */ virtual void read_flags(istream &in); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + virtual unsigned int memory_consumption () const; + /** * Exception. */ diff --git a/deal.II/deal.II/include/grid/tria.h b/deal.II/deal.II/include/grid/tria.h index 51d5239bef..a77b956102 100644 --- a/deal.II/deal.II/include/grid/tria.h +++ b/deal.II/deal.II/include/grid/tria.h @@ -398,6 +398,13 @@ struct TriaNumberCache<1> * by default. */ TriaNumberCache (); + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; }; @@ -451,6 +458,13 @@ struct TriaNumberCache<2> : public TriaNumberCache<1> * by default. */ TriaNumberCache (); + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; }; @@ -504,6 +518,13 @@ struct TriaNumberCache<3> : public TriaNumberCache<2> * by default. */ TriaNumberCache (); + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; }; @@ -2842,6 +2863,20 @@ class Triangulation : public TriaDimensionInfo, unsigned int max_adjacent_cells () const; /*@}*/ + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + * + * This function is made virtual, + * since a triangulation object + * might be accessed through a + * pointer to this base class, + * even if the actual object is a + * derived class. + */ + virtual unsigned int memory_consumption () const; + /** * @name Exceptions @@ -2981,7 +3016,7 @@ class Triangulation : public TriaDimensionInfo, vector &v, const unsigned int magic_number2, istream &in); - + private: /** * Refine all cells on all levels which @@ -3089,7 +3124,13 @@ class Triangulation : public TriaDimensionInfo, vector vertices_used; /** - * Collection of boundary objects. + * Collection of boundary + * objects. We only need 255 + * objects rather than 256, + * since the indicator 255 is + * reserved for interior faces + * and can thus never be + * associated with a boundary. */ const Boundary* boundary[255]; diff --git a/deal.II/deal.II/include/grid/tria_hex.h b/deal.II/deal.II/include/grid/tria_hex.h index 86f8e18fa8..d4fa9f5ae1 100644 --- a/deal.II/deal.II/include/grid/tria_hex.h +++ b/deal.II/deal.II/include/grid/tria_hex.h @@ -64,6 +64,13 @@ class Hexahedron */ void set_quad (const int i, const int index); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + static unsigned int memory_consumption (); + /** * Exception */ @@ -113,4 +120,12 @@ void Hexahedron::set_quad (const int i, const int index) }; + +inline +unsigned int +Hexahedron::memory_consumption () +{ + return sizeof(Hexahedron); +}; + #endif diff --git a/deal.II/deal.II/include/grid/tria_iterator.h b/deal.II/deal.II/include/grid/tria_iterator.h index 87d88a2a0d..b1ba1a4d16 100644 --- a/deal.II/deal.II/include/grid/tria_iterator.h +++ b/deal.II/deal.II/include/grid/tria_iterator.h @@ -460,6 +460,14 @@ class TriaRawIterator : public bidirectional_iterator void print (ostream &out) const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + + /**@name Exceptions*/ /*@{*/ /** @@ -507,7 +515,8 @@ class TriaRawIterator : public bidirectional_iterator * @em{used} lines, quads, cells, etc. */ template -class TriaIterator : public TriaRawIterator { +class TriaIterator : public TriaRawIterator +{ public: /** * Empty constructor. Such an object @@ -653,7 +662,8 @@ class TriaIterator : public TriaRawIterator { * refined and thus a cell on which calculations on the finest level are done. */ template -class TriaActiveIterator : public TriaIterator { +class TriaActiveIterator : public TriaIterator +{ public: /** * Empty constructor. Such an object @@ -940,6 +950,16 @@ TriaRawIterator::print (ostream &out) const +template +inline +unsigned int +TriaRawIterator::memory_consumption () const +{ + return sizeof(TriaRawIterator); +}; + + + template template inline diff --git a/deal.II/deal.II/include/grid/tria_levels.h b/deal.II/deal.II/include/grid/tria_levels.h index b4dcba9959..7d622d6c78 100644 --- a/deal.II/deal.II/include/grid/tria_levels.h +++ b/deal.II/deal.II/include/grid/tria_levels.h @@ -156,6 +156,13 @@ class TriangulationLevel<0> */ void monitor_memory (const unsigned int true_dimension) const; + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + /** * Exception */ @@ -318,6 +325,13 @@ class TriangulationLevel<1> : public TriangulationLevel<0> * @ref{TriangulationLevel} classes. */ void monitor_memory (const unsigned int true_dimension) const; + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; }; @@ -353,21 +367,26 @@ class TriangulationLevel<2> : public TriangulationLevel<1> */ vector quads; /** - * Same as for the @ref{TriangulationLevel<1>::LinesData}@p{::chilren} - * array, but since there are four - * children, the index points to the - * first while the other three are - * following immediately afterwards. + * Same as for the + * @ref{TriangulationLevel<1>::LinesData}@p{::chilren} + * array, but since there + * are four children, the + * index points to the first + * while the other three are + * following immediately + * afterwards. */ vector children; /** - * Same as for @ref{TriangulationLevel<1>::LinesData}@p{::used}. + * Same as for + * @ref{TriangulationLevel<1>::LinesData}@p{::used}. */ vector used; /** - * Same as for @ref{TriangulationLevel<1>::LinesData}@p{::used}. + * Same as for + * @ref{TriangulationLevel<1>::LinesData}@p{::used}. */ vector user_flags; @@ -425,6 +444,13 @@ class TriangulationLevel<2> : public TriangulationLevel<1> * @ref{TriangulationLevel} classes. */ void monitor_memory (const unsigned int true_dimension) const; + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; }; @@ -450,7 +476,8 @@ class TriangulationLevel<3> : public TriangulationLevel<2> * level. * * It is fully analogous to the - * @ref{TriangulationLevel<1>::LinesData} structure inherited from + * @ref{TriangulationLevel<1>::LinesData} + * structure inherited from * @ref{Triangulation<1>}. */ struct HexesData @@ -460,21 +487,26 @@ class TriangulationLevel<3> : public TriangulationLevel<2> */ vector hexes; /** - * Same as for the @ref{TriangulationLevel<1>::LinesData}@p{::chilren} - * array, but since there are four - * children, the index points to the - * first while the other three are - * following immediately afterwards. + * Same as for the + * @ref{TriangulationLevel<1>::LinesData}@p{::chilren} + * array, but since there + * are four children, the + * index points to the first + * while the other three are + * following immediately + * afterwards. */ vector children; /** - * Same as for @ref{TriangulationLevel<1>::LinesData}@p{::used}. + * Same as for + * @ref{TriangulationLevel<1>::LinesData}@p{::used}. */ vector used; /** - * Same as for @ref{TriangulationLevel<1>::LinesData}@p{::used}. + * Same as for + * @ref{TriangulationLevel<1>::LinesData}@p{::used}. */ vector user_flags; @@ -532,6 +564,13 @@ class TriangulationLevel<3> : public TriangulationLevel<2> * @ref{TriangulationLevel} classes. */ void monitor_memory (const unsigned int true_dimension) const; + + /** + * 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/grid/tria_line.h b/deal.II/deal.II/include/grid/tria_line.h index ba4afc90ce..0f86ce87d3 100644 --- a/deal.II/deal.II/include/grid/tria_line.h +++ b/deal.II/deal.II/include/grid/tria_line.h @@ -52,6 +52,13 @@ class Line */ void set_vertex (const int i, const int index); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + static unsigned int memory_consumption (); + /** * Exception */ @@ -71,7 +78,7 @@ class Line /*----------------------------- Inline Function: Line ------------------------*/ -inline // wahrlich inline hier! +inline // truly in-line here! Line::Line (const int i0, const int i1) { end_points[0] = i0; @@ -99,4 +106,13 @@ void Line::set_vertex (const int i, const int index) }; + +inline +unsigned int +Line::memory_consumption () +{ + return sizeof(Line); +}; + + #endif diff --git a/deal.II/deal.II/include/grid/tria_quad.h b/deal.II/deal.II/include/grid/tria_quad.h index 56820e999d..61641c511c 100644 --- a/deal.II/deal.II/include/grid/tria_quad.h +++ b/deal.II/deal.II/include/grid/tria_quad.h @@ -60,6 +60,13 @@ class Quad */ void set_line (const int i, const int index); + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + static unsigned int memory_consumption (); + /** * Exception */ @@ -105,4 +112,12 @@ void Quad::set_line (const int i, const int index) }; + +inline +unsigned int +Quad::memory_consumption () +{ + return sizeof(Quad); +}; + #endif diff --git a/deal.II/deal.II/source/dofs/dof_handler.cc b/deal.II/deal.II/source/dofs/dof_handler.cc index e3336135d3..5fb6a07912 100644 --- a/deal.II/deal.II/source/dofs/dof_handler.cc +++ b/deal.II/deal.II/source/dofs/dof_handler.cc @@ -12,6 +12,7 @@ //---------------------------- dof_handler.cc --------------------------- +#include #include #include #include @@ -1253,6 +1254,24 @@ const Triangulation & DoFHandler::get_tria () const +template +unsigned int +DoFHandler::memory_consumption () const +{ + unsigned int mem = (MemoryConsumption::memory_consumption (tria) + + MemoryConsumption::memory_consumption (selected_fe) + + MemoryConsumption::memory_consumption (tria) + + MemoryConsumption::memory_consumption (levels) + + MemoryConsumption::memory_consumption (used_dofs) + + MemoryConsumption::memory_consumption (vertex_dofs)); + for (unsigned int i=0; i void DoFHandler::distribute_dofs (const FiniteElement &ff, const unsigned int offset) diff --git a/deal.II/deal.II/source/dofs/dof_levels.cc b/deal.II/deal.II/source/dofs/dof_levels.cc new file mode 100644 index 0000000000..bbde931123 --- /dev/null +++ b/deal.II/deal.II/source/dofs/dof_levels.cc @@ -0,0 +1,41 @@ +//---------------------------- dof_levels.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- dof_levels.cc --------------------------- + + +#include +#include + + +unsigned int +DoFLevel<1>::memory_consumption () const +{ + return MemoryConsumption::memory_consumption (line_dofs); +}; + + + +unsigned int +DoFLevel<2>::memory_consumption () const +{ + return (DoFLevel<1>::memory_consumption () + + MemoryConsumption::memory_consumption (quad_dofs)); +}; + + + +unsigned int +DoFLevel<3>::memory_consumption () const +{ + return (DoFLevel<2>::memory_consumption () + + MemoryConsumption::memory_consumption (hex_dofs)); +}; diff --git a/deal.II/deal.II/source/fe/fe.cc b/deal.II/deal.II/source/fe/fe.cc index d9234f41d7..6813a265d4 100644 --- a/deal.II/deal.II/source/fe/fe.cc +++ b/deal.II/deal.II/source/fe/fe.cc @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -246,6 +247,28 @@ bool FiniteElementBase::operator == (const FiniteElementBase &f) const }; + +template +unsigned int +FiniteElementBase::memory_consumption () const +{ + return (sizeof(FiniteElementData) + + MemoryConsumption:: + memory_consumption, sizeof(restriction)/sizeof(restriction[0])> + (restriction)+ + MemoryConsumption::memory_consumption + , sizeof(prolongation)/sizeof(prolongation[0])> + (prolongation) + + MemoryConsumption::memory_consumption (interface_constraints) + + MemoryConsumption::memory_consumption (system_to_component_table) + + MemoryConsumption::memory_consumption (face_system_to_component_table) + + MemoryConsumption::memory_consumption (component_to_system_table) + + MemoryConsumption::memory_consumption (face_component_to_system_table) + + MemoryConsumption::memory_consumption (component_to_base_table) + + MemoryConsumption::memory_consumption (restriction_is_additive_flags)); +}; + + /*------------------------------- FiniteElement ----------------------*/ diff --git a/deal.II/deal.II/source/fe/fe_system.cc b/deal.II/deal.II/source/fe/fe_system.cc index 54979a122b..b91fe98f89 100644 --- a/deal.II/deal.II/source/fe/fe_system.cc +++ b/deal.II/deal.II/source/fe/fe_system.cc @@ -12,6 +12,7 @@ //---------------------------- fe_system.cc --------------------------- +#include #include #include #include @@ -1069,6 +1070,26 @@ FESystem::fill_fe_values (const DoFHandler::cell_iterator &cell, } + +template +unsigned int +FESystem::memory_consumption () const +{ + // neglect size of data stored in + // @p{base_elements} due to some + // problems with teh + // compiler. should be neglectable + // after all, considering the size + // of the data of the subelements + unsigned int mem = (FiniteElement::memory_consumption () + + sizeof (base_elements)); + for (unsigned int i=0; i; diff --git a/deal.II/deal.II/source/fe/fe_values.cc b/deal.II/deal.II/source/fe/fe_values.cc index 3e02dbb2f1..c93fc08039 100644 --- a/deal.II/deal.II/source/fe/fe_values.cc +++ b/deal.II/deal.II/source/fe/fe_values.cc @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -362,6 +363,29 @@ double FEValuesBase::JxW (const unsigned int i) const }; + +template +unsigned int +FEValuesBase::memory_consumption () const +{ + return (MemoryConsumption::memory_consumption (shape_values) + + MemoryConsumption::memory_consumption (shape_gradients) + + MemoryConsumption::memory_consumption (shape_2nd_derivatives) + + MemoryConsumption::memory_consumption (weights) + + MemoryConsumption::memory_consumption (JxW_values) + + MemoryConsumption::memory_consumption (quadrature_points) + + MemoryConsumption::memory_consumption (support_points) + + MemoryConsumption::memory_consumption (jacobi_matrices) + + MemoryConsumption::memory_consumption (jacobi_matrices_grad) + + MemoryConsumption::memory_consumption (shape_values_transform) + + MemoryConsumption::memory_consumption (selected_dataset) + + MemoryConsumption::memory_consumption (jacobi_matrices) + + sizeof(update_flags) + + MemoryConsumption::memory_consumption (present_cell) + + MemoryConsumption::memory_consumption (fe)); +}; + + /*------------------------------- FEValues -------------------------------*/ template @@ -502,6 +526,19 @@ void FEValues::reinit (const typename DoFHandler::cell_iterator &cell) }; + +template +unsigned int +FEValues::memory_consumption () const +{ + return (FEValuesBase::memory_consumption () + + MemoryConsumption::memory_consumption (unit_shape_gradients) + + MemoryConsumption::memory_consumption (unit_shape_2nd_derivatives) + + MemoryConsumption::memory_consumption (unit_shape_gradients_transform) + + MemoryConsumption::memory_consumption (unit_quadrature_points)); +}; + + /*------------------------------- FEFaceValuesBase --------------------------*/ @@ -551,6 +588,24 @@ FEFaceValuesBase::normal_vector (const unsigned int i) const }; + + +template +unsigned int +FEFaceValuesBase::memory_consumption () const +{ + return (FEValuesBase::memory_consumption () + + MemoryConsumption::memory_consumption (unit_shape_gradients) + + MemoryConsumption::memory_consumption (unit_shape_2nd_derivatives) + + MemoryConsumption::memory_consumption (unit_shape_gradients_transform) + + MemoryConsumption::memory_consumption (unit_face_quadrature_points) + + MemoryConsumption::memory_consumption (unit_quadrature_points) + + MemoryConsumption::memory_consumption (face_jacobi_determinants) + + MemoryConsumption::memory_consumption (normal_vectors) + + MemoryConsumption::memory_consumption (present_face)); +}; + + /*------------------------------- FEFaceValues -------------------------------*/ diff --git a/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc b/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc index 983baaeb9b..aa1aa5088d 100644 --- a/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc +++ b/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc @@ -117,8 +117,18 @@ GridOut::parse_output_format (const string &format_name) }; -string GridOut::get_output_format_names () { +string GridOut::get_output_format_names () +{ return "gnuplot|eps"; }; +unsigned int +GridOut::memory_consumption () const +{ + return (sizeof(ucd_flags) + + sizeof(gnuplot_flags) + + sizeof(eps_flags_1) + + sizeof(eps_flags_2) + + sizeof(eps_flags_3)); +}; diff --git a/deal.II/deal.II/source/grid/intergrid_map.cc b/deal.II/deal.II/source/grid/intergrid_map.cc index 6c20a2bad7..1ade48150a 100644 --- a/deal.II/deal.II/source/grid/intergrid_map.cc +++ b/deal.II/deal.II/source/grid/intergrid_map.cc @@ -12,6 +12,7 @@ //---------------------------- intergrid_map.cc --------------------------- +#include #include #include #include @@ -196,7 +197,17 @@ InterGridMap::get_destination_grid () const return *destination_grid; }; - + + +template