Ejemplo n.º 1
0
    /**
     * Grow the tree in the direction of @state
     *
     * @return the new tree Node (may be nullptr if we hit Obstacles)
     * @param target The point to extend the tree to
     * @param source The Node to connect from.  If source == nullptr, then
     *             the closest tree point is used
     */
    virtual Node<T>* extend(const T& target, Node<T>* source = nullptr) {
        //  if we weren't given a source point, try to find a close node
        if (!source) {
            source = nearest(target, nullptr);
            if (!source) {
                return nullptr;
            }
        }

        //  Get a state that's in the direction of @target from @source.
        //  This should take a step in that direction, but not go all the
        //  way unless the they're really close together.
        T intermediateState;
        if (_isASCEnabled) {
            intermediateState = _stateSpace->intermediateState(
                source->state(), target, stepSize(), maxStepSize());
        } else {
            intermediateState = _stateSpace->intermediateState(
                source->state(), target, stepSize());
        }

        //  Make sure there's actually a direct path from @source to
        //  @intermediateState.  If not, abort
        if (!_stateSpace->transitionValid(source->state(), intermediateState)) {
            return nullptr;
        }

        // Add a node to the tree for this state
        Node<T>* n = new Node<T>(intermediateState, source);
        _nodes.push_back(n);
        return n;
    }
//	VERSION  2A).  //
TRIANGLE* MarchingCubes(float mcMinX, float mcMaxX, float mcMinY, float mcMaxY, float mcMinZ, float mcMaxZ, 
							int ncellsX, int ncellsY, int ncellsZ, float minValue, 
							FORMULA formula, INTERSECTION intersection, int &numTriangles)
{
	//space is already defined and subdivided, staring with step 3
	//first initialize the points
	mp4Vector * mcDataPoints = new mp4Vector[(ncellsX+1)*(ncellsY+1)*(ncellsZ+1)];
	mpVector stepSize((mcMaxX-mcMinX)/ncellsX, (mcMaxY-mcMinY)/ncellsY, (mcMaxZ-mcMinZ)/ncellsZ);
	
	int YtimesZ = (ncellsY+1)*(ncellsZ+1);	//for extra speed
	for(int i=0; i < ncellsX+1; i++) {
		int ni = i*YtimesZ;						//for speed
		float vertX = mcMinX + i*stepSize.x;
		for(int j=0; j < ncellsY+1; j++) {
			int nj = j*(ncellsZ+1);				//for speed
			float vertY = mcMinY + j*stepSize.y;
			for(int k=0; k < ncellsZ+1; k++) {
				mp4Vector vert(vertX, vertY, mcMinZ + k*stepSize.z, 0);
				vert.val = formula((mpVector)vert);
   /*(step 3)*/ mcDataPoints[ni + nj + k] = vert;
			}
		}
	}
	//then run Marching Cubes (version 1A) on the data
	return MarchingCubes(ncellsX, ncellsY, ncellsZ, minValue, mcDataPoints, intersection, numTriangles);
}
bool CompliantGraspCopyTask::compliantCopy(const db_planner::Grasp *grasp, Pr2Gripper2010::ComplianceType compliance)
{
  //open slowly (2 degrees increments)
  //also, positive change means open for the pr2 gripper
  double OPEN_BY = 0.035;
  Pr2Gripper2010 *gripper = static_cast<Pr2Gripper2010 *>(mHand);
  gripper->setCompliance(compliance);

  std::vector<double> dof(mHand->getNumDOF(), 0.0);
  std::vector<double> stepSize(mHand->getNumDOF(), M_PI / 36.0);
  mHand->getDOFVals(&dof[0]);
  bool done = false;
  transf lastTran = mHand->getTran();
  while (!done)
  {
    //DBGA("Move loop");
    //open the hand a little bit
    for (int d = 0; d < mHand->getNumDOF(); d++) {
      dof[d] += OPEN_BY;
    }
    mHand->checkSetDOFVals(&dof[0]);
    mHand->moveDOFToContacts(&dof[0], &stepSize[0], true, false);

    //if we are far enough from the last saved grasp, go ahead and save a new one
    transf currentTran = mHand->getTran();
    if (!similarity(currentTran, lastTran)) {
      //save the grasp
      DBGA("Storing a compliant copy");
      //compliance messes up the pre-grasp computation
      gripper->setCompliance(Pr2Gripper2010::NONE);
      if (!checkStoreGrasp(grasp)) {
        return false;
      }
      gripper->setCompliance(compliance);
      //remember the last saved grasp
      lastTran = currentTran;
    }

    //if we have not opened as much as we wanted to, we've hit something; we are done
    for (int d = 0; d < mHand->getNumDOF(); d++) {
      if (fabs(mHand->getDOF(d)->getVal() - dof[d]) > 1.0e-5 ||
          dof[d] == mHand->getDOF(d)->getMin() ||
          dof[d] == mHand->getDOF(d)->getMax()) {
        //DBGA("Done moving");
        done = true;
        break;
      }
    }
  }
  return true;
}
Ejemplo n.º 4
0
void vEqnCoeff()
{

	stepSize();

	//Convective Fluxes
	if(u[i][j+1][k][l] + u[i][j][k][l]==0)	Fned=0;
	else Fned = rho * 2 * u[i][j+1][k][l]   * u[i][j][k][l]    / (u[i][j+1][k][l]   + u[i][j][k][l]  ) *dy*dz; //harmonic mean of ue and uNe

	if(u[i-1][j+1][k][l] + u[i-1][j][k][l]==0)	Fnw=0;
	else	Fnw  = rho * 2 * u[i-1][j+1][k][l] * u[i-1][j][k][l]  / (u[i-1][j+1][k][l] + u[i-1][j][k][l]) *dy*dz; //harmonic mean of uw and uNw

	if(v[i][j+1][k][l] + v[i][j][k][l]==0)	FN=0;
	else	FN   = rho * 2 * v[i][j+1][k][l]   * v[i][j][k][l]    / (v[i][j+1][k][l]   + v[i][j][k][l]  ) *dx*dz; //harmonic mean of vn and vnn

	if(v[i][j-1][k][l] + v[i][j][k][l]==0)	FPd=0;
	else	FPd  = rho * 2 * v[i][j-1][k][l]   * v[i][j][k][l]    / (v[i][j-1][k][l]   + v[i][j][k][l]  ) *dx*dz; //harmonic mean of vn and vs

	if(w[i][j+1][k][l] + w[i][j][k][l]==0)	Fnt=0;
	else	Fnt  = rho * 2 * w[i][j+1][k][l]   * w[i][j][k][l]    / (w[i][j+1][k][l]   + w[i][j][k][l]  ) *dx*dy; //harmonic mean of wt and wNt

	if(w[i][j+1][k-1][l] + w[i][j][k-1][l]==0)	Fnb=0;
	else	Fnb  = rho * 2 * w[i][j+1][k-1][l] * w[i][j][k-1][l]  / (w[i][j+1][k-1][l] + w[i][j][k-1][l]) *dx*dy; //harmonic mean of wb and wNb

	//constant
	bb = mu*(u[i][j+1][k][l]-u[i][j][k][l])*dz - mu*(u[i-1][j+1][k][l]-u[i-1][j][k][l])*dz + mu*(w[i][j+1][k][l]-w[i][j][k][l])*dx - mu*(w[i][j+1][k-1][l]-w[i][j][k-1][l])*dx + rho*yGrav*dx*dy*dz + rho*v[i][j][k][l-1]*dx*dy*dz/dt;  //rho at n

	//Diffusion Fluxes
	Dned=     mu * dy * dz/dx; //mu at ne
	Dnw =     mu * dy * dz/dx; //mu at nw
	DN  = 2 * mu * dx * dz/dy; //mu at N
	DPd = 2 * mu * dx * dz/dy; //mu at P
	Dnt =     mu * dx * dy/dz; //mu at nt
	Dnb =     mu * dx * dy/dz; //mu at nb


	//Coeff of the Equation
	anE = Dned- Fned/ 2;
	anW = Dnw + Fnw / 2;
	ann = DN  + std::max(-FN,0.0);  //upwind Scheme
	as  = DPd + std::max(FPd,0.0);  //upwind Scheme
	anT = Dnt - Fnt / 2;
	anB = Dnb + Fnb / 2;
	an  = anE + anW + ann + as + anT + anB + (Fned - Fnw + Fnt - Fnb + rho*dx*dy*dz/dt); //rho at n

	An = dx*dz/an;
	BB = bb/an;


}
Ejemplo n.º 5
0
void MarchingCube::updateDensityField()
{
    btVector3 stepSize(bMax - bMin);
    stepSize.setX(stepSize.x() / ncellsX);
    stepSize.setY(stepSize.y() / ncellsY);
    stepSize.setZ(stepSize.z() / ncellsZ);
    
    for(int i=0; i < ncellsX+1; i++)
        for(int j=0; j < ncellsY+1; j++)
            for(int k=0; k < ncellsZ+1; k++) {
                mp4Vector vert(bMin.x()+i*stepSize.x(), bMin.y()+j*stepSize.y(), bMin.z()+k*stepSize.z(), 0);
                vert.val = Potential((mpVector)vert, fluid->internalGetParticles());
                mcPoints[i*(ncellsY+1)*(ncellsZ+1) + j*(ncellsZ+1) + k] = vert;
            }
}
Ejemplo n.º 6
0
        /**
         * Grow the tree in the direction of @state
         *
         * @return the new tree Node (may be nullptr if we hit Obstacles)
         * @param source The Node to connect from.  If source == nullptr, then
         *             the closest tree point is used
         */
        virtual Node<T> *extend(const T &target, Node<T> *source = nullptr) {
            //  if we weren't given a source point, try to find a close node
            if (!source) {
                source = nearest(target);
                if (!source) {
                    return nullptr;
                }
            }

            //  if they're the same point, don't add it to the tree again
            float dist;
            if (_reverse) {
                dist = _stateSpace->distance(target, source->state());
            } else {
                dist = _stateSpace->distance(source->state(), target);
            }
            // FIXME: this distance check should be against a relative, not
            // absolute threshold
            if (dist < 0.0001) {
                return nullptr;
            }

            //  Get a state that's in the direction of @target from @source.
            //  This should take a step in that direction, but not go all the
            //  way unless the they're really close together.
            T intermediateState = _stateSpace->intermediateState(
                source->state(), target, stepSize(), _reverse);

            //  Make sure there's actually a direct path from @source to
            //  @intermediateState.  If not, abort
            bool transitionValid;
            if (_reverse) {
                transitionValid = _stateSpace->transitionValid(
                    intermediateState, source->state());
            } else {
                transitionValid = _stateSpace->transitionValid(
                    source->state(), intermediateState);
            }
            if (!transitionValid) return nullptr;

            //  Add a node to the tree for this state
            Node<T> *n = new Node<T>(intermediateState, source);
            _nodes.push_back(n);
            return n;
        }
