Advertisement
Thomas_Lillieskold

Finite Differences 2D Not OK

May 1st, 2023
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Fortran 5.18 KB | Science | 0 0
  1. MODULE Finite_differences
  2. USE, intrinsic :: iso_fortran_env, only: real64
  3. USE DATA
  4. USE Aproximacion
  5. USE Linear_System_Solver, ONLY: Band_Relaxation_Method
  6. PRIVATE
  7.  
  8. PUBLIC:: Solver_BVP
  9.  
  10. CONTAINS
  11.  
  12.     SUBROUTINE Solver_BVP()
  13.     !Ax=b
  14.     REAL(kind=real64),DIMENSION(Extension, Extension)::Mat_Coeficientes !A
  15.     REAL(kind=real64),DIMENSION(Extension)::Mat_Independiente !B
  16.     REAL(kind=real64),DIMENSION(Extension):: Temperatura !x
  17.    
  18.     REAL(kind=real64):: Pos_x,Pos_y
  19.     REAL(kind=real64):: Temperatura_Frontera
  20.     REAL(kind=real64):: Fuente
  21.    
  22.     INTEGER I,J,Nodo_Iter
  23.    
  24.     OPEN(Unit=1,File="write_outs.dat")
  25.    
  26.     Mat_Coeficientes=0.0_real64; Mat_Independiente=0.0_real64; Temperatura=0.0_real64   !Inicializacion de las matrices en cero
  27.    
  28.     DO I=1,Extension                        !Asigno a toda la matriz de coeficientes la matriz identidad => Mat_Coeficientes=I
  29.         Mat_Coeficientes(i,i)=1.0_real64
  30.     END DO
  31.  
  32. !----------------------------ASIGNACION DE VALORES DE FRONTERA---------------------------------------------------------------
  33.  
  34. !-------------------------------FRONTERA DERECHA-----------------------------------------------------------------------------
  35.     DO I= 1,Segmentos_y+1                           !Cantidad de nodos en el eje Vertical
  36.         Pos_x = X_Final                             !Me mantengo siempre en el borde de la derecha
  37.         Pos_y = Y_initial + (i-1)*Incremento_y      !Voy subiendo a medida que pasan las iteraciones
  38.         CALL Condicion_Borde_Der(Pos_x,Pos_y,Temperatura_Frontera)
  39.         Mat_Independiente(I*(Segmentos_x+1))=Temperatura_Frontera
  40.     END DO
  41.    
  42. !-------------------------------FRONTERA IZQUIERDA----------------------------------------------------------------------------
  43.     DO I= 1,Segmentos_y+1                               !Cantidad de nodos en el eje vertical
  44.         Pos_x = X_Initial                               !Me mantengo siempre en el borde de la izquierda
  45.         Pos_y = Y_initial + (i-1)*Incremento_y          !Voy subiendo a medida que pasan las iteraciones
  46.         CALL Condicion_Borde_Izq(Pos_x,Pos_y,Temperatura_Frontera)
  47.         Mat_Independiente((i-1)*(Segmentos_x+1)+1)=Temperatura_Frontera
  48.     END DO
  49.    
  50. !------------------------------FRONTERA INFERIOR--------------------------------------------------------------------------------
  51.     DO I= 1,Segmentos_x+1                               !Cantidad de nodos en el eje horizontal
  52.         Pos_x = X_Initial + (i-1)*Incremento_x          !Voy desplazandome hacia la derecha a medida que pasan las iteraciones
  53.         Pos_y = Y_initial                               !Me mantengo en la frontera inferior
  54.         CALL Condicion_Borde_Inf(Pos_x,Pos_y,Temperatura_Frontera)
  55.         Mat_Independiente(I)=Temperatura_Frontera
  56.     END DO
  57.    
  58. !------------------------------FRONTERA SUPERIOR---------------------------------------------------------------------------------
  59.     DO I= 1,Segmentos_x+1                               !Cantidad de nodos en el eje horizontal
  60.         Pos_x = X_Initial + (i-1)*Incremento_x          !Voy desplazandome hacia la derecha a medida que pasan las iteraciones
  61.         Pos_y = Y_Final                                 !Me mantengo en la frontera inferior
  62.         CALL Condicion_Borde_Sup(Pos_x,Pos_y,Temperatura_Frontera)
  63.         Mat_Independiente((Extension-Segmentos_x)+(I-1))=Temperatura_Frontera
  64.     END DO
  65.    
  66. !--------------------------------------------------------------------------------------------------------------------------------
  67.    
  68. !----------------------------ASIGNACION DE VALORES DE MAT_INDEPENDIENTE (FUENTE)-------------------------------------------------
  69.  
  70.     DO I= 1,Segmentos_y                                 !Cantidad de nodos internos en el eje vertical
  71.        
  72.         DO J= 1,Segmentos_x                             !Cantidad de nodos internos en el eje horizontal
  73.        
  74.             Pos_x= X_Initial + j*Incremento_x           !Me voy desplazando horizontalmente hacia la derecha a medida que aumenta J  
  75.             Pos_y= Y_Initial + i*Incremento_y           !Me voy desplazando verticalmente hacia arriba a medida que aumenta I
  76.            
  77.             CALL Fuente_de_Calor(Pos_x,Pos_y,Fuente)
  78.            
  79.             Mat_Independiente(I*(Segmentos_x+1)+1+J) = Fuente/Conductividad
  80.            
  81.         END DO
  82.     END DO
  83.    
  84. !----------------------------------------------------------------------------------------------------------------------------------
  85.    
  86. !-------------------------ASIGNACION DE VALORES MATRIZ DE COEFICIENTES-------------------------------------------------------------
  87.  
  88.     DO J = 1, Segmentos_y-1                 !Cantidad de veces que debo subir para cubrir todos los nodos incognita
  89.    
  90.         I = J*(Segmentos_x+1)               !Me ubica en el nodo final de cada fila
  91.        
  92.         DO Nodo_iter = I+2, I+Segmentos_x   !Recorro los nodos internos en cada fila
  93.        
  94.         Mat_Coeficientes(Nodo_Iter,Nodo_Iter) =-2.0_real64*(Cte_x+Cte_y)
  95.         Mat_Coeficientes(Nodo_Iter,Nodo_Iter-1) = Cte_x
  96.         Mat_Coeficientes(Nodo_Iter,Nodo_Iter+1) = Cte_x
  97.         Mat_Coeficientes(Nodo_Iter,Nodo_Iter - Segmentos_x - 1) = Cte_y
  98.         Mat_Coeficientes(Nodo_Iter,Nodo_Iter + Segmentos_x + 1) = Cte_y
  99.        
  100.         END DO
  101.    
  102.     END DO  
  103.    
  104.    
  105.     CALL Band_Relaxation_Method(Mat_Coeficientes,Mat_Independiente,Temperatura,Extension)  
  106.    
  107.     DO I=1,Segmentos_y+1
  108.    
  109.         DO J=1,Segmentos_x+1
  110.        
  111.             Pos_x= X_Initial + (j-1)*Incremento_x           !Me voy desplazando horizontalmente hacia la derecha a medida que aumenta J  
  112.             Pos_y= Y_Initial + (i-1)*Incremento_y           !Me voy desplazando verticalmente hacia arriba a medida que aumenta I
  113.            
  114.         Write(1,*) Pos_x, Pos_y, Temperatura((I-1)*(Segmentos_x+1)+J)
  115.        
  116.         END DO
  117.        
  118.     END DO  
  119.    
  120.  
  121.  
  122. END SUBROUTINE Solver_BVP
  123.  
  124. END MODULE Finite_Differences
Tags: Fortran
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement