MOAB: Mesh Oriented datABase  (version 5.4.1)
SphericalGeometryTest.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government retains certain
00007     rights in 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     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected]
00025 
00026   ***************************************************************** */
00027 // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3
00028 // -*-
00029 //
00030 //   SUMMARY:
00031 //     USAGE:
00032 //
00033 //    AUTHOR: Michael Brewer
00034 //       ORG: Sandia National Labs
00035 //    E-MAIL: [email protected]
00036 //
00037 // ORIG-DATE: Jan. 29, 2003
00038 //  LAST-MOD: 25-Feb-04 at 10:49:04 by Thomas Leurent
00039 //
00040 // DESCRIPTION:
00041 // ============
00042 /*! \file SphericalGeometryTest.cpp
00043 
00044 Regression testing using the spherical geometry capabilities in
00045 SimplifiedGeometryEngine.
00046  */
00047 // DESCRIP-END.
00048 //
00049 
00050 #include "meshfiles.h"
00051 
00052 #include "PatchDataInstances.hpp"
00053 #include "cppunit/extensions/HelperMacros.h"
00054 #include <cmath>
00055 
00056 #include "Mesquite.hpp"
00057 #include "MsqError.hpp"
00058 #include "Vector3D.hpp"
00059 #include "InstructionQueue.hpp"
00060 #include "PatchData.hpp"
00061 //#include "StoppingCriterion.hpp"
00062 #include "QualityAssessor.hpp"
00063 
00064 #include "IdealWeightInverseMeanRatio.hpp"
00065 #include "ConditionNumberQualityMetric.hpp"
00066 #include "LPtoPTemplate.hpp"
00067 #include "EdgeLengthQualityMetric.hpp"
00068 #include "LaplacianSmoother.hpp"
00069 #include "SmartLaplacianSmoother.hpp"
00070 #include "LInfTemplate.hpp"
00071 #include "SteepestDescent.hpp"
00072 #include "ConjugateGradient.hpp"
00073 #include "AspectRatioGammaQualityMetric.hpp"
00074 #include "UntangleBetaQualityMetric.hpp"
00075 #include "MultiplyQualityMetric.hpp"
00076 #include "SphericalDomain.hpp"
00077 
00078 #include "MeshImpl.hpp"
00079 
00080 #include <iostream>
00081 using std::cout;
00082 using std::endl;
00083 using namespace MBMesquite;
00084 
00085 class SphericalGeometryTest : public CppUnit::TestFixture
00086 {
00087   private:
00088     CPPUNIT_TEST_SUITE( SphericalGeometryTest );
00089     // run cg on the quad sphere mesh with condition number L2
00090     CPPUNIT_TEST( test_cg_mesh_cond_sphere );
00091     // run cg on the quad sphere mesh with condition number L2
00092     CPPUNIT_TEST( test_smart_lapl_sphere );
00093     // run laplacian smoothing on the geo tri mesh
00094     CPPUNIT_TEST( test_lapl_geo_sphere );
00095 
00096     CPPUNIT_TEST_SUITE_END();
00097 
00098   private:
00099     double qualTol;  // double used for double comparisons
00100     int pF;          // PRINT_FLAG
00101   public:
00102     void setUp()
00103     {
00104         // pF=1;//PRINT_FLAG IS ON
00105         pF = 0;  // PRINT_FLAG IS OFF
00106                  // tolerance double
00107         qualTol = MSQ_MIN;
00108     }
00109 
00110     void tearDown() {}
00111 
00112   public:
00113     SphericalGeometryTest() {}
00114 
00115     void test_cg_mesh_cond_sphere()
00116     {
00117         MBMesquite::MeshImpl mesh;
00118         MBMesquite::MsqPrintError err( cout );
00119         mesh.read_vtk( MESH_FILES_DIR "2D/vtk/quads/untangled/quads_on_sphere_529.vtk", err );
00120         CPPUNIT_ASSERT( !err );
00121 
00122         // create geometry: sphere, center (2,2,0), radius 3
00123         Vector3D center( 2, 2, 0 );
00124         SphericalDomain msq_geom( center, 3.0 );
00125 
00126         // creates an intruction queue
00127         InstructionQueue queue1;
00128 
00129         // creates a mean ratio quality metric ...
00130         ConditionNumberQualityMetric shape;
00131         UntangleBetaQualityMetric untan;
00132 
00133         // ... and builds an objective function with it
00134         LPtoPTemplate obj_func( &shape, 2, err );
00135         // Make sure no errors
00136         CPPUNIT_ASSERT( !err );
00137         // creates the steepest descent optimization procedures
00138         ConjugateGradient pass1( &obj_func, err );
00139         // SteepestDescent* pass2 = new SteepestDescent( obj_func );
00140         pass1.use_global_patch();
00141         // Make sure no errors
00142         CPPUNIT_ASSERT( !err );
00143         QualityAssessor qa = QualityAssessor( &shape );
00144 
00145         //**********Set stopping criterion  5 iterates ****************
00146         // StoppingCriterion sc5(StoppingCriterion::NUMBER_OF_PASSES,5);
00147         // pass1->set_stopping_criterion(&sc5);
00148         TerminationCriterion sc5;
00149         sc5.add_iteration_limit( 5 );
00150         pass1.set_inner_termination_criterion( &sc5 );
00151         // CG's debugging print, increase integer to get more print info
00152         pass1.set_debugging_level( 0 );
00153 
00154         //  queue1.add_preconditioner(pass2, err); CPPUNIT_ASSERT(!err);
00155         queue1.set_master_quality_improver( &pass1, err );
00156         CPPUNIT_ASSERT( !err );
00157         // Make sure no errors
00158         CPPUNIT_ASSERT( !err );
00159         // launches optimization on mesh_set1
00160         MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &msq_geom );
00161         double orig_qa_val              = qa.loop_over_mesh( &mesh_and_domain, 0, err );
00162         // Make sure no errors
00163         CPPUNIT_ASSERT( !err );
00164         queue1.run_instructions( &mesh_and_domain, err );
00165         CPPUNIT_ASSERT( !err );
00166         // Make sure no errors
00167         CPPUNIT_ASSERT( !err );
00168         double fin_qa_val = qa.loop_over_mesh( &mesh_and_domain, 0, err );
00169         // Make sure no errors
00170         CPPUNIT_ASSERT( !err );
00171         // make sure 'quality' improved
00172         CPPUNIT_ASSERT( fin_qa_val <= orig_qa_val );
00173     }
00174     void test_smart_lapl_sphere()
00175     {
00176         MBMesquite::MeshImpl mesh;
00177         MBMesquite::MsqPrintError err( cout );
00178         mesh.read_vtk( MESH_FILES_DIR "2D/vtk/quads/untangled/quads_on_sphere_529.vtk", err );
00179 
00180         // create geometry sphere:  ratius 1, centered at (0,0,0)
00181         Vector3D center( 2, 2, 0 );
00182         SphericalDomain msq_geom( center, 3.0 );
00183 
00184         // creates an intruction queue
00185         InstructionQueue queue1;
00186 
00187         // creates an edge length metric ...
00188         IdealWeightInverseMeanRatio shape_metric( err );
00189         LInfTemplate shape_func( &shape_metric );
00190 
00191         // create the smart laplacian smoother
00192         SmartLaplacianSmoother s_lapl( &shape_func );
00193         // Make sure no errors
00194         CPPUNIT_ASSERT( !err );
00195 
00196         //*******Set stopping criterion 5 iterates  ***********
00197         TerminationCriterion sc5;
00198         sc5.add_iteration_limit( 5 );
00199         s_lapl.set_outer_termination_criterion( &sc5 );
00200         // qa, qi, qa
00201         queue1.set_master_quality_improver( &s_lapl, err );
00202         CPPUNIT_ASSERT( !err );
00203         // Make sure no errors
00204         CPPUNIT_ASSERT( !err );
00205         // launches optimization on mesh_set1
00206         QualityAssessor qa              = QualityAssessor( &shape_metric );
00207         MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &msq_geom );
00208         double orig_val                 = qa.loop_over_mesh( &mesh_and_domain, 0, err );
00209 
00210         // Make sure no errors
00211         CPPUNIT_ASSERT( !err );
00212         queue1.run_instructions( &mesh_and_domain, err );
00213         CPPUNIT_ASSERT( !err );
00214         // Make sure no errors
00215         CPPUNIT_ASSERT( !err );
00216 
00217         double final_val = qa.loop_over_mesh( &mesh_and_domain, 0, err );
00218 
00219         // Make sure no errors
00220         CPPUNIT_ASSERT( !err );
00221         // make sure 'quality' improved
00222         CPPUNIT_ASSERT( final_val < orig_val );
00223     }
00224 
00225     void test_lapl_geo_sphere()
00226     {
00227         MBMesquite::MeshImpl mesh;
00228         MBMesquite::MsqPrintError err( cout );
00229 
00230         mesh.read_vtk( MESH_FILES_DIR "2D/vtk/tris/untangled/Mesquite_geo_10242.vtk", err );
00231 
00232         // create geometry sphere:  ratius 1, centered at (0,0,0)
00233         Vector3D center( 0, 0, 0 );
00234         MBMesquite::SphericalDomain msq_geom( center, 1.0 );
00235 
00236         // creates an intruction queue
00237         InstructionQueue queue1;
00238 
00239         // creates an edge length metric ...
00240         EdgeLengthQualityMetric edg_len;
00241 
00242         // create the laplacian smoother
00243         LaplacianSmoother lapl;
00244         // Make sure no errors
00245         CPPUNIT_ASSERT( !err );
00246 
00247         // create a quality assessor
00248         QualityAssessor qa = QualityAssessor( &edg_len );
00249 
00250         //*******Set stopping criterion 10 iterates  ***********
00251         // StoppingCriterion sc10(StoppingCriterion::NUMBER_OF_PASSES,10);
00252         // lapl->set_stopping_criterion(&sc10);
00253         TerminationCriterion sc10;
00254         sc10.add_iteration_limit( 10 );
00255         lapl.set_outer_termination_criterion( &sc10 );
00256         // qa, qi, qa
00257         queue1.set_master_quality_improver( &lapl, err );
00258         // Make sure no errors
00259         CPPUNIT_ASSERT( !err );
00260         // launches optimization on mesh_set1
00261         MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &msq_geom );
00262         double orig_qa_val              = qa.loop_over_mesh( &mesh_and_domain, 0, err );
00263         // Make sure no errors
00264         CPPUNIT_ASSERT( !err );
00265         queue1.run_instructions( &mesh_and_domain, err );
00266         CPPUNIT_ASSERT( !err );
00267         // Make sure no errors
00268         CPPUNIT_ASSERT( !err );
00269         double fin_qa_val = qa.loop_over_mesh( &mesh_and_domain, 0, err );
00270         // Make sure no errors
00271         CPPUNIT_ASSERT( !err );
00272         // make sure 'quality' improved
00273         CPPUNIT_ASSERT( fin_qa_val <= orig_qa_val );
00274     }
00275 };
00276 
00277 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SphericalGeometryTest, "SphericalGeometryTest" );
00278 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SphericalGeometryTest, "Regression" );
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines