void IntegrationValues2<Scalar>::
  getCubatureCV(const PHX::MDField<Scalar,Cell,NODE,Dim>& in_node_coordinates)
  {
    int num_space_dim = int_rule->topology->getDimension();
    if (int_rule->isSide() && num_space_dim==1) {
       std::cout << "WARNING: 0-D quadrature rule infrastructure does not exist!!! Will not be able to do "
                 << "non-natural integration rules.";
       return; 
    }
     {
      size_type num_cells = in_node_coordinates.dimension(0);
      size_type num_nodes = in_node_coordinates.dimension(1);
      size_type num_dims = in_node_coordinates.dimension(2);

      for (size_type cell = 0; cell < num_cells;  ++cell) {
        for (size_type node = 0; node < num_nodes; ++node) {
          for (size_type dim = 0; dim < num_dims; ++dim) {
            node_coordinates(cell,node,dim) =
                in_node_coordinates(cell,node,dim);
            dyn_node_coordinates(cell,node,dim) =
                Sacado::ScalarValue<Scalar>::eval(in_node_coordinates(cell,node,dim));
          }
        }
      }
     }

    if (int_rule->cv_type == "side")
      intrepid_cubature->getCubature(dyn_phys_cub_points.get_view(),dyn_phys_cub_norms.get_view(),dyn_node_coordinates.get_view());
    else 
      intrepid_cubature->getCubature(dyn_phys_cub_points.get_view(),dyn_phys_cub_weights.get_view(),dyn_node_coordinates.get_view());

    size_type num_cells = dyn_phys_cub_points.dimension(0);
    size_type num_ip =dyn_phys_cub_points.dimension(1); 
    size_type num_dims = dyn_phys_cub_points.dimension(2);

    for (size_type cell = 0; cell < num_cells;  ++cell) {
        for (size_type ip = 0; ip < num_ip;  ++ip) {
           if (int_rule->cv_type != "side")
               weighted_measure(cell,ip) = dyn_phys_cub_weights(cell,ip);
           for (size_type dim = 0; dim < num_dims; ++dim) {
               ip_coordinates(cell,ip,dim) = dyn_phys_cub_points(cell,ip,dim);
               if (int_rule->cv_type == "side")
                  weighted_normals(cell,ip,dim) = dyn_phys_cub_norms(cell,ip,dim);
           }
        }
     }

  }
    virtual void evaluateContainer(const PHX::MDField<panzer::Traits::Residual::ScalarT,panzer::Cell,panzer::IP,panzer::Dim> & points,
                                   PHX::MDField<panzer::Traits::Residual::ScalarT> & field) const
    {
        int num_cells = field.dimension(0);
        int num_qp = points.dimension(1);

        for(int i=0; i<num_cells; i++) {
            for(int j=0; j<num_qp; j++) {
                double x = points(i,j,0); // just x and y
                double y = points(i,j,1);

                field(i,j,0) = (x+y)*(x+y);
                field(i,j,1) = sin(x+y);
            }
        }
    }
void IntegrationValues2<Scalar>::
evaluateValues(const PHX::MDField<Scalar,Cell,NODE,Dim>& in_node_coordinates,
               const PHX::MDField<Scalar,Cell,IP,Dim>& other_ip_coordinates)
{
    getCubature(in_node_coordinates);

    {
        // Determine the permutation.
        std::vector<size_type> permutation(other_ip_coordinates.dimension(1));
        permuteToOther(ip_coordinates, other_ip_coordinates, permutation);
        // Apply the permutation to the cubature arrays.
        MDFieldArrayFactory af(prefix, alloc_arrays);
        const size_type num_ip = dyn_cub_points.dimension(0);
        {
            const size_type num_dim = dyn_side_cub_points.dimension(1);
            DblArrayDynamic old_dyn_side_cub_points = af.template buildArray<double,IP,Dim>(
                        "old_dyn_side_cub_points", num_ip, num_dim);
            old_dyn_side_cub_points.deep_copy(dyn_side_cub_points);
            for (size_type ip = 0; ip < num_ip; ++ip)
                if (ip != permutation[ip])
                    for (size_type dim = 0; dim < num_dim; ++dim)
                        dyn_side_cub_points(ip, dim) = old_dyn_side_cub_points(permutation[ip], dim);
        }
        {
            const size_type num_dim = dyn_cub_points.dimension(1);
            DblArrayDynamic old_dyn_cub_points = af.template buildArray<double,IP,Dim>(
                    "old_dyn_cub_points", num_ip, num_dim);
            old_dyn_cub_points.deep_copy(dyn_cub_points);
            for (size_type ip = 0; ip < num_ip; ++ip)
                if (ip != permutation[ip])
                    for (size_type dim = 0; dim < num_dim; ++dim)
                        dyn_cub_points(ip, dim) = old_dyn_cub_points(permutation[ip], dim);
        }
        {
            DblArrayDynamic old_dyn_cub_weights = af.template buildArray<double,IP>(
                    "old_dyn_cub_weights", num_ip);
            old_dyn_cub_weights.deep_copy(dyn_cub_weights);
            for (size_type ip = 0; ip < dyn_cub_weights.dimension(0); ++ip)
                if (ip != permutation[ip])
                    dyn_cub_weights(ip) = old_dyn_cub_weights(permutation[ip]);
        }
        {
            const size_type num_cells = ip_coordinates.dimension(0), num_ip = ip_coordinates.dimension(1),
                            num_dim = ip_coordinates.dimension(2);
            Array_CellIPDim old_ip_coordinates = af.template buildStaticArray<Scalar,Cell,IP,Dim>(
                    "old_ip_coordinates", num_cells, num_ip, num_dim);
            Kokkos::deep_copy(old_ip_coordinates.get_kokkos_view(), ip_coordinates.get_kokkos_view());
            for (size_type cell = 0; cell < num_cells; ++cell)
                for (size_type ip = 0; ip < num_ip; ++ip)
                    if (ip != permutation[ip])
                        for (size_type dim = 0; dim < num_dim; ++dim)
                            ip_coordinates(cell, ip, dim) = old_ip_coordinates(cell, permutation[ip], dim);
        }
        // All subsequent calculations inherit the permutation.
    }

    evaluateRemainingValues(in_node_coordinates);
}
//**********************************************************************
PHX_EVALUATE_FIELDS(CoordinatesEvaluator,d)
{
    PHX::MDField<double,Cell,NODE,Dim> coords = this->wda(d).cell_vertex_coordinates;
    // const Intrepid::FieldContainer<double> & coords = this->wda(d).cell_vertex_coordinates;

    // copy coordinates directly into the field
    for(std::size_t i=0; i<d.num_cells; i++)
        for(int j=0; j<coords.dimension(1); j++)
            coordinate(i,j) = coords(i,j,dimension);
}
void transformWeightedGradientBF (
    const Field<2>& F, const RealType& F_det,
    const PHX::MDField<RealType, Cell, Node, QuadPoint, Dim>& w_grad_bf,
    const int cell, const int pt, const int node, RealType w[3])
{
    const int nd = w_grad_bf.dimension(3);
    for (int k = 0; k < nd; ++k) {
        w[k] = 0;
        for (int i = 0; i < nd; ++i)
            w[k] += (w_grad_bf(cell, node, pt, i) * F()(cell, pt, i, k));
        w[k] /= F_det;
    }
}
static void
permuteToOther(const PHX::MDField<Scalar,Cell,IP,Dim>& coords,
               const PHX::MDField<Scalar,Cell,IP,Dim>& other_coords,
               std::vector<typename ArrayTraits<Scalar,PHX::MDField<Scalar> >::size_type>& permutation)
{
    typedef typename ArrayTraits<Scalar,PHX::MDField<Scalar> >::size_type size_type;
    // We can safely assume: (1) The permutation is the same for every cell in
    // the workset. (2) The first workset has valid data. Hence we operate only
    // on cell 0.
    const size_type cell = 0;
    const size_type num_ip = coords.dimension(1), num_dim = coords.dimension(2);
    permutation.resize(num_ip);
    std::vector<char> taken(num_ip, 0);
    for (size_type ip = 0; ip < num_ip; ++ip) {
        // Find an other point to associate with ip.
        size_type i_min = 0;
        Scalar d_min = -1;
        for (size_type other_ip = 0; other_ip < num_ip; ++other_ip) {
            // For speed, skip other points that are already associated.
            if (taken[other_ip]) continue;
            // Compute the distance between the two points.
            Scalar d(0);
            for (size_type dim = 0; dim < num_dim; ++dim) {
                const Scalar diff = coords(cell, ip, dim) - other_coords(cell, other_ip, dim);
                d += diff*diff;
            }
            if (d_min < 0 || d < d_min) {
                d_min = d;
                i_min = other_ip;
            }
        }
        // Record the match.
        permutation[ip] = i_min;
        // This point is now taken.
        taken[i_min] = 1;
    }
}
Beispiel #7
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);
      }
    }

  }
void IntegrationValues2<Scalar>::
evaluateValuesCV(const PHX::MDField<Scalar,Cell,NODE,Dim> & in_node_coordinates)
{

    Intrepid2::CellTools<Scalar> cell_tools;

    {
        size_type num_cells = in_node_coordinates.dimension(0);
        size_type num_nodes = in_node_coordinates.dimension(1);
        size_type num_dims = in_node_coordinates.dimension(2);

        for (size_type cell = 0; cell < num_cells;  ++cell) {
            for (size_type node = 0; node < num_nodes; ++node) {
                for (size_type dim = 0; dim < num_dims; ++dim) {
                    node_coordinates(cell,node,dim) =
                        in_node_coordinates(cell,node,dim);
                    dyn_node_coordinates(cell,node,dim) =
                        Sacado::ScalarValue<Scalar>::eval(in_node_coordinates(cell,node,dim));
                }
            }
        }
    }

    if (int_rule->cv_type == "volume")
        intrepid_cubature->getCubature(dyn_phys_cub_points,dyn_phys_cub_weights,dyn_node_coordinates);

    else if (int_rule->cv_type == "side")
        intrepid_cubature->getCubature(dyn_phys_cub_points,dyn_phys_cub_norms,dyn_node_coordinates);

    if (int_rule->cv_type == "volume")
    {
        size_type num_cells = dyn_phys_cub_points.dimension(0);
        size_type num_ip = dyn_phys_cub_points.dimension(1);
        size_type num_dims = dyn_phys_cub_points.dimension(2);

        for (size_type cell = 0; cell < num_cells;  ++cell) {
            for (size_type ip = 0; ip < num_ip;  ++ip) {
                weighted_measure(cell,ip) = dyn_phys_cub_weights(cell,ip);
                for (size_type dim = 0; dim < num_dims; ++dim)
                    ip_coordinates(cell,ip,dim) = dyn_phys_cub_points(cell,ip,dim);
            }
        }
        cell_tools.mapToReferenceFrame(ref_ip_coordinates, ip_coordinates, node_coordinates,
                                       *(int_rule->topology),-1);

        cell_tools.setJacobian(jac, ref_ip_coordinates, node_coordinates,
                               *(int_rule->topology));

    }
    else if (int_rule->cv_type == "side")
    {
        size_type num_cells = dyn_phys_cub_points.dimension(0);
        size_type num_ip = dyn_phys_cub_points.dimension(1);
        size_type num_dims = dyn_phys_cub_points.dimension(2);

        for (size_type cell = 0; cell < num_cells;  ++cell) {
            for (size_type ip = 0; ip < num_ip;  ++ip) {
                for (size_type dim = 0; dim < num_dims; ++dim) {
                    ip_coordinates(cell,ip,dim) = dyn_phys_cub_points(cell,ip,dim);
                    weighted_normals(cell,ip,dim) = dyn_phys_cub_norms(cell,ip,dim);
                }
            }
        }

        cell_tools.mapToReferenceFrame(ref_ip_coordinates, ip_coordinates, node_coordinates,
                                       *(int_rule->topology),-1);
        cell_tools.setJacobian(jac, ref_ip_coordinates, node_coordinates,
                               *(int_rule->topology));
    }

    cell_tools.setJacobianInv(jac_inv, jac);

    cell_tools.setJacobianDet(jac_det, jac);

}
void IntegrationValues2<Scalar>::
evaluateRemainingValues(const PHX::MDField<Scalar,Cell,NODE,Dim>& in_node_coordinates)
{
    Intrepid2::CellTools<Scalar> cell_tools;

    // copy the dynamic data structures into the static data structures
    {
        size_type num_ip = dyn_cub_points.dimension(0);
        size_type num_dims = dyn_cub_points.dimension(1);

        for (size_type ip = 0; ip < num_ip;  ++ip) {
            cub_weights(ip) = dyn_cub_weights(ip);
            for (size_type dim = 0; dim < num_dims; ++dim)
                cub_points(ip,dim) = dyn_cub_points(ip,dim);
        }
    }

    if (int_rule->isSide()) {
        const size_type num_ip = dyn_cub_points.dimension(0), num_side_dims = dyn_side_cub_points.dimension(1);
        for (size_type ip = 0; ip < num_ip; ++ip)
            for (size_type dim = 0; dim < num_side_dims; ++dim)
                side_cub_points(ip,dim) = dyn_side_cub_points(ip,dim);
    }

    {
        size_type num_cells = in_node_coordinates.dimension(0);
        size_type num_nodes = in_node_coordinates.dimension(1);
        size_type num_dims = in_node_coordinates.dimension(2);

        for (size_type cell = 0; cell < num_cells;  ++cell) {
            for (size_type node = 0; node < num_nodes; ++node) {
                for (size_type dim = 0; dim < num_dims; ++dim) {
                    node_coordinates(cell,node,dim) =
                        in_node_coordinates(cell,node,dim);
                }
            }
        }
    }

    cell_tools.setJacobian(jac, cub_points, node_coordinates,
                           *(int_rule->topology));

    cell_tools.setJacobianInv(jac_inv, jac);

    cell_tools.setJacobianDet(jac_det, jac);

    if (!int_rule->isSide()) {
        Intrepid2::FunctionSpaceTools::
        computeCellMeasure<Scalar>(weighted_measure, jac_det, cub_weights);
    }
    else if(int_rule->spatial_dimension==3) {
        Intrepid2::FunctionSpaceTools::
        computeFaceMeasure<Scalar>(weighted_measure, jac, cub_weights,int_rule->side,*int_rule->topology);
    }
    else if(int_rule->spatial_dimension==2) {
        Intrepid2::FunctionSpaceTools::
        computeEdgeMeasure<Scalar>(weighted_measure, jac, cub_weights,int_rule->side,*int_rule->topology);
    }
    else TEUCHOS_ASSERT(false);

    // Shakib contravarient metric tensor
    for (size_type cell = 0; cell < contravarient.dimension(0); ++cell) {
        for (size_type ip = 0; ip < contravarient.dimension(1); ++ip) {

            // zero out matrix
            for (size_type i = 0; i < contravarient.dimension(2); ++i)
                for (size_type j = 0; j < contravarient.dimension(3); ++j)
                    covarient(cell,ip,i,j) = 0.0;

            // g^{ij} = \frac{\parital x_i}{\partial \chi_\alpha}\frac{\parital x_j}{\partial \chi_\alpha}
            for (size_type i = 0; i < contravarient.dimension(2); ++i) {
                for (size_type j = 0; j < contravarient.dimension(3); ++j) {
                    for (size_type alpha = 0; alpha < contravarient.dimension(2); ++alpha) {
                        covarient(cell,ip,i,j) += jac(cell,ip,i,alpha) * jac(cell,ip,j,alpha);
                    }
                }
            }

        }
    }

    Intrepid2::RealSpaceTools<Scalar>::inverse(contravarient, covarient);

    // norm of g_ij
    for (size_type cell = 0; cell < contravarient.dimension(0); ++cell) {
        for (size_type ip = 0; ip < contravarient.dimension(1); ++ip) {
            norm_contravarient(cell,ip) = 0.0;
            for (size_type i = 0; i < contravarient.dimension(2); ++i) {
                for (size_type j = 0; j < contravarient.dimension(3); ++j) {
                    norm_contravarient(cell,ip) += contravarient(cell,ip,i,j) * contravarient(cell,ip,i,j);
                }
            }
            norm_contravarient(cell,ip) = std::sqrt(norm_contravarient(cell,ip));
        }
    }
}