Ejemplo n.º 1
0
void Mesh::setNodesConnectedByElements()
{
    const size_t nNodes (this->_nodes.size());
    for (unsigned i=0; i<nNodes; ++i)
    {
        MeshLib::Node* node (_nodes[i]);
        std::vector<MeshLib::Node*> conn_vec;
        const std::vector<MeshLib::Element*> &conn_elems (node->getElements());
        const size_t nConnElems (conn_elems.size());
        for (unsigned j=0; j<nConnElems; ++j)
        {
            const unsigned nElemNodes (conn_elems[j]->getNNodes());
            for (unsigned k(0); k<nElemNodes; ++k)
            {
                bool is_in_vector (false);
                const MeshLib::Node* c_node (conn_elems[j]->getNode(k));
                if (c_node == node) continue;
                const size_t nConnNodes (conn_vec.size());
                for (unsigned l(0); l<nConnNodes; ++l)
                    if (c_node == conn_vec[l])
                        is_in_vector = true;
                if (!is_in_vector)
                    conn_vec.push_back(_nodes[c_node->getID()]);
            }
        }
        node->setConnectedNodes(conn_vec);
    }
}
Ejemplo n.º 2
0
void Mesh::setNodesConnectedByEdges()
{
	const std::size_t nNodes (this->_nodes.size());
	for (unsigned i=0; i<nNodes; ++i)
	{
		MeshLib::Node* node (_nodes[i]);
		std::vector<MeshLib::Node*> conn_set;
		const std::vector<MeshLib::Element*> &conn_elems (node->getElements());
		const std::size_t nConnElems (conn_elems.size());
		for (unsigned j=0; j<nConnElems; ++j)
		{
			const unsigned idx (conn_elems[j]->getNodeIDinElement(node));
			const unsigned nElemNodes (conn_elems[j]->getNBaseNodes());
			for (unsigned k(0); k<nElemNodes; ++k)
			{
				bool is_in_vector (false);
				const std::size_t nConnNodes (conn_set.size());
				for (unsigned l(0); l<nConnNodes; ++l)
					if (conn_elems[j]->getNode(k) == conn_set[l])
						is_in_vector = true;
				if (is_in_vector) continue;
				if (conn_elems[j]->isEdge(idx, k)) //TODO doesn't work with higher order nodes
					conn_set.push_back(_nodes[conn_elems[j]->getNode(k)->getID()]);
			}
		}
		node->setConnectedNodes(conn_set);
	}
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Query mesh information.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::git_describe +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::git_describe);
    TCLAP::UnlabeledValueArg<std::string> mesh_arg("mesh-file","input mesh file",true,"","string");
    cmd.add( mesh_arg );
    TCLAP::MultiArg<std::size_t> eleId_arg("e","element-id","element ID",false,"number");
    cmd.add( eleId_arg );
    TCLAP::MultiArg<std::size_t> nodeId_arg("n","node-id","node ID",false,"number");
    cmd.add( nodeId_arg );
    TCLAP::SwitchArg showNodeWithMaxEle_arg("", "show-node-with-max-elements", "show a node having the max number of connected elements", false);
    cmd.add( showNodeWithMaxEle_arg );

    cmd.parse( argc, argv );

    const std::string filename(mesh_arg.getValue());

    // read the mesh file
    auto const mesh = std::unique_ptr<MeshLib::Mesh>(
        MeshLib::IO::readMeshFromFile(filename));
    if (!mesh)
    {
        return EXIT_FAILURE;
    }

    std::vector<std::size_t> selected_node_ids;
    if  (showNodeWithMaxEle_arg.getValue())
    {
        auto itr = std::max_element(mesh->getNodes().begin(), mesh->getNodes().end(),
                     [](MeshLib::Node* i, MeshLib::Node* j) { return i->getNumberOfElements() < j->getNumberOfElements(); });
        if (itr != mesh->getNodes().end())
        {
            MeshLib::Node* node = *itr;
            selected_node_ids.push_back(node->getID());
        }
    }
    selected_node_ids.insert(selected_node_ids.end(), nodeId_arg.getValue().begin(), nodeId_arg.getValue().end());

    auto const materialIds = materialIDs(*mesh);
    for (auto ele_id : eleId_arg.getValue())
    {
        std::stringstream out;
        out << std::scientific
            << std::setprecision(std::numeric_limits<double>::digits10);
        out << "--------------------------------------------------------" << std::endl;
        auto* ele = mesh->getElement(ele_id);
        out << "# Element " << ele->getID() << std::endl;
        out << "Type : " << CellType2String(ele->getCellType()) << std::endl;
        if (materialIds)
        {
            out << "Mat ID : " << (*materialIds)[ele_id] << std::endl;
        }
        out << "Nodes: " << std::endl;
        for (unsigned i = 0; i < ele->getNumberOfNodes(); i++)
        {
            out << ele->getNode(i)->getID() << " " << *ele->getNode(i)
                << std::endl;
        }
        out << "Content: " << ele->getContent() << std::endl;
        out << "Neighbors: ";
        for (unsigned i=0; i<ele->getNumberOfNeighbors(); i++)
        {
            if (ele->getNeighbor(i))
            {
                out << ele->getNeighbor(i)->getID() << " ";
            }
            else
            {
                out << "none ";
            }
        }
        out << std::endl;
        INFO("%s", out.str().c_str());
    }

    for (auto node_id : selected_node_ids)
    {
        std::stringstream out;
        out << std::scientific
            << std::setprecision(std::numeric_limits<double>::digits10);
        out << "--------------------------------------------------------" << std::endl;
        MeshLib::Node const* node = mesh->getNode(node_id);
        out << "# Node " << node->getID() << std::endl;
        out << "Coordinates: " << *node << std::endl;
        out << "Connected elements (" << node->getNumberOfElements() << "): ";
        for (auto ele : node->getElements())
        {
            out << ele->getID() << " ";
        }
        out << std::endl;
        out << "Connected nodes (" << node->getConnectedNodes().size() << "): ";
        for (auto nd : node->getConnectedNodes())
        {
            out << nd->getID() << " ";
        }
        out << std::endl;
        INFO("%s", out.str().c_str());
    }
}