Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaMEM with FastScapeFortranLib #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions src/LaMEMLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include "phase_transition.h"
#include "passive_tracer.h"

// surface process
#include "fastscape.h"

//---------------------------------------------------------------------------
PetscErrorCode LaMEMLibMain(void *param,PetscLogStage stages[4])
{
Expand Down Expand Up @@ -504,6 +507,12 @@ PetscErrorCode LaMEMLibSetLinks(LaMEMLib *lm)
lm->fs.scal = &lm->scal;
// FreeSurf
lm->surf.jr = &lm->jr;
lm->surf.FSLib = &lm->FSLib;
// FastScape
lm->FSLib.surf = &lm->surf;
lm->FSLib.pvsurf= &lm->pvsurf;
lm->FSLib.jr = &lm->jr;
lm->FSLib.dbm = &lm->dbm;
// BCCtx
lm->bc.scal = &lm->scal;
lm->bc.ts = &lm->ts;
Expand Down Expand Up @@ -566,8 +575,6 @@ PetscErrorCode LaMEMLibSaveOutput(LaMEMLib *lm)
step = ts->istep;
bgPhase = lm->actx.bgPhase;



// create directory (encode current time & step number)
asprintf(&dirName, "Timestep_%1.8lld_%1.8e", (LLD)step, time);

Expand Down Expand Up @@ -652,7 +659,6 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param, PetscLogStage stages[4])

// initialize boundary constraint vectors
ierr = BCApply(&lm->bc); CHKERRQ(ierr);


// initialize temperature
ierr = JacResInitTemp(&lm->jr); CHKERRQ(ierr);
Expand Down Expand Up @@ -702,7 +708,8 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param, PetscLogStage stages[4])
// restart if fixed time step is larger than CFLMAX
if(restart) continue;

// advect free surface
// advect free surface // change the topography, controled by the surf_max_angle, when equal to 0.0,
// don't using the process
ierr = FreeSurfAdvect(&lm->surf); CHKERRQ(ierr);

// advect markers
Expand All @@ -719,18 +726,51 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param, PetscLogStage stages[4])

PetscCall(PetscLogStagePop()); /* Stop profiling stage*/

// apply erosion to the free surface
ierr = FreeSurfAppErosion(&lm->surf); CHKERRQ(ierr);
int SurfaceMode;
SurfaceMode = SURFACE; // SURFACE, default value = 1

FreeSurf *surfmode;
surfmode = &lm->surf;

// apply sedimentation to the free surface
ierr = FreeSurfAppSedimentation(&lm->surf); CHKERRQ(ierr);
if( 1 == SurfaceMode) // compile without FastScape
{
// PetscPrintf(PETSC_COMM_WORLD, "\nCalculating surface process through LaMEM code \n");
// apply erosion to the free surface
ierr = FreeSurfAppErosion(&lm->surf); CHKERRQ(ierr);

// apply sedimentation to the free surface
ierr = FreeSurfAppSedimentation(&lm->surf); CHKERRQ(ierr);
}

if ( 2 == SurfaceMode) // compile with FastScape
{
if( 1 == surfmode->SurfMode )
// using LaMEM original code to calculate topography
{
// PetscPrintf(PETSC_COMM_WORLD, "\nCalculating surface process through LaMEM code \n");
// apply erosion to the free surface
ierr = FreeSurfAppErosion(&lm->surf); CHKERRQ(ierr);

// apply sedimentation to the free surface
ierr = FreeSurfAppSedimentation(&lm->surf); CHKERRQ(ierr);
}

if( 2 == surfmode->SurfMode)
// Using FastScape to calculate topography
{
// PetscPrintf(PETSC_COMM_WORLD, "\n-------------------------------------------------------------------\n");
PetscPrintf(PETSC_COMM_WORLD, "Begin FastScape \n");
PetscPrintf(PETSC_COMM_WORLD, "--------------------------------------------------------------------------\n");
ierr = fastscape(&lm->FSLib); CHKERRQ(ierr);
}
}

// remap markers onto (stretched) grid
ierr = ADVRemap(&lm->actx); CHKERRQ(ierr);

// update phase ratios taking into account actual free surface position
ierr = FreeSurfGetAirPhaseRatio(&lm->surf); CHKERRQ(ierr);

//==================
// Save data to disk
//==================
Expand Down
6 changes: 5 additions & 1 deletion src/LaMEMLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ enum RunMode
};

//---------------------------------------------------------------------------
#include "fastscape.h"

struct LaMEMLib
{
Scaling scal; // scaling
TSSol ts; // time-stepping controls
DBMat dbm; // material database
DBPropDike dbdike; // dike database
DBPropDike dbdike; // dike database
FDSTAG fs; // staggered-grid layout
FreeSurf surf; // free-surface grid
FastScapeLib FSLib; // fastscape grid
BCCtx bc; // boundary condition context
AdvCtx actx; // advection context
JacRes jr; // Jacobian & residual context
Expand All @@ -48,6 +50,8 @@ struct LaMEMLib
PVPtr pvptr; // paraview out passive tracers
};



//---------------------------------------------------------------------------
// LAMEM LIBRARY FUNCTIONS
//---------------------------------------------------------------------------
Expand Down
60 changes: 51 additions & 9 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ include Makefile.in
# Environmental variables for PETSc installation directories:
# PETSC_DEB = /directory/where/petsc/debug/is/installed
# PETSC_OPT = /directory/where/petsc/optimized/is/installed
# FASTSCAPELIB = /directory/where/FastScapeLib/is/located
#
# LaMEM compilation command:
# make mode=deb all (compile debug version of LaMEM and put in /bin/deb)
# make mode=opt all (compile optimized version of LaMEM and put in /bin/opt)
# make all (compile optimized version of LaMEM and put in /bin/opt)
# make mode=optFS all surface=SURFACE=2 (compile optimized version of LaMEM with fastscape and put in /bin/optFS)
# surf_mode = 1; don't use fastscape; surf_mode = 2; use fastscape

ifeq ($(mode), deb)
ifeq (${PETSC_DEB},)
Expand All @@ -35,6 +38,15 @@ ifeq (${PETSC_OPT},)
$(error Environmental variable PETSC_OPT must be set to PETSc optimized installation directory)
endif
PETSC_DIR = ${PETSC_OPT}
else ifeq ($(mode), optFS)
# ifneq (, $(filter,${FASTSCAPE_LIB} ${PETSC_OPT}))
ifeq (${FASTSCAPE_LIB},)
${error Environmental variable PETSC_OPT and FASTSCAPE_LIB must be set to installation directory, respectively}
else ifeq (${PETSC_OPT},)
${error Environmental variable PETSC_OPT and FASTSCAPE_LIB must be set to installation directory, respectively}
endif
PETSC_DIR = ${PETSC_OPT}
FASTSCAPE_DIR = ${FASTSCAPE_LIB}
else
$(error Unknown compilation mode specified)
endif
Expand All @@ -45,19 +57,30 @@ include ${PETSC_DIR}/lib/petsc/conf/rules
# Define PETSc-based C++ compiler command
CCOMPILER = ${CXX} ${CXX_FLAGS} ${CXXFLAGS} ${CCPPFLAGS}

# Define FastScape-based fortran compiler command
GF = gfortran
# Define FastScapeFortranLib
FS_LIB = -L${FASTSCAPE_DIR} -lfastscapelib_fortran

#====================================================

# Define list of LaMEM library source files
# List files to be excluded after filter-out
CSRC = $(filter-out LaMEM.cpp, $(wildcard *.cpp))
FS = $(wildcard *.f90)

#====================================================

ifeq ($(mode), optFS)
# Generate lists of library object files:
COBJ := $(addprefix ../lib/${mode}/, $(notdir $(CSRC:.cpp=.o)))
COBJ := $(addprefix ../lib/${mode}/, $(notdir $(CSRC:.cpp=.o) $(FS:.f90=.o)))

