From: bangerth Date: Tue, 9 Nov 2010 16:15:01 +0000 (+0000) Subject: More conversions to compile only once. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c9b058e2a075fb891bf350b3b96ae16ba962dde;p=dealii-svn.git More conversions to compile only once. git-svn-id: https://svn.dealii.org/trunk@22648 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/source/grid/persistent_tria.cc b/deal.II/source/grid/persistent_tria.all_dimensions.cc similarity index 94% rename from deal.II/source/grid/persistent_tria.cc rename to deal.II/source/grid/persistent_tria.all_dimensions.cc index c73f84bcdf..c9544f9131 100644 --- a/deal.II/source/grid/persistent_tria.cc +++ b/deal.II/source/grid/persistent_tria.all_dimensions.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009 by the deal.II authors +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -29,7 +29,7 @@ template PersistentTriangulation:: PersistentTriangulation (const Triangulation &coarse_grid) : - coarse_grid (&coarse_grid, typeid(*this).name()) + coarse_grid (&coarse_grid, typeid(*this).name()) {} @@ -52,14 +52,14 @@ PersistentTriangulation (const PersistentTriangulation &old_tria) template -PersistentTriangulation::~PersistentTriangulation () +PersistentTriangulation::~PersistentTriangulation () {} template void -PersistentTriangulation::execute_coarsening_and_refinement () +PersistentTriangulation::execute_coarsening_and_refinement () { // first save flags refine_flags.push_back (std::vector()); @@ -79,10 +79,10 @@ PersistentTriangulation::execute_coarsening_and_refinement () template void PersistentTriangulation::restore () -{ +{ // for each of the previous // refinement sweeps - for (unsigned int i=0; i::restore (const unsigned int step) { Assert(stepload_refine_flags (refine_flags[step-1]); this->load_coarsen_flags (coarsen_flags[step-1]); @@ -126,7 +126,7 @@ PersistentTriangulation::n_refinement_steps() const template void -PersistentTriangulation::copy_triangulation (const Triangulation &old_grid) +PersistentTriangulation::copy_triangulation (const Triangulation &old_grid) { this->clear (); coarse_grid = &old_grid; @@ -164,7 +164,7 @@ void PersistentTriangulation::write_flags(std::ostream &out) const { const unsigned int n_flag_levels=refine_flags.size(); - + AssertThrow (out, ExcIO()); out << mn_persistent_tria_flags_begin << ' ' << n_flag_levels << std::endl; @@ -176,7 +176,7 @@ PersistentTriangulation::write_flags(std::ostream &out) const this->write_bool_vector (mn_tria_coarsen_flags_begin, coarsen_flags[i], mn_tria_coarsen_flags_end, out); } - + out << mn_persistent_tria_flags_end << std::endl; AssertThrow (out, ExcIO()); @@ -191,7 +191,7 @@ PersistentTriangulation::read_flags(std::istream &in) Assert(refine_flags.size()==0 && coarsen_flags.size()==0, ExcFlagsNotCleared()); AssertThrow (in, ExcIO()); - + unsigned int magic_number; in >> magic_number; AssertThrow(magic_number==mn_persistent_tria_flags_begin, @@ -208,7 +208,7 @@ PersistentTriangulation::read_flags(std::istream &in) this->read_bool_vector (mn_tria_coarsen_flags_begin, coarsen_flags.back(), mn_tria_coarsen_flags_end, in); } - + in >> magic_number; AssertThrow(magic_number==mn_persistent_tria_flags_end, typename Triangulation::ExcGridReadError()); @@ -240,7 +240,9 @@ PersistentTriangulation::memory_consumption () const // explicit instantiations -template class PersistentTriangulation; +template class PersistentTriangulation<1>; +template class PersistentTriangulation<2>; +template class PersistentTriangulation<3>; DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/source/grid/tria_levels.cc b/deal.II/source/grid/tria_levels.all_dimensions.cc similarity index 95% rename from deal.II/source/grid/tria_levels.cc rename to deal.II/source/grid/tria_levels.all_dimensions.cc index c128b11376..b5f4766605 100644 --- a/deal.II/source/grid/tria_levels.cc +++ b/deal.II/source/grid/tria_levels.all_dimensions.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2006, 2007 by the deal.II authors +// Copyright (C) 2006, 2007, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -34,28 +34,28 @@ namespace internal // // note that all arrays should have equal // sizes (checked by @p{monitor_memory} - if (total_cells > refine_flags.size()) + if (total_cells > refine_flags.size()) { refine_flags.reserve (total_cells); refine_flags.insert (refine_flags.end(), total_cells - refine_flags.size(), RefinementCase::no_refinement); - + coarsen_flags.reserve (total_cells); coarsen_flags.insert (coarsen_flags.end(), total_cells - coarsen_flags.size(), false); - + subdomain_ids.reserve (total_cells); subdomain_ids.insert (subdomain_ids.end(), total_cells - subdomain_ids.size(), 0); - + parents.reserve ((int) (total_cells + 1) / 2); parents.insert (parents.end (), (total_cells + 1) / 2 - parents.size (), -1); - + neighbors.reserve (total_cells*(2*dimension)); neighbors.insert (neighbors.end(), total_cells*(2*dimension) - neighbors.size(), @@ -110,8 +110,7 @@ namespace internal // This specialization should be only temporary, until the TriaObjects // classes are straightened out. - -#if deal_II_dimension == 3 + void TriaLevel<3>::reserve_space (const unsigned int total_cells, const unsigned int dimension) @@ -123,28 +122,28 @@ namespace internal // // note that all arrays should have equal // sizes (checked by @p{monitor_memory} - if (total_cells > refine_flags.size()) + if (total_cells > refine_flags.size()) { refine_flags.reserve (total_cells); refine_flags.insert (refine_flags.end(), total_cells - refine_flags.size(), RefinementCase<3>::no_refinement); - + coarsen_flags.reserve (total_cells); coarsen_flags.insert (coarsen_flags.end(), total_cells - coarsen_flags.size(), false); - + subdomain_ids.reserve (total_cells); subdomain_ids.insert (subdomain_ids.end(), total_cells - subdomain_ids.size(), 0); - + parents.reserve ((int) (total_cells + 1) / 2); parents.insert (parents.end (), (total_cells + 1) / 2 - parents.size (), -1); - + neighbors.reserve (total_cells*(2*dimension)); neighbors.insert (neighbors.end(), total_cells*(2*dimension) - neighbors.size(), @@ -194,16 +193,12 @@ namespace internal MemoryConsumption::memory_consumption (cells) + MemoryConsumption::memory_consumption (refine_flags)); } - -#endif - } } -#if deal_II_dimension != 3 -template class internal::Triangulation::TriaLevel; -#endif +template class internal::Triangulation::TriaLevel<1>; +template class internal::Triangulation::TriaLevel<2>; DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/source/grid/tria_objects.all_dimensions.cc b/deal.II/source/grid/tria_objects.all_dimensions.cc index 4950342b1d..a1301d281f 100644 --- a/deal.II/source/grid/tria_objects.all_dimensions.cc +++ b/deal.II/source/grid/tria_objects.all_dimensions.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2006, 2007 by the deal.II authors +// Copyright (C) 2006, 2007, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -21,14 +21,14 @@ #include #include - + DEAL_II_NAMESPACE_OPEN namespace internal { namespace Triangulation - { + { template<> void TriaObjects >::reserve_space (const unsigned int new_lines_in_pairs, @@ -39,7 +39,7 @@ namespace internal next_free_single=0; next_free_pair=0; reverse_order_next_free_single=false; - + // count the number of lines, of // unused single lines and of // unused pairs of lines @@ -83,23 +83,23 @@ namespace internal new_size+=additional_single_lines; // only allocate space if necessary - if (new_size>cells.size()) + if (new_size>cells.size()) { cells.reserve (new_size); cells.insert (cells.end(), new_size-cells.size(), TriaObject<1> ()); - + used.reserve (new_size); used.insert (used.end(), new_size-used.size(), false); - + user_flags.reserve (new_size); user_flags.insert (user_flags.end(), new_size-user_flags.size(), false); - + children.reserve (new_size); children.insert (children.end(), new_size-children.size(), @@ -124,13 +124,114 @@ namespace internal } + template <> + template + typename dealii::Triangulation::raw_line_iterator + TriaObjects >::next_free_single_line (const dealii::Triangulation &tria) + { + // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. + + int pos=next_free_single, + last=used.size()-1; + if (!reverse_order_next_free_single) + { + // first sweep forward, only use + // really single slots, do not use + // pair slots + for (; pos=last) + { + reverse_order_next_free_single=true; + next_free_single=used.size()-1; + pos=used.size()-1; + } + else + next_free_single=pos+1; + } + + if(reverse_order_next_free_single) + { + // second sweep, use all slots, even + // in pairs + for(;pos>=0;--pos) + if (!used[pos]) + break; + if (pos>0) + next_free_single=pos-1; + else + // no valid single line anymore + return tria.end_line(); + } + + return typename dealii::Triangulation::raw_line_iterator(&tria,0,pos); + } + + + + template <> + template + typename dealii::Triangulation::raw_line_iterator + TriaObjects >::next_free_pair_line (const dealii::Triangulation &tria) + { + // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. + + int pos=next_free_pair, + last=used.size()-1; + for (; pos=last) + // no free slot + return tria.end_line(); + else + next_free_pair=pos+2; + + return typename dealii::Triangulation::raw_line_iterator(&tria,0,pos); + } + + + + template <> + template + typename dealii::Triangulation::raw_quad_iterator + TriaObjects >::next_free_single_quad (const dealii::Triangulation &tria) + { + Assert(false, ExcWrongIterator("quad","line")); + return tria.end_quad(); + } + + + + template <> + template + typename dealii::Triangulation::raw_quad_iterator + TriaObjects >::next_free_pair_quad (const dealii::Triangulation &tria) + { + Assert(false, ExcWrongIterator("quad","line")); + return tria.end_quad(); + } + + + template<> void TriaObjects >::reserve_space (const unsigned int new_quads_in_pairs, const unsigned int new_quads_single) { Assert(new_quads_in_pairs%2==0, ExcInternalError()); - + next_free_single=0; next_free_pair=0; reverse_order_next_free_single=false; @@ -184,17 +285,17 @@ namespace internal cells.insert (cells.end(), new_size-cells.size(), TriaObject<2> ()); - + used.reserve (new_size); used.insert (used.end(), new_size-used.size(), false); - + user_flags.reserve (new_size); user_flags.insert (user_flags.end(), new_size-user_flags.size(), false); - + children.reserve (2*new_size); children.insert (children.end(), 2*new_size-children.size(), @@ -204,7 +305,7 @@ namespace internal refinement_cases.insert (refinement_cases.end(), new_size - refinement_cases.size(), RefinementCase<2>::no_refinement); - + material_id.reserve (new_size); material_id.insert (material_id.end(), @@ -225,6 +326,139 @@ namespace internal } + + + template <> + template + typename dealii::Triangulation::raw_quad_iterator + TriaObjects >::next_free_single_quad (const dealii::Triangulation &tria) + { + // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. + + int pos=next_free_single, + last=used.size()-1; + if (!reverse_order_next_free_single) + { + // first sweep forward, only use + // really single slots, do not use + // pair slots + for (; pos=last) + { + reverse_order_next_free_single=true; + next_free_single=used.size()-1; + pos=used.size()-1; + } + else + next_free_single=pos+1; + } + + if(reverse_order_next_free_single) + { + // second sweep, use all slots, even + // in pairs + for(;pos>=0;--pos) + if (!used[pos]) + break; + if (pos>0) + next_free_single=pos-1; + else + // no valid single quad anymore + return tria.end_quad(); + } + + return typename dealii::Triangulation::raw_quad_iterator(&tria,0,pos); + } + + + + template <> + template + typename dealii::Triangulation::raw_quad_iterator + TriaObjects >::next_free_pair_quad (const dealii::Triangulation &tria) + { + // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. + + int pos=next_free_pair, + last=used.size()-1; + for (; pos=last) + // no free slot + return tria.end_quad(); + else + next_free_pair=pos+2; + + return typename dealii::Triangulation::raw_quad_iterator(&tria,0,pos); + } + + + template <> + template + typename dealii::Triangulation::raw_line_iterator + TriaObjects >::next_free_single_line (const dealii::Triangulation &tria) + { + Assert(false, ExcWrongIterator("line","quad")); + return tria.end_line(); + } + + + + template <> + template + typename dealii::Triangulation::raw_line_iterator + TriaObjects >::next_free_pair_line (const dealii::Triangulation &tria) + { + Assert(false, ExcWrongIterator("line","quad")); + return tria.end_line(); + } + + + + + template <> + template + typename dealii::Triangulation::raw_hex_iterator + TriaObjects >::next_free_hex (const dealii::Triangulation &tria, + const unsigned int level) + { + // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. + + int pos=next_free_pair, + last=used.size()-1; + for (; pos=last) + // no free slot + return tria.end_hex(); + else + next_free_pair=pos+2; + + return typename dealii::Triangulation::raw_hex_iterator(&tria,level,pos); + } + + + + + void TriaObjectsHex::reserve_space (const unsigned int new_hexes) { @@ -240,17 +474,17 @@ namespace internal cells.insert (cells.end(), new_size-cells.size(), TriaObject<3> ()); - + used.reserve (new_size); used.insert (used.end(), new_size-used.size(), false); - + user_flags.reserve (new_size); user_flags.insert (user_flags.end(), new_size-user_flags.size(), false); - + children.reserve (4*new_size); children.insert (children.end(), 4*new_size-children.size(), @@ -343,7 +577,7 @@ namespace internal used.size() + new_quads_in_pairs - 2*n_unused_pairs; if (additional_single_quads>0) new_size+=additional_single_quads; - + // see above... if (new_size>cells.size()) { @@ -364,7 +598,7 @@ namespace internal reverse_order_next_free_single=true; } } - + template<> void @@ -514,7 +748,7 @@ namespace internal ExcMemoryInexact (cells.size() * GeometryInfo<2>::lines_per_cell, line_orientations.size())); TriaObjects >::monitor_memory (3); - + } @@ -531,7 +765,7 @@ namespace internal user_data.clear(); user_data_type = data_unknown; } - + void TriaObjectsHex::clear() @@ -549,8 +783,8 @@ namespace internal TriaObjects >::clear(); line_orientations.clear(); } - - + + template unsigned int TriaObjects::memory_consumption () const @@ -563,7 +797,7 @@ namespace internal MemoryConsumption::memory_consumption (refinement_cases) + user_data.capacity() * sizeof(UserData) + sizeof(user_data)); } - + unsigned int TriaObjectsHex::memory_consumption () const @@ -582,12 +816,13 @@ namespace internal this->TriaObjects >::memory_consumption() ); } - - // explicit instantiations +// explicit instantiations template class TriaObjects >; template class TriaObjects >; + + #include "tria_objects.inst" } } diff --git a/deal.II/source/grid/tria_objects.cc b/deal.II/source/grid/tria_objects.cc deleted file mode 100644 index d284273579..0000000000 --- a/deal.II/source/grid/tria_objects.cc +++ /dev/null @@ -1,289 +0,0 @@ -//--------------------------------------------------------------------------- -// $Id$ -// Version: $Name$ -// -// Copyright (C) 2006, 2007 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. -// -//--------------------------------------------------------------------------- - - -#include -#include -#include -#include -#include - - - -DEAL_II_NAMESPACE_OPEN - -namespace internal -{ - namespace Triangulation - { - template <> - template - typename dealii::Triangulation::raw_line_iterator - TriaObjects >::next_free_single_line (const dealii::Triangulation &tria) - { - // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. - - int pos=next_free_single, - last=used.size()-1; - if (!reverse_order_next_free_single) - { - // first sweep forward, only use - // really single slots, do not use - // pair slots - for (; pos=last) - { - reverse_order_next_free_single=true; - next_free_single=used.size()-1; - pos=used.size()-1; - } - else - next_free_single=pos+1; - } - - if(reverse_order_next_free_single) - { - // second sweep, use all slots, even - // in pairs - for(;pos>=0;--pos) - if (!used[pos]) - break; - if (pos>0) - next_free_single=pos-1; - else - // no valid single line anymore - return tria.end_line(); - } - - return typename dealii::Triangulation::raw_line_iterator(&tria,0,pos); - } - - - - template <> - template - typename dealii::Triangulation::raw_line_iterator - TriaObjects >::next_free_pair_line (const dealii::Triangulation &tria) - { - // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. - - int pos=next_free_pair, - last=used.size()-1; - for (; pos=last) - // no free slot - return tria.end_line(); - else - next_free_pair=pos+2; - - return typename dealii::Triangulation::raw_line_iterator(&tria,0,pos); - } - - - - template <> - template - typename dealii::Triangulation::raw_quad_iterator - TriaObjects >::next_free_single_quad (const dealii::Triangulation &tria) - { - Assert(false, ExcWrongIterator("quad","line")); - return tria.end_quad(); - } - - - - template <> - template - typename dealii::Triangulation::raw_quad_iterator - TriaObjects >::next_free_pair_quad (const dealii::Triangulation &tria) - { - Assert(false, ExcWrongIterator("quad","line")); - return tria.end_quad(); - } - - - - template <> - template - typename dealii::Triangulation::raw_quad_iterator - TriaObjects >::next_free_single_quad (const dealii::Triangulation &tria) - { - // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. - - int pos=next_free_single, - last=used.size()-1; - if (!reverse_order_next_free_single) - { - // first sweep forward, only use - // really single slots, do not use - // pair slots - for (; pos=last) - { - reverse_order_next_free_single=true; - next_free_single=used.size()-1; - pos=used.size()-1; - } - else - next_free_single=pos+1; - } - - if(reverse_order_next_free_single) - { - // second sweep, use all slots, even - // in pairs - for(;pos>=0;--pos) - if (!used[pos]) - break; - if (pos>0) - next_free_single=pos-1; - else - // no valid single quad anymore - return tria.end_quad(); - } - - return typename dealii::Triangulation::raw_quad_iterator(&tria,0,pos); - } - - - - template <> - template - typename dealii::Triangulation::raw_quad_iterator - TriaObjects >::next_free_pair_quad (const dealii::Triangulation &tria) - { - // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. - - int pos=next_free_pair, - last=used.size()-1; - for (; pos=last) - // no free slot - return tria.end_quad(); - else - next_free_pair=pos+2; - - return typename dealii::Triangulation::raw_quad_iterator(&tria,0,pos); - } - - - template <> - template - typename dealii::Triangulation::raw_line_iterator - TriaObjects >::next_free_single_line (const dealii::Triangulation &tria) - { - Assert(false, ExcWrongIterator("line","quad")); - return tria.end_line(); - } - - - - template <> - template - typename dealii::Triangulation::raw_line_iterator - TriaObjects >::next_free_pair_line (const dealii::Triangulation &tria) - { - Assert(false, ExcWrongIterator("line","quad")); - return tria.end_line(); - } - - - - template <> - template - typename dealii::Triangulation::raw_hex_iterator - TriaObjects >::next_free_hex (const dealii::Triangulation &tria, - const unsigned int level) - { - // TODO: Think of a way to ensure that we are using the correct triangulation, i.e. the one containing *this. - - int pos=next_free_pair, - last=used.size()-1; - for (; pos=last) - // no free slot - return tria.end_hex(); - else - next_free_pair=pos+2; - - return typename dealii::Triangulation::raw_hex_iterator(&tria,level,pos); - } - - - - - - // explicit instantiations - -#if deal_II_dimension > 1 - template dealii::Triangulation::raw_line_iterator - TriaObjects >::next_free_single_line(const dealii::Triangulation &); - template dealii::Triangulation::raw_line_iterator - TriaObjects >::next_free_pair_line(const dealii::Triangulation &); - template dealii::Triangulation::raw_quad_iterator - TriaObjects >::next_free_single_quad(const dealii::Triangulation &); - template dealii::Triangulation::raw_quad_iterator - TriaObjects >::next_free_pair_quad(const dealii::Triangulation &); - - template dealii::Triangulation::raw_line_iterator - TriaObjects >::next_free_single_line(const dealii::Triangulation &); - template dealii::Triangulation::raw_line_iterator - TriaObjects >::next_free_pair_line(const dealii::Triangulation &); - template dealii::Triangulation::raw_quad_iterator - TriaObjects >::next_free_single_quad(const dealii::Triangulation &); - template dealii::Triangulation::raw_quad_iterator - TriaObjects >::next_free_pair_quad(const dealii::Triangulation &); -#endif -#if deal_II_dimension == 3 - template dealii::Triangulation::raw_hex_iterator - TriaObjects >::next_free_hex(const dealii::Triangulation &, const unsigned int); -#endif - } -} - -DEAL_II_NAMESPACE_CLOSE - diff --git a/deal.II/source/grid/tria_objects.inst.in b/deal.II/source/grid/tria_objects.inst.in new file mode 100644 index 0000000000..76fc1259ad --- /dev/null +++ b/deal.II/source/grid/tria_objects.inst.in @@ -0,0 +1,39 @@ +//--------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2006, 2007, 2010 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. +// +//--------------------------------------------------------------------------- + +for (deal_II_dimension : DIMENSIONS) + { +#if deal_II_dimension > 1 + template dealii::Triangulation::raw_line_iterator + TriaObjects >::next_free_single_line(const dealii::Triangulation &); + template dealii::Triangulation::raw_line_iterator + TriaObjects >::next_free_pair_line(const dealii::Triangulation &); + template dealii::Triangulation::raw_quad_iterator + TriaObjects >::next_free_single_quad(const dealii::Triangulation &); + template dealii::Triangulation::raw_quad_iterator + TriaObjects >::next_free_pair_quad(const dealii::Triangulation &); + + template dealii::Triangulation::raw_line_iterator + TriaObjects >::next_free_single_line(const dealii::Triangulation &); + template dealii::Triangulation::raw_line_iterator + TriaObjects >::next_free_pair_line(const dealii::Triangulation &); + template dealii::Triangulation::raw_quad_iterator + TriaObjects >::next_free_single_quad(const dealii::Triangulation &); + template dealii::Triangulation::raw_quad_iterator + TriaObjects >::next_free_pair_quad(const dealii::Triangulation &); +#endif +#if deal_II_dimension == 3 + template dealii::Triangulation::raw_hex_iterator + TriaObjects >::next_free_hex(const dealii::Triangulation &, const unsigned int); +#endif + }