Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do not copy paste: AF want view factors from all the surfaces . combine my two codes so I can have view factors from all

Do not copy paste: AF
want view factors from all the surfaces . combine my two codes so I can have view factors from all surfaces
Using your Monte Carlo code, determine the view factor between a control surface on the left side of
the V-groove with every control surface on the opposite side of the V-groove. Do this for every control
surface on the left side of the V-groove. This means you should know the view factor between any two
control surfaces on opposing sides of the V-groove.
combine the codes below
import random
import numpy as np
import math
import matplotlib.pyplot as plt
# Numerical solution
def rotate_vector(vector, angle):
x, y = vector
theta = math.radians(angle)
x_rotated = math.cos(theta)* x - math.sin(theta)* y
y_rotated = math.sin(theta)* x + math.cos(theta)* y
return [x_rotated, y_rotated]
def find_intersection(x, y, xhat, yhat, surface1, surface2):
xi_s = surface1['X0']+ surface1['XHAT']* x
yi_s = surface1['Y0']+ surface1['YHAT']* y
xi_r = surface2['X0']+ surface2['XHAT']* x
yi_r = surface2['Y0']+ surface2['YHAT']* y
return xi_s, yi_s, xi_r, yi_r
def monte_carlo_ray_tracing(num_rays):
# Step 1: Define surfaces
surface_length =1 # Length of the surfaces
surface_distance =1 # Distance between the surfaces
surface1={'X0': 0,'Y0': 0, 'XHAT': surface_length, 'YHAT': 0}
surface2={'X0': 0,'Y0': surface_distance, 'XHAT': surface_length, 'YHAT': 0}
rays_surface1=[]
for _ in range(num_rays):
# Step 3: Find a random spot for each ray
ts = random.random()
tr = random.random()
# Step 4: Assign emission locations
x_ray_s1, y_ray_s1= surface1['X0']+ surface1['XHAT']* ts, surface1['Y0']+ surface1['YHAT']* ts
surface1_normal = rotate_vector([surface1['XHAT'], surface1['YHAT']],90)
R_theta_s1, R_phi_s1= random.random(), random.random()
theta_s1= math.asin(R_theta_s1)
if R_phi_s1<0.5:
theta_s1=-theta_s1
xhat_ray_s1= math.cos(theta_s1)* surface1_normal[0]- math.sin(theta_s1)* surface1_normal[1]
yhat_ray_s1= math.sin(theta_s1)* surface1_normal[0]+ math.cos(theta_s1)* surface1_normal[1]
rays_surface1.append({'X': x_ray_s1,'Y': y_ray_s1, 'XHAT': xhat_ray_s1, 'YHAT': yhat_ray_s1, 'Reflections': 0,'ts': None, 'tr': None})
# Step 6: Find intersection points and save ts and tr for each surface
for ray in rays_surface1:
xi_s, yi_s, xi_r, yi_r = find_intersection(ray['X'], ray['Y'], ray['XHAT'], ray['YHAT'], surface1, surface2)
denominator = ray['YHAT']* surface2['XHAT']- ray['XHAT']* surface2['YHAT']
if denominator !=0:
tr =(xi_s * surface2['YHAT']- yi_s * surface2['XHAT']+ surface2['X0']* surface2['YHAT']- surface2['Y0']* surface2['XHAT'])/ denominator
ts =(ray['X']+ ray['XHAT']* tr - surface1['X0'])/ surface1['XHAT']
ray['ts']= ts
ray['tr']= tr
# Step 7: Determine impact surface
for ray in rays_surface1:
ts = ray['ts']
tr = ray['tr']
if 0<= ts <=1:
if ray['Reflections']==0 or ts < rays_surface1[ray['Reflections']-1]['ts']:
ray['ImpactedSurface']=1
else:
ray['ImpactedSurface']=2
else:
ray['ImpactedSurface']=0
# Print the results
hit_count = sum(ray['ImpactedSurface']==1 for ray in rays_surface1)
miss_count = num_rays - hit_count
#print(f"Number of rays that hit the surface: {hit_count}")
#print(f"Number of rays that did not hit the surface: {miss_count}")
# view factor
view_factor = hit_count / num_rays
print(f"View Factor: {view_factor}")
# Example usage
monte_carlo_ray_tracing(100000)
second code
import numpy as np
import matplotlib.pyplot as plt
# Problem Definitions
phi =120 # phi (deg)
phi_radians = phi * np.pi /180 # phi (rad)
Nsurf =10 # number of surfaces PER SIDE
length =0.1 # total length per side (m)
dL = length / Nsurf # length of one surface
# Set Initial Conditions
X0=0
Y0=0
# Calculate Surfaces for First Side
for i in range(Nsurf):
XHAT = X0+ dL * np.sin(phi_radians /2)
YHAT = Y0- dL * np.cos(phi_radians /2) # MINUS for -y
temp = "surface" + str(i)+"={'X0':X0,'Y0':Y0,'XHAT':XHAT,'YHAT':YHAT}"
exec(temp)
X0= XHAT
Y0= YHAT
# Calculate Surfaces for Second Side
for i in range(Nsurf):
XHAT = X0+ dL * np.sin(phi_radians /2)
YHAT = Y0+ dL * np.cos(phi_radians /2) # PLUS for +Y
temp = "surface" + str(i + Nsurf)+"={'X0':X0,'Y0':Y0,'XHAT':XHAT,'YHAT':YHAT}"
exec(temp)
X0= XHAT
Y0= YHAT
# Plot Surfaces
for i in range(2* Nsurf):
temp ="plt.plot([surface"+ str(i)+"['X0'], surface" + str(i)+"['XHAT']],[surface"+ str(i)+"['Y0'], surface" + str(i)+"['YHAT']], marker='o')"
exec(temp)
plt.show()
the output should have similar values or I'll down vote
F 0->10=0.000862
F 0->11=0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions