示例#1
0
文件: MeshRead.cpp 项目: JobstM/ogs
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logogCout = new logog::Cout;

	TCLAP::CmdLine cmd("Simple mesh loading test", ' ', "0.1");

	// Define a value argument and add it to the command line.
	// A value arg defines a flag and a type of value that it expects,
	// such as "-m meshfile".
	TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"homer","string");

	// Add the argument mesh_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( mesh_arg );

	cmd.parse( argc, argv );

	std::string fname (mesh_arg.getValue());

	FileIO::MeshIO mesh_io;
#ifndef WIN32
	BaseLib::MemWatch mem_watch;
	unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif
	BaseLib::RunTime run_time;
	run_time.start();
	MeshLib::Mesh* mesh = mesh_io.loadMeshFromFile(fname);
#ifndef WIN32
	unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
//	std::cout << "mem for mesh: " << (mem_with_mesh - mem_without_mesh)/(1024*1024) << " MB" << std::endl;
	INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
#endif
	run_time.stop();
//	std::cout << "time for reading: " << run_time.elapsed() << " s" << std::endl;
	INFO ("time for reading: %f s", run_time.elapsed());


	unsigned elem_id = 25000;
	const MeshLib::Element* e = mesh->getElement(elem_id);
	const size_t nElems = mesh->getNElements();
	for (unsigned i=0; i< e->getNNeighbors(); i++)
	{
		for (unsigned j=0; j< nElems; j++)
			if (mesh->getElement(j) == e->getNeighbor(i))
				std::cout << "neighbour of element " << elem_id << elem_id << " : " << j << std::endl;
	}

	delete mesh;
	delete logogCout;
	LOGOG_SHUTDOWN();
}
示例#2
0
TEST(MeshLib, Duplicate)
{
	MeshLib::Mesh* mesh (MeshLib::MeshGenerator::generateRegularQuadMesh(10, 5, 1));

	std::vector<MeshLib::Node*> new_nodes (MeshLib::copyNodeVector(mesh->getNodes()));
	std::vector<MeshLib::Element*> new_elements (MeshLib::copyElementVector(mesh->getElements(), new_nodes));

	MeshLib::Mesh new_mesh ("new", new_nodes, new_elements);

	ASSERT_EQ (mesh->getNElements(), new_mesh.getNElements());
	ASSERT_EQ (mesh->getNNodes(), new_mesh.getNNodes());

	std::vector<std::size_t> del_idx(1,1);
	MeshLib::removeMeshNodes(*mesh, del_idx);

	ASSERT_EQ (mesh->getNElements(), new_mesh.getNElements()-2);
	ASSERT_EQ (mesh->getNNodes(), new_mesh.getNNodes()-2);

	ASSERT_DOUBLE_EQ (4.0, MathLib::sqrDist(*mesh->getNode(0), *new_mesh.getNode(0)));
	ASSERT_DOUBLE_EQ (0.0, MathLib::sqrDist(*mesh->getNode(0), *new_mesh.getNode(2)));

	ASSERT_DOUBLE_EQ (4.0, MathLib::sqrDist(*mesh->getElement(0)->getNode(0), *new_mesh.getElement(0)->getNode(0)));
	ASSERT_DOUBLE_EQ (0.0, MathLib::sqrDist(*mesh->getElement(0)->getNode(0), *new_mesh.getElement(2)->getNode(0)));
}