Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Window.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Window.C,v 1.25 2008/12/06 08:43:25 mtcampbe Exp $
24 
29 /* Author: Xiangmin Jiao
30  * Created: Jan. 10, 2001
31  * Last modified: May 9, 2001
32  */
33 
34 #include <iostream>
35 #include <cstdlib>
36 #include <cstdio>
37 #include "Window.h"
38 #include "roccom_assertion.h"
39 
40 COM_BEGIN_NAME_SPACE
41 
42 Window::Window( const std::string &s, MPI_Comm c)
43  : _dummy( this, 0), _name( s), _last_id(COM_NUM_KEYWORDS),
44  _comm(c), _status( STATUS_NOCHANGE)
45 {
46  // Insert keywords into _attr_map
47  for ( int i=0; i<COM_NUM_KEYWORDS; ++i) {
49  if ( !Attribute::is_digit(a->name()[0])) _attr_map[ a->name()] = a;
50  }
51 }
52 
54 {
55  for ( Pane_map::iterator it=_pane_map.begin(); it!=_pane_map.end(); ++it)
56  delete it->second;
57 }
58 
59 void Window::set_function( const std::string &fname,
60  Func_ptr func,
61  const std::string &intents,
62  const COM_Type *types,
63  Attribute *a,
64  bool is_f90) throw(COM_exception) {
65  if ( _func_map.find( fname) != _func_map.end())
67  (_name+"."+fname,Window::init_function));
68 
69  _func_map[fname] = Function( func, intents, types, a, is_f90);
70 }
71 
72 void Window::set_function( const std::string &fname,
73  Member_func_ptr func,
74  const std::string &intents,
75  const COM_Type *types,
76  Attribute *a,
77  bool) throw(COM_exception) {
78  if ( _func_map.find( fname) != _func_map.end())
79  throw COM_exception(COM_WARN_DUP_FUNC, append_frame
80  (_name+"."+fname,Window::init_function));
81 
82  _func_map[fname] = Function( func, intents, types, a);
83 }
84 
86 new_attribute( const std::string &aname, const char loc, const int type,
87  int ncomp, const std::string &unit) throw(COM_exception)
88 {
89  // Special handing for connectivity
90  if ( Connectivity::is_element_name( aname) ||
91  Attribute::is_digit(aname[0]))
93  (_name+"."+aname,Window::new_attribute));
94  if ( ncomp<=0)
96  (_name+"."+aname,Window::new_attribute));
97 
98  if ( loc != 'w' && loc != 'p' && loc != 'e' && loc != 'n' && loc != 'c')
100  (_name+"."+aname,Window::new_attribute));
101 
102  if ( type<COM_MIN_TYPEID || type > COM_MAX_TYPEID)
104  (_name+"."+aname,Window::new_attribute));
105 
106  // Redefine an attribute if it pre-exists, but ncomp cannot be increased.
107  Attr_map::const_iterator it = _attr_map.find( aname);
108 
109  if ( it != _attr_map.end() && ncomp > it->second->size_of_components()) {
110  COM_assertion_msg( it->second->id()>=COM_NUM_KEYWORDS,
111  "Cannot increase size of keywords");
112  delete_attribute( it->first);
113  it = _attr_map.end();
114  }
115 
116  int id = (it==_attr_map.end())?_last_id:it->second->id();
117 
118  // Insert the object into both the set and the map.
119  Attribute *a = ((Pane_friend&)_dummy).
120  new_attribute( aname, id, loc, type, ncomp, unit);
121  _attr_map[aname] = a;
122 
123  // Propagete onto all existing panes.
124  for (Pane_map::iterator it=_pane_map.begin(); it!=_pane_map.end(); ++it) {
125  Pane_friend *pn = (Pane_friend*)it->second;
126  pn->new_attribute( aname, id, loc, type, ncomp, unit);
127  }
128 
129  // Update last available id
130  if ( it == _attr_map.end()) _last_id = id+ncomp+(ncomp>1);
131 
132  if ( _status == STATUS_NOCHANGE) _status = STATUS_CHANGED;
133  return a;
134 }
135 
136 void Window::
137 delete_attribute( const std::string &aname) throw(COM_exception)
138 {
139  Attr_map::iterator it = _attr_map.find( aname);
140  if ( it == _attr_map.end())
142  (_name+"."+aname,Window::delete_attribute));
143 
144  Attribute *attr = it->second;
145  int id = attr->id(), ncomp=attr->size_of_components();
146 
147  if ( id < COM_NUM_KEYWORDS && id != COM_ATTS)
149  (_name+"."+aname,Window::delete_attribute));
150 
151  // Remove the object from both the set
152  ((Pane_friend&)_dummy).delete_attribute( id);
153 
154  // Remove from all panes.
155  for (Pane_map::iterator it=_pane_map.begin(); it!=_pane_map.end(); ++it) {
156  Pane_friend *pn = (Pane_friend*)it->second;
157  pn->delete_attribute( id);
158  }
159 
160  // Update last id
161  if (id != COM_ATTS) {
162  _attr_map.erase( it); // Remove from _attr_map
163  if ( _last_id == id + ncomp+(ncomp>1)) {
164  _last_id = id;
165  if ( _status==STATUS_NOCHANGE) _status = STATUS_CHANGED;
166  }
167  else
168  _status = STATUS_SHRUNK;
169  }
170  else if (_last_id>COM_NUM_KEYWORDS) {
171  _attr_map.clear();
172  for ( int i=0; i<COM_NUM_KEYWORDS; ++i) {
173  Attribute *a = _dummy.attribute(i);
174  if ( !Attribute::is_digit(a->name()[0])) _attr_map[ a->name()] = a;
175  }
176 
177  _status = STATUS_CHANGED;
178  _last_id = COM_NUM_KEYWORDS;
179  }
180 }
181 
182 void Window::set_size( const std::string &aname, int pid,
183  int nitems, int ng) throw( COM_exception)
184 {
185  if ( Connectivity::is_element_name( aname)) {
186  Pane_friend &pn = (Pane_friend&)pane(pid,true);
187  Connectivity *con = pn.connectivity( aname,true);
188  pn.set_size( con, nitems, ng);
189  }
190  else {
191  Attribute *a = attribute(aname);
192 
193  if ( a == NULL)
195  (_name+"."+aname,Window::set_size));
196 
197  if ( a->is_windowed())
198  ((Pane_friend&)_dummy).set_size( a, nitems, ng);
199  else if ( pid==0) {
200  // Loop through the panes to set the sizes.
201  for (Pane_map::iterator it=_pane_map.begin(), iend=_pane_map.end();
202  it != iend; ++it) {
203  ((Pane_friend*)it->second)->set_size
204  ( it->second->attribute( a->id()), nitems, ng);
205  }
206  }
207  else
208  ((Pane_friend&)pane(pid,true)).set_size( a, nitems, ng);
209  }
210 }
211 
212 void Window::set_array(const std::string &aname, const int pane_id,
213  void *addr, int strd, int cap, bool is_const)
214  throw(COM_exception)
215 {
216  if ( Connectivity::is_element_name( aname)) {
217  Pane &pn = pane(pane_id,true);
218  Connectivity *con = ((Pane_friend&)pn).connectivity( aname,true);
219 
220  if ( con==NULL)
222  (name()+"."+aname,Window::set_array));
223 
224  reinit_conn( con, is_const?Pane::OP_SET_CONST:Pane::OP_SET,
225  &(int*&)addr, strd, cap);
226  }
227  else {
228  Attribute *a = pane( pane_id,true).attribute( aname);
229  if ( a==NULL)
231  (name()+"."+aname,Window::set_array));
232 
233  reinit_attr( a, is_const?Pane::OP_SET_CONST:Pane::OP_SET,
234  &addr, strd, cap);
235  }
236 }
237 
238 void Window::alloc_array(const std::string &aname, const int pane_id,
239  void **addr, int strd, int cap) throw(COM_exception)
240 {
241  if ( Connectivity::is_element_name( aname)) {
242  Pane &pn = pane(pane_id,true);
243  Connectivity *con = ((Pane_friend&)pn).connectivity( aname);
244 
245  if ( con==NULL)
247  (name()+"."+aname,Window::alloc_array));
248 
249  reinit_conn( con, Pane::OP_ALLOC, (int**)addr, strd, cap);
250  }
251  else {
252  Attribute *a = pane( pane_id,true).attribute( aname);
253 
254  if ( a==NULL)
256  (name()+"."+aname,Window::alloc_array));
257  reinit_attr( a, Pane::OP_ALLOC, addr, strd, cap);
258  }
259 }
260 
261 void Window::resize_array(const std::string &aname, const int pane_id,
262  void **addr, int strd, int cap) throw(COM_exception)
263 {
264  if ( Connectivity::is_element_name( aname)) {
265  Pane &pn = pane(pane_id,true);
266  Connectivity *con = ((Pane_friend&)pn).connectivity( aname);
267 
268  if ( con==NULL)
270  (name()+"."+aname,Window::resize_array));
271 
272  reinit_conn( con, Pane::OP_RESIZE, (int**)addr, strd, cap);
273  }
274  else {
275  Attribute *a = pane( pane_id,true).attribute( aname);
276 
277  if ( a==NULL)
279  (name()+"."+aname,Window::resize_array));
280  reinit_attr( a, Pane::OP_RESIZE, addr, strd, cap);
281  }
282 }
283 
284 void Window::append_array( const std::string &aname, const int pane_id,
285  const void *val, int v_strd, int v_size) throw(COM_exception)
286 {
288  "append_array supports only window and pane attributes");
289 
290  Attribute *a = pane( pane_id,true).attribute( aname);
291 
292  if ( a==NULL)
294  (name()+"."+aname,Window::append_array));
295  try {
296  // Set size to 0 if not yet set.
297  if ( !a->size_set()) a->set_size(0);
298  // resize the target attribute.
299  reinit_attr( a, Pane::OP_RESIZE, NULL, a->stride(),
300  a->size_of_items()+v_size);
301  }
302  catch ( COM_exception ex) {
304  throw ex;
305  }
306 
307  // copy the array to the back of the target array
308  a->append_array( val, v_strd, v_size);
309 }
310 
311 void Window::dealloc_array( const std::string &aname,
312  const int pane_id) throw(COM_exception)
313 {
314  if ( Connectivity::is_element_name( aname)) {
315  Pane &pn = pane(pane_id);
316  Connectivity *con = ((Pane_friend&)pn).connectivity( aname);
317 
318  if ( con==NULL)
320  (name()+"."+aname,Window::dealloc_array));
321 
322  reinit_conn( con, Pane::OP_DEALLOC);
323  }
324  else {
325  Attribute *a = pane( pane_id).attribute( aname);
326 
327  if ( a==NULL)
329  (name()+"."+aname,Window::dealloc_array));
330  reinit_attr( a, Pane::OP_DEALLOC);
331  }
332 }
333 
334 Attribute *Window::inherit( Attribute *from, const std::string &aname,
335  int mode, bool withghost,
336  const Attribute *cond, int val)
337  throw(COM_exception)
338 {
339  Attribute *a = ((Pane_friend&)_dummy).inherit(from, aname, mode, withghost);
340  if ( from->is_windowed()) return a;
341 
342  // Copy the panes
343  Pane_map &ps = from->window()->_pane_map;
344 
345  bool with_conn = from->id()==COM_CONN || from->id()==COM_MESH ||
346  from->id()==COM_PMESH || from->id()==COM_ALL;
347 
348  bool insert_pane = (mode != Pane::INHERIT_COPY) && with_conn;
349 
350  if ( with_conn && aname.size() && from->name() != aname)
352  (from->fullname()+" and " +aname,
353  Window::inherit));
354 
355  if ( cond && cond->window()!=from->window()) {
357  (from->fullname()+" and "+cond->fullname(),
358  Window::inherit));
359  }
360 
361  for ( Pane_map::iterator ppit = ps.begin(); ppit!=ps.end(); ++ppit) {
362  Pane *ppn=ppit->second;
363  const int *cnd = NULL;
364  if ( cond) {
365  const Attribute *cond_pn = ppn->attribute( cond->id());
366  cnd = (const int*)cond_pn->pointer();
367  }
368 
369  // Inherit the pane if the condition was set to an variable (cnd!=NULL),
370  // or set to to pane ID (cnd==NULL && val!=0), or not set.
371  if ( !cond && (val==0 || val==ppn->id()) || cnd && *cnd == val) {
372  // Create new panes only when we are inheriting the mesh.
373  Pane_friend *pn;
374  if ( insert_pane)
375  pn = (Pane_friend*)( &pane( ppit->first, true));
376  else {
377  Pane_map::iterator it = _pane_map.find( ppit->first);
378  pn = ( it!=_pane_map.end())?(Pane_friend*)(it->second):NULL;
379  }
380 
381  if ( pn)
382  pn->inherit( ppn->attribute( from->id()), aname, mode, withghost);
383  }
384  }
385  return a;
386 }
387 
388 void Window::init_done( bool pane_changed) throw(COM_exception) {
389  // Loop through the attributes.
390  if ( _status == STATUS_SHRUNK) {
391  int max_id=0;
392  for (Attr_map::iterator it=_attr_map.begin(); it!=_attr_map.end(); ++it) {
393  int id = it->second->id(), ncomp=it->second->size_of_components();
394  max_id = std::max( max_id, id+ncomp+(ncomp>1));
395  }
396  if (max_id < _last_id) _last_id = max_id;
397  }
398 
399  int npanes = _pane_map.size();
400  std::vector< int> pane_ids; pane_ids.reserve(npanes);
401 
402  for (Pane_map::iterator it=_pane_map.begin(); it!=_pane_map.end(); ++it) {
403  it->second->init_done();
404  pane_ids.push_back( it->second->id());
405  }
406 
407  _status = STATUS_NOCHANGE;
408 
409  if ( !pane_changed) {
410  if ( npanes>int(_pane_map.size())) {
412  (_name,Window::init_done));
413  }
414  return;
415  }
416 
417  // communicate pane mapping
418  int flag; MPI_Initialized( &flag);
419  if ( _comm == MPI_COMM_NULL) flag = 0;
420 
421  // Compute proc_map
422  int nprocs;
423  if ( flag) MPI_Comm_size( _comm, &nprocs); else nprocs = 1;
424 
425  // Obtain the number of panes.
426  std::vector<int> npanes_all(nprocs);
427  if ( flag)
428  MPI_Allgather( &npanes, 1, MPI_INT, &npanes_all[0], 1, MPI_INT, _comm);
429  else
430  npanes_all[0] = npanes;
431 
432  std::vector<int> disps(nprocs+1);
433  disps[0]=0;
434  for ( int i=0; i<nprocs; ++i) disps[i+1] = disps[i]+npanes_all[i];
435 
436  std::vector<int> pane_ids_all( disps[nprocs]);
437  if ( flag)
438  MPI_Allgatherv( &pane_ids[0], npanes, MPI_INT, &pane_ids_all[0],
439  &npanes_all[0], &disps[0], MPI_INT, _comm);
440  else
441  pane_ids_all = pane_ids;
442 
443  // Build process map
444  _proc_map.clear();
445  for ( int p=0; p<nprocs; ++p) {
446  for ( int j=disps[p], jn=disps[p+1]; j<jn; ++j)
447  _proc_map[ pane_ids_all[j]] = p;
448  }
449 }
450 
451 
452 int Window::owner_rank( const int pane_id) const {
453  COM_assertion_msg( _pane_map.size()<=_proc_map.size(),
454  "init_done must be called before owner_rank is called");
455 
456  Proc_map::const_iterator it = _proc_map.find( pane_id);
457  if ( it==_proc_map.end()) return -1;
458  else return it->second;
459 }
460 
462 get_attribute( const std::string &aname, char *loc, int *type,
463  int *ncomp, std::string *unit) const throw(COM_exception) {
464  // Special handing for connectivity tables
465  if ( Connectivity::is_element_name( aname)) {
466  // Set the arguments if not NULL.
467  if ( loc) *loc = 'p';
468  if ( type) *type = COM_INT;
469  // Return the number of nodes.
470  if ( ncomp) *ncomp = Connectivity::get_size_info(aname)
472  if ( unit) *unit = "";
473  return NULL; // A connectivity is not defined in Window scope.
474  }
475  else {
476  // Obtain reference to the attribute
477  Attr_map::const_iterator it = _attr_map.find( aname);
478  if ( it == _attr_map.end())
480  (_name+"."+aname,Window::get_attribute));
481  Attribute &a = *it->second;
482 
483  // Set the arguments if not NULL.
484  if ( loc) *loc = a.location();
485  if ( type) *type = a.data_type();
486  if ( ncomp) *ncomp = a.size_of_components();
487  if ( unit) *unit = a.unit();
488  return &a;
489  }
490 }
491 
492 template <class Attr>
493 void get_size_common( const Attr *a, int pid, int *nitem, int *ng)
494  throw( COM_exception)
495 {
496  if ( pid==0 && a->location() != 'w')
498  ( a->fullname(), Window::get_size));
499 
500  if ( nitem) *nitem = a->size_of_items();
501  if ( ng) *ng = a->size_of_ghost_items();
502 }
503 
504 void Window::
505 get_size( const std::string &aname, int pid,
506  int *nitem, int *ng) const throw( COM_exception) {
507  const Pane_friend *pn;
508  try { pn = &(Pane_friend&)pane(pid); }
509  catch ( COM_exception ex) {
511  throw ex;
512  }
513 
514  // Special handing for connectivity
515  if ( Connectivity::is_element_name( aname)) {
516  // Get the corresponding attribute object.
517  const COM::Connectivity *conn = pn->connectivity( aname);
518  if ( conn==NULL)
520  ( name()+"."+aname, Window::get_size));
521  get_size_common( conn, pid, nitem, ng);
522  }
523  else {
524  // Get the corresponding attribute object.
525  const COM::Attribute *attr = pn->attribute( aname);
526  if ( attr==NULL)
528  ( name()+"."+aname, Window::get_size));
529 
530  get_size_common( attr, pid, nitem, ng);
531  }
532 }
533 
534 int Window::
535 get_status( const std::string &aname, int pid) const throw( COM_exception) {
536  // If aname is empty, then check the status of the pane.
537  if ( aname.empty()) {
538  Pane_map::const_iterator pit = _pane_map.find( pid);
539  if ( pit == _pane_map.end()) return -1;
540  else return 0;
541  }
542 
543  const Pane_friend *pn;
544  try { pn = &(Pane_friend&)pane(pid); }
545  catch ( COM_exception ex) {
547  throw ex;
548  }
549 
550  // Special handing for connectivity
551  if ( Connectivity::is_element_name( aname)) {
552  // Get the corresponding attribute object.
553  const COM::Connectivity *conn = pn->connectivity( aname);
554  if ( conn==NULL) return -1;
555  else return conn->status();
556  }
557  else {
558  // Get the corresponding attribute object.
559  const COM::Attribute *attr = pn->attribute( aname);
560  if ( attr==NULL) return -1;
561  else return attr->status();
562  }
563 }
564 
565 void Window::
566 get_parent( const std::string &aname, int pid,
567  std::string &parent) const throw( COM_exception) {
568 
569  const Pane_friend *pn;
570  try {
571  pn = &(Pane_friend&)pane(pid);
572 
573  // Special handing for connectivity
574  if ( Connectivity::is_element_name( aname)) {
575  // Get the corresponding attribute object.
576  const COM::Connectivity *conn = pn->connectivity( aname);
577  if ( conn==NULL)
579  (name()+"."+aname,Window::get_parent));
580 
581  conn = conn->parent();
582  if ( conn==NULL) parent.clear();
583  else parent = conn->fullname();
584  }
585  else {
586  // Get the corresponding attribute object.
587  const COM::Attribute *attr = pn->attribute( aname);
588  if ( attr==NULL)
590  (name()+"."+aname,Window::get_parent));
591 
592  if ( attr==NULL) parent.clear();
593  else parent = attr->fullname();
594  }
595  } catch ( COM_exception ex) {
597  throw ex;
598  }
599 }
600 
601 template <class Attr>
602 void get_array_common( const Attr *a, int pid,
604  int *strd, int *cap, bool is_const) throw(COM_exception) {
605  if ( !is_const && a->is_const() )
607  (a->fullname(),Window::get_array));
608 
609  if ( pid==0 && a->location() != 'w')
611  ( a->fullname(), Window::get_array));
612 
613  addr.ptr = (void*)(a->pointer());
614  if ( addr.dim==1) {
615  addr.n1 = a->capacity()*a->stride();
616  }
617  else if ( addr.dim == 2) {
618  if ( a->stride()>=a->size_of_components()) {
619  addr.n1 = a->stride();
620  addr.n2 = a->capacity();
621  }
622  else {
623  addr.n1 = a->capacity();
624  addr.n2 = a->size_of_components();
625  }
626  }
627  else {
628  // Scalars must have capacity 1!
629  if ( addr.dim==0 && (a->capacity()!=1 || a->size_of_components()!=1))
631  (a->fullname(),Window::get_array));
632  if ( addr.dim>2)
634  (a->fullname(),Window::get_array));
635  }
636 
637  if ( cap) *cap = a->capacity();
638  if ( strd) *strd = a->stride();
639 }
640 
641 void Window::get_array(const std::string &aname, const int pane_id,
642  Pointer_descriptor &addr,
643  int *strd, int *cap, bool is_const) throw(COM_exception)
644 {
645  Pane_friend *pn;
646  try { pn = &(Pane_friend&)pane(pane_id); }
647  catch ( COM_exception ex) {
649  throw ex;
650  }
651 
652  if ( Connectivity::is_element_name( aname)) {
653  // Define as const reference to avoid exception.
654  const Connectivity *con=pn->connectivity( aname);
655 
656  if ( con==NULL)
658  (name()+"."+aname,Window::get_array));
659 
660  get_array_common( con, pane_id, addr, strd, cap, is_const);
661  }
662  else {
663  // Define as const reference to avoid exception.
664  const Attribute *a = pn->attribute( aname);
665 
666  if ( a==NULL)
668  (name()+"."+aname,Window::get_array));
669  get_array_common( a, pane_id, addr, strd, cap, is_const);
670  }
671 }
672 
673 template <class Attr>
674 inline void copy_array_common( const Attr *a, int pid, void *val, int v_strd,
675  int v_size, int offset) throw(COM_exception) {
676 
677  if ( pid==0 && a->location() != 'w')
679  ( a->fullname(), Window::copy_size));
680 
681  const_cast<Attr*>(a)->copy_array( val, v_strd, v_size,
683 }
684 
685 void Window::copy_array(const std::string &aname, const int pane_id,
686  void *val, int v_strd, int v_size,
687  int offset) const throw(COM_exception)
688 {
689  const Pane_friend *pn;
690  try { pn = &(Pane_friend&)pane(pane_id); }
691  catch ( COM_exception ex) {
693  throw ex;
694  }
695 
696  if ( Connectivity::is_element_name( aname)) {
697  const Connectivity *conn = pn->connectivity( aname);
698  if ( conn == NULL)
700  (name()+"."+aname, Window::copy_array));
701 
702  copy_array_common( conn, pane_id,
703  val, v_strd, v_size, offset);
704  }
705  else {
706  const Attribute *attr = pn->attribute( aname);
707  if ( attr == NULL)
709  (name()+"."+aname, Window::copy_array));
710 
711  copy_array_common( attr, pane_id,
712  val, v_strd, v_size, offset);
713  }
714 }
715 
716 void Window::
717 reinit_attr( Attribute *a, OP_Init op, void **addr,
718  int strd, int cap) throw (COM_exception)
719 {
720  int aid = a->id();
721 
722  if ( a->location()=='w')
723  // Initialize window attributes in dummy pane
724  ((Pane_friend&)_dummy).reinit_attr( aid, op, addr, strd, cap);
725  else {
726  // Initialize other attributes in regular panes
727  Pane *pn = a->pane();
728  if ( pn->id()>0)
729  ((Pane_friend*)pn)->reinit_attr( aid, op, addr, strd, cap);
730  else {
731  if ( aid == COM_ALL || aid == COM_ATTS)
732  ((Pane_friend&)_dummy).reinit_attr( aid, op, addr, strd, cap);
733 
735  // Loop through the panes to initialize each pane
736  for (Pane_map::iterator it=_pane_map.begin(), iend=_pane_map.end();
737  it != iend; ++it) {
738  ((Pane_friend*)it->second)->reinit_attr( aid, op, NULL, strd, cap);
739  }
740  if ( addr) *addr= NULL; // Do not return any address.
741  return;
742  }
743  }
744 }
745 
746 void Window::
747 reinit_conn( Connectivity *con, OP_Init op, int **addr,
748  int strd, int cap) throw (COM_exception)
749 {
750 
751  Pane *pn = con->pane();
752  if ( pn->id()==0) {
754  // Loop through the panes to proecess the connectivity in each pane.
755  for (Pane_map::iterator it=_pane_map.begin(), iend=_pane_map.end();
756  it != iend; ++it) {
757  Connectivity *c=((Pane_friend*)it->second)->connectivity( con->name());
758  if ( c && !c->parent())
759  ((Pane_friend*)it->second)->reinit_conn( c, op, NULL, strd, cap);
760  }
761  if ( addr) *addr= NULL; // Do not return address.
762  return;
763  }
764  else {
765  ((Pane_friend*)pn)->reinit_conn( con, op, addr, strd, cap);
766  }
767 }
768 
769 Pane &Window::pane( const int pid, bool insert) throw( COM_exception)
770 {
771  if ( pid==0) return _dummy;
772 
773  COM_assertion( pid>0);
774  Pane_map::iterator pit = _pane_map.find( pid);
775  if ( pit == _pane_map.end()) {
776  if (insert)
777  return *(_pane_map[pid] = new Pane( &_dummy, pid));
778  else {
779  // print missing pane ID and known IDs in the pane map
780  std::cerr << "No such Pane ID: " << pid << std::endl;
781  std::cerr << "While the known Pane IDs are: [ ";
782  Pane_map::iterator pit;
783  for ( pit=_pane_map.begin(); pit != _pane_map.end(); ++pit)
784  std::cerr << pit->first << " ";
785  std::cerr << "]" << std::endl;
787  (_name,Window::pane));
788  }
789  }
790 
791  return *pit->second;
792 }
793 
794 const Pane &Window::pane( const int pid) const throw( COM_exception)
795 {
796  if ( pid==0) return _dummy;
797 
798  COM_assertion( pid>0);
799  Pane_map::const_iterator pit = _pane_map.find( pid);
800  if ( pit == _pane_map.end()) {
802  (_name,Window::pane));
803  }
804 
805  return *pit->second;
806 }
807 
808 // Obtain the panes of the window on a give process.
809 void Window::panes( std::vector<int> &pane_ids, int rank)
810 {
811 
812  pane_ids.clear();
813 
814  if ( rank == -2) {
815  pane_ids.reserve( _pane_map.size());
816 
817  for ( Pane_map::iterator it=_pane_map.begin(); it != _pane_map.end(); ++it)
818  pane_ids.push_back( it->first);
819  }
820  else {
822  "Can only obtain panes after calling window_init_done");
823 
824  std::map<int,int>::const_iterator it, iend;
825  for ( it=_proc_map.begin(), iend=_proc_map.end(); it!= iend; ++it) {
826  if ( rank==-1 || it->second == rank)
827  pane_ids.push_back( it->first);
828  }
829  }
830 }
831 
832 // Obtain all the panes of the window.
833 void Window::panes( std::vector<Pane*> &ps)
834 {
835  ps.reserve( _pane_map.size());
836  Pane_map::iterator it=_pane_map.begin();
837  for ( ; it != _pane_map.end(); ++it)
838  ps.push_back( it->second);
839 }
840 
842 attribute( const std::string &aname) throw(COM_exception)
843 {
844  if ( !Attribute::is_digit(aname[0])) {
845  Attr_map::iterator it = _attr_map.find( aname);
846  if ( it == _attr_map.end())
847  return NULL;
848  else
849  return it->second;
850  }
851  else {
852  std::string::size_type start = aname.find( '-');
853  if ( start == aname.npos)
855  (_name+"."+aname,Window::attribute));
856 
857  Attr_map::iterator it = _attr_map.find( &aname[start+1]);
858 
859  if ( it != _attr_map.end()) {
860  Attribute *att = it->second;
861  if ( att->size_of_components()>1) {
862  // Get the subcomponent
863  int i = std::atoi( aname.c_str());
864 
865  if ( i<=0 || i>att->size_of_components())
867  (_name+"."+aname,Window::attribute));
868  return attribute( att->id()+i);
869  }
870  }
871 
872  return NULL;
873  }
874 }
875 
877 function( const std::string &fname)
878 {
879  Func_map::iterator it = _func_map.find( fname);
880  if ( it == _func_map.end())
881  return NULL;
882  else
883  return &it->second;
884 }
885 
886 COM_END_NAME_SPACE
887 
888 
889 
890 
891 
892 
void inherit(Attribute *a, bool clone, bool withghost, int depth=0)
Inherit from parent. If depth&gt;0, then the procedure is for the subcomponents.
Definition: Attribute.C:426
int COM_Type
Indices for derived data types.
Definition: roccom_basic.h:122
A Pane object contains a mesh, pane attribute, and field variables.
Definition: Pane.h:43
bool size_set() const
Returns whether the size for the attribute has been set.
Definition: Attribute.C:99
void delete_attribute(const std::string &aname)
Delete an existing Attribute object.
Definition: Window.C:137
void alloc_array(const std::string &aname, const int pane_id, void **addr, int strd=0, int cap=0)
Allocate memory for an attribute for a specific pane and set addr to the address. ...
Definition: Window.C:238
A Function object corresponds to a function member of a window.
Definition: Function.h:49
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
An Attribute object is a data member of a window.
Definition: Attribute.h:51
int get_status(const std::string &aname, int pane_id) const
Get the status of an attribute or pane.
Definition: Window.C:535
void set_array(const std::string &aname, const int pane_id, void *addr, int strd=0, int cap=0, bool is_const=false)
Associate an array with an attribute for a specific pane.
Definition: Window.C:212
static bool is_digit(char c)
Definition: Attribute.h:264
#define COM_assertion_msg(EX, msg)
double s
Definition: blastest.C:80
Connectivity * parent()
Parent attribute being used.
Definition: Connectivity.h:108
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
void copy_array(const std::string &aname, const int pane_id, void *val, int v_strd=0, int v_size=0, int offset=0) const
Copy an attribute on a specific pane into a given array.
Definition: Window.C:685
bool is_windowed() const
Checks whether the attribute is associated with the window.
Definition: Attribute.h:188
void get_size(const std::string &aname, int pane_id, int *nitems, int *ng) const
Get the sizes of an attribute for a specific pane.
Definition: Window.C:505
int _status
Status of the window.
Definition: Window.h:389
void set_size(Attribute *a, int nitems, int ng)
Set the size of an attribute.
Definition: Pane.C:630
int status() const
Obtain the status of the attribute.
Definition: Attribute.h:240
std::map< int, Pane * > Pane_map
Definition: Window.h:45
void get_array_common(const Attr *a, int pid, Window::Pointer_descriptor &addr, int *strd, int *cap, bool is_const)
Definition: Window.C:602
Function * function(const std::string &f)
Obtain the function pointer from its name.
Definition: Window.C:877
void delete_attribute(int id)
Delete an existing attribute with given id.
Definition: Pane.C:240
real *8 function offset(vNorm, x2, y2, z2)
Definition: PlaneNorm.f90:211
void resize_array(const std::string &aname, const int pane_id, void **addr, int strd=-1, int cap=0)
Resize memory for an attribute for a specific pane and set addr to the address.
Definition: Window.C:261
const Window * window() const
Obtain a constant pointer to the parent window of the attribute.
Definition: Attribute.C:80
Shorter_size location() const
Obtain the location of the attribute.
Definition: Attribute.h:186
static const int * get_size_info(const std::string &aname)
Obtain the size info of pre-defined connectivity.
Definition: Connectivity.C:234
Encapsulates the states of an exception.
Attribute * attribute(const std::string &a)
Obtain the attribute from given name.
Definition: Pane.C:148
const std::string & unit() const
Obtain the unit of the attribute.
Definition: Attribute.h:200
void get_array(const std::string &aname, const int pane_id, Pointer_descriptor &addr, int *strd=NULL, int *cap=NULL, bool is_const=false)
Get the address associated with an attribute for a specific pane.
Definition: Window.C:641
std::string msg
Error message.
Attribute * get_attribute(const std::string &aname, char *l, int *t, int *n, std::string *u) const
Get the meta-information about an attribute.
Definition: Window.C:462
const void * pointer() const
Obtain a constant pointer to the physical address.
Definition: Attribute.h:150
void reinit_conn(Connectivity *con, OP_Init op, int **addr=NULL, int strd=0, int cap=0)
Template implementation for setting (op==OP_SET or OP_SET_CONST), allocating (op==OP_ALLOC), resizing (op==OP_RESIZE) and deallocating (op==OP_DEALLOC) an array for a specific connectivity table.
Definition: Window.C:747
Proc_map _proc_map
Map from pane ID to process ranks.
Definition: Window.h:383
Attr_map _attr_map
Map from attribute names to their metadata.
Definition: Window.h:379
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE knode iend
Attribute * new_attribute(const std::string &aname, const char loc, const int type, int ncomp, const std::string &unit)
Create a new Attribute object with given properties.
Definition: Window.C:86
void get_size_common(const Attr *a, int pid, int *nitem, int *ng)
Definition: Window.C:493
void copy_array_common(const Attr *a, int pid, void *val, int v_strd, int v_size, int offset)
Definition: Window.C:674
void(* Func_ptr)()
Pointer of functions.
Definition: roccom_basic.h:123
const std::string & name() const
Obtain the name of the attribute.
Definition: Attribute.h:113
blockLoc i
Definition: read.cpp:79
void reinit_attr(int aid, OP_Init op, void **addr, int strd, int cap)
Definition: Pane.C:265
Window(const std::string &name, MPI_Comm c)
Create a window with a given name and MPI communicator.
Definition: Window.C:42
static bool is_element_name(const std::string &aname)
Definition: Connectivity.h:228
void init_done(bool pane_changed=true)
Perform some final checking of the window.
Definition: Window.C:388
void dealloc_array(const std::string &aname, const int pane_id=0)
Deallocate memory for an attribute for a specific pane if allocated by Roccom.
Definition: Window.C:311
void reinit_attr(Attribute *attr, OP_Init op, void **addr=NULL, int strd=0, int cap=0)
Implementation for setting (op==OP_SET or OP_SET_CONST), allocating (op==OP_ALLOC), resizing (op==OP_RESIZE) and deallocating (op==OP_DEALLOC) an array for a specific attribute.
Definition: Window.C:717
This file contains a set of routines for error assertion.
void get_parent(const std::string &aname, int pane_id, std::string &name) const
Get the parent name of an attribute and load into name.
Definition: Window.C:566
int owner_rank(const int pane_id) const
Obtain the process rank that owns a given pane.
Definition: Window.C:452
int stride() const
Obtain the stride of the attribute in base datatype.
Definition: Attribute.h:233
void set_size(int nitems, int ngitems=0)
Set the size of items and ghost items.
Definition: Attribute.C:191
std::string _name
Name of the window.
Definition: Window.h:378
void append_array(const std::string &aname, const int pane_id, const void *val, int v_strd, int v_size)
Append the given array to the end of the attribute on a specific pane, and reallocate memory for the ...
Definition: Window.C:284
Attribute * attribute(const std::string &a)
Obtain a pointer to the attribute metadata from its name.
Definition: Window.C:842
#define append_frame(s, frame)
Macro for appending the information about the given frame to the string s.
Pane & pane(const int pane_id, bool insert=false)
Find the pane with given ID. If not found, insert a pane with given ID.
Definition: Window.C:769
j indices j
Definition: Indexing.h:6
unsigned long id(const Leda_like_handle &x)
Definition: Handle.h:107
Connectivity * connectivity(Size i)
Obtain the connectivity table containing the element with the given ID.
Definition: Pane.C:99
Pane _dummy
Dummy pane.
Definition: Window.h:377
void set_size(const std::string &aname, int pane_id, int nitems, int ng=0)
Set the sizes of an attribute for a specific pane.
Definition: Window.C:182
Func_map _func_map
Map from function names to their metadata.
Definition: Window.h:381
Attribute * new_attribute(const std::string &aname, int aid, const char loc, const int type, int ncomp, const std::string &unit)
Definition: Pane.C:178
Attribute * inherit(Attribute *from, const std::string &aname, int mode, bool withghost)
Inherit an attribute from another pane onto the current pane:
Definition: Pane.C:451
static int rank
Definition: advectest.C:66
virtual ~Window()
Destructor.
Definition: Window.C:53
Pane_map _pane_map
Map from pane ID to their metadata.
Definition: Window.h:382
COM_Type data_type() const
Obtain the data type of each component of the attribute.
Definition: Attribute.h:197
int id() const
Obtain the id (or index) of the attribute.
Definition: Attribute.h:120
void panes(std::vector< int > &ps, int rank=-2)
Obtain all the local panes of the window.
Definition: Window.C:809
OP_Init
Definition: Pane.h:48
Attribute * inherit(Attribute *from, const std::string &aname, int inherit_mode, bool withghost, const Attribute *cond, int val)
Inherit the attributes of another window with a different name.
Definition: Window.C:334
Contains the prototypes for the Window object.
Encapsulates an element-connectivity of a mesh.
Definition: Connectivity.h:41
int id() const
Get the ID of the pane.
Definition: Pane.h:96
int size_of_items() const
Obtain the number of items in the attribute.
Definition: Attribute.C:111
void set_function(const std::string &fname, Func_ptr func, const std::string &intents, const COM_Type *types, Attribute *a, bool if_f90=false)
Initialize a Function record.
Definition: Window.C:59
int size_of_components() const
Obtain the number of components in the attribute.
Definition: Attribute.h:203
void append_array(const void *from, int strd, int nitem)
Definition: Attribute.C:334