Skip to content
Snippets Groups Projects
Commit f1c512f6 authored by Arturo Sanchez's avatar Arturo Sanchez
Browse files

modificaciones

parent 588c7aa8
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Deposición Aleatoria # Deposición Aleatoria
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Inluimos las librerias necesarias Inluimos las librerias necesarias.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
#include<iostream> #include<iostream>
#include<vector> #include<vector>
#include<stdlib.h> #include<stdlib.h>
#include<time.h> #include<time.h>
#include<fstream> #include<fstream>
#include <math.h> #include <math.h>
using namespace std; using namespace std;
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Definimos la longitud del espacio en donde caerán las partículas y el número de partículas. Definimos la longitud del espacio en donde caerán las partículas y el número de partículas.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
int L,P; int L,P;
L = 100; //Longitud del espacio L = 100; //Longitud del espacio
P = 1000000; //Número de partículas P = 1000000; //Número de partículas
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Creamos un vector que va a contener las alturas de las partículas. Creamos un vector que va a contener las alturas de las partículas.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
vector<int> H(L,0); vector<int> H(L,0);
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Definimos las variables Tiempo, Altura media y Rugosidad. Definimos las variables Tiempo, Altura media y Rugosidad.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
int t=0; //Tiempo int t=0; //Tiempo
double Hm; //Altura media double Hm; //Altura media
double W; //Rugosidad double W; //Rugosidad
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Creamos un archivo para guardar los datos. Creamos un archivo para guardar los datos.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
//Archivo que va a guardar los datos //Archivo que va a guardar los datos
ofstream datos("aleatoria.csv"); ofstream datos("aleatoria.csv");
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Procedemos a llenar el vector de alturas definido anteriormente, generando un número aleatorio $(l)$ entre $0$ y $L-1$ para que represente la posición en donde va a caer la partícula, luego hacemos $H[l] = H[l] + 1$, así hacemos para cada partícula hasta llenar el vector de altura. En el procedimiento se va calculando la altura media y rugosidad y el tiempo, y estos valores se guardan en el archivo aleatoria.csv. Procedemos a llenar el vector de alturas definido anteriormente, generando un número aleatorio $(l)$ entre $0$ y $L-1$ para que represente la posición en donde va a caer la partícula, luego hacemos $H[l] = H[l] + 1$, así hacemos para cada partícula hasta llenar el vector de altura. En el procedimiento se va calculando la altura media y rugosidad y el tiempo, y estos valores se guardan en el archivo aleatoria.csv.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
//Para cada particula} //Para cada particula}
srand(time(NULL)); srand(time(NULL));
for(int i=1;i<=P;i++){ for(int i=1;i<=P;i++){
int l=rand()%(L); int l=rand()%(L);
H[l] = H[l] + 1; H[l] = H[l] + 1;
double s = 0; double s = 0;
for (int i = 0; i < H.size(); i++){ for (int i = 0; i < H.size(); i++){
s = s + H[i]; s = s + H[i];
} }
Hm = s/H.size(); //Altura media Hm = s/H.size(); //Altura media
t=t+1; //Tiempo t=t+1; //Tiempo
double sm = Hm; double sm = Hm;
double ss = 0; double ss = 0;
for(int i = 0; i < H.size(); i++){ for(int i = 0; i < H.size(); i++){
ss=ss+(H[i]-Hm)*(H[i]-Hm); ss=ss+(H[i]-Hm)*(H[i]-Hm);
} }
W = sqrt(ss/H.size()); //Altura media W = sqrt(ss/H.size()); //Rugosidad
datos<<t<<","<<Hm<<","<<W; //Guardando datos datos<<t<<","<<Hm<<","<<W; //Guardando datos
datos<<endl; datos<<endl;
} }
datos.close(); datos.close();
``` ```
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Gráficas # Gráficas
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Importamos las librerias necesarias. Importamos las librerias necesarias.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
%matplotlib inline %matplotlib inline
import pandas as pd import pandas as pd
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import sys import sys
sys.path.append('../data-used/aleatoria.csv') sys.path.append('../data-used/aleatoria.csv')
sys.path.append('../data-used/vecino_mas_cercano.csv') sys.path.append('../data-used/vecino_mas_cercano.csv')
sys.path.append('../data-used/vecino_siguiente_mas_cercano.csv') sys.path.append('../data-used/vecino_siguiente_mas_cercano.csv')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Leemos los datos de cada deposición. Leemos los datos de cada deposición.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#deposicion aleatoria #deposicion aleatoria
data1 = pd.read_csv('../data-used/aleatoria.csv') data1 = pd.read_csv('../data-used/aleatoria.csv')
#deposicion vecino mas cercano #deposicion vecino mas cercano
data2 = pd.read_csv('../data-used/vecino_mas_cercano.csv') data2 = pd.read_csv('../data-used/vecino_mas_cercano.csv')
#deposicion vecino siguiente mas cercano #deposicion vecino siguiente mas cercano
data3 = pd.read_csv('../data-used/vecino_siguiente_mas_cercano.csv') data3 = pd.read_csv('../data-used/vecino_siguiente_mas_cercano.csv')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Guardamos los datos de altura media, rugosidad y tiempo para cada una de las deposiciones. Guardamos los datos de altura media, rugosidad y tiempo para cada una de las deposiciones.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#deposicion aleatoria #deposicion aleatoria
hm1= data1.iloc[:, 1] hm1= data1.iloc[:, 1]
w1= data1.iloc[:, 2] w1= data1.iloc[:, 2]
t1 = data1.iloc[:,0] t1 = data1.iloc[:,0]
#deposicion vecino mas cercano #deposicion vecino mas cercano
hm2 = data2.iloc[:, 1] hm2 = data2.iloc[:, 1]
w2= data2.iloc[:, 2] w2= data2.iloc[:, 2]
t2 = data2.iloc[:,0] t2 = data2.iloc[:,0]
#deposicion vecino siguiente mas cercano #deposicion vecino siguiente mas cercano
hm3 = data3.iloc[:, 1] hm3 = data3.iloc[:, 1]
w3= data3.iloc[:, 2] w3= data3.iloc[:, 2]
t3 = data3.iloc[:,0] t3 = data3.iloc[:,0]
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Altura media vs Tiempo ### Altura media vs Tiempo
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Con los datos anteriores, graficamos la altura media vs tiempo para cada una de las deposiciones. Con los datos anteriores, graficamos la altura media vs tiempo para cada una de las deposiciones.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
#### Deposición aleatoria #### Deposición aleatoria
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
fig = plt.figure(figsize = (10,7)) fig = plt.figure(figsize = (10,7))
plt.subplot(111) plt.subplot(111)
#Título y ejes #Título y ejes
plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15') plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15')
plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15') plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15')
plt.title('Deposicion aleatoria \n Altura media vs tiempo', color = 'darkred', family = 'serif', size = '20') plt.title('Deposicion aleatoria \n Altura media vs tiempo', color = 'darkred', family = 'serif', size = '20')
#Gráfica para todos los datos #Gráfica para todos los datos
plt.scatter(t1, hm1, c = 'black', marker='.') plt.scatter(t1, hm1, c = 'black', marker='.')
plt.show() plt.show()
``` ```
%% Output %% Output
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
#### Deposición vecino mas cercano #### Deposición vecino mas cercano
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
fig = plt.figure(figsize = (10,7)) fig = plt.figure(figsize = (10,7))
plt.subplot(111) plt.subplot(111)
#plt.yscale('symlog') #Escala logaritmica en el eje de luminosidades para visualizar mejor #plt.yscale('symlog') #Escala logaritmica en el eje de luminosidades para visualizar mejor
#Título y ejes #Título y ejes
plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15') plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15')
plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15') plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15')
plt.title('Deposicion vecino mas cercano \n Altura media vs tiempo', color = 'darkred', family = 'serif', size = '20') plt.title('Deposicion vecino mas cercano \n Altura media vs tiempo', color = 'darkred', family = 'serif', size = '20')
#Gráfica para todos los datos #Gráfica para todos los datos
plt.scatter(t2, hm2, c = 'blue', marker='.') plt.scatter(t2, hm2, c = 'blue', marker='.')
plt.show() plt.show()
``` ```
%% Output %% Output
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
#### Deposición vecino siguiente mas cercano #### Deposición vecino siguiente mas cercano
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
fig = plt.figure(figsize = (10,7)) fig = plt.figure(figsize = (10,7))
plt.subplot(111) plt.subplot(111)
#plt.yscale('symlog') #Escala logaritmica en el eje de luminosidades para visualizar mejor #plt.yscale('symlog') #Escala logaritmica en el eje de luminosidades para visualizar mejor
#Título y ejes #Título y ejes
plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15') plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15')
plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15') plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15')
plt.title('Deposicion vecino siguiente mas cercano \n Altura media vs tiempo', color = 'darkred', family = 'serif', size = '20') plt.title('Deposicion vecino siguiente mas cercano \n Altura media vs tiempo', color = 'darkred', family = 'serif', size = '20')
#Gráfica para todos los datos #Gráfica para todos los datos
plt.scatter( t3, hm3, c = 'red', marker='.') plt.scatter( t3, hm3, c = 'red', marker='.')
plt.show() plt.show()
``` ```
%% Output %% Output
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
#### Todas las deposiciones #### Todas las deposiciones
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
fig = plt.figure(figsize = (10,7)) fig = plt.figure(figsize = (10,7))
plt.subplot(111) plt.subplot(111)
#plt.yscale('symlog') #Escala logaritmica en el eje de luminosidades para visualizar mejor #plt.yscale('symlog') #Escala logaritmica en el eje de luminosidades para visualizar mejor
#Título y ejes #Título y ejes
plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15') plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15')
plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15') plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15')
plt.title('Deposiciones \n Altura media vs tiempo', color = 'darkred', family = 'serif', size = '20') plt.title('Deposiciones \n Altura media vs tiempo', color = 'darkred', family = 'serif', size = '20')
#Gráfica para todos los datos #Gráfica para todos los datos
plt.scatter(t1, hm1, c = 'black', marker='.') plt.scatter(t1, hm1, c = 'black', marker='.')
plt.scatter(t2, hm2, c = 'blue', marker='.') plt.scatter(t2, hm2, c = 'blue', marker='.')
plt.scatter(t3, hm3, c = 'red', marker='.') plt.scatter(t3, hm3, c = 'red', marker='.')
plt.show() plt.show()
``` ```
%% Output %% Output
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Rugosidad vs Tiempo ### Rugosidad vs Tiempo
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Con los datos anteriores, graficamos la rugosidad vs tiempo para cada una de las deposiciones. Con los datos anteriores, graficamos la rugosidad vs tiempo para cada una de las deposiciones.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
#### Deposicion aleatoria #### Deposición aleatoria
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
fig = plt.figure(figsize = (10,7)) fig = plt.figure(figsize = (10,7))
plt.subplot(111) plt.subplot(111)
plt.yscale('symlog') #Escala logaritmica en el eje para visualizar mejor plt.yscale('symlog') #Escala logaritmica en el eje para visualizar mejor
plt.xscale('symlog') #Escala logaritmica en el eje para visualizar mejor plt.xscale('symlog') #Escala logaritmica en el eje para visualizar mejor
#Título y ejes #Título y ejes
plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15') plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15')
plt.ylabel('Rugosidad', color = 'black', family = 'serif', size = '15') plt.ylabel('Rugosidad', color = 'black', family = 'serif', size = '15')
plt.title('Deposicion aleatoria \n Rugosidad vs tiempo', color = 'darkred', family = 'serif', size = '20') plt.title('Deposicion aleatoria \n Rugosidad vs tiempo', color = 'darkred', family = 'serif', size = '20')
#Gráfica para todos los datos #Gráfica para todos los datos
plt.scatter(t1, w1, c = 'black', marker='.') plt.scatter(t1, w1, c = 'black', marker='.')
plt.show() plt.show()
``` ```
%% Output %% Output
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
#### Deposicion vecino mas cercano #### Deposición vecino mas cercano
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
fig = plt.figure(figsize = (10,7)) fig = plt.figure(figsize = (10,7))
plt.subplot(111) plt.subplot(111)
plt.yscale('symlog') #Escala logaritmica para visualizar mejor plt.yscale('symlog') #Escala logaritmica para visualizar mejor
plt.xscale('symlog') #Escala logaritmica para visualizar mejor plt.xscale('symlog') #Escala logaritmica para visualizar mejor
#Título y ejes #Título y ejes
plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15') plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15')
plt.ylabel('Rugosidad', color = 'black', family = 'serif', size = '15') plt.ylabel('Rugosidad', color = 'black', family = 'serif', size = '15')
plt.title('Deposicion vecino mas cercano \n Rugosidad vs tiempo', color = 'darkred', family = 'serif', size = '20') plt.title('Deposicion vecino mas cercano \n Rugosidad vs tiempo', color = 'darkred', family = 'serif', size = '20')
#Gráfica para todos los datos #Gráfica para todos los datos
plt.scatter(t2, w2, c = 'blue', marker='.') plt.scatter(t2, w2, c = 'blue', marker='.')
plt.show() plt.show()
``` ```
%% Output %% Output
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
#### Deposicion vecino siguiente mas cercano #### Deposición vecino siguiente mas cercano
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
fig = plt.figure(figsize = (10,7)) fig = plt.figure(figsize = (10,7))
plt.subplot(111) plt.subplot(111)
plt.yscale('symlog') #Escala logaritmica para visualizar mejor plt.yscale('symlog') #Escala logaritmica para visualizar mejor
plt.xscale('symlog') #Escala logaritmica para visualizar mejor plt.xscale('symlog') #Escala logaritmica para visualizar mejor
#Título y ejes #Título y ejes
plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15') plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15')
plt.ylabel('Rugosidad', color = 'black', family = 'serif', size = '15') plt.ylabel('Rugosidad', color = 'black', family = 'serif', size = '15')
plt.title('Deposicion vecino siguiente mas cercano \n Rugosidad vs tiempo', color = 'darkred', family = 'serif', size = '20') plt.title('Deposicion vecino siguiente mas cercano \n Rugosidad vs tiempo', color = 'darkred', family = 'serif', size = '20')
#Gráfica para todos los datos #Gráfica para todos los datos
plt.scatter(t3, w3, c = 'red', marker='.') plt.scatter(t3, w3, c = 'red', marker='.')
plt.show() plt.show()
``` ```
%% Output %% Output
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
#### Todas las deposiciones #### Todas las deposiciones
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
fig = plt.figure(figsize = (10,7)) fig = plt.figure(figsize = (10,7))
plt.subplot(111) plt.subplot(111)
plt.yscale('symlog') #Escala logaritmica para visualizar mejor plt.yscale('symlog') #Escala logaritmica para visualizar mejor
plt.xscale('symlog') #Escala logaritmica para visualizar mejor plt.xscale('symlog') #Escala logaritmica para visualizar mejor
#Título y ejes #Título y ejes
plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15') plt.xlabel('Tiempo', color = 'black', family = 'serif', size = '15')
plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15') plt.ylabel('Altura media', color = 'black', family = 'serif', size = '15')
plt.title('Deposiciones \n Rugosidad vs tiempo', color = 'darkred', family = 'serif', size = '20') plt.title('Deposiciones \n Rugosidad vs tiempo', color = 'darkred', family = 'serif', size = '20')
#Gráfica para todos los datos #Gráfica para todos los datos
plt.scatter(t1, w1, c = 'black', marker='.') plt.scatter(t1, w1, c = 'black', marker='.')
plt.scatter(t2, w2, c = 'blue', marker='.') plt.scatter(t2, w2, c = 'blue', marker='.')
plt.scatter(t3, w3, c = 'red', marker='.') plt.scatter(t3, w3, c = 'red', marker='.')
plt.show() plt.show()
``` ```
%% Output %% Output
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Deposición vecino más cercano # Deposición vecino más cercano
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Inluimos las librerias necesarias. Inluimos las librerias necesarias.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
#include<iostream> #include<iostream>
#include<vector> #include<vector>
#include<stdlib.h> #include<stdlib.h>
#include<time.h> #include<time.h>
#include<fstream> #include<fstream>
#include <math.h> #include <math.h>
using namespace std; using namespace std;
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Definimos la longitud del espacio en donde caerán las partículas y el número de partículas. Definimos la longitud del espacio en donde caerán las partículas y el número de partículas.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
int L,P; int L,P;
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
L = 100; //Longitud del espacio L = 100; //Longitud del espacio
P = 1000000; //Número de partículas P = 1000000; //Número de partículas
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Creamos un vector que va a contener las alturas de las partículas. Creamos un vector que va a contener las alturas de las partículas.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
vector<int> H(L,0); vector<int> H(L,0);
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Definimos las variables Tiempo, Altura media y Rugosidad. Definimos las variables Tiempo, Altura media y Rugosidad.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
int t=0; //Tiempo int t=0; //Tiempo
double Hm; //Altura media double Hm; //Altura media
double W; //Rugosidad double W; //Rugosidad
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Creamos un archivo para guardar los datos. Creamos un archivo para guardar los datos.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
//Archivo que va a guardar los datos //Archivo que va a guardar los datos
ofstream datos("vecino_mas_cercano.csv"); ofstream datos("vecino_mas_cercano.csv");
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Procedemos a llenar el vector de alturas definido anteriormente, generando un número aleatorio (𝑙) entre 0 y 𝐿−1 para que represente la posición en donde va a caer la partícula, luego hacemos llenamos el vector de alturas tomando en cuenta como es la deposición vecino más cercano, así hacemos para cada partícula hasta llenar el vector de alturas. En el procedimiento se va calculando la altura media y rugosidad y el tiempo, y estos valores se guardan en el archivo vecino_mas_cercano.csv. Procedemos a llenar el vector de alturas definido anteriormente, generando un número aleatorio (𝑙) entre 0 y 𝐿−1 para que represente la posición en donde va a caer la partícula, luego hacemos llenamos el vector de alturas tomando en cuenta como es la deposición vecino más cercano, así hacemos para cada partícula hasta llenar el vector de alturas. En el procedimiento se va calculando la altura media y rugosidad y el tiempo, y estos valores se guardan en el archivo vecino_mas_cercano.csv.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
//Para cada particula} //Para cada particula}
srand(time(NULL)); srand(time(NULL));
for(int i=1;i<=P;i++){ for(int i=1;i<=P;i++){
int l=rand()%(L); int l=rand()%(L);
if(l==0){ if(l==0){
int m; int m;
if(H[l]>H[l+1]) m = H[l]; if(H[l]>H[l+1]) m = H[l];
else m = H[l+1]; else m = H[l+1];
if(m==H[l]) H[l]=H[l]+1; if(m==H[l]) H[l]=H[l]+1;
else H[l]=m; else H[l]=m;
} }
else if(l==L-1){ else if(l==L-1){
int m; int m;
if (H[l]>H[l-1]) m = H[l]; if (H[l]>H[l-1]) m = H[l];
else m = H[l-1]; else m = H[l-1];
if(m==H[l]) H[l]=H[l]+1; if(m==H[l]) H[l]=H[l]+1;
else H[l]=m; else H[l]=m;
} }
else { else {
int m; int m;
if(H[l]>H[l-1] && H[l]>H[l+1]) m = H[l]; if(H[l]>H[l-1] && H[l]>H[l+1]) m = H[l];
else if(H[l-1]>H[l] && H[l-1]>H[l+1]) m = H[l-1]; else if(H[l-1]>H[l] && H[l-1]>H[l+1]) m = H[l-1];
else if(H[l+1]>H[l] && H[l+1]>H[l-1]) m = H[l+1]; else if(H[l+1]>H[l] && H[l+1]>H[l-1]) m = H[l+1];
else if(H[l]==H[l-1] && H[l+1]<H[l]) m = H[l]; else if(H[l]==H[l-1] && H[l+1]<H[l]) m = H[l];
else if(H[l]==H[l+1] && H[l-1]<H[l]) m = H[l]; else if(H[l]==H[l+1] && H[l-1]<H[l]) m = H[l];
else m = H[l]; else m = H[l];
if(m==H[l]) H[l]=H[l]+1; if(m==H[l]) H[l]=H[l]+1;
else H[l]=m; else H[l]=m;
} }
double s = 0; double s = 0;
for (int i = 0; i < H.size(); i++){ for (int i = 0; i < H.size(); i++){
s = s + H[i]; s = s + H[i];
} }
Hm = s/H.size(); //Altura media Hm = s/H.size(); //Altura media
t=t+1; //Tiempo t=t+1; //Tiempo
double sm = Hm; double sm = Hm;
double ss = 0; double ss = 0;
for(int i = 0; i < H.size(); i++){ for(int i = 0; i < H.size(); i++){
ss=ss+(H[i]-Hm)*(H[i]-Hm); ss=ss+(H[i]-Hm)*(H[i]-Hm);
} }
W = sqrt(ss/H.size()); //Altura media W = sqrt(ss/H.size()); //Rugosidad
datos<<t<<","<<Hm<<","<<W; //Guardando datos datos<<t<<","<<Hm<<","<<W; //Guardando datos
datos<<endl; datos<<endl;
} }
datos.close(); datos.close();
``` ```
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Deposición vecino siguiente más cercano # Deposición vecino siguiente más cercano
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Inluimos las librerias necesarias. Inluimos las librerias necesarias.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
#include<iostream> #include<iostream>
#include<vector> #include<vector>
#include<stdlib.h> #include<stdlib.h>
#include<time.h> #include<time.h>
#include<fstream> #include<fstream>
#include <math.h> #include <math.h>
using namespace std; using namespace std;
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Definimos la longitud del espacio en donde caerán las partículas y el número de partículas. Definimos la longitud del espacio en donde caerán las partículas y el número de partículas.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
int L,P; int L,P;
L = 100; //Longitud del espacio L = 100; //Longitud del espacio
P = 1000000; //Numero de particulas P = 1000000; //Numero de particulas
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Creamos un vector que va a contener las alturas de las partículas. Creamos un vector que va a contener las alturas de las partículas.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
vector<int> H(L,0); vector<int> H(L,0);
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Definimos las variables Tiempo, Altura media y Rugosidad. Definimos las variables Tiempo, Altura media y Rugosidad.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
int t=0; //Tiempo int t=0; //Tiempo
double Hm; //Altura media double Hm; //Altura media
double W; //Rugosidad double W; //Rugosidad
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Creamos un archivo para guardar los datos. Creamos un archivo para guardar los datos.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
//Archivo que va a guardar los datos //Archivo que va a guardar los datos
ofstream datos("vecino_siguiente_mas_cercano.csv"); ofstream datos("vecino_siguiente_mas_cercano.csv");
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Procedemos a llenar el vector de alturas definido anteriormente, generando un número aleatorio (𝑙) entre 0 y 𝐿−1 para que represente la posición en donde va a caer la partícula, luego hacemos llenamos el vector de alturas tomando en cuenta como es la deposición vecino siguiente más cercano, así hacemos para cada partícula hasta llenar el vector de alturas. En el procedimiento se va calculando la altura media y rugosidad y el tiempo, y estos valores se guardan en el archivo vecino_siguiente_mas_cercano.csv. Procedemos a llenar el vector de alturas definido anteriormente, generando un número aleatorio (𝑙) entre 0 y 𝐿−1 para que represente la posición en donde va a caer la partícula, luego hacemos llenamos el vector de alturas tomando en cuenta como es la deposición vecino siguiente más cercano, así hacemos para cada partícula hasta llenar el vector de alturas. En el procedimiento se va calculando la altura media y rugosidad y el tiempo, y estos valores se guardan en el archivo vecino_siguiente_mas_cercano.csv.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` c++ ``` c++
//Para cada particula} //Para cada particula}
srand(time(NULL)); srand(time(NULL));
for(int i=1;i<=P;i++){ for(int i=1;i<=P;i++){
int l=rand()%(L); int l=rand()%(L);
if(l==0){ if(l==0){
int m; int m;
if(H[l]>H[l+1]) m = H[l]; if(H[l]>H[l+1]) m = H[l];
else m = H[l+1]; else m = H[l+1];
if(m==H[l]) H[l]=H[l]+1; if(m==H[l]) H[l]=H[l]+1;
else H[l]=m + 1; else H[l]=m + 1;
} }
else if(l==L-1){ else if(l==L-1){
int m; int m;
if (H[l]>H[l-1]) m = H[l]; if (H[l]>H[l-1]) m = H[l];
else m = H[l-1]; else m = H[l-1];
if(m==H[l]) H[l]=H[l]+1; if(m==H[l]) H[l]=H[l]+1;
else H[l]=m + 1; else H[l]=m + 1;
} }
else { else {
int m; int m;
if(H[l]>H[l-1] && H[l]>H[l+1]) m = H[l]; if(H[l]>H[l-1] && H[l]>H[l+1]) m = H[l];
else if(H[l-1]>H[l] && H[l-1]>H[l+1]) m = H[l-1]; else if(H[l-1]>H[l] && H[l-1]>H[l+1]) m = H[l-1];
else if(H[l+1]>H[l] && H[l+1]>H[l-1]) m = H[l+1]; else if(H[l+1]>H[l] && H[l+1]>H[l-1]) m = H[l+1];
else if(H[l]==H[l-1] && H[l+1]<H[l]) m = H[l]; else if(H[l]==H[l-1] && H[l+1]<H[l]) m = H[l];
else if(H[l]==H[l+1] && H[l-1]<H[l]) m = H[l]; else if(H[l]==H[l+1] && H[l-1]<H[l]) m = H[l];
else m = H[l]; else m = H[l];
if(m==H[l]) H[l]=H[l]+1; if(m==H[l]) H[l]=H[l]+1;
else H[l]=m + 1; else H[l]=m + 1;
} }
double s = 0; double s = 0;
for (int i = 0; i < H.size(); i++){ for (int i = 0; i < H.size(); i++){
s = s + H[i]; s = s + H[i];
} }
Hm = s/H.size(); //Altura media Hm = s/H.size(); //Altura media
t=t+1; //Tiempo t=t+1; //Tiempo
double sm = Hm; double sm = Hm;
double ss = 0; double ss = 0;
for(int i = 0; i < H.size(); i++){ for(int i = 0; i < H.size(); i++){
ss=ss+(H[i]-Hm)*(H[i]-Hm); ss=ss+(H[i]-Hm)*(H[i]-Hm);
} }
W = sqrt(ss/H.size()); //Altura media W = sqrt(ss/H.size()); //Rugosidad
datos<<t<<","<<Hm<<","<<W; //Guardando datos datos<<t<<","<<Hm<<","<<W; //Guardando datos
datos<<endl; datos<<endl;
} }
datos.close(); datos.close();
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment