<commit_before>#include "openmc/plot.h"

#include <algorithm>
#include <fstream>
#include <sstream>

#include <fmt/core.h>
#include <fmt/ostream.h>
#include "xtensor/xview.hpp"

#include "openmc/constants.h"
#include "openmc/file_utils.h"
#include "openmc/geometry.h"
#include "openmc/error.h"
#include "openmc/hdf5_interface.h"
#include "openmc/material.h"
#include "openmc/mesh.h"
#include "openmc/message_passing.h"
#include "openmc/output.h"
#include "openmc/particle.h"
#include "openmc/progress_bar.h"
#include "openmc/random_lcg.h"
#include "openmc/settings.h"
#include "openmc/simulation.h"
#include "openmc/string_utils.h"

namespace openmc {

//==============================================================================
// Constants
//==============================================================================


constexpr int PLOT_LEVEL_LOWEST {-1}; //!< lower bound on plot universe level
constexpr int32_t NOT_FOUND {-2};
constexpr int32_t OVERLAP {-3};

IdData::IdData(size_t h_res, size_t v_res)
  : data_({v_res, h_res, 2}, NOT_FOUND)
{ }

void
IdData::set_value(size_t y, size_t x, const Particle& p, int level) {
  Cell* c = model::cells[p.coord_[level].cell].get();
  data_(y,x,0) = c->id_;
  if (p.material_ == MATERIAL_VOID) {
    data_(y,x,1) = MATERIAL_VOID;
    return;
  } else if (c->type_ != Fill::UNIVERSE) {
    Material* m = model::materials[p.material_].get();
    data_(y,x,1) = m->id_;
  }
}

void IdData::set_overlap(size_t y, size_t x) {
  xt::view(data_, y, x, xt::all()) = OVERLAP;
}

PropertyData::PropertyData(size_t h_res, size_t v_res)
  : data_({v_res, h_res, 2}, NOT_FOUND)
{ }

void
PropertyData::set_value(size_t y, size_t x, const Particle& p, int level) {
  Cell* c = model::cells[p.coord_[level].cell].get();
  data_(y,x,0) = (p.sqrtkT_ * p.sqrtkT_) / K_BOLTZMANN;
  if (c->type_ != Fill::UNIVERSE && p.material_ != MATERIAL_VOID) {
    Material* m = model::materials[p.material_].get();
    data_(y,x,1) = m->density_gpcc_;
  }
}

void PropertyData::set_overlap(size_t y, size_t x) {
  data_(y, x) = OVERLAP;
}

//==============================================================================
// Global variables
//==============================================================================

namespace model {

std::unordered_map<int, int> plot_map;
std::vector<Plot> plots;
uint64_t plotter_seed = 1;

} // namespace model

//==============================================================================
// RUN_PLOT controls the logic for making one or many plots
//==============================================================================

extern "C"
int openmc_plot_geometry()
{
  for (auto pl : model::plots) {
    write_message(fmt::format("Processing plot {}: {}...",
      pl.id_, pl.path_plot_), 5);

    if (PlotType::slice == pl.type_) {
      // create 2D image
      create_ppm(pl);
    } else if (PlotType::voxel == pl.type_) {
      // create voxel file for 3D viewing
      create_voxel(pl);
    }
  }
  return 0;
}


void read_plots_xml()
{
  // Check if plots.xml exists
  std::string filename = settings::path_input + "plots.xml";
  if (!file_exists(filename)) {
    fatal_error(fmt::format("Plots XML file '{}' does not exist!", filename));
  }

  write_message("Reading plot XML file...", 5);

  // Parse plots.xml file
  pugi::xml_document doc;
  doc.load_file(filename.c_str());

  pugi::xml_node root = doc.document_element();<commit_msg>Apply templated write_message to plot.cpp<commit_after>#include "openmc/plot.h"

#include <algorithm>
#include <fstream>
#include <sstream>

#include <fmt/core.h>
#include <fmt/ostream.h>
#include "xtensor/xview.hpp"

#include "openmc/constants.h"
#include "openmc/file_utils.h"
#include "openmc/geometry.h"
#include "openmc/error.h"
#include "openmc/hdf5_interface.h"
#include "openmc/material.h"
#include "openmc/mesh.h"
#include "openmc/message_passing.h"
#include "openmc/output.h"
#include "openmc/particle.h"
#include "openmc/progress_bar.h"
#include "openmc/random_lcg.h"
#include "openmc/settings.h"
#include "openmc/simulation.h"
#include "openmc/string_utils.h"

namespace openmc {

//==============================================================================
// Constants
//==============================================================================


constexpr int PLOT_LEVEL_LOWEST {-1}; //!< lower bound on plot universe level
constexpr int32_t NOT_FOUND {-2};
constexpr int32_t OVERLAP {-3};

IdData::IdData(size_t h_res, size_t v_res)
  : data_({v_res, h_res, 2}, NOT_FOUND)
{ }

void
IdData::set_value(size_t y, size_t x, const Particle& p, int level) {
  Cell* c = model::cells[p.coord_[level].cell].get();
  data_(y,x,0) = c->id_;
  if (p.material_ == MATERIAL_VOID) {
    data_(y,x,1) = MATERIAL_VOID;
    return;
  } else if (c->type_ != Fill::UNIVERSE) {
    Material* m = model::materials[p.material_].get();
    data_(y,x,1) = m->id_;
  }
}

void IdData::set_overlap(size_t y, size_t x) {
  xt::view(data_, y, x, xt::all()) = OVERLAP;
}

PropertyData::PropertyData(size_t h_res, size_t v_res)
  : data_({v_res, h_res, 2}, NOT_FOUND)
{ }

void
PropertyData::set_value(size_t y, size_t x, const Particle& p, int level) {
  Cell* c = model::cells[p.coord_[level].cell].get();
  data_(y,x,0) = (p.sqrtkT_ * p.sqrtkT_) / K_BOLTZMANN;
  if (c->type_ != Fill::UNIVERSE && p.material_ != MATERIAL_VOID) {
    Material* m = model::materials[p.material_].get();
    data_(y,x,1) = m->density_gpcc_;
  }
}

void PropertyData::set_overlap(size_t y, size_t x) {
  data_(y, x) = OVERLAP;
}

//==============================================================================
// Global variables
//==============================================================================

namespace model {

std::unordered_map<int, int> plot_map;
std::vector<Plot> plots;
uint64_t plotter_seed = 1;

} // namespace model

//==============================================================================
// RUN_PLOT controls the logic for making one or many plots
//==============================================================================

extern "C"
int openmc_plot_geometry()
{
  for (auto pl : model::plots) {
    write_message(5, "Processing plot {}: {}...", pl.id_, pl.path_plot_);

    if (PlotType::slice == pl.type_) {
      // create 2D image
      create_ppm(pl);
    } else if (PlotType::voxel == pl.type_) {
      // create voxel file for 3D viewing
      create_voxel(pl);
    }
  }
  return 0;
}


void read_plots_xml()
{
  // Check if plots.xml exists
  std::string filename = settings::path_input + "plots.xml";
  if (!file_exists(filename)) {
    fatal_error(fmt::format("Plots XML file '{}' does not exist!", filename));
  }

  write_message("Reading plot XML file...", 5);

  // Parse plots.xml file
  pugi::xml_document doc;
  doc.load_file(filename.c_str());

  pugi::xml_node root = doc.document_element();
{'fraction_non_alphanumeric': 0.2808628479813438, 'fraction_numerical': 0.006704562017198659, 'mean_word_length': 4.93598615916955, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '1943267', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2358, 'n_words': 495}