www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
SolutionRasterizer Class Reference

This Userobject is the base class of Userobjects that generate one random number per timestep and quadrature point in a way that the integral over all random numbers is zero. More...

#include <SolutionRasterizer.h>

Inheritance diagram for SolutionRasterizer:
[legend]

Public Member Functions

 SolutionRasterizer (const InputParameters &parameters)
 
virtual ~SolutionRasterizer ()
 
virtual void initialSetup ()
 Initialize the System and Mesh objects for the solution being read. More...
 

Protected Attributes

FileName _xyz_input
 
FileName _xyz_output
 
std::string _variable
 
MooseEnum _raster_mode
 
Real _threshold
 

Detailed Description

This Userobject is the base class of Userobjects that generate one random number per timestep and quadrature point in a way that the integral over all random numbers is zero.

This can be used for a concentration fluctuation kernel such as ConservedLangevinNoise, that keeps the total concenration constant.

See also
ConservedUniformNoise

Definition at line 29 of file SolutionRasterizer.h.

Constructor & Destructor Documentation

◆ SolutionRasterizer()

SolutionRasterizer::SolutionRasterizer ( const InputParameters &  parameters)

Definition at line 34 of file SolutionRasterizer.C.

35  : SolutionUserObject(parameters),
36  _xyz_input(getParam<FileName>("xyz_input")),
37  _xyz_output(getParam<FileName>("xyz_output")),
38  _variable(getParam<std::string>("variable")),
39  _raster_mode(getParam<MooseEnum>("raster_mode")),
40  _threshold(0.0)
41 {
42  if (_raster_mode == "FILTER")
43  {
44  if (!isParamValid("threshold"))
45  mooseError("Please specify 'threshold' parameter for raster_mode = FILTER");
46  _threshold = getParam<Real>("threshold");
47  }
48 }

◆ ~SolutionRasterizer()

virtual SolutionRasterizer::~SolutionRasterizer ( )
inlinevirtual

Definition at line 34 of file SolutionRasterizer.h.

34 {}

Member Function Documentation

◆ initialSetup()

void SolutionRasterizer::initialSetup ( )
virtual

Initialize the System and Mesh objects for the solution being read.

Definition at line 51 of file SolutionRasterizer.C.

52 {
53  // only execute once
54  if (_initialized)
55  return;
56 
57  // initialize parent class
58  SolutionUserObject::initialSetup();
59 
60  // open input XYZ file
61  std::ifstream stream_in(_xyz_input.c_str());
62 
63  // open output XYZ file
64  std::ofstream stream_out(_xyz_output.c_str());
65 
66  std::string line, dummy;
67  Real x, y, z;
68  unsigned int current_line = 0;
69  unsigned int nfilter = 0, len0 = 0;
70  while (std::getline(stream_in, line))
71  {
72  if (current_line < 2)
73  {
74  // dump header
75  stream_out << line << '\n';
76 
77  // get length of line 0 - the amount of space we have to replace the atom count at the end of
78  // filtering
79  if (current_line == 0)
80  len0 = line.size();
81  }
82  else
83  {
84  std::istringstream iss(line);
85 
86  if (iss >> dummy >> x >> y >> z)
87  switch (_raster_mode)
88  {
89  case 0: // MAP
90  stream_out << line << ' ' << pointValue(0.0, Point(x, y, z), _variable) << '\n';
91  break;
92  case 1: // FILTER
93  if (pointValue(0.0, Point(x, y, z), _variable) > _threshold)
94  {
95  stream_out << line << '\n';
96  nfilter++;
97  }
98  break;
99  }
100  }
101 
102  current_line++;
103  }
104 
105  stream_in.close();
106  stream_out.close();
107 
108  // modify output file to fix atom count in line 0
109  if (_raster_mode == "FILTER")
110  {
111  // stringify the new number of atoms
112  std::ostringstream oss;
113  oss << nfilter;
114  std::string newline0 = oss.str();
115 
116  // the new number should always be lower -> shorter than the old one, but we check to be sure
117  if (newline0.size() > len0)
118  {
119  mooseWarning("SolutionRasterizer could not update XYZ atom count in header.");
120  return;
121  }
122 
123  // pad shorter numbers with spaces
124  while (newline0.size() < len0)
125  newline0 += ' ';
126 
127  // inject new number into the file
128  std::ofstream stream_fix(_xyz_output.c_str(), std::ios::binary | std::ios::in | std::ios::out);
129  stream_fix << newline0;
130  stream_fix.close();
131  }
132 }

Member Data Documentation

◆ _raster_mode

MooseEnum SolutionRasterizer::_raster_mode
protected

Definition at line 45 of file SolutionRasterizer.h.

Referenced by initialSetup(), and SolutionRasterizer().

◆ _threshold

Real SolutionRasterizer::_threshold
protected

Definition at line 47 of file SolutionRasterizer.h.

Referenced by initialSetup(), and SolutionRasterizer().

◆ _variable

std::string SolutionRasterizer::_variable
protected

Definition at line 43 of file SolutionRasterizer.h.

Referenced by initialSetup().

◆ _xyz_input

FileName SolutionRasterizer::_xyz_input
protected

Definition at line 40 of file SolutionRasterizer.h.

Referenced by initialSetup().

◆ _xyz_output

FileName SolutionRasterizer::_xyz_output
protected

Definition at line 41 of file SolutionRasterizer.h.

Referenced by initialSetup().


The documentation for this class was generated from the following files: