Skip to content

add first capacitor selection according to a Pareto plane#1

Merged
gituser789 merged 14 commits into
mainfrom
develop
Oct 21, 2025
Merged

add first capacitor selection according to a Pareto plane#1
gituser789 merged 14 commits into
mainfrom
develop

Conversation

@gituser789
Copy link
Copy Markdown
Contributor

Several features are implemented as a first scetch:

  • input DTO with capacitor requirements
  • small capacitor database (actually only a single series of a single manufacturer)
  • calculation of parallel / series connections required due to voltage / current / capacitane requirements
  • loss calculation based on ESR losses for film capacitors
  • show pareto plane

This is the first draft as a base line. Next step is to introduce more features (like electrolytic capacitors).

@gituser789 gituser789 self-assigned this Oct 20, 2025
Copy link
Copy Markdown

@SevenOfNinePE SevenOfNinePE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structural criticism:
The toolbox uses data classes, but it is not object-oriented.
That is, there are functions, but no methods. This may be easier at the beginning,
but ultimately, the structuring options offered by classes are missing.
With classes, the code would be much more maintainable and extensions would be easier to write.
Example:
If there were a class for film capacitors and one for electrolytic capacitors, both classes would be
derived from the general capacitor class. This would have the (virtual) method calc_power_loss,
which calculates the power loss. Virtual means: The method only declared (parameters), but it has no function body.
This means that both the film capacitor and electrolytic capacitor classes must implement this method.
The user has the advantage of only load the capacitor data into the class (which load it to a dataframe, like now implemented)
and then they can calculate the power loss. It doesn't matter whether it's a film capacitor or an electrolytic capacitor.
It simply calls 'MyCap.calc_power_loss(...)' and the correct method is automatically selected.
The electrolytic capacitor or film instance then has its specific data frame.
There are certainly many methods that are the same for both (defined in the general capacitor class).
Different things are defined in the respective derived classes (film or electrolytic capacitor class), although they are declared virtually in the capacitor class.

Comment thread cst/read_capacitor_database.py Outdated
c_df = c_df.drop(columns=["multiplier_1", "multiplier_2", "MOQ", "p1_in_mm"])

# transfer the datasheet given units to SI units
c_df['volume'] = c_df["width_in_mm"].astype(float) * 1e-3 * c_df["height_in_mm"].astype(float) * 1e-3 * c_df["length_in_mm"].astype(float) * 1e-3
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usual magic numbers are forbidden. 1e-3 could be a constant, eg. milli_factor.
This is valid for all previous or succeeding numbers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by adding a separate constant.py file

Comment thread cst/calculations.py Outdated
# own libraries
from cst.cst_dataclasses import SelectCapacitor, CalculatedRequirementsValues

def calculate_from_requirements(capacitor_requirements: SelectCapacitor) -> CalculatedRequirementsValues:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purpose of this function is not clear. In the example, the output is never used (eg. irms). Of course this value is maybe important, but it can be derivate from initial requirements.

Comment thread cst/read_capacitor_database.py Outdated

:param capacitor_type_list: list of capacitor types to load
:type capacitor_type_list: list[CapacitorType]
:return:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type (Should be indicated by tool?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread cst/selection.py

:param capacitor_requirements: capacitor requirements and input values in a DTO
:type capacitor_requirements: CapacitorRequirements
"""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type (Should be indicated by tool?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread cst/selection.py

:param ambient_temperature: ambient temperature in degree Celsius
:param df_derating: dataframe with temperature derating information
:return: derating factor
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Types of parameter inclusive return type (Should be indicated by tool?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread cst/selection.py
:param width: capacitor width in meter
:param length: capacitor length in meter
:param height: capacitor height in meter
:return: thermal equivalent coefficient
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Types of parameter inclusive return type (Should be indicated by tool?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread cst/selection.py
Filtering e.g. for the Pareto front must be done in a separate step by the user.

:param capacitor_requirements: capacitor requirements
:return: pandas data frame with all possible capacitors.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Types of parameter inclusive return type (Should be indicated by tool?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@gituser789 gituser789 merged commit 5f0a787 into main Oct 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants