MOAB: Mesh Oriented datABase  (version 5.3.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) kraftche@cae.wisc.edu
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, ParallelMesh* pmesh, Settings* settings,
00060                                              QualityAssessor* qa, MsqError& err )
00061 {
00062     InstructionQueue q;
00063 
00064     // Set up barrier metric to see if mesh contains inverted elements
00065     TShapeB1 mu_b;
00066     IdealShapeTarget w_ideal;
00067     TQualityMetric barrier( &w_ideal, &mu_b );
00068 
00069     // Check for inverted elements in the mesh
00070     QualityAssessor inv_check( &barrier );
00071     inv_check.disable_printing_results();
00072     q.add_quality_assessor( &inv_check, err );MSQ_ERRRTN( err );
00073     q.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err );
00074     q.remove_quality_assessor( 0, err );MSQ_ERRRTN( err );
00075     const QualityAssessor::Assessor* inv_b = inv_check.get_results( &barrier );
00076     const bool use_barrier                 = ( 0 == inv_b->get_invalid_element_count() );
00077 
00078     // Create remaining metric instances
00079     TShapeNB1 mu;
00080     TShapeSizeOrientNB1 mu_o;
00081     TShapeSizeOrientB1 mu_ob;
00082 
00083     // Select which target metrics to use
00084     TMetric *mu_p, *mu_op;
00085     if( use_barrier )
00086     {
00087         mu_p  = &mu_b;
00088         mu_op = &mu_ob;
00089     }
00090     else
00091     {
00092         mu_p  = μ
00093         mu_op = &mu_o;
00094     }
00095 
00096     // Set up target and weight calculators
00097     Mesh* mesh = mesh_and_domain->get_mesh();
00098     TagVertexMesh init_mesh( err, pmesh ? (Mesh*)pmesh : mesh );MSQ_ERRRTN( err );
00099     ReferenceMesh ref_mesh( &init_mesh );
00100     RefMeshTargetCalculator w_init( &ref_mesh );
00101     TetDihedralWeight c_dihedral( &ref_mesh, dCutoff, aVal );
00102     RemainingWeight c_remaining( &c_dihedral );
00103 
00104     // Create objective function
00105     TQualityMetric metric1( &w_ideal, &c_dihedral, mu_p );
00106     TQualityMetric metric2( &w_init, &c_remaining, mu_op );
00107     AddQualityMetric of_metric( &metric1, &metric2, err );MSQ_ERRRTN( err );
00108     PMeanPTemplate obj_func( 1.0, &of_metric );
00109 
00110     // Create optimizer
00111     TrustRegion solver( &obj_func );
00112     TerminationCriterion term, ptc;
00113     term.add_iteration_limit( iterationLimit );
00114     term.add_absolute_vertex_movement( maxVtxMovement );
00115     ptc.add_iteration_limit( pmesh ? parallelIterations : 1 );
00116     solver.set_inner_termination_criterion( &term );
00117     solver.set_outer_termination_criterion( &ptc );
00118 
00119     // Create instruction queue
00120     qa->add_quality_assessment( &metric1 );
00121     qa->add_quality_assessment( &metric2 );
00122     qa->add_quality_assessment( &of_metric );
00123     q.add_quality_assessor( qa, err );MSQ_ERRRTN( err );
00124     q.set_master_quality_improver( &solver, err );MSQ_ERRRTN( err );
00125     q.add_quality_assessor( qa, err );MSQ_ERRRTN( err );
00126 
00127     // Optimize mesh
00128     q.run_common( mesh_and_domain, pmesh, settings, err );MSQ_CHKERR( err );
00129 }
00130 
00131 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines