예제 #1
0
	void createPolylines()
	{
		auto createPolyline = [](GeoLib::PointVec const& pnt_vec,
			std::vector<GeoLib::Polyline*> & lines, std::size_t line_id,
			std::vector<std::size_t> pnt_ids,
			std::map<std::string,std::size_t> & line_name_map,
			std::string const& name)
		{
			auto const & pnt_id_map(pnt_vec.getIDMap());
			lines[line_id] = new GeoLib::Polyline(*(pnt_vec.getVector()));
			for (std::size_t k(0); k<pnt_ids.size(); ++k) {
				lines[line_id]->addPoint(pnt_id_map[pnt_ids[k]]);
			}

			if (!name.empty())
				line_name_map.insert(std::make_pair(name, line_id));
		};

		auto const& pnt_vec = *(geo_objects.getPointVecObj(geo_name));

		auto lines = std::unique_ptr<std::vector<GeoLib::Polyline*>>(
			new std::vector<GeoLib::Polyline*>(5));
		std::map<std::string, std::size_t>* name_map =
			new std::map<std::string, std::size_t>;

		createPolyline(pnt_vec, *(lines.get()), 0, {0, 1, 2}, *name_map, "left");
		createPolyline(pnt_vec, *(lines.get()), 1, {3, 4, 5}, *name_map, "center");
		createPolyline(pnt_vec, *(lines.get()), 2, {0, 3}, *name_map, "line1");
		createPolyline(pnt_vec, *(lines.get()), 3, {3, 6}, *name_map, "line2");
		createPolyline(pnt_vec, *(lines.get()), 4, {6, 7, 8}, *name_map, "right");
		geo_objects.addPolylineVec(std::move(lines), geo_name, name_map);
	}
// geometry_sets contains the geometric points the boundary conditions will be
// set on, geo_name is the name the geometry can be accessed with, out_fname is
// the base file name the gli and bc as well as the gml file will be written to.
void writeBCsAndGeometry(GeoLib::GEOObjects& geometry_sets,
                         std::string& geo_name, std::string const& out_fname,
                         std::string const& bc_type, bool write_gml)
{
	if (write_gml) {
		INFO("write points to \"%s.gml\".", geo_name.c_str());
		FileIO::writeGeometryToFile(geo_name, geometry_sets, out_fname+".gml");
	}
	FileIO::writeGeometryToFile(geo_name, geometry_sets, out_fname+".gli");

	bool liquid_flow(false);
	if (bc_type == "LIQUID_FLOW")
		liquid_flow = true;


	GeoLib::PointVec const* pnt_vec_objs(geometry_sets.getPointVecObj(geo_name));
	std::vector<GeoLib::Point*> const& pnts(*(pnt_vec_objs->getVector()));
	std::ofstream bc_out (out_fname+".bc");
	for (std::size_t k(0); k<pnts.size(); k++) {
		std::string const& pnt_name(pnt_vec_objs->getItemNameByID(k));
		if (!pnt_name.empty()) {
			if (liquid_flow)
				writeLiquidFlowPointBC(bc_out, pnt_name);
			else
				writeGroundwaterFlowPointBC(bc_out, pnt_name, (*pnts[k])[2]);
		}
	}
	bc_out << "#STOP\n";
	bc_out.close();
}
예제 #3
0
bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects, double eps)
{
    if (mesh.getDimension() != 2)
    {
        ERR ("Mesh to geometry conversion is only working for 2D meshes.");
        return false;
    }

    // nodes to points conversion
    std::string mesh_name(mesh.getName());
    {
        auto points = std::make_unique<std::vector<GeoLib::Point*>>();
        points->reserve(mesh.getNumberOfNodes());

        for (auto node_ptr : mesh.getNodes())
            points->push_back(new GeoLib::Point(*node_ptr, node_ptr->getID()));

        geo_objects.addPointVec(std::move(points), mesh_name, nullptr, eps);
    }
    const std::vector<std::size_t> id_map (geo_objects.getPointVecObj(mesh_name)->getIDMap());

    // elements to surface triangles conversion
    std::string const mat_name ("MaterialIDs");
    auto bounds (MeshInformation::getValueBounds<int>(mesh, mat_name));
    const unsigned nMatGroups(bounds.second-bounds.first+1);
    auto sfcs = std::make_unique<std::vector<GeoLib::Surface*>>();
    sfcs->reserve(nMatGroups);
    auto const& points = *geo_objects.getPointVec(mesh_name);
    for (unsigned i=0; i<nMatGroups; ++i)
        sfcs->push_back(new GeoLib::Surface(points));

    const std::vector<MeshLib::Element*> &elements = mesh.getElements();
    const std::size_t nElems (mesh.getNumberOfElements());

    MeshLib::PropertyVector<int> const*const materialIds =
        mesh.getProperties().existsPropertyVector<int>("MaterialIDs")
            ? mesh.getProperties().getPropertyVector<int>("MaterialIDs")
            : nullptr;

    for (unsigned i=0; i<nElems; ++i)
    {
        auto surfaceId = !materialIds ? 0 : ((*materialIds)[i] - bounds.first);
        MeshLib::Element* e (elements[i]);
        if (e->getGeomType() == MeshElemType::TRIANGLE)
            (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]);
        if (e->getGeomType() == MeshElemType::QUAD)
        {
            (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]);
            (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(2)], id_map[e->getNodeIndex(3)]);
        }
        // all other element types are ignored (i.e. lines)
    }

    std::for_each(sfcs->begin(), sfcs->end(), [](GeoLib::Surface* sfc){ if (sfc->getNumberOfTriangles()==0) delete sfc; sfc = nullptr;});
    auto sfcs_end = std::remove(sfcs->begin(), sfcs->end(), nullptr);
    sfcs->erase(sfcs_end, sfcs->end());

    geo_objects.addSurfaceVec(std::move(sfcs), mesh_name);
    return true;
}
예제 #4
0
	void createSurfaces()
	{
		auto const points = geo_objects.getPointVec(geo_name);
		const std::vector<std::size_t> pnt_id_map(
			geo_objects.getPointVecObj(geo_name)->getIDMap());

		auto sfcs = std::unique_ptr<std::vector<GeoLib::Surface*>>(
			new std::vector<GeoLib::Surface*>(2));
		std::map<std::string, std::size_t>* sfc_names =
			new std::map<std::string, std::size_t>;
		(*sfcs)[0] = new GeoLib::Surface(*points);
		(*sfcs)[0]->addTriangle(pnt_id_map[0], pnt_id_map[3], pnt_id_map[1]);
		(*sfcs)[0]->addTriangle(pnt_id_map[1], pnt_id_map[3], pnt_id_map[4]);
		(*sfcs)[0]->addTriangle(pnt_id_map[1], pnt_id_map[4], pnt_id_map[2]);
		(*sfcs)[0]->addTriangle(pnt_id_map[2], pnt_id_map[4], pnt_id_map[5]);
		(*sfc_names)["FirstSurface"] = 0;
		(*sfcs)[1] = new GeoLib::Surface(*points);
		(*sfcs)[1]->addTriangle(pnt_id_map[3], pnt_id_map[6], pnt_id_map[8]);
		(*sfcs)[1]->addTriangle(pnt_id_map[3], pnt_id_map[8], pnt_id_map[5]);
		(*sfc_names)["SecondSurface"] = 1;
		geo_objects.addSurfaceVec(std::move(sfcs), geo_name, sfc_names);
	}
예제 #5
0
	void checkPointProperties()
	{
		auto const& pointvec(*geo_objects.getPointVecObj(geo_name));
		auto const& read_points(*pointvec.getVector());
		EXPECT_EQ(test_pnts.size(), read_points.size());
		for (std::size_t k(0); k<test_pnts.size(); ++k) {
			GeoLib::Point const& read_pnt = *read_points[k];
			// compare the coordinates
			EXPECT_EQ(test_pnts[k][0], read_pnt[0]);
			EXPECT_EQ(test_pnts[k][1], read_pnt[1]);
			EXPECT_EQ(test_pnts[k][2], read_pnt[2]);
			// compare the ids
			EXPECT_EQ(test_pnts[k].getID(), read_pnt.getID());
		}

		for (auto p : read_points) {
			// fetch name of read point
			std::string read_name;
			pointvec.getNameOfElementByID(p->getID(), read_name);
			// compare the id of the original point fetched by using the
			// read_name and the id of the read point
			EXPECT_EQ(p->getID(), pnt_name_id_map[read_name]);
		}
	}