<commit_before>// The libMesh Finite Element Library.
// Copyright (C) 2002-2019 <NAME>, <NAME>, <NAME>

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



#ifndef LIBMESH_SYNC_REFINEMENT_FLAGS_H
#define LIBMESH_SYNC_REFINEMENT_FLAGS_H

// Local includes
#include "libmesh/libmesh_config.h"

// Only compile these functions if the user requests AMR support
#ifdef LIBMESH_ENABLE_AMR

// libMesh includes
#include "libmesh/elem.h"
#include "libmesh/mesh_base.h"

// C++ includes
#include <vector>

namespace libMesh {

struct SyncRefinementFlags
{
  typedef unsigned char datum;
  typedef Elem::RefinementState (Elem::*get_a_flag)() const;
  typedef void (Elem::*set_a_flag)(const Elem::RefinementState);

  SyncRefinementFlags(MeshBase & _mesh,
                      get_a_flag _getter,
                      set_a_flag _setter) :
    mesh(_mesh), parallel_consistent(true),
    get_flag(_getter), set_flag(_setter) {}

  MeshBase & mesh;
  bool parallel_consistent;
  get_a_flag get_flag;
  set_a_flag set_flag;
  // References to pointers to member functions segfault?
  // get_a_flag & get_flag;
  // set_a_flag & set_flag;

  // Find the refinement flag on each requested element
  void gather_data (const std::vector<dof_id_type> & ids,
                    std::vector<datum> & flags) const
  {
    flags.resize(ids.size());

    for (std::size_t i=0; i != ids.size(); ++i)
      {
        // Look for this element in the mesh
        // We'd better find every element we're asked for
        Elem & elem = mesh.elem_ref(ids[i]);

        // Return the element's refinement flag
        flags[i] = (elem.*get_flag)();
      }
  }

  void act_on_data (const std::vector<dof_id_type> & ids,
                    const std::vector<datum> & flags)
  {
    for (std::size_t i=0; i != ids.size(); ++i)
      {
        Elem & elem = mesh.elem_ref(ids[i]);

        datum old_flag = (elem.*get_flag)();
        datum new_flag = flags[i];

        if (old_flag != new_flag)
          {
            // It's possible for foreign flags to be (temporarily) more
            // conservative than our own, such as when a refinement in
            // one of the foreign processor's elements is mandated by a
            // refinement in one of our neighboring elements it can see
            // which was mandated by a refinement in one of our
            // neighboring elements it can't see
            // libmesh_assert (!(new_flag != Elem::REFINE &&
            //                   old_flag == Elem::REFINE));
            //
            (elem.*set_flag)
              (static_cast<Elem::RefinementState>(new_flag));<commit_msg>Use index_range in sync_refinement_flags.h<commit_after>// The libMesh Finite Element Library.
// Copyright (C) 2002-2019 <NAME>, <NAME>, <NAME>

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



#ifndef LIBMESH_SYNC_REFINEMENT_FLAGS_H
#define LIBMESH_SYNC_REFINEMENT_FLAGS_H

// Local includes
#include "libmesh/libmesh_config.h"

// Only compile these functions if the user requests AMR support
#ifdef LIBMESH_ENABLE_AMR

// libMesh includes
#include "libmesh/elem.h"
#include "libmesh/int_range.h"
#include "libmesh/mesh_base.h"

// C++ includes
#include <vector>

namespace libMesh {

struct SyncRefinementFlags
{
  typedef unsigned char datum;
  typedef Elem::RefinementState (Elem::*get_a_flag)() const;
  typedef void (Elem::*set_a_flag)(const Elem::RefinementState);

  SyncRefinementFlags(MeshBase & _mesh,
                      get_a_flag _getter,
                      set_a_flag _setter) :
    mesh(_mesh), parallel_consistent(true),
    get_flag(_getter), set_flag(_setter) {}

  MeshBase & mesh;
  bool parallel_consistent;
  get_a_flag get_flag;
  set_a_flag set_flag;
  // References to pointers to member functions segfault?
  // get_a_flag & get_flag;
  // set_a_flag & set_flag;

  // Find the refinement flag on each requested element
  void gather_data (const std::vector<dof_id_type> & ids,
                    std::vector<datum> & flags) const
  {
    flags.resize(ids.size());

    for (auto i : index_range(ids))
      {
        // Look for this element in the mesh
        // We'd better find every element we're asked for
        Elem & elem = mesh.elem_ref(ids[i]);

        // Return the element's refinement flag
        flags[i] = (elem.*get_flag)();
      }
  }

  void act_on_data (const std::vector<dof_id_type> & ids,
                    const std::vector<datum> & flags)
  {
    for (auto i : index_range(ids))
      {
        Elem & elem = mesh.elem_ref(ids[i]);

        datum old_flag = (elem.*get_flag)();
        datum new_flag = flags[i];

        if (old_flag != new_flag)
          {
            // It's possible for foreign flags to be (temporarily) more
            // conservative than our own, such as when a refinement in
            // one of the foreign processor's elements is mandated by a
            // refinement in one of our neighboring elements it can see
            // which was mandated by a refinement in one of our
            // neighboring elements it can't see
            // libmesh_assert (!(new_flag != Elem::REFINE &&
            //                   old_flag == Elem::REFINE));
            //
            (elem.*set_flag)
              (static_cast<Elem::RefinementState>(new_flag));
{'fraction_non_alphanumeric': 0.09602649006622517, 'fraction_numerical': 0.007525586995785672, 'mean_word_length': 2.669243511871894, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2254033', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1907, 'n_words': 676}