MeshKit
1.0
|
00001 00007 #include "moab/mesquite/Mesquite.hpp" 00008 #include "SweepWrapper.hpp" 00009 00010 #include "moab/mesquite/InstructionQueue.hpp" 00011 #include "moab/mesquite/PMeanPTemplate.hpp" 00012 #include "moab/mesquite/TrustRegion.hpp" 00013 #include "moab/mesquite/QualityAssessor.hpp" 00014 #include "moab/mesquite/RefMeshTargetCalculator.hpp" 00015 #include "moab/mesquite/ReferenceMesh.hpp" 00016 #include "moab/mesquite/TagVertexMesh.hpp" 00017 #include "moab/mesquite/TQualityMetric.hpp" 00018 #include "moab/mesquite/ConjugateGradient.hpp" 00019 #include "moab/mesquite/SteepestDescent.hpp" 00020 #include "moab/mesquite/QuasiNewton.hpp" 00021 #include "moab/mesquite/NonSmoothDescent.hpp" 00022 00023 00024 //#include "TRel2DShape.hpp" 00025 //#include "TRel3DShape.hpp" 00026 00027 #include "moab/mesquite/TShapeNB1.hpp" 00028 00029 #include "moab/mesquite/MsqError.hpp" 00030 00031 #include "moab/mesquite/MsqMatrix.hpp" 00032 00033 namespace MESQUITE_NS { 00034 00035 class TargetFlipper : public TargetCalculator 00036 { 00037 public: 00038 TargetFlipper( TargetCalculator* unflipped ) : realTargets(unflipped) {} 00039 00040 bool get_3D_target( PatchData& pd, 00041 size_t element, 00042 Sample sample, 00043 MsqMatrix<3,3>& W_out, 00044 MsqError& err ); 00045 00046 bool get_2D_target( PatchData& pd, 00047 size_t element, 00048 Sample sample, 00049 MsqMatrix<2,2>& W_out, 00050 MsqError& err ); 00051 bool have_surface_orient() const; 00052 00053 bool get_surface_target( PatchData& pd, 00054 size_t element, 00055 Sample sample, 00056 MsqMatrix<3,2>& W_out, 00057 MsqError& err ); 00058 private: 00059 TargetCalculator* realTargets; 00060 }; 00061 bool TargetFlipper::get_3D_target( PatchData& pd, 00062 size_t element, 00063 Sample sample, 00064 MsqMatrix<3,3>& W_out, 00065 MsqError& err ) 00066 { 00067 return realTargets->get_3D_target(pd, element, sample, W_out, err); 00068 00069 } 00070 00071 bool TargetFlipper::get_2D_target( PatchData& pd, 00072 size_t element, 00073 Sample sample, 00074 MsqMatrix<2,2>& W_out, 00075 MsqError& err ) 00076 { 00077 return realTargets->get_2D_target( pd, element, sample, W_out, err ); 00078 } 00079 00080 bool TargetFlipper::have_surface_orient() const 00081 { return false; } 00082 00083 bool TargetFlipper::get_surface_target( PatchData& pd, 00084 size_t element, 00085 Sample sample, 00086 MsqMatrix<3,2>& W_out, 00087 MsqError& err ) 00088 { 00089 bool valid = realTargets->get_surface_target( pd, element, sample, W_out, err ); 00090 if (MSQ_CHKERR(err) || !valid) return false; 00091 00092 if (pd.domain_set()) { 00093 Vector3D norm; 00094 pd.get_domain_normal_at_sample( element, sample, norm, err ); 00095 MSQ_ERRZERO(err); 00096 MsqVector<3> c0(W_out.column(0)), c1(W_out.column(1)); 00097 if ((c0 * c1) % MsqVector<3>(&norm[0]) < 0.0) { 00098 W_out.set_column(0, c1); 00099 W_out.set_column(1, c0); 00100 } 00101 } 00102 return true; 00103 } 00104 00105 void SweepWrapper::run_wrapper( Mesh* mesh, 00106 ParallelMesh* pmesh, 00107 MeshDomain* domain, 00108 Settings* settings, 00109 QualityAssessor* qa, 00110 MsqError& err ) 00111 { 00112 // construct target calculator 00113 TagVertexMesh source_mesh( err, mesh, false, initMeshTag.c_str() ); MSQ_ERRRTN(err); 00114 ReferenceMesh ref_mesh( &source_mesh ); 00115 RefMeshTargetCalculator ref_tc( &ref_mesh ); 00116 TargetFlipper flipped_targets( &ref_tc ); 00117 00118 // construct objective function 00119 //TRel2DShape shape2d; 00120 //TRel3DShape shape3d; 00121 TShapeNB1 shape; 00122 //TShapeNB1 shape3d; 00123 TQualityMetric metric(&flipped_targets, &shape); 00124 PMeanPTemplate objfunc( 2.0, &metric ); 00125 00126 // construct smoother 00127 //TrustRegion solver(&objfunc); 00128 //ConjugateGradient solver(&objfunc); 00129 SteepestDescent solver(&objfunc); 00130 //QuasiNewton solver(&objfunc); 00131 00132 00133 TerminationCriterion terminate; 00134 terminate.add_absolute_vertex_movement( maxVtxMovement ); 00135 terminate.write_iterations( "mesquite.gpt", err ); 00136 solver.set_inner_termination_criterion( &terminate ); 00137 00138 // construct instruction queue 00139 qa->add_quality_assessment( &metric ); 00140 InstructionQueue q; 00141 q.add_quality_assessor( qa, err ); 00142 MSQ_ERRRTN(err); 00143 q.set_master_quality_improver( &solver, err ); 00144 MSQ_ERRRTN(err); 00145 q.add_quality_assessor( qa, err ); 00146 MSQ_ERRRTN(err); 00147 00148 // smooth mesh 00149 MeshDomainAssoc mesh_and_domain(mesh, domain); 00150 q.run_common( &mesh_and_domain, pmesh, settings, err ); 00151 MSQ_ERRRTN(err); 00152 } 00153 00154 } // namespace MESQUITE_NS