Examples
Example: a00_test
a00_test.py
Simple smoke-test style example. Demonstrates Medium instantiation and default properties.
1'''
2 a00_test.py
3
4 Simple smoke-test style example.
5 Demonstrates Medium instantiation and default properties.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluids
16import fluidsolve as fls
17# UNITS
18u = fls.unitRegistry
19Quantity = fls.Quantity # type: ignore[misc]
20
21# =============================================================================
22# MAIN
23# =============================================================================
24if __name__ == '__main__':
25 print('\nInstance:')
26 m0 = fls.Medium()
27 print(m0)
28 print(m0.rho)
29 print('\nDefault:')
30 m1 = fls.getDefaultMedium()
31 print(m1)
32 print(m1.rho)
Example: e00_fluids
e00_fluids.py
Basic example combining fluids, pint, and fluidsolve. Shows equivalent calculations with explicit engineering units.
1'''
2 e00_fluids.py
3
4 Basic example combining fluids, pint, and fluidsolve.
5 Shows equivalent calculations with explicit engineering units.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15# pylint: disable=no-member
16# Reason: fluids.units uses dynamic attributes that pylint can't detect
17import fluids.core as fc
18import fluids.friction as ff
19import fluids.units as fu # pylint: disable=no-name-in-module
20import fluidsolve as fls
21# UNITS
22u = fls.unitRegistry
23Quantity = fls.Quantity # type: ignore[misc]
24
25# =============================================================================
26# MAIN
27# =============================================================================
28if __name__ == '__main__':
29 # some values
30 Q = 30 *u.m**3/u.h
31 v = 1.5 *u.m/u.s
32 L = 100 *u.m
33 dia = 65 *u.mm # if no units defaults are presumed
34 dia2 = 25 # if no units defaults are presumed
35 #
36 med = fls.Medium(prd='water')
37 print(f'Water ({med.T:~P}): rho: {med.rho:~P} , mu: {med.mu:~P}')
38 med.T = 95.0 * u.degC
39 print(f'Water ({med.T:~P}): rho: {med.rho:~P} , mu: {med.mu:~P}')
40 med.T = 20.0 * u.degC
41 print(f'Water ({med.T:~P}): rho: {med.rho:~P} , mu: {med.mu:~P}')
42 print('\nBerekeningen kunnen met of zonder units gedaan worden.')
43 print('Dit bepaalt dan de gebruikte library:')
44 print(' import fluids.core as fc voor gebruik zonder units.')
45 print(' import fluids.units as fu voor gebruik met units.')
46 print('Hieronder 1 berekening zonder units:')
47 res = fc.Reynolds(D=0.065, V=1.5, rho=998.224, mu=0.001002058)
48 print(f'Re: {res:.2f}')
49 print('\nWij verkiezen om altijd met units te werken:')
50 res = fu.Reynolds(D=dia, V=v, rho=med.rho, mu=med.mu)
51 print(f'Re: {res:.2f~P}')
52 res = fu.Prandtl(rho=med.rho, mu=med.mu, Cp=4200*u.J/u.kg/u.degK, k=0.6*u.W/u.m/u.degK)
53 print(f'\nPrandtl: {res:.2f~P}')
54 print('\nAlles omzetten naar loss coeff (kunnen gemakkelijk samengeteld worden).')
55 res_K1 = fu.K_from_f(fd=0.018, L=L, D=dia).to_base_units()
56 print(f'K_from_f: {res_K1:.2f~P}')
57 res_K2 = fu.K_from_L_equiv(L_D=L/dia, fd=0.02).to_base_units() # L_D = length/dia
58 print(f'K_from_L_equiv: {res_K2:.2f~P}')
59 print('\nEens totale K gekend kan opvoerhoogte of drukval berekend worden.')
60 res = fu.head_from_K(K=res_K1+res_K2, V=v*2)
61 print(f'head_from_K: {res:.2f~P}')
62 res = fu.dP_from_K(K=res_K1+res_K2, rho=med.rho, V=v*2).to(u.bar)
63 print(f'dP_from_K: {res:.2f~P}')
64 print('\nEen gekende K kan ook omgezet worden naar L/D ratio of equival L.')
65 res = fu.L_from_K(K=6, fd=0.018, D=dia)
66 print(f'L_from_K: {res:.2f~P}')
67 res = fu.L_equiv_from_K(3.6, fd=0.02)
68 print(f'L_equiv_from_K (=L/dia): {res:.2f~P}')
69 print('\nOmrekeningen opvoerhoogte en drukval')
70 res = fls.ptoH(p=1.5*u.bar, rho=med.rho).to_base_units()
71 print(f'head_from_P: {res:.2f~P}')
72 res = fls.Htop(H=15.0*u.m, rho=med.rho).to(u.bar)
73 print(f'P_from_head: {res:.2f~P}')
74 print('\nConverteren tussen dynamische and kinematische viscositeit: nu_mu_converter')
75 res = fu.nu_mu_converter(rho=med.rho, nu=1.0E-6 * u.m**2/u.s)
76 print(f'nu {1.0E-6 * u.m**2/u.s:~P} -> mu: {res:~P}')
77 res = fu.nu_mu_converter(rho=med.rho, mu=med.mu)
78 print(f'mu {med.mu:~P} -> nu: {res:~P}')
79 print('\nZwaartekracht als functie van latitude en hoogte:')
80 res = fu.gravity(latitude=55 *u.deg, H=0 *u.m)
81 print(f'g= {res:.4f~P} voor lat: {55 *u.deg:~P} en H: {0 *u.m:~P}')
82 res = fu.gravity(latitude=55 *u.deg, H=1000 *u.km)
83 print(f'g= {res:.4f~P} voor lat: {55 *u.deg:~P} en H: {1000 *u.km:~P}')
84 print('\nWrijvingsfactor:')
85 epsilon = 1.5 *u.um # clean steel
86 res = ff.friction_factor(Re=15000, eD=epsilon/dia)
87 print(f'friction_factor: {res:.4f~P}')
88 print('\nOvergang laminaire naar turbulente stroming flow is ogenblikkelijk geimplementeerd op Re=2040,')
89 print(' d.i. 1 van de meest recente experemintele resultaten, nauwkeurig op +/- 10.')
90 print(' Als Re in laminair regime debruiken we de gekende formule fd = 64/Re.')
91 res = ff.friction_factor(Re=150)
92 print(f'friction_factor: {res:.4f}')
93 print('\nFriction factor in gebogen leidingen met friction_factor_curved.')
94 print('De curved friction factor is toepasbaar voor helixen en spoelen, en in mindere mate voor gebogen leidingen.')
95 res = ff.friction_factor_curved(Re=15000, Di=dia, Dc=2.5 *u.m, roughness=epsilon)
96 print(f'friction_factor_curved: {res:.4f~P}')
97 print('\nHet kritisch Reynolds getal voor gebogen leidingen is groter (en is functie van de buiging van de leiding')
98 print(' Voorkeur berekeningsmethode (default) is de methode van Schmidt (1967): helical_transition_Re_Schmidt.')
99 res = ff.helical_transition_Re_Schmidt(Di=dia, Dc=2.5 *u.m,)
100 print(f'helical_transition_Re_Schmidt: {res:.0f~P}')
101 print('\n')
Example: e01_basic
e01_basic.py
Basic comparison between fluids and fluidsolve pressure-drop calculations. Demonstrates both direct class construction and factory/builder usage.
1'''
2 e01_basic.py
3
4 Basic comparison between fluids and fluidsolve pressure-drop calculations.
5 Demonstrates both direct class construction and factory/builder usage.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11# pyright: reportAttributeAccessIssue=false
12
13# =============================================================================
14# EXTERNAL MODULE REFERENCES
15# =============================================================================
16from typing import Any
17import fluids.units as fu_module
18import fluidsolve as fls
19# UNITS
20fu: Any = fu_module
21u = fls.unitRegistry
22Quantity = fls.Quantity # type: ignore[misc]
23
24# =============================================================================
25# MAIN
26# =============================================================================
27if __name__ == '__main__':
28
29 mu = 0.001 * u.Pa*u.s
30 rho = 1000 * u.kg/u.m**3
31 e = 0.01 * u.mm
32 dia = 50 *u.mm
33 dia2 = 25 *u.mm
34 L = 15 * u.m
35
36 v = 3 *u.m/u.s
37 Q = fls.vtoQ(v, dia)
38 print(f'v = {v}, Q = {Q}')
39 print('----------\n')
40 Re = fu.Reynolds(V=v, D=dia, rho=rho, mu=mu)
41 fd = fu.friction_factor(Re, eD=e/dia)
42 K_native = [
43 fu.K_from_f(fd=fd, L=L, D=dia),
44 fu.entrance_sharp(),
45 fu.exit_normal(),
46 2*fu.bend_miter(angle=30*u.degrees),
47 fu.bend_rounded(Di=dia, angle=45*u.degrees, fd=fd),
48 fu.contraction_sharp(Di1=dia, Di2=dia2),
49 fu.diffuser_sharp(Di1=dia2, Di2=dia),
50 ]
51 P_native = [
52 fu.dP_from_K(K, rho=rho, V=v)
53 for K in K_native
54 ]
55 K_native_T = sum(K_native)
56 P_native_T = fu.dP_from_K(K_native_T, rho=rho, V=v)
57
58 fls.initFluidsolve(
59 default_medium = fls.Medium(name='test', mu=mu, rho=rho, k=fls.Medium(prd='water').k),
60 default_material = fls.Material(e=e),
61 )
62 path1 = fls.getPath(
63 name='path 1',
64 components=[
65 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
66 {'comp': fls.getComp(comp='Entrance', D=dia)},
67 {'comp': fls.getComp(comp='Entrance', D=dia), 'sense': -1},
68 {'comp': fls.getComp(comp='BendLong', D=dia, A=30, n=2)},
69 {'comp': fls.getComp(comp='Bend', D=dia, A=45, R=5)},
70 {'comp': fls.getComp(comp='SharpReduction', D1=dia, D2=dia2)},
71 {'comp': fls.getComp(comp='Reverse', reverse=fls.getComp(comp='SharpReduction', D1=dia, D2=dia2))},
72 ],
73 )
74 K_fls = []
75 P_fls = []
76 H_fls = []
77 for comp in path1.components:
78 K_fls.append(comp['comp'].calcK(Q, comp['sense']))
79 P_fls.append(comp['comp'].calcP(Q, comp['sense']))
80 H_fls.append(comp['comp'].calcH(Q, comp['sense']))
81 K_fls_T = sum(K_fls)
82 P_fls_T = sum(P_fls)
83 H_fls_T = sum(H_fls)
84
85 print(fls.getDefaultMedium(), '\n')
86 print(path1.toString(detail=1))
87 print('| | K native | K fls | P native | P fls | H fls |')
88 print('|-----|------------|------------|----------------|----------------|----------------|')
89 for i, k_native in enumerate(K_native):
90 print(f'| {i} | {k_native.magnitude:>10,.4f} | {K_fls[i].magnitude:>10,.4f} | {P_native[i].to(u.bar):>10,.6f} | {P_fls[i]:>10,.6f} | {H_fls[i]:>6,.2f} |')
91 print('|-----|------------|------------|----------------|----------------|----------------|')
92 print(f'| TOT | {K_native_T.magnitude:>10,.4f} | {K_fls_T.magnitude:>10,.4f} | {P_native_T.to(u.bar):>10,.6f} | {P_fls_T:>10,.6f} | {H_fls_T:>6,.2f} |')
93 print('|-----|------------|------------|----------------|----------------|----------------|')
94 print('p must be 0.379205 bar')
Example: e02_basic
1'''
2 e02_basic.py
3
4 Basic factory-based example for path and component creation.
5 Prints component-level and path-level hydraulic results.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# FUNCS
22# =============================================================================
23def PrintIt(comp, sense, flow_rate):
24 '''Print component hydraulic details for a given flow and direction.'''
25 print(f'{comp}')
26 try:
27 print(f'K={comp.calcK(flow_rate, sense).magnitude:.2f}')
28 except Exception:
29 print('K= not available')
30 print(f'with Q={flow_rate:.2f~P} sense: {sense} : H={comp.calcH(flow_rate, sense):.2f~P} P={comp.calcP(flow_rate, sense):.2f~P}')
31 print(f'with Q={flow_rate:.2f~P} sense: {-sense} : H={comp.calcH(flow_rate, -sense):.2f~P} P={comp.calcP(flow_rate, -sense):.2f~P}')
32 print('-------------\n')
33
34# =============================================================================
35# MAIN
36# =============================================================================
37if __name__ == '__main__':
38
39 mu = 0.001 * u.Pa*u.s
40 rho = 1000 * u.kg/u.m**3
41 dia = 50 *u.mm
42 dia2 = 25 *u.mm
43 L = 15 * u.m
44
45 medium = fls.Medium(name='test', mu=mu, rho=rho, k=fls.Medium(prd='water').k)
46 v = 3 *u.m/u.s
47 Q = fls.vtoQ(v, dia)
48 #
49 path1 = fls.getPath(
50 name='path 1',
51 components=[
52 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
53 {'comp': fls.getComp(comp='Entrance', D=dia)},
54 {'comp': fls.getComp(comp='Entrance', D=dia), 'sense': -1},
55 {'comp': fls.getComp(comp='BendLong', D=dia, A=30, n=2)},
56 {'comp': fls.getComp(comp='Bend', D=dia, A=45, R=5)},
57 {'comp': fls.getComp(comp='SharpReduction', D1=dia, D2=dia2)},
58 {'comp': fls.getComp(comp='Reverse', reverse=fls.getComp(comp='SharpReduction', D1=dia, D2=dia2))},
59 ],
60 )
61 print('Flow to speed and vice versa (component 0):')
62 print(f'v2Q met v={v:.2f~P}: {fls.vtoQ(v, path1.components[0]['comp'].D):.2f~P}')
63 print(f'Q2v met Q={Q:.2f~P}: {fls.Qtov(Q, path1.components[0]['comp'].D):.2f~P}')
64 print('-------------\n')
65 print('Detail of all components:')
66 for c in path1.components:
67 PrintIt(c['comp'], c['sense'], Q)
68 print('Path:')
69 PrintIt(path1, 1, Q)
70 print ('Calculate profile (Q en H after every component, individual and incremental):')
71 pts_indiv = path1.calcHprofile(Q, sense=1, incr=False)
72 pts_incr = path1.calcHprofile(Q, sense=1, incr=True)
73 for i, pt_indiv in enumerate(pts_indiv):
74 print(f'{pt_indiv} \t\t {pts_incr[i]}')
75 print('-------------\n')
Example: e03_serial
e03_serial.py
Demonstrates serial and parallel composition components. Includes generic Parallel and the dedicated Parallel2 variant.
- x_examples.e03_serial.PrintIt(comp, flow)[source]
Print component hydraulic details for a given flow.
1'''
2 e03_serial.py
3
4 Demonstrates serial and parallel composition components.
5 Includes generic Parallel and the dedicated Parallel2 variant.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# FUNCS
22# =============================================================================
23def PrintIt(comp, flow):
24 '''Print component hydraulic details for a given flow.'''
25 print(f'{comp}')
26 try:
27 print(f'K={comp.calcK(flow, 1).magnitude:.2f}')
28 except Exception:
29 print('K= not available')
30 print(f'with Q={flow:.2f~P}: H={comp.calcH(flow, 1):.2f~P} P={comp.calcP(flow, 1):.2f~P}')
31
32# =============================================================================
33# MAIN
34# =============================================================================
35if __name__ == '__main__':
36 mu = 0.001 * u.Pa*u.s
37 rho = 1000 * u.kg/u.m**3
38 e = 0.01 * u.mm
39 dia1 = 50 *u.mm
40 dia2 = 25 *u.mm
41 L1 = 15 * u.m
42 L2 = 50 * u.m
43
44 v = 3 *u.m/u.s
45 Q = fls.vtoQ(v, dia1)
46 #
47 fls.initFluidsolve(
48 default_medium = fls.Medium(name='test', mu=mu, rho=rho, k=fls.Medium(prd='water').k),
49 default_material = fls.Material(e=e),
50 )
51 c0 = fls.getComp(comp='Tube', L=L1, D=dia1)
52 c1 = fls.getComp(comp='Tube', L=L2, D=dia2)
53 c2 = fls.getComp(comp='Tube', L=L2, D=dia2)
54 comp_serial = fls.getComp(comp='Serial')
55 comp_serial.addComp(c0)
56 comp_serial.addComp(c1)
57 comp_parallel = fls.getComp(comp='Parallel')
58 comp_parallel.addComp(c0)
59 comp_parallel.addComp(c1)
60 comp_parallel.calcH(Q, 1)
61 comp_parallel2 = fls.getComp(comp='Parallel2')
62 comp_parallel2.addComp(c0)
63 comp_parallel2.addComp(c1)
64 #
65 print('-------------\n')
66 print('Detail of all components:')
67 PrintIt(c0, Q)
68 PrintIt(c1, Q)
69 print('-------------\n')
70 print('Total (serial) component:')
71 PrintIt(comp_serial, Q)
72 print ('Calculate profile (Q en H after every item, individual and incremental):')
73 pts_indiv = comp_serial.calcHprofile(Q, sense=1, incr=False)
74 pts_incr = comp_serial.calcHprofile(Q, sense=1, incr=True)
75 for i, pt_indiv in enumerate(pts_indiv):
76 print(f'{pt_indiv} \t\t {pts_incr[i]}')
77 print('-------------\n')
78 print('Total (parallel) component:')
79 PrintIt(comp_parallel, Q)
80 print ('Q en H for every item:')
81 for i in range(len(comp_parallel.components)):
82 print(f'Component {comp_parallel.getComp(i).name}: Q={comp_parallel.getQ()[i]:.2f~P} H={comp_parallel.getH()[i]:.2f~P}')
83 print('-------------\n')
84 print('Total (parallel2) component:')
85 PrintIt(comp_parallel2, Q)
86 print ('Q en H for every item:')
87 print(f'Component {comp_parallel2.getComp(0).name}: Q={comp_parallel2.getQ()[0]:.2f~P} H={comp_parallel2.getH()[0]:.2f~P}')
88 print(f'Component {comp_parallel2.getComp(1).name}: Q={comp_parallel2.getQ()[1]:.2f~P} H={comp_parallel2.getH()[1]:.2f~P}')
Example: e04_cat
e04_cat.py
Example for the catalogue subsystem. Shows library discovery and record filtering with query expressions.
1'''
2 e04_cat.py
3
4 Example for the catalogue subsystem.
5 Shows library discovery and record filtering with query expressions.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16
17# =============================================================================
18# MAIN
19# =============================================================================
20if __name__ == '__main__':
21 cat = fls.Catalogue()
22 cat.loadAllData()
23 print('\n')
24 print('Search Libraries')
25 print('============')
26 lib1 = cat.findLibraries()
27 print(lib1)
28 print('============')
29 lib2 = cat.findLibraries('APV')
30 print(lib2)
31 print('============')
32 lib3 = cat.findLibraries('appendage AND bend')
33 print(lib3)
34 print('============')
35 lib4 = cat.findLibraries('appendage AND (bend OR BS-90) OR (DIN11852 AND BS-90)')
36 print(lib4)
37 print('============')
38 lib5 = cat.findLibraries('appendage AND (bend AND BS-90)')
39 print(lib5)
40 print('============')
41 print('\n')
42 print('Search in Libraries')
43 print('============')
44 items1 = cat.searchInLibrary(lib5, 'OD < 20')
45 print(items1)
46 print('============')
47 items2 = cat.searchInLibrary(lib5, 'WT >= 2 AND DN < 80')
48 print(items2)
49 print('============')
50 items3 = cat.searchInLibrary(lib5, 'OD < 26 AND WT = 1.5')
51 print(items3)
Example: e05_medium
e05_medium.py
Medium example focused on property lookup and temperature effects. Demonstrates updates of rho and mu after changing temperature.
1'''
2 e05_medium.py
3
4 Medium example focused on property lookup and temperature effects.
5 Demonstrates updates of rho and mu after changing temperature.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# MAIN
22# =============================================================================
23if __name__ == '__main__':
24 #
25 m_wtr = fls.Medium(prd='water')
26 print(m_wtr.__dict__)
27 print(f'Water ({m_wtr.T:~P}): rho: {m_wtr.rho:~P} , mu: {m_wtr.mu:~P}')
28 m_wtr.T = 95.0 * u.degC
29 print(f'Water ({m_wtr.T:~P}): rho: {m_wtr.rho:~P} , mu: {m_wtr.mu:~P}')
30 #
31 print('============')
32 m_cust = fls.Medium(prd='water')
33 print(f'Water ({m_cust.T:~P}): rho: {m_cust.rho:~P} , mu: {m_cust.mu:~P}')
34 m_cust.T = 95.0 * u.degC
35 print(f'Water ({m_cust.T:~P}): rho: {m_cust.rho:~P} , mu: {m_cust.mu:~P}')
Example: e06_orifice
e06_orifice.py
Example for orifice-related calculations. Demonstrates solving with different unknown parameters.
1'''
2 e06_orifice.py
3
4 Example for orifice-related calculations.
5 Demonstrates solving with different unknown parameters.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# GLOBALS
22# =============================================================================
23# =============================================================================
24# MAIN
25# =============================================================================
26if __name__ == '__main__':
27 medium = fls.Medium(prd='water')
28 print(medium.cprd)
29 print('\nfls.calcOrifice(medium = medium, d=50, orifice=17.5, Pin=4, Pout=1)')
30 Q = fls.calcOrifice(medium=medium, d=50, orifice=17.5, Pin=4, Pout=1)
31 print(f'Q = {Q:.2f~P}')
32 print('\nfls.calcOrifice(medium=medium, d=50, Q=10, Pin=4, Pout=1)')
33 orifice = fls.calcOrifice(medium=medium, d=50, Q=10, Pin=4, Pout=1)
34 print(f'orifice = {Q:.2f~P}')
35 print('\nfls.calcOrifice(medium=medium, d=50, orifice=17.5, Q=10, Pout=1)')
36 Pin = fls.calcOrifice(medium=medium, d=50, orifice=17.5, Q=10, Pout=1)
37 print(f'Pin = {Pin:.2f~P}')
38 print('\nfls.calcOrifice(medium = medium, d=50, orifice=17.5, Q=10, Pin=4)')
39 Pout = fls.calcOrifice(medium=medium, d=50, orifice=17.5, Q=10, Pin=4)
40 print(f'Pout = {Pout:.2f~P}')
Example: e07_exitflow
e07_exitflow.py
Example for exit-flow calculations. Compares fluids reference functions with fluidsolve helpers.
1'''
2 e07_exitflow.py
3
4 Example for exit-flow calculations.
5 Compares fluids reference functions with fluidsolve helpers.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluids
16import fluidsolve as fls
17# UNITS
18u = fls.unitRegistry
19Quantity = fls.Quantity # type: ignore[misc]
20
21# =============================================================================
22# GLOBALS
23# =============================================================================
24# =============================================================================
25# MAIN
26# =============================================================================
27if __name__ == '__main__':
28 D = 25.4 * u.mm
29 H = 30 * u.m
30 c = fls.getComp(comp='Entrance', D=D)
31 Q = c.calcQ(H=H, sense=-1)
32 print(f'\nFlow D={D:.2f~P}, dH={H:.2f~P} : {Q:.2f~P}')
33 D = 25.4 * u.mm
34 H = 10 * u.m
35 c = fls.getComp(comp='Entrance', D=D)
36 Q = c.calcQ(H=H, sense=-1)
37 print(f'\nFlow D={D:.2f~P}, dH={H:.2f~P} : {Q:.2f~P}')
Example: e08_wp
e08_wp.py
Working-point example in the Q-H plane. Computes the operating point from a pump and a system path.
1'''
2 e08_wp.py
3
4 Working-point example in the Q-H plane.
5 Computes the operating point from a pump and a system path.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# MAIN
22# =============================================================================
23if __name__ == '__main__':
24 pump = fls.getComp(comp='PumpCentrifugal', dataQH=fls.getPumpCurveDataText('''
25 3.1843575418994416, 36.22969837587006
26 5.027932960893855, 36.43851508120649
27 9.944134078212288, 36.75174013921113
28 14.916201117318435, 36.542923433874705
29 19.94413407821229, 36.02088167053363
30 25.083798882681563, 34.87238979118329
31 29.88826815642458, 33.4106728538283
32 34.91620111731844, 31.531322505800457
33 40.055865921787706, 29.02552204176333
34 45.083798882681556, 25.684454756380504
35 48.826815642458094, 23.07424593967517
36 '''), impeller0=1, speed0=2900)
37 L = 315 * u.m
38 dia = 40
39 #
40 system = fls.getComp(comp='Tube', L=L, D=dia)
41 #
42 wpt = fls.WpointDyn(s1=pump, s2=system)
43 #
44 print (f'Pump H: {pump.dataH}')
45 print (f'Pump Q: {pump.dataQ}')
46 print (f'Operating point: {wpt}')
Example: e09_valve
e09_basic.py
- x_examples.e09_valve.PrintIt(pts1, pts2, title1, title2) None[source]
Print paired head-loss profiles side by side for comparison.
1'''
2 e09_basic.py
3
4'''
5# =============================================================================
6# PYLINT DIRECTIVES
7# =============================================================================
8# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
9
10# =============================================================================
11# EXTERNAL MODULE REFERENCES
12# =============================================================================
13import fluidsolve as fls
14# UNITS
15u = fls.unitRegistry
16Quantity = fls.Quantity # type: ignore[misc]
17
18# =============================================================================
19# FUNCS
20# =============================================================================
21def PrintIt(pts1, pts2, title1, title2) -> None:
22 '''Print paired head-loss profiles side by side for comparison.'''
23 comp_w = 16
24 h_w = 16
25 print(f'{"Comp":<{comp_w}}{title1:>{h_w}}{title2:>{h_w}}') # pylint: disable=inconsistent-quotes
26 print(f'{"-" * comp_w}{"-" * h_w}{"-" * h_w}') # pylint: disable=inconsistent-quotes
27 n_rows = max(len(pts1), len(pts2))
28 for i in range(n_rows):
29 p1 = pts1[i] if i < len(pts1) else None
30 p2 = pts2[i] if i < len(pts2) else None
31 comp = p1.name if p1 is not None else (p2.name if p2 is not None else '')
32 h1 = f'{p1.H.to(u.m).magnitude:.2f} m' if p1 is not None else ''
33 h2 = f'{p2.H.to(u.m).magnitude:.2f} m' if p2 is not None else ''
34 print(f'{comp:<{comp_w}}{h1:>{h_w}}{h2:>{h_w}}')
35 print(f'{"-" * comp_w}{"-" * h_w}{"-" * h_w}\n') # pylint: disable=inconsistent-quotes
36
37# =============================================================================
38# MAIN
39# =============================================================================
40if __name__ == '__main__':
41 dia = 80 *u.mm
42 L = 20 * u.m
43 Q = 40 * u.m**3/u.h
44 # NR valve
45 path1 = fls.getPath(
46 name='path 1',
47 components=[
48 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
49 {'comp': fls.getComp(comp='Valve_NR', D=dia, state=1)},
50 ],
51 )
52 path1_ptsA = path1.calcHprofile(Q)
53 path1.getComp(1)['sense'] = -1
54 path1_ptsB = path1.calcHprofile(Q)
55 print(f'Path with non-return valve (Q = {Q:.2f~P}):')
56 PrintIt(path1_ptsA, path1_ptsB, '--->', '<---')
57 # on off valve
58 path2 = fls.getPath(
59 name='path 2',
60 components=[
61 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
62 {'comp': fls.getComp(comp='Valve_01', D=dia, state=1)},
63 ],
64 )
65 path2_ptsA = path2.calcHprofile(Q)
66 path2.getComp(1)['comp'].state = 0
67 path2_ptsB = path2.calcHprofile(Q)
68 print(f'Path with on-off valve (Q = {Q:.2f~P}):')
69 PrintIt(path2_ptsA, path2_ptsB, 'V on', 'V off')
70 # CV valve
71 path3 = fls.getPath(
72 name='path 3',
73 components=[
74 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
75 {'comp': fls.getComp(comp='Valve_Kv', D=dia, Kvs=25, state=0.1)},
76 ],
77 )
78 path3_ptsA = path3.calcHprofile(Q)
79 path3.getComp(1)['comp'].state = 0.6
80 path3_ptsB = path3.calcHprofile(Q)
81 print(f'Path with Kv valve (Q = {Q:.2f~P}):')
82 PrintIt(path3_ptsA, path3_ptsB, 'out=0.1', 'out=0.6')
83 # 3W valve
84 path4 = fls.getPath(
85 name='path 4',
86 components=[
87 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
88 {'comp': fls.getComp(comp='Valve_3W', D=dia, state=1), 'pin':1, 'pout':2},
89 ],
90 )
91 path4_ptsA = path4.calcHprofile(Q)
92 path4.getComp(1)['comp'].state = 2
93 path4_ptsB = path4.calcHprofile(Q)
94 print(f'Path with 3W valve (port 1-2) (Q = {Q:.2f~P}):')
95 PrintIt(path4_ptsA, path4_ptsB, 'rust', 'actief')
96 # change to port 1-3
97 path4.getComp(1)['pout'] = 3
98 path4.getComp(1)['comp'].state = 1
99 path4_ptsC = path4.calcHprofile(Q)
100 path4.getComp(1)['comp'].state = 2
101 path4_ptsD = path4.calcHprofile(Q)
102 print(f'Path with 3W valve (port 1-3) (Q = {Q:.2f~P}):')
103 PrintIt(path4_ptsC, path4_ptsD, 'rust', 'actief')
104 # change to port 2-3
105 path4.getComp(1)['pin'] = 2
106 path4.getComp(1)['comp'].state = 1
107 path4_ptsE = path4.calcHprofile(Q)
108 path4.getComp(1)['comp'].state = 2
109 path4_ptsF = path4.calcHprofile(Q)
110 print(f'Path with 3W valve (port 2-3) (Q = {Q:.2f~P}):')
111 PrintIt(path4_ptsE, path4_ptsF, 'rust', 'actief')
112 # DS valve
113 path5 = fls.getPath(
114 name='path 5',
115 components=[
116 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
117 {'comp': fls.getComp(comp='Valve_DS', D=dia, state=1), 'pin':1, 'pout':3},
118 ],
119 )
120 path5_ptsA = path5.calcHprofile(Q)
121 path5.getComp(1)['comp'].state = 2
122 path5_ptsB = path5.calcHprofile(Q)
123 print(f'Path with double seat valve (Q = {Q:.2f~P}):')
124 PrintIt(path5_ptsA, path5_ptsB, 'State 1', 'State 2')
Example: e10_plot
e10_plot.py
Static Q-H plotting example. Displays one pump curve together with one system curve.
1'''
2 e10_plot.py
3
4 Static Q-H plotting example.
5 Displays one pump curve together with one system curve.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# GLOBALS
22# =============================================================================
23pump = None
24system = None
25plt = None
26
27# =============================================================================
28# FUNCS
29# =============================================================================
30def fun1(value):
31 '''Update system pipe length from slider input.'''
32 system.getItem(0).L = value
33 plt.update()
34
35def fun2(value):
36 '''Update pump speed from slider input.'''
37 pump.speed = value
38 plt.update()
39
40# =============================================================================
41# MAIN
42# =============================================================================
43if __name__ == '__main__':
44 pump = fls.getComp(comp='PumpCentrifugal', dataQH=fls.getPumpCurveDataText('''
45 3.1843575418994416, 36.22969837587006
46 5.027932960893855, 36.43851508120649
47 9.944134078212288, 36.75174013921113
48 14.916201117318435, 36.542923433874705
49 19.94413407821229, 36.02088167053363
50 25.083798882681563, 34.87238979118329
51 29.88826815642458, 33.4106728538283
52 34.91620111731844, 31.531322505800457
53 40.055865921787706, 29.02552204176333
54 45.083798882681556, 25.684454756380504
55 48.826815642458094, 23.07424593967517
56 '''), impeller0=1, speed0=2900)
57 Q = 38.73 * u.m**3/u.h
58 L = 315 * u.m
59 dia = 70
60 dia2 = 40
61 #
62 system = fls.getPath(
63 name='path 1',
64 components=[
65 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
66 {'comp': fls.getComp(comp='Entrance', D=dia)},
67 {'comp': fls.getComp(comp='Entrance', D=dia), 'sense': -1},
68 {'comp': fls.getComp(comp='BendLong', D=dia, A=30, n=2)},
69 {'comp': fls.getComp(comp='Bend', D=dia, A=45, R=5)},
70 {'comp': fls.getComp(comp='SharpReduction', D1=dia, D2=dia2)},
71 {'comp': fls.getComp(comp='Reverse', reverse=fls.getComp(comp='SharpReduction', D1=dia, D2=dia2))},
72 ],
73 )
74 #
75 wpt = fls.WpointDyn(s1=pump, s2=system)
76 #
77 print (f'Pump: {pump}')
78 print (f'Operating point: {wpt}')
79 for i in system.calcHprofile(Q):
80 print (i)
81 #
82 plt = fls.PlotQHcurve(
83 pumps=[pump],
84 circuits=[system],
85 wpoints=[wpt],
86 title=f'Pumpcurve; Operating point: Q={wpt.Q:.1f~P}, H={wpt.H:.1f~P}',
87 )
88 plt.show()
Example: e11_plot
e11_plot.py
Interactive Q-H plotting example with one pump and one system. Sliders modify pipe geometry and pump speed in real time.
1'''
2 e11_plot.py
3
4 Interactive Q-H plotting example with one pump and one system.
5 Sliders modify pipe geometry and pump speed in real time.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# GLOBALS
22# =============================================================================
23system = None
24pump = None
25plt = None
26
27# =============================================================================
28# FUNCTIONS
29# =============================================================================
30def fun1(value):
31 '''Update system pipe length from slider input.'''
32 system.getComp(0)['comp'].L = value
33 plt.updateData()
34
35def fun2(value):
36 '''Update system pipe diameter from slider input.'''
37 system.getComp(0)['comp'].D = value
38 plt.updateData()
39
40def fun3(value):
41 '''Update pump speed from slider input.'''
42 pump.speed = value
43 plt.updateData()
44
45# =============================================================================
46# MAIN
47# =============================================================================
48if __name__ == '__main__':
49 fls.initFluidsolve(prefix_wpt='p')
50 pump = fls.getComp(comp='PumpCentrifugal', dataQH=fls.getPumpCurveDataText('''
51 3.1843575418994416, 36.22969837587006
52 5.027932960893855, 36.43851508120649
53 9.944134078212288, 36.75174013921113
54 14.916201117318435, 36.542923433874705
55 19.94413407821229, 36.02088167053363
56 25.083798882681563, 34.87238979118329
57 29.88826815642458, 33.4106728538283
58 34.91620111731844, 31.531322505800457
59 40.055865921787706, 29.02552204176333
60 45.083798882681556, 25.684454756380504
61 48.826815642458094, 23.07424593967517
62 '''), impeller0=1, speed0=2900)
63 L = 315 * u.m
64 dia = 70
65 dia2 = 40
66 #
67 system = fls.getPath(
68 name='path 1',
69 components=[
70 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
71 {'comp': fls.getComp(comp='Entrance', D=dia)},
72 {'comp': fls.getComp(comp='Entrance', D=dia), 'sense': -1},
73 {'comp': fls.getComp(comp='BendLong', D=dia, A=30, n=2)},
74 {'comp': fls.getComp(comp='Bend', D=dia, A=45, R=5)},
75 {'comp': fls.getComp(comp='SharpReduction', D1=dia, D2=dia2)},
76 {'comp': fls.getComp(comp='Reverse', reverse=fls.getComp(comp='SharpReduction', D1=dia, D2=dia2))},
77 ],
78 )
79 #
80 Q, H = fls.calcOperatingPoint(pump, system)
81 swpt = fls.getWpt(wpt='s', Q=Q, H=H)
82 dwpt = fls.getWpt(wpt='d', s1=pump, s2=system)
83 spts = [
84 fls.Wpoint(name='p1', Q=20, H=2.2),
85 fls.Wpoint(name='p2', Q=20, H=6.4),
86 fls.Wpoint(name='p3', Q=20, H=15.1),
87 ]
88 #
89 print (f'Pump: {pump}')
90 print (f'Operating point (static): {swpt}')
91 print (f'Operating point (dynamic): {dwpt}')
92 #
93 plt = fls.PlotQHcurve(
94 pumps=[pump],
95 circuits=[system],
96 spoints=spts,
97 wpoints=[dwpt],
98 title='Pumpcurve: 1 pump',
99 sliders=[
100 dict(label='L (m)', vmin=100, vmax=800, vinit=system.getComp(0)['comp'].L.magnitude, fun=fun1),
101 dict(label='D (mm)', vmin=40, vmax=100, vinit=system.getComp(0)['comp'].D.magnitude, fun=fun2),
102 dict(label='speed (rpm)', vmin=1450, vmax=2900, vinit=2900, fun=fun3)
103 ]
104 )
105 print(system.getComp(0)['comp'].L)
106 print(system.getComp(0)['comp'].D)
107 plt.show()
Example: e12_plot
e12_plot.py
Interactive Q-H plotting example with two independent pumps. Sliders modify system geometry and each pump speed separately.
1'''
2 e12_plot.py
3
4 Interactive Q-H plotting example with two independent pumps.
5 Sliders modify system geometry and each pump speed separately.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# GLOBALS
22# =============================================================================
23system = None
24plt = None
25pump1 = None
26pump2 = None
27
28# =============================================================================
29# FUNCS
30# =============================================================================
31def fun1(value):
32 '''Update system pipe length from slider input.'''
33 system.getComp(0)['comp'].L = value
34 plt.updateData()
35
36def fun2(value):
37 '''Update system pipe diameter from slider input.'''
38 system.getComp(0)['comp'].D = value
39 plt.updateData()
40
41def fun3(value):
42 '''Update first pump speed from slider input.'''
43 pump1.speed = value
44 plt.updateData()
45
46def fun4(value):
47 '''Update second pump speed from slider input.'''
48 pump2.speed = value
49 plt.updateData()
50
51# =============================================================================
52# MAIN
53# =============================================================================
54if __name__ == '__main__':
55 dataQH=fls.getPumpCurveDataText('''
56 3.1843575418994416, 36.22969837587006
57 5.027932960893855, 36.43851508120649
58 9.944134078212288, 36.75174013921113
59 14.916201117318435, 36.542923433874705
60 19.94413407821229, 36.02088167053363
61 25.083798882681563, 34.87238979118329
62 29.88826815642458, 33.4106728538283
63 34.91620111731844, 31.531322505800457
64 40.055865921787706, 29.02552204176333
65 45.083798882681556, 25.684454756380504
66 48.826815642458094, 23.07424593967517
67 ''')
68 fls.initFluidsolve(prefix_wpt='p')
69 pump1 = fls.getComp(comp='PumpCentrifugal', dataQH=dataQH, impeller0=1, speed0=2900)
70 pump2 = fls.getComp(comp='PumpCentrifugal', dataQH=dataQH, impeller0=1, speed0=2900, speed=1450)
71 L = 315 * u.m
72 dia = 80
73 dia2 = 40
74 #
75 system = fls.getPath(
76 name='path 1',
77 components=[
78 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
79 {'comp': fls.getComp(comp='Entrance', D=dia)},
80 {'comp': fls.getComp(comp='Entrance', D=dia), 'sense': -1},
81 {'comp': fls.getComp(comp='BendLong', D=dia, A=30, n=2)},
82 {'comp': fls.getComp(comp='Bend', D=dia, A=45, R=5)},
83 {'comp': fls.getComp(comp='SharpReduction', D1=dia, D2=dia2)},
84 {'comp': fls.getComp(comp='Reverse', reverse=fls.getComp(comp='SharpReduction', D1=dia, D2=dia2))},
85 ],
86 )
87 #
88 wpt1 = fls.getWpt(wpt='d', s1=pump1, s2= system)
89 wpt2 = fls.getWpt(wpt='d', s1=pump2, s2= system)
90 #
91 print (f'Pump1: {pump1}')
92 print (f'Pump2: {pump2}')
93 print (f'Operating point: {wpt1}')
94 print (f'Operating point: {wpt2}')
95 #
96 plt = fls.PlotQHcurve(
97 pumps=[pump1, pump2],
98 circuits=[system],
99 wpoints=[wpt1, wpt2],
100 title='Pumpcurve: 2 independent pumps',
101 sliders=[
102 dict(label='L (m)', vmin=100, vmax=800, vinit=system.getComp(0)['comp'].L.magnitude, fun=fun1),
103 dict(label='D (mm)', vmin=40, vmax=100, vinit=system.getComp(0)['comp'].D.magnitude, fun=fun2),
104 dict(label='P1 speed (rpm)', vmin=1450, vmax=2900, vinit=2900, fun=fun3),
105 dict(label='P2 speed (rpm)', vmin=1450, vmax=2900, vinit=1450, fun=fun4),
106 ]
107 )
108 print(system.getComp(0)['comp'].L)
109 print(system.getComp(0)['comp'].D)
110 plt.show()
Example: e13_plot_valve
e13_plot_valve.py
Static Q-H plotting example. Displays one pump curve together with one system curve.
1'''
2 e13_plot_valve.py
3
4 Static Q-H plotting example.
5 Displays one pump curve together with one system curve.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# GLOBALS
22# =============================================================================
23system = None
24plt = None
25pump = None
26
27# =============================================================================
28# FUNCS
29# =============================================================================
30def fun1(value):
31 '''Update system pipe length from slider input.'''
32 system.getComp(0)['comp'].L = value
33 plt.updateData()
34
35def fun2(value):
36 '''Update pump speed from slider input.'''
37 pump.speed = value
38 plt.updateData()
39
40def fun3(value):
41 '''Update valve state.'''
42 system.getComp(1)['comp'].state = value
43 plt.updateData()
44
45# =============================================================================
46# MAIN
47# =============================================================================
48if __name__ == '__main__':
49 pump = fls.getComp(comp='PumpCentrifugal', dataQH=fls.getPumpCurveDataText('''
50 3.1843575418994416, 36.22969837587006
51 5.027932960893855, 36.43851508120649
52 9.944134078212288, 36.75174013921113
53 14.916201117318435, 36.542923433874705
54 19.94413407821229, 36.02088167053363
55 25.083798882681563, 34.87238979118329
56 29.88826815642458, 33.4106728538283
57 34.91620111731844, 31.531322505800457
58 40.055865921787706, 29.02552204176333
59 45.083798882681556, 25.684454756380504
60 48.826815642458094, 23.07424593967517
61 '''), impeller0=1, speed0=2900)
62 Q = 38.73 * u.m**3/u.h
63 L = 315 * u.m
64 dia = 70
65 dia2 = 40
66 #
67 system = fls.getPath(
68 name='path 1',
69 components=[
70 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
71 {'comp': fls.getComp(comp='Valve_01', D=dia, state=1)},
72 ],
73 )
74 #
75 wpt = fls.WpointDyn(s1=pump, s2=system)
76 plt = fls.PlotQHcurve(
77 pumps=[pump],
78 circuits=[system],
79 wpoints=[wpt],
80 title='Pumpcurve and system curve with valve',
81 sliders=[
82 dict(label='L (m)', vmin=100, vmax=800, vinit=system.getComp(0)['comp'].L.magnitude, fun=fun1),
83 dict(label='P speed (rpm)', vmin=1450, vmax=2900, vinit=2900, fun=fun2),
84 dict(label='V state', vmin=0, vmax=1, vinit=system.getComp(1)['comp'].state, fun=fun3),
85 ]
86 )
87 plt.show()
Example: e13_pump_rpm
e13_pump_rpm.py
Static Q-H plot example across multiple pump speeds. Overlays speed-scaled pump curves against one system curve.
1'''
2 e13_pump_rpm.py
3
4 Static Q-H plot example across multiple pump speeds.
5 Overlays speed-scaled pump curves against one system curve.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# MAIN
22# =============================================================================
23if __name__ == '__main__':
24
25 cat = fls.Catalogue()
26 c = cat.findLibraries('APV')
27 d1 = cat.searchInLibrary(c, 'T = centrifugal AND spec = "W+ 22/20" AND impeller0 = 110 AND speed0 = 2900')
28 print(d1)
29 d10 = d1[0]
30
31 fls.initFluidsolve(prefix_wpt='p')
32 pump1 = fls.getComp(comp='PumpCentrifugal', dataQH=d10['dataQH'], impeller0=d10['impeller0'], speed0=d10['speed0'])
33 pump1.speed = 2500
34 pump1.updateCurve()
35 pump2 = pump1.clone()
36 pump2.speed = 2000
37 pump2.updateCurve()
38 pump3 = pump1.clone()
39 pump3.speed = 1500
40 pump3.updateCurve()
41 #
42 system = fls.getComp(comp='Tube', L=350, D=80)
43 #
44 wpt1 = fls.getWpt(wpt='d', s1=pump1, s2=system)
45 print(f'For pump (speed0={pump1.speed0:.0f~P} with speed {pump1.speed:.0f~P} : {wpt1}')
46 wpt2 = fls.getWpt(wpt='d', s1=pump2, s2=system)
47 print(f'For pump (speed0={pump2.speed0:.0f~P} with speed {pump2.speed:.0f~P} : {wpt2}')
48 wpt3 = fls.getWpt(wpt='d', s1=pump3, s2=system)
49 print(f'For pump (speed0={pump3.speed0:.0f~P} with speed {pump3.speed:.0f~P} : {wpt3}')
50 #
51 plt = fls.PlotQHcurve(
52 pumps=[pump1, pump2, pump3],
53 circuits=[system],
54 wpoints=[wpt1, wpt2, wpt3],
55 title='Pumpcurve: 1 pump with different speeds (2500, 2000, 1500 rpm)',
56 Qmax = 30,
57 Hmax = 30,
58 )
59 plt.show()
Example: e20_pump_serial
e20_pump_serial.py
Interactive Q-H plotting example for two identical pumps in series. Sliders modify pipe dimensions and both pump speeds.
- x_examples.e20_pump_serial.fun3(value)[source]
Update first pump speed and refresh combined serial curve.
- x_examples.e20_pump_serial.fun4(value)[source]
Update second pump speed and refresh combined serial curve.
1'''
2 e20_pump_serial.py
3
4 Interactive Q-H plotting example for two identical pumps in series.
5 Sliders modify pipe dimensions and both pump speeds.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# GLOBALS
22# =============================================================================
23system = None
24plt = None
25pump1 = None
26pump2 = None
27pumpS = None
28
29# =============================================================================
30# GLOBALS
31# =============================================================================
32def fun1(value):
33 '''Update system pipe length from slider input.'''
34 system.getComp(0)['comp'].L = value
35 plt.updateData()
36
37def fun2(value):
38 '''Update system pipe diameter from slider input.'''
39 system.getComp(0)['comp'].D = value
40 plt.updateData()
41
42def fun3(value):
43 '''Update first pump speed and refresh combined serial curve.'''
44 pump1.speed = value
45 pumpS.updateCurve()
46 plt.updateData()
47
48def fun4(value):
49 '''Update second pump speed and refresh combined serial curve.'''
50 pump2.speed = value
51 pumpS.updateCurve()
52 plt.updateData()
53
54# =============================================================================
55# MAIN
56# =============================================================================
57if __name__ == '__main__':
58 dataQH=fls.getPumpCurveDataText('''
59 3.1843575418994416, 36.22969837587006
60 5.027932960893855, 36.43851508120649
61 9.944134078212288, 36.75174013921113
62 14.916201117318435, 36.542923433874705
63 19.94413407821229, 36.02088167053363
64 25.083798882681563, 34.87238979118329
65 29.88826815642458, 33.4106728538283
66 34.91620111731844, 31.531322505800457
67 40.055865921787706, 29.02552204176333
68 45.083798882681556, 25.684454756380504
69 48.826815642458094, 23.07424593967517
70 ''')
71 fls.initFluidsolve(prefix_wpt='p')
72 pump1 = fls.getComp(comp='PumpCentrifugal', dataQH=dataQH, impeller0=1, speed0=2900)
73 pump2 = fls.getComp(comp='PumpCentrifugal', dataQH=dataQH, impeller0=1, speed0=2900, speed=2600)
74 pumpS = fls.getComp(comp='PumpSerial', pumps=[pump1, pump2])
75 L = 315 * u.m
76 dia = 65
77 dia2 = 40
78 #
79 system = fls.getPath(
80 name='path 1',
81 components=[
82 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
83 {'comp': fls.getComp(comp='Entrance', D=dia)},
84 {'comp': fls.getComp(comp='Entrance', D=dia), 'sense': -1},
85 {'comp': fls.getComp(comp='BendLong', D=dia, A=30, n=2)},
86 {'comp': fls.getComp(comp='Bend', D=dia, A=45, R=5)},
87 {'comp': fls.getComp(comp='SharpReduction', D1=dia, D2=dia2)},
88 {'comp': fls.getComp(comp='Reverse', reverse=fls.getComp(comp='SharpReduction', D1=dia, D2=dia2))},
89 ],
90 )
91 #
92 wpt = fls.getWpt(wpt='d', s1=pumpS, s2= system)
93 #
94 plt = fls.PlotQHcurve(
95 pumps=[pump1, pump2, pumpS],
96 circuits=[system],
97 wpoints=[wpt],
98 title='Pumpcurve: 2 serial pumps',
99 sliders=[
100 dict(label='L (m)', vmin=100, vmax=800, vinit=system.getComp(0)['comp'].L.magnitude, fun=fun1),
101 dict(label='D (mm)', vmin=25, vmax=65, vinit=system.getComp(0)['comp'].D.magnitude, fun=fun2),
102 dict(label='P1 speed (rpm)', vmin=1450, vmax=2900, vinit=2900, fun=fun3),
103 dict(label='P2 speed (rpm)', vmin=1450, vmax=2900, vinit=2600, fun=fun4),
104 ]
105 )
106 plt.show()
Example: e21_pump_serial
e21_pump_serial.py
Interactive Q-H plotting example for two different pumps in series. Sliders modify pipe dimensions and both pump speeds.
- x_examples.e21_pump_serial.fun3(value)[source]
Update first pump speed and refresh combined serial curve.
- x_examples.e21_pump_serial.fun4(value)[source]
Update second pump speed and refresh combined serial curve.
1'''
2 e21_pump_serial.py
3
4 Interactive Q-H plotting example for two different pumps in series.
5 Sliders modify pipe dimensions and both pump speeds.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# GLOBALS
22# =============================================================================
23system = None
24plt = None
25pump1 = None
26pump2 = None
27pumpS = None
28
29# =============================================================================
30# FUNCS
31# =============================================================================
32def fun1(value):
33 '''Update system pipe length from slider input.'''
34 system.getComp(0)['comp'].L = value
35 plt.updateData()
36
37def fun2(value):
38 '''Update system pipe diameter from slider input.'''
39 system.getComp(0)['comp'].D = value
40 plt.updateData()
41
42def fun3(value):
43 '''Update first pump speed and refresh combined serial curve.'''
44 pump1.speed = value
45 pumpS.updateCurve()
46 plt.updateData()
47
48def fun4(value):
49 '''Update second pump speed and refresh combined serial curve.'''
50 pump2.speed = value
51 pumpS.updateCurve()
52 plt.updateData()
53
54# =============================================================================
55# MAIN
56# =============================================================================
57if __name__ == '__main__':
58 cat = fls.Catalogue()
59 cat.loadAllData()
60 c = cat.findLibraries('APV')
61 d1 = cat.searchInLibrary(c, 'T = centrifugal AND spec = "W+ 22/20" AND impeller0 = 110 AND speed0 = 2900')
62 print(d1)
63 d10 = d1[0]
64 d2 = cat.searchInLibrary(c, 'T = centrifugal AND spec = "W+ 35/35" AND impeller0 = 165 AND speed0 = 2900')
65 print(d2)
66 d20 = d2[0]
67
68 fls.initFluidsolve(prefix_wpt='p')
69 pump1 = fls.getComp(comp='PumpCentrifugal', dataQH=d10['dataQH'], impeller0=d10['impeller0'], speed0=d10['speed0'])
70 pump2 = fls.getComp(comp='PumpCentrifugal', dataQH=d20['dataQH'], impeller0=d20['impeller0'], speed0=d20['speed0'])
71 pumpS = fls.getComp(comp='PumpSerial', pumps=[pump1, pump2])
72 L = 315 * u.m
73 dia = 65
74 dia2 = 40
75 #
76 system = fls.getPath(
77 name='path 1',
78 components=[
79 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
80 {'comp': fls.getComp(comp='Entrance', D=dia)},
81 {'comp': fls.getComp(comp='Entrance', D=dia), 'sense': -1},
82 {'comp': fls.getComp(comp='BendLong', D=dia, A=30, n=2)},
83 {'comp': fls.getComp(comp='Bend', D=dia, A=45, R=5)},
84 {'comp': fls.getComp(comp='SharpReduction', D1=dia, D2=dia2)},
85 {'comp': fls.getComp(comp='Reverse', reverse=fls.getComp(comp='SharpReduction', D1=dia, D2=dia2))},
86 ],
87 )
88 #
89 wpt = fls.getWpt(wpt='d', s1=pumpS, s2= system)
90 #
91 plt = fls.PlotQHcurve(
92 pumps=[pump1, pump2, pumpS],
93 circuits=[system],
94 wpoints=[wpt],
95 title='Pumpcurve: 2 serial pumps',
96 sliders=[
97 dict(label='L (m)', vmin=100, vmax=800, vinit=system.getComp(0)['comp'].L.magnitude, fun=fun1),
98 dict(label='D (mm)', vmin=25, vmax=65, vinit=system.getComp(0)['comp'].D.magnitude, fun=fun2),
99 dict(label='P1 speed (rpm)', vmin=1450, vmax=2900, vinit=2900, fun=fun3),
100 dict(label='P2 speed (rpm)', vmin=1450, vmax=2900, vinit=2600, fun=fun4),
101 ]
102 )
103 plt.show()
Example: e22_pump_parallel
e22_pump_parallel.py
Interactive Q-H plotting example for two different pumps in parallel. Sliders modify pipe dimensions and both pump speeds.
- x_examples.e22_pump_parallel.fun3(value)[source]
Update first pump speed and refresh combined parallel curve.
- x_examples.e22_pump_parallel.fun4(value)[source]
Update second pump speed and refresh combined parallel curve.
1'''
2 e22_pump_parallel.py
3
4 Interactive Q-H plotting example for two different pumps in parallel.
5 Sliders modify pipe dimensions and both pump speeds.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16# UNITS
17u = fls.unitRegistry
18Quantity = fls.Quantity # type: ignore[misc]
19
20# =============================================================================
21# GLOBALS
22# =============================================================================
23system = None
24plt = None
25pump1 = None
26pump2 = None
27pumpP = None
28
29# =============================================================================
30# GLOBALS
31# =============================================================================
32def fun1(value):
33 '''Update system pipe length from slider input.'''
34 system.getComp(0)['comp'].L = value
35 plt.updateData()
36
37def fun2(value):
38 '''Update system pipe diameter from slider input.'''
39 system.getComp(0)['comp'].D = value
40 plt.updateData()
41
42def fun3(value):
43 '''Update first pump speed and refresh combined parallel curve.'''
44 pump1.speed = value
45 pumpP.updateCurve()
46 plt.updateData()
47
48def fun4(value):
49 '''Update second pump speed and refresh combined parallel curve.'''
50 pump2.speed = value
51 pumpP.updateCurve()
52 plt.updateData()
53
54# =============================================================================
55# MAIN
56# =============================================================================
57if __name__ == '__main__':
58 cat = fls.Catalogue()
59 cat.loadAllData()
60 c = cat.findLibraries('APV')
61 d1 = cat.searchInLibrary(c, 'T = centrifugal AND spec = "W+ 22/20" AND impeller0 = 110 AND speed0 = 2900')
62 print(d1)
63 d10 = d1[0]
64 d2 = cat.searchInLibrary(c, 'T = centrifugal AND spec = "W+ 35/35" AND impeller0 = 165 AND speed0 = 2900')
65 print(d2)
66 d20 = d2[0]
67
68 fls.initFluidsolve(prefix_wpt='p')
69 pump1 = fls.getComp(comp='PumpCentrifugal', dataQH=d10['dataQH'], impeller0=d10['impeller0'], speed0=d10['speed0'])
70 pump2 = fls.getComp(comp='PumpCentrifugal', dataQH=d20['dataQH'], impeller0=d20['impeller0'], speed0=d20['speed0'], speed = 2300)
71 pumpP = fls.getComp(comp='PumpParallel', pumps=[pump1, pump2])
72 L = 200 * u.m
73 dia = 80
74 dia2 = 60
75 #
76 system = fls.getPath(
77 name='path 1',
78 components=[
79 {'comp': fls.getComp(comp='Tube', L=L, D=dia)},
80 {'comp': fls.getComp(comp='Entrance', D=dia)},
81 {'comp': fls.getComp(comp='Entrance', D=dia), 'sense': -1},
82 {'comp': fls.getComp(comp='BendLong', D=dia, A=30, n=2)},
83 {'comp': fls.getComp(comp='Bend', D=dia, A=45, R=5)},
84 {'comp': fls.getComp(comp='SharpReduction', D1=dia, D2=dia2)},
85 {'comp': fls.getComp(comp='Reverse', reverse=fls.getComp(comp='SharpReduction', D1=dia, D2=dia2))},
86 ],
87 )
88 #
89 wpt = fls.getWpt(wpt='d', s1=pumpP, s2= system)
90 #
91 plt = fls.PlotQHcurve(
92 Qmax=80,
93 pumps=[pump1, pump2, pumpP],
94 circuits=[system],
95 wpoints=[wpt],
96 title='Pumpcurve: 2 parallel pumps',
97 sliders=[
98 dict(label='L (m)', vmin=100, vmax=300, vinit=system.getComp(0)['comp'].L.magnitude, fun=fun1),
99 dict(label='D (mm)', vmin=50, vmax=100, vinit=system.getComp(0)['comp'].D.magnitude, fun=fun2),
100 dict(label='P1 speed (rpm)', vmin=1450, vmax=2900, vinit=2900, fun=fun3),
101 dict(label='P2 speed (rpm)', vmin=1450, vmax=2400, vinit=2300, fun=fun4),
102 ]
103 )
104 plt.show()
Example: e30_basic
e30_basic1.py
Basic network-module example. Builds and solves representative network configurations.
Network 1: single pump and tube:
+--pmp>--+
/ \
A B
\ /
+--------+
100m
1r'''
2e30_basic1.py
3
4Basic network-module example.
5Builds and solves representative network configurations.
6
7Network 1: single pump and tube::
8
9 +--pmp>--+
10 / \
11 A B
12 \ /
13 +--------+
14 100m
15
16'''
17# =============================================================================
18# PYLINT DIRECTIVES
19# =============================================================================
20# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
21
22# =============================================================================
23# EXTERNAL MODULE REFERENCES
24# =============================================================================
25import fluidsolve as fls
26
27# =============================================================================
28# MAIN
29# =============================================================================
30if __name__ == '__main__':
31 fls.initFluidsolve(prefix_wpt='p', prefix_comp='Comp_')
32 cat = fls.Catalogue()
33 pumprecs = cat.searchInLibrary(cat.findLibraries('APV'), 'T = centrifugal AND spec = "W+ 22/20" AND impeller0 = 110 AND speed0 = 2900')
34 if len(pumprecs)>0:
35 pr0 = pumprecs[0]
36 else:
37 raise ValueError('No pump found.')
38
39 net1 = fls.getNetwork(
40 name='net 1',
41 components=[
42 {'nodes': ['A','B'], 'comp': fls.getComp(comp='PumpCentrifugal', dataQH=pr0['dataQH'], impeller0=pr0['impeller0'], speed0=pr0['speed0'], speed=pr0['speed0']-200)},
43 {'nodes': ['B','A'], 'sense': 1, 'comp': fls.getComp(comp='Tube', L=100, D=50)},
44 ],
45 )
46 net1.calcNetwork()
47 print(net1.toString(detail=1))
Example: e31_basic2
e31_basic2.py
Basic network-module example. Builds and solves representative network configurations.
Network 2: single pump and two tubes in parallel:
A---pmp>---B
| |
| |100m
| |
+----------C
90m
1# pylint: disable=anomalous-backslash-in-string
2'''
3e31_basic2.py
4
5Basic network-module example.
6Builds and solves representative network configurations.
7
8Network 2: single pump and two tubes in parallel::
9
10 A---pmp>---B
11 | |
12 | |100m
13 | |
14 +----------C
15 90m
16
17'''
18# =============================================================================
19# PYLINT DIRECTIVES
20# =============================================================================
21# pylint: enable=anomalous-backslash-in-string
22# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
23
24# =============================================================================
25# EXTERNAL MODULE REFERENCES
26# =============================================================================
27import fluidsolve as fls
28
29# =============================================================================
30# MAIN
31# =============================================================================
32if __name__ == '__main__':
33 fls.initFluidsolve(prefix_wpt='p', prefix_comp='Comp_')
34 cat = fls.Catalogue()
35 pumprecs = cat.searchInLibrary(cat.findLibraries('APV'), 'T = centrifugal AND spec = "W+ 22/20" AND impeller0 = 110 AND speed0 = 2900')
36 if len(pumprecs)>0:
37 pr0 = pumprecs[0]
38 else:
39 raise ValueError('No pump found.')
40
41 net2 = fls.getNetwork(
42 name='net 2',
43 components=[
44 {'nodes': ['A','B'], 'comp': fls.getComp(comp='PumpCentrifugal', dataQH=pr0['dataQH'], impeller0=pr0['impeller0'], speed0=pr0['speed0'])},
45 {'nodes': ['B','C'], 'comp': fls.getComp(comp='Tube', L=100, D=50)},
46 {'nodes': ['C','A'], 'comp': fls.getComp(comp='Tube', L=90, D=50)},
47 ],
48 )
49
50 net2.calcNetwork()
51 print(net2.toString(detail=1))
Example: e32_basic3
e32_basic3.py
Basic network-module example. Builds and solves representative network configurations.
Network 3: two pumps and multiple tubes in a more complex configuration:
50m 100m
B----------C----------D
^ | ^
pmp |100m pmp
| | |
A----------F----------E
150m 100m
1# pylint: disable=anomalous-backslash-in-string
2'''
3e32_basic3.py
4
5Basic network-module example.
6Builds and solves representative network configurations.
7
8Network 3: two pumps and multiple tubes in a more complex configuration::
9
10 50m 100m
11 B----------C----------D
12 ^ | ^
13 pmp |100m pmp
14 | | |
15 A----------F----------E
16 150m 100m
17
18'''
19# =============================================================================
20# PYLINT DIRECTIVES
21# =============================================================================
22# pylint: enable=anomalous-backslash-in-string
23# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
24
25# =============================================================================
26# EXTERNAL MODULE REFERENCES
27# =============================================================================
28import fluidsolve as fls
29
30# =============================================================================
31# MAIN
32# =============================================================================
33if __name__ == '__main__':
34 fls.initFluidsolve(prefix_wpt='p', prefix_comp='Comp_')
35 cat = fls.Catalogue()
36 pumprecs = cat.searchInLibrary(cat.findLibraries('APV'), 'T = centrifugal AND spec = "W+ 22/20" AND impeller0 = 110 AND speed0 = 2900')
37 if len(pumprecs)>0:
38 pr0 = pumprecs[0]
39 else:
40 raise ValueError('No pump found.')
41
42 net3 = fls.getNetwork(
43 name='net 3',
44 components=[
45 {'nodes': ['A','B'], 'comp': fls.getComp(comp='PumpCentrifugal', dataQH=pr0['dataQH'], impeller0=pr0['impeller0'], speed0=pr0['speed0'], speed=pr0['speed0']+100)},
46 {'nodes': ['B','C'], 'comp': fls.getComp(comp='Tube', L=50, D=50)},
47 {'nodes': ['D','C'], 'comp': fls.getComp(comp='Tube', L=100, D=50)},
48 {'nodes': ['D','E'], 'sense': -1, 'comp': fls.getComp(comp='PumpCentrifugal', dataQH=pr0['dataQH'], impeller0=pr0['impeller0'], speed0=pr0['speed0'], speed=pr0['speed0']+100)},
49 {'nodes': ['E','F'], 'comp': fls.getComp(comp='Tube', L=100, D=50)},
50 {'nodes': ['C','F'], 'comp': fls.getComp(comp='Tube', L=100, D=50)},
51 {'nodes': ['F','A'], 'comp': fls.getComp(comp='Tube', L=150, D=50)},
52 ],
53 )
54 net3.calcNetwork()
55 print(net3.toString(detail=1))
56
57 #print(net3.resultCandidatesString())
Example: e35_valve
e35_valve.py
Network example featuring a three-way valve component. Illustrates setup and inspection of valve-centered circuits.
1'''
2 e35_valve.py
3
4 Network example featuring a three-way valve component.
5 Illustrates setup and inspection of valve-centered circuits.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16
17# =============================================================================
18# MAIN
19# =============================================================================
20if __name__ == '__main__':
21 cat = fls.Catalogue()
22 pumprecs = cat.searchInLibrary(cat.findLibraries('APV'), 'T = centrifugal AND spec = "W+ 22/20" AND impeller0 = 110 AND speed0 = 2900')
23 if len(pumprecs)>0:
24 pr0 = pumprecs[0]
25 else:
26 raise ValueError('No pump found.')
27
28 valve1 = fls.getComp(comp='Valve_3W', D=50, state=1)
29 net1 = fls.getNetwork(
30 name='net 1',
31 components=[
32 {'nodes': ['A','B'], 'comp': fls.getComp(comp='PumpCentrifugal', dataQH=pr0['dataQH'], impeller0=pr0['impeller0'], speed0=pr0['speed0'], speed=pr0['speed0']-200)},
33 {'nodes': ['B','C','D'], 'comp': fls.getComp(comp='Valve_3W', D=50, state=1)},
34 {'nodes': ['C','A'], 'comp': fls.getComp(comp='Tube', L=100, D=50)},
35 {'nodes': ['D','A'], 'comp': fls.getComp(comp='Tube', L=200, D=50)},
36 ],
37 )
38 #print(net1.toString(detail=1))
39 net1.calcNetwork()
40 print('==========================================================================')
41 print('Valve state 1: B->C open, B->D closed')
42 print(net1.resultString())
43 net1.components[1]['comp'].state = 2
44 net1.calcNetwork()
45 print('Valve state 2: B->C closed, B->D open')
46 print(net1.resultString())
47 print('==========================================================================')
48
49 valve2 = fls.getComp(comp='Valve_DS', D=50, state=1)
50 net2 = fls.getNetwork(
51 name='net 2',
52 components=[
53 {'nodes': ['A','B'], 'comp': fls.getComp(comp='PumpCentrifugal', dataQH=pr0['dataQH'], impeller0=pr0['impeller0'], speed0=pr0['speed0'], speed=pr0['speed0']-200)},
54 {'nodes': ['B','C','E','D'], 'comp': fls.getComp(comp='Valve_DS', D=50, state=1)},
55 {'nodes': ['C','D'], 'comp': fls.getComp(comp='Tube', L=200, D=50)},
56 {'nodes': ['E','A'], 'comp': fls.getComp(comp='Tube', L=50, D=50)},
57 ],
58 )
59 print(net2.toString(detail=1))
60 net2.calcNetwork()
61 print('==========================================================================')
62 print('Valve state 1: closed')
63 print(net1.resultString())
64 net2.components[1]['comp'].state = 2
65 net2.calcNetwork()
66 print('Valve state 2: open')
67 print(net1.resultString())
68 print('==========================================================================')
Example: e50_plot
e50_plot.py
Basic plotting-module example. Demonstrates curves, lines, annotations, and widgets.
1'''
2 e50_plot.py
3
4 Basic plotting-module example.
5 Demonstrates curves, lines, annotations, and widgets.
6'''
7# =============================================================================
8# PYLINT DIRECTIVES
9# =============================================================================
10# pylint: disable=no-member,no-name-in-module,invalid-name,wrong-import-position
11
12# =============================================================================
13# EXTERNAL MODULE REFERENCES
14# =============================================================================
15import fluidsolve as fls
16
17# =============================================================================
18# MAIN
19# =============================================================================
20if __name__ == '__main__':
21 x1 = [x for x in range(0, 10)]
22 y1 = [2+x*2 for x in range(0, 10)]
23 lbl1 = [f"lbl{i}" for i in range(0, 10)]
24 x2 = [x for x in range(5, 15)]
25 y2 = [15*x**2 - x for x in range(0, 10)]
26 y3 = [5*x**3 - 40*x**2 for x in range(0, 10)]
27 fig = fls.PlotFigure(h=400, w=800, hw=60, nr=2, nc=3, nrw=2, ncw=10, title='DETITLE')
28 fig.setExtra('title', size=33)
29 graph1 = fls.PlotGraph(fig, r=0, c=0, title='gr1')
30 graph1.setGrid(axis='both')
31 graph2 = fls.PlotGraph(fig, r=0, c=1, title='gr2')
32 graph2.setExtra('title', size=33)
33 graph3 = fls.PlotGraph(fig, r=1, c='0:2', title='gr3')
34 graph3.setXAxis(vmin=-5, vmax=20, vstep=5, vmstep=3, labeltxt='x')
35 graph3.setYAxis(vmin=-50, vmax=50, vstep=20, vmstep=2, labeltxt='y')
36 graph3.setGrid(axis='both')
37 graph4 = fls.PlotGraph(fig, r=':', c=2, title='gr4')
38 curve1 = fls.PlotCurve(graph1, x=x1, y=y2)
39 curve2 = fls.PlotCurve(graph2, x=x2, y=y3)
40 curve3 = fls.PlotCurve(graph3, x=x1, y=y1)
41 curve4 = fls.PlotCurve(graph4, x=x1, y=y1)
42 btn1 : fls.PlotButton = fls.PlotButton(fig, r=0, c=8, label='BTN1', fun=lambda event: print('btn1'), color='lightblue', hovercolor='yellow')
43 sld1 : fls.PlotSlider = fls.PlotSlider(fig, r=1, c='3:9', label='SLD1', vmin=0, vmax=100, fun=lambda val: print(f'sld1: {val}'), color='lightgreen')
44 fig.show()