예제 #1
0
    NumLibSpatialFunctionQuad() :
        _geometric_size(10.0), _number_of_subdivisions_per_direction(10),
        _msh(MeshLib::MeshGenerator::generateRegularQuadMesh(_geometric_size, _number_of_subdivisions_per_direction)),
        _project_name("test"), _mshNodesSearcher(*_msh), _ply0(nullptr)
    {
        // create geometry
        std::vector<GeoLib::Point*>* pnts (new std::vector<GeoLib::Point*>);
        pnts->push_back(new GeoLib::Point(0.0, 0.0, 0.0));
        pnts->push_back(new GeoLib::Point(_geometric_size, 0.0, 0.0));
        pnts->push_back(new GeoLib::Point(_geometric_size, _geometric_size, 0.0));
        pnts->push_back(new GeoLib::Point(0.0, _geometric_size, 0.0));

        std::vector<GeoLib::Polyline*>* plys (new std::vector<GeoLib::Polyline*>);
        _ply0 = new GeoLib::Polyline(*pnts);
        _ply0->addPoint(0);
        _ply0->addPoint(1);
        plys->push_back(_ply0);

        GeoLib::Polyline* ply1 = new GeoLib::Polyline(*pnts);
        ply1->addPoint(0);
        ply1->addPoint(1);
        ply1->addPoint(2);
        ply1->addPoint(3);
        ply1->addPoint(0);
        plys->push_back(ply1);

        std::vector<GeoLib::Surface*>* sfcs (new std::vector<GeoLib::Surface*>);
        _sfc1 = GeoLib::Surface::createSurface(*ply1);
        sfcs->push_back(_sfc1);

        _geo_objs.addPointVec(pnts,_project_name);
        _geo_objs.addPolylineVec(plys, _project_name);
        _geo_objs.addSurfaceVec(sfcs, _project_name);
    }
예제 #2
0
	NumLibDistributionHex() :
		_geometric_size(10.0), _number_of_subdivisions_per_direction(10),
		_msh(MeshLib::MeshGenerator::generateRegularHexMesh(_geometric_size, _number_of_subdivisions_per_direction)),
		_project_name("test"),
		_mshNodesSearcher(*_msh,MeshGeoToolsLib::SearchLength()),
		_ply0(nullptr)
	{
		// create geometry
		std::vector<GeoLib::Point*>* pnts (new std::vector<GeoLib::Point*>);
		pnts->push_back(new GeoLib::Point(0.0, 0.0, 0.0));
		pnts->push_back(new GeoLib::Point(_geometric_size, 0.0, 0.0));
		pnts->push_back(new GeoLib::Point(_geometric_size, _geometric_size, 0.0));
		pnts->push_back(new GeoLib::Point(0.0, _geometric_size, 0.0));
		pnts->push_back(new GeoLib::Point(0.0, 0.0, _geometric_size));
		pnts->push_back(new GeoLib::Point(_geometric_size, 0.0, _geometric_size));
		pnts->push_back(new GeoLib::Point(_geometric_size, _geometric_size, _geometric_size));
		pnts->push_back(new GeoLib::Point(0.0, _geometric_size, _geometric_size));

		std::vector<GeoLib::Polyline*>* plys (new std::vector<GeoLib::Polyline*>);
		_ply0 = new GeoLib::Polyline(*pnts); // vertical polyline
		_ply0->addPoint(0);
		_ply0->addPoint(4);
		plys->push_back(_ply0);
		GeoLib::Polyline* ply1 = new GeoLib::Polyline(*pnts); // polygon for left surface
		ply1->addPoint(0);
		ply1->addPoint(3);
		ply1->addPoint(7);
		ply1->addPoint(4);
		ply1->addPoint(0);
		plys->push_back(ply1);

		std::vector<GeoLib::Surface*>* sfcs (new std::vector<GeoLib::Surface*>);
		_sfc1 = GeoLib::Surface::createSurface(*ply1);
		sfcs->push_back(_sfc1);

		_geo_objs.addPointVec(pnts,_project_name);
		_geo_objs.addPolylineVec(plys, _project_name);
		_geo_objs.addSurfaceVec(sfcs, _project_name);
	}
예제 #3
0
파일: Gmsh2GeoIO.cpp 프로젝트: JobstM/ogs
void Gmsh2GeoIO::loadMeshAsGeometry (std::string & fname, GeoLib::GEOObjects* geo)
{
	// open file
	std::ifstream ins (fname.c_str());
	if (!ins)
	{
		std::cout << "could not open file " << fname << std::endl;
		return;
	}

	std::string line;
	// read gmsh header
	getline (ins, line); // $MeshFormat
	getline (ins, line);
	getline (ins, line); // $EndMeshFormat

	// read nodes tag
	getline (ins, line);
	// read number of nodes
	getline (ins, line);
	const size_t n_pnts (str2number<size_t>(line));
	std::vector<GeoLib::Point*>* pnts (new std::vector<GeoLib::Point*>);
	for (size_t k(0); k < n_pnts; k++)
	{
		getline (ins, line);
		// parse id
		size_t pos_beg(0);
		size_t pos_end (line.find(" "));
		// the sub string line.substr(pos_beg, pos_end-pos_beg) represents the id
		// parse x coordinate
		pos_beg = pos_end + 1;
		pos_end = line.find(" ", pos_beg);
		double x (str2number<double>(line.substr(pos_beg, pos_end - pos_beg)));
		// parse y coordinate
		pos_beg = pos_end + 1;
		pos_end = line.find(" ", pos_beg);
		double y (str2number<double>(line.substr(pos_beg, pos_end - pos_beg)));
		// parse z coordinate
		pos_beg = pos_end + 1;
		pos_end = line.find("\n", pos_beg);
		double z (str2number<double>(line.substr(pos_beg, pos_end - pos_beg)));

		pnts->push_back (new GeoLib::Point (x,y,z));
	}
	// read end nodes tag
	getline (ins, line);

	geo->addPointVec (pnts, fname);

	std::vector<size_t> const& pnt_id_map (geo->getPointVecObj(fname)->getIDMap());
	// read element tag
	getline (ins, line);
	// read number of elements
	getline (ins, line);
	const size_t n_elements (str2number<size_t>(line));
	GeoLib::Surface* sfc (new GeoLib::Surface (*pnts));
	for (size_t k(0); k < n_elements; k++)
	{
		getline (ins, line);
		// parse id
		size_t pos_beg(0);
		size_t pos_end (line.find(" "));
		// the sub string line.substr(pos_beg, pos_end-pos_beg) represents the id
		// parse element type
		pos_beg = pos_end + 1;
		pos_end = line.find(" ", pos_beg);
		size_t ele_type (str2number<size_t>(line.substr(pos_beg, pos_end - pos_beg)));
		if (ele_type == 2) // read 3 node triangle
		{ // parse number of tags
			pos_beg = pos_end + 1;
			pos_end = line.find(" ", pos_beg);
			const size_t n_tags (str2number<size_t>(line.substr(pos_beg,
			                                                    pos_end - pos_beg)));
			// (over) read tags
			for (size_t j(0); j < n_tags; j++)
			{
				pos_beg = pos_end + 1;
				pos_end = line.find(" ", pos_beg);
			}
			// parse first id of triangle
			pos_beg = pos_end + 1;
			pos_end = line.find(" ", pos_beg);
			const size_t id0 (str2number<size_t>(line.substr(pos_beg,
			                                                 pos_end - pos_beg)) - 1); // shift -1!
			// parse second id of triangle
			pos_beg = pos_end + 1;
			pos_end = line.find(" ", pos_beg);
			const size_t id1 (str2number<size_t>(line.substr(pos_beg,
			                                                 pos_end - pos_beg)) - 1); // shift -1!
			// parse third id of triangle
			pos_beg = pos_end + 1;
			pos_end = line.find(" ", pos_beg);
			const size_t id2 (str2number<size_t>(line.substr(pos_beg,
			                                                 pos_end - pos_beg)) - 1); // shift -1!
			sfc->addTriangle (pnt_id_map[id0], pnt_id_map[id1], pnt_id_map[id2]);
		}
	}
	// read end element tag
	getline (ins, line);

	std::vector<GeoLib::Surface*>* sfcs (new std::vector<GeoLib::Surface*>);
	sfcs->push_back(sfc);
	geo->addSurfaceVec (sfcs, fname);
}