Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Pane.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: Pane.C,v 1.29 2008/12/06 08:43:25 mtcampbe Exp $
24 
25 #include "Pane.h"
26 #include "Window.h"
27 #include "roccom_assertion.h"
28 #include <cstdlib>
29 #include <cstdio>
30 
31 COM_BEGIN_NAME_SPACE
32 
33 Pane::Pane( Window *w, int i) :
34  _window(w), _id(i), _ignore_ghost(false)
35 {
36  _attr_set.resize( COM_NUM_KEYWORDS);
38 
39  for ( int i=0; i<COM_NUM_KEYWORDS; ++i) {
40  // Call constructor in placement form.
41  _attr_set[i] = new (&as[i]) Attribute_friend(this, i);
42  }
43 }
44 
45 Pane::Pane( Pane *p, int id) :
46  _window(p->_window), _id(id), _ignore_ghost(false)
47 {
48  int n = p->_attr_set.size();
49  _attr_set.resize( n, NULL);
50 
51  // First allocate for keywords
53  for ( int i=0; i<COM_NUM_KEYWORDS; ++i) {
54  _attr_set[i] = new (&as[i]) Attribute( this, p->_attr_set[i], "", i);
55  }
56 
57  for ( int i=COM_NUM_KEYWORDS; i<n; ) {
58  Attribute *ap=p->_attr_set[i];
59  if ( ap==NULL || ap->pane()==NULL) { ++i; continue; }
60  int ncomp=ap->size_of_components();
61 
62  // Allocate for attribute and its components
63  as = new Attribute[ncomp+(ncomp>1)];
64 
65  // Call constructor at the attribute and its individual components
66  for ( int k=0, nk=(ncomp==1)?0:ncomp; k<=nk; ++k,++i)
67  _attr_set[i] = new (&as[k]) Attribute( this, &ap[k], "", i);
68 
69  // Inherit window attributes from dummy pane
70  if ( ap->is_windowed())
71  reinterpret_cast<Attribute_friend*>(as)->inherit( ap, INHERIT_USE, true);
72  }
73 }
74 
76  delete [] _attr_set[0]; // Delete all keywords
77 
78  delete_attribute( COM_ATTS); // Delete all user-defined attributes.
79 
80  for ( Size i=0,n=_cnct_set.size(); i<n; ++i)
81  delete _cnct_set[i]; // Delete all connectivity tables.
82 }
83 
84 
86  _attr_set.resize( _window->last_attribute_id()); // Shrink the array.
87 
88  // Loop through the attributes to initialize the unitialized ones to NULL
89  for ( int i=0, s=_attr_set.size(); i<s; ++i) {
90  Attribute *a = _attr_set[i];
91  if ( a==NULL || a->pane()==NULL) continue;
92 
93  if ( a->initialized() && a->size_of_items()>a->capacity())
94  throw COM_exception( COM_ERR_INVALID_CAPACITY,
96  }
97 }
98 
100 {
101  if ( i>size_of_elements()) {
102  // if i is not a valid element ID, it must be one past the last ID
103  COM_assertion( i-1==size_of_elements());
104  return NULL;
105  }
106 
107  // i must be either a valid element ID
108  COM_assertion_msg( i>=1, "ElementID out of bounds");
109 
110  Cnct_set::iterator it=_cnct_set.begin();
111  for ( ; it != _cnct_set.end(); ++it) {
112  Connectivity *c=*it;
113  if ( i>c->index_offset() && i<=c->index_offset()+c->size_of_elements())
114  return c;
115  }
116  return NULL;
117 }
118 
119 
120 Connectivity *Pane::connectivity( const std::string &a,
121  bool insert) throw( COM_exception)
122 {
123  if ( _id == 0) {
125  (_window->name()+"."+a, Pane::connectivity));
126  }
127  Cnct_set::iterator it=_cnct_set.begin();
128  for ( ; it != _cnct_set.end(); ++it) {
129  if ( a==(*it)->name()) return *it;
130  }
131  if ( insert) {
132  const int *size_info=Connectivity::get_size_info(a);
133  if ( size_info) {
134  Connectivity *c = new Connectivity(this, a, -1-int(_cnct_set.size()),
135  size_info);
136  _cnct_set.push_back( c);
137  return _cnct_set.back();
138  }
139  else
141  (_window->name()+"."+a, Pane::connectivity));
142  }
143 
144  return NULL;
145 }
146 
148 attribute( const std::string &a) {
149  Attribute *w_attr = _window->attribute(a);
150  if ( w_attr==NULL) return NULL;
151 
152  return attribute( w_attr->id());
153 }
154 
156 attribute( int i) {
157  if ( (int)_attr_set.size() <= i) return NULL;
158  Attribute *p_attr = _attr_set[ i];
159 
160  if ( p_attr==NULL || p_attr->id () != i) return NULL;
161  return p_attr;
162 }
163 
164 // Obtain all the nonempty attributes of the pane.
165 void Pane::attributes( std::vector<Attribute*> &as) {
166  as.reserve( _attr_set.size()-COM_NUM_KEYWORDS);
167  for ( int i=COM_NUM_KEYWORDS, size=_attr_set.size(); i<size; ++i) {
168  Attribute *a = _attr_set[i];
169  if ( a==NULL || a->pane()==NULL) continue;
170 
171  as.push_back( a);
172  int ncomp = a->size_of_components();
173  if ( ncomp>1) i+=ncomp;
174  }
175 }
176 
178 new_attribute( const std::string &aname, int aid, const char loc,
179  const int type, int ncomp, const std::string &unit)
180  throw(COM_exception)
181 {
182 
183  if ( loc == 'c' && id() != 0) {
184  // check if connectivity table exists, make sure it is not dummy pane
185  std::string::size_type pos = aname.find( ":");
186  std::string conn = aname.substr(pos, aname.size());
187  Connectivity *con = connectivity( conn,false);
188  if (con == NULL)
191  }
192 
193  // Insert the object into both the set and the map.
194  Attribute *atts;
195  if ( aid>=int(_attr_set.size()))
196  atts = new Attribute[ncomp+(ncomp>1)]; // Allocate memory
197  else {
198  atts = attribute(aid); COM_assertion( atts);
199  // Call destructors
200  for ( int i=0, n=ncomp+(ncomp>1); i<n; ++i) atts[i].~Attribute();
201  }
202  Attribute *a = new (atts) Attribute( this, aname, aid, loc,
203  type, ncomp, unit);
204  insert( a);
205 
206  // Create an object for each individual component
207  if ( ncomp>1) for ( int i=1; i<=ncomp; ++i) {
208  char buf[10];
209  std::sprintf( buf, "%d-", i);
210  std::string newname = std::string( buf)+a->name();
211 
212  Attribute *ai = new (&atts[i]) Attribute( this, newname, aid+i,
213  loc, type, 1, unit);
214  insert( ai);
215  }
216 
217  if ( _id && loc == 'w') { // Inherit window attribute
218  reinterpret_cast<Attribute_friend*>(a)->
219  inherit( _window->attribute( aid), INHERIT_USE, true);
220  }
221  return a;
222 }
223 
224 void Pane::insert( Attribute *attr) throw(COM_exception) {
225  COM_assertion( attr->pane()==this);
226 
227  // Determine id of the new attribute
228  int id = attr->id();
229 
230  // Resize _attr_set and delete existing attribute with the id
231  if ( int(_attr_set.size())<=id) { // resize _attr_set
232  int s = attr->size_of_components();
233  _attr_set.resize( id+s+(s>1), NULL);
234  }
235 
236  if ( _attr_set[id]==NULL) _attr_set[id] = attr;
237  else COM_assertion( attr == _attr_set[id]);
238 }
239 
240 void Pane::delete_attribute( int id) throw(COM_exception) {
241  if ( id == COM_ATTS) { // Delete all user-defined attributes.
242  for ( Size i=COM_NUM_KEYWORDS,n=_attr_set.size(); i<n; ++i) {
243  Attribute *a=_attr_set[i];
244  if ( a==NULL || a->pane()==NULL) continue;
245  int ncomp = a->size_of_components();
246  delete [] a; // Delete attribute and its individual components
247  if (ncomp>1) i+=ncomp;
248  }
249  _attr_set.resize( COM_NUM_KEYWORDS);
250  }
251  else {
252  Attribute *a = _attr_set[id]; COM_assertion(a);
253  int ncomp = a->size_of_components();
254  delete [] a; // Delete the attribute and its components.
255 
256  // Reset its pointers in _attr_set.
257  for ( int i=id+((ncomp>1)?ncomp:0); i>=id; --i) _attr_set[i] = NULL;
258 
259  if ( id+ncomp+(ncomp>1) ==int(_attr_set.size()))
260  _attr_set.resize( id);
261  }
262 }
263 
264 void Pane::
265 reinit_attr( int aid, OP_Init op, void **addr,
266  int strd, int cap) throw (COM_exception)
267 {
268  switch ( aid) {
269  case COM_CONN: {
270  COM_assertion( op != OP_SET && op != OP_SET_CONST);
271  // loop through the connectivity
272  for ( int i=0, n=_cnct_set.size(); i<n; ++i) {
273  if ( !_cnct_set[i]->is_structured())
274  reinit_conn( _cnct_set[i], op, NULL, strd, cap);
275  }
276 
277  if ( addr) *addr = NULL;
278  return;
279  }
280  case COM_MESH: {
281  COM_assertion( op != OP_SET && op != OP_SET_CONST);
282  reinit_attr( COM_NC, op, NULL, strd, cap);
283  reinit_attr( COM_CONN, op, NULL, strd, cap);
284  reinit_attr( COM_RIDGES, op, NULL, strd, cap);
285  if ( addr) *addr = NULL;
286  return;
287  }
288  case COM_PMESH: {
289  COM_assertion( op != OP_SET && op != OP_SET_CONST);
290  reinit_attr( COM_NC, op, NULL, strd, cap);
291  reinit_attr( COM_CONN, op, NULL, strd, cap);
292  reinit_attr( COM_RIDGES, op, NULL, strd, cap);
293  reinit_attr( COM_PCONN, op, NULL, strd, cap);
294  if ( addr) *addr = NULL;
295  return;
296  }
297  case COM_ATTS: {
298  COM_assertion( op != OP_SET && op != OP_SET_CONST);
299  // Loop through the attributes
300  for ( int i=COM_NUM_KEYWORDS, n=_attr_set.size(); i<n; ++i) {
301  Attribute *a = _attr_set[i];
302  if ( a==NULL || a->pane()==NULL) continue;
303  if ( !a->is_windowed() || _id==0)
304  reinit_attr( i, op, NULL, strd, cap);
305  int ncomp= a->size_of_components();
306  if ( ncomp>1) i+= ncomp;
307  }
308  return;
309  }
310  case COM_ALL: {
311  COM_assertion( op != OP_SET && op != OP_SET_CONST);
312  reinit_attr( COM_PMESH, op, NULL, strd, cap);
313  reinit_attr( COM_ATTS, op, NULL, strd, cap);
314  return;
315  }
316  default: ;
317  }
318 
319  Attribute *a = attribute( aid);
320  if ( a==NULL)
323 
324  // If _id is 0, then handle only window attributes.
325  if ( !a->is_windowed() && !_id) {
326  if (op == OP_SET || op == OP_SET_CONST)
328  ( _window->name(), Pane::reinit_attr));
329  else
330  return;
331  }
332 
333  int errcode;
334  void *p;
335  int ncomp = a->size_of_components();
336 
337  if ( op==OP_DEALLOC) {
338  // Deallocate if was allocated by Roccom
339  errcode = a->deallocate();
340  p = NULL;
341  }
342  else {
343  COM_assertion( op==OP_SET_CONST||op==OP_SET||op==OP_ALLOC||op==OP_RESIZE);
344 
345  // If size is not yet set
346  if ( !a->size_set()) {
347  if ( a->is_windowed())
348  a->set_size(1); // Change the default size of window attributes to 1
349  else // Throw an exception for other types of attributes
352  }
353 
354  // Assign default value for cap and strd
355  if ( cap==0) {
356  // Default value for capacity is the number of items for set_array
357  // but the large of the current capacity and the the number of items.
358  if ( op==OP_SET || op==OP_SET_CONST) cap = a->size_of_items();
359  else {
360  if ( a->capacity()==0)
361  cap = a->size_of_items();
362  else if ( a->size_of_items()<=a->capacity())
363  cap = a->capacity();
364  else
365  cap = a->size_of_items()+a->size_of_items()/5; // Current size pluse 20% more
366  }
367  }
368 
369  if ( (op == OP_SET || op == OP_SET_CONST) && *addr && cap==0)
370  *addr = NULL; // Enforce the array to be a NULL pointer
371 
372  // Make the attribute itself set to NULL if operating on its components.
373  if ( Attribute::is_digit(a->name()[0])) {
374  int icomp=std::atoi( a->name().c_str());
375  if ( attribute(aid-icomp)->initialized())
378  }
379 
380  if ( strd==0 || strd<0 && a->stride()==0)
381  // Default value for stride is number of components
382  strd = ncomp;
383  else if ( strd<0)
384  strd = a->stride();
385 
386  if ( op == OP_SET || op == OP_SET_CONST) {
387  ((Attribute_friend*)a)->set_pointer(*addr, strd, cap,
388  0, op==OP_SET_CONST);
389  p = *addr;
390  }
391  else {
392  p = a->allocate( strd, cap, op == OP_ALLOC);
393  if ( addr) *addr = p;
394  }
395  errcode=0;
396  }
397 }
398 
399 void Pane::
400 reinit_conn( Connectivity *con, OP_Init op, int **addr,
401  int strd, int cap) throw (COM_exception)
402 {
403  // Assign default value for cap and strd
404  if ( op!=OP_DEALLOC) {
405  if ( cap==0) {
406  // Default value for capacity is the number of items for set_array
407  // but the large of the current capacity and the the number of items plus some buffer.
408  if ( op==OP_SET || op==OP_SET_CONST) cap = con->size_of_items();
409  else {
410  if ( con->capacity()==0)
411  cap = con->size_of_items();
412  else if ( con->size_of_items()<=con->capacity())
413  cap = con->capacity();
414  else
415  cap = con->size_of_items()+con->size_of_items()/5; // Current size pluse 20% more
416  }
417  }
418 
419  if ( strd==0 || strd<0 && con->stride()==0)
420  // Default value for stride is number of components
421  strd = con->size_of_components();
422  else if ( strd<0)
423  strd = con->stride();
424  }
425 
426  if ( op == OP_SET || op == OP_SET_CONST) {
427  if ( !id())
429  append_frame(con->fullname(),Pane::reinit_conn));
430 
431  if ( *addr && cap==0 && !con->is_structured())
432  *addr = NULL; // Enforce the array to be a NULL pointer
433 
434  ((Connectivity_friend*)con)->set_pointer( *addr, strd, cap,
435  op==OP_SET_CONST);
436  }
437  else {
438  if ( con->is_structured())
440  append_frame(con->fullname(),Pane::reinit_conn));
441  void *p=NULL;
442  if ( op==OP_DEALLOC)
443  { con->deallocate(); p=NULL; }
444  else
445  p = con->allocate( strd, cap, op==OP_ALLOC);
446 
447  if ( addr) *addr = (int*)p;
448  }
449 }
450 
451 Attribute *Pane::inherit( Attribute *from, const std::string &aname,
452  int mode, bool withghost) throw(COM_exception)
453 {
454  if ( from==NULL)
456  (_window->name()+"."+aname,Pane::inherit));
457 
458  switch (from->id()) { // Process keywords
459  case COM_ALL:
460  inherit( from->pane()->attribute( COM_PMESH), "", mode, withghost);
461  inherit( from->pane()->attribute( COM_ATTS), "", mode, withghost);
462  return attribute( COM_ALL);
463  case COM_MESH:
464  inherit( from->pane()->attribute( COM_NC), "", mode, withghost);
465  inherit( from->pane()->attribute( COM_CONN), "", mode, withghost);
466  inherit( from->pane()->attribute( COM_RIDGES), "", mode, withghost);
467  return attribute( COM_MESH);
468  case COM_PMESH:
469  inherit( from->pane()->attribute( COM_NC), "", mode, withghost);
470  inherit( from->pane()->attribute( COM_CONN), "", mode, withghost);
471  inherit( from->pane()->attribute( COM_RIDGES), "", mode, withghost);
472  inherit( from->pane()->attribute( COM_PCONN), "", mode, withghost);
473  return attribute( COM_PMESH);
474  case COM_ATTS: {
475  // Loop through all attributes
476  std::vector<Attribute*> &atts=from->pane()->_attr_set;
477 
478  for ( int i=COM_NUM_KEYWORDS,n=atts.size(); i<n; ++i) {
479  Attribute *a = atts[i];
480  if ( a==NULL || a->pane()==NULL) continue;
481  if ( !a->is_windowed() || _id==0)
482  inherit( a, "", mode, withghost);
483  int ncomp= a->size_of_components();
484  if ( ncomp>1) i+= ncomp;
485  }
486  return attribute( COM_ATTS);
487  }
488  case COM_CONN: {
489  if ( _id==0) return attribute(COM_CONN);
490 
491  if (mode != INHERIT_COPY) {
492  // Clean up the current connectivity tables
493  for ( Size i=0; i<_cnct_set.size(); ++i) delete _cnct_set[i];
494  _cnct_set.clear();
495 
496  if ( mode==INHERIT_USE) {
497  ((Attribute_friend*)_attr_set[COM_CONN])->inherit( from, false, withghost);
498  // Check that if structured meshes, the nodal coordinates
499  // was also used.
500  COM_assertion( !is_structured() || _attr_set[COM_NC]->parent() &&
501  _attr_set[COM_NC]->parent()->pane() == from->pane());
502  }
503 
504  // Inherit individual connectivity tables
505  std::vector<Connectivity*>::iterator it=from->pane()->_cnct_set.begin();
506  std::vector<Connectivity*>::iterator iend=from->pane()->_cnct_set.end();
507  for ( ; it != iend; ++it) {
508  _cnct_set.push_back( new Connectivity( this, *it, (*it)->name(),
509  -_cnct_set.size()-1));
510  ((Connectivity_friend*)_cnct_set.back())->inherit(*it, mode, withghost);
511  }
512 
513  // Set _ignore_ghost
514  _ignore_ghost = !withghost;
515  if ( _ignore_ghost && is_structured() && size_of_ghost_layers())
517  (_window->name()+"."+aname,Pane::inherit));
518 
519  if ( mode == INHERIT_USE) return attribute( COM_ATTS);
520  }
521 
522  // Continue to copy mode
523  // Do not copy connectivity tables for structured meshes.
524  const std::vector<Connectivity*> &es = from->pane()->_cnct_set;
525  COM_assertion_msg( es.size() == _cnct_set.size(),
526  "Number of connectivity tables do not match");
527 
528  // Loop over the connectivity tables to copy each table
529  for ( int i=0, ni=_cnct_set.size(); i<ni; ++i) {
530  const Connectivity *conn=es[i];
531  int n=withghost?conn->size_of_items():conn->size_of_real_items();
532  _cnct_set[i]->copy_array( const_cast<int*>(conn->pointer()),
533  conn->stride(), n);
534  }
535 
536  refresh_connectivity();
537  return attribute( COM_ATTS);
538  }
539  default: ;
540  }
541 
542  std::string str = aname.size()?aname:from->name();
543 
544  // If from is a keyword and target is the same, then the current
545  // attribute must have the same ID. Otherwise, must find from name.
546  Attribute *a=(from->id()<COM_NUM_KEYWORDS && aname.empty())?
547  attribute(from->id()) : _window->attribute(str);
548 
549  if ( mode != INHERIT_COPY) {
550  if ( _id == 0) {
551  if ( a==NULL || a->size_of_components()!=from->size_of_components()) {
552  // New attribute only if it does not exist or the sizes do not match
553  try {
554  a=_window->new_attribute( str, from->location(), from->data_type(),
555  from->size_of_components(), from->unit());
556 
557  if ( from->is_windowed())
558  ((Attribute_friend*)a)->inherit( from, mode, withghost);
559 
561  }
562  else try {
563  ((Attribute_friend*)a)->inherit( from, mode, withghost);
565 
566  if ( mode == INHERIT_USE || !from->is_windowed()) return a;
567  }
568  else {
569  COM_assertion( a);
570  a = _attr_set[a->id()];
571  try {
572  ((Attribute_friend*)a)->inherit( from, mode, withghost);
574 
575  if ( mode == INHERIT_USE) return a;
576  }
577  }
578  else {
579  // Copy an attribute only if it exists in the target window.
580  if ( a) a = _attr_set[a->id()];
581  else return a;
582 
583  if ( !Attribute::compatible_types( from->data_type(), a->data_type()))
585  (from->fullname()+" and "+a->fullname(),
586  Pane::inherit));
587  }
588 
589  if ( (_id==0) != (from->is_windowed())) return a;
590 
591  // Continue to copy dataset
592  if ( !withghost && is_structured() && size_of_ghost_layers())
594  (_window->name()+"."+aname,Pane::inherit));
595 
596  // count is the number of panes, nodes, or elements to loop through
597  int count = withghost?from->size_of_items():from->size_of_real_items();
598  int s_nc = from->size_of_components();
599  const Pane *src_pane = from->pane();
600 
601  COM_assertion_msg( from->location() == a->location(),
602  (std::string("Location of attributes ")+
603  from->fullname()+" and " +a->fullname()+
604  " do not match during copying.").c_str());
605 
606  // loop through components of source's data
607  if ( count) for ( int j=(s_nc>1), nj=s_nc-(s_nc==1); j<=nj; ++j) {
608  // src_data points to source data for current component
609  const Attribute *src_data = src_pane->attribute( from->id()+j);
610 
611  // dest_data points to dest data for current component
612  Attribute *dest_data = attribute( a->id()+j);
613 
614  if ( dest_data->pointer() && src_data->pointer()) {
615  COM_assertion_msg( withghost && dest_data->size_of_items()==src_data->size_of_items() ||
616  !withghost && dest_data->size_of_real_items()==src_data->size_of_real_items(),
617  (std::string("Number of items of attributes ")+
618  from->fullname()+" and " +a->fullname()+
619  " do not match during copying.").c_str());
620  try {
621  dest_data->copy_array( const_cast<void*>(src_data->pointer()),
622  src_data->stride(), count);
624  }
625  }
626 
627  return a;
628 }
629 
631  int nitems, int ng) throw( COM_exception) {
632  if ( nitems<ng)
634  append_frame(a->fullname(),Pane::set_size));
635  // Get the corresponding attribute object.
636  if ( !a->is_windowed() && !_id)
638  append_frame(a->fullname(),Pane::set_size));
639 
640  if ( a->is_nodal()) {
641  COM_assertion_msg( a->id() == COM_NC,
642  (std::string("Cannot set size for nodal attribute ")+
643  a->fullname()+". Must use the nc attribute").c_str());
644 
645  _attr_set[COM_NC]->set_size( nitems, ng);
646  }
647  else if ( a->is_elemental()) {
648  COM_assertion_msg( a->id() == COM_CONN,
649  (std::string("Cannot set size for elemental attribute ")+
650  a->fullname()+". Must use the conn attribute").c_str());
651 
652  _attr_set[COM_CONN]->set_size( nitems, ng);
653  }
654  else {
655  attribute(a->id())->set_size( nitems, ng);
656  }
657 }
658 
660  int nitems, int ng) throw( COM_exception) {
661  if ( !con->is_structured() && nitems<ng)
663  append_frame(con->fullname(),Pane::set_size));
664  con->set_size( nitems, ng);
665 }
666 
668  int nelems = 0, ngelems = 0;
669 
670  // Set the number of elements
671  if ( !_attr_set[COM_CONN]->parent()) {
672  // Loop through the connectivity table
673  Cnct_set::iterator it=_cnct_set.begin();
674  for ( ; it != _cnct_set.end(); ++it) {
676  con->set_offset( nelems);
677  nelems += con->size_of_elements();
678  ngelems += con->size_of_ghost_elements();
679  }
680 
681  if ( nelems<0 || ngelems<0)
682  throw COM_exception( COM_ERR_INVALID_SIZE, append_frame
684  _attr_set[COM_CONN]->set_size(nelems, ngelems);
685  }
686 
687  // Set the number of nodes for structured meshes
688  if ( is_structured() && !_attr_set[COM_NC]->parent()) {
689  _attr_set[COM_NC]->set_size(_cnct_set[0]->size_of_nodes(),
691  }
692 }
693 
694 COM_END_NAME_SPACE
695 
696 
697 
698 
699 
700 
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
Size size_of_ghost_elements() const
Get the number of ghost elements.
Definition: Connectivity.C:117
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
bool initialized() const
Returns whether the array for the attribute has been set or allocated.
Definition: Attribute.h:244
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
const int * pointer() const
Get a constant pointer to the connectivity array.
Definition: Connectivity.h:206
Contains the prototypes for the Pane object.
An Attribute object is a data member of a window.
Definition: Attribute.h:51
j indices k indices k
Definition: Indexing.h:6
static bool compatible_types(COM_Type t1, COM_Type t2)
Definition: Attribute.C:531
static bool is_digit(char c)
Definition: Attribute.h:264
#define COM_assertion_msg(EX, msg)
double s
Definition: blastest.C:80
bool is_windowed() const
Checks whether the attribute is associated with the window.
Definition: Attribute.h:188
void reinit_conn(Connectivity *con, OP_Init op, int **addr, int strd, int cap)
Definition: Pane.C:400
A Window object contains multiple panes and multiple data attributes.
Definition: Window.h:42
void set_size(Attribute *a, int nitems, int ng)
Set the size of an attribute.
Definition: Pane.C:630
bool is_structured() const
Is mesh of the pane structured?
Definition: Pane.h:110
Pane(Window *w, int i)
Create a pane in window w with ID i.
Definition: Pane.C:33
Size size_of_ghost_nodes() const
Get the number of ghost nodes.
Definition: Pane.h:126
void delete_attribute(int id)
Delete an existing attribute with given id.
Definition: Pane.C:240
const std::string & name() const
Obtain the window&#39;s name.
Definition: Window.h:92
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.
int deallocate()
Deallocate memory if it was allocated by allocate().
Definition: Attribute.C:473
void init_done()
Finalize the initialization of a pane.
Definition: Pane.C:85
Attribute * attribute(const std::string &a)
Obtain the attribute from given name.
Definition: Pane.C:148
#define CATCHBADALLOC_APPEND(frame)
Macro for catching an deallocation exception and append the information to the current frame...
int capacity() const
Obtain the capacity of the array.
Definition: Attribute.h:230
Window * _window
Point to the parent window.
Definition: Pane.h:313
const void * pointer() const
Obtain a constant pointer to the physical address.
Definition: Attribute.h:150
Size index_offset() const
Get the index of the first element.
Definition: Connectivity.h:189
**********************************************************************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
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
virtual ~Pane()
Default destructor.
Definition: Pane.C:75
This file contains a set of routines for error assertion.
const NT & n
void set_offset(Size offset)
Set the index of the first element.
Definition: Connectivity.C:92
int stride() const
Obtain the stride of the attribute in base datatype.
Definition: Attribute.h:233
unsigned int Size
Unsighed int.
Definition: Pane.h:47
void set_size(int nitems, int ngitems=0)
Set the size of items and ghost items.
Definition: Attribute.C:191
int size_of_real_items() const
Obtain the number of real items in the attribute.
Definition: Attribute.C:167
const Pane * pane() const
Obtain a constant pointer to the owner pane of the attribute.
Definition: Attribute.h:172
Attribute * attribute(const std::string &a)
Obtain a pointer to the attribute metadata from its name.
Definition: Window.C:842
Cnct_set _cnct_set
Set of element connectivity.
Definition: Pane.h:316
void int int * nk
Definition: read.cpp:74
#define append_frame(s, frame)
Macro for appending the information about the given frame to the string s.
int last_attribute_id() const
Return the last attribute id.
Definition: Window.h:291
j indices j
Definition: Indexing.h:6
Size size_of_nodes() const
Get the total number of nodes in the pane (including ghost nodes).
Definition: Pane.h:118
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
void * allocate(int strd, int cap, bool force)
Allocate memory for the attribute.
Definition: Attribute.C:345
void refresh_connectivity()
Update offsets and sizes of connectivity of an unstructured mesh.
Definition: Pane.C:667
Size size_of_elements() const
Get the total number of elements (including ghost elements) in the table.
Definition: Connectivity.C:96
void int int REAL REAL REAL *z blockDim dim * ni
Definition: read.cpp:77
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
void copy_array(void *buf, int strd, int nitem, int offset=0, int direction=COPY_IN)
Definition: Attribute.C:249
void int * nj
Definition: read.cpp:74
#define CATCHEXP_APPEND(frame)
Macro for catching an exception and append the information to the current frame.
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
Attr_set _attr_set
Set of attributes.
Definition: Pane.h:315
void attributes(std::vector< Attribute * > &as)
Obtain all the attributes of the pane.
Definition: Pane.C:165
OP_Init
Definition: Pane.h:48
void insert(Attribute *attr)
Insert an attribute onto the pane.
Definition: Pane.C:224
Contains the prototypes for the Window object.
Encapsulates an element-connectivity of a mesh.
Definition: Connectivity.h:41
int size_of_items() const
Obtain the number of items in the attribute.
Definition: Attribute.C:111
std::string fullname() const
Obtain the full name of the attribute including window name suitable for printing out error messages...
Definition: Attribute.C:82
int size_of_components() const
Obtain the number of components in the attribute.
Definition: Attribute.h:203