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

#include <Neutral_Reader.h>

Public Member Functions

 Neutral_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, int nn)
 
void read_pane_elems (std::istream &is, const std::string &wname, int ne)
 

Private Attributes

char buf [MAXLEN+1]
 

Detailed Description

Definition at line 39 of file Neutral_Reader.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
MAXLEN 

Definition at line 127 of file Neutral_Reader.h.

Constructor & Destructor Documentation

Neutral_Reader ( )
inline

Definition at line 42 of file Neutral_Reader.h.

42 {}

Member Function Documentation

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

Definition at line 88 of file Neutral_Reader.h.

References MAXLEN.

Referenced by read_mesh(), read_pane_coors(), and read_pane_elems().

88  {
89  str[0] = '\0';
90  if ( is.eof()) { return; }
91  is.getline( str, MAXLEN);
92  }

Here is the caller graph for this function:

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

Definition at line 46 of file Neutral_Reader.h.

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

Referenced by main().

46  {
47  std::ifstream is( fname);
48  if ( is == NULL) {
49  std::cerr << "Error: Could not open file " << fname << std::endl;
50  exit(-1);
51  }
52 
53  // Create the window if not yet exist
54  int h=COM_get_window_handle(wname.c_str());
55  if ( h<=0) COM_new_window( wname.c_str());
56 
57  std::cout << "Reading file " << fname << std::endl;
58 
59  // Search for NUMNP
60  do {
61  get_nextline( is, buf);
62  } while ( !is.eof() && std::string(buf).find( "NUMNP")==std::string::npos);
63 
64  std::cerr << "Buf is now \"" << buf << "\" before getting nn" << std::endl;
65  get_nextline( is, buf);
66  int t1, t2, t3, t4, nn, ne;
67  std::sscanf( buf, "%d %d %d %d %d %d", &nn, &ne, &t1, &t2, &t3, &t4);
68 
69  // Search for NODAL COORDINAES
70  do {
71  get_nextline( is, buf);
72  } while ( !is.eof() && std::string(buf).find( "NODAL")==std::string::npos);
73 
74  std::cout << "Reading " << nn << " nodes and "
75  << ne << " triangles " << std::endl;
76  read_pane_coors( is, wname, nn);
77 
78  // Search for ELEMENTS
79  do {
80  get_nextline( is, buf);
81  } while ( !is.eof() && std::string(buf).find( "ELEMENTS")==std::string::npos);
82  read_pane_elems( is, wname, ne);
83 
84  return 1;
85  }
void read_pane_elems(std::istream &is, const std::string &wname, int ne)
char buf[MAXLEN+1]
void get_nextline(std::istream &is, char *str)
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, int nn)

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,
int  nn 
)
inlineprivate

Definition at line 95 of file Neutral_Reader.h.

References buf, COM_allocate_array(), COM_assertion, COM_set_size(), get_nextline(), and i.

Referenced by read_mesh().

95  {
96  COM_set_size( (wname+".nc").c_str(), 1, nn);
97  SURF::Point_3<double> *ps;
98  COM_allocate_array( (wname+".nc").c_str(), 1, &(void*&)ps);
99 
100  for ( int i=0; i<nn; ++i) {
101  get_nextline( is, buf);
102  int t1;
103 
104  std::sscanf( buf, "%d %lf %lf %lf", &t1, &ps[i][0], &ps[i][1], &ps[i][2]);
105  COM_assertion( t1==i+1);
106  }
107  }
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
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]
void get_nextline(std::istream &is, char *str)
blockLoc i
Definition: read.cpp:79
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

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,
int  ne 
)
inlineprivate

Definition at line 110 of file Neutral_Reader.h.

References buf, COM_allocate_array(), COM_assertion, COM_set_size(), get_nextline(), and i.

Referenced by read_mesh().

110  {
111  // Note: Only supports triangular meshes now.
112  COM_set_size( (wname+".:t3:").c_str(), 1, ne);
113  SURF::Vector_3<int> *es;
114  COM_allocate_array( (wname+".:t3:").c_str(), 1, &(void*&)es);
115 
116  for (int i=0; i<ne; ++i) {
117  int t1, t2, t3;
118 
119  get_nextline( is, buf);
120  std::sscanf( buf, "%d %d %d %d %d %d", &t1, &t2, &t3,
121  &es[i][0], &es[i][1], &es[i][2]);
122  COM_assertion( t1 == i+1 && t2==3 && t3==3);
123  }
124  }
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
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]
void get_nextline(std::istream &is, char *str)
blockLoc i
Definition: read.cpp:79
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

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 128 of file Neutral_Reader.h.

Referenced by read_mesh(), read_pane_coors(), and read_pane_elems().


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