Exemple #1
0
// test driver
main(int , char **)
{
	// start testing
	cout << "START OF LUP TEST CASES ..." << endl;

	// print out epsilon
	eps = calcEpsilon(double(0));
	cout.precision(6);
	cout.setf(ios::showpoint);
	cout << "EPSILON IS ... " << eps << endl;

	// run test cases
	runit(test1, data1);
	runit(test2, data2);
	runit(test3, data3);
	runit(test4, data4);
	runit(test5, data5);
	runit(test6, data6);
	runit(test7, data7);
	runit(test8, data8);
	runit(test9, data9);
	runit(test10, data10);
	runit(test11, data11);
	runit(test12, data12);
	runit(test13, data13);
	runit(test14, data14);
	runit(test15, data15);
	runit(test16, data16);
	runit(test17, data17);

	// all done
	cout << "END OF LUP TEST CASES ..." << endl << endl;
	return(0);
}
Exemple #2
0
bool LayeredVolume::createRasterLayers(const MeshLib::Mesh &mesh,
                                       const std::vector<GeoLib::Raster const*> &rasters,
                                       double minimum_thickness,
                                       double noDataReplacementValue)
{
	if (mesh.getDimension() != 2)
		return false;

	_elevation_epsilon = calcEpsilon(*rasters[0], *rasters.back());
	if (_elevation_epsilon <= 0)
		return false;

	// remove line elements, only tri + quad remain
	MeshLib::ElementSearch ex(mesh);
	ex.searchByElementType(MeshLib::MeshElemType::LINE);
	MeshLib::Mesh* top (removeElements(mesh, ex.getSearchedElementIDs(), "MeshLayer"));
	if (top==nullptr)
		top = new MeshLib::Mesh(mesh);

	if (!MeshLib::MeshLayerMapper::layerMapping(*top, *rasters.back(), noDataReplacementValue))
		return false;

	MeshLib::Mesh* bottom (new MeshLib::Mesh(*top));
	if (!MeshLib::MeshLayerMapper::layerMapping(*bottom, *rasters[0], 0))
	{
		delete top;
		return false;
	}

	this->_minimum_thickness = minimum_thickness;
	_nodes = MeshLib::copyNodeVector(bottom->getNodes());
	_elements = MeshLib::copyElementVector(bottom->getElements(), _nodes);
	delete bottom;

	// map each layer and attach to subsurface mesh
	const std::size_t nRasters (rasters.size());
	for (std::size_t i=1; i<nRasters; ++i)
		this->addLayerToMesh(*top, i, *rasters[i]);

	// close boundaries between layers
	this->addLayerBoundaries(*top, nRasters);
	this->removeCongruentElements(nRasters, top->getNElements());
	delete top;
	return true;
}
Exemple #3
0
int
solveLUP(Matrix<T> &m, Vector<T> &x, Vector<T> &y, Vector<int> &p, T ep)
{
	// must be a square matrix
	MustBeTrue(m.getRows() == m.getCols() && m.getRows() > 0);

	// check epsilon, set if invalid
	T minep = calcEpsilon(T(0));
	if ((ep = fabs(ep)) < minep)
		ep = minep;

	// get number of rows and columns
	int max = m.getRows();

	// update y-vector
	for (int k = 0; k < (max-1); k++)
	{
		for (int i = k+1; i < max; i++)
		{
			CheckForOverFlow(m(p[i], k), y[p[k]]);
			y[p[i]] -= m(p[i], k)*y[p[k]];
		}
	}

	// start backward substitution
	for (int i = max-1; i >= 0; i--)
	{
		// check for a singular matrix
		if (fabs(m(p[i], i)) <= ep)
			return(NOTOK);

		// solve for x by substituting previous solutions
		x[i] = y[p[i]];
		for (int j = i+1; j < max; j++)
		{
			CheckForOverFlow(m(p[i], j), x[j]);
			x[i] -= m(p[i], j)*x[j];
		}
		x[i] /= m(p[i], i);
	}

	// all done
	return(OK);
}
Exemple #4
0
int
gaussianLUP(Matrix<T> &m, Vector<int> &p, T ep, T &sign)
{
	// must be a square matrix
	MustBeTrue(m.getRows() == m.getCols() && m.getRows() > 0);
	sign = -1;

	// check epsilon, set if invalid
	T minep = calcEpsilon(T(0));
	if ((ep = fabs(ep)) < minep)
		ep = minep;

	// get number of rows and columns
	int max = m.getRows();

	// generate scaling information for each row. initialize 
	// permutation array, p.
	int i;
	Vector<T> s(max);
	for (i = 0; i < max; i++)
	{
		p[i] = i;
		if (1 < max)
			s[i] = fabs(m(i, 1));
		else
			s[i] = fabs(m(i, 0));
		for (int j = 2; j < max; j++)
		{
			T tmp = fabs(m(i, j));
			if (tmp > s[i])
				s[i] = tmp;
		}
	}

	// start gaussian elimination process
	for (int k = 0; k < (max-1); k++)
	{
		// find pivot row
		int pivot = k;
		T tmpf = fabs(m(p[pivot], k))/s[p[pivot]];
		for (i = k+1; i < max; i++)
		{
			T tmpf2 = fabs(m(p[i], k))/s[p[i]];
			if (tmpf2 > tmpf)
			{
				pivot = i;
				tmpf = tmpf2;
			}
		}
		if (pivot != k)
		{
			int tmpp = p[k];
			p[k] = p[pivot];
			p[pivot] = tmpp;
			sign = -sign;
		}

		// check for division by zero
		if (fabs(m(p[k], k)) <= ep)
			return(NOTOK);

		// calculate L and U matrices
		for (i = k+1; i < max; i++)
		{
			// multiplier for column
			T d = m(p[i], k)/m(p[k], k);

			// save multiplier since it is L.
			m(p[i], k) = d;

			// reduce original matrix to get U.
			for (int j = k+1; j < max; j++)
			{
				CheckForOverFlow(d, m(p[k], j));
				m(p[i], j) -= d*m(p[k], j);
			}
		}
	}

	// all done
	return(OK);
}