LeafData.h 10.8 KB
Newer Older
1 2 3 4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6 7
// ==                                                                        ==
// ============================================================================
8 9 10 11 12 13 14 15 16 17 18 19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

/** \file LeafData.h */

#ifndef AMDIS_LEAFDATA_H
#define AMDIS_LEAFDATA_H

#include <list>
#include <map>
#include "Serializable.h"
#include "FixVec.h"
#include "ElementData.h"
#include "Boundary.h"

namespace AMDiS {

  class LeafDataEstimatableInterface
  {
  public:
    virtual ~LeafDataEstimatableInterface() {};
    virtual void setErrorEstimate(int, double) = 0;
    virtual double getErrorEstimate(int) = 0;
  };

  class LeafDataEstimatable : public ElementData,
			      public LeafDataEstimatableInterface
  {
  public:
47 48 49
    inline bool isOfType(int type) const 
    {
      if (type == ESTIMATABLE)
50
	return true;
51
      
52
      return false;
53
    }
54 55 56 57

    class Creator : public CreatorInterface<ElementData>
    {
    public:
58 59
      ElementData* create() 
      {
Thomas Witkowski's avatar
Thomas Witkowski committed
60
	return new LeafDataEstimatable;
61
      }
62 63
    };

64
    /// constructor
65
    LeafDataEstimatable(ElementData *decorated = NULL)
66 67 68
      : ElementData(decorated), 
	errorEstimate(0.0)
    {}
69

70 71
    /// Refinement of parent to child1 and child2.
    /// @return true: must this ElementData, else not allowed to delete it
72 73 74 75 76 77 78 79 80 81
    bool refineElementData(Element* parent, 
			   Element* child1,
			   Element* child2,
			   int elType);

    void coarsenElementData(Element* parent, 
			    Element* thisChild,
			    Element* otherChild,
			    int elTypeParent);

82 83 84
    /// Sets \ref errorEstimate
    inline void setErrorEstimate(int, double est) 
    { 
85 86
      errorEstimate = est; 
    }
87

88 89 90
    /// Returns \ref errorEstimate
    inline double getErrorEstimate(int) 
    { 
91 92
      return errorEstimate; 
    }
93

94 95 96
    /// Implements ElementData::clone().
    virtual ElementData *clone() const 
    {
97 98 99 100 101 102
      // create new estimatable leaf data
      LeafDataEstimatable *newObj = new LeafDataEstimatable(NULL);

      newObj->errorEstimate = errorEstimate;

      // clone decorated element data (=> deep copy)
103
      newObj->decorated = ElementData::clone();
104 105 106

      // return the clone
      return newObj;
107
    }
108

109 110 111
    /// Returns the name of element data type.
    inline std::string getTypeName() const 
    { 
112 113
      return "LeafDataEstimatable"; 
    }
114

115
    inline int getTypeID() const 
116
    { 
117 118
      return ESTIMATABLE; 
    }
119

Thomas Witkowski's avatar
Thomas Witkowski committed
120
    void serialize(std::ostream& out);
121

Thomas Witkowski's avatar
Thomas Witkowski committed
122
    void deserialize(std::istream& in); 
123 124 125 126 127 128 129 130 131 132 133 134

  private:
    double errorEstimate;
  };

  class LeafDataEstimatableVec : public ElementData,
				 public LeafDataEstimatableInterface
  {
  public:
    class Creator : public CreatorInterface<ElementData>
    {
    public:
135 136
      ElementData* create() 
      {
Thomas Witkowski's avatar
Thomas Witkowski committed
137
	return new LeafDataEstimatableVec;
138
      }
139 140
    };

141 142
    inline bool isOfType(int type) const 
    {
143
      if (type == ESTIMATABLE) 
144 145
	return true;
      return false;
146
    }
147

148
    /// constructor
149 150
    LeafDataEstimatableVec(ElementData *decorated = NULL)
      : ElementData(decorated)
151
    {}
152

153
    /// Refinement of parent to child1 and child2.
154 155 156 157 158 159 160 161 162 163
    bool refineElementData(Element* parent, 
			   Element* child1,
			   Element* child2,
			   int elType);

    void coarsenElementData(Element* parent, 
			    Element* thisChild,
			    Element* otherChild,
			    int elTypeParent);

164 165 166
    /// Sets \ref errorEstimate
    inline void setErrorEstimate(int index, double est) 
    { 
167
      errorEstimate[index] = est; 
168
    }
169

170 171 172
    /// Returns \ref errorEstimate
    inline double getErrorEstimate(int index) 
    { 
173
      return errorEstimate[index];
174
    }
175

176 177 178
    /// Implements ElementData::clone().
    virtual ElementData *clone() const 
    {
179 180 181 182 183 184 185
      // create new estimatable leaf data
      LeafDataEstimatableVec *newObj = 
	new LeafDataEstimatableVec(NULL);

      newObj->errorEstimate = errorEstimate;

      // clone decorated element data (=> deep copy)
186
      newObj->decorated = ElementData::clone();
187 188 189

      // return the clone
      return newObj;
190
    }
191

Thomas Witkowski's avatar
Thomas Witkowski committed
192
    void serialize(std::ostream& out);
193

Thomas Witkowski's avatar
Thomas Witkowski committed
194
    void deserialize(std::istream& in);
195

196 197
    std::string getTypeName() const 
    {
198
      return "LeafDataEstimatableVec";
199
    }
200
  
201
    inline int getTypeID() const 
202
    { 
203 204
      return ESTIMATABLE; 
    }
205 206

  private:
207
    std::map<int, double> errorEstimate;
208 209 210 211 212
  };

  class LeafDataCoarsenableInterface
  {
  public:
213
    virtual ~LeafDataCoarsenableInterface() {}
214

215
    /// Sets \ref coarseningError
216
    virtual void setCoarseningErrorEstimate(int index, double est) = 0;
217

218
    /// Returns \ref coarseningError
219 220 221 222 223 224 225 226 227 228
    virtual double getCoarseningErrorEstimate(int index) = 0;
  };

  class LeafDataCoarsenable : public ElementData,
			      public LeafDataCoarsenableInterface
  {
  public:
    class Creator : public CreatorInterface<ElementData>
    {
    public:
229 230
      ElementData* create() 
      {
Thomas Witkowski's avatar
Thomas Witkowski committed
231
	return new LeafDataCoarsenable;
232
      }
233 234
    };

235 236
    inline bool isOfType(int type) const 
    {
237 238 239
      if(type == COARSENABLE) 
	return true;
      return false;
240
    }
241

242
    /// constructor
243
    LeafDataCoarsenable(ElementData *decorated = NULL)
244 245 246 247 248 249
      : ElementData(decorated), 
	coarseningError(0.00)
    {}

    ~LeafDataCoarsenable()
    {}
250

251
    /// Refinement of parent to child1 and child2.
252 253 254 255 256
    bool refineElementData(Element* parent, 
			   Element* child1,
			   Element* child2,
			   int elType);

257
    /// Refinement of parent to child1 and child2.
258 259 260 261 262
    void coarsenElementData(Element* parent, 
			    Element* thisChild,
			    Element* otherChild,
			    int elTypeParent);

263
    /// Implements ElementData::clone().
Thomas Witkowski's avatar
Thomas Witkowski committed
264 265
    inline ElementData *clone() const 
    {
266 267 268 269
      // create new estimatable leaf data
      LeafDataCoarsenable *newObj = new LeafDataCoarsenable(NULL);

      // clone decorated element data (=> deep copy)
270
      newObj->decorated = ElementData::clone();
271 272 273

      // return the clone
      return newObj;
274
    }
275

276 277 278
    /// Sets \ref coarseningError
    virtual void setCoarseningErrorEstimate(int , double est) 
    { 
279
      coarseningError = est; 
280
    }
281

282 283 284
    /// Returns \ref coarseningError
    virtual double getCoarseningErrorEstimate(int) 
    { 
285
      return coarseningError; 
286
    }
287

Thomas Witkowski's avatar
Thomas Witkowski committed
288
    void serialize(std::ostream& out);
289

Thomas Witkowski's avatar
Thomas Witkowski committed
290
    void deserialize(std::istream& in);
291

Thomas Witkowski's avatar
Thomas Witkowski committed
292 293
    std::string getTypeName() const 
    {
294
      return "LeafDataCoarsenable";
295
    }
296
  
297
    inline int getTypeID() const 
Thomas Witkowski's avatar
Thomas Witkowski committed
298
    { 
299 300
      return COARSENABLE; 
    }
301 302

  private:
303
    double coarseningError;
304 305 306 307 308 309 310 311 312 313 314
  };



  class LeafDataCoarsenableVec : public ElementData,
				 public LeafDataCoarsenableInterface
  {
  public:
    class Creator : public CreatorInterface<ElementData>
    {
    public:
315 316
      ElementData* create() 
      {
Thomas Witkowski's avatar
Thomas Witkowski committed
317
	return new LeafDataCoarsenableVec;
318
      }
319 320
    };

321 322 323
    inline bool isOfType(int type) const 
    {
      if (type == COARSENABLE) 
324 325
	return true;
      return false;
326
    }
327

328
    /// constructor
329 330
    LeafDataCoarsenableVec(ElementData *decorated = NULL)
      : ElementData(decorated) 
331
    {}
332

333 334 335
    /// Implements ElementData::clone().
    inline ElementData *clone() const 
    {
336 337 338 339 340 341 342
      // create new estimatable leaf data
      LeafDataCoarsenableVec *newObj = 
	new LeafDataCoarsenableVec(NULL);

      newObj->coarseningError = coarseningError; 

      // clone decorated leaf data (=> deep copy)
343
      newObj->decorated = ElementData::clone();
344 345 346

      // return the clone
      return newObj;
347
    }
348

349
    /// Refinement of parent to child1 and child2.
350 351 352 353 354
    bool refineElementData(Element* parent, 
			   Element* child1,
			   Element* child2,
			   int elType);

355
    /// Refinement of parent to child1 and child2.
356 357 358 359 360
    void coarsenElementData(Element* parent, 
			    Element* thisChild,
			    Element* otherChild,
			    int elTypeParent);

361 362 363
    /// Sets \ref coarseningError
    virtual void setCoarseningErrorEstimate(int index, double est) 
    { 
364
      coarseningError[index] = est; 
365
    }
366

367 368 369
    /// Returns \ref coarseningError
    virtual double getCoarseningErrorEstimate(int index) 
    { 
370
      return coarseningError[index]; 
371
    }
372

Thomas Witkowski's avatar
Thomas Witkowski committed
373
    void serialize(std::ostream& out);
374

Thomas Witkowski's avatar
Thomas Witkowski committed
375
    void deserialize(std::istream& in);
376

377
    std::string getTypeName() const 
378 379
    {
      return "LeafDataCoarsenableVec";
380
    }
381
  
382
    inline int getTypeID() const 
383 384 385
    { 
      return COARSENABLE; 
    }
386 387

  private:
388
    std::map<int, double> coarseningError;
389 390 391 392 393 394 395 396 397 398
  };



  class LeafDataPeriodic : public ElementData
  {
  public:
    class Creator : public CreatorInterface<ElementData>
    {
    public:
399 400
      ElementData* create() 
      {
Thomas Witkowski's avatar
Thomas Witkowski committed
401
	return new LeafDataPeriodic;
402
      }
403 404
    };

405 406 407
    inline bool isOfType(int type) const 
    {
      if (type == PERIODIC) 
408
	return true;
409
      
410
      return false;
411
    }
412 413 414 415 416 417


    class PeriodicInfo : public Serializable
    {
    public:
      PeriodicInfo() 
418 419
	: periodicCoords(NULL)
      {}
420 421 422 423 424 425

      PeriodicInfo(int mode,
		   BoundaryType t,
		   int side,
		   const DimVec<WorldVector<double> > *coords);

426 427 428 429 430
      virtual ~PeriodicInfo() 
      {
	if (periodicCoords) 
	  delete periodicCoords;
      }
431 432 433

      PeriodicInfo(const PeriodicInfo &rhs);

Thomas Witkowski's avatar
Thomas Witkowski committed
434
      void serialize(std::ostream &out);
435

Thomas Witkowski's avatar
Thomas Witkowski committed
436
      void deserialize(std::istream &in);
437 438

      int periodicMode;
439

440
      BoundaryType type;
441

442
      int elementSide;
443

444 445 446 447
      DimVec<WorldVector<double> > *periodicCoords;
    };

  public:
448
    /// constructor
449 450
    LeafDataPeriodic(ElementData *decorated = NULL)
      : ElementData(decorated)
451
    {}
452

453 454
    /// Destructor.
    ~LeafDataPeriodic() {}
455

456 457 458
    /// Implements LeafData::clone().
    inline ElementData *clone() const 
    {
459
      LeafDataPeriodic *newObj = new LeafDataPeriodic;
460
      newObj->decorated = ElementData::clone();
461
      return newObj;
462
    }
463 464 465 466 467 468 469 470

    inline void addPeriodicInfo(int mode,
				BoundaryType type,
				int side,
				const DimVec<WorldVector<double> > *coords)
    {
      PeriodicInfo periodicInfo(mode, type, side, coords);
      periodicInfoList.push_back(periodicInfo);
471
    }
472

473 474
    inline std::list<PeriodicInfo>& getInfoList() 
    {
475
      return periodicInfoList;
476
    }
477

Thomas Witkowski's avatar
Thomas Witkowski committed
478
    void serialize(std::ostream& out);
479

Thomas Witkowski's avatar
Thomas Witkowski committed
480
    void deserialize(std::istream& in);
481

482
    std::string getTypeName() const
483 484
    {
      return "LeafDataPeriodic";
485
    }
486
  
487
    inline int getTypeID() const 
488 489 490
    { 
      return PERIODIC; 
    }
491

Thomas Witkowski's avatar
Thomas Witkowski committed
492
    bool refineElementData(Element* parent, Element* child1, Element* child2, 
493 494 495
			   int elType);

  private:
496
    std::list<PeriodicInfo> periodicInfoList;
497 498 499 500 501 502 503 504 505

    friend class LeafDataPeriodicRefinable;
    friend class LeafDataPeriodicCoarsenable;
  };

}

#endif  // AMDIS_LEAFDATA_H