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
147
148
149
150
151
152 | /** \file SweepWrapper.cpp
* \brief
*
*/
#include "Mesquite.hpp"
#include "SweepWrapper.hpp"
#include "InstructionQueue.hpp"
#include "PMeanPTemplate.hpp"
#include "TrustRegion.hpp"
#include "QualityAssessor.hpp"
#include "RefMeshTargetCalculator.hpp"
#include "ReferenceMesh.hpp"
#include "TagVertexMesh.hpp"
#include "TQualityMetric.hpp"
#include "ConjugateGradient.hpp"
#include "SteepestDescent.hpp"
#include "QuasiNewton.hpp"
#include "NonSmoothDescent.hpp"
//#include "TRel2DShape.hpp"
//#include "TRel3DShape.hpp"
#include "TShapeNB1.hpp"
#include "MsqError.hpp"
#include "MsqMatrix.hpp"
namespace MESQUITE_NS {
class TargetFlipper : public TargetCalculator
{
public:
TargetFlipper( TargetCalculator* unflipped ) : realTargets(unflipped) {}
bool get_3D_target( PatchData& pd,
size_t element,
Sample sample,
MsqMatrix<3,3>& W_out,
MsqError& err );
bool get_2D_target( PatchData& pd,
size_t element,
Sample sample,
MsqMatrix<2,2>& W_out,
MsqError& err );
bool have_surface_orient() const;
bool get_surface_target( PatchData& pd,
size_t element,
Sample sample,
MsqMatrix<3,2>& W_out,
MsqError& err );
private:
TargetCalculator* realTargets;
};
bool TargetFlipper::get_3D_target( PatchData& pd,
size_t element,
Sample sample,
MsqMatrix<3,3>& W_out,
MsqError& err )
{
return realTargets->get_3D_target(pd, element, sample, W_out, err);
}
bool TargetFlipper::get_2D_target( PatchData& pd,
size_t element,
Sample sample,
MsqMatrix<2,2>& W_out,
MsqError& err )
{
return realTargets->get_2D_target( pd, element, sample, W_out, err );
}
bool TargetFlipper::have_surface_orient() const
{ return false; }<--- The function 'have_surface_orient' is never used.
bool TargetFlipper::get_surface_target( PatchData& pd,
size_t element,
Sample sample,
MsqMatrix<3,2>& W_out,
MsqError& err )
{
bool valid = realTargets->get_surface_target( pd, element, sample, W_out, err );
if (MSQ_CHKERR(err) || !valid) return false;
if (pd.domain_set()) {
Vector3D norm;
pd.get_domain_normal_at_sample( element, sample, norm, err );
MSQ_ERRZERO(err);
MsqVector<3> c0(W_out.column(0)), c1(W_out.column(1));
if ((c0 * c1) % MsqVector<3>(&norm[0]) < 0.0) {
W_out.set_column(0, c1);
W_out.set_column(1, c0);
}
}
return true;
}
void SweepWrapper::run_wrapper( Mesh* mesh,
ParallelMesh* pmesh,
MeshDomain* domain,
Settings* settings,
QualityAssessor* qa,
MsqError& err )
{
// construct target calculator
TagVertexMesh source_mesh( err, mesh, false, initMeshTag.c_str() ); MSQ_ERRRTN(err);
ReferenceMesh ref_mesh( &source_mesh );
RefMeshTargetCalculator ref_tc( &ref_mesh );
TargetFlipper flipped_targets( &ref_tc );
// construct objective function
//TRel2DShape shape2d;
//TRel3DShape shape3d;
TShapeNB1 shape;
//TShapeNB1 shape3d;
TQualityMetric metric(&flipped_targets, &shape);
PMeanPTemplate objfunc( 2.0, &metric );
// construct smoother
//TrustRegion solver(&objfunc);
//ConjugateGradient solver(&objfunc);
SteepestDescent solver(&objfunc);
//QuasiNewton solver(&objfunc);
TerminationCriterion terminate;
terminate.add_absolute_vertex_movement( maxVtxMovement );
terminate.write_iterations( "mesquite.gpt", err );
solver.set_inner_termination_criterion( &terminate );
// construct instruction queue
qa->add_quality_assessment( &metric );
InstructionQueue q;
q.add_quality_assessor( qa, err );
MSQ_ERRRTN(err);
q.set_master_quality_improver( &solver, err );
MSQ_ERRRTN(err);
q.add_quality_assessor( qa, err );
MSQ_ERRRTN(err);
// smooth mesh
q.run_common( mesh, pmesh, domain, settings, err );
MSQ_ERRRTN(err);
}
} // namespace MESQUITE_NS
|