########################################################################
#   Sample ALBERTA Makefile for DIM_OF_WORLD = 3                       #
########################################################################
.PHONY: all

PROGS = \
 ellipt nonlin heat \
 ellipt-periodic \
 ellipt-isoparam ellipt-moebius ellipt-torus ellipt-sphere \
 stokes quasi-stokes quasi-stokes-slip \
 ellipt2 ellipt-dg

all: $(PROGS)

DEFAULT = ellipt

prefix = /usr/local
exec_prefix = ${prefix}

# delete line, if the paths are environment variables
ALBERTA_INCLUDE_PATH = ${prefix}/include/alberta
ALBERTA_LIB_PATH = ${exec_prefix}/lib
ALBERTA_LIBEXEC_PATH = ${exec_prefix}/libexec/alberta-3.0.3

# compile flags
#
# run make with "make DEBUG=1" to get debuggable code
#
ifeq ($(DEBUG),1)
CFLAGS = -pipe -O2 -isystem /usr/local/include -fno-strict-aliasing  -O0 -ggdb3 -fno-inline -fno-builtin 
ALBERTA_DEBUG = 1
LIBALBAS = albas_$(DIM_OF_WORLD)d_debug
else
CFLAGS = -pipe -O2 -isystem /usr/local/include -fno-strict-aliasing  
ALBERTA_DEBUG = 0
LIBALBAS = albas_$(DIM_OF_WORLD)d
endif
FFLAGS = 

# link flags (use "-shared" or "-static" to specify ALBERTA library type)
# Default type is "-shared", if the configuration permits it.
# Use "-all-static" to create a standalone, truly static binary.

LDFLAGS =  -lXm -lXt -pthread -Wl,-rpath=/usr/local/lib/gcc11  -L/usr/local/lib/gcc11 -L/usr/local/lib 

# uncomment line for using the debug library
#DEBUG = 1

include $(ALBERTA_LIBEXEC_PATH)/Makefile.alberta

########################################################################
# DFLAGS: DIM_OF_WORLD
########################################################################

DIM_OF_WORLD = 3

########################################################################
# set virtual path
########################################################################
VPATH = ./:../Common

########################################################################
# and now the applications
########################################################################

# small support library for graphics and command-line parsing
libdemo.a: libdemo.a(cmdline.o graphics.o geomview-graphics.o)
	/usr/local/bin/ranlib $@
libdemo.a(cmdline.o graphics.o geomview-graphics.o): alberta-demo.h

# the classical Poisson demo-program
ELLIPT_OFILES = ellipt.o libdemo.a

ellipt: $(ELLIPT_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(ELLIPT_OFILES) $(LIBS)

# the classical non-linear elliptic test problem
NONLIN_OFILES = nonlin.o nlprob.o nlsolve.o libdemo.a
$(NONLIN_OFILES): nonlin.h

nonlin: $(NONLIN_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(NONLIN_OFILES) $(LIBS)

# the classical heat test-problem
HEAT_OFILES = heat.o libdemo.a
heat: $(HEAT_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(HEAT_OFILES) $(LIBS)

# test program for periodic meshes (torus and Klein's bottle)
ELLIPT_PERIODIC_OFILES = ellipt-periodic.o libdemo.a

ellipt-periodic: $(ELLIPT_PERIODIC_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(ELLIPT_PERIODIC_OFILES) $(LIBS)

# test program for sub-meshes
ELLIPT2_OFILES = ellipt2.o libdemo.a

ellipt2: $(ELLIPT2_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(ELLIPT2_OFILES) $(LIBS)

# test-program for iso-parametric boundary approximation of degree up to 4
ELLIPT_ISOPARAM_OFILES = ellipt-isoparam.o libdemo.a

ellipt-isoparam: $(ELLIPT_ISOPARAM_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(ELLIPT_ISOPARAM_OFILES) $(LIBS)

# test-program for a sphere with co-dimension 1, i.e. S^2
ELLIPT_SPHERE_OFILES = ellipt-sphere.o libdemo.a

ellipt-sphere: $(ELLIPT_SPHERE_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(ELLIPT_SPHERE_OFILES) $(LIBS)

# test-program for an embedded 2-torus with co-dimension 1
ELLIPT_TORUS_OFILES = ellipt-torus.o libdemo.a

ellipt-torus: $(ELLIPT_TORUS_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(ELLIPT_TORUS_OFILES) $(LIBS)

# test-program for non-orientable 2d meshes
ELLIPT_MOEBIUS_OFILES = ellipt-moebius.o libdemo.a

ellipt-moebius :$(ELLIPT_MOEBIUS_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(ELLIPT_MOEBIUS_OFILES) $(LIBS)

# Stokes test-problem, to exercise the oem_sp_solve_ds() frame-work
# and the new extendable error-estimator interface
STOKES_OFILES = stokes.o libdemo.a

stokes: $(STOKES_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(STOKES_OFILES) $(LIBS) -l$(LIBALBAS) $(LIBS)

# Quasi-Stokes test-problem with stress boundary-conditions.
#
# This is a test-case for the following features:
# - oem_sp_solve_ds() saddle-point solver interface
# - DOW x DOW block-matrices
# - Robin-boundary conditions (and hence a test for the boundary
#   operator framework)
# - extendable error estimators
QUASI_STOKES_OFILES = quasi-stokes.o libdemo.a

quasi-stokes: $(QUASI_STOKES_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(QUASI_STOKES_OFILES) $(LIBS) -l$(LIBALBAS) $(LIBS)

# Quasi-Stokes test-problem with slip boundary-conditions.
#
# This is a test-case for the following features:
# - oem_sp_solve_ds() saddle-point solver interface
# - DOW x DOW block-matrices
# - Robin-boundary conditions (and hence a test for the boundary
#   operator framework)
# - extendable error estimators
# - saddle-point problems with more than one constaint, here we have
#   the pressure for the divergence and the normal stresses for the
#   slip boundary conditions.
#
QUASI_STOKES_SLIP_OFILES = quasi-stokes-slip.o libdemo.a

quasi-stokes-slip: $(QUASI_STOKES_SLIP_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(QUASI_STOKES_SLIP_OFILES) $(LIBS) -l$(LIBALBAS) $(LIBS)

# the classical Poisson demo-program, this time with a simplistic
# discontinuous Galerkin implementation.
ELLIPT_DG_OFILES = ellipt-dg.o libdemo.a

ellipt-dg: $(ELLIPT_DG_OFILES) $(ALBERTA_INCLUDE_PATH)/alberta.h
	$(LINK) $(ELLIPT_DG_OFILES) $(LIBS)

################################################################################

.PHONY: clean realclean new

clean: albertaclean
	-rm -f $(PROGS) libdemo.a

realclean: clean albertarealclean

new: albertanew
