Created
December 6, 2022 20:08
-
-
Save sourceperl/226f050871d7f1bc40962e8756431c08 to your computer and use it in GitHub Desktop.
Fit a polynomial to reflect the Cv curve of a control valve (Cv/position).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Fit a polynomial to reflect the Cv curve of a control valve (Cv/position).""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# a list of reference points extracted from the data sheet of the valve | |
ref_pts_l = [(0, 0), (4, 5), (10, 15), (16, 21), (20, 25), (30, 40), (40, 75), | |
(50, 145), (53, 166), (60, 235), (70, 345), (80, 460), (90, 580), (100, 680)] | |
# fitting a seventh-order polynomial with this point | |
x_ref, y_ref = zip(*ref_pts_l) | |
poly_coef = np.polyfit(x_ref, y_ref, deg=7) | |
pos2cv_pol = np.poly1d(poly_coef) | |
# show result as plot | |
x = np.linspace(0, 100, 1000) | |
plt.scatter(x_ref, y_ref) | |
plt.plot(x, pos2cv_pol(x)) | |
plt.xlabel('Valve opening (%)') | |
plt.xlim(0, 100) | |
plt.ylabel('Flow Coefficient (Cv)') | |
plt.ylim(0, 800) | |
plt.grid() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment