<commit_before>/****************************************************************/
/*               DO NOT MODIFY THIS HEADER                      */
/* MOOSE - Multiphysics Object Oriented Simulation Environment  */
/*                                                              */
/*           (c) 2010 Battelle Energy Alliance, LLC             */
/*                   ALL RIGHTS RESERVED                        */
/*                                                              */
/*          Prepared by Battelle Energy Alliance, LLC           */
/*            Under Contract No. DE-AC07-05ID14517              */
/*            With the U. S. Department of Energy               */
/*                                                              */
/*            See COPYRIGHT for full restrictions               */
/****************************************************************/

#include "GaussianUserObject.h"

// LibMesh
#include "libmesh/point_locator_base.h"
#include "libmesh/elem.h"

template<>
InputParameters validParams<GaussianUserObject>()
{
  // Define the general parameters
  InputParameters params = validParams<GeneralUserObject>();
  params.addClassDescription("Function for generating Gaussian distributions normalized to the mesh dimension.");

  params.addParam<Real>("scale", 1.0, "Scaling factor");
  params.addParam<Real>("sigma", 1.0, "Standard deviation of the Gaussian curve");
  params.addParam<Point>("peak_location", "Center of Gaussian distribution");
  params.addParam<bool>("use_random_points", false, "Use a random point for the Gaussian peak location");
  params.addParam<UserObjectName>("random_point_user_object", "Name of the RandomPointUserObject to use");
  params.addCoupledVar("periodic_variable", "Use perodic boundary conditions of this variable to determine the distance to the function peak location");

  return params;
}

GaussianUserObject::GaussianUserObject(const InputParameters & parameters) :
    GeneralUserObject(parameters),
    Coupleable(this, false),
    _scale(getParam<Real>("scale")),
    _sigma(getParam<Real>("sigma")),
    _periodic_var(isCoupled("periodic_variable") ? (int) coupled("periodic_variable") : -1),
    _mesh(_fe_problem.mesh())
{
  // normalization constant so integral over domain (theoretically) equals 1
  unsigned int dim = _mesh.dimension();
  _norm = 1.0/(pow(_sigma,dim)*pow(pow(2.0*pi,dim),0.5));
}

GaussianUserObject::~GaussianUserObject()
{
}

Real
GaussianUserObject::value(const Point & p, const Point & center) const
{
  // distance to center depends on perodicity
  Real r;
  if (_periodic_var < 0)
    r = (p-center).norm();
  else
    r = _mesh.minPeriodicDistance(_periodic_var, p, center);

  Real f = exp(-r*r/2.0/_sigma/_sigma);

  return f*_norm*_scale;
}<commit_msg>pretty up normalization constant in GaussianUserObject, closes #45<commit_after>/****************************************************************/
/*               DO NOT MODIFY THIS HEADER                      */
/* MOOSE - Multiphysics Object Oriented Simulation Environment  */
/*                                                              */
/*           (c) 2010 Battelle Energy Alliance, LLC             */
/*                   ALL RIGHTS RESERVED                        */
/*                                                              */
/*          Prepared by Battelle Energy Alliance, LLC           */
/*            Under Contract No. DE-AC07-05ID14517              */
/*            With the U. S. Department of Energy               */
/*                                                              */
/*            See COPYRIGHT for full restrictions               */
/****************************************************************/

#include "GaussianUserObject.h"

// LibMesh
#include "libmesh/point_locator_base.h"
#include "libmesh/elem.h"

template<>
InputParameters validParams<GaussianUserObject>()
{
  // Define the general parameters
  InputParameters params = validParams<GeneralUserObject>();
  params.addClassDescription("Function for generating Gaussian distributions normalized to the mesh dimension.");

  params.addParam<Real>("scale", 1.0, "Scaling factor");
  params.addParam<Real>("sigma", 1.0, "Standard deviation of the Gaussian curve");
  params.addParam<Point>("peak_location", "Center of Gaussian distribution");
  params.addParam<bool>("use_random_points", false, "Use a random point for the Gaussian peak location");
  params.addParam<UserObjectName>("random_point_user_object", "Name of the RandomPointUserObject to use");
  params.addCoupledVar("periodic_variable", "Use perodic boundary conditions of this variable to determine the distance to the function peak location");

  return params;
}

GaussianUserObject::GaussianUserObject(const InputParameters & parameters) :
    GeneralUserObject(parameters),
    Coupleable(this, false),
    _scale(getParam<Real>("scale")),
    _sigma(getParam<Real>("sigma")),
    _periodic_var(isCoupled("periodic_variable") ? (int) coupled("periodic_variable") : -1),
    _mesh(_fe_problem.mesh())
{
  // normalization constant so integral over domain (theoretically) equals 1
  unsigned int dim = _mesh.dimension();
  _norm = 1.0/std::pow(_sigma*std::sqrt(2.0*libMesh::pi), Real(dim));
}

GaussianUserObject::~GaussianUserObject()
{
}

Real
GaussianUserObject::value(const Point & p, const Point & center) const
{
  // distance to center depends on perodicity
  Real r;
  if (_periodic_var < 0)
    r = (p-center).norm();
  else
    r = _mesh.minPeriodicDistance(_periodic_var, p, center);

  Real f = exp(-r*r/2.0/_sigma/_sigma);

  return f*_norm*_scale;
}
{'fraction_non_alphanumeric': 0.15364073348762686, 'fraction_numerical': 0.009969734733843688, 'mean_word_length': 2.6911957950065704, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6596455', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1399, 'n_words': 376}