Branch data Line data Source code
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 : : [email protected], [email protected], [email protected],
24 : : [email protected], [email protected], [email protected]
25 : :
26 : : ***************************************************************** */
27 : : // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3
28 : : // -*-
29 : :
30 : : /*! \file Instruction.cpp
31 : : Default implementation for Instruction::loop_over_mesh( ParallelMesh* mesh, ...)
32 : : so we do not force every class that derives from Instruction to implement this
33 : : parallel function.
34 : :
35 : : \author Martin Isenburg
36 : : \date 2008-04-03
37 : : */
38 : :
39 : : #include "Instruction.hpp"
40 : : #include "MeshInterface.hpp"
41 : : #include "MsqError.hpp"
42 : : #include "MsqVertex.hpp"
43 : : #include "Settings.hpp"
44 : :
45 : : using namespace MBMesquite;
46 : :
47 [ - + ]: 532 : Instruction::~Instruction() {}
48 : :
49 : 0 : double Instruction::loop_over_mesh( ParallelMesh* mesh, MeshDomain* domain, const Settings* settings, MsqError& err )
50 : : {
51 [ # # ]: 0 : MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( (Mesh*)mesh, domain, false, true );
52 [ # # ]: 0 : return loop_over_mesh( &mesh_and_domain, settings, err );
53 : : }
54 : :
55 : 272 : void Instruction::initialize_vertex_byte( MeshDomainAssoc* mesh_and_domain, const Settings* settings, MsqError& err )
56 : : {
57 [ + - ]: 272 : std::vector< Mesh::VertexHandle > verts;
58 [ + - ][ + - ]: 544 : std::vector< unsigned char > bytes;
59 : :
60 [ + - ]: 272 : Mesh* mesh = mesh_and_domain->get_mesh();
61 [ + - ]: 272 : MeshDomain* domain = mesh_and_domain->get_domain();
62 : :
63 : : // Handle SLAVE_ALL first because we want to work with vertices
64 : : // in element connectivity lists rather than one big array of
65 : : // vertex handles.
66 : 272 : bool use_existing_slaved_flag = false;
67 [ + - ][ + - ]: 272 : if( !settings || settings->get_slaved_ho_node_mode() == Settings::SLAVE_ALL )
[ + + ][ + + ]
68 : : {
69 [ + - ]: 263 : std::vector< Mesh::ElementHandle > elems;
70 [ + - ][ + - ]: 526 : std::vector< size_t > junk;
71 [ + - ][ + - ]: 263 : mesh->get_all_elements( elems, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
72 [ + + ][ + - ]: 398897 : for( size_t i = 0; i < elems.size(); ++i )
73 : : {
74 : : EntityTopology type;
75 [ + - ][ + - ]: 398634 : mesh->elements_get_topologies( &elems[i], &type, 1, err );MSQ_ERRRTN( err );
[ + - ][ - + ]
[ # # ][ # # ]
[ - + ]
76 [ + - ]: 398634 : unsigned ncorner = TopologyInfo::corners( type );
77 : :
78 : 398634 : verts.clear();
79 : 398634 : junk.clear();
80 [ + - ][ + - ]: 398634 : mesh->elements_get_attached_vertices( &elems[i], 1, verts, junk, err );MSQ_ERRRTN( err );
[ + - ][ - + ]
[ # # ][ # # ]
[ - + ]
81 [ + + ][ + + ]: 398634 : if( ncorner < verts.size() && type != POLYGON ) use_existing_slaved_flag = true;
[ + + ]
82 : :
83 : 398634 : bytes.clear();
84 [ + - ]: 398634 : bytes.resize( verts.size(), 0 );
85 [ + - ][ + - ]: 398634 : std::fill( bytes.begin() + TopologyInfo::corners( type ), bytes.end(), MsqVertex::MSQ_DEPENDENT );
[ + - ]
86 [ + - ][ + - ]: 398634 : mesh->vertices_set_byte( arrptr( verts ), arrptr( bytes ), verts.size(), err );MSQ_ERRRTN( err );
[ + - ][ + - ]
[ - + ][ # # ]
[ # # ][ - + ]
87 : 263 : }
88 : : }
89 [ + - ][ + - ]: 9 : else if( settings && settings->get_slaved_ho_node_mode() == Settings::SLAVE_CALCULATED )
[ + + ][ + + ]
90 : 2 : use_existing_slaved_flag = true;
91 : :
92 [ + - ][ + - ]: 544 : std::vector< bool > flags;
93 : 272 : verts.clear();
94 [ + - ][ + - ]: 272 : mesh->get_all_vertices( verts, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
95 : 272 : bytes.clear();
96 [ + - ]: 272 : bytes.resize( verts.size(), 0 );
97 : :
98 : : // Normally we start out with all bits cleared. However, if
99 : : // we're doing SLAVE_CALCULATED mode then we need to perserve
100 : : // the exinsting value of that bit because it was presumably
101 : : // set by a previous tool in the InstructionQueue. Also, if doing
102 : : // SLAVE_ALL, preserve the value we just set.
103 [ + + ]: 272 : if( use_existing_slaved_flag )
104 : : {
105 [ + - ][ + - ]: 5 : mesh->vertices_get_byte( arrptr( verts ), arrptr( bytes ), verts.size(), err );MSQ_ERRRTN( err );
[ + - ][ + - ]
[ - + ][ # # ]
[ # # ][ - + ]
106 [ + + ]: 529 : for( size_t i = 0; i < bytes.size(); ++i )
107 [ + - ]: 524 : bytes[i] &= (unsigned char)MsqVertex::MSQ_DEPENDENT;
108 : : }
109 : : // If getting slaved flag for higher-order nodes from application,
110 : : // copy it into vertex byte now.
111 [ + - ][ + - ]: 267 : else if( settings && settings->get_slaved_ho_node_mode() == Settings::SLAVE_FLAG )
[ + + ][ + + ]
112 : : {
113 [ + - ][ + - ]: 3 : mesh->vertices_get_slaved_flag( arrptr( verts ), flags, verts.size(), err );MSQ_ERRRTN( err );
[ + - ][ - + ]
[ # # ][ # # ]
[ - + ]
114 [ + + ]: 366 : for( size_t i = 0; i < bytes.size(); ++i )
115 [ + - ][ + + ]: 363 : if( flags[i] ) bytes[i] |= (unsigned char)MsqVertex::MSQ_DEPENDENT;
[ + - ]
116 : : }
117 : :
118 : : // If using application-specified fixed flag, copy that into
119 : : // vertex byte now.
120 [ + - ][ + - ]: 272 : if( !settings || settings->get_fixed_vertex_mode() == Settings::FIXED_FLAG )
[ + - ][ + - ]
121 : : {
122 [ + - ][ + - ]: 272 : mesh->vertices_get_fixed_flag( arrptr( verts ), flags, verts.size(), err );MSQ_ERRRTN( err );
[ + - ][ - + ]
[ # # ][ # # ]
[ - + ]
123 [ + + ]: 213834 : for( size_t i = 0; i < bytes.size(); ++i )
124 [ + - ][ + + ]: 213562 : if( flags[i] ) bytes[i] |= (unsigned char)MsqVertex::MSQ_HARD_FIXED;
[ + - ]
125 : : }
126 : : // otherwise need to mark vertices as fixed based on geometric domain
127 : : else
128 : : {
129 [ # # ]: 0 : if( !domain )
130 : : {
131 : : MSQ_SETERR( err )
132 : : ( "Request to fix vertices by domain classification "
133 : : "requres a domain.",
134 [ # # ][ # # ]: 0 : MsqError::INVALID_STATE );
135 : 0 : return;
136 : : }
137 [ # # ]: 0 : const unsigned short dim = settings->get_fixed_vertex_mode();
138 [ # # ]: 0 : assert( dim < 4u );
139 [ # # ]: 0 : std::vector< unsigned short > dof( verts.size() );
140 [ # # ][ # # ]: 0 : domain->domain_DoF( arrptr( verts ), arrptr( dof ), verts.size(), err );MSQ_ERRRTN( err );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
141 [ # # ][ # # ]: 0 : for( size_t i = 0; i < bytes.size(); ++i )
142 [ # # ][ # # ]: 0 : if( dof[i] <= dim ) bytes[i] |= (unsigned char)MsqVertex::MSQ_HARD_FIXED;
[ # # ]
143 : : }
144 : :
145 : : // Copy flag values back to mesh instance
146 [ + - ][ + - ]: 544 : mesh->vertices_set_byte( arrptr( verts ), arrptr( bytes ), verts.size(), err );MSQ_ERRRTN( err );
[ + - ][ + - ]
[ - + ][ # # ]
[ # # ][ - + ]
[ + - ]
147 [ + - ][ + - ]: 124 : }
|