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);
}
  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);
           }
        }
     }

  }
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);

}