Advertisement
FelipeNeto2

Comparação da Numérica com a Analíticca

Mar 18th, 2024
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 4.91 KB | None | 0 0
  1. clc
  2. clear
  3. %===============Spacial and Temporal mesh creation=========================
  4. nSpacialPoints=500;
  5. nElements=nSpacialPoints-1;
  6. L=1;
  7. T=1;
  8. nTemporalPoints=100;
  9. [x_nodes,x_centers,temporalMesh,dx,dt]=malha(L,nSpacialPoints,T,nTemporalPoints);
  10.  
  11. %=================Boundary and initialConditions===========================
  12. pressureIn=1;
  13. pressureOut=0;
  14. %
  15. concentrationIn=1;
  16. concentrationOut=0;
  17. %=====================Physical Properties ================================
  18. permeability=ones([1, nElements]);
  19. compressibility=0;
  20. porosity=1;
  21. waterViscosity=1e0;
  22. difusionCoeff = 1*ones([1, nElements]);
  23. %====================Numerical Solution definiton==========================
  24. numericalConcentrationPredictor = zeros(nElements,1);
  25. numericalConcentrationPredictor(1:end) = concentrationOut;
  26. numericalConcentrationPredictorMatrix = zeros(nElements,nTemporalPoints);
  27. numericalConcentrationPredictorMatrix(:,1) = numericalConcentrationPredictor;
  28. %
  29. numericalConcentrationCorrector = zeros(nElements,1);
  30. numericalConcentrationCorrector(1:end) = concentrationOut;
  31. numericalConcentrationCorrectorMatrix = zeros(nElements,nTemporalPoints);
  32. %
  33. numericalConcentrationFiniteVolumeArray = zeros(nSpacialPoints,1);
  34. numericalConcentrationFiniteVolumeMatrix = zeros(nSpacialPoints,nTemporalPoints);
  35. numericalConcentrationFiniteVolumeMatrix(:,1) = zeros(nSpacialPoints,1);
  36. %
  37. numericalPressurePrevious = zeros(nElements,1);
  38. numericalPressurePrevious(:) = pressureOut;
  39. %=======================Permeability array definition======================
  40. condutivity=condutividade(permeability,waterViscosity,x_centers);
  41. %===========================Hydrodynamics solver===========================
  42. [A_hidro,b_hidro]=A_global_hidro(x_nodes,nSpacialPoints,nElements,condutivity,pressureIn,pressureOut,...
  43.     compressibility,dx,dt,numericalPressurePrevious);
  44. solucao_hidro=A_hidro\b_hidro;
  45. A_hidro(:,:)=0.0;
  46. b_hidro(:)=0.0;
  47. pressure=solucao_hidro(nSpacialPoints+1:nSpacialPoints+nElements);
  48. velocity=solucao_hidro(1:nSpacialPoints);
  49. pressureprevious=pressure;
  50. %============================Temporal Loop=================================
  51. dtMicro=0;
  52. for j=2:1:nTemporalPoints
  53.     %========================CFL CHECK + MICRO MESH========================
  54.     dt=temporalMesh(j)-temporalMesh(j-1);
  55.     micro=false;
  56.     if((max(velocity)*max(dt))/(min(porosity)*min(dx))>=1)
  57.         dtMicro = ((min(porosity)*min(dx))/velocity(1))-1e-40;
  58.         micro=true;
  59.     end
  60.     numericalConcentrationFiniteVolumeArray = volumes_finitos(porosity,velocity(1),difusionCoeff(1),...
  61.     nSpacialPoints,dx,dt,numericalConcentrationFiniteVolumeArray,concentrationIn,concentrationOut);
  62.     %==========================PREDICTOR STEP==============================
  63.     [numericalConcentrationPredictor]=transporte_concentracao_explicito_vetorial(numericalConcentrationCorrector,...
  64.     dx,dt,velocity,j,porosity,x_centers,temporalMesh,micro,dtMicro,concentrationIn);
  65.     numericalConcentrationPredictorMatrix(:,j) = numericalConcentrationPredictor;
  66.     numericalConcentrationFiniteVolumeMatrix(:,j) = numericalConcentrationFiniteVolumeArray;
  67.     %==========================CORRECTOR STEP==============================
  68.     [A_hidro,b_hidro]=A_global_hidro(x_nodes,nSpacialPoints,nElements,difusionCoeff,concentrationIn,concentrationOut,...
  69.     porosity,dx,dt,numericalConcentrationPredictor);
  70.     solucao_hidro=A_hidro\b_hidro;
  71.     A_hidro(:,:)=0.0;
  72.     b_hidro(:)=0.0;
  73.     numericalConcentrationCorrector=solucao_hidro(nSpacialPoints+1:nSpacialPoints+nElements);
  74.     flux=solucao_hidro(1:nSpacialPoints);
  75.     numericalConcentrationCorrectorMatrix(:,j) = numericalConcentrationCorrector;
  76.    
  77. end
  78.  
  79. % Parâmetros do problema
  80. U0 = concentrationIn; % Condição de contorno em x = 0
  81. UL = concentrationOut; % Condição inicial
  82. phi = porosity; % Porosidade
  83. vel = velocity(1); % Velocidade
  84. D = difusionCoeff(1); % Coeficiente de difusão
  85. L = 1; % Comprimento característico
  86. x = x_centers;
  87. t = temporalMesh;
  88.  
  89. % Calcula a solução analítica
  90. solucao_analitica = analitica_conveccao_difusao_cartesiana(U0,UL,phi,vel,D,L,x,t);
  91.  
  92. % Calcula a solução numérica
  93. solucao_numerica1 = zeros(nElements, nTemporalPoints);
  94. solucao_numerica2 = zeros(nElements, nTemporalPoints);
  95.  
  96. for i = 1:nTemporalPoints
  97.     solucao_numerica1(:, i) = numericalConcentrationCorrectorMatrix(:, i);
  98.     solucao_numerica2(:, i) = numericalConcentrationPredictorMatrix(:, i);
  99. end
  100.  
  101. % Plotagem das soluções
  102. for i = 1:nTemporalPoints
  103.     clf;
  104.     plot(x, solucao_numerica1(:, i), 'b', 'LineWidth', 2);
  105.     hold on;
  106.     plot(x, solucao_numerica2(:, i), 'm', 'LineWidth', 2);
  107.     hold on;
  108.     plot(x, solucao_analitica(:, i), 'r--', 'LineWidth', 2);
  109.     hold on;    
  110.     xlabel('Posição (m)');
  111.     ylabel('Concentração');
  112.     title(['Comparação entre solução numérica e analítica (t = ', num2str(t(i)), ')']);
  113.     legend('Corretor', 'Upwind implícito','Analítica');
  114.     grid on;
  115.    
  116.     pause(0.1);
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement