2 #include "RBGen_BurkardtFileIOHandler.h"
3 #include "RBGen_ConfigDefs.h"
5 #include "Epetra_BLAS.h"
6 #include "Epetra_Export.h"
7 #include "Epetra_Import.h"
8 #include "Epetra_Map.h"
9 #include "Epetra_Vector.h"
10 #include "Epetra_MultiVector.h"
13 #include "Teuchos_Assert.hpp"
16 #include "Epetra_MpiComm.h"
18 #include "Epetra_SerialComm.h"
25 : num_nodes(0), isInit(false)
41 if( fileio_params.
isParameter(
"Burkardt Data Format File") )
43 std::string format_file = Teuchos::getParameter<std::string>( fileio_params,
"Burkardt Data Format File" );
47 if ( comm.
MyPID() == 0 )
48 num_nodes = data_size( format_file );
57 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Cannot find the data size or data format file 'Burkardt Data Format File'!");
62 if ( fileio_params.
isParameter(
"Data Input Path" ) ) {
63 in_path = Teuchos::getParameter<std::string>( fileio_params,
"Data Input Path" );
68 if ( fileio_params.
isParameter(
"Data Output Path" ) ) {
69 out_path = Teuchos::getParameter<std::string>( fileio_params,
"Data Output Path" );
90 int num_vecs = filenames.size();
91 int dim = 2*num_nodes;
92 int* index =
new int[ num_nodes ];
93 double *u =
new double[ num_nodes ];
94 double *v =
new double[ num_nodes ];
102 if ( comm.
MyPID() == 0 ) {
103 Proc0Map =
new Epetra_Map( dim, dim, 0, comm );
116 for ( i=0; i<num_vecs; i++ ) {
120 col_newMV = (*newMV)( i );
124 if ( comm.
MyPID() == 0 ) {
128 std::string temp_filename = in_path + filenames[i];
129 read_vec( temp_filename.c_str(), num_nodes, u, v );
134 for ( j=0; j<num_nodes; j++ )
139 for ( j=0; j<num_nodes; j++ )
146 col_newMV->Import(Proc0Vector, importer,
Add);
174 int num_vecs = MV->NumVectors();
175 int dim = 2*num_nodes;
176 double *u = 0, *v = 0;
181 std::string out_file;
182 int num_places = (int)::ceil( ::log10( (
double)(num_vecs) ) );
186 if ( comm.
MyPID() == 0 ) {
187 Proc0Map =
new Epetra_Map( dim, dim, 0, comm );
188 u =
new double[ num_nodes ];
189 v =
new double[ num_nodes ];
200 while ( i < num_vecs ) {
204 col_newMV = (*MV)( i );
206 Proc0Vector.Export(*col_newMV, exporter,
Insert);
212 if ( comm.
MyPID() == 0 ) {
213 blas.
COPY( num_nodes, &Proc0Vector[0], u, 2, 1 );
214 blas.
COPY( num_nodes, &Proc0Vector[0]+1, v, 2, 1 );
218 out_file = out_path + filename;
219 int curr_places = (int)::ceil( ::log10( (
double)(i) ) );
222 for (
int j=curr_places; j<num_places; j++) {
232 write_vec( out_file, num_nodes, u, v );
238 if ( u )
delete [] u;
239 if ( v )
delete [] v;
250 int BurkardtFileIOHandler::data_size(
const std::string filename )
256 if ( (in_file = fopen( filename.c_str(),
"r")) == NULL ) {
257 fprintf(stderr,
"Error: Cannot open file: %s\n",filename.c_str());
263 while( fgets( temp_str, 100, in_file ) != NULL ) { i++; }
272 int BurkardtFileIOHandler::read_vec(
const std::string filename,
int n_equations,
double *x,
double *y )
278 fprintf(stderr,
"Error: pointer to x vector is NULL \n");
282 if ( (in_file = fopen( filename.c_str(),
"r")) == NULL ) {
283 fprintf(stderr,
"Error: Cannot open file: %s\n", filename.c_str());
288 for (i=0; i< n_equations; i++)
289 fscanf(in_file,
"%lf%lf", x+i, y+i);
292 for(i=0; i< n_equations; i++)
293 fscanf(in_file,
"%lf", x+i);
303 int BurkardtFileIOHandler::write_vec(
const std::string filename,
int n_equations,
double *x,
double *y )
309 fprintf(stderr,
"Error: pointer to x vector is NULL \n");
313 if ( (out_file = fopen( filename.c_str(),
"w")) == NULL ) {
314 fprintf(stderr,
"Error: Cannot open file: %s\n",filename.c_str());
319 for (i=0; i< n_equations; i++)
320 fprintf(out_file,
"%25.15e%25.15e\n", x[i], y[i]) ;
323 for(i=0; i< n_equations; i++)
324 fprintf(out_file,
"%25.15e\n", x[i]) ;
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static std::string toString(const double &x)
BurkardtFileIOHandler()
Default constructor.
int ReplaceGlobalValues(int NumEntries, const double *Values, const int *Indices)
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Epetra_MultiVector > Read(const std::vector< std::string > &filenames)
Method for reading multiple files and putting them into an Epetra_MultiVector.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void COPY(const int N, const float *X, float *Y, const int INCX=1, const int INCY=1) const
int Broadcast(double *MyVals, int Count, int Root) const
void Initialize(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Initialize file reader using.
void Write(const Teuchos::RCP< const Epetra_MultiVector > &MV, const std::string &filename)
Method for writing one Epetra_MultiVector into a file.