33 #ifndef CONNECTIONVIEWEROUTPUT_H_
34 #define CONNECTIONVIEWEROUTPUT_H_
51 #define CONNECTION_VIEWER_VERSION 1
55 namespace ConnectionViewer
84 bool AddMarkers(std::string filename, std::string markfilename);
85 bool WriteMarkers(std::string markfilename, std::vector<bool> markers,
float r,
float g,
float b,
float alpha,
int size);
87 template<
typename TPosition>
88 bool WriteGridHeader(std::ostream &f,
const TPosition &positions,
size_t N,
int dimension)
92 f << dimension <<
"\n";
95 for(
size_t i=0; i < N; i++)
96 f << positions[i][0] <<
" 0.0\n";
97 else if(dimension == 2)
98 for(
size_t i=0; i < N; i++)
99 f << positions[i][0] <<
" " << positions[i][1] <<
"\n";
101 for(
size_t i=0; i < N; i++)
102 f << positions[i][0] <<
" " << positions[i][1] <<
" " << positions[i][2] <<
"\n";
108 template<
typename TPosition>
123 template<
typename Matrix_type,
typename postype>
124 void WriteMatrix(std::ostream &file,
const Matrix_type &A, postype *positions,
int dimensions)
127 size_t rows = A.num_rows();
130 PROGRESS_START(prog, rows,
"WriteMatrixToConnectionViewer " << dimensions <<
"d, " << rows <<
"x" << rows);
133 for(
size_t i=0; i < rows; i++)
136 for(
typename Matrix_type::const_row_iterator conn = A.begin_row(i); conn != A.end_row(i); ++conn)
137 if(conn.value() != 0.0)
138 file << i <<
" " << conn.index() <<
" " << conn.value() << std::endl;
140 file << i <<
" " << conn.index() <<
" 0" << std::endl;
144 template<
typename Matrix_type,
typename postype>
145 void WriteMatrix(std::string filename,
const Matrix_type &A, postype *positions,
int dimensions)
147 std::fstream file(filename.c_str(), std::ios::out);
152 template<
typename Matrix_type,
typename postype>
153 void WriteMatrixPar(std::string
name,
const Matrix_type &A,
const postype *positions,
int dimensions)
178 file << pc.
size() <<
"\n";
179 for(
size_t i=0; i<pc.
size(); i++)
183 file << fname << buf <<
"\n";
321 template <
typename Matrix_type,
typename postype>
323 const Matrix_type &A,
324 const std::vector<postype> &positionsFrom,
325 const std::vector<postype> &positionsTo,
size_t dimensions)
329 if(positionsFrom.size() != A.num_cols())
331 UG_LOG(
"uFrom.size() != A.num_cols() !\n");
334 if(positionsTo.size() != A.num_rows())
336 UG_LOG(
"uTo.size() != A.num_rows() !\n");
340 size_t fromOffset = positionsTo.size();
343 std::fstream file(filename.c_str(), std::ios::out);
345 file << dimensions << std::endl;
348 file << positionsFrom.size() + positionsTo.size() << std::endl;
351 for(
size_t i=0; i < positionsTo.size(); i++)
352 file << positionsTo[i][0] <<
" 0.0" << std::endl;
353 for(
size_t i=0; i < positionsFrom.size(); i++)
354 file << positionsFrom[i][0] <<
" 0.0" << std::endl;
356 else if(dimensions == 2){
357 for(
size_t i=0; i < positionsTo.size(); i++)
358 file << positionsTo[i][0] <<
" " << positionsTo[i][1] << std::endl;
359 for(
size_t i=0; i < positionsFrom.size(); i++)
360 file << positionsFrom[i][0] <<
" " << positionsFrom[i][1] << std::endl;
363 for(
size_t i=0; i < positionsTo.size(); i++)
364 file << positionsTo[i][0] <<
" " << positionsTo[i][1] <<
" " << positionsTo[i][2] << std::endl;
365 for(
size_t i=0; i < positionsFrom.size(); i++)
366 file << positionsFrom[i][0] <<
" " << positionsFrom[i][1] <<
" " << positionsFrom[i][2] << std::endl;
369 file << 1 << std::endl;
372 PROGRESS_START(prog, A.num_rows(),
"WriteMatrixToConnectionViewer " << dimensions <<
"d, " << A.num_rows() <<
"x" << A.num_rows() );
373 for(
size_t i=0; i < A.num_rows(); i++)
376 for(
typename Matrix_type::const_row_iterator conn = A.begin_row(i); conn != A.end_row(i); ++conn)
377 if(conn.value() != 0.0)
378 file << i <<
" " << conn.index() + fromOffset <<
" " << conn.value() << std::endl;
380 file << i <<
" " << conn.index() + fromOffset <<
" 0" << std::endl;
386 template <
typename Matrix_type,
typename postype>
388 const std::vector<postype> &positionsFrom,
const std::vector<postype> &positionsTo,
size_t dimensions)
402 template<
typename Vector_type,
typename postype>
403 void WriteVector(std::string filename,
const Vector_type &b,
const postype *positions,
int dimensions,
const Vector_type *compareVec=NULL)
407 std::fstream file(filename.c_str(), std::ios::out);
408 size_t rows = b.size();
412 if(compareVec == NULL)
413 for(
size_t i=0; i < rows; i++)
414 file << i <<
" " << i <<
" "
415 << std::setprecision(std::numeric_limits<number>::digits10 + 1)
416 << b[i] << std::endl;
418 for(
size_t i=0; i < rows; i++)
419 file << i <<
" " << i <<
" "
420 << std::setprecision(std::numeric_limits<number>::digits10 + 1)
421 << b[i]-(*compareVec)[i] << std::endl;
424 template<
typename Vector_type,
typename postype>
425 void WriteVectorPar(std::string filename,
const Vector_type &b,
const postype *positions,
int dimensions,
const Vector_type *compareVec=NULL)
430 template<
typename Matrix_type,
typename Vector_type,
typename postype>
431 void WriteVector(std::string filename,
const Matrix_type &A,
const Vector_type &v,
432 postype *positions,
int dimensions,
const Vector_type *compareVec=NULL)
437 UG_LOG(__FILE__ <<
":" << __LINE__ <<
" WriteVectorToConnectionViewer: only dimension=2 supported");
442 size_t rows = A.num_rows();
443 std::fstream file(filename.c_str(), std::ios::out);
446 PROGRESS_START(prog, rows,
"WriteVectorToConnectionViewer " << dimensions <<
"d, " << A.num_rows() <<
"x" << A.num_rows() );
448 for(
size_t i=0; i < rows; i++)
451 for(
typename Matrix_type::const_row_iterator conn = A.begin_row(i); conn != A.end_row(i); ++conn)
452 if(conn.value() != 0.0)
453 file << i <<
" " << conn.index() <<
" "
454 << std::setprecision(std::numeric_limits<number>::digits10 + 1)
455 << conn.value() << std::endl;
457 file << i <<
" " << conn.index() <<
" 0" << std::endl;
461 std::string nameValues = filename;
462 nameValues.resize(nameValues.find_last_of(
"."));
463 nameValues.append(
".values");
464 file <<
"v " << nameValues <<
"\n";
466 std::fstream fileValues(nameValues.c_str(), std::ios::out);
467 if(compareVec == NULL)
469 for(
size_t i=0; i < rows; i++)
470 fileValues << i <<
" " << v[i] <<
"\n";
475 for(
size_t i=0; i < rows; i++)
478 t -= (*compareVec)[i];
479 fileValues << i <<
" " << t <<
"\n";
485 template<
typename Matrix_type,
typename Vector_type,
typename postype>
486 void WriteVectorPar(std::string filename,
const Matrix_type &A,
const Vector_type &v,
487 postype *positions,
int dimensions,
const Vector_type *compareVec=NULL)
493 template<
typename Vector_type,
typename postype>
494 void WriteVectorNEW(std::string filename,
const Vector_type &b, postype *positions,
int dimensions)
499 std::fstream file(filename.c_str(), std::ios::out);
501 file << 3 << std::endl;
504 for(
size_t i=0; i<b.size(); i++)
508 double scale = 1.0/nmax;
509 size_t rows = b.size();
511 file << rows << std::endl;
513 for(
size_t i=0; i < rows; i++)
514 file << positions[i][0] <<
" 0.0" << std::endl;
515 else if(dimensions == 2)
516 for(
size_t i=0; i < rows; i++)
517 file << positions[i][0] <<
" " << positions[i][1] <<
" " << b[i] * scale << std::endl;
519 for(
size_t i=0; i < rows; i++)
520 file << positions[i][0] <<
" " << positions[i][1] <<
" " << positions[i][2] << std::endl;
522 file << 1 << std::endl;
524 for(
size_t i=0; i < rows; i++)
526 file << i <<
" " << i <<
" " << b[i] << std::endl;
location name
Definition: checkpoint_util.lua:128
Definition: parallel_archive.h:102
std::stringstream & create_stringstream_file(std::string name)
Definition: parallel_archive.h:213
Definition: pcl_process_communicator.h:70
int get_proc_id(size_t index) const
returns the i-th process in the communicator
Definition: pcl_process_communicator.cpp:86
size_t size() const
returns the size of the communicator
Definition: pcl_process_communicator.cpp:71
#define CONNECTION_VIEWER_VERSION
Definition: connection_viewer_output.h:51
int ProcRank()
returns the rank of the process
Definition: pcl_base.cpp:83
int NumProcs()
returns the number of processes
Definition: pcl_base.cpp:91
#define UG_LOG(msg)
Definition: log.h:367
bool g_parallelConnectionViewer
Definition: connection_viewer_output.cpp:48
void WriteMatrix(std::ostream &file, const Matrix_type &A, postype *positions, int dimensions)
writes to a file in somewhat SparseMatrix-market format (for connection viewer)
Definition: connection_viewer_output.h:124
bool WriteMarkers(string markfilename, vector< bool > markers, float r, float g, float b, float alpha, int size)
Definition: connection_viewer_output.cpp:95
bool AddMarkers(string filename, string markfilename)
Definition: connection_viewer_output.cpp:88
void WriteVectorPar(std::string filename, const Vector_type &b, const postype *positions, int dimensions, const Vector_type *compareVec=NULL)
Definition: connection_viewer_output.h:425
bool WriteGridHeader(std::ostream &f, const TPosition &positions, size_t N, int dimension)
Definition: connection_viewer_output.h:88
void WriteMatrixPar(std::string name, const Matrix_type &A, const postype *positions, int dimensions)
Definition: connection_viewer_output.h:153
void WriteVector(std::string filename, const Vector_type &b, const postype *positions, int dimensions, const Vector_type *compareVec=NULL)
writes to a file in somewhat SparseMatrix-market format (for connection viewer)
Definition: connection_viewer_output.h:403
string GetParallelName(string name, const pcl::ProcessCommunicator &pc, bool bWriteHeader)
Definition: connection_viewer_output.cpp:51
std::string GetStringPrintf(const char *format, Args... args)
Definition: string_util.h:449
string FilenameWithoutExtension(string str)
Definition: string_util.cpp:209
string GetFilenameExtension(const string &str)
Definition: string_util.cpp:224
double BlockNorm(const TYPE &v)
Definition: blocks.h:57
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258
#define PROGRESS_START(progVarName, dSize, msg)
Definition: progress.h:111
#define PROGRESS_UPDATE(progVarName, d)
Definition: progress.h:117
T value_type
Definition: sparsematrix_interface.h:2