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 26 of file SolutionRasterizer.h.

Constructor & Destructor Documentation

SolutionRasterizer::SolutionRasterizer ( const InputParameters &  parameters)

Definition at line 30 of file SolutionRasterizer.C.

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

Definition at line 31 of file SolutionRasterizer.h.

31 {}

Member Function Documentation

void SolutionRasterizer::initialSetup ( )
virtual

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

Definition at line 47 of file SolutionRasterizer.C.

Referenced by ~SolutionRasterizer().

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

Member Data Documentation

MooseEnum SolutionRasterizer::_raster_mode
protected

Definition at line 42 of file SolutionRasterizer.h.

Referenced by initialSetup(), and SolutionRasterizer().

Real SolutionRasterizer::_threshold
protected

Definition at line 44 of file SolutionRasterizer.h.

Referenced by initialSetup(), and SolutionRasterizer().

std::string SolutionRasterizer::_variable
protected

Definition at line 40 of file SolutionRasterizer.h.

Referenced by initialSetup().

FileName SolutionRasterizer::_xyz_input
protected

Definition at line 37 of file SolutionRasterizer.h.

Referenced by initialSetup().

FileName SolutionRasterizer::_xyz_output
protected

Definition at line 38 of file SolutionRasterizer.h.

Referenced by initialSetup().


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