Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <array>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. class Mesh;
  8.  
  9. class Node
  10. {
  11. public:
  12.    Node()
  13.       : connections(25, 1), intetr(20, 1), freedom(20)
  14.    {}
  15.    ~Node() {}
  16.  
  17.    std::vector<Node> find_conns(const Mesh* mesh);
  18.    std::vector<const Node*> find_connps(const Mesh* mesh);
  19.    void set_freedom(const size_t& free) { freedom = free; }
  20.    const size_t& get_freedom() const { return freedom; }
  21. private:
  22.    std::array<double,3> location;
  23.    double* inmesh;
  24.    std::vector<size_t> connections;
  25.    std::vector<size_t> intetr;
  26.    size_t freedom;
  27. };
  28.  
  29. class Mesh
  30. {
  31. public:
  32.    Mesh()
  33.       : m_nodes(1000000)
  34.    {}
  35.    ~Mesh() {}
  36.    
  37.    const Node& get_node(const size_t &index) const { return m_nodes[index]; }
  38.    const Node* get_node_ptr(const size_t &index) const { return &m_nodes[index]; }
  39.  
  40.    void dostuff()
  41.    {
  42.       for (auto n : m_nodes)
  43.       {
  44.          std::vector<Node> conns = n.find_conns(this);
  45.          for (auto c : conns)
  46.          {
  47.             c.set_freedom(1);
  48.          }
  49.          
  50.       }
  51.    
  52.    }
  53.    void dostuffp()
  54.    {
  55.       for (auto n : m_nodes)
  56.       {
  57.          std::vector<const Node*> conns = n.find_connps(this);
  58.          for (auto c : conns)
  59.          {
  60.             c->get_freedom();
  61.          }
  62.          
  63.       }
  64.    
  65.    }
  66. private:
  67.    std::vector<Node> m_nodes;
  68. };
  69.  
  70.  
  71. std::vector<const Node*> Node::find_connps(const Mesh* mesh)
  72. {
  73.    std::vector<const Node*> nodes(connections.size());
  74.    std::transform(connections.begin(), connections.end(), nodes.begin(), [&] (size_t i) {return mesh->get_node_ptr(i);});
  75.    return nodes;
  76. }
  77.  
  78. std::vector<Node> Node::find_conns(const Mesh* mesh)
  79. {
  80.    std::vector<Node> nodes(connections.size());
  81.    std::transform(connections.begin(), connections.end(), nodes.begin(), [&] (size_t i) {return mesh->get_node(i);});
  82.    return nodes;
  83. }
  84.  
  85. int main(int argc, char *argv[])
  86. {
  87.    Mesh mesh;
  88.    cout << sizeof(Node) << " " << sizeof(Mesh) << " " << sizeof(Node*) << endl;
  89.    mesh.dostuffp();
  90.    return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement