# Makefile for compiling and managing MCT code for modulated liquids in Cartesian coordinates.
# Tested on Ubuntu 18.04-22.04.

# Variables
mkdir = mkdir -p # Command to create directories (with -p to avoid errors if the directory already exists)
MY_PATH = pwd    # Command to get the current working directory
# echo MY_PATH    # Uncomment this line to print the current working directory

CC = gcc         # Compiler to be used (GNU Compiler Collection)
N = 40           # Number of grid points
PF = 0.549779    # Packing fraction
Rho = 0.7        # Number density of the hard disks
Lnum = 109       # Number of full periods in the modulation direction
Lx = 120         # Length of the simulation box
iniChi = 4.0     # Initial value of Chi parameter
iniChi0 = 0.0    # Initial value of Chi0 parameter for minimum value of chi
qmax = 39.6      # Maximum value of q (wave vector)

# Compiler flags
CFLAGS += -O2 -lm -Wall # Flags for normal compilation (optimization, math library, and warnings)
CFLAGS_PARA += -O2 -lm -fopenmp # Flags for parallel compilation (OpenMP support)

# Parameters for final modulated liquid to find the critical X
FMODU_PHI_CX_OPTP += -DRHO=$(Rho) -DV=$(PF) -DQ=1 -DLnumber=$(Lnum) -DqxMAX=$(qmax) -Dini_chi=$(iniChi) -Dini_chi0=$(iniChi0)

# Print the value of Lnum (can be used for debugging)
$(echo $Lnum)

# Targets

# Compile function for modulated liquid in Cartesian coordinates for critical X
2cx_fmodu : MMCT_2D.c para.c funcs.c
	$(mkdir) ./$(Lnum) ./$(Lnum)/data # Create directories for output files
	$(CC) -o ./$(Lnum)/2cx_fmodu $(FMODU_PHI_CX_OPTP) MMCT_2D.c para.c funcs.c $(CFLAGS_PARA) # Compile the code with parallel flags

# Cleaning Functions

# Clean function to remove compiled files
clean:
	$(RM) -rf ./$(N)

# Clean function to delete data files
clean_data:
	$(RM) ./$(N)/data/*
