# default parameter values of a desired mesh

# displacement of ampoule in m
h = 0.2485

# height of (melted) PbCl2 charge
H = 0.0800

# max area of element in m^2 in respective regions
a1 = 0.0001
a2 = 0.0001
a3 = 0.0001
a4 = 0.0001
a5 = 0.0001

# minimal angle in triangle in degrees, scientific format can't be used!
theta = 34

# poly file with unparsed parameter h and processing script
mhdata   = $(srcdir)/mh.poly
mhscript = $(srcdir)/poly_parser.py

# input dir and output dirs 
srcdir  = .
meshdir = ./mesh

# filenames
meshbase = $(meshdir)/m_$(h)_$(H)_$(a1)_$(a2)_$(a3)_$(a4)_$(a5)

.PHONY : all MESH clean

# This is workaround to bug http://savannah.gnu.org/bugs/index.php?32042
.INTERMEDIATE : $(meshbase).node $(meshbase).edge

all : MESH

MESH : $(meshbase).xml.gz $(meshbase).attr0.xml.gz

%.xml.gz %.attr0.xml.gz : %.ele %.node %.edge
	dolfin-convert $*.ele $*.xml
	gzip -f $*.xml $*.attr0.xml

%.ele %.node %.edge : %.poly
	triangle -pIq$(theta)eAa $<

$(meshbase).poly : $(mhdata) $(mhscript) | $(meshdir)
	python $(mhscript) $< $@ $(h) $(H) $(a1) $(a2) $(a3) $(a4) $(a5)

$(meshdir) : 
	mkdir $@

clean : 
	rm -rf $(meshdir)

