DirichletBC.cc 2.89 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20
21


22
23
24
25
26
27
28
29
#include "DirichletBC.h"
#include "ElInfo.h"
#include "BasisFunction.h"
#include "DOFVector.h"
#include "DOFMatrix.h"

namespace AMDiS {

30
31
  DirichletBC::DirichletBC(BoundaryType type,
			   AbstractFunction<double, WorldVector<double> > *fct,
32
33
			   const FiniteElemSpace *rowFeSpace,
			   const FiniteElemSpace *colFeSpace,
34
			   bool apply)
35
    : BoundaryCondition(type, rowFeSpace, colFeSpace), 
36
      f(fct), 
37
      dofVec(NULL),
38
      applyBC(apply)
39
  {}
40

41

42
  DirichletBC::DirichletBC(BoundaryType type,
43
44
			   DOFVectorBase<double> *vec,
			   bool apply)
45
    : BoundaryCondition(type, vec->getFeSpace(), vec->getFeSpace()), 
46
      f(NULL), 
47
      dofVec(vec),
48
49
50
      applyBC(apply)
  {}

51

52
53
  void DirichletBC::fillBoundaryCondition(DOFMatrix* matrix,
					  ElInfo* elInfo,
54
					  const DegreeOfFreedom* dofIndices,
55
56
					  const BoundaryType* localBound,
					  int nBasFcts)
57
  {
58
    FUNCNAME_DBG("DirichletBC::fillBoundaryCondition()");
59
    TEST_EXIT_DBG(matrix->getRowFeSpace() == rowFeSpace)("invalid row fe space\n");
60
61
  }

62

63
64
  void DirichletBC::fillBoundaryCondition(DOFVectorBase<double>* vector,
					  ElInfo* elInfo,
65
					  const DegreeOfFreedom* dofIndices,
66
67
					  const BoundaryType* localBound,
					  int nBasFcts)
68
69
  {
    FUNCNAME("DirichletBC::fillBoundaryCondition()");
70

71
    TEST_EXIT_DBG(vector->getFeSpace() == rowFeSpace)("invalid row fe space\n");
72

73
    const BasisFunction *basFcts = rowFeSpace->getBasisFcts();
74

75
76
77
    if (f) {
      for (int i = 0; i < nBasFcts; i++)
	if (localBound[i] == boundaryType) {
78
	  elInfo->coordToWorld(*(basFcts->getCoords(i)), worldCoords);
79
80
81
	  double value = (*f)(worldCoords);
	  vector->setDirichletDofValue(dofIndices[i], value);
	  (*vector)[dofIndices[i]] = value;
Thomas Witkowski's avatar
Thomas Witkowski committed
82
	}
83
84
85
86
87
88
89
90
91
    } else if (dofVec) {
      for (int i = 0; i < nBasFcts; i++)
	if (localBound[i] == boundaryType) {
	  double value = value = (*dofVec)[dofIndices[i]];
	  vector->setDirichletDofValue(dofIndices[i], value);
	  (*vector)[dofIndices[i]] = value;
	}
    } else {
      ERROR_EXIT("No data provided to assemble DirichletBC!\n");
92
93
94
    }
  }

95
96
97
98
99
100
101

  void DirichletBC::initVector(DOFVectorBase<double>* vec)
  {
    if (dynamic_cast<DOFVector<double>*>(vec))
      dynamic_cast<DOFVector<double>*>(vec)->getDirichletValues().clear();
  }

102
}