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: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 <iostream>
47 #include <cstdlib>
48
49 #include "Mesquite.hpp"
50 #include "MeshImpl.hpp"
51 #include "MsqError.hpp"
52 #include "Vector3D.hpp"
53 #include "InstructionQueue.hpp"
54 #include "PatchData.hpp"
55 #include "TerminationCriterion.hpp"
56 #include "QualityAssessor.hpp"
57
58 // algorithms
59 #include "IdealWeightInverseMeanRatio.hpp"
60 #include "ConditionNumberQualityMetric.hpp"
61 #include "LPtoPTemplate.hpp"
62 #include "LInfTemplate.hpp"
63 #include "SteepestDescent.hpp"
64 #include "TestUtil.hpp"
65
66 using namespace MBMesquite;
67
main()68 int main()
69 {
70 MsqPrintError err(std::cout);
71 MBMesquite::MeshImpl mesh;
72
73 std::string file_name = TestDir + "/3D/vtk/hexes/untangled/hexes_4by2by2.vtk";
74 mesh.read_vtk(file_name.c_str(), err);
75
76 // creates an intruction queue
77 InstructionQueue queue1;
78
79 // creates a mean ratio quality metric ...
80 IdealWeightInverseMeanRatio mean_ratio(err);
81 if (err) return 1;
82 ConditionNumberQualityMetric cond_num;
83 mean_ratio.set_averaging_method(QualityMetric::LINEAR);
84
85 // ... and builds an objective function with it
86 //LInfTemplate* obj_func = new LInfTemplate(mean_ratio);
87 LPtoPTemplate obj_func(&mean_ratio, 2, err);
88 if (err) return 1;
89 // creates the steepest descent optimization procedures
90 SteepestDescent pass1( &obj_func );
91 pass1.use_global_patch();
92 //if (err) return 1;
93 //pass1.set_maximum_iteration(6);
94
95 QualityAssessor stop_qa=QualityAssessor(&mean_ratio);
96 if (err) return 1;
97 stop_qa.add_quality_assessment(&cond_num);
98 if (err) return 1;
99
100
101 //**************Set stopping criterion****************
102 // StoppingCriterion sc1(&stop_qa,1.0,1.8);
103 //StoppingCriterion sc2(StoppingCriterion::NUMBER_OF_PASSES,1);
104 TerminationCriterion tc2;
105 tc2.add_iteration_limit( 1 );
106 // CompositeAndStoppingCriterion sc(&sc1,&sc2);
107 pass1.set_inner_termination_criterion(&tc2);
108
109 // adds 1 pass of pass1 to mesh_set1
110 // queue1.add_preconditioner(pass1, err);
111 // if (err) return 1;
112 queue1.add_quality_assessor(&stop_qa,err);
113 queue1.set_master_quality_improver(&pass1, err);
114 if (err) return 1;
115 queue1.add_quality_assessor(&stop_qa,err);
116 if (err) return 1;
117 // adds 1 passes of pass2 to mesh_set1
118 // mesh_set1.add_quality_pass(pass2);
119
120 mesh.write_vtk("original_mesh.vtk", err);
121 if (err) return 1;
122
123 // launches optimization on mesh_set1
124 queue1.run_instructions(&mesh, err);
125 if (err) return 1;
126
127 mesh.write_vtk("smoothed_mesh.vtk", err);
128 if (err) return 1;
129
130 return 0;
131 }
132