Skip to content

Commit

Permalink
Merge branch 'main' into tMaker_field_interp
Browse files Browse the repository at this point in the history
  • Loading branch information
hansec committed Feb 26, 2024
2 parents 3fbe967 + 69b2704 commit fb121ae
Show file tree
Hide file tree
Showing 43 changed files with 546 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ on:

jobs:
build:
name: ${{ matrix.config.name }}
name: ${{ format('{0} ({1})', matrix.config.name, matrix.parallel) }}
runs-on: ${{ matrix.config.os }}
env:
CC: ${{ matrix.config.cc }}
CXX: ${{ matrix.config.cxx }}
FC: ${{ matrix.config.fc }}
OMP_NUM_THREADS: 2

strategy:
fail-fast: false
matrix:
parallel: ["openmp", "mpi_openmp"]
config:
- {
name: "Ubuntu 20.04 GCC 10",
Expand All @@ -42,7 +44,8 @@ jobs:
}

steps:
- uses: actions/checkout@v4
- name: Checkout repo
uses: actions/checkout@v4

- name: Install prerequisites
run: ${{ matrix.config.pip }} install pytest numpy scipy h5py triangle
Expand All @@ -52,10 +55,10 @@ jobs:
uses: actions/cache@v4
with:
path: libs
key: ${{ runner.os }}-build-${{ hashFiles('src/utilities/build_libs.py') }}
key: ${{ matrix.config.os }}-build-${{ matrix.parallel }}-${{ hashFiles('src/utilities/build_libs.py') }}

- if: ${{ steps.cache-ext-libs.outputs.cache-hit != 'true' }}
name: Create build dir
- name: Create build dir
if: ${{ steps.cache-ext-libs.outputs.cache-hit != 'true' }}
run: mkdir libs

- name: Check compilers
Expand All @@ -64,14 +67,25 @@ jobs:
$CXX --version
$FC --version
- name: Build external
- name: Build external (OpenMP)
if: ${{ matrix.parallel == 'openmp' }}
shell: bash
working-directory: libs
run: >
${{ matrix.config.python }} ../src/utilities/build_libs.py --no_dl_progress --nthread=2 --ref_blas
--build_umfpack=1 --build_arpack=1 --oft_build_tests=1
- name: Build external (MPI+OpenMP)
if: ${{ matrix.parallel == 'mpi_openmp' }}
shell: bash
working-directory: libs
run: >
${{ matrix.config.python }} ../src/utilities/build_libs.py --no_dl_progress --nthread=2 --ref_blas
--build_mpi=1 --build_umfpack=1 --build_superlu=1 --build_superlu_dist=1
--build_arpack=1 --oft_build_tests=1
- uses: actions/upload-artifact@v4
- name: Upload library failure log
uses: actions/upload-artifact@v4
if: failure()
with:
name: Library failure log
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/cov_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Open FUSION Toolkit code coverage build

on:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
name: Code coverage
runs-on: ubuntu-22.04
env:
CC: gcc-13
CXX: g++-13
FC: gfortran-13
OMP_NUM_THREADS: 1

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install prerequisites
run: |
sudo apt -y install lcov
pip3 install pytest numpy scipy h5py triangle
- name: Cache external libraries
id: cache-ext-libs
uses: actions/cache@v4
with:
path: libs
key: cov_build-${{ hashFiles('src/utilities/build_libs.py') }}

- name: Create build dir
if: ${{ steps.cache-ext-libs.outputs.cache-hit != 'true' }}
run: mkdir libs

- name: Check compilers
run: |
$CC --version
$CXX --version
$FC --version
- name: Build external
shell: bash
working-directory: libs
run: >
python3 ../src/utilities/build_libs.py --no_dl_progress --nthread=2
--ref_blas --build_mpi=1 --build_umfpack=1 --build_superlu=1 --build_superlu_dist=1
--build_arpack=1 --oft_build_tests=1 --oft_build_coverage
- name: Upload library failure log
uses: actions/upload-artifact@v4
if: failure()
with:
name: Library failure log
path: libs/build/build_error.log

- name: Remove external build directory
shell: bash
working-directory: libs
run: rm -rf build

- name: Configure OFT
shell: bash
working-directory: libs
run: bash config_cmake.sh

- name: Build OFT
shell: bash
working-directory: libs/build_release
run: make

- name: Test OFT
shell: bash
working-directory: libs/build_release
run: make test_cov

- name: Generate coverage report
shell: bash
working-directory: libs/build_release
run: |
lcov -c --directory . --output-file main_coverage.info --gcov-tool gcov-13
lcov --ignore-errors unused -r main_coverage.info -o cleaned_coverage.txt '/opt/*' '/usr/*'
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4
with:
file: libs/build_release/cleaned_coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}
slug: hansec/OpenFUSIONToolkit
verbose: true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Open Flexible Unstructured Simulation Infrastructure with Open Numerics (FUSION) Toolkit (OFT)
=====================================

![CI status](https://github.com/hansec/OpenFUSIONToolkit/actions/workflows/build_test.yaml/badge.svg?branch=main)
![CI status](https://github.com/hansec/OpenFUSIONToolkit/actions/workflows/ci_build.yaml/badge.svg?branch=main)
[![codecov](https://codecov.io/gh/hansec/OpenFUSIONToolkit/graph/badge.svg?token=GG282HKNAO)](https://codecov.io/gh/hansec/OpenFUSIONToolkit)
[![DOI](https://zenodo.org/badge/710415041.svg)](https://zenodo.org/doi/10.5281/zenodo.10306801)

The Open FUSION Toolkit (OFT) is a suite of modeling tools, and their underlying finite element
Expand Down
16 changes: 16 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
coverage:
# Set ranges for status displays
range: 50..80
round: down
precision: 1
# Make check informational only (not blocking/failing)
status:
project:
default:
informational: true
patch:
default:
informational: true
# GitHub specific settings
github_checks:
annotations: false # Disable code annotations
17 changes: 13 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ option(OFT_BUILD_DOCS "Build documentation?" OFF)
option(OFT_DOCS_ONLY "Build documentation only?" OFF)
option(OFT_PACKAGE_BUILD "Perform a destributable package?" OFF)
option(OFT_PACKAGE_NIGHTLY "Perform a nightly build and include git hash in package filename?" ON)
option(OFT_COVERAGE "Build with code coverage information?" OFF)

# Internal variables
set(OFT_SHARED_LIBS CACHE INTERNAL "package_shared_libs")
Expand Down Expand Up @@ -91,12 +92,20 @@ if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel")
set( EXT_LIBS "-lstdc++" )
endif()
elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
set( CMAKE_C_FLAGS_DEBUG "-g -O0" )
if(OFT_COVERAGE)
set( CMAKE_C_FLAGS_DEBUG "-Og --coverage -fprofile-update=atomic -g -Wuninitialized" ) # -fprofile-arcs -ftest-coverage
set( CMAKE_C_FLAGS_RELEASE "-Og --coverage -fprofile-update=atomic -g" ) # -fprofile-arcs -ftest-coverage
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE ON)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
set(CMAKE_Fortran_OUTPUT_EXTENSION_REPLACE ON)
else()
set( CMAKE_C_FLAGS_DEBUG "-g -O0 -Wuninitialized" )
set( CMAKE_C_FLAGS_RELEASE "-O2" )
endif()
set( CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} )
set( CMAKE_Fortran_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} )
set( CMAKE_C_FLAGS_RELEASE "-O2" )
set( CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} )
set( CMAKE_Fortran_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} )
set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror=line-truncation -Wconversion" )
set( CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror=line-truncation -Wconversion" )
if(NOT OFT_PACKAGE_BUILD)
set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -fcheck=all" )
endif()
Expand Down
33 changes: 28 additions & 5 deletions src/base/oft_base.F90
Original file line number Diff line number Diff line change
Expand Up @@ -922,20 +922,43 @@ END SUBROUTINE orient_listn_inv
!! @warning This function requires `x` be sorted lowest to highest.
!! @note This function performs an interval search each time it is called.
!!
!! @returns \f$ F(xx) \f$
!! @returns \f$ F(xx) \f$ (-1.E99 if outside domain and `extrap=0`)
!------------------------------------------------------------------------------
PURE FUNCTION linterp(x,y,n,xx) result(yy)
FUNCTION linterp(x,y,n,xx,extrap) result(yy)
REAL(r8), INTENT(in) :: x(n) !< Paramaterizing array \f$ x_i \f$ [n]
REAL(r8), INTENT(in) :: y(n) !< Function values \f$ F(x_i) \f$ [n]
REAL(r8), INTENT(in) :: xx !< Length of function parameterization
INTEGER(i4), INTENT(in) :: n !< Location to perform interpolation
REAL(r8), INTENT(in) :: xx !< Location to perform interpolation
INTEGER(i4), INTENT(in) :: n !< Length of function parameterization
INTEGER(i4), OPTIONAL, INTENT(in) :: extrap !< Extrapolation mode (0: none, 1: constant, 2: linear)
INTEGER(i4) :: i
REAL(r8) :: yy
yy=-1.d99
DO i=2,n
IF(x(i-1)<=xx.AND.x(i)>=xx)EXIT
END DO
IF(i<=n)yy=(y(i)-y(i-1))*(xx-x(i-1))/(x(i)-x(i-1)) + y(i-1)
IF(i<=n)THEN
yy=(y(i)-y(i-1))*(xx-x(i-1))/(x(i)-x(i-1)) + y(i-1)
ELSE
IF(PRESENT(extrap))THEN
SELECT CASE(extrap)
CASE(0)
CASE(1)
IF(xx<x(1))THEN
yy=y(1)
ELSE IF(xx>x(n))THEN
yy=y(n)
END IF
CASE(2)
IF(xx<x(1))THEN
yy=(y(2)-y(1))*(xx-x(1))/(x(2)-x(1)) + y(1)
ELSE IF(xx>x(n))THEN
yy=(y(n)-y(n-1))*(xx-x(n-1))/(x(n)-x(n-1)) + y(n-1)
END IF
CASE DEFAULT
CALL oft_abort("Invalid extrapolation type","linterp",__FILE__)
END SELECT
END IF
END IF
END FUNCTION linterp
!---------------------------------------------------------------------------
!> Reset the stack
Expand Down
26 changes: 13 additions & 13 deletions src/bin/thincurr_td.F90
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,nplot,sensors)
t=0.d0
IF(ntimes_curr>0)THEN
DO j=1,self%n_icoils
icoil_curr(j)=linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t)
icoil_curr(j)=linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t,1)
END DO
END IF
!---Save sensor data for t=0
Expand Down Expand Up @@ -373,32 +373,32 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,nplot,sensors)
IF(ntimes_curr>0)THEN
DO j=1,self%n_icoils
! Start of step
icoil_dcurr(j)=linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt/4.d0)
icoil_dcurr(j)=icoil_dcurr(j)-linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t-dt/4.d0)
icoil_dcurr(j)=linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt/4.d0,1)
icoil_dcurr(j)=icoil_dcurr(j)-linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t-dt/4.d0,1)
! End of step
icoil_dcurr(j)=icoil_dcurr(j)+linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt*5.d0/4.d0)
icoil_dcurr(j)=icoil_dcurr(j)-linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt*3.d0/4.d0)
icoil_dcurr(j)=icoil_dcurr(j)+linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt*5.d0/4.d0,1)
icoil_dcurr(j)=icoil_dcurr(j)-linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt*3.d0/4.d0,1)
END DO
END IF
IF(ntimes_volt>0)THEN
DO j=1,self%n_vcoils
! Start of step
pcoil_volt(j)=linterp(volt_waveform(:,1),volt_waveform(:,j+1),ntimes_volt,t)/2.d0
pcoil_volt(j)=pcoil_volt(j)+linterp(volt_waveform(:,1),volt_waveform(:,j+1),ntimes_volt,t+dt)/2.d0
pcoil_volt(j)=linterp(volt_waveform(:,1),volt_waveform(:,j+1),ntimes_volt,t,1)/2.d0
pcoil_volt(j)=pcoil_volt(j)+linterp(volt_waveform(:,1),volt_waveform(:,j+1),ntimes_volt,t+dt,1)/2.d0
END DO
END IF
ELSE
CALL Lmat%apply(u,g)
IF(ntimes_curr>0)THEN
DO j=1,self%n_icoils
icoil_dcurr(j)=linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt*5.d0/4.d0)
icoil_dcurr(j)=icoil_dcurr(j)-linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt*3.d0/4.d0)
icoil_dcurr(j)=linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt*5.d0/4.d0,1)
icoil_dcurr(j)=icoil_dcurr(j)-linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t+dt*3.d0/4.d0,1)
END DO
icoil_dcurr=icoil_dcurr*2.d0
END IF
IF(ntimes_volt>0)THEN
DO j=1,self%n_vcoils
pcoil_volt(j)=linterp(volt_waveform(:,1),volt_waveform(:,j+1),ntimes_volt,t+dt)
pcoil_volt(j)=linterp(volt_waveform(:,1),volt_waveform(:,j+1),ntimes_volt,t+dt,1)
END DO
END IF
END IF
Expand All @@ -425,7 +425,7 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,nplot,sensors)
CALL u%get_local(vals)
IF(ntimes_curr>0)THEN
DO j=1,self%n_icoils
icoil_curr(j)=linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t)
icoil_curr(j)=linterp(curr_waveform(:,1),curr_waveform(:,j+1),ntimes_curr,t,1)
END DO
END IF
IF(sensors%nfloops>0)THEN
Expand Down Expand Up @@ -531,7 +531,7 @@ SUBROUTINE plot_td_sim(self,dt,nsteps,nplot,sensors)
t=0.d0
IF(ntimes_curr>0)THEN
DO j=1,self%n_icoils
coil_vec(j)=linterp(coil_waveform(:,1),coil_waveform(:,j+1),ntimes_curr,t)
coil_vec(j)=linterp(coil_waveform(:,1),coil_waveform(:,j+1),ntimes_curr,t,1)
END DO
END IF
!
Expand Down Expand Up @@ -600,7 +600,7 @@ SUBROUTINE plot_td_sim(self,dt,nsteps,nplot,sensors)
IF(MOD(i,nplot)==0)THEN
IF(ntimes_curr>0)THEN
DO j=1,self%n_icoils
coil_vec(j)=linterp(coil_waveform(:,1),coil_waveform(:,j+1),ntimes_curr,t)
coil_vec(j)=linterp(coil_waveform(:,1),coil_waveform(:,j+1),ntimes_curr,t,1)
END DO
END IF
!
Expand Down
3 changes: 1 addition & 2 deletions src/docs/thincurr_example2.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ ToDo: Describe current potential "holes"

**Coil current waveform file** (`curr.drive`)
\verbatim
2 4
-1.0 1.E3
2 3
0.0 1.E3
1.E-4 0.0
1.0 0.0
Expand Down
2 changes: 1 addition & 1 deletion src/docs/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h4>How To Cite</h4>
<li><strong>MUG:</strong>
<ul class="no_bullet">
<li>C. Hansen et al., <em>Phys. Plasmas</em> <strong>22</strong>, 042505 (2015) <a href="http://dx.doi.org/10.1063/1.4917476">[DOI]</a></li>
<li>C. Hansen et al., <em>PhD Thesis: U. Washington</em> (2014) <a href="http://hdl.handle.net/1773/25420">[URI]</a></li>
<li>C. Hansen, <em>PhD Thesis: U. Washington</em> (2014) <a href="http://hdl.handle.net/1773/25420">[URI]</a></li>
</ul>
</li>
<li><strong>Marklin:</strong>
Expand Down
Loading

0 comments on commit fb121ae

Please sign in to comment.