Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rocsurf.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: Rocsurf.C,v 1.12 2008/12/06 08:43:23 mtcampbe Exp $
24 
25 #include "Rocsurf.h"
26 #include "roccom.h"
27 #include "Manifold_2.h"
28 
30 
32 
33 Rocsurf::~Rocsurf() { if (_wm) delete _wm; }
34 
35 void Rocsurf::initialize( const COM::Attribute *mesh) {
36  COM_assertion_msg( validate_object()==0, "Invalid object");
37  COM_assertion_msg( !mesh || mesh->id()==COM::COM_MESH ||
38  mesh->id()==COM::COM_PMESH,
39  "Input argument must be a mesh or pmesh");
40 
41  if ( _wm) delete _wm;
42 
43  _wm = new Window_manifold_2( const_cast<COM::Attribute*>(mesh));
44 
46 }
47 
48 // Evaluate nodal normals
49 void Rocsurf::compute_normals( const COM::Attribute *mesh,
50  COM::Attribute *nrm,
51  const int *scheme) {
52  COM_assertion_msg( validate_object()==0, "Invalid object");
53 
54  if ( _wm == NULL) initialize( mesh);
55 
56  if ( scheme)
57  _wm->compute_normals( nrm, *scheme);
58  else
59  _wm->compute_normals( nrm);
60 }
61 
62 // Evaluate nodal normals
63 void Rocsurf::compute_mcn( COM::Attribute *mcn,
64  COM::Attribute *lbmcn) {
65  COM_assertion_msg( validate_object()==0, "Invalid object");
66 
67  COM_assertion_msg( _wm, "initialization must be called first before calling compute_mcn");
68 
69  _wm->compute_mcn( mcn, lbmcn);
70 }
71 
72 void Rocsurf::elements_to_nodes( const COM::Attribute *elem_vals,
73  COM::Attribute *nodal_vals,
74  const COM::Attribute *mesh,
75  const int *scheme,
76  const COM::Attribute *elem_weights,
77  COM::Attribute *nodal_weights)
78 {
79  COM_assertion_msg( validate_object()==0, "Invalid object");
80 
81  if ( _wm == NULL) initialize( mesh);
82 
83  _wm->elements_to_nodes( elem_vals, nodal_vals, scheme?*scheme:E2N_AREA,
84  elem_weights, nodal_weights);
85 }
86 
87 void Rocsurf::compute_edge_lengths( double *lave, double *lmin, double *lmax) {
88 
90 
91  double local_lmin=HUGE_VAL, local_lmax=0, local_lsum=0, local_weights=0;
92 
93  // Loop through the panes to identify strong edges
94  for ( ; it!=iend; ++it) {
95  for (int i=0, nf=it->size_of_real_faces(); i<nf; ++i) {
96  Halfedge h=Halfedge( &*it, Edge_ID( i+1, 0), ACROSS_PANE), h0=h;
97  do {
98  Halfedge hopp=h.opposite();
99 
100  if ( hopp.is_border() || h < hopp) {
101  double l = h.tangent().norm();
102 
103  local_lmin = std::min( local_lmin, l);
104  local_lmax = std::max( local_lmax, l);
105  local_lsum += l;
106  local_weights += 1;
107  }
108  } while ( (h=h.next())!=h0);
109  }
110  }
111 
112  double global_lmin=local_lmin, global_lmax=local_lmax,
113  global_lsum=local_lsum, global_weighs=local_weights;
114 
115  if ( COMMPI_Initialized()) {
116  MPI_Comm comm = _wm->window()->get_communicator();
117  MPI_Allreduce( &local_lmin, &global_lmin, 1, MPI_DOUBLE, MPI_MIN, comm);
118  MPI_Allreduce( &local_lmax, &global_lmax, 1, MPI_DOUBLE, MPI_MAX, comm);
119  MPI_Allreduce( &local_lsum, &global_lsum, 1, MPI_DOUBLE, MPI_SUM, comm);
120  MPI_Allreduce( &local_weights, &global_weighs, 1, MPI_DOUBLE, MPI_SUM, comm);
121  }
122 
123  if ( lave) *lave = (global_weighs>0)? (global_lsum / global_weighs) : 0.;
124  if ( lmin) *lmin = global_lmin;
125  if ( lmax) *lmax = global_lmax;
126 }
127 
128 void Rocsurf::serialize_mesh( const COM::Attribute *inmesh, COM::Attribute *outmesh) {
129  COM_assertion_msg( validate_object()==0, "Invalid object");
130 
131  if ( _wm == NULL) initialize( inmesh);
132 
133  COM::Window *outwin = outmesh->window();
134 
135  // Serialize input mesh and put into output mesh
136  _wm->serialize_window( outwin);
137 }
138 
139 void Rocsurf::load( const std::string &mname) {
140  Rocsurf *surf = new Rocsurf();
141 
142  COM_new_window( mname.c_str());
143 
144  std::string glb=mname+".global";
145 
146  COM_new_attribute( glb.c_str(), 'w', COM_VOID, 1, "");
147  COM_set_object( glb.c_str(), 0, surf);
148 
149  COM_Type types[7];
150 
151  types[0] = COM_METADATA; types[1] = COM_METADATA;
152  types[2] = COM_METADATA; types[3] = COM_VOID;
153  COM_set_function( (mname+".interpolate_to_centers").c_str(),
154  (Func_ptr)interpolate_to_centers, "io", types);
155 
156  COM_set_function( (mname+".compute_element_areas").c_str(),
157  (Func_ptr)compute_element_areas, "oI", types);
158 
159  COM_set_function( (mname+".compute_bounded_volumes").c_str(),
160  (Func_ptr)compute_bounded_volumes, "iioI", types);
161 
162  COM_set_function( (mname+".compute_swept_volumes").c_str(),
163  (Func_ptr)compute_swept_volumes, "iioI", types);
164 
165  types[0] = COM_METADATA; types[1] = COM_DOUBLE;
166  COM_set_function( (mname+".integrate").c_str(),
167  (Func_ptr)integrate, "io", types);
168 
169  COM_set_function( (mname+".compute_signed_volumes").c_str(),
170  (Func_ptr)compute_signed_volumes, "io", types);
171 
172  types[1] = COM_INTEGER;
173  COM_set_function( (mname+".compute_element_normals").c_str(),
174  (Func_ptr)compute_element_normals, "oII", types);
175 
176 
177  types[0] = COM_RAWDATA; types[1] = types[2] = COM_METADATA;
178  COM_set_member_function( (mname+".initialize").c_str(),
179  (Member_func_ptr)(&Rocsurf::initialize),
180  glb.c_str(), "bi", types);
181 
182  types[3] = COM_INT;
183  COM_set_member_function( (mname+".compute_normals").c_str(),
184  (Member_func_ptr)(&Rocsurf::compute_normals),
185  glb.c_str(), "bioI", types);
186 
187 
188  COM_set_member_function( (mname+".compute_mcn").c_str(),
189  (Member_func_ptr)(&Rocsurf::compute_mcn),
190  glb.c_str(), "boo", types);
191 
192  types[3] = types[5] = types[6] = COM_METADATA; types[4] = COM_INT;
193  COM_set_member_function( (mname+".elements_to_nodes").c_str(),
194  (Member_func_ptr)(&Rocsurf::elements_to_nodes),
195  glb.c_str(), "bioiIIO", types);
196 
197  COM_new_attribute((mname+".E2N_USER").c_str(), 'w', COM_INT, 1, "");
198  COM_set_array_const((mname+".E2N_USER").c_str(), 0, &scheme_vals[E2N_USER]);
199  COM_new_attribute((mname+".E2N_ONE").c_str(), 'w', COM_INT, 1, "");
200  COM_set_array_const((mname+".E2N_ONE").c_str(), 0, &scheme_vals[E2N_ONE]);
201  COM_new_attribute((mname+".E2N_AREA").c_str(), 'w', COM_INT, 1, "");
202  COM_set_array_const((mname+".E2N_AREA").c_str(), 0, &scheme_vals[E2N_AREA]);
203  COM_new_attribute((mname+".E2N_ANGLE").c_str(), 'w', COM_INT, 1, "");
204  COM_set_array_const((mname+".E2N_ANGLE").c_str(), 0, &scheme_vals[E2N_ANGLE]);
205 
206  types[1] = types[2] = types[3] = COM_DOUBLE;
207  COM_set_member_function( (mname+".compute_edge_lengths").c_str(),
208  (Member_func_ptr)(&Rocsurf::compute_edge_lengths),
209  glb.c_str(), "boOO", types);
210 
211  types[1] = types[2] = COM_METADATA;
212  COM_set_member_function( (mname+".serialize_mesh").c_str(),
213  (Member_func_ptr)(&Rocsurf::serialize_mesh),
214  glb.c_str(), "bio", types);
215 
216  COM_window_init_done( mname.c_str());
217 }
218 
219 void Rocsurf::unload( const std::string &mname) {
220  Rocsurf *surf;
221  std::string glb=mname+".global";
222 
223  COM_get_object( glb.c_str(), 0, &surf);
224  delete surf;
225 
226  COM_delete_window( mname.c_str());
227 }
228 
229 extern "C" void Rocsurf_load_module( const char *mname)
230 { Rocsurf::load( mname); }
231 
232 extern "C" void Rocsurf_unload_module( const char *mname)
233 { Rocsurf::unload( mname); }
234 
235 #ifndef DOXYGEN_SHOULD_SKIP_THIS
236 // Fortran bindings
237 extern "C" void rocsurf_load_module( const char *mname, long int length)
238 { Rocsurf::load( std::string(mname, length)); }
239 
240 extern "C" void rocsurf_unload_module( const char *mname, long int length)
241 { Rocsurf::unload( std::string(mname, length)); }
242 
243 extern "C" void ROCSURF_LOAD_MODULE( const char *mname, long int length)
244 { Rocsurf::load( std::string(mname, length)); }
245 
246 extern "C" void ROCSURF_UNLOAD_MODULE( const char *mname, long int length)
247 { Rocsurf::unload( std::string(mname, length)); }
248 
249 extern "C" void rocsurf_load_module_( const char *mname, long int length)
250 { Rocsurf::load( std::string(mname, length)); }
251 
252 extern "C" void rocsurf_unload_module_( const char *mname, long int length)
253 { Rocsurf::unload( std::string(mname, length)); }
254 
255 extern "C" void ROCSURF_LOAD_MODULE_( const char *mname, long int length)
256 { Rocsurf::load( std::string(mname, length)); }
257 
258 extern "C" void ROCSURF_UNLOAD_MODULE_( const char *mname, long int length)
259 { Rocsurf::unload( std::string(mname, length)); }
260 #endif // DOXYGEN_SHOULD_SKIP_THIS
261 
263 
264 
265 
266 
267 
268 
This class implements a data structure for 2-manifold over a whole window, which can be composed of m...
Definition: Manifold_2.h:185
static const int scheme_vals[]
Definition: Rocsurf.h:164
void rocsurf_load_module_(const char *mname, long int length)
Definition: Rocsurf.C:249
Window_manifold_2 * _wm
Definition: Rocsurf.h:163
void elements_to_nodes(const COM::Attribute *elem_vals, COM::Attribute *nodal_vals, const COM::Attribute *mesh=NULL, const int *scheme=NULL, const COM::Attribute *elem_weights=NULL, COM::Attribute *nodal_weights=NULL)
Computes nodal or elemental normals of a given window.
Definition: Rocsurf.C:72
int COM_Type
Indices for derived data types.
Definition: roccom_basic.h:122
void ROCSURF_LOAD_MODULE(const char *mname, long int length)
Definition: Rocsurf.C:243
PM_iterator pm_begin()
Obtain an iterator to the first pane manifold of the window.
Definition: Manifold_2.h:223
Rocsurf()
Definition: Rocsurf.h:44
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_GROUP_EMPTY INTEGER MPI_MAX
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
#define COM_assertion_msg(EX, msg)
void elements_to_nodes(const COM::Attribute *evals, COM::Attribute *nvals, const int scheme=E2N_ONE, const COM::Attribute *ews=NULL, COM::Attribute *nws=NULL, const int tosum=false)
Convert element values to nodal values using weighted averaging.
Definition: Manifold_2.C:816
#define SURF_END_NAMESPACE
Definition: surfbasic.h:29
MAP::Facet_ID Edge_ID
Definition: Manifold_2.h:49
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
void ROCSURF_UNLOAD_MODULE(const char *mname, long int length)
Definition: Rocsurf.C:246
Halfedge opposite() const
Get the ID of the opposite edge of a given edge.
Definition: Manifold_2.h:454
void COM_set_function(const char *wf_str, Func_ptr func, const char *intents, const COM_Type *types)
Definition: roccom_c++.h:323
This file contains the prototypes for Roccom API.
static void load(const std::string &mname)
Loads Rocsurf onto Roccom with a given module name.
Definition: Rocsurf.C:139
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_GROUP_EMPTY INTEGER MPI_MIN
void ROCSURF_LOAD_MODULE_(const char *mname, long int length)
Definition: Rocsurf.C:255
This class encapsulate a halfedge over a window manifold.
Definition: Manifold_2.h:446
Halfedge next() const
Get the next halfedge of its owner element.
Definition: Manifold_2.h:465
void COM_set_object(const char *wa_str, int pane_id, Type *addr)
Definition: roccom_c++.h:144
static void compute_bounded_volumes(const COM::Attribute *old_location, const COM::Attribute *new_location, COM::Attribute *volumes, void *flag=NULL)
Computes the volume bounded between two different locations of each face of the surface mesh of windo...
static void compute_signed_volumes(const COM::Attribute *mesh, double *vol)
Computes the signed volume of a body.
virtual ~Rocsurf()
Definition: Rocsurf.C:33
void ROCSURF_UNLOAD_MODULE_(const char *mname, long int length)
Definition: Rocsurf.C:258
double length(Vector3D *const v, int n)
void COM_get_object(const char *wa_str, int pane_id, Type **addr)
Definition: roccom_c++.h:152
std::vector< Pane_manifold_2 >::iterator PM_iterator
Definition: Manifold_2.h:187
static const int scheme
#define SURF_BEGIN_NAMESPACE
Definition: surfbasic.h:28
Vector_3< Real > tangent() const
Get the tangent of the given halfedge.
Definition: Manifold_2.h:484
void initialize(const COM::Attribute *pmesh)
Constructs the communication patterns of a distributed mesh.
Definition: Rocsurf.C:35
**********************************************************************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
void compute_mcn(COM::Attribute *mcn, COM::Attribute *lbmcn)
Computes nodal or elemental normals of a given window.
Definition: Rocsurf.C:63
void(* Func_ptr)()
Pointer of functions.
Definition: roccom_basic.h:123
static void interpolate_to_centers(const COM::Attribute *x, COM::Attribute *z)
Interpolates nodal coordinates to element centers.
void Rocsurf_load_module(const char *mname)
Definition: Rocsurf.C:229
void serialize_mesh(const COM::Attribute *inmesh, COM::Attribute *outmesh)
Serialize the mesh of a given window.
Definition: Rocsurf.C:128
blockLoc i
Definition: read.cpp:79
void Rocsurf_unload_module(const char *mname)
Definition: Rocsurf.C:232
void compute_normals(const COM::Attribute *mesh, COM::Attribute *nrm, const int *scheme=NULL)
Computes nodal or elemental normals of a given window.
Definition: Rocsurf.C:49
static void integrate(const COM::Attribute *x, double *z)
Integrate a function given by an elemental attribute over surface z is an array of size equal to numb...
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_set_array_const(const char *wa_str, int pane_id, const void *addr, int strd=0, int cap=0)
Definition: roccom_c++.h:160
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
static void compute_element_normals(COM::Attribute *nrm, const int *to_normalize=NULL, const COM::Attribute *pnts=NULL)
Computes elemental normals of a given window.
bool is_border() const
Is the edge a border edge?
Definition: Manifold_2.h:476
COM::Window * window()
Obtain the underlying window object.
Definition: Manifold_2.h:203
void compute_mcn(COM::Attribute *mcn_in, COM::Attribute *lbmcn_in)
void compute_normals(COM::Attribute *normals, int scheme=E2N_ANGLE, bool to_normalize=true)
Compute the normals at nodes or faces, depending on the type of the attribute normals.
Definition: Manifold_2.C:1045
static void compute_swept_volumes(const COM::Attribute *location, const COM::Attribute *disps, COM::Attribute *volumes, void *flag=NULL)
Computes the swept volume by a given displacement of each face of the surface mesh of window volumes-...
void init_communicator()
Initialize a pane communicator.
Definition: Manifold_2.C:389
void serialize_window(COM::Window *outwin) const
Create a serial window (with single pane) from the current window.
Definition: Manifold_2.C:1353
int validate_object() const
Definition: Rocsurf.h:156
void compute_edge_lengths(double *lave, double *lmin, double *lmax)
Computes edge lengths of a given window.
Definition: Rocsurf.C:87
void rocsurf_unload_module(const char *mname, long int length)
Definition: Rocsurf.C:240
void COM_new_attribute(const char *wa_str, const char loc, const int type, int ncomp, const char *unit)
Registering an attribute type.
Definition: roccom_c++.h:118
void COM_set_member_function(const char *wf_str, Member_func_ptr func, const char *wa_str, const char *intents, const COM_Type *types)
Definition: roccom_c++.h:330
static void unload(const std::string &mname)
Unloads Rocsurf from Roccom.
Definition: Rocsurf.C:219
static void compute_element_areas(COM::Attribute *areas, const COM::Attribute *pnts=NULL)
Computes the area of each face of the surface mesh of window areas-&gt;window and saves the results in a...
int COMMPI_Initialized()
Definition: commpi.h:168
PM_iterator pm_end()
Obtain an iterator to the past-the-last pane manifold of the window.
Definition: Manifold_2.h:227
void rocsurf_unload_module_(const char *mname, long int length)
Definition: Rocsurf.C:252
void rocsurf_load_module(const char *mname, long int length)
Definition: Rocsurf.C:237
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_GROUP_EMPTY INTEGER MPI_SUM
Type norm() const
Definition: mapbasic.h:112