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 15 of file ExodusFormatter.h.

Constructor & Destructor Documentation

◆ ExodusFormatter()

ExodusFormatter::ExodusFormatter ( )

Definition at line 23 of file ExodusFormatter.C.

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

Member Function Documentation

◆ format()

void ExodusFormatter::format ( )

Definition at line 51 of file ExodusFormatter.C.

Referenced by Exodus::outputInput().

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

◆ getInputFileRecord()

std::vector<std::string>& ExodusFormatter::getInputFileRecord ( )
inline

Definition at line 24 of file ExodusFormatter.h.

Referenced by Exodus::outputInput().

24 { return _input_file_record; }
std::vector< std::string > _input_file_record

◆ haveSeenIt()

bool SyntaxTree::haveSeenIt ( const std::string &  prefix,
const std::string &  item 
) const
inherited

Definition at line 63 of file SyntaxTree.C.

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

64 {
65  return _params_printed.find(prefix + item) != _params_printed.end();
66 }
std::set< std::string > _params_printed
Definition: SyntaxTree.h:79

◆ insertNode()

void SyntaxTree::insertNode ( std::string  syntax,
const std::string &  action,
bool  is_action_params = true,
InputParameters params = NULL 
)
inherited

Definition at line 27 of file SyntaxTree.C.

Referenced by ActionWarehouse::printInputFile().

31 {
32  if (_root == NULL)
33  _root = new TreeNode("", *this);
34 
35  _root->insertNode(syntax, action, is_action_params, params);
36 }
void insertNode(std::string &syntax, const std::string &action, bool is_action_params=true, InputParameters *params=NULL)
Definition: SyntaxTree.C:92
TreeNode * _root
Definition: SyntaxTree.h:75

◆ isLongNames()

bool SyntaxTree::isLongNames ( ) const
protectedinherited

Definition at line 236 of file SyntaxTree.C.

237 {
238  return _use_long_names;
239 }
bool _use_long_names
Definition: SyntaxTree.h:76

◆ postscript()

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 46 of file SyntaxFormatterInterface.h.

Referenced by SyntaxTree::print().

46 { return std::string(); }

◆ preamble()

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 38 of file SyntaxFormatterInterface.h.

Referenced by SyntaxTree::print().

38 { return std::string(); }

◆ preTraverse()

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 52 of file SyntaxFormatterInterface.h.

52 { return std::string(); }

◆ print()

std::string SyntaxTree::print ( const std::string &  search_string)
inherited

Definition at line 39 of file SyntaxTree.C.

Referenced by ActionWarehouse::printInputFile().

40 {
41  bool found = false;
42  std::string output;
43 
44  // Clear the list of "seen" parameters before printing the tree
45  _params_printed.clear();
46 
47  if (_root)
48  output = _root->print(-1, search_string, found);
49 
50  if (found)
51  return preamble() + output + postscript();
52  else
53  return "";
54 }
TreeNode * _root
Definition: SyntaxTree.h:75
std::set< std::string > _params_printed
Definition: SyntaxTree.h:79
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 ...
std::string print(short depth, const std::string &search_string, bool &found)
Definition: SyntaxTree.C:136
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...

◆ printBlockClose()

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 34 of file InputFileFormatter.C.

35 {
36  std::string indent(depth * 2, ' ');
37  std::string closing_string;
38 
39  if (depth)
40  closing_string = "../";
41 
42  return std::string("") + indent + "[" + closing_string + "]\n";
43 }
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:29

◆ printBlockOpen()

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 20 of file InputFileFormatter.C.

23 {
24  std::string indent(depth * 2, ' ');
25  std::string opening_string;
26 
27  if (depth)
28  opening_string = "./";
29 
30  return std::string("\n") + indent + "[" + opening_string + name + "]\n";
31 }
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:29

◆ printInputFile()

void ExodusFormatter::printInputFile ( ActionWarehouse wh)

Definition at line 26 of file ExodusFormatter.C.

Referenced by Exodus::outputInput().

27 {
28  _ss << "####################\n"
29  << "# Created by MOOSE #\n"
30  << "####################\n";
31 
32  // Grab the command line arguments first
33  _ss << "### Command Line Arguments ###\n";
34  if (wh.mooseApp().commandLine())
35  {
36  auto argc = wh.mooseApp().commandLine()->argc();
37  auto argv = wh.mooseApp().commandLine()->argv();
38  for (int i = 1; i < argc; i++)
39  _ss << " " << argv[i];
40  }
41  if (wh.mooseApp().getSystemInfo() != NULL)
42  {
43  _ss << "### Version Info ###\n" << wh.mooseApp().getSystemInfo()->getInfo() << "\n";
44  }
45 
46  _ss << "### Input File ###" << std::endl;
47  wh.printInputFile(_ss);
48 }
MooseApp & mooseApp()
std::shared_ptr< CommandLine > commandLine() const
Get the command line.
Definition: MooseApp.h:293
void printInputFile(std::ostream &out)
This method uses the Actions in the warehouse to reproduce the input file.
std::stringstream _ss
const SystemInfo * getSystemInfo() const
Get SystemInfo object.
Definition: MooseApp.h:421
std::string getInfo() const
Definition: SystemInfo.C:26

◆ printParams()

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 46 of file InputFileFormatter.C.

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

◆ seenIt()

void SyntaxTree::seenIt ( const std::string &  prefix,
const std::string &  item 
)
inherited

Definition at line 57 of file SyntaxTree.C.

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

58 {
59  _params_printed.insert(prefix + item);
60 }
std::set< std::string > _params_printed
Definition: SyntaxTree.h:79

Member Data Documentation

◆ _dump_mode

bool InputFileFormatter::_dump_mode
protectedinherited

Definition at line 35 of file InputFileFormatter.h.

Referenced by InputFileFormatter::printParams().

◆ _input_file_record

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

Definition at line 28 of file ExodusFormatter.h.

Referenced by format(), and getInputFileRecord().

◆ _root

TreeNode* SyntaxTree::_root
protectedinherited

Definition at line 75 of file SyntaxTree.h.

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

◆ _ss

std::stringstream ExodusFormatter::_ss
protected

Definition at line 27 of file ExodusFormatter.h.

Referenced by format(), and printInputFile().

◆ _use_long_names

bool SyntaxTree::_use_long_names
protectedinherited

Definition at line 76 of file SyntaxTree.h.

Referenced by SyntaxTree::isLongNames().


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