Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me write a code for this problem in Fortran. Here are some f90 files

ID: 3886353 • Letter: P

Question

Please help me write a code for this problem in Fortran. Here are some f90 files that I was given. If possible, please add notes to each line of code to explain the process. Thanks!

WATER_TANK_MASS_CONSERVATION.f90

Module my_subs
implicit none
!
! (Declare Shared data here)
!
real, parameter :: V_in=5, A_in=0.0025, A_exit=0.0025, g=9.8, A_tank=0.1
real :: V_exit
!
contains
Subroutine sub_rhs(rhs_1, h, time)
implicit none
real :: rhs_1, h, time
V_exit=sqrt(2.*g*h)
rhs_1=(V_in*A_in-V_exit*A_exit)/A_tank
end subroutine sub_rhs
end Module my_subs
!
!
Program Main
Use my_subs
implicit none
real :: del_t, rhs, time_total,t,h
real, dimension(:), allocatable :: height, time, V_e
integer :: i, i_max
i_max=1000
time_total=200.
del_t=time_total/Real(i_max)
t=0.d0
h=1.d0
allocate (height(0:i_max),time(0:i_max), V_e(0:i_max))
height(0)=h
time(0)=t
V_e(0)=0.d0
do i=1,i_max
call sub_rhs(rhs,h,t)
h=h+rhs*del_t
t=t+del_t
print *,t,h
time(i)=t
height(i)=h
v_e(i)=V_exit
enddo
open(1, file='out.dat')
write(1,*)'Variables = "time" "height" "Vexit"'
write(1,*)'Zone Datapacking = point'
do i=0,i_max
write(1,*)time(i),height(i),V_e(i)
enddo
stop
end program main

WATER_TANK_ENERGY_CONSERVATION.f90

Module my_subs
implicit none
!
! (Declare Shared data here)
!
real, parameter :: V_in=5., A_in=0.0025, A_exit=0.0025, g=9.8, A_tank=0.1
real, parameter :: T_in=85.
real :: V_exit, T_tank
!
contains
Subroutine sub_rhs(rhs_1,rhs_2, h, time)
implicit none
real :: rhs_1,rhs_2, h, time
V_exit=sqrt(2.*g*h)
rhs_1=(V_in*A_in-V_exit*A_exit)/A_tank
rhs_2=(v_in*A_in*T_in-V_exit*A_exit*T_tank)/A_tank
end subroutine sub_rhs
end Module my_subs
!
!
Program Main
Use my_subs
implicit none
real :: del_t, rhs_1,rhs_2, time_total, t,h,h_Ttank
real, dimension(:), allocatable :: height, time, V_e, T_e
integer :: i, i_max
i_max=1000
time_total=200.
del_t=time_total/Real(i_max)
t=0.
h=1.
T_tank=20.
h_Ttank=h*T_Tank
allocate (height(0:i_max),time(0:i_max), V_e(0:i_max),T_e(0:i_max))
height(0)=h
time(0)=t
V_e(0)=0.
T_e(0)=T_tank
do i=1,i_max
call sub_rhs(rhs_1,rhs_2,h, t)
h=h+rhs_1*del_t
h_Ttank=h_Ttank+rhs_2*del_t
t=t+del_t
T_tank=h_Ttank/h
print *,t,h,T_tank
time(i)=t
height(i)=h
v_e(i)=V_exit
T_e(i)=T_tank
enddo
open(1, file='out.dat')
write(1,*)'Variables = "time" "height" "Vexit" "Ttank"'
write(1,*)'Zone Datapacking = point'
do i=0,i_max
write(1,*)time(i),height(i),V_e(i),T_e(i)
enddo
stop
end program main

PUMP.f90

Module Global_Data
implicit none
real, parameter:: Pi=3.14159265358979, densit=998., ks=0.000046, D1=0.10226,D2=0.0525018, viscos=0.001
real ::Q, V1,V2,Re1,Re2,A1=pi*D1**2/4.,A2=pi*D2**2/4.,f1,f2,rough1,rough2
real :: bhp_ref=7.5,pump_efficiency=0.75
real::f, Re, roughness
real:: alpha=0.5
integer:: iter_max=100
end Module Global_Data
!
!
Module Functions
Use Global_data
implicit none
contains
subroutine func(function_value,x)
real:: x,function_value
function_value=1/sqrt(x)+2.*log10(roughness/3.7+2.51/Re/sqrt(x))
return
end subroutine func
!
subroutine func_Prime(dfdx,x)
real:: x,dfdx
dfdx=-1/(2.*x**1.5) + 1/(-2.3025850929940463*x - 0.24793637267083515*x**1.5*Re*roughness)
return
end subroutine func_Prime
!
end Module Functions

!
Module inter_Solver
use functions
implicit none
contains
subroutine Newton_Raphson(icount,x,x_guess)
implicit none
real:: x,x_guess,f,dfdx,del_x
integer:: icount
x=x_guess
do icount=1,iter_max
call func(f,x)
call func_prime(dfdx,x)
del_x =-f/dfdx
x=x+del_x*alpha
! print *,icount,abs(del_x)
if(abs(del_x)<1.e-6)exit
enddo
return
end subroutine Newton_Raphson
end Module inter_Solver
!
Module Functions_Q
Use inter_Solver
implicit none
contains
subroutine func_Q(bhp,Q)
real:: Q,bhp,h ,f_guess
integer::iteration
V1=Q/A1
V2=Q/A2
Re1=densit*V1*D1/viscos
Re2=densit*V2*D2/viscos
rough1=ks/D1
rough2=ks/D2
!---------------------- Newton Raphson Method------------------
f_guess=0.001
Re=Re1
roughness=rough1
call Newton_Raphson(iteration,f1,f_guess)
if(iteration > iter_max)then
print *,'Newton-Raphson method failed'
else
! print *,'Newton-Raphson method'
! print *,'number of iterations =',iteration,' the solution is =', f1
endif
!
f_guess=0.001
Re=Re2
roughness=rough2
call Newton_Raphson(iteration,f2,f_guess)
if(iteration > iter_max)then
print *,'Newton-Raphson method failed'
else
! print *,'Newton-Raphson method'
! print *,'number of iterations =',iteration,' the solution is =', f2
endif
h=6.4+6.98*f1*V1**2+4.443*f2*V2**2+0.452*V1**2+0.21*V2**2
bhp=998*Q*9.8*h /pump_efficiency/745.7
print *,998*Q*9.8*h,998*Q*9.8*h/745.7,bhp
return
end subroutine func_Q
end Module Functions_Q
!
Module exter_Solver
use functions_Q
implicit none
contains
!
subroutine Secant_Q(icount,x,x_1,x_2)
implicit none
real:: x,x_1,x_2,f_1,f_2,del_x
integer:: icount
x=x_1
call func_Q(f_1, x_1)
call func_Q(f_2, x_2)
do icount=1,iter_max
del_x =(bhp_ref-f_1)*(x_2-x_1)/(f_2-f_1)
x=x+del_x*alpha
if(abs(del_x)<1.e-8)exit
if(abs(f_1) < abs(f_2))then
x_2=x_1
f_2=f_1
endif
x_1=x
call func_Q(f_1, x_1)
enddo
return
end subroutine secant_Q
end Module exter_Solver
!
Program Main
use exter_Solver
Implicit none
real:: Q_1,Q_2
integer :: iteration
!
Q_1=0.015
Q_2=0.016
call Secant_Q(iteration,Q,Q_1,Q_2)
if(iteration > iter_max)then
print *,'Secant method for flow rate failed'
else
print *,iteration,Q
endif
print *,Q,Q_1,Q_2
stop
end program main

MOODY.f90

Module Global_Data
implicit none
double precision, parameter:: alpha=0.5d0,Pi=3.14159265358979d0, &
& densit=998., viscos=0.001
double precision::f, Re, roughness
integer:: iter_max=100
end Module Global_Data
!
!
Module Functions
Use Global_data
implicit none
contains
subroutine x_equals_to(x)
implicit none
double precision::x
x=1./(-2.*log10(roughness/3.7+2.51/Re/sqrt(x)))**2
return
end subroutine x_equals_to
!
subroutine func(function_value,x)
implicit none
double precision:: x,function_value
function_value=1/sqrt(x)+2.*log10(roughness/3.7+2.51/Re/sqrt(x))
return
end subroutine func
!
subroutine func_Prime(dfdx,x)
implicit none
double precision:: x,dfdx
dfdx=-1/(2.*x**1.5) + 1/(-2.3025850929940463*x - 0.24793637267083515*x**1.5*Re*roughness)
return
end subroutine func_Prime
end Module Functions
!
!
Module Solver
use functions
implicit none
contains
subroutine Direct_substitution(icount,x_1,x)
implicit none
double precision:: x,x_1,x_old
integer:: icount
x=x_1
do icount=1,iter_max
x_old=x
call x_equals_to(x)
! print *,icount,abs(x-x_old)
if(abs(x-x_old) <1.e-6)exit
x=alpha*x+(1.-alpha)*x_old
enddo
return
end subroutine Direct_substitution
!
subroutine Secant(icount,x_1,x_2,x)
implicit none
double precision:: x,x_1,x_2,f_1,f_2,del_x
integer:: icount
x=x_1
call func(f_1, x_1)
call func(f_2, x_2)
do icount=1,iter_max
del_x =-f_1*(x_1-x_2)/(f_1-f_2)
x=x+del_x*alpha
if(abs(del_x)<1.e-6)exit
! print *,icount,abs(del_x)
if(abs(f_1) < abs(f_2))then
x_2=x_1
f_2=f_1
endif
x_1=x
call func(f_1, x_1)
enddo
return
end subroutine secant
!
subroutine Newton_Raphson(icount,x_guess,x)
implicit none
double precision:: x,x_guess,f,dfdx,del_x
integer:: icount
x=x_guess
do icount=1,iter_max
call func(f,x)
call func_prime(dfdx,x)
del_x =-f/dfdx
x=x+del_x*alpha
! print *,icount,abs(del_x)
if(abs(del_x)<1.e-6)exit
enddo
return
end subroutine Newton_Raphson
end Module Solver
!
!
Program Main
use Solver
Implicit none
double precision :: Q,U,ks,D,Area,f_1,f_2
double precision :: gallon2m3=0.003785411784d0
integer :: iteration
!
Q=50.d0*gallon2m3/60.d0
D=0.05d0
ks=0.00026d0
Area= Pi*D**2/4.d0
U=Q/Area
Re=densit*U*D/viscos
roughness=ks/D
print *,' Q =',Q,' U =',U
print *,' Re =',Re,' roughness =',roughness
!
!---------------------- Direct Substitution Method------------------
f_1=0.001
call Direct_substitution(iteration,f_1,f)
if(iteration > iter_max)then
print *,'Direct Substitution failed'
else
print *,'Direct Substitution'
print *,'number of iterations =',iteration,' the solution is =', f
endif
!---------------------- Secant Method------------------
f_1=0.001
f_2=0.002
call Secant(iteration,f_1,f_2,f)
if(iteration > iter_max)then
print *,'Secant method failed'
else
print *,'Secant method'
print *,'number of iterations =',iteration,' the solution is =', f
endif
!---------------------- Newton Raphson Method------------------
f_1=0.001
call Newton_Raphson(iteration,f_1,f)
if(iteration > iter_max)then
print *,'Newton-Raphson method failed'
else
print *,'Newton-Raphson method'
print *,'number of iterations =',iteration,' the solution is =', f
endif
stop
end program main

10hp.f90

Module Global_Data
implicit none
double precision, parameter:: Pi=3.14159265358979,gallon_to_m_cubic= 0.003785411784
double precision, parameter::D=0.05,ks=0.00026,den=998.,vis=0.001, L=1000.
double precision::f, Re, roughness, V
double precision:: alpha=0.5
integer:: iter_max=100
end Module Global_Data
!
!
Module Functions
Use Global_data
implicit none
contains
subroutine x_equals_to(x)
implicit none
double precision::x
x=1./(-2.*log10(roughness/3.7+2.51/Re/sqrt(x)))**2
return
end subroutine x_equals_to
!
subroutine func(function_value,x)
implicit none
double precision:: x,function_value
function_value=1/sqrt(x)+2.*log10(roughness/3.7+2.51/Re/sqrt(x))
return
end subroutine func
!
subroutine func_Prime(dfdx,x)
implicit none
double precision:: x,dfdx
dfdx=-1/(2.*x**1.5) + 1/(-2.3025850929940463*x - 0.24793637267083515*x**1.5*Re*roughness)
return
end subroutine func_Prime

subroutine Newton_Raphson(icount,x_guess,x)
implicit none
double precision:: x,x_guess,f,dfdx,del_x
integer:: icount
x=x_guess
do icount=1,iter_max
call func(f,x)
call func_prime(dfdx,x)
del_x =-f/dfdx
x=x+del_x*alpha
if(abs(del_x)<1.d-9)exit
enddo
return
end subroutine Newton_Raphson

subroutine Cal_Power(D,Q,P)
implicit none
double precision::Q,P,f_1,f,delp,D
integer::iteration, iter_max=100
V=Q/(Pi*D**2/4.)
Re=den*V*D/vis
roughness=ks/D
f_1=0.001
call Newton_Raphson(iteration,f_1,f)
if(iteration > iter_max)then
print *,'Newton-Raphson method failed'
stop
endif
delp=f*L/D*(0.5*den*V**2)
P=delp*Q/745.7
return
end subroutine Cal_power

end Module Functions
!
!
Module Solver
use functions
implicit none
contains
subroutine Secant(icount,D,Q_1,Q_2,P_1,P_ref)
implicit none
double precision:: Q,Q_1,Q_2,P_1,P_2,del_Q,P_ref,D
integer:: icount
Q=Q_1
call cal_power(D,Q_1,P_1)
call cal_power(D,Q_2,P_2)
do icount=1,iter_max
del_Q =(P_ref-P_1)*(Q_1-Q_2)/(P_1-P_2)
Q=Q+del_Q*alpha
if(abs(P_1-P_ref) < abs(P_2-P_ref))then
Q_2=Q_1
P_2=P_1
endif
Q_1=Q
call cal_power(D,Q_1,P_1)
print *,icount,Q_1,P_1,abs(del_Q)
if(abs(del_Q)<1.d-9)exit
enddo
return
end subroutine secant
!
end Module Solver
!
!
Program Main
use Solver
Implicit none
double precision:: Q,Q1,Q2, W, Power_ref=10.d0,power
integer::iter
Q1=50.d0*gallon_to_m_cubic/60.d0
Q2=60.d0*gallon_to_m_cubic/60.d0
call secant(iter,D,Q1,Q2,Power,Power_ref)
Q=Q1*60d0/gallon_to_m_cubic
print *,iter,Q,Power
stop
end program main

A large reservoir supplies water of 100 gallon/min for a community as shown in the following figure. Assume water is 20°C with p-998kg/m3, =0.001 kg/m. sec. Water is pumped from the reservoir to a large storage tank before being sent on to the water treatment facility. From B to C the system consists of a square-edged entrance, 500m of pipe, one globe valve, two 45° elbows, and two 90° elbows. The section between D and E is only a straight 100 m pipe. The system between E and F contains 400m of pipe, one gate valves, two 45° elbows and two 90° elbows. The sections between B to C and D to E are 24 inches schedule 40 pipe and the section between E and F is 5 inches schedule 40 pipe. The pipe material is steel. Assume all elbows are long-radius flanged and all valves are fully open. (1) Calculate the break horse power input to the pump (its efficiency is 60%) (2) If the electric motor can deliver hydraulic power of 50 hp, what will be the flow rate? z 120 m oF urm

Explanation / Answer

gfortran -c source.f90 gfortran -o executable object1.o object2.o ... gfortran -o executable source1.f90 source2.f90 gfortran -c aux.f gfortran -c diag.f gfortran flow.f aux.o diag.o -o flow.exe program f_prog integer :: i,j(2) real :: r character(len=10) :: str i = 4711 j = (/13, 14/) r = 4712.0 str = "abcd" call c_sub(trim(str)//char(0), i, r, j) end program f_prog

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote