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: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3 -*-
28 //
29 //   SUMMARY:
30 //     USAGE:
31 //
32 // ORIG-DATE: 19-Feb-02 at 10:57:52
33 //  LAST-MOD: 23-Jul-03 at 18:09:51 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 #include <iostream>
46 using std::cout;
47 using std::endl;
48 #include <cstdlib>
49 
50 #include "Mesquite.hpp"
51 #include "MeshImpl.hpp"
52 #include "MsqError.hpp"
53 #include "Vector3D.hpp"
54 #include "InstructionQueue.hpp"
55 #include "PatchData.hpp"
56 #include "TerminationCriterion.hpp"
57 #include "QualityAssessor.hpp"
58 
59 // algorythms
60 #include "IdealWeightInverseMeanRatio.hpp"
61 #include "ConditionNumberQualityMetric.hpp"
62 #include "LPtoPTemplate.hpp"
63 #include "LInfTemplate.hpp"
64 #include "FeasibleNewton.hpp"
65 #include "ConjugateGradient.hpp"
66 #include "TestUtil.hpp"
67 using namespace MBMesquite;
68 
main()69 int main()
70 {
71   MsqPrintError err(cout);
72   MBMesquite::MeshImpl mesh;
73 
74   std::string file_name = TestDir + "/3D/vtk/tets/untangled/tire.vtk";
75   mesh.read_vtk(file_name.c_str(), err);
76   if (err) return 1;
77 
78     // creates an intruction queue
79   InstructionQueue queue1;
80 
81   // creates a mean ratio quality metric ...
82   IdealWeightInverseMeanRatio mean(err);
83   if (err) return 1;
84 
85   LPtoPTemplate obj_func(&mean, 1, err);
86   if (err) return 1;
87 
88   // creates the optimization procedures
89 //   ConjugateGradient* pass1 = new ConjugateGradient( obj_func, err );
90   FeasibleNewton pass1( &obj_func );
91 
92   //perform optimization globally
93   pass1.use_global_patch();
94   if (err) return 1;
95 
96   QualityAssessor mean_qa=QualityAssessor(&mean);
97 
98     //**************Set termination criterion****************
99 
100   //perform 1 pass of the outer loop (this line isn't essential as it is
101   //the default behavior).
102   TerminationCriterion tc_outer;
103   tc_outer.add_iteration_limit( 1 );
104   pass1.set_outer_termination_criterion(&tc_outer);
105 
106   //perform the inner loop until a certain objective function value is
107   //reached.  The exact value needs to be determined (about 18095).
108   //As a safety, also stop if the time exceeds 10 minutes (600 seconds).
109   TerminationCriterion tc_inner;
110   tc_inner.add_absolute_quality_improvement( 13975 );
111 //  tc_inner.add_absolute_quality_improvement( 13964.93818 );
112   tc_inner.add_cpu_time( 1800 );
113 
114   pass1.set_inner_termination_criterion(&tc_inner);
115 
116   //used for cg to get some info
117 //  pass1->set_debugging_level(2);
118 
119   // adds 1 pass of pass1 to mesh_set1
120   queue1.add_quality_assessor(&mean_qa,err);
121   if (err) return 1;
122   queue1.set_master_quality_improver(&pass1, err);
123   if (err) return 1;
124   queue1.add_quality_assessor(&mean_qa,err);
125   if (err) return 1;
126   mesh.write_vtk("original_mesh.vtk", err);
127   if (err) return 1;
128 
129     // launches optimization on mesh_set1
130   queue1.run_instructions(&mesh, err);
131   if (err) return 1;
132 
133   mesh.write_vtk("smoothed_mesh.vtk", err);
134   if (err) return 1;
135   print_timing_diagnostics( cout );
136   return 0;
137 }
138