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

#include <IM_Reader.h>

Public Types

typedef bool(* Func_ptr )(int pane_id, int comm_rank, int comm_size)
 

Public Member Functions

 IM_Reader (MPI_Comm comm=MPI_COMM_WORLD, double a=1)
 
int read_winmesh (const char *fname, const std::string &wname, bool del=true)
 
int read_mesh (const char *fname, const std::string &wname, Func_ptr is_local)
 

Private Types

enum  { MAXLEN =255 }
 

Private Member Functions

bool isfinite (double x)
 
void get_nextline (std::istream &is, char *str)
 
void read_pane_coors (std::istream &is, const std::string &wname, int pid, int n, bool local)
 
void read_pane_elems (std::istream &is, const std::string &wname, int pid, int num_elems, int nodes_per_elem, bool local)
 
void read_pane_ij (std::istream &is, const std::string &wname, int pid, bool local)
 
void read_pane_uns (std::istream &is, const std::string &wname, int pid, int nodes_per_elem, bool local)
 
void read_pane_mixed (std::istream &is, const std::string &wname, int pid, bool local)
 

Private Attributes

char buf [MAXLEN+1]
 
double _alpha
 
int _rank
 
int _size
 

Detailed Description

Definition at line 39 of file IM_Reader.h.

Member Typedef Documentation

typedef bool(* Func_ptr)(int pane_id, int comm_rank, int comm_size)

Definition at line 56 of file IM_Reader.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
MAXLEN 

Definition at line 302 of file IM_Reader.h.

302 {MAXLEN=255};

Constructor & Destructor Documentation

IM_Reader ( MPI_Comm  comm = MPI_COMM_WORLD,
double  a = 1 
)
inlineexplicit

Definition at line 45 of file IM_Reader.h.

References _rank, and _size.

45  : _alpha(a) {
46  int flag; MPI_Initialized(&flag);
47  if ( !flag || comm == MPI_COMM_NULL) {
48  _rank = 0; _size = 1;
49  }
50  else {
51  MPI_Comm_rank( comm, &_rank);
52  MPI_Comm_size( comm, &_size);
53  }
54  }
int _rank
Definition: IM_Reader.h:305
double _alpha
Definition: IM_Reader.h:304
int _size
Definition: IM_Reader.h:305

Member Function Documentation

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

Definition at line 185 of file IM_Reader.h.

References MAXLEN.

Referenced by read_mesh(), read_pane_coors(), read_pane_elems(), read_pane_ij(), read_pane_mixed(), and read_pane_uns().

185  {
186  char accpet[]={'0','1','2','3','4','5','6','7','8','9',
187  '.','+','-','e','E'};
188 
189  do {
190  if ( is.eof()) {
191  std::cerr << "Error: Unexpected EOF" << std::endl;
192  exit(-1);
193  }
194  is.getline( str, MAXLEN);
195  } while ( str[0]=='#' || strpbrk( str,accpet)==NULL);
196  }

Here is the caller graph for this function:

bool isfinite ( double  x)
inlineprivate

Definition at line 41 of file IM_Reader.h.

Referenced by read_pane_coors().

41 { return x>-HUGE_VAL && x<HUGE_VAL; }
void int int REAL * x
Definition: read.cpp:74

Here is the caller graph for this function:

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

Definition at line 102 of file IM_Reader.h.

References _rank, _size, buf, COM_get_window_handle(), COM_new_window(), get_nextline(), i, is_local(), n, read_pane_ij(), read_pane_mixed(), and read_pane_uns().

Referenced by main(), and read_winmesh().

103  {
104  std::ifstream is( fname);
105  if ( is == NULL) {
106  std::cerr << "Error: Could not open file " << fname << std::endl;
107  exit(-1);
108  }
109 
110  // Create the window if not yet exist
111  int h=COM_get_window_handle(wname.c_str());
112  if ( h<=0) COM_new_window( wname.c_str());
113 
114  std::cout << "Reading file " << fname << std::endl;
115 
116  get_nextline( is, buf);
117  int num_panes, mesh_type;
118  char t;
119 
120  std::sscanf( buf, "%d%c%d", &num_panes, &t, &mesh_type);
121  if ( num_panes<=0) {
122  std::cerr << "Error: The number of panes must be positive." << std::endl;
123  exit(-1);
124  }
125 
126  int n=0;
127  switch (mesh_type) {
128  case 2: // Structured mesh
129  for ( int i=0; i<num_panes; ++i) {
130  get_nextline( is, buf);
131  int pid;
132  std::sscanf( buf, "%d", &pid);
133  if ( pid<=0) {
134  std::cerr << "Error: Found nonpositive pane id " << pid << std::endl;
135  exit(-1);
136  }
137 
138  bool local=(!is_local) || is_local( pid, _rank, _size);
139  n+=local;
140  read_pane_ij( is, wname, pid, local);
141  }
142  break;
143  case 3: // Unstrured mesh with 3-node triangles
144  case 4: // Unstrured mesh with 4-node quadrilaterals
145  case 6: // Unstrured mesh with 6-node triangles
146  for ( int i=0; i<num_panes; ++i) {
147  get_nextline( is, buf);
148  int pid;
149  std::sscanf( buf, "%d", &pid);
150  if ( pid<=0) {
151  std::cerr << "Error: Found nonpositive pane id " << pid << std::endl;
152  exit(-1);
153  }
154 
155  bool local=(!is_local) || is_local( pid, _rank, _size);
156  n+=local;
157  read_pane_uns( is, wname, pid, mesh_type, local);
158  }
159  break;
160  case 5: // Mixed mesh with 3-node triangles and 4-node quadrilaterals
161  for ( int i=0; i<num_panes; ++i) {
162  get_nextline( is, buf);
163  int pid;
164  std::sscanf( buf, "%d", &pid);
165  if ( pid<=0) {
166  std::cerr << "Error: Found nonpositive pane id " << pid << std::endl;
167  exit(-1);
168  }
169 
170  bool local=(!is_local) || is_local( pid, _rank, _size);
171  n+=local;
172  read_pane_mixed( is, wname, pid, local);
173  }
174  break;
175  default:
176  std::cerr << "Error: File: " << fname
177  << " has unknown mesh type" << mesh_type << std::endl;
178  exit(-1);
179  }
180  std::cout << "Finished reading file " << fname << std::endl;
181  return n;
182  }
void get_nextline(std::istream &is, char *str)
Definition: IM_Reader.h:185
int _rank
Definition: IM_Reader.h:305
void read_pane_mixed(std::istream &is, const std::string &wname, int pid, bool local)
Definition: IM_Reader.h:286
bool is_local(int pid, int comm_rank, int comm_size)
char buf[MAXLEN+1]
Definition: IM_Reader.h:303
blockLoc i
Definition: read.cpp:79
const NT & n
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
int _size
Definition: IM_Reader.h:305
void read_pane_uns(std::istream &is, const std::string &wname, int pid, int nodes_per_elem, bool local)
Definition: IM_Reader.h:270
void read_pane_ij(std::istream &is, const std::string &wname, int pid, bool local)
Definition: IM_Reader.h:255

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  pid,
int  n,
bool  local 
)
inlineprivate

Definition at line 199 of file IM_Reader.h.

References _alpha, buf, COM_allocate_array(), COM_set_size(), get_nextline(), i, isfinite(), and n.

Referenced by read_pane_ij(), read_pane_mixed(), and read_pane_uns().

200  {
201  SURF::Point_3<double> *coors=NULL;
202 
203  if ( local) {
204  COM_set_size( (wname+".nc").c_str(), pid, n);
205  COM_allocate_array( (wname+".nc").c_str(), pid, &(void*&)coors);
206  }
207 
208  for ( int i=0; i<n; ++i) {
209  get_nextline( is, buf);
210  if ( local) {
211  std::sscanf( buf, "%lf %lf %lf", &coors[i][0], &coors[i][1], &coors[i][2]);
212  if (!isfinite( coors[i][0]) || !isfinite(coors[i][1]) ||
213  !isfinite( coors[i][2])) {
214  std::cerr << "Error: Got invalid coordinates " << coors[i]
215  << " for node " << i+1 << " on pane " << pid
216  << " of window " << wname << std::endl;
217  exit(-1);
218  }
219  }
220  }
221 
222  if ( local && _alpha!=1.)
223  for ( int i=0; i<n; ++i) {
224  coors[i][0]*=_alpha; coors[i][1]*=_alpha; coors[i][2]*=_alpha;
225  }
226  }
bool isfinite(double x)
Definition: IM_Reader.h:41
void get_nextline(std::istream &is, char *str)
Definition: IM_Reader.h:185
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: IM_Reader.h:303
blockLoc i
Definition: read.cpp:79
double _alpha
Definition: IM_Reader.h:304
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

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  pid,
int  num_elems,
int  nodes_per_elem,
bool  local 
)
inlineprivate

