FiniteElemSpace.cc 3.42 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


13
14
15
16
17
18
19
20
21
#include "FiniteElemSpace.h"
#include "DOFAdmin.h"
#include "DOFVector.h"
#include "BasisFunction.h"
#include "Mesh.h"
#include <algorithm>

namespace AMDiS {

22
  std::vector<FiniteElemSpace*> FiniteElemSpace::feSpaces;
23
24

  FiniteElemSpace::FiniteElemSpace(DOFAdmin* admin_,
25
				   const BasisFunction* bas_fcts,
Thomas Witkowski's avatar
Thomas Witkowski committed
26
				   Mesh* aMesh, 
Thomas Witkowski's avatar
Thomas Witkowski committed
27
				   std::string aString)
28
29
    : name(aString), 
      admin(admin_), 
30
      basFcts(bas_fcts), 
31
      mesh(aMesh)
32
33
34
  {
    FUNCNAME("FiniteElemSpace::FiniteElemSpace()");

35
36
    TEST_EXIT(mesh)("No mesh!\n");
    TEST_EXIT(basFcts)("No basis functions!\n");
37
38
39
40
   
    if (!admin) {
      const DOFAdmin *admin_local = NULL;
      const DimVec<int> *ndof = NULL;
41

42
      ndof = basFcts->getNumberOfDofs();
43
      TEST_EXIT(ndof)("no n_dof or basFcts->n_dof\n");
44

45
      for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
46
	admin_local = &(mesh->getDofAdmin(i));
47
	int j = 0;
48
	for (; j <= mesh->getDim(); j++)
49
	  if (admin_local->getNumberOfDofs(j) != (*ndof)[j]) 
50
	    break;
51
52
	if (j > mesh->getDim()) 
	  break;
53
54
	admin_local = NULL;
      }
55

56
      if (!admin_local) 
57
	admin_local = mesh->createDOFAdmin(name, *ndof);
58

59
60
61
62
63
      admin = const_cast<DOFAdmin*>(admin_local);
    }

    feSpaces.push_back(this);
  }
64

65
  
66

67
  FiniteElemSpace::FiniteElemSpace()
Thomas Witkowski's avatar
Thomas Witkowski committed
68
  {}
69

70

71
  FiniteElemSpace::~FiniteElemSpace()
Thomas Witkowski's avatar
Thomas Witkowski committed
72
  {}
73

74

75
76
77
78
79
  FiniteElemSpace& FiniteElemSpace::operator=(const FiniteElemSpace& feSpace)
  {
    if (&feSpace == this)
      return *this;

Thomas Witkowski's avatar
Thomas Witkowski committed
80
    mesh = new Mesh(feSpace.mesh->getName(), feSpace.mesh->getDim());
81
    *mesh = *(feSpace.mesh);
82
    admin = &(const_cast<DOFAdmin&>(mesh->getDofAdmin(0)));
83
    basFcts = feSpace.basFcts;
84

85
    TEST_EXIT(feSpace.admin == &(feSpace.mesh->getDofAdmin(0)))
86
      ("Gut, dass muss ich mir noch mal ueberlegen!\n");
87
88
89

    return *this;
  }
90

91

92
  FiniteElemSpace* FiniteElemSpace::provideFeSpace(DOFAdmin *admin,
93
						   const BasisFunction *basFcts,
94
						   Mesh *mesh,
Thomas Witkowski's avatar
Thomas Witkowski committed
95
						   std::string name_)
96
  {
97
    for (unsigned int i = 0; i < feSpaces.size(); i++)
98
99
100
101
      if (feSpaces[i]->basFcts == basFcts && 
	  feSpaces[i]->mesh == mesh &&
	  (!admin || (admin && feSpaces[i]->admin == admin)))
	return feSpaces[i];
102

103
    return new FiniteElemSpace(admin, basFcts, mesh, name_);    
104
105
  }

106

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#if DEBUG
  FiniteElemSpace* FiniteElemSpace::provideFeSpace(Mesh *mesh)
  {
    FUNCNAME("FiniteElemSpace::provideFeSpace()");

    for (unsigned int i = 0; i < feSpaces.size(); i++)
      if (feSpaces[i]->mesh == mesh)
	return feSpaces[i];

    ERROR_EXIT("FE space not found!\n");
    
    return NULL;
  }
#endif


123
124
125
126
127
128
129
  int FiniteElemSpace::calcMemoryUsage() 
  {
    int result = sizeof(FiniteElemSpace);
    result += mesh->calcMemoryUsage();
    return result;
  }

130

131
132
  void FiniteElemSpace::clear()
  {
133
    for (unsigned int i = 0; i < feSpaces.size(); i++) {
134
      if (feSpaces[i]) {
Thomas Witkowski's avatar
Thomas Witkowski committed
135
	delete feSpaces[i];
136
137
	feSpaces[i] = NULL;
      }
138
139
    }
  }
140
141
142
143
144
145
146
147
148
149
150
151
152
153


  const FiniteElemSpace* 
  FiniteElemSpace::getHighest(vector<const FiniteElemSpace*>& feSpaces)
  {
    const FiniteElemSpace *feSpace = feSpaces[0];
    for (unsigned int i = 1; i < feSpaces.size(); i++)
      if (feSpaces[i]->getBasisFcts()->getDegree() >
	  feSpace->getBasisFcts()->getDegree())
	feSpace = feSpaces[i];

    return feSpace;
  }

154
}