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