FiniteElemSpace.cc 1.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "FiniteElemSpace.h"
#include "DOFAdmin.h"
#include "DOFVector.h"
#include "BasisFunction.h"
#include "Mesh.h"
#include <algorithm>

namespace AMDiS {

  ::std::vector<FiniteElemSpace*> FiniteElemSpace::feSpaces;

  FiniteElemSpace::FiniteElemSpace(DOFAdmin* admin_,
				   const BasisFunction* bas_fcts_,
				   Mesh* aMesh, const ::std::string& aString)
    : name(aString), admin(admin_), basFcts(bas_fcts_), mesh(aMesh)
  {
    FUNCNAME("FiniteElemSpace::FiniteElemSpace()");

    TEST_EXIT(mesh)("no Mesh\n");
   
    if (!admin) {
      const DOFAdmin *admin_local = NULL;
      int i, j;
      const DimVec<int> *ndof = NULL;
      ndof = basFcts->getNumberOfDOFs();
      TEST_EXIT(ndof)("no n_dof or basFcts->n_dof\n");
      for (i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
	admin_local = &(mesh->getDOFAdmin(i));
	for (j = 0; j <= mesh->getDim(); j++) {
	  if (admin_local->getNumberOfDOFs(j) != (*ndof)[j]) break;
	}
	if (j > mesh->getDim()) break;
	admin_local = NULL;
      }
      if (!admin_local) {
	admin_local = mesh->createDOFAdmin(name, *ndof);
      }
      admin = const_cast<DOFAdmin*>(admin_local);
    }

    feSpaces.push_back(this);
  }

  FiniteElemSpace *FiniteElemSpace::provideFESpace(DOFAdmin            *admin,
						   const BasisFunction *basFcts,
						   Mesh                *mesh,
						   const ::std::string&   name_)
  {
    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];
	}
      }
    }

    if(admin) {
      ERROR_EXIT("no fespace found for this admin\n");
      return NULL;
    } else {
      return NEW FiniteElemSpace(NULL, basFcts, mesh, name_);
    }
  }

}