FiniteElemSpace.cc 2.68 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
13

  FiniteElemSpace::FiniteElemSpace(DOFAdmin* admin_,
				   const BasisFunction* bas_fcts_,
Thomas Witkowski's avatar
Thomas Witkowski committed
14
15
				   Mesh* aMesh, 
				   const std::string& aString)
16
17
18
19
    : name(aString), 
      admin(admin_), 
      basFcts(bas_fcts_), 
      mesh(aMesh)
20
21
22
23
24
25
26
27
28
29
  {
    FUNCNAME("FiniteElemSpace::FiniteElemSpace()");

    TEST_EXIT(mesh)("no Mesh\n");
   
    if (!admin) {
      const DOFAdmin *admin_local = NULL;
      const DimVec<int> *ndof = NULL;
      ndof = basFcts->getNumberOfDOFs();
      TEST_EXIT(ndof)("no n_dof or basFcts->n_dof\n");
30
      for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
31
	admin_local = &(mesh->getDOFAdmin(i));
32
33
	int j = 0;
	for (; j <= mesh->getDim(); j++) {
34
35
	  if (admin_local->getNumberOfDOFs(j) != (*ndof)[j]) 
	    break;
36
	}
37
38
	if (j > mesh->getDim()) 
	  break;
39
40
41
42
43
44
45
46
47
48
	admin_local = NULL;
      }
      if (!admin_local) {
	admin_local = mesh->createDOFAdmin(name, *ndof);
      }
      admin = const_cast<DOFAdmin*>(admin_local);
    }

    feSpaces.push_back(this);
  }
49
50
  
  FiniteElemSpace::FiniteElemSpace()
Thomas Witkowski's avatar
Thomas Witkowski committed
51
  {}
52

53
  FiniteElemSpace::~FiniteElemSpace()
Thomas Witkowski's avatar
Thomas Witkowski committed
54
  {}
55

56
57
58
59
60
  FiniteElemSpace& FiniteElemSpace::operator=(const FiniteElemSpace& feSpace)
  {
    if (&feSpace == this)
      return *this;

61
62
63
    mesh = NEW Mesh(feSpace.mesh->getName(), feSpace.mesh->getDim());
    *mesh = *(feSpace.mesh);
    admin = &(const_cast<DOFAdmin&>(mesh->getDOFAdmin(0)));
64
    basFcts = feSpace.basFcts;
65
66
67

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

    return *this;
  }
71

72
  FiniteElemSpace *FiniteElemSpace::provideFESpace(DOFAdmin *admin,
73
						   const BasisFunction *basFcts,
74
75
						   Mesh *mesh,
						   const std::string& name_)
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  {
    int numSpaces = static_cast<int>(feSpaces.size());

    for (int i = 0; i < numSpaces; i++) {
      if (admin) {
	if (feSpaces[i]->admin == admin) {
	  return feSpaces[i];
	}
      } else {
	if (feSpaces[i]->basFcts == basFcts && feSpaces[i]->mesh == mesh) {
	  return feSpaces[i];
	}
      }
    }

91
    if (admin) {
92
93
94
95
96
97
98
      ERROR_EXIT("no fespace found for this admin\n");
      return NULL;
    } else {
      return NEW FiniteElemSpace(NULL, basFcts, mesh, name_);
    }
  }

99
100
101
102
103
104
105
  int FiniteElemSpace::calcMemoryUsage() 
  {
    int result = sizeof(FiniteElemSpace);
    result += mesh->calcMemoryUsage();
    return result;
  }

106
107
  void FiniteElemSpace::clear()
  {
108
109
110
111
112
    for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
      if (feSpaces[i]) {
	DELETE feSpaces[i];
	feSpaces[i] = NULL;
      }
113
114
    }
  }
115
}