CompositeFEMMethods.cc 3.72 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
#include "BasisFunction.h"
#include "DOFAdmin.h"
#include "Element.h"
#include "ElInfo.h"
#include "FiniteElemSpace.h"
#include "Global.h"
#include "Mesh.h"
#include "Parameters.h"
#include "Traverse.h"

#include "CompositeFEMMethods.h"


void
CompositeFEMMethods::setPosLsToVal(DOFVector<double> *dof,
				   const double &val,
				   const DOFVector<double> *lsFct_dof)
{
  DOFVector<double>::Iterator it_dof(dof, USED_DOFS);
  DOFVector<double>::Iterator it_lsFct_dof(
                     const_cast<DOFVector<double> *>(lsFct_dof), 
		     USED_DOFS);
  for (it_dof.reset(), it_lsFct_dof.reset();
       !it_dof.end();
       ++it_dof, ++it_lsFct_dof) {

    // Is vertex in domain with positive level set function values ?
    if (*it_lsFct_dof > 0) {
      *it_dof = val;
    }
  }
}

void
CompositeFEMMethods::setPosLsToFct(
	    DOFVector<double> *dof,
	    const AbstractFunction<double, WorldVector<double> > *fct,
	    const DOFVector<double> *lsFct_dof)
{
  const BasisFunction *basisFcts = dof->getFESpace()->getBasisFcts();
  const DOFAdmin *admin = dof->getFESpace()->getAdmin();
  const int dim = dof->getFESpace()->getMesh()->getDim();
  const double *locVec;
  const Element *el;
  const DegreeOfFreedom *locInd;
  TraverseStack stack;

  ElInfo *elInfo = stack.traverseFirst(dof->getFESpace()->getMesh(), -1, 
				       Mesh::CALL_LEAF_EL | 
				       Mesh::FILL_COORDS);
  
  while (elInfo) {

    el = elInfo->getElement();
    
    // Get level set function values for all vertices of element.
    locVec = lsFct_dof->getLocalVector(el, NULL);

    // Get dof indices of vertices.
    locInd = basisFcts->getLocalIndices(el, admin, NULL);

    for (int i=0; i<=dim; ++i) {
      // Is vertex in domain with positive level set function values ?
      if (locVec[i] > 0) {
	(*dof)[locInd[i]] = (*fct)(elInfo->getCoord(i));
      }
    }

    elInfo = stack.traverseNext(elInfo);
  }
}

void 
CompositeFEMMethods::printBoundaryElements(const std::string fn_str,
				       ElementLevelSet *elLS,
				       FiniteElemSpace *feSpace)
{
  FUNCNAME("CompositeFEMMethods::printBoundaryElements()");

  int dim = feSpace->getMesh()->getDim();
  std::string fn_main;
  std::string fn;
  GET_PARAMETER(0, fn_str + "->filename", &fn_main);
  fn = fn_main + "boundary_elements";
  int elStatus;

  ofstream boundaryOut(fn.c_str());

  // ===== Traverse mesh and print boundary elements. =====
  TraverseStack stack;
  int boundEl_cntr = 0;
  WorldVector<double> coord;

  const int nBasFcts = feSpace->getBasisFcts()->getNumber();
  DegreeOfFreedom *locInd = GET_MEMORY(DegreeOfFreedom, nBasFcts);

  ElInfo *loc_elInfo = stack.traverseFirst(feSpace->getMesh(),
					   -1, 
					   Mesh::CALL_LEAF_EL | 
					   Mesh::FILL_BOUND |
					   Mesh::FILL_COORDS);
  while(loc_elInfo) {

    // Get local indices of vertices.
    feSpace->getBasisFcts()->getLocalIndices(
	  const_cast<Element *>(loc_elInfo->getElement()),
	  const_cast<DOFAdmin *>(feSpace->getAdmin()),
	  locInd); 

    // Get element status.
    elStatus = elLS->createElementLevelSet(loc_elInfo);

    // Is element cut by the interface ?
    if (elStatus == ElementLevelSet::LEVEL_SET_BOUNDARY) {
      ++boundEl_cntr;

      boundaryOut << loc_elInfo->getElement()->getIndex() << ": \t";

      for (int i=0; i<=dim; ++i) {

	coord = loc_elInfo->getCoord(i);

	if (i > 0) {
	  boundaryOut << "\n\t";
	}

	boundaryOut << "\t" << coord[0];
	for (int j=1; j<dim; ++j) {
	  boundaryOut << "; " << coord[j] ;
	}
	boundaryOut << " (" << locInd[i] << ")";
      }
      boundaryOut << "\n";
    }

    loc_elInfo = stack.traverseNext(loc_elInfo);

  }  // end of: mesh traverse

  FREE_MEMORY(locInd, DegreeOfFreedom, nBasFcts);

  boundaryOut << "\nNumber of boundary elements: \t" << boundEl_cntr << "\n";

  boundaryOut.close();
}