<commit_before>/* The Next Great Finite Element Library. */
/* Copyright (C) 2003  <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 "getpot.h"

#include "laplace_system.h"

#include "boundary_info.h"
#include "dof_map.h"
#include "fe_base.h"
#include "fe_interface.h"
#include "fem_context.h"
#include "mesh.h"
#include "quadrature.h"
#include "string_to_enum.h"


// Bring in everything from the libMesh namespace
using namespace libMesh;

LaplaceSystem::LaplaceSystem( EquationSystems& es,
			      const std::string& name,
			      const unsigned int number)
  : FEMSystem(es, name, number)
{
  return;
}

void LaplaceSystem::init_data ()
{
  // Check the input file for Reynolds number, application type,
  // approximation type
  GetPot infile("laplace.in");

  // Add the solution variable
  u_var = this->add_variable ("u", SECOND, LAGRANGE_VEC);

  this->time_evolving(u_var);

  // Useful debugging options
  // Set verify_analytic_jacobians to 1e-6 to use
  this->verify_analytic_jacobians = infile("verify_analytic_jacobians", 0.);
  this->print_jacobians = infile("print_jacobians", false);
  this->print_element_jacobians = infile("print_element_jacobians", false);

  this->init_dirichlet_bcs();

  // Do the parent's initialization after variables and boundary constraints are defined
  FEMSystem::init_data();
}

void LaplaceSystem::init_dirichlet_bcs()
{
  const boundary_id_type all_ids[6] = {0,1,2,3,4,5};
  std::set<boundary_id_type> boundary_ids( all_ids, all_ids+6 );

  std::vector<unsigned int> vars;
  vars.push_back( u_var );

  BoundaryFunction func( u_var );

  this->get_dof_map().add_dirichlet_boundary( libMesh::DirichletBoundary( boundary_ids, vars, &func ) );
  return;
}

void LaplaceSystem::init_context(DiffContext &context)
{
  FEMContext &c = libmesh_cast_ref<FEMContext&>(context);

  // Get finite element object
  FEGenericBase<RealGradient>* fe;
  c.get_element_fe<RealGradient>( u_var, fe );
  
  // We should prerequest all the data
  // we will need to build the linear system.
  fe->get_JxW();
  fe->get_phi();
  fe->get_dphi();
  fe->get_xyz();

  FEGenericBase<RealGradient>* side_fe;
  c.get_side_fe<RealGradient>( u_var, side_fe );

  side_fe->get_JxW();
  side_fe->get_phi();
}


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

  // Get finite element object
  FEGenericBase<RealGradient>* fe = NULL;
  c.get_element_fe<RealGradient>( u_var, fe );
  
  // First we get some references to cell-specific data that
  // will be used to assemble the linear system.

  // Element Jacobian * quadrature weights for interior integration
  const std::vector<Real> &JxW = fe->get_JxW();

  // The velocity shape functions at interior quadrature points.
  const std::vector<std::vector<RealGradient> >& phi = fe->get_phi();

  // The velocity shape function gradients at interior
  // quadrature points.
  const std::vector<std::vector<RealTensor> >& grad_phi = fe->get_dphi();
 
  const std::vector<Point>& qpoint = fe->get_xyz();

  // The number of local degrees of freedom in each variable
  const unsigned int n_u_dofs = c.dof_indices_var[u_var].size();

  DenseSubMatrix<Number> &Kuu = *c.elem_subjacobians[u_var][u_var];

  DenseSubVector<Number> &Fu = *c.elem_subresiduals[u_var];
      
  // Now we will build the element Jacobian and residual.
  // Constructing the residual requires the solution and its
  // gradient from the previous timestep.  This must be
  // calculated at each quadrature point by summing the
  // solution degree-of-freedom values by the appropriate
  // weight functions.
  const unsigned int n_qpoints = (c.get_element_qrule())->n_points();

  for (unsigned int qp=0; qp != n_qpoints; qp++)
    {
      RealTensor grad_u;
      
      c.interior_gradient<RealGradient>( u_var, qp, grad_u );


      // Value of the forcing function at this quadrature point
      RealGradient f = this->forcing(qpoint[qp]);<commit_msg>Fix for --enable-complex<commit_after>/* The Next Great Finite Element Library. */
/* Copyright (C) 2003  <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 "getpot.h"

#include "laplace_system.h"

#include "boundary_info.h"
#include "dof_map.h"
#include "fe_base.h"
#include "fe_interface.h"
#include "fem_context.h"
#include "mesh.h"
#include "quadrature.h"
#include "string_to_enum.h"


// Bring in everything from the libMesh namespace
using namespace libMesh;

LaplaceSystem::LaplaceSystem( EquationSystems& es,
			      const std::string& name,
			      const unsigned int number)
  : FEMSystem(es, name, number)
{
  return;
}

void LaplaceSystem::init_data ()
{
  // Check the input file for Reynolds number, application type,
  // approximation type
  GetPot infile("laplace.in");

  // Add the solution variable
  u_var = this->add_variable ("u", SECOND, LAGRANGE_VEC);

  this->time_evolving(u_var);

  // Useful debugging options
  // Set verify_analytic_jacobians to 1e-6 to use
  this->verify_analytic_jacobians = infile("verify_analytic_jacobians", 0.);
  this->print_jacobians = infile("print_jacobians", false);
  this->print_element_jacobians = infile("print_element_jacobians", false);

  this->init_dirichlet_bcs();

  // Do the parent's initialization after variables and boundary constraints are defined
  FEMSystem::init_data();
}

void LaplaceSystem::init_dirichlet_bcs()
{
  const boundary_id_type all_ids[6] = {0,1,2,3,4,5};
  std::set<boundary_id_type> boundary_ids( all_ids, all_ids+6 );

  std::vector<unsigned int> vars;
  vars.push_back( u_var );

  BoundaryFunction func( u_var );

  this->get_dof_map().add_dirichlet_boundary( libMesh::DirichletBoundary( boundary_ids, vars, &func ) );
  return;
}

void LaplaceSystem::init_context(DiffContext &context)
{
  FEMContext &c = libmesh_cast_ref<FEMContext&>(context);

  // Get finite element object
  FEGenericBase<RealGradient>* fe;
  c.get_element_fe<RealGradient>( u_var, fe );
  
  // We should prerequest all the data
  // we will need to build the linear system.
  fe->get_JxW();
  fe->get_phi();
  fe->get_dphi();
  fe->get_xyz();

  FEGenericBase<RealGradient>* side_fe;
  c.get_side_fe<RealGradient>( u_var, side_fe );

  side_fe->get_JxW();
  side_fe->get_phi();
}


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

  // Get finite element object
  FEGenericBase<RealGradient>* fe = NULL;
  c.get_element_fe<RealGradient>( u_var, fe );
  
  // First we get some references to cell-specific data that
  // will be used to assemble the linear system.

  // Element Jacobian * quadrature weights for interior integration
  const std::vector<Real> &JxW = fe->get_JxW();

  // The velocity shape functions at interior quadrature points.
  const std::vector<std::vector<RealGradient> >& phi = fe->get_phi();

  // The velocity shape function gradients at interior
  // quadrature points.
  const std::vector<std::vector<RealTensor> >& grad_phi = fe->get_dphi();
 
  const std::vector<Point>& qpoint = fe->get_xyz();

  // The number of local degrees of freedom in each variable
  const unsigned int n_u_dofs = c.dof_indices_var[u_var].size();

  DenseSubMatrix<Number> &Kuu = *c.elem_subjacobians[u_var][u_var];

  DenseSubVector<Number> &Fu = *c.elem_subresiduals[u_var];
      
  // Now we will build the element Jacobian and residual.
  // Constructing the residual requires the solution and its
  // gradient from the previous timestep.  This must be
  // calculated at each quadrature point by summing the
  // solution degree-of-freedom values by the appropriate
  // weight functions.
  const unsigned int n_qpoints = (c.get_element_qrule())->n_points();

  for (unsigned int qp=0; qp != n_qpoints; qp++)
    {
      Tensor grad_u;
      
      c.interior_gradient<RealGradient>( u_var, qp, grad_u );


      // Value of the forcing function at this quadrature point
      RealGradient f = this->forcing(qpoint[qp]);
{'fraction_non_alphanumeric': 0.11236542280756769, 'fraction_numerical': 0.006689662381101704, 'mean_word_length': 3.9421487603305785, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5389011', 'n_tokens_mistral': 3177, 'n_tokens_neox': 2974, 'n_words': 919}