Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
inks/MeanMidNodeMover.cpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Lawrence Livermore National Laboratory. Under
5  the terms of Contract B545069 with the University of Wisconsin --
6  Madison, Lawrence Livermore National Laboratory 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  kraftche@cae.wisc.edu
24 
25  ***************************************************************** */
26 
27 #include "MeanMidNodeMover.hpp"
28 #include "MsqError.hpp"
29 #include "MsqFreeVertexIndexIterator.hpp"
30 #include "TopologyInfo.hpp"
31 
32 namespace Mesquite {
33 
35 {
36  MsqError err;
38  MSQ_CHKERR(err);
39 }
40 
42 
43 void MeanMidNodeMover::set_patch_type( PatchData::PatchType, MsqError &err, int , int )
44 {
45  MSQ_SETERR(err)("Patch type cannot be changed for MeanMidNodeMover.",MsqError::INVALID_ARG);
46  return;
47 }
48 
49 msq_std::string MeanMidNodeMover::get_name()
50 { return "MeanMidNodeMover"; }
51 
54 
55 
56 double MeanMidNodeMover::loop_over_mesh( MeshSet& ms, MsqError& err )
57 {
60  return 0;
61  }
62 
63  if (!get_global_patch()) {
64  MSQ_SETERR(err)("No global patch", MsqError::INVALID_STATE);
65  return 0;
66  }
67 
68  PatchData& pd = *get_global_patch();
69 
70  // For each higher-order node in the patch
71  for (size_t vtx = pd.num_vertices(); vtx < pd.num_nodes(); ++vtx)
72  {
73  // Get an adjacent element
74  size_t num_elems, *elem_list;
75  elem_list = pd.get_vertex_element_adjacencies( vtx, num_elems, err ); MSQ_ERRZERO(err);
76  if (num_elems < 1) // Mid-node without adjacent elements????
77  continue;
78  size_t element_index = elem_list[0];
79  MsqMeshEntity& element = pd.element_by_index( element_index );
80 
81  // Find position of current vertex in element connectivity list
82  unsigned elem_vert_index;
83  size_t num_verts = element.node_count();
84  size_t* vert_list = element.get_vertex_index_array();
85  for (elem_vert_index = 0; elem_vert_index < num_verts; ++elem_vert_index)
86  if (vert_list[elem_vert_index] == vtx)
87  break;
88 
89  // Sanity checks
90  // Mesh is corrupt if vertex not in connectivity list
91  if (elem_vert_index == num_verts)
92  {
93  MSQ_SETERR(err)("Inconsistent connectivity/adjacency data.", MsqError::INVALID_MESH );
94  return 0;
95  }
96  // Must be appropriate element type (e.g. can't have higher-order
97  // nodes on a polygon)
98  EntityTopology topo = element.get_element_type();
99  unsigned num_corners = TopologyInfo::corners( topo );
100  if (!num_corners)
101  {
103  "Element type %d cannot have higher-order nodes.",
104  (int)topo );
105  return 0;
106  }
107  // The current vertex must be one of the higher-order nodes of the element
108  if (elem_vert_index < num_corners)
109  {
110  MSQ_SETERR(err)( "Invalid mid-node flag for mesh (mixed connectivity?)",
112  return 9;
113  }
114 
115  // Get the element "side" that the node is a mid-node of.
116  unsigned side, dimension;
117  TopologyInfo::side_number( topo, element.node_count(), elem_vert_index,
118  side, dimension, err ); MSQ_ERRZERO(err);
119  // Get the indices of the vertices defining the "side"
120  unsigned side_size;
121  const unsigned* side_indices =
122  TopologyInfo::side_vertices( topo, side, dimension, side_size, err ); MSQ_ERRZERO(err);
123  if (!side_size)
124  {
126  return 0;
127  }
128 
129  // Calculate average position of side vertices
130  const msq_stdc::size_t* conn_array = element.get_vertex_index_array();
131  Vector3D pos(0,0,0);
132  for (unsigned i = 0; i < side_size; ++i)
133  pos += pd.vertex_by_index( conn_array[side_indices[i]] );
134  pos /= side_size;
135 
136  // Set new vertex position
137  pd.set_vertex_coordinates( pos, vtx, err ); MSQ_ERRZERO(err);
138  pd.snap_vertex_to_domain( vtx, err ); MSQ_ERRZERO(err);
139  }
140 
141  pd.update_mesh(err); MSQ_ERRZERO(err);
142 
143  return 0;
144 }
145 
146 
147 
148 } // namespace Mesquite
149 
150 
151 
152 
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
virtual double loop_over_mesh(MeshSet &ms, MsqError &err)
This is the &quot;run&quot; function of PatchDataUser. It can do anything really.
virtual void set_patch_type(PatchData::PatchType patch_type, MsqError &err, int param1=0, int param2=0)
Sets the Patch Type.
EntityTopology
Definition: Mesquite.hpp:92
virtual void set_patch_type(PatchData::PatchType patch_type, MsqError &err, int param1=0, int param2=0)
Sets the Patch Type.
invalid function argument passed
NVec< 3, double > Vector3D
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
static unsigned corners(EntityTopology topo)
Get the number of defining vertices for a given element topology.
blockLoc i
Definition: read.cpp:79
PatchData::PatchType get_patch_type()
Returns the Patch Type.
PatchType
Tells MeshSet how to retrieve the mesh entities that will be stored in PatchData. ...
static const unsigned * side_vertices(EntityTopology topo, unsigned side_dimension, unsigned side_number, unsigned &num_verts_out, MsqError &err)
Get corner indices of side.
PatchData * get_global_patch()
Returns the Global Patch.
object is in an invalid state
virtual PatchDataUser::AlgorithmType get_algorithm_type()
Return the algorithm type (to avoid RTTI use).
static void side_number(EntityTopology topo, unsigned connectivity_length, unsigned node_index, unsigned &side_dimension_out, unsigned &side_number_out, MsqError &err)
Return which side the specified mid-node lies on.
virtual msq_std::string get_name()
Returns the algorithm name.