<commit_before>//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "Nemesis.h"

// MOOSE includes
#include "FEProblem.h"
#include "MooseApp.h"
#include "MooseMesh.h"
#include "MooseVariableScalar.h"
#include "SystemBase.h"

#include "libmesh/dof_map.h"
#include "libmesh/nemesis_io.h"

registerMooseObject("MooseApp", Nemesis);

template <>
InputParameters
validParams<Nemesis>()
{
  // Get the base class parameters
  InputParameters params = validParams<AdvancedOutput>();
  params += AdvancedOutput::enableOutputTypes("scalar postprocessor input");

  // Add description for the Nemesis class
  params.addClassDescription("Object for output data in the Nemesis format");

  // Return the InputParameters
  return params;
}

Nemesis::Nemesis(const InputParameters & parameters)
  : AdvancedOutput(parameters),
    _nemesis_io_ptr(nullptr),
    _file_num(0),
    _nemesis_num(0),
    _nemesis_initialized(false)
{
}

Nemesis::~Nemesis() {}

void
Nemesis::initialSetup()
{

  AdvancedOutput::initialSetup();

  // Make certain that a Nemesis_IO object exists
  meshChanged();
}

void
Nemesis::meshChanged()
{
  // Do not delete the Nemesis_IO object if it has not been used; also there is no need to setup
  // the object in this case, so just return
  if (_nemesis_io_ptr != nullptr && !_nemesis_initialized)
    return;

  // Increment the file number
  _file_num++;

  // Reset the number of outputs for this file
  _nemesis_num = 1;

  // Create the new NemesisIO object
  _nemesis_io_ptr = libmesh_make_unique<Nemesis_IO>(_problem_ptr->mesh().getMesh());
  _nemesis_initialized = false;
}

void
Nemesis::outputPostprocessors()
{
  // List of desired postprocessor outputs
  const std::set<std::string> & pps = getPostprocessorOutput();

  // Append the postprocessor data to the global name value parameters; scalar outputs
  // also append these member variables
  for (const auto & name : pps)
  {
    _global_names.push_back(name);
    _global_values.push_back(_problem_ptr->getPostprocessorValue(name));
  }
}

void
Nemesis::outputScalarVariables()
{
  // List of desired scalar outputs
  const std::set<std::string> & out = getScalarOutput();

  // Append the scalar to the global output lists
  for (const auto & out_name : out)
  {
    // Make sure scalar values are in sync with the solution vector
    // and are visible on this processor.  See TableOutput.C for
    // TableOutput::outputScalarVariables() explanatory comments

    MooseVariableScalar & scalar_var = _problem_ptr->getScalarVariable(0, out_name);
    scalar_var.reinit();
    VariableValue value = scalar_var.sln();

    const std::vector<dof_id_type> & dof_indices = scalar_var.dofIndices();
    const unsigned int n = dof_indices.size();
    value.resize(n);

    const DofMap & dof_map = scalar_var.sys().dofMap();
    for (unsigned int i = 0; i != n; ++i)
    {
      const processor_id_type pid = dof_map.dof_owner(dof_indices[i]);
      this->comm().broadcast(value[i], pid);
    }

    // If the scalar has a single component, output the name directly
    if (n == 1)
    {
      _global_names.push_back(out_name);
      _global_values.push_back(value[0]);
    }

    // If the scalar as many components add indices to the end of the name
    else
    {
      for (unsigned int i = 0; i < n; ++i)
      {
        std::ostringstream os;
        os << out_name << "_" << i;
        _global_names.push_back(os.str());
        _global_values.push_back(value[i]);
      }
    }
  }
}

void
Nemesis::output(const ExecFlagType & type)
{
  if (!shouldOutput(type))
    return;

  // Clear the global variables (postprocessors and scalars)
  _global_names.clear();
  _global_values.clear();

  // Call the output methods
  AdvancedOutput::output(type);

  // Set up the whitelist of nodal variable names to write.
  _nemesis_io_ptr->set_output_variables(
      std::vector<std::string>(getNodalVariableOutput().begin(), getNodalVariableOutput().end()));

  // Write the data
  _nemesis_io_ptr->write_timestep(
      filename(), *_es_ptr, _nemesis_num, time() + _app.getGlobalTimeOffset());
  _nemesis_initialized = true;

  // Increment output call counter for the current file
  _nemesis_num++;

  // Write the global variables (populated by the output methods)
  if (!_global_values.empty())
    _nemesis_io_ptr->write_global_data(_global_values, _global_names);
}

std::string
Nemesis::filename()
{
  // Append the .e extension on the base file name
  std::ostringstream output;
  output << _file_base << ".e";<commit_msg>Nemeis: Add call to write_element_data().<commit_after>//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "Nemesis.h"

// MOOSE includes
#include "FEProblem.h"
#include "MooseApp.h"
#include "MooseMesh.h"
#include "MooseVariableScalar.h"
#include "SystemBase.h"

#include "libmesh/dof_map.h"
#include "libmesh/nemesis_io.h"

registerMooseObject("MooseApp", Nemesis);

template <>
InputParameters
validParams<Nemesis>()
{
  // Get the base class parameters
  InputParameters params = validParams<AdvancedOutput>();
  params += AdvancedOutput::enableOutputTypes("scalar postprocessor input");

  // Add description for the Nemesis class
  params.addClassDescription("Object for output data in the Nemesis format");

  // Return the InputParameters
  return params;
}

Nemesis::Nemesis(const InputParameters & parameters)
  : AdvancedOutput(parameters),
    _nemesis_io_ptr(nullptr),
    _file_num(0),
    _nemesis_num(0),
    _nemesis_initialized(false)
{
}

Nemesis::~Nemesis() {}

void
Nemesis::initialSetup()
{

  AdvancedOutput::initialSetup();

  // Make certain that a Nemesis_IO object exists
  meshChanged();
}

void
Nemesis::meshChanged()
{
  // Do not delete the Nemesis_IO object if it has not been used; also there is no need to setup
  // the object in this case, so just return
  if (_nemesis_io_ptr != nullptr && !_nemesis_initialized)
    return;

  // Increment the file number
  _file_num++;

  // Reset the number of outputs for this file
  _nemesis_num = 1;

  // Create the new NemesisIO object
  _nemesis_io_ptr = libmesh_make_unique<Nemesis_IO>(_problem_ptr->mesh().getMesh());
  _nemesis_initialized = false;
}

void
Nemesis::outputPostprocessors()
{
  // List of desired postprocessor outputs
  const std::set<std::string> & pps = getPostprocessorOutput();

  // Append the postprocessor data to the global name value parameters; scalar outputs
  // also append these member variables
  for (const auto & name : pps)
  {
    _global_names.push_back(name);
    _global_values.push_back(_problem_ptr->getPostprocessorValue(name));
  }
}

void
Nemesis::outputScalarVariables()
{
  // List of desired scalar outputs
  const std::set<std::string> & out = getScalarOutput();

  // Append the scalar to the global output lists
  for (const auto & out_name : out)
  {
    // Make sure scalar values are in sync with the solution vector
    // and are visible on this processor.  See TableOutput.C for
    // TableOutput::outputScalarVariables() explanatory comments

    MooseVariableScalar & scalar_var = _problem_ptr->getScalarVariable(0, out_name);
    scalar_var.reinit();
    VariableValue value = scalar_var.sln();

    const std::vector<dof_id_type> & dof_indices = scalar_var.dofIndices();
    const unsigned int n = dof_indices.size();
    value.resize(n);

    const DofMap & dof_map = scalar_var.sys().dofMap();
    for (unsigned int i = 0; i != n; ++i)
    {
      const processor_id_type pid = dof_map.dof_owner(dof_indices[i]);
      this->comm().broadcast(value[i], pid);
    }

    // If the scalar has a single component, output the name directly
    if (n == 1)
    {
      _global_names.push_back(out_name);
      _global_values.push_back(value[0]);
    }

    // If the scalar as many components add indices to the end of the name
    else
    {
      for (unsigned int i = 0; i < n; ++i)
      {
        std::ostringstream os;
        os << out_name << "_" << i;
        _global_names.push_back(os.str());
        _global_values.push_back(value[i]);
      }
    }
  }
}

void
Nemesis::output(const ExecFlagType & type)
{
  if (!shouldOutput(type))
    return;

  // Clear the global variables (postprocessors and scalars)
  _global_names.clear();
  _global_values.clear();

  // Call the output methods
  AdvancedOutput::output(type);

  // Set up the whitelist of nodal variable names to write.
  _nemesis_io_ptr->set_output_variables(
      std::vector<std::string>(getNodalVariableOutput().begin(), getNodalVariableOutput().end()));

  // Write nodal data
  _nemesis_io_ptr->write_timestep(
      filename(), *_es_ptr, _nemesis_num, time() + _app.getGlobalTimeOffset());
  _nemesis_initialized = true;

  // Write elemental data
  std::vector<std::string> elemental(getElementalVariableOutput().begin(),
                                     getElementalVariableOutput().end());
  _nemesis_io_ptr->set_output_variables(elemental);
  _nemesis_io_ptr->write_element_data(*_es_ptr);

  // Increment output call counter for the current file
  _nemesis_num++;

  // Write the global variables (populated by the output methods)
  if (!_global_values.empty())
    _nemesis_io_ptr->write_global_data(_global_values, _global_names);
}

std::string
Nemesis::filename()
{
  // Append the .e extension on the base file name
  std::ostringstream output;
  output << _file_base << ".e";
{'fraction_non_alphanumeric': 0.11690155125215451, 'fraction_numerical': 0.002433336712967657, 'mean_word_length': 3.8093612871769866, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 36, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4497178', 'n_tokens_mistral': 3178, 'n_tokens_neox': 3111, 'n_words': 827}