Difference between revisions of "User:Bhamakerti.mohammad"

From ccitonlinewiki
Jump to: navigation, search
(Progress Pekan 2)
(Progress Pekan 2)
Line 39: Line 39:
  
 
== Progress Pekan 2 ==
 
== Progress Pekan 2 ==
Berikut adalah program yang sudah saya coba buat
 
  
 +
Final Report
  
import math
+
'''1) Dimensi optimal'''
 +
Dalam melakukan desain optimasi dari tabung hidrogen, parameter yang pertama diperhitungkan adalah dimensi dari tabung,
 +
 
 +
Adapun constraintnya adalah :
 +
Tekanan 8 bar, volume 1 L, dan harga Rp.500.000
 +
 
 +
Untuk memperhitungkan optimasi dimensi, saya menggunakan pemrograman melalui kode berikut :
 +
 
 +
<syntaxhighlight lang=xml>
 +
import numpy as np
 
from scipy.optimize import minimize
 
from scipy.optimize import minimize
  
def calculate_cylinder_volume(radius, height):
+
def objective_function(x, density, price_per_unit):
     return math.pi * radius**2 * height
+
    radius, height, thickness = x
 +
 
 +
    # Calculate the weight of the cylinder (assuming density of aluminium)
 +
     inner_radius = radius - thickness
 +
    inner_volume = np.pi * inner_radius**2 * height
 +
    outer_volume = np.pi * radius**2 * height
 +
    shell_volume = outer_volume - inner_volume
 +
    weight = shell_volume * density
 +
 
 +
    # Calculate the cost of the cylinder (based on material price per kg)
 +
    cost = weight * price_per_unit
 +
 
 +
    return cost
  
def calculate_cylinder_surface_area(radius, height):
+
def volume_constraint(x, target_volume):
     return 2 * math.pi * radius * (radius + height)
+
    radius, height, thickness = x
 +
     volume = np.pi * radius**2 * height * 1000  # Convert to liters
 +
    return volume - target_volume
  
def calculate_cylinder_weight(radius, height, thickness, density):
+
def pressure_constraint(x, target_pressure, allowable_stress):
 +
    radius, height, thickness = x
 
     inner_radius = radius - thickness
 
     inner_radius = radius - thickness
     inner_surface_area = calculate_cylinder_surface_area(inner_radius, height)
+
     stress = target_pressure * inner_radius / thickness
     return inner_surface_area * thickness * density
+
     return allowable_stress - stress
 +
 
 +
# Target volume in liters
 +
target_volume = 1
 +
 
 +
# Target pressure in bar
 +
target_pressure = 8
  
def objective_function(dimensions, target_capacity, target_pressure, density, price_per_unit):
+
# Density of aluminium in kg/m^3
    radius, height, thickness = dimensions
+
density_aluminium = 2700
  
    volume = calculate_cylinder_volume(radius, height) / 1000  # Convert to cubic meters
+
# Allowable stress for aluminium in Pa
    pressure = target_pressure * 1e5  # Convert to pascal
+
allowable_stress = 250e6
  
    error = pressure - target_pressure
+
# Initial guess for radius, height, and thickness
 +
x0 = [10.0, 50.0, 1.0]
  
    weight = calculate_cylinder_weight(radius, height, thickness, density)
+
# Define the bounds for radius, height, and thickness
    cost = weight * price_per_unit
+
bounds = [(0.1, None), (0.1, None), (0.01, None)]
  
    return error + cost
+
# Define the constraint functions
 +
volume_constraint_func = lambda x: volume_constraint(x, target_volume)
 +
pressure_constraint_func = lambda x: pressure_constraint(x, target_pressure, allowable_stress)
  
def optimize_cylinder_dimensions(target_capacity, target_pressure, density, price_per_unit):
+
# Define the optimization problem
     initial_guess = [0.1, 0.1, 0.01] # initial guess for radius, height, and thickness
+
problem = {
 +
    'fun': objective_function,
 +
    'x0': x0,
 +
    'bounds': bounds,
 +
     'constraints': [{'type': 'eq', 'fun': volume_constraint_func}, {'type': 'ineq', 'fun': pressure_constraint_func}],
 +
    'args': (density_aluminium, price_per_unit),
 +
    'method': 'SLSQP'
 +
}
  
    bounds = [(0.1, None), (0.1, None), (0.001, None)]  # bounds for radius, height, and thickness
+
# Solve the optimization problem
 +
result = minimize(**problem)
  
    result = minimize(objective_function, initial_guess, args=(target_capacity, target_pressure, density, price_per_unit), bounds=bounds)
+
# Extract the optimized dimensions
 +
optimal_radius, optimal_height, optimal_thickness = result.x
  
    radius, height, thickness = result.x
+
# Convert dimensions to mm
    weight = calculate_cylinder_weight(radius, height, thickness, density)
+
optimal_radius_mm = optimal_radius * 10
    cost = weight * price_per_unit
+
optimal_height_mm = optimal_height * 10
 +
optimal_thickness_mm = optimal_thickness * 10
  
    return radius, height, thickness, weight, cost
+
# Calculate the weight of the cylinder
 +
inner_volume = np.pi * (optimal_radius - optimal_thickness)**2 * optimal_height / 1000
 +
outer_volume = np.pi * optimal_radius**2 * optimal_height / 1000
 +
weight = (outer_volume - inner_volume) * density_aluminium
  
# Input Parameeter
+
# Print the optimized results
target_capacity = 1  # target capacity in liters
+
print("Optimization Results:")
target_pressure = 8  # target pressure in bar
+
print("Optimal Radius: {:.2f} mm".format(optimal_radius_mm))
density = 2700  # density of aluminium in kg/m^3
+
print("Optimal Height: {:.2f} mm".format(optimal_height_mm)) }
price_per_unit = 10500  # price per unit weight of the material
+
</syntaxhighlight>
  
radius, height, thickness, weight, cost = optimize_cylinder_dimensions(target_capacity, target_pressure, density, price_per_unit)
+
Sehingga didapatkan hasil
  
print("Optimized Cylinder Dimensions:")
+
Optimization Results:
print("Radius:", radius * 1000, "mm")
 
print("Height:", height * 1000, "mm")
 
print("Thickness:", thickness * 1000, "mm")
 
print("Weight:", weight, "kg")
 
print("Cost:", cost, "currency")
 
  
 +
Optimal Radius: 100.00 mm
  
Namun, hasilnya masih kurang benar, sehingga masih perlu perbaikan
+
Optimal Height: 500.00 mm

Revision as of 09:47, 5 June 2023

Introduction

Bhamakerti Mohammad Aydan.jpg

ٱلسَّلَامُ عَلَيْكُمْ وَرَحْمَةُ ٱللَّٰهِ وَبَرَكَاتُهُ

Perkenalkan saya Bhamakerti Mohammad Aydan biasa dipanggil Bhama dengan NPM 2106728023.

Saat ini saya sedang menjalani kelas Metode Numerik 01. Saya berharap bisa terus belajar dengan consciousness yang tinggi.

Progress Pekan 1

Tugas : Optimasi tangki hidrogen dengan kapasitas 1 liter, pressure 8 bar, dan biaya produksi maksimal Rp. 500.000

Pada pekan 1, saya membaca sebuah paper dari Jiai Chen, dkk(2018) dengan judul "Design And Optimization of High-Pressure Hydrogen Cylinders For Intermodal Container Transportation".

Pada paper tersebut, ada beberapa parameter yang mejadi fokus untuk melakukan optimisasi pada desain tabung hydrogen

1. Geometri dari tabung Pada bagian geometri, akan didapatkan nilai outer diameter (2r), length of cylinder (l), dan thickness of cylinder(t)

2. Tekanan Optimal hidrogen Parameter ini dicari untuk menentukan geometri dan ukuran dari tabung

3. Packing Problem Paper ini juga memperhatikan bagaimana mentransport hydrogen seefisien mungkin

Adapun workflow yang digunakan adalah sebagai berikut First, for a single cylinder with the external diameter (2𝑟) and the length of the cylinder body (𝑙), we will search for the optimal hydrogen pressure (Section 3). Second, with a given external diameter (2𝑟) of the cylinders, we will find the optimal body length (𝑙 ) (Section 4). Third, in the cross-section, circle packing problem in a square will be studied and optimal external diameter (2𝑟 ) will be found (Section 5). Finally, combining Sections 3-5, the optimal strategy can be attained.


Progress Pekan 2

Final Report

1) Dimensi optimal Dalam melakukan desain optimasi dari tabung hidrogen, parameter yang pertama diperhitungkan adalah dimensi dari tabung,

Adapun constraintnya adalah : Tekanan 8 bar, volume 1 L, dan harga Rp.500.000

Untuk memperhitungkan optimasi dimensi, saya menggunakan pemrograman melalui kode berikut :

import numpy as np
from scipy.optimize import minimize

def objective_function(x, density, price_per_unit):
    radius, height, thickness = x

    # Calculate the weight of the cylinder (assuming density of aluminium)
    inner_radius = radius - thickness
    inner_volume = np.pi * inner_radius**2 * height
    outer_volume = np.pi * radius**2 * height
    shell_volume = outer_volume - inner_volume
    weight = shell_volume * density

    # Calculate the cost of the cylinder (based on material price per kg)
    cost = weight * price_per_unit

    return cost

def volume_constraint(x, target_volume):
    radius, height, thickness = x
    volume = np.pi * radius**2 * height * 1000  # Convert to liters
    return volume - target_volume

def pressure_constraint(x, target_pressure, allowable_stress):
    radius, height, thickness = x
    inner_radius = radius - thickness
    stress = target_pressure * inner_radius / thickness
    return allowable_stress - stress

# Target volume in liters
target_volume = 1

# Target pressure in bar
target_pressure = 8

# Density of aluminium in kg/m^3
density_aluminium = 2700

# Allowable stress for aluminium in Pa
allowable_stress = 250e6

# Initial guess for radius, height, and thickness
x0 = [10.0, 50.0, 1.0]

# Define the bounds for radius, height, and thickness
bounds = [(0.1, None), (0.1, None), (0.01, None)]

# Define the constraint functions
volume_constraint_func = lambda x: volume_constraint(x, target_volume)
pressure_constraint_func = lambda x: pressure_constraint(x, target_pressure, allowable_stress)

# Define the optimization problem
problem = {
    'fun': objective_function,
    'x0': x0,
    'bounds': bounds,
    'constraints': [{'type': 'eq', 'fun': volume_constraint_func}, {'type': 'ineq', 'fun': pressure_constraint_func}],
    'args': (density_aluminium, price_per_unit),
    'method': 'SLSQP'
}

# Solve the optimization problem
result = minimize(**problem)

# Extract the optimized dimensions
optimal_radius, optimal_height, optimal_thickness = result.x

# Convert dimensions to mm
optimal_radius_mm = optimal_radius * 10
optimal_height_mm = optimal_height * 10
optimal_thickness_mm = optimal_thickness * 10

# Calculate the weight of the cylinder
inner_volume = np.pi * (optimal_radius - optimal_thickness)**2 * optimal_height / 1000
outer_volume = np.pi * optimal_radius**2 * optimal_height / 1000
weight = (outer_volume - inner_volume) * density_aluminium

# Print the optimized results
print("Optimization Results:")
print("Optimal Radius: {:.2f} mm".format(optimal_radius_mm))
print("Optimal Height: {:.2f} mm".format(optimal_height_mm)) }

Sehingga didapatkan hasil

Optimization Results:

Optimal Radius: 100.00 mm

Optimal Height: 500.00 mm