Meshtest.cpp 2.04 KB
Newer Older
1
2
#include "Mesh.h"
#include "Parameters.h"
3
4
5
#include "ProblemScal.h"

#include <sstream>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <string>
#include <stdexcept>

typedef std::vector< std::string > StringVector	 ;

template< typename Test >
void require(Test l, Test r, int line, std::string message) {
	if(l != r) {
		std::stringstream ss;
		ss<< "Condition for "<<message<<" is wrong\n";
		ss<< "l: "<<l<<"\n"<<"r: "<<r<<"\n";
		throw std::runtime_error(ss.str());
	}
}

template< typename Test >
void require(Test l, Test r, std::string message, StringVector& res) {
	if(l != r) {
		std::stringstream ss;
		ss<< "Condition for "<<message<<" is wrong\n";
		ss<< "l: "<<l<<"\n"<<"r: "<<r<<"\n";
		res.push_back(ss.str());
	}
}
30
31

using namespace AMDiS;
32
void testMesh(int dim, int nrEls, int nrVert , StringVector& res) {
33
34
35
36
37
38
39
40
41
	std::stringstream ss;
	ss<< dim;
	Parameters::addGlobalParameter(0, "dimension of world", ss.str());
	Global::init();
	Mesh mesh("testMesh", dim);
	DimVec< int > ln_dof(dim, DEFAULT_VALUE, 0);
	ln_dof[VERTEX]=1;
	mesh.createDOFAdmin("vertex_dofs", ln_dof);
	mesh.initialize();
42
43
44
45
46
	require(mesh.getDim(), dim, __LINE__, "mesh dimension");
	std::stringstream ss2;
	ss2<<"\ncurrent dimension: "<<dim<<"\n";
	require(mesh.getNumberOfElements() , nrEls, ss2.str() + "number of elements",res);
	require(mesh.getNumberOfVertices(), nrVert, ss2.str() + "number of vertices",res);
47
48
}

49
50
int main(int argc, char** argv) {
  //cannot use Parameters::addGlobalParameter(...) because of some string errors
51
52
53
  Parameters::addGlobalParameter(0,"testMesh1->macro file name","macro/macro.stand.1d");
  Parameters::addGlobalParameter(0,"testMesh2->macro file name","macro/macro.stand.2d");
  Parameters::addGlobalParameter(0,"testMesh3->macro file name","macro/macro.stand.3d");
54

55
56
57
58
	StringVector errorMessages;
  testMesh(1,1,2, errorMessages);
  testMesh(2,4,5, errorMessages);
  testMesh(3,6,8, errorMessages);
59

60
61
62
63
64
65
66
	if(errorMessages.size() > 0)
		std::cout<<" got errors: \n";
	for(StringVector::size_type i=0; i< errorMessages.size();++i) 
		std::cout<<errorMessages[i]<<"\n";
  if (errorMessages.size() != 0)
		return 1;
	return 0;
67
68
}