Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSH_Reader Class Reference

#include <MSH_Reader.h>

Public Member Functions

 MSH_Reader ()
 
int read_mesh (const char *fname, const std::string &wname)
 

Private Types

enum  { MAXLEN =255 }
 

Private Member Functions

void get_nextline (std::istream &is, char *str)
 
void read_pane_coors (std::istream &is, const std::string &wname)
 
void read_pane_elems (std::istream &is, const std::string &wname)
 

Private Attributes

char buf [MAXLEN+1]
 

Detailed Description

Definition at line 40 of file MSH_Reader.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
MAXLEN 

Definition at line 144 of file MSH_Reader.h.

144 {MAXLEN=255};

Constructor & Destructor Documentation

MSH_Reader ( )
inline

Definition at line 43 of file MSH_Reader.h.

43 {}

Member Function Documentation

void get_nextline ( std::istream &  is,
char *  str 
)
inlineprivate

Definition at line 67 of file MSH_Reader.h.

References MAXLEN.

Referenced by read_pane_coors(), and read_pane_elems().

67  {
68  str[0] = '\0';
69  if ( is.eof()) { return; }
70  is.getline( str, MAXLEN);
71  }

Here is the caller graph for this function:

int read_mesh ( const char *  fname,
const std::string &  wname 
)
inline

Definition at line 47 of file MSH_Reader.h.

References COM_get_window_handle(), COM_new_window(), read_pane_coors(), and read_pane_elems().

Referenced by main().

47  {
48  std::ifstream is( fname);
49  if ( is == NULL) {
50  std::cerr << "Error: Could not open file " << fname << std::endl;
51  exit(-1);
52  }
53 
54  // Create the window if not yet exist
55  int h=COM_get_window_handle(wname.c_str());
56  if ( h<=0) COM_new_window( wname.c_str());
57 
58  std::cout << "Reading file " << fname << std::endl;
59 
60  read_pane_coors( is, wname);
61  read_pane_elems( is, wname);
62 
63  return 1;
64  }
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
int COM_get_window_handle(const char *wname)
Definition: roccom_c++.h:404
void read_pane_coors(std::istream &is, const std::string &wname)
Definition: MSH_Reader.h:74
void read_pane_elems(std::istream &is, const std::string &wname)
Definition: MSH_Reader.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

void read_pane_coors ( std::istream &  is,
const std::string &  wname 
)
inlineprivate

Definition at line 74 of file MSH_Reader.h.

References buf, COM_allocate_array(), COM_assertion_msg, COM_set_size(), copy, get_nextline(), i, n, and s.

Referenced by read_mesh().

74  {
75  std::vector<SURF::Point_3<double> > coors;
76 
77  // First, look for number of vertices
78  for ( ;;) {
79  get_nextline( is, buf);
80  std::string s(buf);
81 
82  if ( s.find("Vertices",0)!=std::string::npos) break;
83  }
84 
85  int n=0;
86  is >> n; get_nextline(is, buf);
87  coors.reserve(n);
88 
89  for ( int i=0; i<n; ++i) {
90  get_nextline( is, buf);
91 
92  SURF::Point_3<double> p;
93 
94  std::sscanf( buf, "%lf %lf %lf", &p[0], &p[1], &p[2]);
95  coors.push_back( p);
96  }
97 
98  COM_assertion_msg( n>0, "Did not find any nodes");
99  std::cout << "Read in " << n << " nodes" << std::endl;
100 
101  COM_set_size( (wname+".nc").c_str(), 1, n);
102  SURF::Point_3<double> *p;
103  COM_allocate_array( (wname+".nc").c_str(), 1, &(void*&)p);
104 
105  std::copy( coors.begin(), coors.end(), p);
106  }
#define COM_assertion_msg(EX, msg)
double s
Definition: blastest.C:80
void COM_set_size(const char *wa_str, int pane_id, int size, int ng=0)
Set sizes of for a specific attribute.
Definition: roccom_c++.h:136
char buf[MAXLEN+1]
Definition: MSH_Reader.h:145
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to ** copy
Definition: roccomf90.h:20
blockLoc i
Definition: read.cpp:79
const NT & n
void COM_allocate_array(const char *wa_str, int pane_id=0, void **addr=NULL, int strd=0, int cap=0)
Allocate space for an attribute on a specific pane and return the address by setting addr...
Definition: roccom_c++.h:196
void get_nextline(std::istream &is, char *str)
Definition: MSH_Reader.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

void read_pane_elems ( std::istream &  is,
const std::string &  wname 
)
inlineprivate

Definition at line 109 of file MSH_Reader.h.

References buf, COM_allocate_array(), COM_assertion_msg, COM_set_size(), copy, get_nextline(), i, n, and s.

Referenced by read_mesh().

109  {
110  std::vector<SURF::Vector_3<int> > elems;
111 
112  // First, look for number of triangles
113  for (;;) {
114  get_nextline( is, buf);
115  std::string s(buf);
116 
117  if ( s.find("Triangles",0)!=std::string::npos) break;
118  }
119 
120  int n=0;
121  is >> n; get_nextline(is, buf);
122  elems.reserve(n);
123 
124  // When entering this routine, buf[0] should start with 'f'
125  for ( int i=0; i<n; ++i) {
126  get_nextline( is, buf);
127 
128  SURF::Vector_3<int> p;
129  std::sscanf( buf, "%d %d %d", &p[0], &p[1], &p[2]);
130  elems.push_back( p);
131  }
132 
133  COM_assertion_msg( n>0, "Did not find any faces");
134  std::cout << "Read in " << n << " triangles" << std::endl;
135 
136  COM_set_size( (wname+".:t3:").c_str(), 1, n);
137  SURF::Vector_3<int> *p;
138  COM_allocate_array( (wname+".:t3:").c_str(), 1, &(void*&)p);
139 
140  std::copy( elems.begin(), elems.end(), p);
141  }
#define COM_assertion_msg(EX, msg)
double s
Definition: blastest.C:80
void COM_set_size(const char *wa_str, int pane_id, int size, int ng=0)
Set sizes of for a specific attribute.
Definition: roccom_c++.h:136
char buf[MAXLEN+1]
Definition: MSH_Reader.h:145
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to ** copy
Definition: roccomf90.h:20
blockLoc i
Definition: read.cpp:79
const NT & n
void COM_allocate_array(const char *wa_str, int pane_id=0, void **addr=NULL, int strd=0, int cap=0)
Allocate space for an attribute on a specific pane and return the address by setting addr...
Definition: roccom_c++.h:196
void get_nextline(std::istream &is, char *str)
Definition: MSH_Reader.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

char buf[MAXLEN+1]
private

Definition at line 145 of file MSH_Reader.h.

Referenced by read_pane_coors(), and read_pane_elems().


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