Branch data Line data Source code
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) [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : /** \file ViscousCFDTetShapeWrapper.cpp
28 : : * \brief
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #include "Mesquite.hpp"
33 : : #include "ViscousCFDTetShapeWrapper.hpp"
34 : :
35 : : #include "QualityAssessor.hpp"
36 : : #include "InstructionQueue.hpp"
37 : : #include "TagVertexMesh.hpp"
38 : : #include "TrustRegion.hpp"
39 : : #include "TerminationCriterion.hpp"
40 : :
41 : : #include "PMeanPTemplate.hpp"
42 : : #include "TQualityMetric.hpp"
43 : : #include "AddQualityMetric.hpp"
44 : :
45 : : #include "TShapeB1.hpp"
46 : : #include "TShapeNB1.hpp"
47 : : #include "TShapeSizeOrientB1.hpp"
48 : : #include "TShapeSizeOrientNB1.hpp"
49 : :
50 : : #include "IdealShapeTarget.hpp"
51 : : #include "RefMeshTargetCalculator.hpp"
52 : : #include "ReferenceMesh.hpp"
53 : : #include "TetDihedralWeight.hpp"
54 : : #include "RemainingWeight.hpp"
55 : :
56 : : namespace MBMesquite
57 : : {
58 : :
59 : 1 : void ViscousCFDTetShapeWrapper::run_wrapper( MeshDomainAssoc* mesh_and_domain, ParallelMesh* pmesh, Settings* settings,
60 : : QualityAssessor* qa, MsqError& err )
61 : : {
62 [ + - ]: 1 : InstructionQueue q;
63 : :
64 : : // Set up barrier metric to see if mesh contains inverted elements
65 [ + - ]: 1 : TShapeB1 mu_b;
66 [ + - ]: 1 : IdealShapeTarget w_ideal;
67 [ + - ][ + - ]: 2 : TQualityMetric barrier( &w_ideal, &mu_b );
68 : :
69 : : // Check for inverted elements in the mesh
70 [ + - ][ + - ]: 2 : QualityAssessor inv_check( &barrier );
[ + - ]
71 [ + - ]: 1 : inv_check.disable_printing_results();
72 [ + - ][ + - ]: 1 : q.add_quality_assessor( &inv_check, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
73 [ + - ][ + - ]: 1 : q.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
74 [ + - ][ + - ]: 1 : q.remove_quality_assessor( 0, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
75 [ + - ]: 1 : const QualityAssessor::Assessor* inv_b = inv_check.get_results( &barrier );
76 [ + - ]: 1 : const bool use_barrier = ( 0 == inv_b->get_invalid_element_count() );
77 : :
78 : : // Create remaining metric instances
79 [ + - ]: 1 : TShapeNB1 mu;
80 [ + - ]: 1 : TShapeSizeOrientNB1 mu_o;
81 [ + - ]: 1 : TShapeSizeOrientB1 mu_ob;
82 : :
83 : : // Select which target metrics to use
84 : : TMetric *mu_p, *mu_op;
85 [ + - ]: 1 : if( use_barrier )
86 : : {
87 : 1 : mu_p = &mu_b;
88 : 1 : mu_op = &mu_ob;
89 : : }
90 : : else
91 : : {
92 : 0 : mu_p = μ
93 : 0 : mu_op = &mu_o;
94 : : }
95 : :
96 : : // Set up target and weight calculators
97 [ + - ]: 1 : Mesh* mesh = mesh_and_domain->get_mesh();
98 [ + - ][ - + ]: 2 : TagVertexMesh init_mesh( err, pmesh ? (Mesh*)pmesh : mesh );MSQ_ERRRTN( err );
[ + - ][ + - ]
[ - + ][ # # ]
[ # # ][ - + ]
[ + - ]
99 [ + - ][ + - ]: 2 : ReferenceMesh ref_mesh( &init_mesh );
100 [ + - ][ + - ]: 2 : RefMeshTargetCalculator w_init( &ref_mesh );
101 [ + - ][ + - ]: 2 : TetDihedralWeight c_dihedral( &ref_mesh, dCutoff, aVal );
102 [ + - ][ + - ]: 2 : RemainingWeight c_remaining( &c_dihedral );
103 : :
104 : : // Create objective function
105 [ + - ][ + - ]: 2 : TQualityMetric metric1( &w_ideal, &c_dihedral, mu_p );
106 [ + - ][ + - ]: 2 : TQualityMetric metric2( &w_init, &c_remaining, mu_op );
107 [ + - ][ + - ]: 2 : AddQualityMetric of_metric( &metric1, &metric2, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
[ + - ]
108 [ + - ][ + - ]: 2 : PMeanPTemplate obj_func( 1.0, &of_metric );
109 : :
110 : : // Create optimizer
111 [ + - ][ + - ]: 2 : TrustRegion solver( &obj_func );
112 [ + - ][ + - ]: 2 : TerminationCriterion term, ptc;
[ + - ][ + - ]
[ + - ][ + - ]
113 [ + - ]: 1 : term.add_iteration_limit( iterationLimit );
114 [ + - ]: 1 : term.add_absolute_vertex_movement( maxVtxMovement );
115 [ - + ][ + - ]: 1 : ptc.add_iteration_limit( pmesh ? parallelIterations : 1 );
116 [ + - ]: 1 : solver.set_inner_termination_criterion( &term );
117 [ + - ]: 1 : solver.set_outer_termination_criterion( &ptc );
118 : :
119 : : // Create instruction queue
120 [ + - ]: 1 : qa->add_quality_assessment( &metric1 );
121 [ + - ]: 1 : qa->add_quality_assessment( &metric2 );
122 [ + - ]: 1 : qa->add_quality_assessment( &of_metric );
123 [ + - ][ + - ]: 1 : q.add_quality_assessor( qa, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
124 [ + - ][ + - ]: 1 : q.set_master_quality_improver( &solver, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
125 [ + - ][ + - ]: 1 : q.add_quality_assessor( qa, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
126 : :
127 : : // Optimize mesh
128 [ + - ][ + - ]: 2 : q.run_common( mesh_and_domain, pmesh, settings, err );MSQ_CHKERR( err );
[ - + ][ # # ]
[ # # ][ + - ]
129 : : }
130 : :
131 [ + - ][ + - ]: 4 : } // namespace MBMesquite
|