Definition at line 229 of file IM_Reader.h.

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

Referenced by read_pane_mixed(), and read_pane_uns().

230  {
231  int *elems;
232 
233  const char *types[] = {".:t3:", ".:q4:", "", ".:t6:"};
234  if (local) {
235  COM_set_size( (wname+types[nodes_per_elem-3]).c_str(), pid, num_elems);
236  COM_allocate_array( (wname+types[nodes_per_elem-3]).c_str(),
237  pid, &(void*&)elems);
238  }
239 
240  for ( int i=0; i<num_elems; ++i) {
241  get_nextline( is, buf);
242  if (local) {
243  int *p = &elems[i*nodes_per_elem];
244  switch ( nodes_per_elem) {
245  case 3: std::sscanf( buf, "%d %d %d", p, p+1, p+2); break;
246  case 4: std::sscanf( buf, "%d %d %d %d", p, p+1, p+2, p+3); break;
247  case 6: std::sscanf( buf, "%d %d %d %d %d %d", p, p+1, p+2, p+3, p+4, p+5); break;
248  default: assert(false); abort();
249  }
250  }
251  }
252  }
void get_nextline(std::istream &is, char *str)
Definition: IM_Reader.h:185
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: IM_Reader.h:303
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_ij ( std::istream &  is,
const std::string &  wname,
int  pid,
bool  local 
)
inlineprivate

Definition at line 255 of file IM_Reader.h.

References buf, COM_set_array(), get_nextline(), and read_pane_coors().

Referenced by read_mesh().

256  {
257  get_nextline( is, buf);
258  int dims[2];
259  std::sscanf( buf, "%d %d", &dims[0], &dims[1]);
260  if ( dims[0]<0 && dims[1]<0) {
261  std::cerr << "Error: Negative mesh dimension " << std::endl;
262  exit(-1);
263  }
264 
265  COM_set_array( (wname+".:st2:").c_str(), pid, dims);
266  read_pane_coors( is, wname, pid, dims[0]*dims[1], local);
267  }
void get_nextline(std::istream &is, char *str)
Definition: IM_Reader.h:185
void read_pane_coors(std::istream &is, const std::string &wname, int pid, int n, bool local)
Definition: IM_Reader.h:199
char buf[MAXLEN+1]
Definition: IM_Reader.h:303
void COM_set_array(const char *wa_str, int pane_id, void *addr, int strd=0, int cap=0)
Associates an array with an attribute for a specific pane.
Definition: roccom_c++.h:156

Here is the call graph for this function:

Here is the caller graph for this function:

void read_pane_mixed ( std::istream &  is,
const std::string &  wname,
int  pid,
bool  local 
)
inlineprivate

Definition at line 286 of file IM_Reader.h.

References buf, get_nextline(), num_nodes, read_pane_coors(), and read_pane_elems().

Referenced by read_mesh().

287  {
288  int num_nodes, num_tris, num_quads;
289  get_nextline( is, buf);
290  std::sscanf( buf, "%d %d %d", &num_nodes, &num_tris, &num_quads);
291  if ( num_nodes<0 && num_tris<0 || num_quads<0) {
292  std::cerr << "Error: Negative node or element size" << std::endl;
293  exit(-1);
294  }
295 
296  read_pane_coors( is, wname, pid, num_nodes, local);
297  read_pane_elems( is, wname, pid, num_tris, 3, local);
298  read_pane_elems( is, wname, pid, num_quads, 4, local);
299  }
void get_nextline(std::istream &is, char *str)
Definition: IM_Reader.h:185
void read_pane_coors(std::istream &is, const std::string &wname, int pid, int n, bool local)
Definition: IM_Reader.h:199
void read_pane_elems(std::istream &is, const std::string &wname, int pid, int num_elems, int nodes_per_elem, bool local)
Definition: IM_Reader.h:229
const int num_nodes
Definition: ex1.C:96
char buf[MAXLEN+1]
Definition: IM_Reader.h:303

Here is the call graph for this function:

Here is the caller graph for this function:

void read_pane_uns ( std::istream &  is,
const std::string &  wname,
int  pid,
int  nodes_per_elem,
bool  local 
)
inlineprivate

Definition at line 270 of file IM_Reader.h.

References buf, get_nextline(), num_nodes, read_pane_coors(), and read_pane_elems().

Referenced by read_mesh().

271  {
272  int num_nodes, num_elmes;
273 
274  get_nextline( is, buf);
275  std::sscanf( buf, "%d %d", &num_nodes, &num_elmes);
276  if ( num_nodes<0 || num_elmes<0) {
277  std::cerr << "Error: Negative node or element size" << std::endl;
278  exit(-1);
279  }
280 
281  read_pane_coors( is, wname, pid, num_nodes, local);
282  read_pane_elems( is, wname, pid, num_elmes, nodes_per_elem, local);
283  }
void get_nextline(std::istream &is, char *str)
Definition: IM_Reader.h:185
void read_pane_coors(std::istream &is, const std::string &wname, int pid, int n, bool local)
Definition: IM_Reader.h:199
void read_pane_elems(std::istream &is, const std::string &wname, int pid, int num_elems, int nodes_per_elem, bool local)
Definition: IM_Reader.h:229
const int num_nodes
Definition: ex1.C:96
char buf[MAXLEN+1]
Definition: IM_Reader.h:303

Here is the call graph for this function:

Here is the caller graph for this function:

int read_winmesh ( const char *  fname,
const std::string &  wname,
bool  del = true 
)
inline

Definition at line 58 of file IM_Reader.h.

References COM_call_function(), COM_delete_attribute(), COM_get_attribute_handle(), COM_get_function_handle(), COM_get_panes(), COM_LOAD_MODULE_STATIC_DYNAMIC, COM_resize_array(), COM_UNLOAD_MODULE_STATIC_DYNAMIC, and read_mesh().

Referenced by main(), and read_in_mesh().

59  {
60 
61  const char *lastdot=std::strrchr( fname, '.');
62  if ( lastdot && (std::strcmp( lastdot, ".hdf")==0 ||
63  std::strcmp( lastdot, ".cgns")==0 ||
64  std::strcmp( lastdot, ".txt")==0)) {
65  // Read in HDF format
67 
68  int IN_read;
69  if ( std::strcmp( lastdot, ".hdf") == 0 ||
70  std::strcmp( lastdot, ".cgns") == 0)
71  IN_read = COM_get_function_handle( "IN.read_window");
72  else
73  IN_read = COM_get_function_handle( "IN.read_by_control_file");
74 
75  COM_call_function( IN_read, fname, wname.c_str());
76 
77  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
78  int mesh_hdl = COM_get_attribute_handle((wname+".mesh").c_str());
79  COM_call_function( IN_obtain, &mesh_hdl, &mesh_hdl);
81 
82  // Change the memory layout to contiguous.
83  COM_resize_array( (wname+".mesh").c_str(), 0, NULL, 0);
84 
85  if ( del) {
86  // Delete all attributes and leave alone the mesh.
87  COM_delete_attribute( (wname+".atts").c_str());
88  }
89 
90  int npanes; COM_get_panes( wname.c_str(), &npanes, NULL);
91  return npanes;
92  }
93  else if (!lastdot || std::strcmp( lastdot, ".im")) {
94  std::cerr << "Unknown file format with suffix " << lastdot << std::endl;
95  return -1;
96  }
97  return read_mesh( fname, wname, NULL);
98  }
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void COM_delete_attribute(const char *wa_str)
Delete an existing attribute.
Definition: roccom_c++.h:128
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
int read_mesh(const char *fname, const std::string &wname, Func_ptr is_local)
Definition: IM_Reader.h:102
Definition: Rocin.h:64
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
Definition: roccom_c++.h:350
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
void COM_resize_array(const char *wa_str, int pane_id=0, void **addr=NULL, int strd=-1, int cap=0)
Resize an attribute on a specific pane and return the address by setting addr.
Definition: roccom_c++.h:200
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

double _alpha
private

Definition at line 304 of file IM_Reader.h.

Referenced by read_pane_coors().

int _rank
private

Definition at line 305 of file IM_Reader.h.

Referenced by IM_Reader(), and read_mesh().

int _size
private

Definition at line 305 of file IM_Reader.h.

Referenced by IM_Reader(), and read_mesh().

char buf[MAXLEN+1]
private

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