FiniteElemSpace.cc 2.51 KB
Newer Older
1 2 3 4 5 6 7 8 9
#include "FiniteElemSpace.h"
#include "DOFAdmin.h"
#include "DOFVector.h"
#include "BasisFunction.h"
#include "Mesh.h"
#include <algorithm>

namespace AMDiS {

10
  std::vector<FiniteElemSpace*> FiniteElemSpace::feSpaces;
11 12

  FiniteElemSpace::FiniteElemSpace(DOFAdmin* admin_,
13
				   const BasisFunction* bas_fcts,
Thomas Witkowski's avatar
Thomas Witkowski committed
14
				   Mesh* aMesh, 
Thomas Witkowski's avatar
Thomas Witkowski committed
15
				   std::string aString)
16 17
    : name(aString), 
      admin(admin_), 
18
      basFcts(bas_fcts), 
19
      mesh(aMesh)
20 21 22
  {
    FUNCNAME("FiniteElemSpace::FiniteElemSpace()");

23 24
    TEST_EXIT(mesh)("No mesh!\n");
    TEST_EXIT(basFcts)("No basis functions!\n");
25 26 27 28
   
    if (!admin) {
      const DOFAdmin *admin_local = NULL;
      const DimVec<int> *ndof = NULL;
29
      ndof = basFcts->getNumberOfDofs();
30
      TEST_EXIT(ndof)("no n_dof or basFcts->n_dof\n");
31
      for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
32
	admin_local = &(mesh->getDofAdmin(i));
33
	int j = 0;
34
	for (; j <= mesh->getDim(); j++)
35
	  if (admin_local->getNumberOfDofs(j) != (*ndof)[j]) 
36
	    break;
37 38
	if (j > mesh->getDim()) 
	  break;
39 40
	admin_local = NULL;
      }
41
      if (!admin_local) 
42
	admin_local = mesh->createDOFAdmin(name, *ndof);
43

44 45 46 47 48
      admin = const_cast<DOFAdmin*>(admin_local);
    }

    feSpaces.push_back(this);
  }
49
  
50

51
  FiniteElemSpace::FiniteElemSpace()
Thomas Witkowski's avatar
Thomas Witkowski committed
52
  {}
53

54

55
  FiniteElemSpace::~FiniteElemSpace()
Thomas Witkowski's avatar
Thomas Witkowski committed
56
  {}
57

58

59 60 61 62 63
  FiniteElemSpace& FiniteElemSpace::operator=(const FiniteElemSpace& feSpace)
  {
    if (&feSpace == this)
      return *this;

Thomas Witkowski's avatar
Thomas Witkowski committed
64
    mesh = new Mesh(feSpace.mesh->getName(), feSpace.mesh->getDim());
65
    *mesh = *(feSpace.mesh);
66
    admin = &(const_cast<DOFAdmin&>(mesh->getDofAdmin(0)));
67
    basFcts = feSpace.basFcts;
68

69
    TEST_EXIT(feSpace.admin == &(feSpace.mesh->getDofAdmin(0)))
70
      ("Gut, dass muss ich mir noch mal ueberlegen!\n");
71 72 73

    return *this;
  }
74

75

76
  FiniteElemSpace *FiniteElemSpace::provideFeSpace(DOFAdmin *admin,
77
						   const BasisFunction *basFcts,
78
						   Mesh *mesh,
Thomas Witkowski's avatar
Thomas Witkowski committed
79
						   std::string name_)
80
  {
81
    for (unsigned int i = 0; i < feSpaces.size(); i++)
82 83 84 85
      if (feSpaces[i]->basFcts == basFcts && 
	  feSpaces[i]->mesh == mesh &&
	  (!admin || (admin && feSpaces[i]->admin == admin)))
	return feSpaces[i];
86

87
    return new FiniteElemSpace(admin, basFcts, mesh, name_);    
88 89
  }

90

91 92 93 94 95 96 97
  int FiniteElemSpace::calcMemoryUsage() 
  {
    int result = sizeof(FiniteElemSpace);
    result += mesh->calcMemoryUsage();
    return result;
  }

98

99 100
  void FiniteElemSpace::clear()
  {
101 102
    for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
      if (feSpaces[i]) {
Thomas Witkowski's avatar
Thomas Witkowski committed
103
	delete feSpaces[i];
104 105
	feSpaces[i] = NULL;
      }
106 107
    }
  }
108
}