Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ex3.C File Reference
#include "roccom.h"
#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include "commpi.h"
Include dependency graph for ex3.C:

Go to the source code of this file.

Functions

 COM_EXTERN_MODULE (Rocface)
 
 COM_EXTERN_MODULE (Rocout)
 
int read_obj (std::istream &is, vector< double > &coors, vector< int > &elems)
 
void read_ij (std::istream &is, vector< double > &coors, int dims[2])
 
int main (int argc, char *argv[])
 

Function Documentation

COM_EXTERN_MODULE ( Rocface  )
COM_EXTERN_MODULE ( Rocout  )
int main ( int  argc,
char *  argv[] 
)

Definition at line 44 of file ex3.C.

References COM_call_function(), COM_delete_window(), COM_DOUBLE, COM_finalize(), COM_get_attribute_handle(), COM_get_function_handle(), COM_init(), COM_LOAD_MODULE_STATIC_DYNAMIC, COM_new_attribute(), COM_new_window(), COM_print_profile(), COM_set_array(), COM_set_profiling(), COM_set_size(), COM_set_verbose(), COM_window_init_done(), i, MPI_COMM_WORLD, read_ij(), and read_obj().

44  {
45  COM_init( &argc, &argv);
46 
47  if ( argc < 7) {
48  std::cout << "Usage: " << argv[0]
49  << " <str_prefix> <str_num_blocks> <str_suffix> "
50  << " <tri_prefix> <tri_num_blocks> <tri_suffix>" << std::endl;
51  exit(-1);
52  }
53 
54  COM_set_verbose( 1);
56 
57  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
58 
59  MPI_Comm comm = MPI_COMM_WORLD;
60  const int comm_rank=0;
61  const int comm_size=1;
62 
63  const char *str_prefix = argv[1];
64  const int str_num_blocks=atoi(argv[2]);
65  const char *str_suffix = argv[3];
66  assert( str_num_blocks <= 5);
67 
68  const char *tri_prefix = argv[4];
69  const int tri_num_blocks=atoi(argv[5]);
70  const char *tri_suffix = argv[6];
71  assert( tri_num_blocks <= 5);
72 
73  std::vector<double> str_mesh_coors[5];
74  std::vector<double> str_mesh_nd[5];
75  std::vector<double> str_mesh_npress[5];
76  std::vector<double> str_mesh_fpress[5];
77  int dims[5][2];
78 
79  for ( int i=0; i<str_num_blocks; ++i) {
80  if ( i%comm_size==comm_rank) {
81  char fname[100];
82  std::sprintf( fname, "%s%d%s", str_prefix, i+1, str_suffix);
83  std::ifstream is( fname);
84  assert( is != NULL);
85  read_ij( is, str_mesh_coors[i], dims[i]);
86 
87  str_mesh_nd[i] = str_mesh_coors[i];
88  str_mesh_npress[i].resize( dims[i][0]*dims[i][1]*3,3);
89  str_mesh_fpress[i].resize( (dims[i][0]-1)*(dims[i][1]-1)*3,3);
90  }
91  }
92 
93  COM_new_window("str");
94 
95  COM_new_attribute("str.coor", 'n', COM_DOUBLE, 3, "m");
96  COM_new_attribute("str.npress", 'n', COM_DOUBLE, 3, "Pa");
97  COM_new_attribute("str.fpress", 'e', COM_DOUBLE, 3, "Pa");
98 
99  for ( int i=0; i<str_num_blocks; ++i) {
100  if ( i%comm_size==comm_rank) {
101  COM_set_array( "str.:st2:", i+1, dims[i]);
102  COM_set_array( "str.nc", i+1, &str_mesh_coors[i][0]);
103 
104  COM_set_array( "str.coor", i+1, &str_mesh_nd[i][0]);
105  COM_set_array( "str.npress", i+1, &str_mesh_npress[i][0]);
106  COM_set_array( "str.fpress", i+1, &str_mesh_fpress[i][0]);
107  }
108  }
109  COM_window_init_done( "str");
110 
111  std::vector<double> tri_mesh_coors[5];
112  std::vector<int> tri_mesh_elems[5];
113  std::vector<double> tri_mesh_nd[5];
114  std::vector<double> tri_mesh_npress[5];
115  std::vector<double> tri_mesh_fpress[5];
116 
117  for ( int i=0; i<tri_num_blocks; ++i) {
118  if ( i%comm_size==comm_rank) {
119  char fname[100];
120  std::sprintf( fname, "%s%d%s", tri_prefix, i+1, tri_suffix);
121  ifstream is( fname); assert( is != NULL);
122  read_obj( is, tri_mesh_coors[i], tri_mesh_elems[i]);
123 
124  tri_mesh_nd[i] = tri_mesh_coors[i];
125  tri_mesh_npress[i].resize( tri_mesh_coors[i].size(),3);
126  tri_mesh_fpress[i].resize( tri_mesh_elems[i].size(),3);
127  }
128  }
129 
130  COM_new_window("tri");
131  COM_new_attribute("tri.coor", 'n', COM_DOUBLE, 3, "m");
132  COM_new_attribute("tri.npress", 'n', COM_DOUBLE, 3, "Pa");
133  COM_new_attribute("tri.fpress", 'e', COM_DOUBLE, 3, "Pa");
134 
135  for ( int i=0; i<tri_num_blocks; ++i) {
136  if ( i%comm_size==comm_rank) {
137  COM_set_size( "tri.nc", i+1, tri_mesh_coors[i].size()/3);
138  COM_set_array( "tri.nc", i+1, &tri_mesh_coors[i][0]);
139  COM_set_size( "tri.:t3:", i+1, tri_mesh_elems[i].size()/3);
140  COM_set_array( "tri.:t3:", i+1, &tri_mesh_elems[i][0]);
141 
142  COM_set_array("tri.coor", i+1, &tri_mesh_nd[i][0]);
143  COM_set_array("tri.npress", i+1, &tri_mesh_npress[i][0]);
144  COM_set_array("tri.fpress", i+1, &tri_mesh_fpress[i][0]);
145  }
146  }
147  COM_window_init_done( "tri");
148 
149  int tri_mesh = COM_get_attribute_handle( "tri.mesh");
150  int str_mesh = COM_get_attribute_handle( "str.mesh");
151  int RFC_clear = COM_get_function_handle( "RFC.clear_overlay");
152  int RFC_write = COM_get_function_handle( "RFC.write_overlay");
153 
154  if ( comm_size == 1) {
155  int RFC_overlay = COM_get_function_handle( "RFC.overlay");
156 
157  COM_call_function( RFC_overlay, &tri_mesh, &str_mesh, &comm);
158  COM_call_function( RFC_write, &tri_mesh, &str_mesh, "tri", "str", "HDF");
159  COM_call_function( RFC_clear, "tri", "str");
160  }
161 
162  int RFC_read = COM_get_function_handle( "RFC.read_overlay");
163  COM_call_function( RFC_read, &tri_mesh, &str_mesh, &comm,
164  "tri", "str", "HDF");
165 
166  char prefix1[100], prefix2[100];
167  std::sprintf(prefix1, "tri_%d", comm_rank);
168  std::sprintf(prefix2, "str_%d", comm_rank);
169 
170  if ( argc>7) {
172  std::sprintf(prefix1, "tri_coor%d", comm_rank);
173  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
174  int OUT_set = COM_get_function_handle( "OUT.set_option");
175  int tri_coor = COM_get_attribute_handle( "tri.coor");
176  int str_coor = COM_get_attribute_handle( "str.coor");
177 
178  COM_call_function( OUT_set, "mode", "w");
179  COM_call_function( OUT_write, prefix1, &tri_coor, "tri", "000");
180  std::sprintf(prefix2, "str_coor%d", comm_rank);
181  COM_call_function( OUT_write, prefix2, &str_coor, "str", "000");
182 
183  int RFC_transfer = COM_get_function_handle( "RFC.least_squares_transfer");
184  COM_call_function( RFC_transfer, &tri_coor, &str_coor);
185  COM_call_function( RFC_transfer, &str_coor, &tri_coor);
186 
187  COM_call_function( OUT_set, "mode", "a");
188  COM_call_function( OUT_write, prefix1, &tri_coor, "tri", "001", "a");
189  COM_call_function( OUT_write, prefix2, &str_coor, "str", "001", "a");
190 
191  int tri_npress = COM_get_attribute_handle( "tri.npress");
192  int str_fpress = COM_get_attribute_handle( "str.fpress");
193  std::sprintf(prefix1, "tri_press%d", comm_rank);
194  std::sprintf(prefix2, "str_press%d", comm_rank);
195 
196  COM_call_function( OUT_set, "mode", "w");
197  COM_call_function( OUT_write, prefix1, &tri_npress, "tri", "000");
198  COM_call_function( OUT_write, prefix2, &str_fpress, "str", "000");
199 
200  int tri_fpress = COM_get_attribute_handle( "tri.fpress");
201  int str_npress = COM_get_attribute_handle( "str.npress");
202  COM_call_function( RFC_transfer, &str_npress, &tri_fpress);
203  COM_call_function( RFC_transfer, &tri_fpress, &str_npress);
204 
205  COM_call_function( OUT_set, "mode", "a");
206  COM_call_function( OUT_write, prefix1, &tri_fpress, "tri", "001", "a");
207  COM_call_function( OUT_write, prefix2, &str_npress, "str", "001", "a");
208  COM_call_function( RFC_clear, "tri", "str");
209  }
210 
211  COM_delete_window( "tri");
212  COM_delete_window( "str");
213 
214  COM_print_profile( "", "");
215 
216  COM_finalize();
217 }
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
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
void COM_set_verbose(int i)
Definition: roccom_c++.h:543
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
int read_obj(std::istream &is, vector< double > &coors, vector< int > &elems)
Definition: meshio.C:39
void COM_finalize()
Definition: roccom_c++.h:59
void COM_print_profile(const char *fname, const char *header)
Definition: roccom_c++.h:557
Definition: Rocout.h:81
blockLoc i
Definition: read.cpp:79
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_set_profiling(int i)
Definition: roccom_c++.h:550
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
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
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
void read_ij(std::istream &is, vector< double > &coors, int dims[2])
Definition: meshio.C:81
void COM_new_attribute(const char *wa_str, const char loc, const int type, int ncomp, const char *unit)
Registering an attribute type.
Definition: roccom_c++.h:118
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428

