<commit_before>// Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#include "../config/config.hpp"

#ifdef MFEM_USE_MPI

#include "restriction.hpp"
#include "prestriction.hpp"
#include "pgridfunc.hpp"
#include "pfespace.hpp"
#include "fespace.hpp"
#include "../general/forall.hpp"

namespace mfem
{

ParNCH1FaceRestriction::ParNCH1FaceRestriction(const ParFiniteElementSpace &fes,
                                               ElementDofOrdering ordering,
                                               FaceType type)
   : H1FaceRestriction(fes, ordering, type, false),
     type(type),
     interpolations(fes, ordering, type)
{
   if (nf==0) { return; }
   x_interp.UseDevice(true);

   CheckFESpace(ordering);

   ComputeScatterIndicesAndOffsets(ordering, type);

   ComputeGatherIndices(ordering, type);
}

void ParNCH1FaceRestriction::Mult(const Vector &x, Vector &y) const
{
   H1FaceRestriction::Mult(x, y);
   NonconformingInterpolation(y);
}

void ParNCH1FaceRestriction::NonconformingInterpolation(Vector& y) const
{
   // Assumes all elements have the same number of dofs
   const int nface_dofs = face_dofs;
   const int vd = vdim;
   auto d_y = Reshape(y.ReadWrite(), nface_dofs, vd, nf);
   auto &nc_interp_config = interpolations.GetNCFaceInterpConfig();
   const int num_nc_faces = nc_interp_config.Size();
   auto interp_config_ptr = nc_interp_config.Read();
   const int nc_size = interpolations.GetNumInterpolators();
   auto d_interp = Reshape(interpolations.GetInterpolators().Read(),
                           nface_dofs, nface_dofs, nc_size);
   static constexpr int max_nd = 16*16;
   MFEM_VERIFY(nface_dofs<=max_nd, "Too many degrees of freedom.");
   MFEM_FORALL_3D(nc_face, num_nc_faces, nface_dofs, 1, 1,
   {
      MFEM_SHARED double dof_values[max_nd];
      const NCInterpConfig conf = interp_config_ptr[nc_face];
      if ( conf.is_non_conforming && conf.master_side == 0)
      {
         const int interp_index = conf.index;
         const int face = conf.face_index;
         for (int c = 0; c < vd; ++c)
         {
            MFEM_FOREACH_THREAD(dof,x,nface_dofs)
            {
               dof_values[dof] = d_y(dof, c, face);
            }
            MFEM_SYNC_THREAD;
            MFEM_FOREACH_THREAD(dof_out,x,nface_dofs)
            {
               double res = 0.0;
               for (int dof_in = 0; dof_in<nface_dofs; dof_in++)
               {
                  res += d_interp(dof_out, dof_in, interp_index)*dof_values[dof_in];
               }
               d_y(dof_out, c, face) = res;
            }
            MFEM_SYNC_THREAD;
         }
      }
   });
}

void ParNCH1FaceRestriction::AddMultTranspose(const Vector &x, Vector &y) const
{
   if (nf==0) { return; }
   if (x_interp.Size()==0)
   {
      x_interp.SetSize(x.Size());
   }
   x_interp = x;
   AddMultTranspose(x_interp, y);
}

void ParNCH1FaceRestriction::AddMultTranspose(Vector &x, Vector &y) const
{
   NonconformingTransposeInterpolation(x);
   H1FaceRestriction::AddMultTranspose(x, y);
}

void ParNCH1FaceRestriction::NonconformingTransposeInterpolation(
   Vector& x) const
{
   // Assumes all elements have the same number of dofs
   const int nface_dofs = face_dofs;
   const int vd = vdim;
   const bool t = byvdim;
   if ( type==FaceType::Interior )
   {
      // Interpolation from slave to master face dofs
      auto d_x = Reshape(x.ReadWrite(), nface_dofs, vd, nf);
      auto &nc_interp_config = interpolations.GetNCFaceInterpConfig();
      const int num_nc_faces = nc_interp_config.Size();
      auto interp_config_ptr = nc_interp_config.Read();
      const int nc_size = interpolations.GetNumInterpolators();
      auto d_interp = Reshape(interpolations.GetInterpolators().Read(),
                              nface_dofs, nface_dofs, nc_size);
      static constexpr int max_nd = 1024;
      MFEM_VERIFY(nface_dofs<=max_nd, "Too many degrees of freedom.");
      MFEM_FORALL_3D(face, num_nc_faces, nface_dofs, 1, 1,
      {
         MFEM_SHARED double dof_values[max_nd];
         const NCInterpConfig conf = interp_config_ptr[face];
         const int master_side = conf.master_side;
         const int interp_index = conf.index;
         if ( conf.is_non_conforming && master_side==0 )
         {
            // Interpolation from fine to coarse
            for (int c = 0; c < vd; ++c)
            {
               MFEM_FOREACH_THREAD(dof,x,nface_dofs)
               {
                  dof_values[dof] = d_x(dof, c, face);
               }
               MFEM_SYNC_THREAD;
               MFEM_FOREACH_THREAD(dof_out,x,nface_dofs)
               {
                  double res = 0.0;
                  for (int dof_in = 0; dof_in<nface_dofs; dof_in++)
                  {
                     res += d_interp(dof_in, dof_out, interp_index)*dof_values[dof_in];
                  }
                  d_x(dof_out, c, face) = res;
               }
               MFEM_SYNC_THREAD;
            }
         }
      });
   }
}<commit_msg>Fix face index.<commit_after>// Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#include "../config/config.hpp"

#ifdef MFEM_USE_MPI

#include "restriction.hpp"
#include "prestriction.hpp"
#include "pgridfunc.hpp"
#include "pfespace.hpp"
#include "fespace.hpp"
#include "../general/forall.hpp"

namespace mfem
{

ParNCH1FaceRestriction::ParNCH1FaceRestriction(const ParFiniteElementSpace &fes,
                                               ElementDofOrdering ordering,
                                               FaceType type)
   : H1FaceRestriction(fes, ordering, type, false),
     type(type),
     interpolations(fes, ordering, type)
{
   if (nf==0) { return; }
   x_interp.UseDevice(true);

   CheckFESpace(ordering);

   ComputeScatterIndicesAndOffsets(ordering, type);

   ComputeGatherIndices(ordering, type);
}

void ParNCH1FaceRestriction::Mult(const Vector &x, Vector &y) const
{
   H1FaceRestriction::Mult(x, y);
   NonconformingInterpolation(y);
}

void ParNCH1FaceRestriction::NonconformingInterpolation(Vector& y) const
{
   // Assumes all elements have the same number of dofs
   const int nface_dofs = face_dofs;
   const int vd = vdim;
   auto d_y = Reshape(y.ReadWrite(), nface_dofs, vd, nf);
   auto &nc_interp_config = interpolations.GetNCFaceInterpConfig();
   const int num_nc_faces = nc_interp_config.Size();
   auto interp_config_ptr = nc_interp_config.Read();
   const int nc_size = interpolations.GetNumInterpolators();
   auto d_interp = Reshape(interpolations.GetInterpolators().Read(),
                           nface_dofs, nface_dofs, nc_size);
   static constexpr int max_nd = 16*16;
   MFEM_VERIFY(nface_dofs<=max_nd, "Too many degrees of freedom.");
   MFEM_FORALL_3D(nc_face, num_nc_faces, nface_dofs, 1, 1,
   {
      MFEM_SHARED double dof_values[max_nd];
      const NCInterpConfig conf = interp_config_ptr[nc_face];
      if ( conf.is_non_conforming && conf.master_side == 0)
      {
         const int interp_index = conf.index;
         const int face = conf.face_index;
         for (int c = 0; c < vd; ++c)
         {
            MFEM_FOREACH_THREAD(dof,x,nface_dofs)
            {
               dof_values[dof] = d_y(dof, c, face);
            }
            MFEM_SYNC_THREAD;
            MFEM_FOREACH_THREAD(dof_out,x,nface_dofs)
            {
               double res = 0.0;
               for (int dof_in = 0; dof_in<nface_dofs; dof_in++)
               {
                  res += d_interp(dof_out, dof_in, interp_index)*dof_values[dof_in];
               }
               d_y(dof_out, c, face) = res;
            }
            MFEM_SYNC_THREAD;
         }
      }
   });
}

void ParNCH1FaceRestriction::AddMultTranspose(const Vector &x, Vector &y) const
{
   if (nf==0) { return; }
   if (x_interp.Size()==0)
   {
      x_interp.SetSize(x.Size());
   }
   x_interp = x;
   AddMultTranspose(x_interp, y);
}

void ParNCH1FaceRestriction::AddMultTranspose(Vector &x, Vector &y) const
{
   NonconformingTransposeInterpolation(x);
   H1FaceRestriction::AddMultTranspose(x, y);
}

void ParNCH1FaceRestriction::NonconformingTransposeInterpolation(
   Vector& x) const
{
   // Assumes all elements have the same number of dofs
   const int nface_dofs = face_dofs;
   const int vd = vdim;
   const bool t = byvdim;
   if ( type==FaceType::Interior )
   {
      // Interpolation from slave to master face dofs
      auto d_x = Reshape(x.ReadWrite(), nface_dofs, vd, nf);
      auto &nc_interp_config = interpolations.GetNCFaceInterpConfig();
      const int num_nc_faces = nc_interp_config.Size();
      auto interp_config_ptr = nc_interp_config.Read();
      const int nc_size = interpolations.GetNumInterpolators();
      auto d_interp = Reshape(interpolations.GetInterpolators().Read(),
                              nface_dofs, nface_dofs, nc_size);
      static constexpr int max_nd = 1024;
      MFEM_VERIFY(nface_dofs<=max_nd, "Too many degrees of freedom.");
      MFEM_FORALL_3D(nc_face, num_nc_faces, nface_dofs, 1, 1,
      {
         MFEM_SHARED double dof_values[max_nd];
         const NCInterpConfig conf = interp_config_ptr[nc_face];
         const int master_side = conf.master_side;
         if ( conf.is_non_conforming && master_side==0 )
         {
            const int interp_index = conf.index;
            const int face = conf.face_index;
            // Interpolation from fine to coarse
            for (int c = 0; c < vd; ++c)
            {
               MFEM_FOREACH_THREAD(dof,x,nface_dofs)
               {
                  dof_values[dof] = d_x(dof, c, face);
               }
               MFEM_SYNC_THREAD;
               MFEM_FOREACH_THREAD(dof_out,x,nface_dofs)
               {
                  double res = 0.0;
                  for (int dof_in = 0; dof_in<nface_dofs; dof_in++)
                  {
                     res += d_interp(dof_in, dof_out, interp_index)*dof_values[dof_in];
                  }
                  d_x(dof_out, c, face) = res;
               }
               MFEM_SYNC_THREAD;
            }
         }
      });
   }
}
{'fraction_non_alphanumeric': 0.09946162971074003, 'fraction_numerical': 0.009489916963226572, 'mean_word_length': 2.404784094439267, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2089119', 'n_tokens_mistral': 3807, 'n_tokens_neox': 3673, 'n_words': 798}