xref: /libCEED/examples/solids/Makefile (revision 1a8516d00062e8132c3db0515cc9f5fa064f6664)
1# Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and other CEED contributors.
2# All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# This file is part of CEED:  http://github.com/ceed
7
8COMMON ?= ../../common.mk
9-include $(COMMON)
10
11# Note: PETSC_ARCH can be undefined or empty for installations which do not use
12#       PETSC_ARCH - for example when using PETSc installed through Spack.
13PETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc
14CEED_DIR ?= ../..
15ceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc
16
17CC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc))
18CFLAGS = -std=c11 \
19  $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
20  $(call pkgconf, --cflags-only-other $(PETSc.pc)) \
21  $(OPT)
22CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \
23  $(call pkgconf, --variable=cflags_dep $(PETSc.pc))
24LDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc))
25LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc)))
26LDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm
27
28OBJDIR := build
29SRCDIR := src
30PROBLEMDIR := problems
31
32src.c := elasticity.c $(sort $(wildcard $(PROBLEMDIR)/*.c)) $(sort $(wildcard $(SRCDIR)/*.c))
33src.o = $(src.c:%.c=$(OBJDIR)/%.o)
34
35all: elasticity
36
37elasticity: $(src.o) | $(PETSc.pc) $(ceed.pc)
38	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
39
40.SECONDEXPANSION: # to expand $$(@D)/.DIR
41%/.DIR :
42	@mkdir -p $(@D)
43	@touch $@
44
45# Quiet, color output
46quiet ?= $($(1))
47
48$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
49	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
50
51# Rules for building the examples
52#%: %.c
53
54print: $(PETSc.pc) $(ceed.pc)
55	$(info CC      : $(CC))
56	$(info CFLAGS  : $(CFLAGS))
57	$(info CPPFLAGS: $(CPPFLAGS))
58	$(info LDFLAGS : $(LDFLAGS))
59	$(info LDLIBS  : $(LDLIBS))
60	@true
61
62clean:
63	$(RM) -r $(OBJDIR) elasticity *.vtu
64
65$(PETSc.pc):
66	$(if $(wildcard $@),,$(error \
67	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
68
69.PHONY: all print clean
70
71pkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
72
73# E = 2 * mu + (1 + nu)
74tests-output/NH-strain.csv: args = -problem FSInitial-NH1 -E 2.8 -nu 0.4
75tests-output/MR-strain.csv: args = -problem FSInitial-MR1 -mu_1 1 -mu_2 0.0 -nu .4
76tests-output/MR-strain1.csv: args = -problem FSInitial-MR1 -mu_1 .5 -mu_2 0.5 -nu .4
77
78tests-output/%.csv: elasticity
79	./$<  $(args) -degree 2 -dm_plex_box_faces 3,3,3 -num_steps 15 -bc_clamp 6 -bc_traction 5 -bc_traction_5 0,0,-1 -snes_converged_reason -snes_linesearch_atol 1e-30 -strain_energy_monitor $@
80
81-include $(src.o:%.o=%.d)
82