Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvachier committed Oct 28, 2023
1 parent 8d08bdd commit 2ad3600
Show file tree
Hide file tree
Showing 8 changed files with 625 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Author(s)
-[Jeremy Vachier](https://github.com/jvachier)
4 changes: 4 additions & 0 deletions .github/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Contributor(s)

## Main contributor(s)
-[Jeremy Vachier](https://github.com/jvachier)
9 changes: 9 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Describe your changes

## Issue ticket number and link

## Checklist before requesting a review
- [ ] I have performed a self-review of my code
- [ ] If it is a core feature, I have added thorough tests.
- [ ] Do we need to implement analytics?
- [ ] Will this be part of a product update? If yes, please write one phrase about this update.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Ignore Mac system files
.DS_store
.dSYM

# Ignore all csv files
*.csv

# Ignore all png files
*.png

# Ignore all text files
*.txt

# Ignore specific file
test.mp4

# Ignore all executable files
*.o
*.out

# Ignore jupyter checkpoints
*.ipynb_checkpoints
396 changes: 396 additions & 0 deletions LICENCE

Large diffs are not rendered by default.

Empty file added README.md
Empty file.
29 changes: 29 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CC = g++-13
CFLAGS = -Wall -g -fopenmp

abp_2D_confine: abp_2D_confine.o print_file.o reflective_boundary_conditions.o circular_reflective_boundary_conditions.o initialization.o update_position.o check_nooverlap.o
$(CC) $(CFLAGS) -o abp_2D_confine.out abp_2D_confine.o print_file.o reflective_boundary_conditions.o circular_reflective_boundary_conditions.o initialization.o update_position.o check_nooverlap.o

abp_2D_confine.o: abp_2D_confine.cpp
$(CC) -c abp_2D_confine.cpp

print_file.o: print_file.cpp
$(CC) -c print_file.cpp

reflective_boundary_conditions.o: reflective_boundary_conditions.cpp
$(CC) -c reflective_boundary_conditions.cpp

circular_reflective_boundary_conditions.o: circular_reflective_boundary_conditions.cpp
$(CC) -c circular_reflective_boundary_conditions.cpp

initialization.o: initialization.cpp
$(CC) -c initialization.cpp

update_position.o: update_position.cpp
$(CC) -c update_position.cpp

check_nooverlap.o: check_nooverlap.cpp
$(CC) -c check_nooverlap.cpp

clean:
rm *.o
163 changes: 163 additions & 0 deletions src/abp_3D_confine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Author: Jeremy Vachier
* Purpose: ABP 3D confine in a square using an Euler-Mayurama algorithm
* Language: C++
* Date: 2023
* Compilation line to use pragma: g++ name.cpp -fopenmp -o name.o (on mac run g++-12 ; 12 latest version obtain using brew list gcc)
* Compilation line to use pragma, simd (vectorization) and tuple: g++ -O3 -std=c++17 name.cpp -fopenmp -o name.o
*/

#include <iostream>
#include <random>
#include <cstring>
#include <stdio.h>
#include <cmath>
#include <time.h>
#include <omp.h> //import library to use pragma
#include <tuple> //to output multiple components of a function

#include "print_file.h"
#include "reflective_boundary_conditions.h"
#include "circular_reflective_boundary_conditions.h"
#include "initialization.h"
#include "update_position.h"
#include "check_nooverlap.h"

#define PI 3.141592653589793
#define N_thread 6

using namespace std;

int main(int argc, char *argv[])
{
// File
FILE *datacsv;
FILE *parameter;
parameter = fopen("parameter.txt", "r");
datacsv = fopen("./data/simulation.csv", "w");

// check if the file parameter is exist
if (parameter == NULL)
{
printf("no such file.");
return 0;
}

// read the parameters from the file
double epsilon, delta, Dt, De, vs;
double F, R, Wall;
int Particles;
char name[100];
char key1[] = "circular";
char key2[] = "squared";

bool flag = false;

printf("Select confinement geometry, either squared or circular:");
scanf("%s", &name);

while (flag == false)
{
if ((strcmp(name, key1) == 0) or (strcmp(name, key2) == 0))
{
flag = true;
}
else
{
printf("You have not selected the correct, please select again\n");
printf("Select confinement geometry, either squared or circular:");
scanf("%s", &name);
flag = false;
}
}
fscanf(parameter, "%lf\t%lf\t%d\t%lf\t%lf\t%lf\t%lf\n", &epsilon, &delta, &Particles, &Dt, &De, &vs, &Wall);
printf("%lf\t%lf\t%d\t%lf\t%lf\t%lf\t%lf\n", epsilon, delta, Particles, Dt, De, vs, Wall);

double *x = (double *)malloc(Particles * sizeof(double)); // x-position
double *y = (double *)malloc(Particles * sizeof(double)); // y-position

// parameters
const int N = 1E6; // number of iterations
const int L = 1.0; // particle size

// initialization of the random generator
random_device rdev;
default_random_engine generator(rdev()); // random seed -> rdev
// default_random_engine generator(1); //same seed

// Distributions Gaussian
normal_distribution<double> Gaussdistribution(0.0, 1.0);
// Distribution Uniform for initialization
uniform_real_distribution<double> distribution(-Wall, Wall);
// uniform_real_distribution<double> distribution_e(0.0,360.0*PI / 180.0); // directly in radian
uniform_real_distribution<double> distribution_e(0.0, 360.0);

double xi_px; // noise for x-position
double xi_py; // noise for y-position
double xi_e; // noise ortientation
double x_x; // used to initialize
double y_y; // used to initialize
int i, j, k;

double phi = 0.0;
double prefactor_e = sqrt(2.0 * delta * De);
double prefactor_xi_px = sqrt(2.0 * delta * Dt);
double prefactor_xi_py = sqrt(2.0 * delta * Dt);
double prefactor_interaction = epsilon * 48.0;
double r = 5.0 * L;

clock_t tStart = clock(); // check time for one trajectory

fprintf(datacsv, "Particles,x-position,y-position,time,%s\n", name);

// initialization position and activity
initialization(
x, y, Particles,
generator, distribution);

check_nooverlap(
x, y, Particles,
R, L,
generator, distribution);
printf("Initialization done.\n");

// Time evoultion
int time;
for (time = 0; time < N; time++)
{
update_position(
x, y, phi, prefactor_e, Particles,
delta, De, Dt, xi_e, xi_px,
xi_py, vs, prefactor_xi_px, prefactor_xi_py,
r, R, F, prefactor_interaction,
generator, Gaussdistribution, distribution_e);
if (strcmp(name, key1) == 0)
{
circular_reflective_boundary_conditions(
x, y, Particles,
Wall, L);
}
if (strcmp(name, key2) == 0)
{
reflective_boundary_conditions(
x, y, Particles,
Wall, L);
}

if (time % 100 == 0 && time >= 0)
{
print_file(
x, y,
Particles, time,
datacsv);
}
}

printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC); // time for one trajectory

free(x);
free(y);

fclose(datacsv);
return 0;
}

0 comments on commit 2ad3600

Please sign in to comment.