# Problem with variable flux

**URL:** <https://fortran-lang.discourse.group/t/problem-with-variable-flux/5814>\
**Category:** Homework\
**Created:** [May 17, 2023, 6:23am UTC](https://fortran-lang.discourse.group/t/problem-with-variable-flux/5814 "2023-05-17T06:23:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![solaleh](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@solaleh](https://fortran-lang.discourse.group/u/solaleh)\
**Post date:** [May 17, 2023, 6:23am UTC](https://fortran-lang.discourse.group/t/problem-with-variable-flux/5814/1 "2023-05-17T06:23:14Z")

</div>

![photo_2023-05-12_19-45-46](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/e/eb5a784a133fc3810ca9b960d0bb02ce9a68d5c3.jpeg)  
can you solve my problem? I can`t figure out how fix it?!  
codes:

program project  
implicit none  
doubleprecision :: l,w,dx,dy,tig,errorr,eps,beta,tb  
doubleprecision,allocatable :: x(:),y(:),t(:,:),told(:,:),q2(:,🙂  
integer ::n,m,i,j,iteration

!open file  
open(10,file=“input.txt”)  
open(11,file=“output.plt”)  
open(12,file=“output.txt”)  
!reading input  
read(10,_)  
read(10,_) l  
read(10,_)  
read(10,_) w  
read(10,_)  
read(10,_) n  
read(10,_)  
read(10,_) m  
read(10,_)  
read(10,_) tig  
read(10,_)  
read(10,_) tb  
read(10,_)  
read(10,_) eps

!allocating  
allocate (x(n),y(m),t(n,m),told(n,m),q2(n,m))

!grid generation  
dx=l/(n-1)  
dy=w/(m-1)  
do i=1,n  
x(i)=(i-1)\*dx  
end do  
do j=1,m  
y(j)=(j-1)\*dy  
end do  
beta=dx/dy

!intial guess

```
t(:,:)=tig

```

!boundry condition  
t(:,0)=tb

! function flux

do i=1,n  
do j=1,m  
q2(i,j)=(t(i-1,j)-2.0_t(i,j)+t(i+1,j))/(dx\*\*2.0)  
q2(0,j)=5_j+27  
q2(i,0)=0.0  
q2(n,j)=0.0  
q2(i,m)=0.0  
end do  
end do

!solving problem  
told(:,:)=t(:,🙂  
iteration=0  
do  
errorr=0.0  
iteration=iteration+1  
do i=2,n-1  
do j=2,m-1  
t(i,j) = (t(i-1,j)+told(i+1,j)+((beta**2.0)_(t(i,j-1)+told(i,j+1))))/(2.0_(1.0+(beta**2.0)))  
errorr =max((abs(t(i,j)-told(i,j))),errorr)  
q2(i,j)=(t(i-1,j)-2.0_t(i,j)+t(i+1,j))/(dx\*\*2.0)  
if (q2(0,j)=5_j+27) exit  
end do  
end do

```
    if(errorr<eps) exit
     told(:,:)=t(:,:)
     print *, iteration,errorr
end do

```

!writing results  
write (11,_)‘variables=x,y,T zone i=’,m,‘j=’,n  
do i=1,n  
do j=1,m  
write (11,_) x(i),y(j),t(i,j)  
write (12,\*) x(i),y(j),t(i,j)  
end do  
end do

end program project

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [May 17, 2023, 6:53am UTC](https://fortran-lang.discourse.group/t/problem-with-variable-flux/5814/2 "2023-05-17T06:53:48Z")

</div>

Welcome to the forum! Please note that if you post source code, you best use the \</\> button to copy and paste the text with preservation of indentation and such. This makes it much more readable. And it avoids the replacement of certain combinations of characters by formatting, like the italics and the emoticons I now see.

Is this a homework assignment? The problem you say you are trying to solve is rather textbook 🙂 . And the updating of t(i,j) seems to be wrong - t(i-1,j) instead of told(|i-1,j) and what is the role of beta? Also beta does not seem to have been set to a particular value.

If the flux is variable (in time I resume), where is it updated?

Please elaborate on what you are trying to do and what you have tried so far. And what it is you think is going wrong. We are quite willing to help you solve it, but we do not intend to do your work 🙂 .

---

<div class="post-metadata">

**Author:** ![solaleh](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@solaleh](https://fortran-lang.discourse.group/u/solaleh)\
**Post date:** [May 17, 2023, 7:10am UTC](https://fortran-lang.discourse.group/t/problem-with-variable-flux/5814/3 "2023-05-17T07:10:49Z")

</div>

sorry, I am new.  
yes this is my homework.  
flux doesn’t need update, its variable and change temperature. I cant related them with each other.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [May 17, 2023, 8:09am UTC](https://fortran-lang.discourse.group/t/problem-with-variable-flux/5814/4 "2023-05-17T08:09:26Z")

</div>

Please edit your post and format the code (including proper indentations) as suggested by @Arjen . As it is, it is difficult to read.

Then please state more precisely what is the problem. Which values you get, and which values you are expecting. Also, without knowing the equations you are trying to translate to code, it can be hard to tell where is the problem in the code.
