Exemplo n.º 1
0
int main(int argc, char** argv) {
  GammaFunction<size_t> G_1;

  std::cout << "G_1(1): " << G_1(1) << std::endl;
  if (G_1(1) != 1)
    return 1;

  std::cout << "G_1(2): " << G_1(2) << std::endl;
  if (G_1(2) != 1)
    return 1;

  try {
    std::cout << "G_1(0): " << G_1(0) << std::endl;
  }
  catch (BadArgumentException<size_t>& e) {
    std::cout << e.what() << std::endl;
  }

  FactorialFunction f;
  if (G_1(10) != f(9))
    return 1;

  GammaFunction<double> G_2;

  std::cout << "G_2(0.5): " << G_2(0.5) << std::endl;
  if (fabs(G_2(0.5) - sqrt(M_PI)) > std::numeric_limits<double>::epsilon())
    return 1;

  std::cout << "G_2(1.0): " << G_2(1.0) << std::endl;
  if (fabs(G_2(1.0) - 1.0) > std::numeric_limits<double>::epsilon())
    return 1;

  return 0;
}
  void SurfaceScalarGradient<EvalT, Traits>::
  evaluateFields(typename Traits::EvalData workset)
  {
    ScalarT midPlaneAvg;
    for (int cell=0; cell < workset.numCells; ++cell) {
      for (int pt=0; pt < numQPs; ++pt) {

        Intrepid2::Vector<MeshScalarT> G_0(3, refDualBasis, cell, pt, 0, 0);
        Intrepid2::Vector<MeshScalarT> G_1(3, refDualBasis, cell, pt, 1, 0);
        Intrepid2::Vector<MeshScalarT> G_2(3, refDualBasis, cell, pt, 2, 0);
        Intrepid2::Vector<MeshScalarT> N(3, refNormal,cell, pt, 0);

        Intrepid2::Vector<ScalarT> scalarGradPerpendicular(0, 0, 0);
        Intrepid2::Vector<ScalarT> scalarGradParallel(0, 0, 0);

       // Need to inverse basis [G_0 ; G_1; G_2] and none of them should be normalized
        Intrepid2::Tensor<MeshScalarT> gBasis(3, refDualBasis,cell, pt, 0, 0);
        Intrepid2::Tensor<MeshScalarT> invRefDualBasis(3);

        // This map the position vector from parent to current configuration in R^3
        gBasis = Intrepid2::transpose(gBasis);
       invRefDualBasis = Intrepid2::inverse(gBasis);

        Intrepid2::Vector<MeshScalarT> invG_0(3, &invRefDualBasis( 0, 0));
        Intrepid2::Vector<MeshScalarT> invG_1(3, &invRefDualBasis( 1, 0));
        Intrepid2::Vector<MeshScalarT> invG_2(3, &invRefDualBasis( 2, 0));

        // in-plane (parallel) contribution
        for (int node(0); node < numPlaneNodes; ++node) {
          int topNode = node + numPlaneNodes;
          midPlaneAvg = 0.5 * (nodalScalar(cell, node) + nodalScalar(cell, topNode));
          for (int i(0); i < numDims; ++i) {
            scalarGradParallel(i) += 
              refGrads(node, pt, 0) * midPlaneAvg * invG_0(i) +
              refGrads(node, pt, 1) * midPlaneAvg * invG_1(i);
          }
        }

        // normal (perpendicular) contribution
        for (int i(0); i < numDims; ++i) {
          scalarGradPerpendicular(i) = jump(cell,pt) / thickness *invG_2(i);
        }

        // assign components to MDfield ScalarGrad
        for (int i(0); i < numDims; ++i )
          scalarGrad(cell, pt, i) = scalarGradParallel(i) + scalarGradPerpendicular(i);
      }
    }
  }
Exemplo n.º 3
0
  void SurfaceBasis<EvalT, Traits>::computeJacobian(
      const PHX::MDField<MeshScalarT, Cell, QuadPoint, Dim, Dim> basis,
      const PHX::MDField<MeshScalarT, Cell, QuadPoint, Dim, Dim> dualBasis,
      PHX::MDField<MeshScalarT, Cell, QuadPoint> area)
  {
    const std::size_t worksetSize = basis.dimension(0);

    for (std::size_t cell(0); cell < worksetSize; ++cell) {
      for (std::size_t pt(0); pt < numQPs; ++pt) {
        Intrepid::Tensor<MeshScalarT> dPhiInv(3, &dualBasis(cell, pt, 0, 0));
        Intrepid::Tensor<MeshScalarT> dPhi(3, &basis(cell, pt, 0, 0));
        Intrepid::Vector<MeshScalarT> G_2(3, &basis(cell, pt, 2, 0));

        MeshScalarT j0 = Intrepid::det(dPhi);
        MeshScalarT jacobian = j0 *
          std::sqrt( Intrepid::dot(Intrepid::dot(G_2, Intrepid::transpose(dPhiInv) * dPhiInv), G_2));
        area(cell, pt) = jacobian * refWeights(pt);
      }
    }

  }
Exemplo n.º 4
0
  void SurfaceVectorGradient<EvalT, Traits>::
  evaluateFields(typename Traits::EvalData workset)
  {
    for (std::size_t cell=0; cell < workset.numCells; ++cell) {
      for (std::size_t pt=0; pt < numQPs; ++pt) {
        Intrepid::Vector<ScalarT> g_0(3, &currentBasis(cell, pt, 0, 0));
        Intrepid::Vector<ScalarT> g_1(3, &currentBasis(cell, pt, 1, 0));
        Intrepid::Vector<ScalarT> g_2(3, &currentBasis(cell, pt, 2, 0));
        Intrepid::Vector<ScalarT> G_2(3, &refNormal(cell, pt, 0));
        Intrepid::Vector<ScalarT> d(3, &jump(cell, pt, 0));
        Intrepid::Vector<ScalarT> G0(3, &refDualBasis(cell, pt, 0, 0));
        Intrepid::Vector<ScalarT> G1(3, &refDualBasis(cell, pt, 1, 0));
        Intrepid::Vector<ScalarT> G2(3, &refDualBasis(cell, pt, 2, 0));

        Intrepid::Tensor<ScalarT>
        Fpar(Intrepid::bun(g_0, G0) +
            Intrepid::bun(g_1, G1) +
            Intrepid::bun(g_2, G2));
        // for Jay: bun()
        Intrepid::Tensor<ScalarT> Fper((1 / thickness) * Intrepid::bun(d, G_2));

        Intrepid::Tensor<ScalarT> F = Fpar + Fper;

        defGrad(cell, pt, 0, 0) = F(0, 0);
        defGrad(cell, pt, 0, 1) = F(0, 1);
        defGrad(cell, pt, 0, 2) = F(0, 2);
        defGrad(cell, pt, 1, 0) = F(1, 0);
        defGrad(cell, pt, 1, 1) = F(1, 1);
        defGrad(cell, pt, 1, 2) = F(1, 2);
        defGrad(cell, pt, 2, 0) = F(2, 0);
        defGrad(cell, pt, 2, 1) = F(2, 1);
        defGrad(cell, pt, 2, 2) = F(2, 2);

        J(cell,pt) = Intrepid::det(F);
      }
    }

    if (weightedAverage)
    {
      ScalarT Jbar, wJbar, vol;
      for (std::size_t cell=0; cell < workset.numCells; ++cell)
      {
        Jbar = 0.0;
        vol = 0.0;
        for (std::size_t qp=0; qp < numQPs; ++qp)
        {
          Jbar += weights(cell,qp) * std::log( J(cell,qp) );
          vol  += weights(cell,qp);
        }
        Jbar /= vol;

        // Jbar = std::exp(Jbar);
        for (std::size_t qp=0; qp < numQPs; ++qp)
        {
          for (std::size_t i=0; i < numDims; ++i)
          {
            for (std::size_t j=0; j < numDims; ++j)
            {
              wJbar = std::exp( (1-alpha) * Jbar + alpha * std::log( J(cell,qp) ) );
              defGrad(cell,qp,i,j) *= std::pow( wJbar / J(cell,qp) ,1./3. );
            }
          }
          J(cell,qp) = wJbar;
        }
      }
    }

  }