~ubuntu-branches/ubuntu/utopic/dune-grid/utopic-proposed

« back to all changes in this revision

Viewing changes to dune/grid/utility/test/persistentcontainertest.cc

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2014-02-14 10:49:16 UTC
  • mfrom: (1.3.1) (5.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20140214104916-2clchnny3eu7ks4w
Tags: 2.3.0-2
InstallĀ /usr/share/dune-grid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi: set et ts=4 sw=2 sts=2:
1
3
/** \file
2
4
    \brief A unit test for the PersistentContainer
3
 
*/
 
5
 */
4
6
 
5
7
#include <config.h>
6
8
 
7
9
#include <iostream>
8
 
#include <cassert>
9
10
 
10
 
#include <dune/common/mpihelper.hh>
 
11
#include <dune/common/parallel/mpihelper.hh>
11
12
#include <dune/grid/yaspgrid.hh>
12
13
#if HAVE_ALUGRID
13
14
#include <dune/grid/alugrid.hh>
36
37
  PersistentContainer<GridType,DataType> container0(grid,0);
37
38
  PersistentContainer<GridType,DataType> container1(grid,1);
38
39
  PersistentContainer<GridType,DataType> container2(grid,2);
39
 
  
 
40
 
40
41
  typedef typename GridType::LeafGridView GridView;
41
42
  const GridView &view = grid.leafView();
42
43
  typedef typename GridView::template Codim<0>::Iterator EIterator;
46
47
    for(EIterator eit = view.template begin<0>(); eit != eend; ++eit)
47
48
    {
48
49
      container0[*eit] = eit->geometry().center();
49
 
      const Dune::GenericReferenceElement< typename GridType::ctype, GridType::dimension > &refElement
50
 
          = Dune::GenericReferenceElements< typename GridType::ctype, GridType::dimension >::general( eit->type() );
51
 
      for (int i=0;i<eit->template count<1>();++i)
 
50
      const Dune::ReferenceElement< typename GridType::ctype, GridType::dimension > &refElement
 
51
        = Dune::ReferenceElements< typename GridType::ctype, GridType::dimension >::general( eit->type() );
 
52
      for (int i=0; i<eit->template count<1>(); ++i)
52
53
        container1(*eit,i) = eit->geometry().global( refElement.position(i,1) );
53
 
      for (int i=0;i<eit->template count<2>();++i)
 
54
      for (int i=0; i<eit->template count<2>(); ++i)
54
55
        container2(*eit,i) = eit->geometry().global( refElement.position(i,2) );
55
56
    }
56
57
  }
57
58
 
58
59
  grid.globalRefine(1);
59
 
  container0.update();
60
 
  container1.update();
61
 
  container2.update();
 
60
  container0.resize();
 
61
  container1.resize();
 
62
  container2.resize();
62
63
 
63
64
  {
64
65
    const EIterator &eend = view.template end<0>();
65
66
    for(EIterator eit = view.template begin<0>(); eit != eend; ++eit)
66
67
    {
67
 
      if (container0[*eit].used == true) 
 
68
      if (container0[*eit].used == true)
68
69
      {
69
70
        std::cout << "ERROR: a new element is marked as 'used' in the container - stop testing" << std::endl;
70
71
        ret = false;
74
75
      while ( !container0[*up].used )
75
76
      {
76
77
        if (up->level() == 0)
77
 
        {  
 
78
        {
78
79
          std::cout << "ERROR: could not find a father element in container - stop testing" << std::endl;
79
80
          ret = false;
80
81
          break;
87
88
        ret = false;
88
89
        break;
89
90
      }
90
 
      const Dune::GenericReferenceElement< typename GridType::ctype, GridType::dimension > &refElement
91
 
          = Dune::GenericReferenceElements< typename GridType::ctype, GridType::dimension >::general( eit->type() );
92
 
      for (int i=0;i<eit->template count<1>();++i)
 
91
      const Dune::ReferenceElement< typename GridType::ctype, GridType::dimension > &refElement
 
92
        = Dune::ReferenceElements< typename GridType::ctype, GridType::dimension >::general( eit->type() );
 
93
      for (int i=0; i<eit->template count<1>(); ++i)
93
94
        if ( ( container1(*up,i).coord - up->geometry().global( refElement.position(i,1) ) ).two_norm() > 1e-8 )
94
95
        {
95
96
          std::cout << "ERROR: wrong data stored in container1 - stop testing" << std::endl;
96
97
          ret = false;
97
98
          break;
98
99
        }
99
 
      for (int i=0;i<eit->template count<2>();++i)
 
100
      for (int i=0; i<eit->template count<2>(); ++i)
100
101
        if ( ( container2(*up,i).coord - up->geometry().global( refElement.position(i,2) ) ).two_norm() > 1e-8 )
101
102
        {
102
103
          std::cout << "ERROR: wrong data stored in container1 - stop testing" << std::endl;
110
111
 
111
112
int main (int argc , char **argv)
112
113
try {
113
 
  
114
 
    // this method calls MPI_Init, if MPI is enabled
115
 
    MPIHelper::instance(argc,argv);
116
 
    
117
 
    // /////////////////////////////////////////////////////////////////////////////
118
 
    //   Test YaspGrid
119
 
    // /////////////////////////////////////////////////////////////////////////////
120
 
    {
121
 
      typedef YaspGrid<2> GridType;
122
 
      Dune::FieldVector<double,2> Len; Len = 1.0;
123
 
      Dune::FieldVector<int,2> s; s = 2; s[0] = 6;
124
 
      Dune::FieldVector<bool,2> p; p = false;
125
 
      int overlap = 1;
126
 
      GridType grid(Len,s,p,overlap);
127
 
      std::cout << "Testing YaspGrid" << std::endl;
128
 
      test(grid);
129
 
    }
130
 
 
 
114
 
 
115
  // this method calls MPI_Init, if MPI is enabled
 
116
  MPIHelper::instance(argc,argv);
 
117
 
 
118
  // /////////////////////////////////////////////////////////////////////////////
 
119
  //   Test YaspGrid
 
120
  // /////////////////////////////////////////////////////////////////////////////
 
121
  {
 
122
    typedef YaspGrid<2> GridType;
 
123
    Dune::FieldVector<double,2> Len; Len = 1.0;
 
124
    Dune::array<int,2> s = { {2, 6} };
 
125
    std::bitset<2> p;
 
126
    int overlap = 1;
 
127
    GridType grid(Len,s,p,overlap);
 
128
    std::cout << "Testing YaspGrid" << std::endl;
 
129
    test(grid);
 
130
  }
 
131
 
131
132
#if HAVE_ALUGRID
132
 
    {
133
 
      typedef ALUCubeGrid<2,2> GridType;
134
 
      array<unsigned int,2> elements2d;
135
 
      elements2d.fill(4);
136
 
      shared_ptr<GridType> grid = StructuredGridFactory<GridType>::createCubeGrid(FieldVector<double,2>(0),
137
 
                                                                                  FieldVector<double,2>(1), elements2d);
138
 
      std::cout << "Testing ALUGrid" << std::endl;
139
 
      test(*grid);
140
 
    }
 
133
  {
 
134
    typedef Dune::ALUGrid<2, 2, cube, nonconforming> GridType;
 
135
    array<unsigned int,2> elements2d;
 
136
    elements2d.fill(4);
 
137
    shared_ptr<GridType> grid = StructuredGridFactory<GridType>::createCubeGrid(FieldVector<double,2>(0),
 
138
                                                                                FieldVector<double,2>(1), elements2d);
 
139
    std::cout << "Testing ALUGrid" << std::endl;
 
140
    test(*grid);
 
141
  }
141
142
#endif
142
 
                                                                                   
143
 
    return 0;
144
 
 
145
 
 } catch (Exception &e) {
146
 
    std::cerr << e << std::endl;
147
 
    return 1;
148
 
 } catch (...) {
149
 
    std::cerr << "Generic exception!" << std::endl;
150
 
    return 2;
151
 
 }
 
143
 
 
144
  return 0;
 
145
 
 
146
}
 
147
catch (Exception &e) {
 
148
  std::cerr << e << std::endl;
 
149
  return 1;
 
150
} catch (...) {
 
151
  std::cerr << "Generic exception!" << std::endl;
 
152
  return 2;
 
153
}