Skip to content
Snippets Groups Projects
DirichletBC.cc 1.89 KiB
#include "DirichletBC.h"
#include "ElInfo.h"
#include "BasisFunction.h"
#include "DOFVector.h"
#include "DOFMatrix.h"

namespace AMDiS {

  DirichletBC::DirichletBC(BoundaryType type,
			   AbstractFunction<double, WorldVector<double> > *fct,
			   FiniteElemSpace *rowFESpace,
			   FiniteElemSpace *colFESpace,
			   bool apply)
    : BoundaryCondition(type, rowFESpace, colFESpace), 
      f(fct), 
      dofVec(NULL),
      applyBC(apply)
  {
    worldCoords.resize(omp_get_overall_max_threads());
  }

  DirichletBC::DirichletBC(BoundaryType type,
			   DOFVectorBase<double> *vec)
    : BoundaryCondition(type, vec->getFESpace()), 
      f(NULL), 
      dofVec(vec),
      applyBC(true)
  {
    worldCoords.resize(omp_get_overall_max_threads());
  }

  void DirichletBC::fillBoundaryCondition(DOFMatrix* matrix,
					  ElInfo* elInfo,
					  const DegreeOfFreedom* dofIndices,
					  const BoundaryType* localBound,
					  int nBasFcts)
  {
    FUNCNAME("DirichletBC::fillBoundaryCondition()");
    TEST_EXIT_DBG(matrix->getRowFESpace() == rowFESpace)("invalid row fe space\n");
  }

  void DirichletBC::fillBoundaryCondition(DOFVectorBase<double>* vector,
					  ElInfo* elInfo,
					  const DegreeOfFreedom* dofIndices,
					  const BoundaryType* localBound,
					  int nBasFcts)
  {
    FUNCNAME("DirichletBC::fillBoundaryCondition()");

    TEST_EXIT_DBG(vector->getFESpace() == rowFESpace)("invalid row fe space\n");

    const BasisFunction *basFcts = rowFESpace->getBasisFcts();
    int myRank = omp_get_thread_num();

    for (int i = 0; i < nBasFcts; i++) {
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
      if (vector->isRankDof(dofIndices[i]))
#endif
      if (localBound[i] == boundaryType) {
	if (f) {
          elInfo->coordToWorld(*(basFcts->getCoords(i)), worldCoords[myRank]);
	  (*vector)[dofIndices[i]] = (*f)(worldCoords[myRank]);
	}
	if (dofVec)
	  (*vector)[dofIndices[i]] = (*dofVec)[dofIndices[i]];
      }
    }
  }

}