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:11:05 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 "TestUtil.hpp"
47 #include "Mesquite.hpp"
48 #include "MeshImpl.hpp"
49 #include "PlanarDomain.hpp"
50 #include "InstructionQueue.hpp"
51 #include "TerminationCriterion.hpp"
52 #include "QualityAssessor.hpp"
53 #include "MsqError.hpp"
54 #include "ShapeImprovementWrapper.hpp"
55 // algorythms
56 #include "IdealWeightInverseMeanRatio.hpp"
57 #include "EdgeLengthQualityMetric.hpp"
58 #include "LPtoPTemplate.hpp"
59 #include "SteepestDescent.hpp"
60 #include "ConjugateGradient.hpp"
61 
62 #include <iostream>
63 using std::cout;
64 using std::endl;
65 #include <cstdlib>
66 
67 using namespace MBMesquite;
68 
main()69 int main()
70 {
71   MBMesquite::MeshImpl mesh;
72   MsqPrintError err(cout);
73     //create geometry: plane z=0, normal (0,0,1)
74   Vector3D pnt(0,0,0);
75   Vector3D s_norm(0,0,1);
76   MBMesquite::PlanarDomain msq_geom(s_norm, pnt);
77 
78   std::string default_file_name = TestDir + "/2D/vtk/mixed/untangled/hybrid_3quad_1tri.vtk";
79   mesh.read_vtk(default_file_name.c_str(), err);
80   if (err) return 1;
81 
82     // creates an intruction queue
83   InstructionQueue queue1;
84 
85     // creates a mean ratio quality metric ...
86   IdealWeightInverseMeanRatio mean_ratio(err);
87   if (err) return 1;
88     //   mean_ratio->set_gradient_type(QualityMetric::NUMERICAL_GRADIENT);
89     //   mean_ratio->set_hessian_type(QualityMetric::NUMERICAL_HESSIAN);
90     //mean_ratio->set_averaging_method(QualityMetric::SUM, err);
91     //MSQ_CHKERR(err);
92 
93     // ... and builds an objective function with it
94   LPtoPTemplate obj_func(&mean_ratio, 2, err);
95   if (err) return 1;;
96 
97     // creates the steepest descent, feas newt optimization procedures
98     //ConjugateGradient* pass1 = new ConjugateGradient( &obj_func, err );
99   SteepestDescent pass1( &obj_func );
100   pass1.use_global_patch();
101   if (err) return 1;;
102 
103   QualityAssessor qa=QualityAssessor(&mean_ratio);
104   if (err) return 1;;
105 
106     // **************Set termination criterion****************
107   TerminationCriterion tc_inner;
108   tc_inner.add_iteration_limit( 1 );
109     //_inner.add_absolute_quality_improvement( OF_value );
110     //tc_inner.add_absolute_gradient_L2_norm( OF_value );
111   TerminationCriterion tc_outer;
112     //tc_outer.add_iteration_limit( 1 );
113   tc_outer.add_iteration_limit( 1 );
114 
115   pass1.set_inner_termination_criterion(&tc_inner);
116   pass1.set_outer_termination_criterion(&tc_outer);
117 
118   queue1.add_quality_assessor(&qa,err);
119   if (err) return 1;
120     // adds 1 pass of pass1 to mesh_set1
121   queue1.set_master_quality_improver(&pass1, err);
122   if (err) return 1;
123   queue1.add_quality_assessor(&qa,err);
124   if (err) return 1;
125   mesh.write_vtk("original_mesh.vtk",err);
126   if (err) return 1;
127 
128   MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &msq_geom);
129   queue1.run_instructions(&mesh_and_domain, err);
130   if (err) return 1;
131   mesh.write_vtk("smoothed_mesh.vtk",err);
132   if (err) return 1;
133     //std::cout<<"\n\nNow running the shape wrapper.\n=n";
134     //ShapeImprovementWrapper wrap(100);
135     //wrap.run_instructions(mesh_set1, err); MSQ_CHKERR(err);
136   print_timing_diagnostics(cout);
137   return 0;
138 }
139 
140