Answered step by step
Verified Expert Solution
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 Vgroove with every control surface on the opposite side of the Vgroove. Do this for every control
surface on the left side of the Vgroove. This means you should know the view factor between any two
control surfaces on opposing sides of the Vgroove.
combine the codes below
import random
import numpy as np
import math
import matplotlib.pyplot as plt
# Numerical solution
def rotatevectorvector angle:
x y vector
theta math.radiansangle
xrotated math.costheta x math.sintheta y
yrotated math.sintheta x math.costheta y
return xrotated, yrotated
def findintersectionx y xhat, yhat, surface surface:
xis surfaceX surfaceXHAT x
yis surfaceY surfaceYHAT y
xir surfaceX surfaceXHAT x
yir surfaceY surfaceYHAT y
return xis yis xir yir
def montecarloraytracingnumrays:
# Step : Define surfaces
surfacelength # Length of the surfaces
surfacedistance # Distance between the surfaces
surfaceX: Y: 'XHAT': surfacelength, 'YHAT':
surfaceX: Y: surfacedistance, 'XHAT': surfacelength, 'YHAT':
rayssurface
for in rangenumrays:
# Step : Find a random spot for each ray
ts random.random
tr random.random
# Step : Assign emission locations
xrays yrays surfaceX surfaceXHAT ts surfaceY surfaceYHAT ts
surfacenormal rotatevectorsurfaceXHAT surfaceYHAT
Rthetas Rphis random.random random.random
thetas math.asinRthetas
if Rphis:
thetasthetas
xhatrays math.costhetas surfacenormal math.sinthetas surfacenormal
yhatrays math.sinthetas surfacenormal math.costhetas surfacenormal
rayssurfaceappendX: xraysY: yrays 'XHAT': xhatrays 'YHAT': yhatrays 'Reflections': ts: None, tr: None
# Step : Find intersection points and save ts and tr for each surface
for ray in rayssurface:
xis yis xir yir findintersectionrayX rayY rayXHAT rayYHAT surface surface
denominator rayYHAT surfaceXHAT rayXHAT surfaceYHAT
if denominator :
tr xis surfaceYHAT yis surfaceXHAT surfaceX surfaceYHAT surfaceY surfaceXHAT denominator
ts rayX rayXHAT tr surfaceX surfaceXHAT
rayts ts
raytr tr
# Step : Determine impact surface
for ray in rayssurface:
ts rayts
tr raytr
if ts :
if rayReflections or ts rayssurfacerayReflectionsts:
rayImpactedSurface
else:
rayImpactedSurface
else:
rayImpactedSurface
# Print the results
hitcount sumrayImpactedSurface for ray in rayssurface
misscount numrays hitcount
#printfNumber of rays that hit the surface: hitcount
#printfNumber of rays that did not hit the surface: misscount
# view factor
viewfactor hitcount numrays
printfView Factor: viewfactor
# Example usage
montecarloraytracing
second code
import numpy as np
import matplotlib.pyplot as plt
# Problem Definitions
phi # phi deg
phiradians phi nppi # phi rad
Nsurf # number of surfaces PER SIDE
length # total length per side m
dL length Nsurf # length of one surface
# Set Initial Conditions
X
Y
# Calculate Surfaces for First Side
for i in rangeNsurf:
XHAT X dL npsinphiradians
YHAT Y dL npcosphiradians # MINUS for y
temp "surface" striX:XY:Y'XHAT':XHAT,'YHAT':YHAT
exectemp
X XHAT
Y YHAT
# Calculate Surfaces for Second Side
for i in rangeNsurf:
XHAT X dL npsinphiradians
YHAT Y dL npcosphiradians # PLUS for Y
temp "surface" stri NsurfX:XY:Y'XHAT':XHAT,'YHAT':YHAT
exectemp
X XHAT
Y YHAT
# Plot Surfaces
for i in range Nsurf:
temp pltplotsurface striX surface" striXHATsurface striY surface" striYHAT markero
exectemp
pltshow
the output should have similar values or I'll down vote
F
F
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started