Real bindY(Real y) const {
     if(y < yMin())
         return yMin();
     if (y > yMax()) 
         return yMax();
     return y;
 }
    Evaluation eval(const Evaluation& x, const Evaluation& y) const
    {
        typedef MathToolbox<Evaluation> Toolbox;

#ifndef NDEBUG
        if (!applies(x,y))
        {
            OPM_THROW(NumericalProblem,
                       "Attempt to get tabulated value for ("
                       << x << ", " << y
                       << ") on a table of extend "
                       << xMin() << " to " << xMax() << " times "
                       << yMin() << " to " << yMax());
        };
#endif

        Evaluation alpha = xToI(x);
        Evaluation beta = yToJ(y);

        unsigned i = std::max(0U, std::min(static_cast<unsigned>(numX()) - 2,
                                           static_cast<unsigned>(Toolbox::value(alpha))));
        unsigned j = std::max(0U, std::min(static_cast<unsigned>(numY()) - 2,
                                           static_cast<unsigned>(Toolbox::value(beta))));

        alpha -= i;
        beta -= j;

        // bi-linear interpolation
        const Evaluation& s1 = getSamplePoint(i, j)*(1.0 - alpha) + getSamplePoint(i + 1, j)*alpha;
        const Evaluation& s2 = getSamplePoint(i, j + 1)*(1.0 - alpha) + getSamplePoint(i + 1, j + 1)*alpha;
        return s1*(1.0 - beta) + s2*beta;
    }
void BinnedMap::save(QTextStream& ts, const QString& indent) {
  QString l2 = indent + "  ";
  ts << indent << "<plugin name=\"Binned Map\">" << endl;
  ts << l2 << "<tag>" << QStyleSheet::escape(tagName()) << "</tag>" << endl;

  for (KstVectorMap::Iterator i = _inputVectors.begin(); i != _inputVectors.end(); ++i) {
    ts << l2 << "<ivector name=\"" << QStyleSheet::escape(i.key()) << "\">"
        << QStyleSheet::escape(i.data()->tagName())
        << "</ivector>" << endl;
  }

  for (KstMatrixMap::Iterator i = _outputMatrices.begin(); i != _outputMatrices.end(); ++i) {
    ts << l2 << "<omatrix name=\"" << QStyleSheet::escape(i.key());
    ts << "\">" << QStyleSheet::escape(i.data()->tagName())
        << "</omatrix>" << endl;
  }
  ts << 12 << "<minX>" << xMin() << "</minX>" << endl;
  ts << 12 << "<maxX>" << xMax() << "</maxX>" << endl;
  ts << 12 << "<minY>" << yMin() << "</minY>" << endl;
  ts << 12 << "<maxY>" << yMax() << "</maxY>" << endl;
  ts << 12 << "<nX>" << nX() << "</nX>" << endl;
  ts << 12 << "<nY>" << nY() << "</nY>" << endl;
  if (autoBin()) {
    ts << 12 << "<autoBin/>" << endl;
  }

  ts << indent << "</plugin>" << endl;
}
Esempio n. 4
0
bool		poly2::PointInPoly(const point2& p0) const
{
	//	Poly bounding box test
	if (p0[0] <= vxMin || p0[0] >= vxMax) return false;
	if (p0[1] <= vyMin || p0[1] >= vyMax) return false;

	//	else Ray-PolyEdge intresection tests
	ray2	rHor(p0,vector2(1,0));
	bool	inFlag = false;
	bool	vFlag = false;
	point2 vInt;
	for (int jj=0; jj<size(); jj++) {
//		cout << "\n" << jj << " " << (jj+1)%4 << " " << vPoly[jj] << " " << vPoly[(jj+1)%4] << " ";
		if (vFlag && (sqrdist(vInt,vPoly[jj]) < MAXPointTol || sqrdist(vInt,vPoly[(jj+1)%4]) < MAXPointTol )) {	//	cached vertex intersection point test
			vFlag = false;
			continue;	//	skip test for this edge
		}
		Double tParam = NaN_QUIET;
		int	result = rHor.intersect(lsEdge(jj),tParam);
//		cout << result << " " << tParam << " " ;
		if (result == 0) {
			continue;
		}
		if (result == -1) {	//	vertex intersection
			vFlag = true;
			vInt = p0 + tParam*rHor.dir();
// 			cout << vInt << " ";
			if (vInt[1] == yMax() || vInt[1] == yMin()) continue;	//	NECESSARY! - but only works for convex polygons!
		}
		inFlag = !inFlag;
// 		cout << inFlag << " ";
	}
// 		cout << "\n";
	return	inFlag;
}
Esempio n. 5
0
void QPScrollingCurve::appendDataPoints(const QVector<float> &data)
{
    if (data.isEmpty())
        return;

    float oldMin = yMin();
    float oldMax = yMax();

    for (float f : data) {
        if (m_data.full()) {
            m_orderedData.erase(m_orderedData.find(m_data.front()));
        }
        m_data.push_back(f);
        m_orderedData.insert(f);
    }

    if (yMin() != oldMin || yMax() != oldMax) {
        emit coordinateBoundsChanged(coordinateBounds());
    }

    update();
}
Esempio n. 6
0
point2		poly2::RandInPoly() const
{
	Double dx = xMax() - xMin();
	Double dy = yMax() - yMin();
	Double range = max(dx,dy);	//	VS2008

	// rejection sampling logic  
	point2 p0;	
	do {
		Double	x = xMin() + range*RandU();
		Double	y = yMin() + range*RandU();
		p0 = point2(x,y);	
	} while (!PointInPoly(p0));	
	return p0;
}
 bool applies(const Evaluation& x, const Evaluation& y) const
 {
     return
         xMin() <= x && x <= xMax() &&
         yMin() <= y && y <= yMax();
 }
 Evaluation yToJ(const Evaluation& y) const
 { return (y - yMin())/(yMax() - yMin())*(numY() - 1); }
    /*!
     * \brief Return the position on the y-axis of the j-th interval.
      */
    Scalar jToY(unsigned j) const
    {
        assert(0 <= j && j < numY());

        return yMin() + j*(yMax() - yMin())/(numY() - 1);
    }
Esempio n. 10
0
QRectF QPScrollingCurve::coordinateBounds() const
{
    QRectF bounds;
    bounds.setCoords(0, yMax(), numPoints(), yMin());
    return bounds;
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
#   include "setRootCase.H"
#   include "createTime.H"
#   include "createMesh.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


// Read in the existing solution files.   
Info << "Reading field U" << endl;
volVectorField U
(
    IOobject
    (
        "U",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);

Info << "Reading field T" << endl;
volScalarField T
(
    IOobject
    (
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);

Info << "Reading field p_rgh" << endl;
volScalarField p_rgh
(
    IOobject
    (
        "p_rgh",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);


// Compute the velocity flux at the faces.  This is needed
// by the laminar transport model.
Info<< "Creating/Calculating face flux field, phi..." << endl;
surfaceScalarField phi
(
    IOobject
    (
        "phi",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
    ),
    linearInterpolate(U) & mesh.Sf()
);


// Read the gravitational acceleration.  This is needed 
// for calculating dp/dn on boundaries.
Info << "Reading gravitational acceleration..." << endl;
uniformDimensionedVectorField g
(
    IOobject
    (
        "g",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    )
);


// Read the value of TRef in the transportProperties file.
singlePhaseTransportModel laminarTransport(U, phi);
dimensionedScalar TRef(laminarTransport.lookup("TRef"));


// Use Tref and the T field to compute rhok, which is needed
// to calculate dp/dn on boundaries.
Info<< "Creating the kinematic density field, rhok..." << endl;
volScalarField rhok
(
    IOobject
    (
        "rhok",
        runTime.timeName(),
        mesh
    ),
    1.0 - (T - TRef)/TRef
);


// Get access to the input dictionary.
IOdictionary setFieldsABLDict
(
    IOobject
    (
        "setFieldsABLDict",
        runTime.time().system(),
        runTime,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    )
);



// Read in the setFieldsABLDict entries.
word velocityInitType(setFieldsABLDict.lookup("velocityInitType"));
word temperatureInitType(setFieldsABLDict.lookup("temperatureInitType"));
word tableInterpTypeU(setFieldsABLDict.lookupOrDefault<word>("tableInterpTypeU","linear"));
word tableInterpTypeT(setFieldsABLDict.lookupOrDefault<word>("tableInterpTypeT","linear"));
scalar deltaU(setFieldsABLDict.lookupOrDefault<scalar>("deltaU",1.0));
scalar deltaV(setFieldsABLDict.lookupOrDefault<scalar>("deltaV",1.0));
scalar zPeak(setFieldsABLDict.lookupOrDefault<scalar>("zPeak",0.03));
scalar Uperiods(setFieldsABLDict.lookupOrDefault<scalar>("Uperiods",4));
scalar Vperiods(setFieldsABLDict.lookupOrDefault<scalar>("Vperiods",4));
scalar xMin(setFieldsABLDict.lookupOrDefault<scalar>("xMin",0.0));
scalar yMin(setFieldsABLDict.lookupOrDefault<scalar>("yMin",0.0));
scalar zMin(setFieldsABLDict.lookupOrDefault<scalar>("zMin",0.0));
scalar xMax(setFieldsABLDict.lookupOrDefault<scalar>("xMax",3000.0));
scalar yMax(setFieldsABLDict.lookupOrDefault<scalar>("yMax",3000.0));
scalar zMax(setFieldsABLDict.lookupOrDefault<scalar>("zMax",1000.0));
scalar zRef(setFieldsABLDict.lookupOrDefault<scalar>("zRef",600.0));
bool useWallDistZ(setFieldsABLDict.lookupOrDefault<bool>("useWallDistZ",false));
bool scaleVelocityWithHeight(setFieldsABLDict.lookupOrDefault<bool>("scaleVelocityWithHeight",false));
scalar zInversion(setFieldsABLDict.lookupOrDefault<scalar>("zInversion",600.0));
scalar Ug(setFieldsABLDict.lookupOrDefault<scalar>("Ug",15.0));
scalar UgDir(setFieldsABLDict.lookupOrDefault<scalar>("UgDir",270.0));
scalar Tbottom(setFieldsABLDict.lookupOrDefault<scalar>("Tbottom",300.0));
scalar Ttop(setFieldsABLDict.lookupOrDefault<scalar>("Ttop",304.0));
scalar dTdz(setFieldsABLDict.lookupOrDefault<scalar>("dTdz",0.003));
scalar widthInversion(setFieldsABLDict.lookupOrDefault<scalar>("widthInversion",80.0));
scalar TPrimeScale(setFieldsABLDict.lookupOrDefault<scalar>("TPrimeScale",0.0));
scalar z0(setFieldsABLDict.lookupOrDefault<scalar>("z0",0.016));
scalar kappa(setFieldsABLDict.lookupOrDefault<scalar>("kappa",0.40));
List<List<scalar> > profileTable(setFieldsABLDict.lookup("profileTable"));
bool updateInternalFields(setFieldsABLDict.lookupOrDefault<bool>("updateInternalFields",true));
bool updateBoundaryFields(setFieldsABLDict.lookupOrDefault<bool>("updateBoundaryFields",true));

// Change the table profiles from scalar lists to scalar fields
scalarField zProfile(profileTable.size(),0.0);
scalarField UProfile(profileTable.size(),0.0);
scalarField VProfile(profileTable.size(),0.0);
scalarField TProfile(profileTable.size(),0.0);
forAll(zProfile,i)
{
   zProfile[i] = profileTable[i][0];
   UProfile[i] = profileTable[i][1];
   VProfile[i] = profileTable[i][2];
   TProfile[i] = profileTable[i][3];
}
Esempio n. 12
0
float BinomialLaw::yMin() {
  return -k_displayBottomMarginRatio*yMax();
}
Esempio 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;
}