Adding to_s (aka str(...)) methods to RNetExtractor tech objects

This commit is contained in:
Matthias Koefferlein 2025-05-25 16:31:20 +02:00
parent dec7ad9da1
commit ad80019b12
5 changed files with 132 additions and 0 deletions

View File

@ -81,6 +81,9 @@ static void via_set_merge_distance (pex::RExtractorTechVia *via, double dist)
}
Class<pex::RExtractorTechVia> decl_RExtractorTechVia ("pex", "RExtractorTechVia",
gsi::method ("to_s", &pex::RExtractorTechVia::to_string,
"@brief Returns a string describing this object"
) +
gsi::method_ext ("merge_distance", &via_get_merge_distance,
"@brief Gets the merge distance\n"
"If this value is not zero, it specifies the distance below (or equal) which "
@ -186,6 +189,9 @@ static void cond_set_triangulation_max_area (pex::RExtractorTechConductor *cond,
}
Class<pex::RExtractorTechConductor> decl_RExtractorTechConductor ("pex", "RExtractorTechConductor",
gsi::method ("to_s", &pex::RExtractorTechConductor::to_string,
"@brief Returns a string describing this object"
) +
gsi::method_ext ("algorithm", &cond_get_algorithm,
"@brief Gets the algorithm to use\n"
"Specifies the algorithm to use. The default algorithm is 'SquareCounting'."
@ -305,6 +311,9 @@ static void tech_add_conductor (pex::RExtractorTech *tech, const pex::RExtractor
}
Class<pex::RExtractorTech> decl_RExtractorTech ("pex", "RExtractorTech",
gsi::method ("to_s", &pex::RExtractorTech::to_string,
"@brief Returns a string describing this object"
) +
gsi::method_ext ("skip_simplify", &tech_get_skip_simplify,
"@brief Gets a value indicating whether to skip the simplify step\n"
"This values specifies to skip the simplify step of the network after the extraction has "

View File

@ -23,13 +23,75 @@
#include "pexRExtractorTech.h"
#include "tlString.h"
namespace pex
{
// ------------------------------------------------------------------
std::string
RExtractorTechVia::to_string () const
{
std::string res = "Via(";
res += tl::sprintf ("bottom=L%u, cut=L%u, top=L%u, R=%.12gµm²*Ohm", bottom_conductor, cut_layer, top_conductor, resistance);
if (merge_distance > 1e-10) {
res += tl::sprintf(", d_merge=%.12gµm", merge_distance);
}
res += ")";
return res;
}
// ------------------------------------------------------------------
std::string
RExtractorTechConductor::to_string () const
{
std::string res = "Conductor(";
res += tl::sprintf ("layer=L%u, R=%.12gOhm/sq", layer, resistance);
switch (algorithm) {
case SquareCounting:
res += ", algo=SquareCounting";
break;
case Tesselation:
res += ", algo=Tesselation";
break;
default:
break;
}
if (triangulation_min_b > 1e-10) {
res += tl::sprintf(", tri_min_b=%.12gµm", triangulation_min_b);
}
if (triangulation_max_area > 1e-10) {
res += tl::sprintf(", tri_max_area=%.12gµm", triangulation_max_area);
}
res += ")";
return res;
}
// ------------------------------------------------------------------
RExtractorTech::RExtractorTech ()
: skip_simplify (false)
{
// .. nothing yet ..
}
std::string
RExtractorTech::to_string () const
{
std::string res;
if (skip_simplify) {
res += "skip_simplify=true\n";
}
res += tl::join (vias.begin (), vias.end (), "\n");
res += "\n";
res += tl::join (conductors.begin (), conductors.end (), "\n");
return res;
}
}

View File

@ -26,6 +26,7 @@
#include "pexCommon.h"
#include <list>
#include <string>
namespace pex
{
@ -45,6 +46,11 @@ public:
// .. nothing yet ..
}
/**
* @brief Returns a string describing this object
*/
std::string to_string () const;
/**
* @brief Specifies the cut layer
* This is the layer the via sits on
@ -112,6 +118,11 @@ public:
// .. nothing yet ..
}
/**
* @brief Returns a string describing this object
*/
std::string to_string () const;
/**
* @brief Specifies the layer
* The value is the generic ID of the layer.
@ -155,6 +166,11 @@ public:
*/
RExtractorTech ();
/**
* @brief Returns a string describing this object
*/
std::string to_string () const;
/**
* @brief A list of via definitions
*/

View File

@ -64,6 +64,45 @@ static std::string network2s (const pex::RNetwork &network)
return tl::join (r, "\n");
}
TEST(basic)
{
unsigned int l1 = 1;
unsigned int l2 = 1;
unsigned int l3 = 1;
pex::RExtractorTech tech;
pex::RExtractorTechVia via1;
via1.bottom_conductor = l1;
via1.cut_layer = l2;
via1.top_conductor = l3;
via1.resistance = 2.0;
via1.merge_distance = 0.2;
tech.vias.push_back (via1);
pex::RExtractorTechConductor cond1;
cond1.layer = l1;
cond1.resistance = 0.5;
tech.conductors.push_back (cond1);
pex::RExtractorTechConductor cond2;
cond2.layer = l3;
cond2.resistance = 0.25;
cond2.algorithm = pex::RExtractorTechConductor::Tesselation;
cond2.triangulation_max_area = 1.5;
cond2.triangulation_min_b = 0.5;
tech.conductors.push_back (cond2);
tech.skip_simplify = true;
EXPECT_EQ (tech.to_string (),
"skip_simplify=true\n"
"Via(bottom=L1, cut=L1, top=L1, R=2µm²*Ohm, d_merge=0.2µm)\n"
"Conductor(layer=L1, R=0.5Ohm/sq, algo=SquareCounting)\n"
"Conductor(layer=L1, R=0.25Ohm/sq, algo=Tesselation, tri_min_b=0.5µm, tri_max_area=1.5µm)"
);
}
TEST(netex_viagen1)
{
db::Layout ly;

View File

@ -142,6 +142,7 @@ class PEX_TestClass < TestBase
via1.top_conductor = l3
via1.resistance = 2.0
via1.merge_distance = 0.2
assert_equal(via1.to_s, "Via(bottom=L1, cut=L2, top=L3, R=2µm²*Ohm, d_merge=0.2µm)")
assert_equal(via1.bottom_conductor, l1)
assert_equal(via1.cut_layer, l2)
@ -161,6 +162,7 @@ class PEX_TestClass < TestBase
cond1 = RBA::RExtractorTechConductor::new
cond1.layer = l1
cond1.resistance = 0.5
assert_equal(cond1.to_s, "Conductor(layer=L1, R=0.5Ohm/sq, algo=SquareCounting)")
assert_equal(cond1.layer, l1)
assert_equal(cond1.resistance, 0.5)
@ -171,6 +173,10 @@ class PEX_TestClass < TestBase
tech.add_conductor(cond2)
assert_equal(tech.each_conductor.collect { |c| c.layer }, [ l3 ])
assert_equal(tech.to_s,
"Via(bottom=L1, cut=L2, top=L3, R=2µm²*Ohm, d_merge=0.2µm)\n" +
"Conductor(layer=L3, R=0.25Ohm/sq, algo=SquareCounting)"
)
tech.clear_conductors
assert_equal(tech.each_conductor.collect { |c| c.layer }, [])