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 diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
24 pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
25
26 ***************************************************************** */
27 // -*- Mode : c++; tab-width: 2; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 2 -*-
28 //
29 // SUMMARY:
30 // USAGE:
31 //
32 // ORIG-DATE: 19-Feb-02 at 10:57:52
33 // LAST-MOD: 23-Jul-03 at 18:08:13 by Thomas Leurent
34 //
35 //
36 // DESCRIPTION:
37 // ============
38 /*! \file main.cpp
39
40 describe main.cpp here
41
42 */
43 // DESCRIP-END.
44 //
45
46 #include "MeshImpl.hpp"
47 #include "MsqTimer.hpp"
48 #include "Mesquite.hpp"
49 #include "MsqError.hpp"
50 #include "Vector3D.hpp"
51 #include "InstructionQueue.hpp"
52 #include "PatchData.hpp"
53 #include "TerminationCriterion.hpp"
54 #include "QualityAssessor.hpp"
55 #include "TestUtil.hpp"
56
57 // algorithms
58 #include "Randomize.hpp"
59 #include "ConditionNumberQualityMetric.hpp"
60 #include "UntangleBetaQualityMetric.hpp"
61 #include "LPtoPTemplate.hpp"
62 #include "LInfTemplate.hpp"
63 #include "SteepestDescent.hpp"
64 #include "ConjugateGradient.hpp"
65 #include "PlanarDomain.hpp"
66
67 #include <iostream>
68 using std::cout;
69 using std::endl;
70 #include <cstdlib>
71
72 using namespace MBMesquite;
73
74 std::string DEFAULT_MESH = TestDir + "/2D/vtk/quads/tangled/tangled_quad.vtk";
75
76 const bool brief_output = true;
77 const bool write_output = false;
78
main()79 int main( )
80 {
81 MBMesquite::MeshImpl mesh;
82 MsqPrintError err(cout);
83 mesh.read_vtk(DEFAULT_MESH.c_str(), err);
84 if (err) return 1;
85
86 // Set Domain Constraint
87 Vector3D pnt(0,0,5);
88 Vector3D s_norm(0,0,1);
89 PlanarDomain msq_geom(s_norm, pnt);
90
91 // creates an intruction queue
92 InstructionQueue queue1;
93
94 // creates a mean ratio quality metric ...
95 ConditionNumberQualityMetric shape_metric;
96 UntangleBetaQualityMetric untangle(2);
97 Randomize pass0(.05);
98 // ... and builds an objective function with it
99 //LInfTemplate* obj_func = new LInfTemplate(shape_metric);
100 LInfTemplate obj_func(&untangle);
101 LPtoPTemplate obj_func2(&shape_metric, 2, err);
102 if (err) return 1;
103 // creates the steepest descent optimization procedures
104 ConjugateGradient pass1( &obj_func, err );
105 if (err) return 1;
106
107 //SteepestDescent* pass2 = new SteepestDescent( obj_func2 );
108 ConjugateGradient pass2( &obj_func2, err );
109 if (err) return 1;
110 pass2.use_element_on_vertex_patch();
111 if (err) return 1;
112 pass2.use_global_patch();
113 if (err) return 1;
114 QualityAssessor stop_qa=QualityAssessor(&shape_metric);
115 QualityAssessor stop_qa2=QualityAssessor(&shape_metric);
116 if (brief_output) {
117 stop_qa.disable_printing_results();
118 stop_qa2.disable_printing_results();
119 }
120
121 stop_qa.add_quality_assessment(&untangle);
122 // **************Set stopping criterion**************
123 //untangle beta should be 0 when untangled
124 TerminationCriterion sc1;
125 sc1.add_relative_quality_improvement( 0.000001 );
126 TerminationCriterion sc3;
127 sc3.add_iteration_limit( 10 );
128 TerminationCriterion sc_rand;
129 sc_rand.add_iteration_limit( 1 );
130
131 //StoppingCriterion sc1(&stop_qa,-1.0,.0000001);
132 //StoppingCriterion sc3(&stop_qa2,.9,1.00000001);
133 //StoppingCriterion sc2(StoppingCriterion::NUMBER_OF_PASSES,10);
134 //StoppingCriterion sc_rand(StoppingCriterion::NUMBER_OF_PASSES,1);
135 //either until untangled or 10 iterations
136 pass0.set_outer_termination_criterion(&sc_rand);
137 pass1.set_outer_termination_criterion(&sc1);
138 pass2.set_inner_termination_criterion(&sc3);
139
140 // adds 1 pass of pass1 to mesh_set1
141 queue1.add_quality_assessor(&stop_qa,err);
142 if (err) return 1;
143 //queue1.add_preconditioner(pass0,err);MSQ_CHKERR(err);
144 //queue1.add_preconditioner(pass1,err);MSQ_CHKERR(err);
145 //queue1.set_master_quality_improver(pass2, err); MSQ_CHKERR(err);
146 queue1.set_master_quality_improver(&pass1, err);
147 if (err) return 1;
148 queue1.add_quality_assessor(&stop_qa2,err);
149 if (err) return 1;
150 if (write_output)
151 mesh.write_vtk("original_mesh.vtk", err);
152 if (err) return 1;
153
154 // launches optimization on mesh_set1
155 MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &msq_geom);
156 queue1.run_instructions(&mesh_and_domain, err);
157 if (err) return 1;
158
159 if (write_output)
160 mesh.write_vtk("smoothed_mesh.vtk", err);
161 if (err) return 1;
162
163 if (!brief_output)
164 print_timing_diagnostics(cout);
165 return 0;
166 }
167