1 /* *****************************************************************
2     MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4     Copyright 2009 Sandia National Laboratories.  Developed at the
5     University of Wisconsin--Madison under SNL contract number
6     624796.  The U.S. Government and the University of Wisconsin
7     retain certain rights to 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     (2009) kraftche@cae.wisc.edu
24 
25   ***************************************************************** */
26 
27 
28 /** \file PaverMinEdgeLengthWrapper.cpp
29  *  \brief
30  *  \author Jason Kraftcheck
31  */
32 
33 #include "Mesquite.hpp"
34 #include "PaverMinEdgeLengthWrapper.hpp"
35 
36 #include "TerminationCriterion.hpp"
37 #include "InstructionQueue.hpp"
38 #include "QualityAssessor.hpp"
39 #include "MeshImpl.hpp"
40 #include "PlanarDomain.hpp"
41 
42 #include "ElementPMeanP.hpp"
43 #include "PMeanPTemplate.hpp"
44 #include "TrustRegion.hpp"
45 #include "TQualityMetric.hpp"
46 #include "IdealShapeTarget.hpp"
47 #include "TShapeSizeB1.hpp"
48 #include "RefMeshTargetCalculator.hpp"
49 #include "ReferenceMesh.hpp"
50 
51 #include "EdgeLengthMetric.hpp"
52 #include "LambdaConstant.hpp"
53 
54 #include "MsqFPE.hpp"
55 #include "MeshUtil.hpp"
56 #include "SimpleStats.hpp"
57 
58 namespace MBMesquite {
59 
run_wrapper(MeshDomainAssoc * mesh_and_domain,ParallelMesh * pmesh,Settings * settings,QualityAssessor * qa,MsqError & err)60 void PaverMinEdgeLengthWrapper::run_wrapper( MeshDomainAssoc* mesh_and_domain,
61                                              ParallelMesh* pmesh,
62                                              Settings* settings,
63                                              QualityAssessor* qa,
64                                              MsqError& err )
65 {
66   InstructionQueue q;
67   Mesh* mesh = mesh_and_domain->get_mesh();
68 
69     // calculate average lambda for mesh
70   ReferenceMesh ref_mesh( mesh );
71   RefMeshTargetCalculator W_0( &ref_mesh );
72   SimpleStats lambda_stats;
73   MeshUtil tool(mesh, settings);
74   tool.lambda_distribution( lambda_stats, err ); MSQ_ERRRTN(err);
75   double lambda = lambda_stats.average();
76 
77     // create objective function
78   IdealShapeTarget W_i;
79   LambdaConstant W( lambda, &W_i );
80   TShapeSizeB1 tm;
81   TQualityMetric mu_0( &W, &tm );
82   ElementPMeanP mu( 1.0, &mu_0 );
83   PMeanPTemplate of( 1.0, &mu );
84 
85     // create quality assessor
86   EdgeLengthMetric len(0.0);
87   qa->add_quality_assessment( &mu );
88   qa->add_quality_assessment( &len );
89   q.add_quality_assessor( qa, err );
90 
91     // create solver
92   TrustRegion solver( &of );
93   TerminationCriterion tc, ptc;
94   tc.add_absolute_vertex_movement( maxVtxMovement );
95   tc.add_iteration_limit( iterationLimit );
96   ptc.add_iteration_limit( pmesh ? parallelIterations : 1 );
97   solver.set_inner_termination_criterion( &tc );
98   solver.set_outer_termination_criterion( &ptc );
99   q.set_master_quality_improver( &solver, err ); MSQ_ERRRTN(err);
100   q.add_quality_assessor( qa, err );
101 
102   // Optimize mesh
103   q.run_common( mesh_and_domain, pmesh, settings, err ); MSQ_CHKERR(err);
104 }
105 
106 } // namespace MBMesquite
107