# Generate lists of library dependency files:
CDEP := $(addprefix ../dep/${mode}/, $(notdir $(CSRC:.cpp=.d) $(FS:.f90=.d)))

else
COBJ := $(addprefix ../lib/${mode}/, $(notdir $(CSRC:.cpp=.o)))
CDEP := $(addprefix ../dep/${mode}/, $(notdir $(CSRC:.cpp=.d)))
endif

# Get library and executable objects:
LaMEM = ../bin/${mode}/LaMEM
Expand All @@ -74,7 +97,7 @@ endif

# Target list

.PHONY: builddir buildlib lamemlib linkexe lamem print clean_all doc
.PHONY: builddir buildlib lamemlib linkexe lamem print clean_all doc

# Default target (build executable)

Expand Down Expand Up @@ -136,8 +159,11 @@ ${LaMEM_LIB} : ../dep/$(mode)/makefile.stat ${COBJ}

# Create a dynamic library
dylib: ${COBJ}
ifeq ($(mode), optFS)
$(CCOMPILER) -shared -fPIC -o ../lib/$(mode)/LaMEMLib.dylib ${COBJ} ${PETSC_LIB} ${FS_LIB}
else
$(CCOMPILER) -shared -fPIC -o ../lib/$(mode)/LaMEMLib.dylib ${COBJ} ${PETSC_LIB}

endif
#====================================================

# Link LaMEM executable
Expand All @@ -150,16 +176,28 @@ ${LaMEM} : ${LaMEM_LIB} ${LaMEM_OBJ}
@echo "............................................."
@echo "......... Linking LaMEM Executable .........."
@echo "............................................."
${CXXLINKER} ${LaMEM_OBJ} ${LaMEM_LIB} ${PETSC_LIB} ${CLIB_FLAGS} -o $@
ifeq ($(mode), optFS)
${CXXLINKER} ${LaMEM_OBJ} ${LaMEM_LIB} ${PETSC_LIB} ${CLIB_FLAGS} ${FS_LIB} -o $@
else
${CXXLINKER} ${LaMEM_OBJ} ${LaMEM_LIB} ${PETSC_LIB} ${CLIB_FLAGS} -o $@
endif

#====================================================

# Pattern rules for automatic generation of object & dependency files
# Insert full path to object files in dependency files with sed command
# NOTE: IBM XL compiler generates dependency as a by-product of compilation
ifeq ($(mode), optFS)
../lib/${mode}/%.o : %.f90
${GF} ${FS_LIB} -c $< -o $@
endif

# define SURFACE 1 in Cpp script when there isn't a value setting in bash
surface=SURFACE=1

../lib/${mode}/%.o : %.cpp
${CCOMPILER} ${LAMEM_FLAGS} -D$(surface) -c $< -o $@

../lib/${mode}/%.o : %.cpp
${CCOMPILER} ${LAMEM_FLAGS} -c $< -o $@
ifeq ($(PLATFORM), ppc64)
@mv -f ../lib/${mode}/$*.d ../dep/${mode}/$*.d.tmp
else
Expand Down Expand Up @@ -210,6 +248,11 @@ endif
@echo "............................................."
@echo "PETSC_LIB : " ${PETSC_LIB}
@echo "............................................."
ifeq ($(mode), optFS)
@echo "............................................."
@echo "FASTSCAPE_LIB : " ${FS_LIB}
@echo "............................................."
endif
@echo "CLIB_FLAGS : " ${CLIB_FLAGS}
@echo "............................................."

Expand All @@ -222,12 +265,11 @@ clean_all :
@rm -rf ../lib/$(mode)/*
@rm -rf ../bin/$(mode)/*
@rm -rf ../dep/$(mode)/*

#====================================================

# Create automatic documentation

doc:
PDFLATEX=$(PDFLATEX) BIBTEX=$(BIBTEX) ../doc/Manual/./CreateDevelDoc.sh

#====================================================
#====================================================
Loading
Loading