Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Window.h
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.h,v 1.12 2008/12/06 08:43:24 mtcampbe Exp $
24 
29 /* Author: Xiangmin Jiao */
30 
31 #ifndef __ROCCOM_WINDOW_H__
32 #define __ROCCOM_WINDOW_H__
33 
34 #include "Function.h"
35 #include "Pane.h"
36 #include <map>
37 
38 COM_BEGIN_NAME_SPACE
39 
42 class Window {
43  typedef std::map< std::string, Function> Func_map;
44  typedef std::map< std::string, Attribute*> Attr_map;
45  typedef std::map< int, Pane*> Pane_map;
46 
47  class Pane_friend : public Pane {
48  explicit Pane_friend( Pane&);
49  public:
50  using Pane::new_attribute;
52  using Pane::inherit;
53  using Pane::set_size;
54  using Pane::reinit_attr;
55  using Pane::reinit_conn;
56  using Pane::connectivity;
57  };
59 
60 public:
61  typedef std::map<int,int> Proc_map;
62 
63  // Used by get_array. Note that the default dimension is -1, which
64  // is for void*. Nonnegative dimensions are reserved for Fortran pointers.
66  explicit Pointer_descriptor( void *p, int d=-1)
67  : ptr(p), dim(d), n1(0), n2(0) {}
68  void *at() { return ptr; }
69 
70  void *ptr;
71  int dim;
72  int n1, n2;
73  };
74 
82  Window( const std::string &name, MPI_Comm c);
83 
85  virtual ~Window();
86  //\}
87 
91  const std::string &name() const { return _name; }
93 
95  MPI_Comm get_communicator() const { return _comm; }
96  //\}
97 
101  void set_function( const std::string &fname,
103  Func_ptr func,
104  const std::string &intents,
105  const COM_Type *types,
106  Attribute *a,
107  bool if_f90=false) throw(COM_exception);
108 
110  void set_function( const std::string &fname,
111  Member_func_ptr func,
112  const std::string &intents,
113  const COM_Type *types,
114  Attribute *a,
115  bool if_f90=false) throw(COM_exception);
116 
124  Attribute *new_attribute( const std::string &aname, const char loc,
125  const int type, int ncomp,
126  const std::string &unit) throw(COM_exception);
127 
129  void delete_attribute( const std::string &aname) throw(COM_exception);
130 
137  void set_size( const std::string &aname, int pane_id,
138  int nitems, int ng=0) throw( COM_exception);
139 
148  void set_array( const std::string &aname, const int pane_id,
149  void *addr, int strd=0, int cap=0, bool is_const=false)
150  throw(COM_exception);
151 
156  void alloc_array( const std::string &aname, const int pane_id,
157  void **addr, int strd=0, int cap=0) throw(COM_exception);
158 
163  void resize_array( const std::string &aname, const int pane_id,
164  void **addr, int strd=-1, int cap=0) throw(COM_exception);
165 
166  void resize_array( Attribute *a, void **addr,
167  int strd=-1, int cap=0) throw(COM_exception)
168  { reinit_attr( a, Pane::OP_RESIZE, addr, strd, cap); }
169 
170  void resize_array( Connectivity *c, void **addr,
171  int strd=-1, int cap=0) throw(COM_exception)
172  { reinit_conn( c, Pane::OP_RESIZE, (int**)addr, strd, cap); }
173 
178  void append_array( const std::string &aname, const int pane_id,
179  const void *val, int v_strd, int v_size) throw(COM_exception);
180 
185  void dealloc_array( const std::string &aname,
186  const int pane_id=0) throw(COM_exception);
187 
188  void dealloc_array( Attribute *a) throw(COM_exception)
189  { reinit_attr( a, Pane::OP_DEALLOC); }
190 
192  { reinit_conn( c, Pane::OP_DEALLOC); }
193 
202  Attribute *inherit( Attribute *from, const std::string &aname,
203  int inherit_mode, bool withghost,
204  const Attribute *cond, int val) throw(COM_exception);
205 
207  void copy_attribute( const Attribute *from,
208  Attribute *to) throw(COM_exception) {
209  inherit( const_cast<Attribute*>(from), to->name(),
210  Pane::INHERIT_COPY, true, NULL, 0);
211  }
212 
220  Attribute *get_attribute( const std::string &aname, char *l, int *t,
221  int *n, std::string *u) const throw(COM_exception);
222 
229  void get_size( const std::string &aname, int pane_id,
230  int *nitems, int *ng) const throw( COM_exception);
231 
235  int get_status( const std::string &aname, int pane_id) const
236  throw(COM_exception);
237 
241  void get_parent( const std::string &aname, int pane_id,
242  std::string &name) const throw(COM_exception);
243 
252  void get_array( const std::string &aname, const int pane_id,
253  Pointer_descriptor &addr,
254  int *strd=NULL, int *cap=NULL, bool is_const=false)
255  throw(COM_exception);
256 
268  void copy_array( const std::string &aname, const int pane_id,
269  void *val, int v_strd=0, int v_size=0,
270  int offset=0) const throw(COM_exception);
271 
273  void init_done( bool pane_changed=true) throw(COM_exception);
274 
275  //\}
276 
280  int size_of_panes() const { return _pane_map.size(); }
282 
284  int size_of_panes_global() const { return _proc_map.size(); }
285 
288  int owner_rank( const int pane_id) const;
289 
291  int last_attribute_id() const { return _last_id; }
292 
294  const Proc_map &proc_map() const { return _proc_map; }
295 
297  void delete_pane( const int pane_id) throw(COM_exception) {
298  if ( pane_id == 0) { // delete all panes
299  _pane_map.clear();
300  }
301  else {
302  Pane_map::iterator it = _pane_map.find( pane_id);
303  if ( it == _pane_map.end()) throw COM_exception(COM_ERR_PANE_NOTEXIST);
304  delete it->second;
305  _pane_map.erase( it);
306  }
307  }
308 
309  //\}
310 
314  Pane &pane( const int pane_id, bool insert=false) throw(COM_exception);
316  const Pane &pane( const int pane_id) const throw(COM_exception);
317 
319  void panes( std::vector<int> &ps, int rank=-2);
320 
322  void panes( std::vector<Pane*> &ps);
324  void panes( std::vector<const Pane*> &ps) const
325  { const_cast<Window*>(this)->panes( (std::vector<Pane*> &)ps); }
326 
328  void attributes( std::vector<Attribute*> &as)
329  { _dummy.attributes( as); }
331  void attributes( std::vector< const Attribute*> &as) const
332  { _dummy.attributes( as); }
333 
335  Attribute *attribute( const std::string &a) throw(COM_exception);
336  const Attribute *attribute( const std::string &a) const throw(COM_exception)
337  { return const_cast<Window*>(this)->attribute( a); }
338 
340  Attribute *attribute( int i) throw(COM_exception)
341  { return _dummy.attribute( i); }
342  const Attribute *attribute( int i) const throw(COM_exception)
343  { return _dummy.attribute( i); }
344 
346  Function *function( const std::string &f);
347  const Function *function( const std::string &f) const
348  { return const_cast<Window*>(this)->function( f); }
349  //\}
350 
351 protected:
361  void reinit_attr( Attribute *attr, OP_Init op, void **addr=NULL,
362  int strd=0, int cap=0) throw(COM_exception);
363 
373  void reinit_conn( Connectivity *con, OP_Init op, int **addr=NULL,
374  int strd=0, int cap=0) throw(COM_exception);
375 
376 protected:
378  std::string _name;
384 
385  int _last_id;
386  MPI_Comm _comm;
389  int _status;
390 
391 private:
392  // Disable the following two functions (they are dangerous)
393  Window( const Window&);
394  Window &operator=( const Window&);
395 
396 private:
397 #ifdef DOXYGEN
398  // This is to fool DOXYGEN to generate the correct collabration diagram
401  Pane *_pane_map;
402 #endif /* DOXYGEN */
403 
404 };
405 
406 COM_END_NAME_SPACE
407 
408 #endif
409 
410 
411 
412 
413 
414 
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
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
void dealloc_array(Connectivity *c)
Definition: Window.h:191
int _last_id
The last used attribute index.
Definition: Window.h:385
Pane::OP_Init OP_Init
Definition: Window.h:58
void resize_array(Connectivity *c, void **addr, int strd=-1, int cap=0)
Definition: Window.h:170
const NT & d
Contains the prototypes for the Pane object.
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
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
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 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
const Attribute * attribute(const std::string &a) const
Definition: Window.h:336
void set_size(Attribute *a, int nitems, int ng)
Set the size of an attribute.
Definition: Pane.C:630
std::map< std::string, Attribute * > Attr_map
Definition: Window.h:44
std::map< int, Pane * > Pane_map
Definition: Window.h:45
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
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
Window & operator=(const Window &)
MPI_Comm _comm
the MPI communicator of the window.
Definition: Window.h:387
Encapsulates the states of an exception.
Attribute * attribute(const std::string &a)
Obtain the attribute from given name.
Definition: Pane.C:148
void attributes(std::vector< Attribute * > &as)
Obtain all the attributes of the pane.
Definition: Window.h:328
void copy_attribute(const Attribute *from, Attribute *to)
Copy an attribute object onto another.
Definition: Window.h:207
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
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
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
void attributes(std::vector< const Attribute * > &as) const
Obtain all the attributes of the pane.
Definition: Window.h:331
void delete_pane(const int pane_id)
Remove the pane with given ID.
Definition: Window.h:297
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
MPI_Comm get_communicator() const
Obtain the communicator of the window.
Definition: Window.h:95
void(* Func_ptr)()
Pointer of functions.
Definition: roccom_basic.h:123
int size_of_panes_global() const
Obtain the total number of panes in the window on all processes.
Definition: Window.h:284
blockLoc i
Definition: read.cpp:79
Pointer_descriptor(void *p, int d=-1)
Definition: Window.h:66
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
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
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
const NT & n
int owner_rank(const int pane_id) const
Obtain the process rank that owns a given pane.
Definition: Window.C:452
int size_of_panes() const
Obtain the number of local panes in the window.
Definition: Window.h:281
std::map< std::string, Function > Func_map
Definition: Window.h:43
std::string _name
Name of the window.
Definition: Window.h:378
const Proc_map & proc_map() const
Obtain the process map.
Definition: Window.h:294
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
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
int last_attribute_id() const
Return the last attribute id.
Definition: Window.h:291
std::map< int, int > Proc_map
Definition: Window.h:61
Contains the prototypes and implementation for the Funcion object.
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
const Attribute * attribute(int i) const
Definition: Window.h:342
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
Attribute * attribute(int i)
Obtain a pointer to the attribute metadata from its index.
Definition: Window.h:340
void attributes(std::vector< Attribute * > &as)
Obtain all the attributes of the pane.
Definition: Pane.C:165
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
Encapsulates an element-connectivity of a mesh.
Definition: Connectivity.h:41
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