KiCad PCB EDA Suite
Loading...
Searching...
No Matches
RES_EQUIV_CALC Class Reference

Performs calculations on E-series values primarily to find target values as combinations (serial, parallel) of them. More...

#include <resistor_substitution_utils.h>

Public Types

enum  { S2R , S3R , S4R , NUMBER_OF_LEVELS }
 

Public Member Functions

 RES_EQUIV_CALC ()
 
void SetSeries (uint32_t aSeries)
 Set E-series to be used in calculations.
 
void NewCalc (double aTargetValue)
 Initialize next calculation, clear exclusion mask and erase results from previous calculation.
 
void Exclude (double aValue)
 If any value of the selected E-series not available, it can be entered as an exclude value.
 
void Calculate ()
 Executes all the calculations.
 
const std::array< std::optional< RESISTANCE >, NUMBER_OF_LEVELS > & GetResults ()
 Accessor to calculation results.
 

Private Member Functions

std::vector< RESISTANCEbuildSeriesData (const ESERIES::ESERIES_VALUES &aList)
 Add values from aList to m_e_series tables.
 
void prepare1RBuffer ()
 Build 1R buffer, which is selected E-series table with excluded values removed.
 
void prepare2RBuffer ()
 Build 2R buffer, which consists of all possible combinations of two resistors from 1R buffer (serial and parallel), sorted by value.
 
std::pair< RESISTANCE &, RESISTANCE & > findIn2RBuffer (double aTargetValue)
 Find in 2R buffer two values nearest to the given value (one smaller and one larger).
 
RESISTANCE calculate2RSolution ()
 Calculate the best combination consisting of exactly 2, 3 or 4 resistors.
 
RESISTANCE calculate3RSolution ()
 
RESISTANCE calculate4RSolution ()
 

Private Attributes

std::vector< std::vector< RESISTANCE > > m_e_series
 
std::vector< bool > m_exclude_mask
 
std::vector< RESISTANCEm_buffer_1R
 
std::vector< RESISTANCEm_buffer_2R
 
uint32_t m_series = ESERIES::E6
 
double m_target = 0
 
std::array< std::optional< RESISTANCE >, NUMBER_OF_LEVELSm_results
 

Detailed Description

Performs calculations on E-series values primarily to find target values as combinations (serial, parallel) of them.

RES_EQUIV_CALC class stores and performs calcuations on E-series values. It currently is targeted toward the resistor calculator and hard codes some limitations to optimize its use in the resistor calculator.

At this time these limitations are that this class handles only E-series up to E24 and it does not consider resistor values below 10 Ohm or above 1M Ohm.

Definition at line 54 of file resistor_substitution_utils.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
S2R 
S3R 
S4R 
NUMBER_OF_LEVELS 

Definition at line 69 of file resistor_substitution_utils.h.

Constructor & Destructor Documentation

◆ RES_EQUIV_CALC()

RES_EQUIV_CALC::RES_EQUIV_CALC ( )

Definition at line 219 of file resistor_substitution_utils.cpp.

References buildSeriesData(), and m_e_series.

Member Function Documentation

◆ buildSeriesData()

std::vector< RESISTANCE > RES_EQUIV_CALC::buildSeriesData ( const ESERIES::ESERIES_VALUES aList)
private

Add values from aList to m_e_series tables.

Covers all decades between FIRST_VALUE and LAST_VALUE.

Definition at line 282 of file resistor_substitution_utils.cpp.

References RES_EQUIV_CALC_FIRST_VALUE, RES_EQUIV_CALC_LAST_VALUE, and strValue().

Referenced by RES_EQUIV_CALC().

◆ Calculate()

void RES_EQUIV_CALC::Calculate ( )

Executes all the calculations.

Results are to be retrieved using GetResults (below).

Definition at line 256 of file resistor_substitution_utils.cpp.

References std::abs(), calculate2RSolution(), calculate3RSolution(), calculate4RSolution(), epsilon, m_results, m_target, prepare1RBuffer(), prepare2RBuffer(), S2R, S3R, S4R, PROF_TIMER::Show(), and RESISTANCE::value.

Referenced by PANEL_R_CALCULATOR::OnCalculateESeries().

◆ calculate2RSolution()

RESISTANCE RES_EQUIV_CALC::calculate2RSolution ( )
private

Calculate the best combination consisting of exactly 2, 3 or 4 resistors.

Definition at line 350 of file resistor_substitution_utils.cpp.

References SolutionCollector::Add2RLookupResults(), findIn2RBuffer(), SolutionCollector::GetBest(), and m_target.

Referenced by Calculate().

◆ calculate3RSolution()

◆ calculate4RSolution()

◆ Exclude()

void RES_EQUIV_CALC::Exclude ( double  aValue)

If any value of the selected E-series not available, it can be entered as an exclude value.

Parameters
aValueis the value (in Ohms) to exclude from calculation Values to exclude are set to true in the current exclusion mask and will not be considered during calculations.

Definition at line 244 of file resistor_substitution_utils.cpp.

References std::abs(), epsilon, m_e_series, m_exclude_mask, and m_series.

Referenced by PANEL_R_CALCULATOR::OnCalculateESeries().

◆ findIn2RBuffer()

std::pair< RESISTANCE &, RESISTANCE & > RES_EQUIV_CALC::findIn2RBuffer ( double  aTargetValue)
private

Find in 2R buffer two values nearest to the given value (one smaller and one larger).

It always returns two valid values, even for input out of range or Nan.

Definition at line 329 of file resistor_substitution_utils.cpp.

References m_buffer_2R.

Referenced by calculate2RSolution(), calculate3RSolution(), and calculate4RSolution().

◆ GetResults()

const std::array< std::optional< RESISTANCE >, NUMBER_OF_LEVELS > & RES_EQUIV_CALC::GetResults ( )
inline

Accessor to calculation results.

Empty std::optional means that the exact value can be achieved using fewer resistors.

Definition at line 112 of file resistor_substitution_utils.h.

References m_results.

Referenced by PANEL_R_CALCULATOR::OnCalculateESeries().

◆ NewCalc()

void RES_EQUIV_CALC::NewCalc ( double  aTargetValue)

Initialize next calculation, clear exclusion mask and erase results from previous calculation.

Parameters
aTargetValueis the value (in Ohms) to be looked for

Definition at line 234 of file resistor_substitution_utils.cpp.

References m_e_series, m_exclude_mask, m_results, m_series, and m_target.

Referenced by PANEL_R_CALCULATOR::OnCalculateESeries().

◆ prepare1RBuffer()

void RES_EQUIV_CALC::prepare1RBuffer ( )
private

Build 1R buffer, which is selected E-series table with excluded values removed.

Definition at line 301 of file resistor_substitution_utils.cpp.

References m_buffer_1R, m_e_series, m_exclude_mask, and m_series.

Referenced by Calculate().

◆ prepare2RBuffer()

void RES_EQUIV_CALC::prepare2RBuffer ( )
private

Build 2R buffer, which consists of all possible combinations of two resistors from 1R buffer (serial and parallel), sorted by value.

Definition at line 313 of file resistor_substitution_utils.cpp.

References m_buffer_1R, m_buffer_2R, parallelResistanceSimple(), and serialResistanceSimple().

Referenced by Calculate().

◆ SetSeries()

void RES_EQUIV_CALC::SetSeries ( uint32_t  aSeries)

Set E-series to be used in calculations.

Correct values are from 0 to 4 inclusive, representing series (consecutively) E1, E3, E6, E12, E24. After changing the series, NewCalc must be called before running calculations.

Definition at line 229 of file resistor_substitution_utils.cpp.

References m_series.

Referenced by PANEL_R_CALCULATOR::OnESeriesSelection().

Member Data Documentation

◆ m_buffer_1R

std::vector<RESISTANCE> RES_EQUIV_CALC::m_buffer_1R
private

◆ m_buffer_2R

std::vector<RESISTANCE> RES_EQUIV_CALC::m_buffer_2R
private

◆ m_e_series

std::vector<std::vector<RESISTANCE> > RES_EQUIV_CALC::m_e_series
private

Definition at line 149 of file resistor_substitution_utils.h.

Referenced by Exclude(), NewCalc(), prepare1RBuffer(), and RES_EQUIV_CALC().

◆ m_exclude_mask

std::vector<bool> RES_EQUIV_CALC::m_exclude_mask
private

Definition at line 150 of file resistor_substitution_utils.h.

Referenced by Exclude(), NewCalc(), and prepare1RBuffer().

◆ m_results

std::array<std::optional<RESISTANCE>, NUMBER_OF_LEVELS> RES_EQUIV_CALC::m_results
private

Definition at line 157 of file resistor_substitution_utils.h.

Referenced by Calculate(), GetResults(), and NewCalc().

◆ m_series

uint32_t RES_EQUIV_CALC::m_series = ESERIES::E6
private

Definition at line 154 of file resistor_substitution_utils.h.

Referenced by Exclude(), NewCalc(), prepare1RBuffer(), and SetSeries().

◆ m_target

double RES_EQUIV_CALC::m_target = 0
private

The documentation for this class was generated from the following files: