1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 | /* *****************************************************************
MESQUITE -- The Mesh Quality Improvement Toolkit
Copyright 2004 Sandia Corporation and Argonne National
Laboratory. Under the terms of Contract DE-AC04-94AL85000
with Sandia Corporation, the U.S. Government retains certain
rights in this software.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
(lgpl.txt) along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
[email protected], [email protected], [email protected],
[email protected], [email protected], [email protected]
***************************************************************** */
/*! \file EdgeLengthRangeQualityMetric.cpp
\author Michael Brewer
\date 2002-05-14
Evaluates the lengths of the edges attached to the given vertex.
By default, the averaging method is set to SUM.
*/
#include "EdgeLengthRangeQualityMetric.hpp"
#include "Vector3D.hpp"
#include "QualityMetric.hpp"
#include "MsqVertex.hpp"
#include "PatchData.hpp"
#include "MsqDebug.hpp"
#include "MsqError.hpp"
#include <vector>
using std::vector;
using namespace MBMesquite;
EdgeLengthRangeQualityMetric::EdgeLengthRangeQualityMetric( double low_a, double high_a )
: AveragingQM( SUM ), highVal( high_a ), lowVal( low_a )
{
if( lowVal > highVal ) std::swap( lowVal, highVal );
}
EdgeLengthRangeQualityMetric::~EdgeLengthRangeQualityMetric() {}
std::string EdgeLengthRangeQualityMetric::get_name() const
{
return "Edge Length Range Metric";
}
int EdgeLengthRangeQualityMetric::get_negate_flag() const
{
return 1;
}
/*!For the given vertex, vert, with connected edges of lengths l_j for
j=1...k, the metric value is the average (where the default average
type is SUM) of
u_j = ( | l_j - lowVal | - (l_j - lowVal) )^2 +
( | highVal - l_j | - (highVal - l_j) )^2.
*/
bool EdgeLengthRangeQualityMetric::evaluate_common( PatchData& pd,
size_t this_vert,
double& fval,
std::vector< size_t >& adj_verts,
MsqError& err )
{
fval = 0.0;
Vector3D edg;
pd.get_adjacent_vertex_indices( this_vert, adj_verts, err );
MSQ_ERRZERO( err );
int num_sample_points = adj_verts.size();
double* metric_values = new double[num_sample_points];
const MsqVertex* verts = pd.get_vertex_array( err );
MSQ_ERRZERO( err );
// store the length of the edge, and the first and second component of
// metric values, respectively.
double temp_length = 0.0;<--- The scope of the variable 'temp_length' can be reduced. [+]The scope of the variable 'temp_length' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:<--- Variable 'temp_length' is assigned a value that is never used.
void f(int x)<--- Variable 'temp_length' is assigned a value that is never used.
{<--- Variable 'temp_length' is assigned a value that is never used.
int i = 0;<--- Variable 'temp_length' is assigned a value that is never used.
if (x) {<--- Variable 'temp_length' is assigned a value that is never used.
// it's safe to move 'int i = 0;' here<--- Variable 'temp_length' is assigned a value that is never used.
for (int n = 0; n < 10; ++n) {<--- Variable 'temp_length' is assigned a value that is never used.
// it is possible but not safe to move 'int i = 0;' here<--- Variable 'temp_length' is assigned a value that is never used.
do_something(&i);<--- Variable 'temp_length' is assigned a value that is never used.
}<--- Variable 'temp_length' is assigned a value that is never used.
}<--- Variable 'temp_length' is assigned a value that is never used.
}<--- Variable 'temp_length' is assigned a value that is never used.
When you see this message it is always safe to reduce the variable scope 1 level. <--- Variable 'temp_length' is assigned a value that is never used.
double temp_first = 0.0;<--- The scope of the variable 'temp_first' can be reduced. [+]The scope of the variable 'temp_first' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:<--- Variable 'temp_first' is assigned a value that is never used.
void f(int x)<--- Variable 'temp_first' is assigned a value that is never used.
{<--- Variable 'temp_first' is assigned a value that is never used.
int i = 0;<--- Variable 'temp_first' is assigned a value that is never used.
if (x) {<--- Variable 'temp_first' is assigned a value that is never used.
// it's safe to move 'int i = 0;' here<--- Variable 'temp_first' is assigned a value that is never used.
for (int n = 0; n < 10; ++n) {<--- Variable 'temp_first' is assigned a value that is never used.
// it is possible but not safe to move 'int i = 0;' here<--- Variable 'temp_first' is assigned a value that is never used.
do_something(&i);<--- Variable 'temp_first' is assigned a value that is never used.
}<--- Variable 'temp_first' is assigned a value that is never used.
}<--- Variable 'temp_first' is assigned a value that is never used.
}<--- Variable 'temp_first' is assigned a value that is never used.
When you see this message it is always safe to reduce the variable scope 1 level. <--- Variable 'temp_first' is assigned a value that is never used.
double temp_second = 0.0;<--- The scope of the variable 'temp_second' can be reduced. [+]The scope of the variable 'temp_second' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:<--- Variable 'temp_second' is assigned a value that is never used.
void f(int x)<--- Variable 'temp_second' is assigned a value that is never used.
{<--- Variable 'temp_second' is assigned a value that is never used.
int i = 0;<--- Variable 'temp_second' is assigned a value that is never used.
if (x) {<--- Variable 'temp_second' is assigned a value that is never used.
// it's safe to move 'int i = 0;' here<--- Variable 'temp_second' is assigned a value that is never used.
for (int n = 0; n < 10; ++n) {<--- Variable 'temp_second' is assigned a value that is never used.
// it is possible but not safe to move 'int i = 0;' here<--- Variable 'temp_second' is assigned a value that is never used.
do_something(&i);<--- Variable 'temp_second' is assigned a value that is never used.
}<--- Variable 'temp_second' is assigned a value that is never used.
}<--- Variable 'temp_second' is assigned a value that is never used.
}<--- Variable 'temp_second' is assigned a value that is never used.
When you see this message it is always safe to reduce the variable scope 1 level. <--- Variable 'temp_second' is assigned a value that is never used.
// PRINT_INFO("INSIDE ELR, vertex =
// %f,%f,%f\n",verts[this_vert][0],verts[this_vert][1],verts[this_vert][2]); loop while there are
// still more adjacent vertices.
for( unsigned i = 0; i < adj_verts.size(); ++i )
{
edg = verts[this_vert] - verts[adj_verts[i]];
// compute the edge length
temp_length = edg.length();
// get the first component
temp_first = temp_length - lowVal;
temp_first = fabs( temp_first ) - ( temp_first );
temp_first *= temp_first;
// get the second component
temp_second = highVal - temp_length;
temp_second = fabs( temp_second ) - ( temp_second );
temp_second *= temp_second;
// combine the two components
metric_values[i] = temp_first + temp_second;
}
// average the metric values of the edges
fval = average_metrics( metric_values, num_sample_points, err );
// clean up
delete[] metric_values;
// always return true because mesh is always valid wrt this metric.
return !MSQ_CHKERR( err );
}
bool EdgeLengthRangeQualityMetric::evaluate( PatchData& pd, size_t vertex, double& value, MsqError& err )
{
std::vector< size_t > verts;
bool rval = evaluate_common( pd, vertex, value, verts, err );
return !MSQ_CHKERR( err ) && rval;
}
bool EdgeLengthRangeQualityMetric::evaluate_with_indices( PatchData& pd,
size_t vertex,
double& value,
std::vector< size_t >& indices,
MsqError& err )
{
indices.clear();
bool rval = evaluate_common( pd, vertex, value, indices, err );
std::vector< size_t >::iterator r, w;
for( r = w = indices.begin(); r != indices.end(); ++r )
{
if( *r < pd.num_free_vertices() )
{
*w = *r;
++w;
}
}
indices.erase( w, indices.end() );
if( vertex < pd.num_free_vertices() ) indices.push_back( vertex );
return !MSQ_CHKERR( err ) && rval;
}
|