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

30
      ndof = basFcts->getNumberOfDofs();
31
      TEST_EXIT(ndof)("no n_dof or basFcts->n_dof\n");
32

33
      for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
34
	admin_local = &(mesh->getDofAdmin(i));
35
	int j = 0;
36
	for (; j <= mesh->getDim(); j++)
37
	  if (admin_local->getNumberOfDofs(j) != (*ndof)[j]) 
38
	    break;
39
40
	if (j > mesh->getDim()) 
	  break;
41
42
	admin_local = NULL;
      }
43

44
      if (!admin_local) 
45
	admin_local = mesh->createDOFAdmin(name, *ndof);
46

47
48
49
50
51
      admin = const_cast<DOFAdmin*>(admin_local);
    }

    feSpaces.push_back(this);
  }
52

53
  
54

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

58

59
  FiniteElemSpace::~FiniteElemSpace()
Thomas Witkowski's avatar
Thomas Witkowski committed
60
  {}
61

62

63
64
65
66
67
  FiniteElemSpace& FiniteElemSpace::operator=(const FiniteElemSpace& feSpace)
  {
    if (&feSpace == this)
      return *this;

Thomas Witkowski's avatar
Thomas Witkowski committed
68
    mesh = new Mesh(feSpace.mesh->getName(), feSpace.mesh->getDim());
69
    *mesh = *(feSpace.mesh);
70
    admin = &(const_cast<DOFAdmin&>(mesh->getDofAdmin(0)));
71
    basFcts = feSpace.basFcts;
72

73
    TEST_EXIT(feSpace.admin == &(feSpace.mesh->getDofAdmin(0)))
74
      ("Gut, dass muss ich mir noch mal ueberlegen!\n");
75
76
77

    return *this;
  }
78

79

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

91
    return new FiniteElemSpace(admin, basFcts, mesh, name_);    
92
93
  }

94

95
96
97
98
99
100
101
  int FiniteElemSpace::calcMemoryUsage() 
  {
    int result = sizeof(FiniteElemSpace);
    result += mesh->calcMemoryUsage();
    return result;
  }

102

103
104
  void FiniteElemSpace::clear()
  {
105
    for (unsigned int i = 0; i < feSpaces.size(); i++) {
106
      if (feSpaces[i]) {
Thomas Witkowski's avatar
Thomas Witkowski committed
107
	delete feSpaces[i];
108
109
	feSpaces[i] = NULL;
      }
110
111
    }
  }
112
}