MOAB: Mesh Oriented datABase  (version 5.4.1)
ViscousCFDTetShapeWrapper.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2009 Sandia National Laboratories.  Developed at the
00005     University of Wisconsin--Madison under SNL contract number
00006     624796.  The U.S. Government and the University of Wisconsin
00007     retain certain rights to this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     (2009) [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 /** \file ViscousCFDTetShapeWrapper.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "ViscousCFDTetShapeWrapper.hpp"
00034 
00035 #include "QualityAssessor.hpp"
00036 #include "InstructionQueue.hpp"
00037 #include "TagVertexMesh.hpp"
00038 #include "TrustRegion.hpp"
00039 #include "TerminationCriterion.hpp"
00040 
00041 #include "PMeanPTemplate.hpp"
00042 #include "TQualityMetric.hpp"
00043 #include "AddQualityMetric.hpp"
00044 
00045 #include "TShapeB1.hpp"
00046 #include "TShapeNB1.hpp"
00047 #include "TShapeSizeOrientB1.hpp"
00048 #include "TShapeSizeOrientNB1.hpp"
00049 
00050 #include "IdealShapeTarget.hpp"
00051 #include "RefMeshTargetCalculator.hpp"
00052 #include "ReferenceMesh.hpp"
00053 #include "TetDihedralWeight.hpp"
00054 #include "RemainingWeight.hpp"
00055 
00056 namespace MBMesquite
00057 {
00058 
00059 void ViscousCFDTetShapeWrapper::run_wrapper( MeshDomainAssoc* mesh_and_domain,
00060                                              ParallelMesh* pmesh,
00061                                              Settings* settings,
00062                                              QualityAssessor* qa,
00063                                              MsqError& err )
00064 {
00065     InstructionQueue q;
00066 
00067     // Set up barrier metric to see if mesh contains inverted elements
00068     TShapeB1 mu_b;
00069     IdealShapeTarget w_ideal;
00070     TQualityMetric barrier( &w_ideal, &mu_b );
00071 
00072     // Check for inverted elements in the mesh
00073     QualityAssessor inv_check( &barrier );
00074     inv_check.disable_printing_results();
00075     q.add_quality_assessor( &inv_check, err );MSQ_ERRRTN( err );
00076     q.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err );
00077     q.remove_quality_assessor( 0, err );MSQ_ERRRTN( err );
00078     const QualityAssessor::Assessor* inv_b = inv_check.get_results( &barrier );
00079     const bool use_barrier                 = ( 0 == inv_b->get_invalid_element_count() );
00080 
00081     // Create remaining metric instances
00082     TShapeNB1 mu;
00083     TShapeSizeOrientNB1 mu_o;
00084     TShapeSizeOrientB1 mu_ob;
00085 
00086     // Select which target metrics to use
00087     TMetric *mu_p, *mu_op;
00088     if( use_barrier )
00089     {
00090         mu_p  = &mu_b;
00091         mu_op = &mu_ob;
00092     }
00093     else
00094     {
00095         mu_p  = μ
00096         mu_op = &mu_o;
00097     }
00098 
00099     // Set up target and weight calculators
00100     Mesh* mesh = mesh_and_domain->get_mesh();
00101     TagVertexMesh init_mesh( err, pmesh ? (Mesh*)pmesh : mesh );MSQ_ERRRTN( err );
00102     ReferenceMesh ref_mesh( &init_mesh );
00103     RefMeshTargetCalculator w_init( &ref_mesh );
00104     TetDihedralWeight c_dihedral( &ref_mesh, dCutoff, aVal );
00105     RemainingWeight c_remaining( &c_dihedral );
00106 
00107     // Create objective function
00108     TQualityMetric metric1( &w_ideal, &c_dihedral, mu_p );
00109     TQualityMetric metric2( &w_init, &c_remaining, mu_op );
00110     AddQualityMetric of_metric( &metric1, &metric2, err );MSQ_ERRRTN( err );
00111     PMeanPTemplate obj_func( 1.0, &of_metric );
00112 
00113     // Create optimizer
00114     TrustRegion solver( &obj_func );
00115     TerminationCriterion term, ptc;
00116     term.add_iteration_limit( iterationLimit );
00117     term.add_absolute_vertex_movement( maxVtxMovement );
00118     ptc.add_iteration_limit( pmesh ? parallelIterations : 1 );
00119     solver.set_inner_termination_criterion( &term );
00120     solver.set_outer_termination_criterion( &ptc );
00121 
00122     // Create instruction queue
00123     qa->add_quality_assessment( &metric1 );
00124     qa->add_quality_assessment( &metric2 );
00125     qa->add_quality_assessment( &of_metric );
00126     q.add_quality_assessor( qa, err );MSQ_ERRRTN( err );
00127     q.set_master_quality_improver( &solver, err );MSQ_ERRRTN( err );
00128     q.add_quality_assessor( qa, err );MSQ_ERRRTN( err );
00129 
00130     // Optimize mesh
00131     q.run_common( mesh_and_domain, pmesh, settings, err );MSQ_CHKERR( err );
00132 }
00133 
00134 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines