Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/PatchData.hpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
24  pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
25 
26  ***************************************************************** */
27 #ifndef MESQUITE_PATCHDATA_HPP
28 #define MESQUITE_PATCHDATA_HPP
29 
43 #include "Mesquite.hpp"
44 #include "MsqVertex.hpp"
45 #include "MsqMeshEntity.hpp"
46 #include "MsqVertex.hpp"
47 #include "MeshInterface.hpp"
48 #include "PatchDataMem.hpp"
49 #include "CornerTag.hpp"
50 #include "TargetMatrix.hpp"
51 
52 
53 #ifndef MSQ_USE_OLD_C_HEADERS
54 # include <cstddef>
55 # include <cstdlib>
56 #else
57 # include <stddef.h>
58 # include <stdlib.h>
59 #endif
60 
61 #ifdef MSQ_USE_OLD_STD_HEADERS
62 # include <map.h>
63 # include <vector.h>
64 #else
65 # include <map>
66 # include <vector>
67 #endif
68 
69 #ifdef MSQ_USE_OLD_IO_HEADERS
70  class ostream;
71 #else
72 # include <iosfwd>
73 #endif
74 
75 
76 namespace Mesquite
77 {
78  class PatchDataVerticesMemento;
79  class MeshSet;
80  class TargetMatrix;
81 // class SimplifiedGeometryEngine;
82 
87  class PatchData
88  {
89  public:
90  // Constructor/Destructor
91  PatchData();
92  ~PatchData();
93 
94  private:
97  PatchData(const PatchData &pd);
100  PatchData& operator=(const PatchData &pd);
101 
102  public:
103 
113  };
114 
117 
119  { return 0 != (haveComputedInfos&(1<<info)); }
120 
124  void get_minmax_element_unsigned_area(double& min, double& max, MsqError &err);
125 
129  double get_barrier_delta(MsqError &err);
130 
134  double get_average_Lambda_3d(MsqError &err);
135 
137  void clear();
139  void reorder();
140 
146  void allocate_storage( size_t vertex_count,
147  size_t element_count,
148  size_t vertex_use_count,
149  MsqError& err );
150 
151 
172  void initialize_data( size_t* elem_offset_array, MsqError& err );
173 
174 
176  size_t num_vertices() const
177  { return numCornerVertices;}
179  size_t num_elements() const
180  { return elementArray.size(); }
182  size_t num_corners() ;
184  size_t num_nodes() const
185  { return vertexArray.size(); }
186 
190  int num_free_vertices(MsqError &err) const;
191  unsigned num_free_nodes( MsqError& err ) const;
192 
194  const MsqVertex* get_vertex_array( MsqError& err ) const;
196 
198  const MsqMeshEntity* get_element_array( MsqError& err ) const;
200 
202  { return &elemConnectivityArray[0]; }
203 
205  { return &elementHandlesArray[0]; }
206 
211  //const size_t* get_vertex_to_elem_array(MsqError &err);
219  //const size_t* get_vertex_to_elem_offset(MsqError &err);
220 
221  MsqVertex& vertex_by_index(size_t index);
222  MsqMeshEntity& element_by_index(size_t index);
223  size_t get_vertex_index(MsqVertex* vertex);
224  size_t get_element_index(MsqMeshEntity* element);
225 
227  void get_element_vertex_coordinates(size_t elem_index,
228  msq_std::vector<Vector3D> &coords,
229  MsqError &err);
231  void get_element_vertex_indices(size_t elem_index,
232  msq_std::vector<size_t> &vertex_indices,
233  MsqError &err);
235  void get_vertex_element_indices(size_t vertex_index,
236  msq_std::vector<size_t> &elem_indices,
237  MsqError &err);
238 
240  size_t* get_vertex_element_adjacencies( size_t vertex_index,
241  size_t& array_len_out,
242  MsqError& err );
243 
247  void get_adjacent_vertex_indices(size_t vertex_index,
248  msq_std::vector<size_t> &vert_indices,
249  MsqError &err);
250 
251 
258  void get_adjacent_entities_via_n_dim(int n, size_t ent_ind,
259  msq_std::vector<size_t> &adj_ents,
260  MsqError &err);
261 
267 
268  void set_vertex_coordinates(const Vector3D &coords,
269  size_t index,
270  MsqError &err);
275  void snap_vertex_to_domain(size_t vertex_index, MsqError &err);
276 
280  bool domain_set()
281  { return domainSet; }
282 
289  void get_domain_normal_at_vertex(size_t vertex_index, bool normalize,
290  Vector3D &surf_norm,
291  MsqError &err) ;
292 
300  void get_domain_normal_at_element(size_t elem_index, Vector3D &surf_norm,
301  MsqError &err) const;
302 
307  //void get_domain_normal_at_corner( size_t elem_index,
308  // size_t elem_corner,
309  // Vector3D& normal_out,
310  // MsqError& err ) const;
315  void get_domain_normals_at_corners( size_t element_index,
316  Vector3D normals_out[],
317  MsqError& err ) ;
318 
319 
322  Vector3D &surf_norm, MsqError &err) const
323  { get_domain_normal_at_element(size_t(elem_ptr-&(elementArray[0])), surf_norm, err); }
324 
326  /*\param dk an array of directions, ordered like the vertices in
327  the PatchData.
328  \param nb_vtx number of vertices.
329  \param step_size a scalar that multiplies the vectors given in dk.
330  */
331  void move_free_vertices_constrained(Vector3D dk[], size_t nb_vtx,
332  double step_size, MsqError &err);
333 
342  Vector3D dk[], size_t nb_vtx,
343  double step_size, MsqError &err);
344 
348  MsqError &err);
349 
352  void update_mesh(MsqError &err);
353 
360 
367  void get_subpatch(size_t center_vertex_index,
368  PatchData &pd_to_fill,
369  MsqError &err);
370 
374  bool include_higher_order = false );
375 
379  MsqError &err,
380  bool include_higher_order = false );
381 
385  MsqError &err);
386 
388 
392  {
400  };
401 
412  };
413 
414 
415  PatchType type() const
416  { return mType; }
417 
420  void set_mesh_set(MeshSet* ms);
421 
424  { return meshSet; }
425 
428  void clear_tag_data();
429 
430 
432  friend msq_stdio::ostream& operator<<( msq_stdio::ostream&, const PatchData& );
433 
434  private:
435 
437  { haveComputedInfos |= (1<<info); }
438 
440 
441  friend class MeshSet;
442 
444  bool domainSet;
447 
457 
458  // Patch Computed Information (maxs, mins, etc ... )
461 
462  };
463 
464 
473  {
474  public:
476  { delete[] vertices; }
477  private:
478  // Constructor accessible only to originator (i.e. PatchData)
479  friend class PatchData;
481  : originator(0), vertices(0), numVertices(0), arraySize(0)
482  {}
483 
486  size_t numVertices;
487  size_t arraySize;
488  };
489 
490 
491  inline void PatchData::clear()
492  {
493  vertexArray.clear();
494  vertexHandlesArray.clear();
495  elementArray.clear();
496  elementHandlesArray.clear();
500  vertexNormals.clear();
501  numCornerVertices = 0;
502  haveComputedInfos = 0;
503  meshSet = 0;
504  }
505 
506 
507 
508 
513  inline const MsqVertex* PatchData::get_vertex_array(MsqError &err) const
514  {
515  if (vertexArray.empty())
516  MSQ_SETERR(err)( "No vertex array defined", MsqError::INVALID_STATE );
517  return &vertexArray[0];
518  }
520  {
521  if (vertexArray.empty())
522  MSQ_SETERR(err)( "No vertex array defined", MsqError::INVALID_STATE );
523  return &vertexArray[0];
524  }
525 
531  {
532  if (elementArray.empty())
533  MSQ_SETERR(err)( "No element array defined", MsqError::INVALID_STATE );
534  return &elementArray[0];
535  }
537  {
538  if (elementArray.empty())
539  MSQ_SETERR(err)( "No element array defined", MsqError::INVALID_STATE );
540  return &elementArray[0];
541  }
542 
547  inline void PatchData::set_vertex_coordinates(const Vector3D &coords,
548  size_t index,
549  MsqError &err)
550  {
551  if (index >= vertexArray.size()) {
552  MSQ_SETERR(err)( "Index bigger than numVertices.", MsqError::INVALID_ARG );
553  return;
554  }
555 
556  vertexArray[index] = coords;
557  }
558 
559 
562  //inline const size_t* PatchData::get_vertex_to_elem_offset(MsqError &/*err*/)
563  //{
564  // // Make sure we've got the data
565  // if (vertAdjacencyOffsets.empty())
566  // {
567  // generate_vertex_to_element_data();
568  // }
569  // return &vertAdjacencyOffsets[0];
570  //}
571 
574  //inline const size_t* PatchData::get_vertex_to_elem_array(MsqError &/*err*/)
575  //{
576  // // Make sure we've got the data
577  // if (vertAdjacencyArray.empty())
578  // {
579  // generate_vertex_to_element_data();
580  // }
581  // return &vertAdjacencyArray[0];
582  //}
583 
584  inline MsqVertex& PatchData::vertex_by_index(size_t index)
585  {
586  return vertexArray[index];
587  }
588 
590  {
591  return elementArray[index];
592  }
593 
596  inline size_t PatchData::get_vertex_index(MsqVertex* vertex)
597  {
598  return vertex - &vertexArray[0];
599  }
600 
602  {
603  return element - &elementArray[0];
604  }
605 
606 
616  bool include_higher_order)
617  {
618  size_t num_verts = include_higher_order ? num_nodes() : num_vertices();
620  memento->originator = this;
621  if (num_verts)
622  memento->vertices = new MsqVertex[num_verts];
623  memento->numVertices = num_verts;
624  memento->arraySize = num_verts;
625 
626  // Copy the coordinates
627  msq_stdc::memcpy(memento->vertices, &vertexArray[0], num_verts*sizeof(MsqVertex) );
628 
629  return memento;
630  }
631 
641  MsqError& /*err*/,
642  bool include_higher_order)
643  {
644  size_t num_verts = include_higher_order ? num_nodes() : num_vertices();
645  memento->originator = this;
646 
647  if ( num_verts > memento->arraySize
648  || num_verts < memento->arraySize/10)
649  {
650  delete[] memento->vertices;
651  // Allocate the new array
652  memento->vertices = new MsqVertex[num_verts];
653  memento->arraySize = num_verts;
654  }
655 
656  // Copy the coordinates
657  msq_stdc::memcpy(memento->vertices, &vertexArray[0],num_verts*sizeof(MsqVertex) );
658 
659  memento->numVertices = num_verts;
660  }
661 
670  MsqError &err)
671  {
672  if (memento->originator != this)
673  {
674  MSQ_SETERR(err)("Memento may only be used to restore the PatchData "
675  "object from which it was created.",
677  return;
678  }
679 
680  if (memento->numVertices != num_vertices() &&
681  memento->numVertices != num_nodes())
682  {
683  MSQ_SETERR(err)("Unable to restore patch coordinates. Number of "
684  "vertices in PatchData has changed.",
686  return;
687  }
688 
689  // copies the memento array into the PatchData array.
690  msq_stdc::memcpy(&vertexArray[0], memento->vertices, memento->numVertices*sizeof(MsqVertex) );
691  }
692 
693 } // namespace
694 
695 
696 #endif
void update_mesh(MsqError &err)
Updates the underlying mesh (the Mesquite::Mesh implementation) with new node coordinates and flag va...
void set_free_vertices_soft_fixed(MsqError &err)
Add a soft_fixed flag to all free vertices in the patch.
double get_max_vertex_movement_squared(PatchDataVerticesMemento *memento, MsqError &err)
Calculates the distance each vertex has moved from its original position as defined by the PatchDataV...
PatchDataMem< MsqVertex > vertexArray
void set_all_vertices_soft_free(MsqError &err)
Remove the soft_fixed flag from all vertices in the patch.
MsqVertex & vertex_by_index(size_t index)
Returns the start of the vertex-&gt;element array.
CornerTag< TargetMatrix > targetMatrices
Target matrix data.
Used to hold the error state and return it to the application.
void get_domain_normals_at_corners(size_t element_index, Vector3D normals_out[], MsqError &err)
Get surface normal at a point where the surface is the domain of an element and the point is the loca...
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
void recreate_vertices_memento(PatchDataVerticesMemento *memento, MsqError &err, bool include_higher_order=false)
reinstantiates a memento to holds the current state of the PatchData coordinates. ...
DomainHint
A hint on the characteristics of the domain that Mesquite may use to determine what, if any, scheme to use to cache characteristics of the geometric domain.
void allocate_storage(size_t vertex_count, size_t element_count, size_t vertex_use_count, MsqError &err)
Used by test code when creating a PatchData directly.
void get_vertex_element_indices(size_t vertex_index, msq_std::vector< size_t > &elem_indices, MsqError &err)
const Mesh::ElementHandle * get_element_handles_array() const
EntityHandle ElementHandle
MsqMeshEntity is the Mesquite object that stores information about the elements in the mesh...
This file contains the Mesquite mesh interface. Many users will want to implement a concrete class de...
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
void note_have_info(ComputedInfo info)
PatchDataMem< size_t > elemConnectivityArray
void set_to_vertices_memento(PatchDataVerticesMemento *memento, MsqError &err)
Restore the PatchData coordinates to the state contained in the memento.
int num_free_vertices(MsqError &err) const
Returns the number of elements in the current patch who are free to move.
double computedInfos[MAX_COMPUTED_INFO_ENUM]
void initialize_data(size_t *elem_offset_array, MsqError &err)
Call after filling vertex handle and connectivity arrays to finish initializing the PatchData...
PatchDataVerticesMemento * create_vertices_memento(MsqError &err, bool include_higher_order=false)
Creates a memento that holds the current state of the PatchData coordinates.
void get_minmax_element_unsigned_area(double &min, double &max, MsqError &err)
Returns the maximum volume or area out of all the elements in the patch This information is stored in...
void generate_vertex_to_element_data()
average corner determinant out of all elements in the patch
void get_adjacent_entities_via_n_dim(int n, size_t ent_ind, msq_std::vector< size_t > &adj_ents, MsqError &err)
Get the indices of entities attached to entity (given by ent_ind). adj_ents is filled with the indice...
void get_domain_normal_at_element(size_t elem_index, Vector3D &surf_norm, MsqError &err) const
PatchData & operator=(const PatchData &pd)
Doesn&#39;t allow a PatchData object to be assigned to another.
invalid function argument passed
size_t num_elements() const
number of elements in the Patch.
void clear()
Removes data.
void get_subpatch(size_t center_vertex_index, PatchData &pd_to_fill, MsqError &err)
Fills a PatchData with the elements attached to a center vertex.
double get_barrier_delta(MsqError &err)
Returns delta based on the minimum and maximum corner determinant over all elements in the patch This...
void set_vertex_coordinates(const Vector3D &coords, size_t index, MsqError &err)
set the coordinates of a vertex in the raw array
size_t get_element_index(MsqMeshEntity *element)
bool have_computed_info(ComputedInfo info) const
size_t get_vertex_index(MsqVertex *vertex)
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
minimum and maximum corner area out of all elements in the patch
void snap_vertex_to_domain(size_t vertex_index, MsqError &err)
Adjust the position of the specified vertex so that it lies on its constraining domain.
void get_element_vertex_indices(size_t elem_index, msq_std::vector< size_t > &vertex_indices, MsqError &err)
void get_adjacent_vertex_indices(size_t vertex_index, msq_std::vector< size_t > &vert_indices, MsqError &err)
const NT & n
void update_cached_normals(MsqError &)
void clear_computed_info()
This function clears the patch information such as maximum volume, etc ...
PatchType
Tells MeshSet how to retrieve the mesh entities that will be stored in PatchData. ...
size_t num_nodes() const
Get number of nodes (vertex + higher-order nodes)
PatchDataMem< Vector3D > vertexNormals
double get_average_Lambda_3d(MsqError &err)
Returns average corner determinant over all corners in the patch This information is stored in the pa...
maximum edge length in the patch
size_t num_vertices() const
number of vertices in the patch.
MsqMeshEntity & element_by_index(size_t index)
PatchDataMem< size_t > vertAdjacencyOffsets
size_t num_corners()
number of elements corners in the Patch.
A class for caching and managing Tags on element corners.
PatchDataMem< MsqMeshEntity > elementArray
void move_free_vertices_constrained(Vector3D dk[], size_t nb_vtx, double step_size, MsqError &err)
Moves free vertices and then snaps the free vertices to the domain.
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
const MsqVertex * get_vertex_array(MsqError &err) const
Returns a pointer to the start of the vertex array.
void get_domain_normal_at_element(MsqMeshEntity *elem_ptr, Vector3D &surf_norm, MsqError &err) const
Alternative signature. Same functionality.
void set_free_vertices_constrained(PatchDataVerticesMemento *memento, Vector3D dk[], size_t nb_vtx, double step_size, MsqError &err)
void get_domain_normal_at_vertex(size_t vertex_index, bool normalize, Vector3D &surf_norm, MsqError &err)
friend msq_stdio::ostream & operator<<(msq_stdio::ostream &, const PatchData &)
Display the coordinates and connectivity information.
object is in an invalid state
MeshSet * get_mesh_set()
Returns the originating meshSet.
void reorder()
Reorders the mesh data.
PatchDataMem< Mesh::ElementHandle > elementHandlesArray
Contains a copy of the coordinates of a PatchData.
PatchDataMem< Mesh::VertexHandle > vertexHandlesArray
const MsqMeshEntity * get_element_array(MsqError &err) const
Returns a pointer to the start of the element array.
minimum and maximum corner volume out of all elements in the patch
minimum volume or area out of all elements in the patch
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
PatchData * originator
PatchData whose state is kept.
size_t * get_vertex_element_adjacencies(size_t vertex_index, size_t &array_len_out, MsqError &err)
maximum volume or area out of all elements in the patch
void set_all_vertices_soft_fixed(MsqError &err)
Add a soft_fixed flag to all vertices in the patch.
PatchDataMem< size_t > vertAdjacencyArray
MsqVertex * vertices
array of vertices
void set_mesh_set(MeshSet *ms)
Sets the originating meshSet.
void info()
Print informations about CImg environement variables.
Definition: CImg.h:5702
minimum edge length in the patch
The MeshSet class stores one or more Mesquite::Mesh pointers and manages access to the mesh informati...
void get_element_vertex_coordinates(size_t elem_index, msq_std::vector< Vector3D > &coords, MsqError &err)
Get the coordinates of vertices attached to the specified element.
unsigned num_free_nodes(MsqError &err) const