dune-fem 2.12-git
Loading...
Searching...
No Matches
readtupledata.cc
Go to the documentation of this file.
1//**************************************************************
2// (C) written and directecd by Robert Kloefkorn
3//**************************************************************
4#ifndef DATADISP_READTUPLE_CC
5#define DATADISP_READTUPLE_CC
6
7//- system includes
8#include <stack>
9
10//- include grape io stuff
15
17
19typedef Dune::GridSelector::GridType GR_GridType;
20
23
25
26template <class T>
27inline void deleteObjects(std::stack<T *> & stack);
28
30{
31 std::cerr << msg << std::endl;
32 std::cerr.flush();
33 exit(EXIT_FAILURE);
34}
35
36inline void readTupleData(const char * path, const char * filename,
37 double & time ,
38 const int n,
39 const int timestep,
40 const int myRank,
41 const int numProcs,
42 INFO* info)
43{
44 // check whether we use a fixed mesh
45 const bool fixedMesh = (info->fix_mesh == 1) ? true : false;
46
47 // the grid is new if not a fixed mesh or the stack is empty
48 const bool newGrid = ( ! fixedMesh || gridStack.empty() );
49
50 // init grid
51 GR_GridType * grid = ( ! newGrid ) ? gridStack.top() : 0;
52
53 assert(filename);
54 std::string fn (filename);
55
56 Fem::IOTuple<GR_DiscFuncType>::ReturnType* tup =
57 Fem::IOTuple<GR_DiscFuncType>::input(grid,time,myRank,numProcs,path,fn);
58
59 // push all new grids to grid stack
60 if( newGrid ) gridStack.push(grid);
61
62 // do some processing
63 process(*grid,*tup,time,timestep,myRank,numProcs);
64
65 Fem::IOTuple<GR_DiscFuncType>::removeData(*tup);
66 delete tup;
67
68 if( ! fixedMesh ) delete grid;
69}
70
71// setup the hole data tree for grape
72inline INFO * readData(INFO * info , const char * path, int i_start, int i_end,
73 int i_delta, int n, double timestep, int numProcs)
74{
75 double t_start = 1e308;
76 double t_end = -t_start, t_act = 0.0;
77 int ntime, n_step = 0;
78
79 const bool useRankPath = Dune::Fem::DataWriterParameters().separateRankPath();
80
81 for (ntime = i_start; ntime <= i_end; ntime += i_delta)
82 {
83 printf("timestep = %d | last timestep = %d | stepsize = %d\n", ntime, i_end, i_delta);
84 {
85 int anzProcs = numProcs;
86
87 for(int proc=0; proc<anzProcs; ++proc)
88 {
89 assert(path || numProcs <= 1);
90
91 int anz = n; // (n > 0) ? n : 1;
92 for(int i=0; i<anz; ++i)
93 {
94 // use standard procedure to create path name
95 std::string newpath =
96 Fem::IOInterface::createRecoverPath(path,proc,info[i].name,ntime, useRankPath);
97
98 readTupleData(newpath.c_str(), info[i].name,
99 t_act , i , ntime, proc, numProcs, info);
100 }
101 }
102 }
103 printf("actual time: %f (timestep size: %e)\n\n",t_act,timestep);
104
105
106 if (ntime == i_start) t_start = t_end = t_act;
107 t_start = std::min(t_start, t_act);
108 t_end = std::max(t_end, t_act);
109
110 if (timestep > 0) t_act += timestep*i_delta;
111 n_step++;
112 }
113 return info;
114}
115
116template <class T>
117inline void deleteObjects(std::stack<T *> & stack)
118{
119 while(! stack.empty() )
120 {
121 T * obj = stack.top();
122 stack.pop();
123 delete obj;
124 }
125 return;
126}
127
128inline void deleteAllObjects()
129{
131 return ;
132}
133#endif
const char * name()
Dune::GridSelector::GridType GR_GridType
type of used grid
Definition readiotupledata.cc:19
InTupleType GR_InputType
Definition converttemplate.cc:20
void process(const GR_GridType &grid, const InTupleType &data, const double time, const int timestep, const int myRank, const int numProcs)
Definition converttemplate.cc:24
std::string path
Definition readioparams.cc:156
void dataDispErrorExit(std::string msg)
Definition readtupledata.cc:29
Dune::GridSelector::GridType GR_GridType
type of used grid
Definition readtupledata.cc:19
void deleteAllObjects()
Definition readtupledata.cc:128
static std::stack< GR_GridType * > gridStack
Definition readtupledata.cc:24
void deleteObjects(std::stack< T * > &stack)
Definition readtupledata.cc:117
void readTupleData(const char *path, const char *filename, double &time, const int n, const int timestep, const int myRank, const int numProcs, INFO *info)
Definition readtupledata.cc:36
INFO * readData(INFO *info, const char *path, int i_start, int i_end, int i_delta, int n, double timestep, int numProcs)
Definition readtupledata.cc:72
GR_InputType GR_DiscFuncType
type of discrete function tuple
Definition readtupledata.cc:22
Definition datawriter.hh:34
virtual bool separateRankPath() const
return true if all data should be written to a spearate path per rank
Definition datawriter.hh:50
Definition grcommon.hh:31
int fix_mesh
Definition grcommon.hh:32
const char * name
Definition grcommon.hh:33
T c_str(T... args)
T empty(T... args)
T endl(T... args)
T max(T... args)
T min(T... args)
T pop(T... args)
T top(T... args)