コード例 #1
0
//---------------------------------------------------------
// Matlab "intersect" operation
//---------------------------------------------------------
IVec& intersect(const IVec& A, const IVec& B)
{
  // return integer values contained in both 
  // A and B, sorted and without duplicates
  IVec *tmp = new IVec("(A)&(B)", OBJ_temp);

  int Na=A.size(), Nb=B.size(), i=0, val=0, sk=0;
  if (Na<1 || Nb<1) {
    // degenerate case: one array is empty
    tmp->resize(0);
  }
  else
  {
    typedef std::set<int>::iterator SetIt;

    // sort and remove duplicates from A and B by loading into sets
    std::set<int> sA, sB, sC;
    for (i=1; i<=Na; ++i) {sA.insert(A(i));} int lenA = (int) sA.size();
    for (i=1; i<=Nb; ++i) {sB.insert(B(i));} int lenB = (int) sB.size();

    // Use set "C" to store unique values from the 
    // smaller set which also occur in larger set
    SetIt it, it2;
    if (lenA <= lenB) {
      //---------------------------------
      // find values in A that occur in B
      //---------------------------------
      for (it=sA.begin(); it!=sA.end(); it++) {
        val = (*it);
        it2=sB.find(val);
        if (it2 != sB.end()) {
          sC.insert(val);
        }
      }
    } else {
      //---------------------------------
      // find values in B that occur in A
      //---------------------------------
      for (it=sB.begin(); it!=sB.end(); it++) {
        val = (*it);
        it2=sA.find(val);
        if (it2 != sA.end()) {
          sC.insert(val);
        }
      }
    }

    int lenC = (int) sC.size(); tmp->resize(lenC);  
    for (it=sC.begin(), sk=1; it!=sC.end(); it++, sk++) {
      (*tmp)(sk) = (*it);
    }
  }
  if (A.get_mode() == OBJ_temp) { delete (&A); }
  if (B.get_mode() == OBJ_temp) { delete (&B); }
  return (*tmp);
}
コード例 #2
0
//---------------------------------------------------------
void CurvedINS2D::INScylinderBC2D
(
  const DVec&   xin,    // [in]
  const DVec&   yin,    // [in]
  const DVec&   nxi,    // [in]
  const DVec&   nyi,    // [in]
  const IVec&   MAPI,   // [in]
  const IVec&   MAPO,   // [in]
  const IVec&   MAPW,   // [in]
  const IVec&   MAPC,   // [in]
        double  ti,     // [in]
        double  nu,     // [in]
        DVec&   BCUX,   // [out]
        DVec&   BCUY,   // [out]
        DVec&   BCPR,   // [out]
        DVec&   BCDUNDT // [out]
)
//---------------------------------------------------------
{
  // function [bcUx, bcUy, bcPR, bcdUndt] = INScylinderBC2D(x, y, nx, ny, mapI, mapO, mapW, mapC, time, nu)
  // Purpose: evaluate boundary conditions for channel bounded cylinder flow with walls at y=+/- .15

  // TEST CASE: from 
  // V. John "Reference values for drag and lift of a two-dimensional time dependent flow around a cylinder", 
  // Int. J. Numer. Meth. Fluids 44, 777 - 788, 2004

  DVec yI("yI");  int len = xin.size();
  BCUX.resize(len); BCUY.resize(len);     // resize result arrays
  BCPR.resize(len); BCDUNDT.resize(len);  // and set to zero

  // inflow
#ifdef _MSC_VER
  yI = yin(MAPI);  yI += 0.20;
#else
  int Ni=MAPI.size(); yI.resize(Ni);
  for(int n=1;n<=Ni;++n) {yI(n)=yin(MAPI(n))+0.2;}
#endif

  BCUX(MAPI)    =  SQ(1.0/0.41)*6.0 * yI.dm(0.41 - yI);
  BCUY(MAPI)    =  0.0;
  BCDUNDT(MAPI) = -SQ(1.0/0.41)*6.0 * yI.dm(0.41 - yI);

  // wall
  BCUX(MAPW) = 0.0;
  BCUY(MAPW) = 0.0;

  // cylinder
  BCUX(MAPC) = 0.0;
  BCUY(MAPC) = 0.0;

  // outflow
  BCUX(MAPO)    = 0.0;
  BCUY(MAPO)    = 0.0;
  BCDUNDT(MAPO) = 0.0;
}
コード例 #3
0
ファイル: OCCEdge.cpp プロジェクト: erossignon/occmodel
int OCCEdge::createNURBS(OCCVertex *start, OCCVertex *end, std::vector<OCCStruct3d> points,
                          DVec knots, DVec weights, IVec mult)
{
    try {
        Standard_Boolean periodic = false;
        
        int vertices = 0;
        if (start != NULL && end != NULL) {
            vertices = 2;
            periodic = true;
        }
        
        int nbControlPoints = points.size() + vertices;
        TColgp_Array1OfPnt  ctrlPoints(1, nbControlPoints);
        
        TColStd_Array1OfReal _knots(1, knots.size());
        TColStd_Array1OfReal _weights(1, weights.size());
        TColStd_Array1OfInteger  _mult(1, mult.size());
        
        for (unsigned i = 0; i < knots.size(); i++) {
            _knots.SetValue(i+1, knots[i]);
        }
        
        for (unsigned i = 0; i < weights.size(); i++) {
            _weights.SetValue(i+1, weights[i]);
        }
        
        int totKnots = 0;
        for (unsigned i = 0; i < mult.size(); i++) {
            _mult.SetValue(i+1, mult[i]);   
            totKnots += mult[i];
        }

        const int degree = totKnots - nbControlPoints - 1;

        int index = 1;
        
        if (!periodic) {
            ctrlPoints.SetValue(index++, gp_Pnt(start->X(), start->Y(), start->Z()));
        }
        
        for (unsigned i = 0; i < points.size(); i++) {
            gp_Pnt aP(points[i].x,points[i].y,points[i].z);
            ctrlPoints.SetValue(index++, aP);
        }
        
        if (!periodic) {
            ctrlPoints.SetValue(index++, gp_Pnt(end->X(), end->Y(), end->Z()));
        }
        
        Handle(Geom_BSplineCurve) NURBS = new Geom_BSplineCurve
        (ctrlPoints, _weights, _knots, _mult, degree, periodic);
        
        if (!periodic) {
            this->setShape(BRepBuilderAPI_MakeEdge(NURBS, start->vertex, end->vertex));
        } else {
            this->setShape(BRepBuilderAPI_MakeEdge(NURBS));
        }
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create nurbs");
        }
        return 1;
    }
    return 0;
}
コード例 #4
0
//---------------------------------------------------------
void CurvedINS2D::KovasznayBC2D
(
  const DVec&   xin,    // [in]
  const DVec&   yin,    // [in]
  const DVec&   nxi,    // [in]
  const DVec&   nyi,    // [in]
  const IVec&   MAPI,   // [in]
  const IVec&   MAPO,   // [in]
  const IVec&   MAPW,   // [in]
  const IVec&   MAPC,   // [in]
        double  ti,     // [in]
        double  nu,     // [in]
        DVec&   BCUX,   // [out]
        DVec&   BCUY,   // [out]
        DVec&   BCPR,   // [out]
        DVec&   BCDUNDT // [out]
)
//---------------------------------------------------------
{
  // function [bcUx, bcUy, bcPR, bcdUndt] = KovasznayBC2D(x, y, nx, ny, MAPI, MAPO, MAPW, MAPC, time, nu)
  // Purpose: evaluate boundary conditions for Kovasznay flow 

  static DVec xI("xI"), yI("yI"), xO("xO"), yO("yO");

  int len = xin.size();
  BCUX.resize(len); BCUY.resize(len);     // resize result arrays
  BCPR.resize(len); BCDUNDT.resize(len);  // and set to zero

  double lam = (0.5/nu) - sqrt( (0.25/SQ(nu)) + 4.0*SQ(pi));

  // inflow
#ifdef _MSC_VER
  xI = xin(MAPI);  yI = yin(MAPI);
#else
  int Ni=MAPI.size(), n=0; xI.resize(Ni); yI.resize(Ni);
  for (n=1;n<=Ni;++n) {xI(n)=xin(MAPI(n));}
  for (n=1;n<=Ni;++n) {yI(n)=yin(MAPI(n));}
#endif

  DVec elamXI = exp(lam*xI), twopiyI = 2.0*pi*yI;

  BCUX(MAPI) =          1.0 - elamXI.dm(cos(twopiyI));
  BCUY(MAPI) = (0.5*lam/pi) * elamXI.dm(sin(twopiyI));


  // outflow
#ifdef _MSC_VER
  xO = xin(MAPO); yO = yin(MAPO);
#else
  int No=MAPO.size(); xO.resize(No); yO.resize(No);
  for (n=1;n<=No;++n) {xO(n)=xin(MAPO(n));}
  for (n=1;n<=No;++n) {yO(n)=yin(MAPO(n));}
#endif

  DVec elamXO = exp(lam*xO), twopiyO = 2.0*pi*yO;

  BCPR   (MAPO) =  0.5*(1.0-exp(2.0*lam*xO));
//BCDUNDT(MAPO) = -lam*elamXO.dm(cos(twopiyO));

  if (0) {
    // THIS WORKED
    BCUX(MAPO) =         1.0  - elamXO.dm(cos(twopiyO));
    BCUY(MAPO) = (0.5*lam/pi) * elamXO.dm(sin(twopiyO));
  } else {
    // Neumann data for each velocity
    BCUX(MAPO) = -lam*               elamXO.dm(cos(twopiyO));
    BCUY(MAPO) =  lam*(0.5*lam/pi) * elamXO.dm(sin(twopiyO));
  }
}
コード例 #5
0
void dumpIV(const IV& X, const char* s) { 
  IVec V; V.copy(X.size(), X.data());
  V.print(g_MSGFile, s, "d",  0, 4, true); 
}
コード例 #6
0
void dumpIVec(const IVec& V, const char* s) { V.print(g_MSGFile, s, "d",  0, 4, true); }
コード例 #7
0
// free unused allocations in the array registries
//---------------------------------------------------------
void NDG_garbage_collect()
//---------------------------------------------------------
{
  DVec dv; dv.compact();  umTRC(2, "*** compacted <double> *** \n");
  IVec iv; iv.compact();  umTRC(2, "*** compacted <int>    *** \n");
}