RBGen  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RBGen_Params.cpp
1 #include "RBGen_Params.h"
2 #include "RBGen_ConfigDefs.h"
3 
6 #include "Teuchos_Utils.hpp"
7 #include "Teuchos_Assert.hpp"
8 #include "Teuchos_Ptr.hpp"
9 
11 {
12  // Create initial empty parameter list
14 
15  // Read in parameter list from XML file
16  Teuchos::updateParametersFromXmlFile( filename, Teuchos::Ptr<Teuchos::ParameterList>(&*params) );
17 
18  /*
19  //
20  // --------------------------------------------------------------
21  // This function scans the input arguments for relevant information
22  // used to specialize the reduced-basis method and its parameters.
23  // --------------------------------------------------------------
24  //
25  // params->set("Number of Input Arguments", argc );
26  // params->set("Input Argument Vector", argv );
27  //
28  // --------------------------------------------------------------
29  // GET FILE FORMAT INFORMATION
30  // --------------------------------------------------------------
31  //
32  // Absolute path where the input files (snapshot files, format file, steady state)
33  //
34  std::string in_path = "/home/hkthorn/TestCode/DataSets/Salsa/";
35  params->set( "Data Input Path", in_path );
36  //
37  // Absolute path where the files containing the computed reduced basis should be placed
38  //
39  std::string out_path = "/home/hkthorn/TestCode/ROM/POD/test_output/";
40  params->set( "Data Output Path", out_path );
41  //
42  // Input / Output file format type
43  // Choices: "Matrix Market", "Burkardt", or "NetCDF"
44  //
45  params->set( "File IO Type", "NetCDF" );
46  //
47  // Name of nodal file (containing XY coordinates)
48  // Note: Only needed if the file IO type is "Burkardt"
49  //
50  params->set( "Data Format File", in_path + "xy.txt" );
51  //
52  // Name of output file
53  //
54  //params->set( "Reduced Basis Output File", out_path + "pod_basis.nc" );
55  //
56  // --------------------------------------------------------------
57  // GENERATE SNAPSHOT FILENAMES
58  // --------------------------------------------------------------
59  //
60  // Vector of snapshot filenames
61  //
62  // If the file format is "Burkardt", construct all the 500 input filenames.
63  //
64  if (Teuchos::getParameter<std::string>( *params, "File IO Type" ) == "Burkardt") {
65  std::vector< std::string > filenames;
66  int num_files = 500;
67  for (int i=0; i<num_files; i++) {
68  if (i < 9)
69  filenames.push_back( in_path + "up00" + Teuchos::Utils::toString(i + 1) + ".txt" );
70  else if (i < 99)
71  filenames.push_back( in_path + "up0" + Teuchos::Utils::toString(i + 1) + ".txt" );
72  else if (i < 999)
73  filenames.push_back( in_path + "up" + Teuchos::Utils::toString(i + 1) + ".txt" );
74  else
75  std::cout << "There are more than 1000 files!" << endl;
76  }
77  //
78  // Insert the vector of snapshot filenames into the parameter list.
79  //
80  params->set("Snapshot Files", filenames);
81  }
82  //
83  // If the file format is "netCDF", then input each of the filenames that holds any snapshots
84  //
85  if (Teuchos::getParameter<std::string>( *params, "File IO Type" ) == "netCDF") {
86  std::vector< std::string > filenames;
87  //
88  // List as many files as necessary that hold the snapshots
89  //
90  filenames.push_back( in_path + "snap-time1200-2400-stride8.nc" );
91  //filenames.push_back( in_path + "inout-41x41-1_3.nc" );
92  //
93  // Insert the vector of snapshot filenames into the parameter list.
94  //
95  params->set("Snapshot Files", filenames);
96  }
97  //
98  // --------------------------------------------------------------
99  // GET PREPROCESSING INFORMATION
100  // --------------------------------------------------------------
101  //
102  // Preprocessing method used on the input snapshot set
103  // Choices: "none" = no preprocessing
104  // "ModifiedSS" = creates modified snapshot set using steady state file, scalings, and scaling_idx
105  //
106  params->set( "Preprocessing", "none" );
107  //
108  // Name of steady state file to be used if the preprocessing method is "ModifiedSS"
109  //
110  params->set( "Steady State File", in_path + "snap-time_ave1200-7200.nc" );
111  //
112  // Scaling vector for subtracting steady state from solutions given in the snapshot files
113  // if the preprocessing method is "ModifiedSS".
114  // List as many scalings as needed for all snapshots
115  //
116  //std::vector< double > scalings;
117  //scalings.push_back( 1.0/3.0 );
118  //scalings.push_back( 5.0/3.0 );
119  //scalings.push_back( 1.0 );
120  //
121  //params->set("Snapshot Scaling", scalings);
122  //
123  // Index vector for subtracting steady state from solutions given in the snapshot files
124  // if the preprocessing method is "ModifiedSS".
125  // This vector contains pairs indicating the beginning and ending of each scaling section.
126  //
127  // NOTE: If the "Snapshot Scaling Indices" are not specified here, and you are using the
128  // netCDF file i/o handlers, then a scaling_idx vector will be created by the netCDF file i/o
129  // handler that is consistent with the snapshot size of each file. For example, say you have
130  // two files "snap1.nc" which has 100 snapshots and "snap2.nc" which has 500 snapshots, then
131  // the netCDF file i/o handler will create "scaling_idx" which has the pairs [0,99] and [100,599].
132  // This ALSO assumes that you have two entries in the scaling vector above, one for each file.
133  //
134  //std::vector< std::pair<int,int> > scaling_idx;
135  //std::pair< int, int > first_pair( 0, 249 );
136  //scaling_idx.push_back( first_pair );
137  //std::pair< int, int > second_pair( 250, 499 );
138  //scaling_idx.push_back( second_pair );
139  //
140  //params->set("Snapshot Scaling Indices", scaling_idx);
141  //
142  // --------------------------------------------------------------
143  // GET REDUCED BASIS METHOD AND SIZE INFORMATION
144  // --------------------------------------------------------------
145  //
146  // Reduced basis method that RBGen should use
147  // Choices: "LAPACK POD" or "Anasazi POD"
148  //
149  params->set( "Reduced Basis Method", "Anasazi POD" ); // "LAPACK POD" or "Anasazi POD"
150  //
151  // Size of reduced basis (number of vectors that should be computed)
152  //
153  params->set( "Basis Size", 64 ); // Any size of basis you'd like
154  //
155  */
156  //Teuchos::writeParameterListToXmlFile( *params, "rbGenInput_new.xml" );
157 
158  return params;
159 }
160 
162 {
163  Teuchos::RCP< std::vector< std::string > > filenames = Teuchos::rcp( new std::vector< std::string >() );
164 
165  // See if the "File I/O" sublist exists
166  TEUCHOS_TEST_FOR_EXCEPTION(!params.isSublist( "File IO" ), std::invalid_argument, "File I/O sublist does not exist!");
167 
168  // Get the "File I/O" sublist.
169  Teuchos::ParameterList& fileio_params = const_cast<Teuchos::ParameterList&>(params.sublist( "File IO" ) );
170 
171  // See if the "Data Filename Format" sublist exists
172  TEUCHOS_TEST_FOR_EXCEPTION(!fileio_params.isSublist( "Data Filename Format" ), std::invalid_argument, "Data Filename Format sublist does not exist!");
173 
174  // Get the "Data Filename Format" sublist.
175  Teuchos::ParameterList& fileformat_params = fileio_params.sublist( "Data Filename Format" );
176 
177  // Get the string prepended to the numeric characters.
178  std::string prepend = "";
179  if ( fileformat_params.isParameter( "Prepend" ) ) {
180  prepend = Teuchos::getParameter<std::string>( fileformat_params, "Prepend" );
181  }
182 
183  // Get the string postpended to the numeric characters.
184  std::string postpend = "";
185  if ( fileformat_params.isParameter( "Postpend" ) ) {
186  postpend = Teuchos::getParameter<std::string>( fileformat_params, "Postpend" );
187  }
188 
189  // Get the string prepended to the numeric characters.
190  std::string extension = "";
191  if ( fileformat_params.isParameter( "Extension" ) ) {
192  extension = Teuchos::getParameter<std::string>( fileformat_params, "Extension" );
193  }
194 
195  // Get the base for the numeric count
196  int base_num = 0;
197  if ( fileformat_params.isParameter( "File Number Base" ) ) {
198  base_num = Teuchos::getParameter<int>( fileformat_params, "File Number Base" );
199  }
200 
201  std::string format_type = Teuchos::getParameter<std::string>( fileformat_params, "Type" );
202 
203  if ( format_type == "Single file" ) {
204 
205  // Get the file to process
206  filenames->push_back( Teuchos::getParameter<std::string>( fileformat_params, "Data File" ) );
207 
208  } else
209 
210  if ( format_type == "Fixed length numeric" ) {
211 
212  // Get the number of files to process
213  int num_files = Teuchos::getParameter<int>( fileformat_params, "Number of Files" );
214  int max_num = base_num + num_files;
215  int num_places = (int)::ceil( ::log10( (double)(max_num) ) );
216 
217  for (int i=base_num; i<max_num; i++) {
218 
219  // Generate the current filename
220  std::string curr_filename = prepend;
221 
222  // Get the number of places needed for the current file number
223  int curr_places = (int)::ceil( ::log10( (double)(i+1) ) );
224 
225  // Add zeros to pad the file number
226  for (int j=curr_places; j<num_places; j++) {
227  curr_filename += "0";
228  }
229 
230  // Now add on the current file number, postpend string and extension
231  filenames->push_back( curr_filename + Teuchos::Utils::toString( i ) + postpend + extension );
232  }
233 
234  } else
235 
236  if ( format_type == "Variable length numeric" ) {
237 
238  // Get the number of files to process
239  int num_files = Teuchos::getParameter<int>( fileformat_params, "Number of Files" );
240  int max_num = base_num + num_files;
241 
242  for (int i=base_num; i<max_num; i++) {
243  filenames->push_back( prepend + Teuchos::Utils::toString( i ) + postpend + extension );
244  }
245  }
246 
247  else {
248  std::string err_str = "File format type, 'Type = " + format_type + "', is not recognized!";
249  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, err_str);
250  }
251 
252  return filenames;
253 
254 }
255 
256 
Teuchos::RCP< Teuchos::ParameterList > createParams(const std::string &filename)
Create a Teuchos::ParameterList from an XML file.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static std::string toString(const double &x)
Teuchos::RCP< std::vector< std::string > > genFileList(const Teuchos::ParameterList &params)
Extract the filename list from a Teuchos::ParameterList.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool isSublist(const std::string &name) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")