[Dune] [Dune-Commit] dune-grid-howto r338 - trunk

Oliver Sander sander at mi.fu-berlin.de
Mon Nov 29 10:41:50 CET 2010


The hard facts are much appreciated.

Am 29.11.2010 10:06, schrieb dedner at dune-project.org:
> Author: dedner
> Date: 2010-11-29 10:06:22 +0100 (Mon, 29 Nov 2010)
> New Revision: 338
>
> Modified:
>     trunk/finitevolumeadapt.hh
> Log:
> Use PersistentConatiner from dune-grid to store data
> during adaptation.
>
> For those who like "hard facts":
> Test with more level of refinement and larger grid,
> using ALUGrid simplex (IdType=int so tr1 provides hash)
> -------------------------------------------------
> std::map:           17m28s
> std::unordered_map: 17m06s (all hash parameters are default)
> std::vector:        14m55s (using the HierarchicIndexSet)
>
>
>
> Modified: trunk/finitevolumeadapt.hh
> ===================================================================
> --- trunk/finitevolumeadapt.hh	2010-11-29 08:45:42 UTC (rev 337)
> +++ trunk/finitevolumeadapt.hh	2010-11-29 09:06:22 UTC (rev 338)
> @@ -1,7 +1,10 @@
> +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
> +// vi: set et ts=4 sw=2 sts=2:
>   #ifndef __DUNE_GRID_HOWTO_FINITEVOLUMEADAPT_HH__
>   #define __DUNE_GRID_HOWTO_FINITEVOLUMEADAPT_HH__
> -#include<map>
> +
>   #include<cmath>
> +#include<dune/grid/utility/persistentcontainer.hh>
>
>   struct RestrictedValue
>   {
> @@ -39,11 +42,6 @@
>     // intersection iterator type
>     typedef typename LeafGridView::IntersectionIterator LeafIntersectionIterator;
>
> -  // global id set types, local means that the numbering is unique in a single process only.
> -  typedef typename G::LocalIdSet IdSet;
> -  // type for the index set, note that this is _not_ an integer
> -  typedef typename IdSet::IdType IdType;
> -
>     // get grid view on leaf grid
>     LeafGridView leafView = grid.leafView();
>
> @@ -118,9 +116,11 @@
>     if( marked==0 )
>       return false;
>
> -  // restrict to coarse elements
> -  std::map<IdType,RestrictedValue>  restrictionmap; // restricted concentration /*@\label{fah:loop4}@*/
> -  const IdSet&  idset = grid.localIdSet();
> +  grid.preAdapt();
> +
> +  typedef Dune::PersistentContainer<G,RestrictedValue>  RestrictionMap;
> +  RestrictionMap restrictionmap(grid,0); // restricted concentration /*@\label{fah:loop4}@*/
> +
>     for (int level=grid.maxLevel(); level>=0; level--)
>       {
>         // get grid view on level grid
> @@ -129,9 +129,7 @@
>              it!=levelView.template end<0>(); ++it)
>   	  {
>   		// get your map entry
> -		IdType idi = idset.id(*it);
> -		RestrictedValue&  rv = restrictionmap[idi];
> -
> +		RestrictedValue&  rv = restrictionmap[*it];
>   		// put your value in the map
>   		if (it->isLeaf())
>   		  {
> @@ -144,14 +142,12 @@
>   		if (it.level()>0)
>   		  {
>   			EntityPointer ep = it->father();
> -			IdType idf = idset.id(*ep);
> -			RestrictedValue&  rvf = restrictionmap[idf];
> +	    	RestrictedValue&  rvf = restrictionmap[*ep];
>   			rvf.value += rv.value/rv.count;
>   			rvf.count += 1;
>   		  }
>   	  }                                            /*@\label{fah:loop5}@*/
> -      }
> -  grid.preAdapt();
> +    }
>
>     // adapt mesh and mapper
>     bool rv=grid.adapt();                                /*@\label{fah:adapt}@*/
> @@ -166,45 +162,40 @@
>              it!=levelView.template end<0>(); ++it)
>   	  {
>   		// get your id
> -		IdType idi = idset.id(*it);
>
>   		// check map entry
> -          typename std::map<IdType,RestrictedValue>::iterator rit
> -              = restrictionmap.find(idi);
> -		if (rit!=restrictionmap.end())
> +        if (! it->isNew() )
>   		  {
>   			// entry is in map, write in leaf
>   			if (it->isLeaf())
>   			  {
> +		        RestrictedValue&  rv = restrictionmap[*it];
>   				int indexi = mapper.map(*it);
> -				c[indexi] = rit->second.value/rit->second.count;
> +				c[indexi] = rv.value/rv.count;
>   			  }
>   		  }
>   		else
>   		  {
> -              // value is not in map, interpolate from father element
> -			if (it.level()>0)
> -			  {
> -				EntityPointer ep = it->father();
> -				IdType idf = idset.id(*ep);
> -				RestrictedValue&  rvf = restrictionmap[idf];
> -				if (it->isLeaf())
> -				  {
> -					int indexi = mapper.map(*it);
> -					c[indexi] = rvf.value/rvf.count;
> -				  }
> -				else
> -				  {
> -					// create new entry
> -					RestrictedValue&  rv = restrictionmap[idi];
> -					rv.value = rvf.value/rvf.count;
> -					rv.count = 1;
> -				  }
> -			  }
> +            // value is not in map, interpolate from father element
> +			assert (it.level()>0);
> +            EntityPointer ep = it->father();
> +            RestrictedValue&  rvf = restrictionmap[*ep];
> +            if (it->isLeaf())
> +              {
> +                int indexi = mapper.map(*it);
> +                c[indexi] = rvf.value/rvf.count;
> +              }
> +            else
> +              {
> +                // create new entry
> +                RestrictedValue&  rv = restrictionmap[*it];
> +                rv.value = rvf.value/rvf.count;
> +                rv.count = 1;
> +              }
>   		  }
>   	  }                                            /*@\label{fah:loop7}@*/
>       }
> -  grid.postAdapt();
> +   grid.postAdapt();
>
>     return rv;
>   }
>
>
> _______________________________________________
> Dune-Commit mailing list
> Dune-Commit at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-commit
>    


-- 
************************************************************************
* Oliver Sander                ** email: sander at mi.fu-berlin.de        *
* Freie Universität Berlin     ** phone: + 49 (30) 838 75348           *
* Institut für Mathematik      ** URL  : page.mi.fu-berlin.de/~sander  *
* Arnimallee 6                 ** -------------------------------------*
* 14195 Berlin, Germany        ** Member of MATHEON (www.matheon.de)   *
************************************************************************





More information about the Dune mailing list