Here is the call graph for this function:

void read_ij ( std::istream &  is,
vector< double > &  coors,
int  dims[2] 
)

Definition at line 81 of file meshio.C.

References i, MAXLEN, p0, and p1.

Referenced by main().

81  {
82  const int MAXLEN=255;
83  char buf[MAXLEN];
84 
85  do { is.getline( buf, MAXLEN); } while ( buf[0]=='#' && !is.eof());
86  sscanf( buf, "%d %d", &dims[0], &dims[1]);
87 
88  int np=dims[0]*dims[1];
89  // Allocate space for points and faces.
90 
91  // Read in the coordinates
92  for ( int i=0; i<np; ++i) {
93  do { is.getline( buf, MAXLEN); } while ( buf[0]=='#' && !is.eof());
94  double p0, p1, p2;
95  sscanf( buf, "%lf %lf %lf", &p0, &p1, &p2);
96  coors.push_back( p0); coors.push_back( p1); coors.push_back( p2);
97  }
98 }
NT p1
#define MAXLEN
Definition: Coupling.h:41
NT p0
blockLoc i
Definition: read.cpp:79

Here is the caller graph for this function:

int read_obj ( std::istream &  is,
vector< double > &  coors,
vector< int > &  elems 
)

Definition at line 39 of file meshio.C.

Referenced by main().

40  {
41  const int MAXLEN=255;
42  char buf[MAXLEN];
43  int face_type = 3;
44 
45  is.getline( buf, MAXLEN);
46  if ( strncmp( buf, "#OBJ", 4)==0 && !is.eof()) {
47  face_type = buf[4] - '0';
48  assert( face_type == 3 || face_type == 4 || face_type == 6);
49  do { is.getline( buf, MAXLEN); } while ( buf[0]=='#' && !is.eof());
50  }
51  int np=0, nf=0;
52  if ( strcmp( buf, "off")==0 || strcmp( buf, "OFF")==0 )
53  do { is.getline( buf, MAXLEN); } while ( buf[0]=='#' && !is.eof());
54  sscanf( buf, "%d %d", &np, &nf);
55 
56  // Allocate space for points and faces.
57  coors.reserve( np*3); elems.reserve( nf*face_type);
58 
59  // Read in the coordinates
60  for ( int i=0; i<np; ++i) {
61  do { is.getline( buf, MAXLEN); } while ( buf[0]=='#' && !is.eof());
62  double p0, p1, p2;
63  sscanf( buf, "%lf %lf %lf", &p0, &p1, &p2);
64  coors.push_back( p0); coors.push_back( p1); coors.push_back( p2);
65  }
66 
67  // Read in faces
68  vector<int> f( face_type);
69  while( is.peek() == '#' && !is.eof()) is.getline( buf, MAXLEN);
70  for ( int i=0; i<nf; ++i) {
71  for ( int j=0; j<face_type; ++j) {
72  is >> f[j]; assert( f[j] >= 1 && f[j] <= np);
73  elems.push_back( f[j]);
74  }
75  }
76 
77  return face_type;
78 }
NT p1
#define MAXLEN
Definition: Coupling.h:41
NT p0
blockLoc i
Definition: read.cpp:79
j indices j
Definition: Indexing.h:6

Here is the caller graph for this function: