FiniteElemSpace.cc 2.31 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_,
14
				   Mesh* aMesh, const std::string& aString)
15
16
17
18
    : name(aString), 
      admin(admin_), 
      basFcts(bas_fcts_), 
      mesh(aMesh)
19
20
21
22
23
24
25
26
27
28
  {
    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");
29
      for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
30
	admin_local = &(mesh->getDOFAdmin(i));
31
	int j;
32
	for (j = 0; j <= mesh->getDim(); j++) {
33
34
	  if (admin_local->getNumberOfDOFs(j) != (*ndof)[j]) 
	    break;
35
	}
36
37
	if (j > mesh->getDim()) 
	  break;
38
39
40
41
42
43
44
45
46
47
	admin_local = NULL;
      }
      if (!admin_local) {
	admin_local = mesh->createDOFAdmin(name, *ndof);
      }
      admin = const_cast<DOFAdmin*>(admin_local);
    }

    feSpaces.push_back(this);
  }
48
49
50
51
52
53
54
55
56
57
  
  FiniteElemSpace::FiniteElemSpace()
  {
  }

  FiniteElemSpace& FiniteElemSpace::operator=(const FiniteElemSpace& feSpace)
  {
    if (&feSpace == this)
      return *this;

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

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

    return *this;
  }
68

69
  FiniteElemSpace *FiniteElemSpace::provideFESpace(DOFAdmin *admin,
70
						   const BasisFunction *basFcts,
71
72
						   Mesh *mesh,
						   const std::string& name_)
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  {
    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];
	}
      }
    }

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

}