CXXFLAGS += -O3 -ffast-math -std=c++23 -Wall -I../matrix -I../evd
LDLIBS += -lstdc++ -lm

all:Psi.svg E0.rmax.svg E1.rmax.svg E0.dr.svg

E0.rmax.svg:out.E0.rmax.txt Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set title "Hydrogen, matrix, E_0 convergence with r_{max}";\
	set xlabel "r_{max}, Bohr radius";\
	set ylabel "E_{0}, Hartree";\
	plot [][-0.6:]\
	 "$<" using 1:3 with linespoints pointtype 5 title "calculated"\
	,-0.5 with lines title "exact"\
	'|gnuplot

E1.rmax.svg:out.E1.rmax.txt Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set title "Hydrogen, matrix, E_1 convergence with r_{max}";\
	set xlabel "r_{max}, Bohr radius";\
	set ylabel "E_{1}, Hartree";\
	plot []\
	 "$<" using 1:4 with linespoints pointtype 5 title "calculated"\
	,-0.125 with lines title "exact"\
	'|gnuplot

E0.dr.svg:out.E0.dr.txt Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set title "Hydrogen, matrix, E_0 convergence with dr";\
	set xlabel "dr, Bohr radius";\
	set ylabel "E_{0}, Hartree";\
	set key left;\
	plot []\
	 "$<" using 2:3 with linespoints pointtype 5 title "calculated"\
	,-0.5 with lines title "exact (-0.5 Hartree)"\
	'|gnuplot

out.E0.dr.txt: main
	>$@
	for dr in 0.05 0.1 0.15 0.2 0.25 0.3; do \
	echo $$dr; ./main -rmax 6 -dr $$dr 1>/dev/null 2>>$@ \
	; done

out.E1.rmax.txt: main
	>$@
	for R in 7 8 9 10 11 12 13; do \
	echo $$R; ./main -rmax $$R -dr 0.1 1>/dev/null 2>>$@ \
	; done

out.E0.rmax.txt: main
	>$@
	for R in 2 3 4 5 6; do \
	./main -rmax $$R -dr 0.1 1>/dev/null 2>>$@ \
	; done

Psi.svg:out.data.txt Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set xlabel "r, Bohr radius";\
	set ylabel "f(r), arb. u.";\
	set title "Hydrogen atom ground state radial wave-function";\
	plot\
	 "$<" index 1 using 1:2 with points pointtype 7 pointsize 0.5 title "calculated"\
	,"$<" index 1 using 1:3 with lines title "exact"\
	'| gnuplot

out.data.txt: main
	./$< > $@

main:main.o matrix.o jacobi.o
main.o: main.cc ../matrix/matrix.h ../evd/jacobi.h
matrix.o: ../matrix/matrix.cc ../matrix/matrix.h
	$(CXX) $(CXXFLAGS) -c -o $@ $<
jacobi.o: ../evd/jacobi.cc ../evd/jacobi.h ../matrix/matrix.h
	$(CXX) $(CXXFLAGS) -c -o $@ $<

clean:
	$(RM) *.o main *.svg out*
