Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
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 }
00129 }
00130 }
00131 }
00132
00133 XMLObject CellCurvePredicate::toXML() const
00134 {
00135 XMLObject rtn("SundanceCellCurvePredicate");
00136 return rtn;
00137 }