extract_devices.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright 2010 Intel Corporation
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. //extract_devices.hpp
  8. #ifndef BOOST_POLYGON_TUTORIAL_EXTRACT_DEVICES_HPP
  9. #define BOOST_POLYGON_TUTORIAL_EXTRACT_DEVICES_HPP
  10. #include <string>
  11. #include <iostream>
  12. #include <fstream>
  13. #include <vector>
  14. #include "connectivity_database.hpp"
  15. #include "device.hpp"
  16. typedef boost::polygon::connectivity_extraction_90<int> connectivity_extraction;
  17. inline std::vector<std::set<int> >
  18. extract_layer(connectivity_extraction& ce, std::vector<std::string>& net_ids,
  19. connectivity_database& connectivity, polygon_set& layout,
  20. std::string layer) {
  21. for(connectivity_database::iterator itr = connectivity.begin(); itr != connectivity.end(); ++itr) {
  22. net_ids.push_back((*itr).first);
  23. ce.insert((*itr).second[layer]);
  24. }
  25. std::vector<polygon> polygons;
  26. layout.get_polygons(polygons);
  27. for(std::size_t i = 0; i < polygons.size(); ++i) {
  28. ce.insert(polygons[i]);
  29. }
  30. std::vector<std::set<int> > graph(polygons.size() + net_ids.size(), std::set<int>());
  31. ce.extract(graph);
  32. return graph;
  33. }
  34. inline void extract_device_type(std::vector<device>& devices, connectivity_database& connectivity,
  35. polygon_set& layout, std::string type) {
  36. //recall that P and NDIFF were merged into one DIFF layer in the connectivity database
  37. //find the two nets on the DIFF layer that interact with each transistor
  38. //and then find the net on the poly layer that interacts with each transistor
  39. boost::polygon::connectivity_extraction_90<int> cediff;
  40. std::vector<std::string> net_ids_diff;
  41. std::vector<std::set<int> > graph_diff =
  42. extract_layer(cediff, net_ids_diff, connectivity, layout, "DIFF");
  43. boost::polygon::connectivity_extraction_90<int> cepoly;
  44. std::vector<std::string> net_ids_poly;
  45. std::vector<std::set<int> > graph_poly =
  46. extract_layer(cepoly, net_ids_poly, connectivity, layout, "POLY");
  47. std::vector<device> tmp_devices(graph_diff.size() - net_ids_poly.size());
  48. for(std::size_t i = net_ids_poly.size(); i < graph_diff.size(); ++i) {
  49. tmp_devices[i - net_ids_diff.size()].type = type;
  50. tmp_devices[i - net_ids_diff.size()].terminals = std::vector<std::string>(3, std::string());
  51. std::size_t j = 0;
  52. for(std::set<int>::iterator itr = graph_diff[i].begin();
  53. itr != graph_diff[i].end(); ++itr, ++j) {
  54. if(j == 0) {
  55. tmp_devices[i - net_ids_diff.size()].terminals[0] = net_ids_diff[*itr];
  56. } else if(j == 1) {
  57. tmp_devices[i - net_ids_diff.size()].terminals[2] = net_ids_diff[*itr];
  58. } else {
  59. //error, too many diff connections
  60. tmp_devices[i - net_ids_diff.size()].terminals = std::vector<std::string>(3, std::string());
  61. }
  62. }
  63. j = 0;
  64. for(std::set<int>::iterator itr = graph_poly[i].begin();
  65. itr != graph_poly[i].end(); ++itr, ++j) {
  66. if(j == 0) {
  67. tmp_devices[i - net_ids_diff.size()].terminals[1] = net_ids_poly[*itr];
  68. } else {
  69. //error, too many poly connections
  70. tmp_devices[i - net_ids_poly.size()].terminals = std::vector<std::string>(3, std::string());
  71. }
  72. }
  73. }
  74. devices.insert(devices.end(), tmp_devices.begin(), tmp_devices.end());
  75. }
  76. //populates vector of devices based on connectivity and layout data
  77. inline void extract_devices(std::vector<device>& devices, connectivity_database& connectivity,
  78. layout_database& layout) {
  79. using namespace boost::polygon::operators;
  80. //p-type transistors are gate that interact with p diffusion and nwell
  81. polygon_set ptransistors = layout["GATE"];
  82. ptransistors.interact(layout["PDIFF"]);
  83. ptransistors.interact(layout["NWELL"]);
  84. //n-type transistors are gate that interact with n diffusion and not nwell
  85. polygon_set ntransistors = layout["GATE"];
  86. ntransistors.interact(layout["NDIFF"]);
  87. polygon_set not_ntransistors = ntransistors;
  88. not_ntransistors.interact(layout["NWELL"]);
  89. ntransistors -= not_ntransistors;
  90. extract_device_type(devices, connectivity, ptransistors, "PTRANS");
  91. extract_device_type(devices, connectivity, ntransistors, "NTRANS");
  92. }
  93. #endif