SundanceCellCurvePredicate.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 //
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 //
00007 // Copyright (year first published) Sandia Corporation.  Under the terms
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00009 // retains certain rights in this software.
00010 //
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Kevin Long (krlong@sandia.gov),
00026 // Sandia National Laboratories, Livermore, California, USA
00027 //
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 /*
00032  * SundanceCellCurvePredicate.cpp
00033  *
00034  *  Created on: Feb 19, 2010
00035  *      Author: benk
00036  */
00037 
00038 #include "SundanceCellCurvePredicate.hpp"
00039 #include "SundanceStdMathOps.hpp"
00040 
00041 using namespace Sundance;
00042 
00043 #define SIGN(X) ((X>0.0)?1:-1)
00044 
00045 bool CellCurvePredicate::lessThan(const CellPredicateBase* other) const
00046 {
00047   const CellCurvePredicate* S = dynamic_cast<const CellCurvePredicate*>(other);
00048 
00049   TEST_FOR_EXCEPTION( S== 0,
00050                      InternalError,
00051                      "argument " << other->toXML()
00052                      << " to CellCurvePredicate::lessThan() should be "
00053                      "a CellCurvePredicate pointer.");
00054   // This comparison is IMPORTANT, to determine RQCs
00055   return OrderedPair<ParametrizedCurve, int>(curve_, (int)filterMode_)
00056       < OrderedPair<ParametrizedCurve, int>(S->curve_, (int)S->filterMode_);
00057 }
00058 
00059 void CellCurvePredicate::testBatch(const Array<int>& cellLID,
00060                                         Array<int>& results) const
00061 {
00062   results.resize(cellLID.size());
00063 
00064   if (cellDim()==0)
00065     {
00066     switch (filterMode_){
00067     case Outside_Curve:
00068         for (int i=0; i<cellLID.size(); i++)
00069           if ( curve_.curveEquation( mesh().nodePosition(cellLID[i])) > 0.0 )
00070                 results[i] = true;
00071           else
00072             results[i] = false;
00073       break;
00074     case Inside_Curve:
00075         for (int i=0; i<cellLID.size(); i++)
00076           if ( curve_.curveEquation( mesh().nodePosition(cellLID[i])) < 0.0 )
00077                 results[i] = true;
00078           else
00079             results[i] = false;
00080       break;
00081     case On_Curve:
00082         for (int i=0; i<cellLID.size(); i++)
00083           if ( fabs(curve_.curveEquation( mesh().nodePosition(cellLID[i]))) < 1e-8 )
00084                 results[i] = true;
00085           else
00086             results[i] = false;
00087       break;
00088     }
00089     }
00090   else
00091     {
00092       Array<int> facetLIDs;
00093       Array<int> facetSigns;
00094       int nf = mesh().numFacets(cellDim(), cellLID[0], 0);
00095       mesh().getFacetLIDs(cellDim(), cellLID, 0, facetLIDs, facetSigns);
00096       for (int c=0; c<cellLID.size(); c++)
00097         {
00098           results[c] = true;
00099           if (filterMode_ == On_Curve) results[c] = false;
00100           int curve_sign = 0;
00101           for (int f=0; f<nf; f++)
00102             {
00103             int fLID = facetLIDs[c*nf + f];
00104             switch (filterMode_){
00105             case Outside_Curve:
00106               if ( curve_.curveEquation( mesh().nodePosition(fLID) ) <= 0.0 ) {
00107                  results[c] = false;
00108                  continue;
00109               }
00110               break;
00111             case Inside_Curve:
00112               if ( curve_.curveEquation( mesh().nodePosition(fLID) ) >= 0.0 ) {
00113                  results[c] = false;
00114                  continue;
00115               }
00116               break;
00117             case On_Curve:
00118               if (f == 0){
00119                 curve_sign = SIGN(curve_.curveEquation( mesh().nodePosition(fLID)));
00120               } else {
00121                 if ( curve_sign != SIGN(curve_.curveEquation( mesh().nodePosition(fLID))) ){
00122                      results[c] = true;
00123                      continue;
00124                 }
00125               }
00126               break;
00127             }
00128             } // from for loop
00129         }
00130     }
00131 }
00132 
00133 XMLObject CellCurvePredicate::toXML() const
00134 {
00135   XMLObject rtn("SundanceCellCurvePredicate");
00136   return rtn;
00137 }

Site Contact