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

« back to all changes in this revision

Viewing changes to dune/grid/io/file/test/vtksequencetest.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: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 
// vi: set et ts=8 sw=2 sts=2:
 
1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi: set et ts=4 sw=2 sts=2:
3
3
// $Id:$
4
4
 
5
5
#include "config.h" // autoconf defines, needed by the dune headers
15
15
{
16
16
  switch(dm)
17
17
  {
18
 
  case Dune::VTK::conforming:
 
18
  case Dune::VTK::conforming :
19
19
    return "conforming";
20
 
  case Dune::VTK::nonconforming:
 
20
  case Dune::VTK::nonconforming :
21
21
    return "nonconforming";
22
22
  }
23
23
  return "";
25
25
 
26
26
template< class GridView >
27
27
class VTKVectorFunction
28
 
: public Dune :: VTKWriter< GridView > :: VTKFunction
 
28
  : public Dune :: VTKWriter< GridView > :: VTKFunction
29
29
{
30
30
  // extract types
31
31
  enum { n = GridView :: dimension };
39
39
    time_ = time;
40
40
  }
41
41
  //! return number of components
42
 
  virtual int ncomps () const  { return n; }
43
 
  
 
42
  virtual int ncomps () const { return n; }
 
43
 
44
44
  //! evaluate single component comp in the entity e at local coordinates xi
45
45
  /*! Evaluate the function in an entity at local coordinates.
46
 
    @param[in]  comp   number of component to be evaluated
47
 
    @param[in]  e      reference to grid entity of codimension 0
48
 
    @param[in]  xi     point in local coordinates of the reference element of e
49
 
    \return            value of the component
50
 
  */
 
46
     @param[in]  comp   number of component to be evaluated
 
47
     @param[in]  e      reference to grid entity of codimension 0
 
48
     @param[in]  xi     point in local coordinates of the reference element of e
 
49
     \return            value of the component
 
50
   */
51
51
  virtual double evaluate (int comp, const Entity& e, const Dune::FieldVector<DT,n>& xi) const
52
 
    {
53
 
      return comp*0.1*sin(time_*2.*M_PI);
54
 
    }
 
52
  {
 
53
    return comp*0.1*sin(time_*2.*M_PI);
 
54
  }
55
55
 
56
56
  // get name
57
57
  virtual std::string name () const
58
 
    {
59
 
      char _name[256];
60
 
      snprintf(_name, 256, "vector-%iD", ncomps());
61
 
      return std::string(_name);
62
 
    }
 
58
  {
 
59
    char _name[256];
 
60
    snprintf(_name, 256, "vector-%iD", ncomps());
 
61
    return std::string(_name);
 
62
  }
63
63
};
64
64
 
65
65
template< class GridView >
66
66
void doWrite( const GridView &gridView, Dune::VTK::DataMode dm )
67
67
{
68
 
   enum { dim = GridView :: dimension };
69
 
 
70
 
   const typename GridView :: IndexSet &is = gridView.indexSet();
71
 
   std::vector<int> vertexdata(is.size(dim),dim);
72
 
   std::vector<int> celldata(is.size(0),0);
73
 
 
74
 
   std::stringstream name;
75
 
   name << "vtktest-" << dim << "D-" << VTKDataMode(dm);
76
 
   Dune :: VTKSequenceWriter< GridView > 
77
 
     vtk( gridView, name.str(), ".", "", dm );
78
 
 
79
 
 
80
 
   vtk.addVertexData(vertexdata,"vertexData");
81
 
   vtk.addCellData(celldata,"cellData");
82
 
   VTKVectorFunction< GridView > *vectordata = new VTKVectorFunction< GridView >;
83
 
   vtk.addVertexData(vectordata);
84
 
   double time = 0;
85
 
   while (time<1) {
86
 
     vectordata->setTime(time);
87
 
     vtk.write(time);
88
 
     time += 0.1;
89
 
   }
 
68
  enum { dim = GridView :: dimension };
 
69
 
 
70
  const typename GridView :: IndexSet &is = gridView.indexSet();
 
71
  std::vector<int> vertexdata(is.size(dim),dim);
 
72
  std::vector<int> celldata(is.size(0),0);
 
73
 
 
74
  std::stringstream name;
 
75
  name << "vtktest-" << dim << "D-" << VTKDataMode(dm);
 
76
  Dune :: VTKSequenceWriter< GridView >
 
77
  vtk( gridView, name.str(), ".", "", dm );
 
78
 
 
79
 
 
80
  vtk.addVertexData(vertexdata,"vertexData");
 
81
  vtk.addCellData(celldata,"cellData");
 
82
  VTKVectorFunction< GridView > *vectordata = new VTKVectorFunction< GridView >;
 
83
  vtk.addVertexData(vectordata);
 
84
  double time = 0;
 
85
  while (time<1) {
 
86
    vectordata->setTime(time);
 
87
    vtk.write(time);
 
88
    time += 0.1;
 
89
  }
90
90
}
91
91
 
92
92
template<int dim>
93
93
void vtkCheck(int* n, double* h)
94
94
{
95
95
  const Dune :: PartitionIteratorType VTK_Partition = Dune :: InteriorBorder_Partition;
96
 
   std::cout << std::endl << "vtkSequenceCheck dim=" << dim << std::endl << std::endl;
97
 
   Dune::SGrid<dim,dim> g(n, h);
98
 
   g.globalRefine(1);
 
96
  std::cout << std::endl << "vtkSequenceCheck dim=" << dim << std::endl << std::endl;
 
97
  Dune::SGrid<dim,dim> g(n, h);
 
98
  g.globalRefine(1);
99
99
 
100
 
   doWrite( g.template leafView< VTK_Partition >(), Dune::VTK::conforming );
101
 
   doWrite( g.template leafView< VTK_Partition >(), Dune::VTK::nonconforming );
102
 
   doWrite( g.template levelView< VTK_Partition >( 0 ), Dune::VTK::conforming );
103
 
   doWrite( g.template levelView< VTK_Partition >( 0 ), Dune::VTK::nonconforming );
104
 
   doWrite( g.template levelView< VTK_Partition >( g.maxLevel() ), Dune::VTK::conforming );
105
 
   doWrite( g.template levelView< VTK_Partition >( g.maxLevel() ), Dune::VTK::nonconforming );
 
100
  doWrite( g.template leafGridView< VTK_Partition >(), Dune::VTK::conforming );
 
101
  doWrite( g.template leafGridView< VTK_Partition >(), Dune::VTK::nonconforming );
 
102
  doWrite( g.template levelGridView< VTK_Partition >( 0 ), Dune::VTK::conforming );
 
103
  doWrite( g.template levelGridView< VTK_Partition >( 0 ), Dune::VTK::nonconforming );
 
104
  doWrite( g.template levelGridView< VTK_Partition >( g.maxLevel() ), Dune::VTK::conforming );
 
105
  doWrite( g.template levelGridView< VTK_Partition >( g.maxLevel() ), Dune::VTK::nonconforming );
106
106
}
107
107
 
108
108
int main(int argc, char **argv)
119
119
  } catch (Dune::Exception &e) {
120
120
    std::cerr << e << std::endl;
121
121
    return 1;
 
122
  } catch (std::exception &e) {
 
123
    std::cerr << e.what() << std::endl;
 
124
    return 1;
122
125
  } catch (...) {
123
126
    std::cerr << "Generic exception!" << std::endl;
124
127
    return 2;