MOAB: Mesh Oriented datABase  (version 5.5.0)
scdseq_timing.cpp File Reference
#include "ScdVertexSeq.hpp"
#include "ScdElementSeq.hpp"
#include "EntitySequenceManager.hpp"
#include "EntitySequence.hpp"
#include "moab/Core.hpp"
#include "moab/ReadUtilIface.hpp"
#include <iostream>
#include <ctime>
+ Include dependency graph for scdseq_timing.cpp:

Go to the source code of this file.

Functions

int create_3dtri_3_sequences (Core *gMB, const int intervals, EntityHandle *vstart, EntityHandle *estart)
 
int create_3dtri_ucd_sequences (Core *gMB, const int intervals, EntityHandle *vstart, EntityHandle *estart)
 
void print_time ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ create_3dtri_3_sequences()

int create_3dtri_3_sequences ( Core gMB,
const int  intervals,
EntityHandle vstart,
EntityHandle estart 
)

Definition at line 176 of file scdseq_timing.cpp.

177 {
178  // create 3 brick esequences arranged such that the all share a common (tri-valent) edge;
179  // orient each region similarly to the 2dtri_3_esequences test problem, swept into 3d in the
180  // positive k direction. This direction is divided into intervals intervals
181  //
182  // intervals and intervals controls the i and j intervals in region 0, intervals follows from
183  // that; intervals divides the k axis
184 
185  // input is 4 interval settings controlling the 4 degrees of freedom on the interfacesp
186  int errors = 0;
187 
188  ScdVertexSeq* vseq[3];
189  ScdElementSeq* eseq[3];
190 
191  // set vseq parametric spaces directly from intervals-4
192  // use 0-based parameterization on vseq's just for fun, which means we'll have to transform into
193  // eseq system
194  HomCoord vseq0_minmax[2] = { HomCoord( 0, 0, 0 ), HomCoord( intervals, intervals, intervals ) };
195  HomCoord vseq1_minmax[2] = { HomCoord( 0, 0, 0 ), HomCoord( intervals - 1, intervals, intervals ) };
196  HomCoord vseq2_minmax[2] = { HomCoord( 0, 0, 0 ), HomCoord( intervals - 1, intervals - 1, intervals ) };
197 
198  // get the seq manager from gMB
199  EntitySequenceManager* seq_mgr = gMB->sequence_manager();
200 
201  // create three vertex sequences
202  EntitySequence* dum_seq;
203  vseq[0] = vseq[1] = vseq[2] = NULL;
204 
205  // first vertex sequence
206  ErrorCode result =
207  seq_mgr->create_scd_sequence( vseq0_minmax[0], vseq0_minmax[1], MBVERTEX, 1, vstart[0], dum_seq );
208  if( NULL != dum_seq ) vseq[0] = dynamic_cast< ScdVertexSeq* >( dum_seq );
209  assert( MB_FAILURE != result && vstart[0] != 0 && dum_seq != NULL && vseq[0] != NULL );
210 
211  // second vertex sequence
212  result = seq_mgr->create_scd_sequence( vseq1_minmax[0], vseq1_minmax[1], MBVERTEX, 1, vstart[1], dum_seq );
213  if( NULL != dum_seq ) vseq[1] = dynamic_cast< ScdVertexSeq* >( dum_seq );
214  assert( MB_FAILURE != result && vstart[1] != 0 && dum_seq != NULL && vseq[1] != NULL );
215 
216  // third vertex sequence
217  result = seq_mgr->create_scd_sequence( vseq2_minmax[0], vseq2_minmax[1], MBVERTEX, 1, vstart[2], dum_seq );
218  if( NULL != dum_seq ) vseq[2] = dynamic_cast< ScdVertexSeq* >( dum_seq );
219  assert( MB_FAILURE != result && vstart[2] != 0 && dum_seq != NULL && vseq[2] != NULL );
220 
221  // now create the three element sequences
222 
223  // set eseq parametric spaces directly from intervals-4
224  // use 0-based parameterization on eseq's just for fun, which means we'll have to transform into
225  // eseq system
226  HomCoord eseq0_minmax[2] = { HomCoord( 0, 0, 0 ), HomCoord( intervals, intervals, intervals ) };
227  HomCoord eseq1_minmax[2] = { HomCoord( 0, 0, 0 ), HomCoord( intervals, intervals, intervals ) };
228  HomCoord eseq2_minmax[2] = { HomCoord( 0, 0, 0 ), HomCoord( intervals, intervals, intervals ) };
229 
230  eseq[0] = eseq[1] = eseq[2] = NULL;
231 
232  // create the first element sequence
233  result = seq_mgr->create_scd_sequence( eseq0_minmax[0], eseq0_minmax[1], MBHEX, 1, estart[0], dum_seq );
234  if( NULL != dum_seq ) eseq[0] = dynamic_cast< ScdElementSeq* >( dum_seq );
235  assert( MB_FAILURE != result && estart[0] != 0 && dum_seq != NULL && eseq[0] != NULL );
236 
237  // only need to add one vseq to this, unity transform
238  result = eseq[0]->add_vsequence( vseq[0],
239  // trick: if I know it's going to be unity, just input
240  // 3 sets of equivalent points
241  vseq0_minmax[0], vseq0_minmax[0], vseq0_minmax[0], vseq0_minmax[0],
242  vseq0_minmax[0], vseq0_minmax[0] );
243 
244  if( MB_SUCCESS != result )
245  {
246  std::cout << "Couldn't add first vsequence to first element sequence in tri-composite 3d eseq." << std::endl;
247  errors++;
248  }
249 
250  // create the second element sequence
251  result = seq_mgr->create_scd_sequence( eseq1_minmax[0], eseq1_minmax[1], MBHEX, 1, estart[1], dum_seq );
252  if( NULL != dum_seq ) eseq[1] = dynamic_cast< ScdElementSeq* >( dum_seq );
253  assert( MB_FAILURE != result && estart[1] != 0 && dum_seq != NULL && eseq[1] != NULL );
254 
255  // add shared side from first vseq to this eseq, with bb to get just the face
256  result = eseq[1]->add_vsequence( vseq[0],
257  // p1: origin in both systems
258  vseq0_minmax[0], eseq0_minmax[0],
259  // p2: one unit along the shared line (i in one, j in other)
260  vseq0_minmax[0] + HomCoord::unitv[0], eseq0_minmax[0] + HomCoord::unitv[1],
261  // p3: arbitrary
262  vseq0_minmax[0], eseq0_minmax[0],
263  // set bb such that it's the jmin side of vseq
264  true, eseq[1]->min_params(),
265  HomCoord( eseq[1]->min_params().i(), eseq[1]->max_params().j(),
266  eseq[1]->max_params().k() ) );
267  if( MB_SUCCESS != result )
268  {
269  std::cout << "Couldn't add shared vsequence to second element sequence in tri-composite 3d eseq." << std::endl;
270  errors++;
271  }
272 
273  // add second vseq to this eseq, with different orientation but all of it (no bb input)
274  result =
275  eseq[1]->add_vsequence( vseq[1],
276  // p1: origin/i+1 (vseq/eseq)
277  vseq1_minmax[0], eseq1_minmax[0] + HomCoord::unitv[0],
278  // p2: j+1 from p1
279  vseq1_minmax[0] + HomCoord::unitv[1],
280  eseq1_minmax[0] + HomCoord::unitv[0] + HomCoord::unitv[1],
281  // p3: i+1 from p1
282  vseq1_minmax[0] + HomCoord::unitv[0], eseq[1]->min_params() + HomCoord::unitv[0] * 2 );
283  if( MB_SUCCESS != result )
284  {
285  std::cout << "Couldn't add second vseq to second element sequence in tri-composite 3d eseq." << std::endl;
286  errors++;
287  }
288 
289  // create the third element sequence
290  result = seq_mgr->create_scd_sequence( eseq2_minmax[0], eseq2_minmax[1], MBHEX, 1, estart[2], dum_seq );
291  if( NULL != dum_seq ) eseq[2] = dynamic_cast< ScdElementSeq* >( dum_seq );
292  assert( MB_FAILURE != result && estart[2] != 0 && dum_seq != NULL && eseq[2] != NULL );
293 
294  // add shared side from second vseq to this eseq
295  result = eseq[2]->add_vsequence(
296  vseq[1],
297  // p1: origin/j+1 (vseq/eseq)
298  vseq1_minmax[0], eseq[2]->min_params() + HomCoord::unitv[1],
299  // p2: i+1/j+2 (vseq/eseq)
300  vseq1_minmax[0] + HomCoord::unitv[0], eseq[2]->min_params() + HomCoord::unitv[1] * 2,
301  // p3: arbitrary
302  vseq1_minmax[0], eseq[2]->min_params() + HomCoord::unitv[1],
303  // bb input such that we only get one side of eseq parameter space
304  true, eseq[2]->min_params() + HomCoord::unitv[1],
305  HomCoord( eseq[2]->min_params().i(), eseq[2]->max_params().j(), eseq[2]->max_params().k() ) );
306  if( MB_SUCCESS != result )
307  {
308  std::cout << "Couldn't add shared vsequence to third element sequence in tri-composite 3d eseq." << std::endl;
309  errors++;
310  }
311 
312  // add shared side from first vseq to this eseq
313  result = eseq[2]->add_vsequence( vseq[0],
314  // p1: origin/origin
315  vseq1_minmax[0], eseq2_minmax[0],
316  // p2: j+1/i+1
317  vseq1_minmax[0] + HomCoord::unitv[1], eseq2_minmax[0] + HomCoord::unitv[0],
318  // p3: arbitrary
319  vseq1_minmax[0], eseq2_minmax[0],
320  // bb input such that we only get one side of eseq parameter space
321  true, eseq2_minmax[0],
322  HomCoord( eseq2_minmax[1].i(), eseq2_minmax[0].j(), eseq2_minmax[1].k() ) );
323  if( MB_SUCCESS != result )
324  {
325  std::cout << "Couldn't add left shared vsequence to third element sequence in "
326  "tri-composite 3d eseq."
327  << std::endl;
328  errors++;
329  }
330 
331  // add third vseq to this eseq
332  result = eseq[2]->add_vsequence( vseq[2],
333  // p1: origin/i+1,j+1
334  vseq2_minmax[0], eseq[2]->min_params() + HomCoord::unitv[0] + HomCoord::unitv[1],
335  // p2: i+1 from p1
336  vseq2_minmax[0] + HomCoord::unitv[0],
337  eseq[2]->min_params() + HomCoord::unitv[0] * 2 + HomCoord::unitv[1],
338  // p3: j+1 from p1
339  vseq2_minmax[0] + HomCoord::unitv[1],
340  eseq[2]->min_params() + HomCoord::unitv[0] + HomCoord::unitv[1] * 2 );
341  if( MB_SUCCESS != result )
342  {
343  std::cout << "Couldn't add third vseq to third element sequence in tri-composite 3d eseq." << std::endl;
344  errors++;
345  }
346 
347  return errors;
348 }

References ErrorCode, gMB, MB_SUCCESS, MBHEX, MBVERTEX, and moab::HomCoord::unitv.

Referenced by main().

◆ create_3dtri_ucd_sequences()

int create_3dtri_ucd_sequences ( Core gMB,
const int  intervals,
EntityHandle vstart,
EntityHandle estart 
)

Definition at line 350 of file scdseq_timing.cpp.

351 {
352 
353  ReadUtilIface* readMeshIface;
354  gMB->query_interface( readMeshIface );
355 
356  int num_elements = intervals * intervals * intervals;
357  int num_verts = ( intervals + 1 ) * ( intervals + 1 ) * ( intervals + 1 );
358 
359  std::vector< double* > arrays;
360  for( int i = 0; i < 3; i++ )
361  {
362  readMeshIface->get_node_coords( 3, num_verts, MB_START_ID, vstart[i], arrays );
363  arrays.clear();
364  }
365 
366  EntityHandle* conn[3];
367 
368  // allocate 3 arrays to initialize connectivity data
369  for( int i = 0; i < 3; i++ )
370  {
371  readMeshIface->get_element_connect( num_elements, 8, MBHEX, 1, estart[i], conn[i] );
372 
373  // now, initialize connectivity data to what it should be; just fudge for now
374  for( int j = 0; j < num_elements * 8; j++ )
375  conn[i][j] = vstart[i];
376  }
377 
378  return 0;
379 }

References moab::ReadUtilIface::get_element_connect(), moab::ReadUtilIface::get_node_coords(), gMB, MB_START_ID, MBHEX, and moab::Interface::query_interface().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 46 of file scdseq_timing.cpp.

47 {
48  int errors = 0;
49 
50  // first we need to make a new Core
51  Core* gMB = new Core();
52 
53  // get the intervals
54  if( argc < 2 )
55  {
56  std::cout << "Usage: <scdseq_timing> <#intervals> " << std::endl
57  << " where #intervals is the number of intervals on each side of each cube." << std::endl;
58  return 0;
59  }
60 
61  int intervals;
62  sscanf( argv[1], "%d", &intervals );
63 
64  char do_option[8];
65 
66  bool do_scd = true, do_ucd = true;
67 
68  if( argc > 2 )
69  {
70  sscanf( argv[2], "%s", do_option );
71  if( do_option[0] == 'u' )
72  do_scd = false;
73  else if( do_option[0] == 's' )
74  do_ucd = false;
75  else
76  {
77  std::cout << "Didn't understand input; doing both scd and ucd." << std::endl;
78  }
79  }
80 
81  EntityHandle estart[3], vstart[3];
82  int total_elements = intervals * intervals * intervals;
83  std::vector< EntityHandle > connect;
84  ErrorCode result;
85  clock_t start, stop;
86  float time;
87  char inp[1];
88 
89  // wait for input to get memory reading
90  std::cout << "Hit any key and return to continue...";
91  std::cin >> inp;
92  std::cout << std::endl;
93 
94  if( do_scd )
95  {
96 
97  // create structured mesh
98  errors = create_3dtri_3_sequences( gMB, intervals, vstart, estart );
99  if( errors != 0 )
100  {
101  std::cout << "Problem creating structured sequences." << std::endl;
102  return errors;
103  }
104 
105  // get connectivity
106 
107  start = clock();
108  for( int j = 0; j < 3; j++ )
109  {
110  for( int i = 0; i < total_elements; i++ )
111  {
112  result = gMB->get_connectivity( estart[j] + i, connect );
113  if( MB_SUCCESS != result ) break;
114  connect.clear();
115  }
116  }
117  stop = clock();
118  time = static_cast< float >( stop - start ) / CLOCKS_PER_SEC;
119 
120  std::cout << "Time to get connectivity for scd mesh of " << 3 * total_elements << " elements: " << time
121  << " seconds." << std::endl;
122 
123  print_time();
124  // wait for input to get memory reading
125  std::cout << "Hit any key and return to continue...";
126  std::cin >> inp;
127  std::cout << std::endl;
128 
129  // destroy this mesh
130  delete gMB;
131  }
132 
133  if( do_ucd )
134  {
135 
136  // now do the same thing, only unstructured
137  gMB = new Core();
138 
139  // create the elements
140  errors = create_3dtri_ucd_sequences( gMB, intervals, vstart, estart );
141  if( errors != 0 )
142  {
143  std::cout << "Problem creating unstructured sequences." << std::endl;
144  return errors;
145  }
146 
147  // get connectivity
148  std::vector< EntityHandle > connect;
149  start = clock();
150  for( int j = 0; j < 3; j++ )
151  {
152  for( int i = 0; i < total_elements; i++ )
153  {
154  result = gMB->get_connectivity( estart[j] + i, connect );
155  if( MB_SUCCESS != result ) break;
156  connect.clear();
157  }
158  }
159  stop = clock();
160  time = static_cast< float >( stop - start ) / CLOCKS_PER_SEC;
161 
162  std::cout << "Time to get connectivity for ucd mesh of " << 3 * total_elements << " elements: " << time
163  << " seconds." << std::endl;
164 
165  print_time();
166  // wait for input to get memory reading
167  std::cout << "Hit any key and return to continue...";
168  std::cin >> inp;
169  std::cout << std::endl;
170 
171  // destroy this mesh
172  delete gMB;
173  }
174 }

References create_3dtri_3_sequences(), create_3dtri_ucd_sequences(), ErrorCode, moab::Interface::get_connectivity(), gMB, MB_SUCCESS, and print_time().

◆ print_time()

void print_time ( )

Definition at line 381 of file scdseq_timing.cpp.

382 {
383  /*
384  struct rusage r_usage;
385  float utime, stime;
386  getrusage(RUSAGE_SELF, &r_usage);
387 
388  if (r_usage.ru_maxrss == 0) {
389  // this machine doesn't return rss - try going to /proc
390  // print the file name to open
391  char file_str[4096], dum_str[4096];
392  int file_ptr = -1, file_len;
393  file_ptr = open("/proc/self/stat", O_RDONLY);
394  file_len = read(file_ptr, file_str, sizeof(file_str)-1);
395  if (file_len == 0) return;
396  close(file_ptr);
397  file_str[file_len] = '\0';
398  // read the preceeding fields and the ones we really want...
399  int dum_int;
400  unsigned int dum_uint, vm_size, rss;
401  static int page_size = getpagesize();
402  int num_fields = sscanf(file_str,
403  "%d " // pid
404  "%s " // comm
405  "%c " // state
406  "%d %d %d %d %d " // ppid, pgrp, session, tty, tpgid
407  "%u %u %u %u %u " // flags, minflt, cminflt, majflt, cmajflt
408  "%d %d %d %d %d %d " // utime, stime, cutime, cstime, counter,
409  priority
410  "%u %u " // timeout, itrealvalue
411  "%d " // starttime
412  "%u %u", // vsize, rss
413  &dum_int,
414  dum_str,
415  dum_str,
416  &dum_int, &dum_int, &dum_int, &dum_int, &dum_int,
417  &dum_uint, &dum_uint, &dum_uint, &dum_uint, &dum_uint,
418  &dum_int, &dum_int, &dum_int, &dum_int, &dum_int, &dum_int,
419  &dum_uint, &dum_uint,
420  &dum_int,
421  &vm_size, &rss);
422  if (num_fields == 24) {
423  r_usage.ru_maxrss = rss/page_size;
424  r_usage.ru_idrss = vm_size/page_size;
425  }
426  }
427  utime = (float)r_usage.ru_utime.tv_sec +
428  ((float)r_usage.ru_utime.tv_usec/1.e6);
429  stime = (float)r_usage.ru_stime.tv_sec +
430  ((float)r_usage.ru_stime.tv_usec/1.e6);
431  static int pagesize = getpagesize();
432 
433  std::cout << "Execution time = " << utime+stime << ", max RSS = "
434  << r_usage.ru_maxrss*pagesize << " bytes." << std::endl;
435 
436  */
437 }

Referenced by main().