FiniteElemSpace.cc 2.55 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
  
  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;

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

66
    TEST_EXIT(feSpace.admin == &(feSpace.mesh->getDofAdmin(0)))
67
      ("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
						   Mesh *mesh,
Thomas Witkowski's avatar
Thomas Witkowski committed
75
						   std::string name_)
76 77 78
  {
    int numSpaces = static_cast<int>(feSpaces.size());

79 80 81 82 83
    for (int i = 0; i < numSpaces; i++)
      if (feSpaces[i]->basFcts == basFcts && 
	  feSpaces[i]->mesh == mesh &&
	  (!admin || (admin && feSpaces[i]->admin == admin)))
	return feSpaces[i];
84

85
    return new FiniteElemSpace(admin, basFcts, mesh, name_);    
86 87
  }

88 89 90 91 92 93 94
  int FiniteElemSpace::calcMemoryUsage() 
  {
    int result = sizeof(FiniteElemSpace);
    result += mesh->calcMemoryUsage();
    return result;
  }

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