ConditionalEstimator.cc 2.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#include "ConditionalEstimator.h"
#include "ElInfo.h"
#include "PartitionElementData.h"
#include "Element.h"
#include "Traverse.h"
#include "mpi.h"

namespace AMDiS {

  double ConditionalEstimator::estimate(double ts) 
  {
12
    if (decoratedEstimator_) {
13
14
15
16
17
18
19
20
21
22
23
24

      double partition_sum = 0.0;

      elementCount_ = 0;

      decoratedEstimator_->init(ts);

      mesh = decoratedEstimator_->getMesh();
      traverseFlag = decoratedEstimator_->getTraverseFlag();

      TraverseStack stack;
      ElInfo *elInfo = stack.traverseFirst(mesh, -1, traverseFlag);
25
      while (elInfo) {
26
27
28
	PartitionElementData *elData = dynamic_cast<PartitionElementData*>
	  (elInfo->getElement()->getElementData(PARTITION_ED));

29
	TEST_EXIT_DBG(elInfo->getElement()->isLeaf())("element not leaf\n");
30
	TEST_EXIT_DBG(elData)("no partition data on leaf element %d (rank %d)\n", 
31
32
			      elInfo->getElement()->getIndex(),
			      MPI::COMM_WORLD.Get_rank());
33
     
34
	//if(status == IN || status == OVERLAP) {
35
	  decoratedEstimator_->estimateElement(elInfo);
36
37
38
	//} else {
	//  elInfo->getElement()->setMark(0);
	//}
39
40
41
42
	elInfo = stack.traverseNext(elInfo);
      }

      elInfo = stack.traverseFirst(mesh, -1, traverseFlag);
43
      while (elInfo) {
44
	//if(status == IN) {
45
46
	  elementCount_++;
	  partition_sum += elInfo->getElement()->getEstimation(row_);
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
92
93
94
95
96
	elInfo = stack.traverseNext(elInfo);
      }

      // !!! test !!!
      double total_sum = 0.0;
      MPI::COMM_WORLD.Allreduce(&partition_sum,
				&total_sum,
				1,
				MPI_DOUBLE,
				MPI_SUM);

      decoratedEstimator_->setErrorSum(total_sum);

      double total_max = 0.0;
      est_max = decoratedEstimator_->getErrorMax();
      MPI::COMM_WORLD.Allreduce(&est_max,
				&total_max,
				1,
				MPI_DOUBLE,
				MPI_MAX);

      decoratedEstimator_->setErrorMax(total_max);
    
      decoratedEstimator_->exit();

      est_sum = decoratedEstimator_->getErrorSum();
      est_max = decoratedEstimator_->getErrorMax();

      // !!! test !!!
#if 0
      decoratedEstimator_->exit();

      est_sum = sqrt(partition_sum); //decoratedEstimator_->getErrorSum();
      est_t_sum = decoratedEstimator_->getTimeEst();
      est_max = decoratedEstimator_->getErrorMax();
#endif

      //   MSG("rank %d , estimate %e (total %e) elements %d (total %d)\n", 
      //       MPI::COMM_WORLD.Get_rank(), est_sum, total_sum,
      //       elementCount_,
      //       mesh->getNumberOfLeaves());

      return est_sum;
    } else {
      return 0.0;
    }
  }

}