BEBilinearFormLaplace2Layer.cpp 6.42 KB
Newer Older
Jan Zapletal's avatar
Jan Zapletal committed
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
/*!
 * @file    BEBilinearFormLaplace2Layer.cpp
 * @author  Michal Merta
 * @date    August 8, 2013
 *
 */

#ifdef BEBILINEARFORMLAPLACE2LAYER_H

namespace bem4i {

template<class LO, class SC>
BEBilinearFormLaplace2Layer<LO, SC>::BEBilinearFormLaplace2Layer( ) {
}

template<class LO, class SC>
BEBilinearFormLaplace2Layer<LO, SC>::BEBilinearFormLaplace2Layer(
  const BEBilinearFormLaplace2Layer& orig
  ) {
  this->space = orig.space;
  this->quadratureOrder = orig.quadratureOrder;
  this->quadratureOrderDisjointElems = orig.quadratureOrderDisjointElems;
}

template<class LO, class SC>
BEBilinearFormLaplace2Layer<LO, SC>::BEBilinearFormLaplace2Layer(
  BESpace<LO, SC>* space,
  int* quadratureOrder,
  quadratureType quadrature,
  int* quadratureOrderDisjointElems
  ) {

  this->quadrature = quadrature;
  this->space = space;
  if ( quadratureOrder ) {
    this->quadratureOrder = quadratureOrder;
  } else {
    switch ( quadrature ) {
      case SauterSchwab:
        this->quadratureOrder = defaultQuadraturesSauterSchwab;
        break;
      case Steinbach:
        this->quadratureOrder = defaultQuadraturesSteinbach;
    }
  }

  this->quadratureOrderDisjointElems = quadratureOrderDisjointElems;

}

template<class LO, class SC>
BEBilinearFormLaplace2Layer<LO, SC>::~BEBilinearFormLaplace2Layer( ) {
}

template<class LO, class SC>
void BEBilinearFormLaplace2Layer<LO, SC>::assemble(
  FullMatrix<LO, SC>& matrix
  ) const {

  if ( this->space->getAnsatzFunctionType( ) == p1 &&
    this->space->getTestFunctionType( ) == p0 ) {

    this->assembleP0P1( matrix );
    return;
  } else if ( this->space->getAnsatzFunctionType( ) == p1 &&
    this->space->getTestFunctionType( ) == p1 ) {

    this->assembleP1P1( matrix );
    return;
  } else if ( this->space->getAnsatzFunctionType( ) == p0 &&
    this->space->getTestFunctionType( ) == p0 ) {

    this->assembleP0P0( matrix );
    return;
  } else if ( this->space->getTestFunctionType( ) == p1dis &&
    this->space->getAnsatzFunctionType( ) == p1dis ) {

    this->assembleP1DisP1Dis( matrix );
    return;
  }
}

template<class LO, class SC>
void BEBilinearFormLaplace2Layer<LO, SC>::assembleP0P1(
  FullMatrix<LO, SC> & matrix
  ) const {


  LO nNodes = this->space->getMesh( )->getNNodes( );
  LO nElems = this->space->getMesh( )->getNElements( );

  matrix.resize( nElems, nNodes, false );
  SC * matrixData = matrix.getData( );

#pragma omp parallel for schedule( static, 32 )
  for ( LO j = 0; j < nNodes; ++j ) {
    for ( LO i = 0; i < nElems; ++i ) {
      matrixData[ j * nElems + i ] = 0.0;
    }
  }

#pragma omp parallel
  {
    BEIntegratorLaplace<LO, SC> integrator( this->space, this->quadratureOrder,
      this->quadrature, this->quadratureOrderDisjointElems );

    FullMatrix< LO, SC > elemMatrix( 1, 3 );
    LO elem[ 3 ];

#pragma omp for schedule( dynamic, 8 )
    for ( LO i = 0; i < nElems; ++i ) {
      for ( LO j = 0; j < nElems; ++j ) {

        integrator.getElemMatrix2Layer( i, j, elemMatrix );
        this->space->getMesh( )->getElement( j, elem );

        matrixData[ elem[ 0 ] * nElems + i ] += elemMatrix.get( 0, 0 );
        matrixData[ elem[ 1 ] * nElems + i ] += elemMatrix.get( 0, 1 );
        matrixData[ elem[ 2 ] * nElems + i ] += elemMatrix.get( 0, 2 );
      }
    }
  } // end omp parallel
}

template<class LO, class SC>
void BEBilinearFormLaplace2Layer<LO, SC>::assembleP1P1(
  FullMatrix<LO, SC> & matrix
  ) const {

  LO nNodes = this->space->getMesh( )->getNNodes( );
  LO nElems = this->space->getMesh( )->getNElements( );

  matrix.resize( nNodes, nNodes, false );
  SC * matrixData = matrix.getData( );

#pragma omp parallel for schedule( static, 32 )
  for ( LO j = 0; j < nNodes; ++j ) {
    for ( LO i = 0; i < nNodes; ++i ) {
      matrixData[ j * nNodes + i ] = 0.0;
    }
  }

#pragma omp parallel
  {
    BEIntegratorLaplace<LO, SC> integrator( this->space,
      this->quadratureOrder, this->quadrature,
      this->quadratureOrderDisjointElems );

    FullMatrix< LO, SC > elemMatrix( 3, 3 );
    LO iElem[ 3 ], oElem[ 3 ];

    SC * elemMatrixData = elemMatrix.getData( );

#pragma omp for schedule( dynamic, 32 )
    for ( LO i = 0; i < nElems; ++i ) { // i outer row
      for ( LO j = 0; j < nElems; ++j ) { // j inner col
        integrator.getElemMatrix2Layer( i, j, elemMatrix );
        this->space->getMesh( )->getElement( i, oElem );
        this->space->getMesh( )->getElement( j, iElem );

        for ( int oRot = 0; oRot < 3; ++oRot ) {
          for ( int iRot = 0; iRot < 3; ++iRot ) {
#pragma omp atomic update
            matrixData[ iElem[ iRot ] * nNodes + oElem[ oRot ] ] +=
              elemMatrixData[ iRot * 3 + oRot ];
          }
        }
      }
    }
  } // end omp parallel
}

template<class LO, class SC>
void BEBilinearFormLaplace2Layer<LO, SC>::assembleP1DisP1Dis(
  FullMatrix<LO, SC> & matrix
  ) const {

  LO nElems = this->space->getMesh( )->getNElements( );

  matrix.resize( 3 * nElems, 3 * nElems, false );
  SC * matrixData = matrix.getData( );

#pragma omp parallel
  {
    BEIntegratorLaplace<LO, SC> integrator( this->space,
      this->quadratureOrder, this->quadrature,
      this->quadratureOrderDisjointElems );

    FullMatrix< LO, SC > elemMatrix( 3, 3 );

    SC * elemMatrixData = elemMatrix.getData( );

#pragma omp for //schedule( dynamic, 8 )
    for ( LO j = 0; j < nElems; ++j ) { // j inner col
      for ( LO i = 0; i < nElems; ++i ) { // i outer row
        integrator.getElemMatrix2Layer( i, j, elemMatrix );

        for ( int oRot = 0; oRot < 3; ++oRot ) {
          for ( int iRot = 0; iRot < 3; ++iRot ) {
            matrixData[ ( 3 * j + iRot ) * 3 * nElems + 3 * i + oRot ] =
              elemMatrixData[ iRot * 3 + oRot ];
          }
        }
      }
    }
  } // end omp parallel
}

template<class LO, class SC>
void BEBilinearFormLaplace2Layer<LO, SC>::assembleP0P0(
  FullMatrix<LO, SC> & matrix
  ) const {

  LO nElems = this->space->getMesh( )->getNElements( );

  matrix.resize( nElems, nElems, false );
  SC * matrixData = matrix.getData( );

#pragma omp parallel
  {
    BEIntegratorLaplace<LO, SC> integrator( this->space, this->quadratureOrder,
      this->quadrature, this->quadratureOrderDisjointElems );

    FullMatrix< LO, SC > elemMatrix( 1, 1 );

#pragma omp for schedule( dynamic, 8 )
    for ( LO j = 0; j < nElems; ++j ) {
      for ( LO i = 0; i < nElems; ++i ) {
        integrator.getElemMatrix2Layer( i, j, elemMatrix );
        matrixData[ j * nElems + i ] = elemMatrix.get( 0, 0 );
      }
    }
  } // end omp parallel
}

}

#endif