<commit_before>// The libMesh Finite Element Library.
// Copyright (C) 2002-2014 <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


#include "libmesh/diff_context.h"
#include "libmesh/diff_physics.h"
#include "libmesh/system.h"

namespace libMesh
{

DifferentiablePhysics::~DifferentiablePhysics()
{
  DifferentiablePhysics::clear_physics();
}



void DifferentiablePhysics::clear_physics ()
{
  _time_evolving.resize(0);
}



void DifferentiablePhysics::init_physics (const System& sys)
{
  // give us flags for every variable that might be time evolving
  _time_evolving.resize(sys.n_vars(), false);
}



bool DifferentiablePhysics::nonlocal_mass_residual(bool request_jacobian,
                                                   DiffContext &c)
{
  FEMContext &context = libmesh_cast_ref<FEMContext&>(c);

  for (unsigned int var = 0; var != context.n_vars(); ++var)
    {
      if (!this->is_time_evolving(var))
        continue;

      if (c.get_system().variable(var).type().family != SCALAR)
        continue;

      const std::vector<dof_id_type>& dof_indices =
              context.get_dof_indices(var);

      const std::size_t n_dofs = dof_indices.size();

      DenseSubVector<Number> &Fs = context.get_elem_residual(var);
      DenseSubMatrix<Number> &Kss = context.get_elem_jacobian( var, var );

      for (std::size_t i=0; i != n_dofs; ++i)
        {
          Number s = c.get_system().current_solution(dof_indices[i]);

          Fs(i) += s;

          if (request_jacobian && context.elem_solution_derivative)
            {
              libmesh_assert_equal_to (context.elem_solution_derivative, 1.0);

              Kss(i,i) += 1;
            }
        }
    }

  return request_jacobian;
}



bool DifferentiablePhysics::_eulerian_time_deriv (bool request_jacobian,
                                                  DiffContext &context)<commit_msg>Fix default nonlocal_mass_residual<commit_after>// The libMesh Finite Element Library.
// Copyright (C) 2002-2014 <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


#include "libmesh/diff_context.h"
#include "libmesh/diff_physics.h"
#include "libmesh/system.h"

namespace libMesh
{

DifferentiablePhysics::~DifferentiablePhysics()
{
  DifferentiablePhysics::clear_physics();
}



void DifferentiablePhysics::clear_physics ()
{
  _time_evolving.resize(0);
}



void DifferentiablePhysics::init_physics (const System& sys)
{
  // give us flags for every variable that might be time evolving
  _time_evolving.resize(sys.n_vars(), false);
}



bool DifferentiablePhysics::nonlocal_mass_residual(bool request_jacobian,
                                                   DiffContext &c)
{
  FEMContext &context = libmesh_cast_ref<FEMContext&>(c);

  for (unsigned int var = 0; var != context.n_vars(); ++var)
    {
      if (!this->is_time_evolving(var))
        continue;

      if (c.get_system().variable(var).type().family != SCALAR)
        continue;

      const std::vector<dof_id_type>& dof_indices =
              context.get_dof_indices(var);

      const std::size_t n_dofs = dof_indices.size();

      DenseSubVector<Number> &Fs = context.get_elem_residual(var);
      DenseSubMatrix<Number> &Kss = context.get_elem_jacobian( var, var );

      const libMesh::DenseSubVector<libMesh::Number> &Us =
        context.get_elem_solution(var);

      for (std::size_t i=0; i != n_dofs; ++i)
        {
          Fs(i) += Us(i);

          if (request_jacobian && context.elem_solution_derivative)
            {
              libmesh_assert_equal_to (context.elem_solution_derivative, 1.0);

              Kss(i,i) += 1;
            }
        }
    }

  return request_jacobian;
}



bool DifferentiablePhysics::_eulerian_time_deriv (bool request_jacobian,
                                                  DiffContext &context)
{'fraction_non_alphanumeric': 0.0997697620874904, 'fraction_numerical': 0.011511895625479662, 'mean_word_length': 2.9702970297029703, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, 'https://': 0, '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': '4091335', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1520, 'n_words': 452}