Ejemplo n.º 7
0
static cv::Mat patchImage(const cv::Mat &image, int patchSize, bool reduceMean=false)
{
    vector<int> blockSize(2, patchSize);
    vector<int> stepSize(2, 1);
    cv::Mat temp = im2col(image, blockSize, stepSize);
    if (! reduceMean)
        return temp;

    cv::Mat mean;
    cv::reduce(temp, mean, 0, cv::REDUCE_AVG);
    cv::Mat res;
    for (int i=0; i<temp.rows; i++)
    {
        cv::Mat temp2 = (temp.row(i) - mean.row(0));
        res.push_back(temp2.row(0));
    }
    return res;
}
HRESULT CVolumeRaycasting::OnResetDevice(LPDIRECT3DDEVICE9 pD3DDevice)
{
	CObject::OnResetDevice( pD3DDevice );

	m_fxShader = CShaderManager::GetInstance()->GetShader( m_hShader );
	
	if(!m_pVolume || !m_fxShader) return E_FAIL;

	HRESULT hr;
	D3DPRESENT_PARAMETERS pp = DXUTGetDeviceSettings().d3d9.pp;

	SAFE_RELEASE( m_pBack );
	V_RETURN( D3DXCreateTexture(m_pD3DDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, pp.BackBufferFormat, D3DPOOL_DEFAULT, &m_pBack));

	SAFE_RELEASE( m_pFront );
	V_RETURN( D3DXCreateTexture(m_pD3DDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, pp.BackBufferFormat, D3DPOOL_DEFAULT, &m_pFront));

	int iWidth = m_pVolume->m_iWidth, iHeight = m_pVolume->m_iHeight, iDepth = m_pVolume->m_iDepth;

	float maxSize = (float)max(iWidth, max(iHeight, iDepth));
	D3DXVECTOR3 stepSize(1.0f  / (iWidth * (maxSize / iWidth)),
						   1.0f / (iHeight * (maxSize / iHeight)),
						   1.0f / (iDepth * (maxSize / iDepth)));


	float mStepScale = 0.5;

	stepSize = stepSize * mStepScale;
	m_fxShader->SetFloatArray("SampleDist", (const FLOAT*)&stepSize, 3);
	m_fxShader->SetFloat("ActualSampleDist", mStepScale);
	m_fxShader->SetInt("Iterations", (int)(maxSize * (1.0f / mStepScale) * 2.0f));

	//calculate the scale factor
	//volumes are not always perfect cubes. so we need to scale our cube
	//by the sizes of the volume. Also, scalar data is not always sampled
	//at equidistant steps. So we also need to scale the cube model by mRatios.
	D3DXVECTOR4 ratios( iWidth / maxSize, iHeight / maxSize, iDepth / maxSize, 1.0f);
	m_fxShader->SetFloatArray("ScaleFactor", (const FLOAT*)&ratios, 4);
	m_fxShader->SetTexture( "Volume", m_pVolume->m_pVolumeTexture );
	m_fxShader->SetTexture( "Transfer", m_pVolume->m_pTransferFunction );


	return D3D_OK;
}
Point EscapeObstaclesPathPlanner::findNonBlockedGoal(
    Point goal, boost::optional<Point> prevGoal, const ShapeSet& obstacles,
    int maxItr) {
    if (obstacles.hit(goal)) {
        FixedStepTree goalTree;
        goalTree.init(goal, &obstacles);
        goalTree.step = stepSize();

        // The starting point is in an obstacle, extend the tree until we find
        // an unobstructed point
        Point newGoal;
        for (int i = 0; i < maxItr; ++i) {
            // extend towards a random point
            Tree::Point* newPoint = goalTree.extend(RandomFieldLocation());

            // if the new point is not blocked, it becomes the new goal
            if (newPoint && newPoint->hit.empty()) {
                newGoal = newPoint->pos;
                break;
            }
        }

        if (!prevGoal || obstacles.hit(*prevGoal)) return newGoal;

        // Only use this newly-found point if it's closer to the desired goal by
        // at least a certain threshold
        float oldDist = (*prevGoal - goal).mag();
        float newDist = (newGoal - goal).mag();
        if (newDist + *_goalChangeThreshold < oldDist) {
            return newGoal;
        } else {
            return *prevGoal;
        }
    }

    return goal;
}
Ejemplo n.º 10
0
int 
Server::main()
{
#ifndef WINDOOF
  signal(SIGPIPE,sigPipeHandler);
#endif
  signal(SIGTERM,sigTermHandler);
  signal(SIGINT,sigTermHandler);

  NetStreamBufServer listener(m_config.m_port);
  listener.init();
  listener.newConnection.connect(SigC::slot(*this,&Server::handleNewConnection));
  listener.dataAvailable.connect(SigC::slot(*this,&Server::handleDataAvailable));
  listener.connectionClosed.connect(SigC::slot(*this,&Server::handleConnectionClosed));

  if (!m_config.m_useMetaServer)
    m_config.m_metaServer.clear();
  else{
    if (m_config.m_myAddress.empty())
      /* myAddress not set => we only report our port and the metaserver will use the ip
	 from which it was connected (if the server is behind a nat-firewall this means
	 that the nat firewall must redirect this port to the server) */
      m_maddr.port=m_config.m_port;
    else{
      /* myAddress is set => we report it to the metaserver (if the address contains a :
	 the port is assumed to follow the :
      */
      m_maddr.adr=m_config.m_myAddress;
      std::string::size_type pos(m_maddr.adr.find_first_of(':'));
      if (pos!=std::string::npos) {
	if (pos+1<m_maddr.adr.size())
	  stringToAny(std::string(m_maddr.adr,pos+1),m_maddr.port);
	else
	  m_maddr.port=m_config.m_port;
	m_maddr.adr=std::string(m_maddr.adr,0,pos);
      }
    }
  }
  const std::string &msURI(m_config.m_metaServer);
  if (!msURI.empty()) {
    try {
      MetaServer metaServer(msURI.c_str());
      RegisterServer reg;
      reg.host=m_maddr;
      ServerRegistered answer;
      metaServer.rpc(reg,answer);
      std::cerr << "Metaserver answered !:\nRegistered: " << answer.registered << " , secret:"<<answer.secret<<std::endl;
      m_msecret=answer.secret;

      updateMetaserver();
    }catch(...){
      DOPE_WARN("Could not connect to Metaserver\n");
    }
  }
  
  TimeStamp start;
  start.now();
  TimeStamp oldTime;
  TimeStamp newTime;
  TimeStamp stepSize(0,11111); // ~90Hz
  TimeStamp frameSize(stepSize);
  TimeStamp dt;
  TimeStamp null;
  TimeStamp timeOut;
  oldTime.now();
  unsigned frames=0;
  while (!quit) {
    listener.select(&null); // test for input and emit corresponding signals
    newTime.now();
    dt=newTime-oldTime;
    // consume remaining time (this is the end of one frame)
    while(dt<frameSize) {
      timeOut=(frameSize-dt);
      listener.select(&timeOut);
      newTime.now();
      dt=newTime-oldTime;
    }

#ifdef ADIC_DEBUG_TIMING
    // todo remove again
    // last frame size was dt
    // and it should have been frameSize
    std::cerr << "\nLast frame took: "
	      << (R(dt.getSec())+(R(dt.getUSec())/1000000))
	      << " and should have taken: "
	      << (R(frameSize.getSec())+(R(frameSize.getUSec())/1000000));
#endif

    frameSize=(dt-frameSize);
    int eframes=1;
    while (frameSize>stepSize) {
      ++eframes;
      frameSize-=stepSize;
    }
    frameSize=stepSize-frameSize;

#ifdef ADIC_DEBUG_TIMING
    // todo remove again
    std::cerr << "\nFramesize: "<< (R(frameSize.getSec())+(R(frameSize.getUSec())/1000000));
    if (eframes>1) {
      DOPE_WARN("\nmachine too slow: calculate "<<eframes<<" frames at once");
    }
#endif

    // start of one frame
    R rdt(R(stepSize.getSec())+R(stepSize.getUSec())/1000000);
    for (int f=0;f<eframes;++f)
      m_game.step(rdt);

    // todo perhaps choose different frames for different clients
    if (!(frames%m_config.m_broadcastFreq))
      broadcastGame();
    // check for win condition
    TeamID wt;
    int winner(m_game.getWinner(wt));
    if (winner) {
      if (winner==2)
	std::cout << "\nThe game ended in a draw\n";
      else
	// the winner is
	std::cout << "\nTeam \""<<m_game.getTeams()[wt].name << "\" wins\n";
      EndGame msg;
      msg.reason=winner;
      msg.winner=wt;
      broadcast(msg);
      restart();
      
    }
    
    oldTime=newTime;
    ++frames;
    dt=newTime-start;
    R uptime=R(dt.getSec())+(R(dt.getUSec())/1000000);
    std::cout << "\rUp: " << std::fixed << std::setprecision(2) << std::setw(8) << uptime 
	      << " FPS: " << std::setw(6) << R(frames)/uptime 
	      << " Frame: " << std::setw(8) << frames;
  }
  connections.clear();

  if (!m_msecret.empty()) {
    try {
      MetaServer metaServer(msURI.c_str());
      ServerExit exitmsg;
      exitmsg.host=m_maddr;
      exitmsg.secret=m_msecret;
      
      Result answer;
      metaServer.rpc(exitmsg,answer);
      answer.print();
    }catch(...){
      DOPE_WARN("Could not connect to Metaserver\n");
    }
  }
  return 0;
}
Ejemplo n.º 11
0
int QRangeModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: valueChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 1: positionChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 2: stepSizeChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 3: invertedChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 4: minimumChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 5: maximumChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 6: positionAtMinimumChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 7: positionAtMaximumChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 8: toMinimum(); break;
        case 9: toMaximum(); break;
        case 10: setValue((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 11: setPosition((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 12: { qreal _r = valueForPosition((*reinterpret_cast< qreal(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< qreal*>(_a[0]) = _r; }  break;
        case 13: { qreal _r = positionForValue((*reinterpret_cast< qreal(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< qreal*>(_a[0]) = _r; }  break;
        default: ;
        }
        _id -= 14;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< qreal*>(_v) = value(); break;
        case 1: *reinterpret_cast< qreal*>(_v) = minimum(); break;
        case 2: *reinterpret_cast< qreal*>(_v) = maximum(); break;
        case 3: *reinterpret_cast< qreal*>(_v) = stepSize(); break;
        case 4: *reinterpret_cast< qreal*>(_v) = position(); break;
        case 5: *reinterpret_cast< qreal*>(_v) = positionAtMinimum(); break;
        case 6: *reinterpret_cast< qreal*>(_v) = positionAtMaximum(); break;
        case 7: *reinterpret_cast< bool*>(_v) = inverted(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setValue(*reinterpret_cast< qreal*>(_v)); break;
        case 1: setMinimum(*reinterpret_cast< qreal*>(_v)); break;
        case 2: setMaximum(*reinterpret_cast< qreal*>(_v)); break;
        case 3: setStepSize(*reinterpret_cast< qreal*>(_v)); break;
        case 4: setPosition(*reinterpret_cast< qreal*>(_v)); break;
        case 5: setPositionAtMinimum(*reinterpret_cast< qreal*>(_v)); break;
        case 6: setPositionAtMaximum(*reinterpret_cast< qreal*>(_v)); break;
        case 7: setInverted(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Ejemplo n.º 12
0
void uEqnCoeff()
{

	stepSize();
	
	//Convective Fluxes
	if(w[i][j][k][l] + w[i+1][j][k][l]==0)	Fte=0; 	
	else 	Fte = rho * 2 * w[i][j][k][l]   * w[i+1][j][k][l]   *dx*dy / (w[i][j][k][l]   +   w[i+1][j][k][l]);   //harmonic mean of wt and wtE

	if(w[i][j][k-1][l] + w[i+1][j][k-1][l]==0)	Fbe=0;	
	else	Fbe = rho * 2 * w[i][j][k-1][l] * w[i+1][j][k-1][l] *dx*dy / (w[i][j][k-1][l] +   w[i+1][j][k-1][l]); //harmonic mean of wb and wbE

	if(u[i][j][k][l] + u[i+1][j][k][l]==0)	FE=0;
	else	FE  = rho * 2 * u[i][j][k][l]   * u[i+1][j][k][l]   *dy*dz / (u[i][j][k][l]   +   u[i+1][j][k][l]);   //harmonic mean of ue and uee

	if(u[i][j][k][l] + u[i-1][j][k][l]==0)	FP=0;
	else	FP  = rho * 2 * u[i][j][k][l]   * u[i-1][j][k][l]   *dy*dz / (u[i][j][k][l]   +   u[i-1][j][k][l]);   //harmonic mean of ue and uw

	if(v[i][j][k][l] + v[i+1][j][k][l]==0)	Fne=0;
	else	Fne = rho * 2 * v[i][j][k][l]   * v[i+1][j][k][l]   *dx*dz / (v[i][j][k][l]   +   v[i+1][j][k][l]);   //harmonic mean of vn and vnE

	if(v[i][j-1][k][l] + v[i+1][j-1][k][l]==0)	Fse=0;
	else	Fse = rho * 2 * v[i][j-1][k][l] * v[i+1][j-1][k][l] *dx*dz / (v[i][j-1][k][l] +   v[i+1][j-1][k][l]); //harmonic mean of vs and vsE
	
	

	//constant 
 	b = mu*(v[i+1][j][k][l]-v[i][j][k][l])*dz - mu*(v[i+1][j-1][k][l]-v[i][j-1][k][l])*dz + mu*(w[i+1][j][k][l]-w[i][j][k][l])*dy - mu*(w[i+1][j][k-1][l]-w[i][j][k-1][l])*dy + rho*xGrav*dx*dy*dz + rho*u[i][j][k][l-1]*dx*dy*dz/dt; //rho at e



	if(dx==0)	printf("ERROR dx=0");
	if(dy==0)	printf("ERROR dy=0");
	if(dz==0)	printf("ERROR dz=0");
	if(dt==0)	printf("ERROR dt=0");
	

	//Diffusion Fluxes
	DE  = 2 * mu * dy * dz / dx; //mu at E
	DP  = 2 * mu * dy * dz / dx; //mu at P
	Dne =     mu * dx * dz / dy; //mu at ne
	Dse =     mu * dx * dz / dy; //mu at se
	Dte =     mu * dx * dy / dz; //mu at te
	Dbe =     mu * dx * dy / dz; //mu at be


	//Coeff of the Equation
	aee = std::max(-FE,0.0) + DE;  //upwind Scheme
	aw  = std::max(FP,0.0)  + DP;  //upwind Scheme
	aNe = Dne - Fne/2;
	aSe = Dse + Fse/2;
	aTe = Dte - Fte/2;
	aBe = Dbe + Fbe/2;
	ae  = aee + aw + aNe + aSe + aTe + aBe + (Fne - Fse + Fte - Fbe + rho*dx*dy*dz/dt); //rho at e

	Ae = dy*dz/ae;
	B  = b / ae; 

	


}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
  if(argc < 7)
  {
    cerr << "Usage : " << argv[0] 
         << " xDimMax yDimMax edgeCost stepSize choice(R/W) filename" << endl;
    exit(0);
  }

  size_t xMax(0);
  size_t yMax(0);
  size_t stepSize(DEFAULT_L1_INC);
  double maxEC(EDGE_COST_MAX);
  int    choice;

  xMax = (size_t) atoi(argv[1]);
  yMax = (size_t) atoi(argv[2]);

  if(argc >= 4)
  {
    maxEC = atof(argv[3]);
  }
  
  if(argc >= 5)
  {
    stepSize = atoi(argv[4]);
  }

  if(argc >= 6)
  {
    choice = argv[5][0];
  }

  /*
  grid testGW(xMax, yMax, maxEC);

  testGW.ConstructGrid();
  testGW.Print();

  ofstream fout;
  string fName = argv[7];
  fout.open(fName.c_str());
  testGW.WriteToFile(fout);
  fout.close();

  grid testGR;
  ifstream fin;
  fin.open(fName.c_str());
  testGR.ReadFromFile(fin);
  fin.close();
  testGR.Print();
  */

  if(('W' == choice) || ('w' == choice))
  {
    gridSearch myGridSearchObjW(xMax, yMax, maxEC);

    myGridSearchObjW.ConstructGrid();
    //myGridSearchObjW.PrintProblemInstance();

    myGridSearchObjW.MOASearchL1Ordered();

    ofstream fout;
    fout.open(argv[6]);
    myGridSearchObjW.WriteToFile(fout);
    fout.close();
  }
  else if(('R' == choice) || ('r' == choice))
  {
    struct stat fileStat;
    int retVal = stat(argv[6], &fileStat);
    if(retVal == -1)
    {
      cerr << "Error in accessing file : " << strerror(errno) << endl;
      exit(EXIT_FAILURE);
    }
    
    gridSearch myGridSearchObjR;
    ifstream fin;
    fin.open(argv[6]);
    myGridSearchObjR.ReadFromFile(fin);
    fin.close();

    myGridSearchObjR.ComputeOptSFHV();
    myGridSearchObjR.SearchContract(stepSize);
  }
  else
  {
    cerr << "Invalid choice" << endl;
  }
  
  return 0;
}