MOAB: Mesh Oriented datABase  (version 5.4.1)
Instruction.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government retains certain
00007     rights in this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected]
00025 
00026   ***************************************************************** */
00027 // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3
00028 // -*-
00029 
00030 /*! \file Instruction.cpp
00031 Default implementation for Instruction::loop_over_mesh( ParallelMesh* mesh, ...)
00032 so we do not force every class that derives from Instruction to implement this
00033 parallel function.
00034 
00035   \author Martin Isenburg
00036   \date   2008-04-03
00037  */
00038 
00039 #include "Instruction.hpp"
00040 #include "MeshInterface.hpp"
00041 #include "MsqError.hpp"
00042 #include "MsqVertex.hpp"
00043 #include "Settings.hpp"
00044 
00045 using namespace MBMesquite;
00046 
00047 Instruction::~Instruction() {}
00048 
00049 double Instruction::loop_over_mesh( ParallelMesh* mesh, MeshDomain* domain, const Settings* settings, MsqError& err )
00050 {
00051     MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( (Mesh*)mesh, domain, false, true );
00052     return loop_over_mesh( &mesh_and_domain, settings, err );
00053 }
00054 
00055 void Instruction::initialize_vertex_byte( MeshDomainAssoc* mesh_and_domain, const Settings* settings, MsqError& err )
00056 {
00057     std::vector< Mesh::VertexHandle > verts;
00058     std::vector< unsigned char > bytes;
00059 
00060     Mesh* mesh         = mesh_and_domain->get_mesh();
00061     MeshDomain* domain = mesh_and_domain->get_domain();
00062 
00063     // Handle SLAVE_ALL first because we want to work with vertices
00064     // in element connectivity lists rather than one big array of
00065     // vertex handles.
00066     bool use_existing_slaved_flag = false;
00067     if( !settings || settings->get_slaved_ho_node_mode() == Settings::SLAVE_ALL )
00068     {
00069         std::vector< Mesh::ElementHandle > elems;
00070         std::vector< size_t > junk;
00071         mesh->get_all_elements( elems, err );MSQ_ERRRTN( err );
00072         for( size_t i = 0; i < elems.size(); ++i )
00073         {
00074             EntityTopology type;
00075             mesh->elements_get_topologies( &elems[i], &type, 1, err );MSQ_ERRRTN( err );
00076             unsigned ncorner = TopologyInfo::corners( type );
00077 
00078             verts.clear();
00079             junk.clear();
00080             mesh->elements_get_attached_vertices( &elems[i], 1, verts, junk, err );MSQ_ERRRTN( err );
00081             if( ncorner < verts.size() && type != POLYGON ) use_existing_slaved_flag = true;
00082 
00083             bytes.clear();
00084             bytes.resize( verts.size(), 0 );
00085             std::fill( bytes.begin() + TopologyInfo::corners( type ), bytes.end(), MsqVertex::MSQ_DEPENDENT );
00086             mesh->vertices_set_byte( arrptr( verts ), arrptr( bytes ), verts.size(), err );MSQ_ERRRTN( err );
00087         }
00088     }
00089     else if( settings && settings->get_slaved_ho_node_mode() == Settings::SLAVE_CALCULATED )
00090         use_existing_slaved_flag = true;
00091 
00092     std::vector< bool > flags;
00093     verts.clear();
00094     mesh->get_all_vertices( verts, err );MSQ_ERRRTN( err );
00095     bytes.clear();
00096     bytes.resize( verts.size(), 0 );
00097 
00098     // Normally we start out with all bits cleared.  However, if
00099     // we're doing SLAVE_CALCULATED mode then we need to perserve
00100     // the exinsting value of that bit because it was presumably
00101     // set by a previous tool in the InstructionQueue.  Also, if doing
00102     // SLAVE_ALL, preserve the value we just set.
00103     if( use_existing_slaved_flag )
00104     {
00105         mesh->vertices_get_byte( arrptr( verts ), arrptr( bytes ), verts.size(), err );MSQ_ERRRTN( err );
00106         for( size_t i = 0; i < bytes.size(); ++i )
00107             bytes[i] &= (unsigned char)MsqVertex::MSQ_DEPENDENT;
00108     }
00109     // If getting slaved flag for higher-order nodes from application,
00110     // copy it into vertex byte now.
00111     else if( settings && settings->get_slaved_ho_node_mode() == Settings::SLAVE_FLAG )
00112     {
00113         mesh->vertices_get_slaved_flag( arrptr( verts ), flags, verts.size(), err );MSQ_ERRRTN( err );
00114         for( size_t i = 0; i < bytes.size(); ++i )
00115             if( flags[i] ) bytes[i] |= (unsigned char)MsqVertex::MSQ_DEPENDENT;
00116     }
00117 
00118     // If using application-specified fixed flag, copy that into
00119     // vertex byte now.
00120     if( !settings || settings->get_fixed_vertex_mode() == Settings::FIXED_FLAG )
00121     {
00122         mesh->vertices_get_fixed_flag( arrptr( verts ), flags, verts.size(), err );MSQ_ERRRTN( err );
00123         for( size_t i = 0; i < bytes.size(); ++i )
00124             if( flags[i] ) bytes[i] |= (unsigned char)MsqVertex::MSQ_HARD_FIXED;
00125     }
00126     // otherwise need to mark vertices as fixed based on geometric domain
00127     else
00128     {
00129         if( !domain )
00130         {
00131             MSQ_SETERR( err )
00132             ( "Request to fix vertices by domain classification "
00133               "requres a domain.",
00134               MsqError::INVALID_STATE );
00135             return;
00136         }
00137         const unsigned short dim = settings->get_fixed_vertex_mode();
00138         assert( dim < 4u );
00139         std::vector< unsigned short > dof( verts.size() );
00140         domain->domain_DoF( arrptr( verts ), arrptr( dof ), verts.size(), err );MSQ_ERRRTN( err );
00141         for( size_t i = 0; i < bytes.size(); ++i )
00142             if( dof[i] <= dim ) bytes[i] |= (unsigned char)MsqVertex::MSQ_HARD_FIXED;
00143     }
00144 
00145     // Copy flag values back to mesh instance
00146     mesh->vertices_set_byte( arrptr( verts ), arrptr( bytes ), verts.size(), err );MSQ_ERRRTN( err );
00147 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines