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

#include <ExodusFormatter.h>

Inheritance diagram for ExodusFormatter:
[legend]

Public Member Functions

 ExodusFormatter ()
 
void printInputFile (ActionWarehouse &wh)
 
void format ()
 
std::vector< std::string > & getInputFileRecord ()
 
virtual std::string printBlockOpen (const std::string &name, short depth, const std::string &) override
 This method is called at the beginning of each Node in the tree. More...
 
virtual std::string printBlockClose (const std::string &name, short depth) const override
 This method is called at the end of of each Node in the tree. More...
 
virtual std::string printParams (const std::string &prefix, const std::string &fully_qualified_name, InputParameters &params, short depth, const std::string &search_string, bool &found) override
 This function is called for each InputParameters object stored at a particular node. More...
 
void insertNode (std::string syntax, const std::string &action, bool is_action_params=true, InputParameters *params=NULL)
 
std::string print (const std::string &search_string)
 
void seenIt (const std::string &prefix, const std::string &item)
 
bool haveSeenIt (const std::string &prefix, const std::string &item) const
 
virtual std::string preamble () const
 This method is called once at the beginning of the tree traversal and can be used to build up header information. More...
 
virtual std::string postscript () const
 This method is called once at the end of the tree traversal and can be used to add any necessary trailing information to the final formatted string. More...
 
virtual std::string preTraverse (short) const
 This method is called once at each node in the syntax tree before traversing child nodes. More...
 

Protected Member Functions

bool isLongNames () const
 

Protected Attributes

std::stringstream _ss
 
std::vector< std::string > _input_file_record
 
bool _dump_mode
 
TreeNode_root
 
bool _use_long_names
 

Detailed Description

Definition at line 20 of file ExodusFormatter.h.

Constructor & Destructor Documentation

ExodusFormatter::ExodusFormatter ( )

Definition at line 28 of file ExodusFormatter.C.

28 : InputFileFormatter(false) {}
InputFileFormatter(bool dump_mode)

Member Function Documentation

void ExodusFormatter::format ( )

Definition at line 56 of file ExodusFormatter.C.

Referenced by Exodus::outputInput().

57 {
58  std::string s;
59  _input_file_record.clear();
60 
61  while (std::getline(_ss, s))
62  {
63  // MAX_LINE_LENGTH is from ExodusII
64  if (s.length() > MAX_LINE_LENGTH)
65  {
66  const std::string continuation("...");
67  const size_t cont_len = continuation.length();
68  size_t num_lines = s.length() / (MAX_LINE_LENGTH - cont_len) + 1;
69  std::string split_line;
70  for (size_t j = 0, l_begin = 0; j < num_lines; ++j, l_begin += MAX_LINE_LENGTH - cont_len)
71  {
72  size_t l_len = MAX_LINE_LENGTH - cont_len;
73  if (s.length() < l_begin + l_len)
74  l_len = s.length() - l_begin;
75 
76  split_line = s.substr(l_begin, l_len);
77 
78  if (l_begin + l_len != s.length())
79  split_line += continuation;
80 
81  _input_file_record.push_back(split_line);
82  }
83  }
84  else
85  _input_file_record.push_back(s);
86  }
87 }
std::vector< std::string > _input_file_record
std::stringstream _ss
std::vector<std::string>& ExodusFormatter::getInputFileRecord ( )
inline

Definition at line 29 of file ExodusFormatter.h.

Referenced by Exodus::outputInput().

29 { return _input_file_record; }
std::vector< std::string > _input_file_record
bool SyntaxTree::haveSeenIt ( const std::string &  prefix,
const std::string &  item 
) const
inherited

Definition at line 68 of file SyntaxTree.C.

Referenced by InputFileFormatter::printParams(), and YAMLFormatter::printParams().

69 {
70  return _params_printed.find(prefix + item) != _params_printed.end();
71 }
std::set< std::string > _params_printed
Definition: SyntaxTree.h:84
void SyntaxTree::insertNode ( std::string  syntax,
const std::string &  action,
bool  is_action_params = true,
InputParameters params = NULL 
)
inherited

Definition at line 32 of file SyntaxTree.C.

Referenced by ActionWarehouse::printInputFile().

36 {
37  if (_root == NULL)
38  _root = new TreeNode("", *this);
39 
40  _root->insertNode(syntax, action, is_action_params, params);
41 }
void insertNode(std::string &syntax, const std::string &action, bool is_action_params=true, InputParameters *params=NULL)
Definition: SyntaxTree.C:97
TreeNode * _root
Definition: SyntaxTree.h:80
bool SyntaxTree::isLongNames ( ) const
protectedinherited

Definition at line 241 of file SyntaxTree.C.

Referenced by SyntaxTree::TreeNode::print().

242 {
243  return _use_long_names;
244 }
bool _use_long_names
Definition: SyntaxTree.h:81
virtual std::string SyntaxFormatterInterface::postscript ( ) const
inlinevirtualinherited

This method is called once at the end of the tree traversal and can be used to add any necessary trailing information to the final formatted string.

Returns
- The formatted postscript string

Reimplemented in YAMLFormatter.

Definition at line 51 of file SyntaxFormatterInterface.h.

Referenced by SyntaxTree::print().

51 { return std::string(); }
virtual std::string SyntaxFormatterInterface::preamble ( ) const
inlinevirtualinherited

This method is called once at the beginning of the tree traversal and can be used to build up header information.

Returns
- The formatted preamble string

Reimplemented in YAMLFormatter.

Definition at line 43 of file SyntaxFormatterInterface.h.

Referenced by SyntaxTree::print().

43 { return std::string(); }
virtual std::string SyntaxFormatterInterface::preTraverse ( short  ) const
inlinevirtualinherited

This method is called once at each node in the syntax tree before traversing child nodes.

Returns
- The formatted pre-node traversal string

Reimplemented in YAMLFormatter.

Definition at line 57 of file SyntaxFormatterInterface.h.

Referenced by SyntaxTree::TreeNode::print().

57 { return std::string(); }
std::string SyntaxTree::print ( const std::string &  search_string)
inherited

Definition at line 44 of file SyntaxTree.C.

Referenced by ActionWarehouse::printInputFile().

45 {
46  bool found = false;
47  std::string output;
48 
49  // Clear the list of "seen" parameters before printing the tree
50  _params_printed.clear();
51 
52  if (_root)
53  output = _root->print(-1, search_string, found);
54 
55  if (found)
56  return preamble() + output + postscript();
57  else
58  return "";
59 }
TreeNode * _root
Definition: SyntaxTree.h:80
std::set< std::string > _params_printed
Definition: SyntaxTree.h:84
virtual std::string preamble() const
This method is called once at the beginning of the tree traversal and can be used to build up header ...
virtual std::string postscript() const
This method is called once at the end of the tree traversal and can be used to add any necessary trai...
std::string print(short depth, const std::string &search_string, bool &found)
Definition: SyntaxTree.C:141
std::string InputFileFormatter::printBlockClose ( const std::string &  name,
short  depth 
) const
overridevirtualinherited

This method is called at the end of of each Node in the tree.

It is typically used to provide formatting necessary when closing blocks.

Returns
- The formatted block close string

Implements SyntaxFormatterInterface.

Definition at line 39 of file InputFileFormatter.C.

40 {
41  std::string indent(depth * 2, ' ');
42  std::string closing_string;
43 
44  if (depth)
45  closing_string = "../";
46 
47  return std::string("") + indent + "[" + closing_string + "]\n";
48 }
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:34
std::string InputFileFormatter::printBlockOpen ( const std::string &  name,
short  depth,
const std::string &  doc 
)
overridevirtualinherited

This method is called at the beginning of each Node in the tree.

It is typically used to provide formatting necessary when opening new blocks.

Returns
- The formatted block open string

Implements SyntaxFormatterInterface.

Definition at line 25 of file InputFileFormatter.C.

28 {
29  std::string indent(depth * 2, ' ');
30  std::string opening_string;
31 
32  if (depth)
33  opening_string = "./";
34 
35  return std::string("\n") + indent + "[" + opening_string + name + "]\n";
36 }
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:34
void ExodusFormatter::printInputFile ( ActionWarehouse wh)

Definition at line 31 of file ExodusFormatter.C.

Referenced by Exodus::outputInput().

32 {
33  _ss << "####################\n"
34  << "# Created by MOOSE #\n"
35  << "####################\n";
36 
37  // Grab the command line arguments first
38  _ss << "### Command Line Arguments ###\n";
39  if (wh.mooseApp().commandLine())
40  {
41  auto argc = wh.mooseApp().commandLine()->argc();
42  auto argv = wh.mooseApp().commandLine()->argv();
43  for (int i = 1; i < argc; i++)
44  _ss << " " << argv[i];
45  }
46  if (wh.mooseApp().getSystemInfo() != NULL)
47  {
48  _ss << "### Version Info ###\n" << wh.mooseApp().getSystemInfo()->getInfo() << "\n";
49  }
50 
51  _ss << "### Input File ###" << std::endl;
52  wh.printInputFile(_ss);
53 }
MooseApp & mooseApp()
const SystemInfo * getSystemInfo() const
Get SystemInfo object.
Definition: MooseApp.h:377
void printInputFile(std::ostream &out)
This method uses the Actions in the warehouse to reproduce the input file.
std::stringstream _ss
std::shared_ptr< CommandLine > commandLine()
Get the command line.
Definition: MooseApp.h:265
std::string getInfo() const
Definition: SystemInfo.C:32
std::string InputFileFormatter::printParams ( const std::string &  prefix,
const std::string &  fully_qualified_name,
InputParameters params,
short  depth,
const std::string &  search_string,
bool &  found 
)
overridevirtualinherited

This function is called for each InputParameters object stored at a particular node.

It is responsible for formatting the parameters for the current node.

Returns
- The formatted parameters string for a Node.

Implements SyntaxFormatterInterface.

Definition at line 51 of file InputFileFormatter.C.

57 {
58  std::stringstream oss;
59 
60  std::string quotes = "";
61  std::string spacing = "";
62  std::string forward = "";
63  std::string backdots = "";
64  int offset = 30;
65  for (int i = 0; i < depth; ++i)
66  {
67  spacing += " ";
68  forward = ".";
69  offset -= 2;
70  }
71 
72  for (const auto & iter : params)
73  {
74  // We only want non-private params and params that we haven't already seen
75  if (params.isPrivate(iter.first) || haveSeenIt(fully_qualified_name, iter.first))
76  continue;
77 
78  std::string value = "INVALID";
79  if (params.isParamValid(iter.first))
80  {
81  // Print the parameter's value to a stringstream.
82  std::ostringstream toss;
83  iter.second->print(toss);
84  value = MooseUtils::trim(toss.str());
85  }
86  else if (params.hasDefaultCoupledValue(iter.first))
87  {
88  std::ostringstream toss;
89  toss << params.defaultCoupledValue(iter.first);
90  value = toss.str();
91  }
92 
93  // See if we match the search string
94  if (MooseUtils::wildCardMatch(iter.first, search_string) ||
95  MooseUtils::wildCardMatch(value, search_string))
96  {
97  // Don't print active if it is the default all, that means it's not in the input file - unless
98  // of course we are in dump mode
99  if (!_dump_mode && iter.first == "active")
100  {
101  libMesh::Parameters::Parameter<std::vector<std::string>> * val =
102  dynamic_cast<libMesh::Parameters::Parameter<std::vector<std::string>> *>(iter.second);
103  const std::vector<std::string> & active = val->get();
104  if (val != NULL && active.size() == 1 && active[0] == "__all__")
105  continue;
106  }
107 
108  // Mark it as "seen"
109  seenIt(fully_qualified_name, iter.first);
110 
111  // Don't print type if it is blank
112  if (iter.first == "type")
113  {
114  libMesh::Parameters::Parameter<std::string> * val =
115  dynamic_cast<libMesh::Parameters::Parameter<std::string> *>(iter.second);
116  const std::string & active = val->get();
117  if (val != NULL && active == "")
118  continue;
119  }
120 
121  found = true;
122  oss << spacing << " " << std::left << std::setw(offset) << iter.first << " = ";
123  // std::setw() takes an int
124  int l_offset = 30;
125 
126  if (!_dump_mode || value != "INVALID")
127  {
128  // If the value has spaces, surround it with quotes, otherwise no quotes
129  if (value.find(' ') != std::string::npos)
130  {
131  quotes = "'";
132  l_offset -= 2;
133  }
134  else
135  quotes = "";
136  oss << quotes << value << quotes;
137  l_offset -= value.size();
138  }
139  else if (_dump_mode && params.isParamRequired(iter.first))
140  {
141  oss << "(required)";
142  l_offset -= 10;
143  }
144 
145  // Documentation string
146  if (_dump_mode)
147  {
148  std::vector<std::string> elements;
149  std::string doc = params.getDocString(iter.first);
150  if (MooseUtils::trim(doc) != "")
151  {
152  MooseUtils::tokenize(doc, elements, 68, " \t");
153 
154  for (auto & element : elements)
155  MooseUtils::escape(element);
156 
157  oss << std::right << std::setw(l_offset) << "# " << elements[0];
158  for (unsigned int i = 1; i < elements.size(); ++i)
159  oss << " ...\n"
160  << " " << std::setw(63) << "# " << elements[i];
161  }
162  const std::string group = params.getGroupName(iter.first);
163  if (!group.empty())
164  {
165  if (MooseUtils::trim(doc) != "")
166  oss << " ...\n"
167  << " " << std::setw(70) << "# Group: " << group;
168  else
169  oss << std::right << std::setw(l_offset) << "# Group: " << group;
170  }
171  }
172  oss << "\n";
173  }
174  }
175 
176  return oss.str();
177 }
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:350
bool wildCardMatch(std::string name, std::string search_string)
Definition: MooseUtils.C:511
std::string trim(const std::string &str, const std::string &white_space=" \t\n\v\f\r")
Standard scripting language trim function.
Definition: MooseUtils.C:95
bool haveSeenIt(const std::string &prefix, const std::string &item) const
Definition: SyntaxTree.C:68
void seenIt(const std::string &prefix, const std::string &item)
Definition: SyntaxTree.C:62
void escape(std::string &str)
This function will escape all of the standard C++ escape characters so that they can be printed...
Definition: MooseUtils.C:77
void SyntaxTree::seenIt ( const std::string &  prefix,
const std::string &  item 
)
inherited

Definition at line 62 of file SyntaxTree.C.

Referenced by InputFileFormatter::printParams(), and YAMLFormatter::printParams().

63 {
64  _params_printed.insert(prefix + item);
65 }
std::set< std::string > _params_printed
Definition: SyntaxTree.h:84

Member Data Documentation

bool InputFileFormatter::_dump_mode
protectedinherited

Definition at line 40 of file InputFileFormatter.h.

Referenced by InputFileFormatter::printParams().

std::vector<std::string> ExodusFormatter::_input_file_record
protected

Definition at line 33 of file ExodusFormatter.h.

Referenced by format(), and getInputFileRecord().

TreeNode* SyntaxTree::_root
protectedinherited

Definition at line 80 of file SyntaxTree.h.

Referenced by SyntaxTree::insertNode(), SyntaxTree::print(), and SyntaxTree::~SyntaxTree().

std::stringstream ExodusFormatter::_ss
protected

Definition at line 32 of file ExodusFormatter.h.

Referenced by format(), and printInputFile().

bool SyntaxTree::_use_long_names
protectedinherited

Definition at line 81 of file SyntaxTree.h.

Referenced by SyntaxTree::isLongNames().


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