Difference between revisions of "User talk:Tianrhs"
(Numerical Calculation on Optimizing Design of 1 Litre Hydrogen Tank with 8 bar Pressure and cost expanse should not exceed 500K IDR) |
|||
Line 14: | Line 14: | ||
from scipy.optimize import minimize | from scipy.optimize import minimize | ||
− | + | -Constants | |
density_h2 = 70.85 # Density of hydrogen (kg/m^3) | density_h2 = 70.85 # Density of hydrogen (kg/m^3) | ||
cost_h2 = 1.5 # Cost of hydrogen ($/kg) | cost_h2 = 1.5 # Cost of hydrogen ($/kg) | ||
Line 21: | Line 21: | ||
cost_limit = 35 # Cost limit ($) | cost_limit = 35 # Cost limit ($) | ||
− | + | -Objective function | |
def objective(x): | def objective(x): | ||
volume, diameter, thickness = x | volume, diameter, thickness = x | ||
Line 28: | Line 28: | ||
return cost | return cost | ||
− | + | Constraint functions | |
def pressure_constraint(x): | def pressure_constraint(x): | ||
volume, diameter, thickness = x | volume, diameter, thickness = x | ||
Line 39: | Line 39: | ||
return objective(x) - cost_limit | return objective(x) - cost_limit | ||
− | + | -Initial guess | |
x0 = np.array([0.01, 0.01, 0.01]) # Initial guess for volume, diameter, and thickness | x0 = np.array([0.01, 0.01, 0.01]) # Initial guess for volume, diameter, and thickness | ||
− | + | -Bounds for volume, diameter, and thickness | |
bounds = [(0, None), (0, None), (0, None)] | bounds = [(0, None), (0, None), (0, None)] | ||
− | + | -Constraints | |
pressure_constr = {'type': 'ineq', 'fun': pressure_constraint} | pressure_constr = {'type': 'ineq', 'fun': pressure_constraint} | ||
cost_constr = {'type': 'ineq', 'fun': cost_constraint} | cost_constr = {'type': 'ineq', 'fun': cost_constraint} | ||
constraints = [pressure_constr, cost_constr] | constraints = [pressure_constr, cost_constr] | ||
− | + | -Optimization | |
result = minimize(objective, x0, method='SLSQP', bounds=bounds, constraints=constraints) | result = minimize(objective, x0, method='SLSQP', bounds=bounds, constraints=constraints) | ||
− | + | - Extract optimized values | |
opt_volume, opt_diameter, opt_thickness = result.x | opt_volume, opt_diameter, opt_thickness = result.x | ||
opt_length = opt_volume / (np.pi * ((opt_diameter / 2) ** 2)) | opt_length = opt_volume / (np.pi * ((opt_diameter / 2) ** 2)) | ||
− | + | - Print optimized values | |
print(f"Optimized Volume: {opt_volume} m^3") | print(f"Optimized Volume: {opt_volume} m^3") | ||
print(f"Optimized Diameter: {opt_diameter} m") | print(f"Optimized Diameter: {opt_diameter} m") | ||
Line 66: | Line 66: | ||
setelah program dilakukan run, didapatkan | setelah program dilakukan run, didapatkan | ||
− | Optimized Volume: 0.29694876042766083 | + | Optimized Volume: 0.29694876042766083 meter^3 |
− | Optimized Diameter: 0.19785008828415787 | + | Optimized Diameter: 0.19785008828415787 meter |
− | Optimized Thickness: 1.2073387849232942 | + | Optimized Thickness: 1.2073387849232942 meter |
− | Optimized Length: 9.658710263937978 | + | Optimized Length: 9.658710263937978 meter |
Sekian dan terimakasih | Sekian dan terimakasih |
Revision as of 09:55, 5 June 2023
Dalam melakukan kalkulasi mengoptimasi desain dari tank hydrogen, pertama2 kita harus bisa menentukan 3 hal pokok yang menjadi parameter kita dalam pengoptimasian: 1. Desain Variabel Variabel desain merujuk pada parameter atau variabel yang dapat diubah atau dioptimalkan dalam suatu proses desain. Variabel desain mempengaruhi karakteristik atau performa suatu sistem atau produk yang sedang dirancang. Dalam konteks desain, variabel desain dapat mencakup berbagai faktor seperti dimensi, bahan, bentuk, konfigurasi, struktur, dan lain sebagainya. Dalam konteks persoalan kita, saya menentukan volume, tekanan, dan cost efficiency sebagai parameter utk desain variabel
2.Fungsi Objektif Fungsi objektif (objective function) adalah sebuah fungsi matematis yang harus dioptimalkan dalam suatu masalah optimisasi. Tujuan dari fungsi objektif adalah untuk mengukur performa, efisiensi, atau kualitas dari solusi yang dicari dalam konteks permasalahan tertentu. Dalam konteks permasalahan ini, obj (x) akan digunakan untuk mengevaluasi apakah desain yang dimiliki melewati 500K IDR dengan dasar volume dan tekanan pada tank. Biaya termasuk biaya hidrogen (per kilogram) dikalikan dengan volume dan densitas hidrogen, serta biaya material tangki (per kilogram) dikalikan dengan volume.
3. Constraint Konstrain (constraint) merujuk pada batasan atau pembatas yang harus dipatuhi dalam mencari solusi optimal. Konstrain digunakan untuk membatasi ruang pencarian solusi agar memenuhi persyaratan atau kriteria tertentu yang diinginkan. Ada beberapa jenis konstrain, konstrain geometri, konstrain biaya, konstrain kinerja. Dalam konteks soal kita, Fungsi konstrain constraint(x) memeriksa apakah tekanan melebihi batas tekanan. Fungsi konstrain biaya cost_constraint(x) memeriksa apakah total biaya melebihi batas biaya sebesar 500k IDR.
Setelah menentukan 3 hal diatas, saya melakukan proses kalkulasi tersebut melalui PYTHON, berikut hasil codingannya:
import numpy as np from scipy.optimize import minimize
-Constants density_h2 = 70.85 # Density of hydrogen (kg/m^3) cost_h2 = 1.5 # Cost of hydrogen ($/kg) cost_material = 1.2 # Cost of tank material ($/kg) pressure_limit = 8 # Pressure limit (bar) cost_limit = 35 # Cost limit ($)
-Objective function def objective(x):
volume, diameter, thickness = x length = volume / (np.pi * ((diameter / 2) ** 2)) # Calculate length based on volume and diameter cost = cost_h2 * density_h2 * volume + cost_material * volume * length return cost
Constraint functions def pressure_constraint(x):
volume, diameter, thickness = x length = volume / (np.pi * ((diameter / 2) ** 2)) # Calculate length based on volume and diameter pressure = pressure_limit - (volume / (np.pi * ((diameter / 2) ** 2) * thickness))
return pressure
def cost_constraint(x):
return objective(x) - cost_limit
-Initial guess x0 = np.array([0.01, 0.01, 0.01]) # Initial guess for volume, diameter, and thickness
-Bounds for volume, diameter, and thickness bounds = [(0, None), (0, None), (0, None)]
-Constraints pressure_constr = {'type': 'ineq', 'fun': pressure_constraint} cost_constr = {'type': 'ineq', 'fun': cost_constraint} constraints = [pressure_constr, cost_constr]
-Optimization result = minimize(objective, x0, method='SLSQP', bounds=bounds, constraints=constraints)
- Extract optimized values opt_volume, opt_diameter, opt_thickness = result.x opt_length = opt_volume / (np.pi * ((opt_diameter / 2) ** 2))
- Print optimized values print(f"Optimized Volume: {opt_volume} m^3") print(f"Optimized Diameter: {opt_diameter} m") print(f"Optimized Thickness: {opt_thickness} m") print(f"Optimized Length: {opt_length} m")
setelah program dilakukan run, didapatkan Optimized Volume: 0.29694876042766083 meter^3 Optimized Diameter: 0.19785008828415787 meter Optimized Thickness: 1.2073387849232942 meter Optimized Length: 9.658710263937978 meter
Sekian dan terimakasih