ConditionalMarker.h 3.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file ConditionalMarker.h */

#ifndef AMDIS_CONDITIONALMARKER_H
#define AMDIS_CONDITIONALMARKER_H

#include "mpi.h"
#include "Marker.h"
#include "Marker.h"
#include "MemoryManager.h"
#include "PartitionElementData.h"
#include "Traverse.h"
#include "ElInfo.h"

namespace AMDiS {

  // ===========================================================================
  // ===== class ESMarker ======================================================
  // ===========================================================================

  /**
   * \ingroup Adaption
   * 
   * \brief
   * 
   */
  class ConditionalMarker : public Marker
  {
  public:
    MEMORY_MANAGED(ConditionalMarker);

    /** \brief
     * Constructor.
     */
    ConditionalMarker(const std::string name,
		      int row,
		      Marker *decoratedMarker,
		      int globalCoarseGridLevel,
		      int localCoarseGridLevel)
      : Marker(name, row), 
	decoratedMarker_(decoratedMarker),
	globalCoarseGridLevel_(globalCoarseGridLevel),    
	localCoarseGridLevel_(localCoarseGridLevel)
    {};

    /** \brief
     * Implementation of MarkScal::initMarking().
     */
    virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh) {
      if(decoratedMarker_) 
	decoratedMarker_->initMarking(adaptInfo, mesh);
    };

    virtual void finishMarking(AdaptInfo *adaptInfo) {
      if(decoratedMarker_) {
	int tmp = decoratedMarker_->getElMarkRefine();
	MPI::COMM_WORLD.Allreduce(&tmp,
				  &elMarkRefine,
				  1,
				  MPI_INT,
				  MPI_SUM);
	tmp = decoratedMarker_->getElMarkCoarsen();
	MPI::COMM_WORLD.Allreduce(&tmp,
				  &elMarkCoarsen,
				  1,
				  MPI_INT,
				  MPI_SUM);
	decoratedMarker_->finishMarking(adaptInfo);
      }
    };

    void markElement(AdaptInfo *adaptInfo, ElInfo *elInfo) {
      FUNCNAME("ConditionalMarker::markElement()");
92
      if (decoratedMarker_) {
93 94 95 96
	PartitionElementData *elData = 
	  dynamic_cast<PartitionElementData*>(elInfo->getElement()->
					      getElementData(PARTITION_ED));

97
	TEST_EXIT_DBG(elData)("no partition data\n");
98 99 100

	decoratedMarker_->markElement(adaptInfo, elInfo);

101
	if (elData->getPartitionStatus() == OUT) {
102
	  Element *element = elInfo->getElement();
103
	  if (element->getMark() > 0) {
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
	    element->setMark(0);
	  }
	}

	int minLevel = 
	  elData->getPartitionStatus() != OUT ? 
	  localCoarseGridLevel_ :
	  globalCoarseGridLevel_;

	if(elData->getLevel() + elInfo->getElement()->getMark() < minLevel) {
	  elInfo->getElement()->setMark(-(elData->getLevel() - minLevel));
	}
      }
    };

  protected:
    Marker *decoratedMarker_;
    int globalCoarseGridLevel_;
    int localCoarseGridLevel_;
  };

}

#endif