-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 06e9313
Showing
63 changed files
with
6,015 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
name: CI | ||
|
||
on: | ||
|
||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
|
||
extract-nd: | ||
name: Compile sources and push 2d and 3d branches | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
dimension: [2, 3] | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@main | ||
with: | ||
repository: "NaokiHori/SpectralNSSolver1" | ||
ref: ${{ github.ref_name }} | ||
submodules: "recursive" | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get -y update && \ | ||
sudo apt-get -y install make libopenmpi-dev libfftw3-dev | ||
- name: Remove another dimension | ||
run: | | ||
python .github/workflows/extract_nd_main.py ${{ matrix.dimension }} | ||
- name: Modify Makefile | ||
run: | | ||
sed -i "s/DNDIMS=2/DNDIMS=${{ matrix.dimension }}/g" Makefile | ||
- name: Compile | ||
run: | | ||
make all | ||
- name: Commit and push change | ||
run: | | ||
set -x | ||
set -e | ||
git switch -c ${{ matrix.dimension }}d | ||
git config --local user.email "36466440+NaokiHori@users.noreply.github.com" | ||
git config --local user.name "NaokiHori" | ||
# not include documentation in each branch | ||
git rm -r docs | ||
# let IC generator of the given dimension as main.py | ||
cd initial_condition | ||
find . -type f -not -name ${{ matrix.dimension }}d.py | xargs git rm | ||
git mv ${{ matrix.dimension }}d.py main.py | ||
cd .. | ||
# declare to track others, just in case | ||
git add exec.sh | ||
git add include | ||
git add LICENSE | ||
git add Makefile | ||
git add README.rst | ||
git add src | ||
# commit and push | ||
git commit -m "Extract ${{ matrix.dimension }}d sources" -a || true | ||
git push -f origin ${{ matrix.dimension }}d | ||
build-and-run: | ||
name: Build library and try to run test case | ||
runs-on: ubuntu-latest | ||
needs: [extract-nd] | ||
strategy: | ||
matrix: | ||
dimension: [2, 3] | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@main | ||
with: | ||
repository: "NaokiHori/SpectralNSSolver1" | ||
ref: ${{ matrix.dimension }}d | ||
submodules: "recursive" | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get -y update && \ | ||
sudo apt-get -y install make libopenmpi-dev libfftw3-dev | ||
- name: Install python dependencies for pre-processing | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install numpy | ||
- name: Pre-process | ||
run: | | ||
set -x | ||
set -e | ||
cd initial_condition | ||
python3 main.py 0 | ||
ls output | ||
cd .. | ||
- name: Build | ||
run: | | ||
set -x | ||
set -e | ||
make clean | ||
make output | ||
make all | ||
- name: Run | ||
run: | | ||
export timemax=5.0e+0 | ||
export wtimemax=6.0e+2 | ||
export log_rate=5.0e-1 | ||
export save_rate=1.0e+0 | ||
export Re=1.0e+2 | ||
export Sc=1.0e-1 | ||
dirname_ic=initial_condition/output | ||
mpirun -n 4 --oversubscribe ./a.out ${dirname_ic} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Documentation | ||
|
||
on: | ||
|
||
push: | ||
branches: | ||
- main | ||
paths: | ||
- docs/** | ||
- .github/workflows/documentation.yml | ||
|
||
jobs: | ||
|
||
build-doc: | ||
name: Build documentation | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@main | ||
with: | ||
repository: "NaokiHori/SpectralNSSolver1" | ||
ref: ${{ github.ref_name }} | ||
- name: Check dead links | ||
run: | | ||
docker run \ | ||
--rm \ | ||
--volume ${PWD}:/project \ | ||
--workdir /project \ | ||
sphinxdoc/sphinx:latest \ | ||
sphinx-build -M linkcheck "docs/source" "docs/build" | ||
log=docs/build/linkcheck/output.txt | ||
if [ -e ${log} ]; then | ||
wc -l ${log} | ||
cat ${log} | ||
fi | ||
- name: Build documentation using Sphinx | ||
run: | | ||
docker run \ | ||
--rm \ | ||
--volume ${PWD}:/project \ | ||
--workdir /project \ | ||
sphinxdoc/sphinx:latest \ | ||
sphinx-build -M html "docs/source" "docs/build" | ||
- name: Upload HTML artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: DocHTML | ||
path: docs/build/html | ||
|
||
deploy-doc: | ||
name: Deploy documentation | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: true | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
needs: [build-doc] | ||
steps: | ||
- name: Download HTML artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: DocHTML | ||
path: docs/build/html | ||
- name: Setup GitHub Pages | ||
uses: actions/configure-pages@main | ||
- name: Upload HTML | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: docs/build/html | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import os | ||
import sys | ||
import glob | ||
import enum | ||
|
||
def get_filenames(root): | ||
results = glob.glob(f"{root}/**", recursive=True) | ||
retvals = list() | ||
for result in results: | ||
if result.endswith(".c") or result.endswith(".h"): | ||
retvals.append(result) | ||
return retvals | ||
|
||
class NdimsType(enum.Enum): | ||
OUT = enum.auto() | ||
IN_2D = enum.auto() | ||
IN_3D = enum.auto() | ||
|
||
def extract(ndims, lines): | ||
state = NdimsType.OUT | ||
if_level = 0 | ||
if_level_ndims = 0 | ||
newlines = list() | ||
for line in lines: | ||
is_on_ndims_macro = False | ||
if "#if" in line: | ||
# found "if", increase nest counter | ||
if_level += 1 | ||
if " NDIMS" in line: | ||
if "NDIMS==2" in line.replace(" ", ""): | ||
is_on_ndims_macro = True | ||
# now in 2D condition | ||
state = NdimsType.IN_2D | ||
if_level_ndims = if_level | ||
if "NDIMS==3" in line.replace(" ", ""): | ||
is_on_ndims_macro = True | ||
# now in 3D condition | ||
state = NdimsType.IN_3D | ||
if_level_ndims = if_level | ||
elif "#else" in line: | ||
# check this "else" is for ndims | ||
if if_level == if_level_ndims: | ||
is_on_ndims_macro = True | ||
# if it is, swap state (3d if now 2d, vice versa) | ||
if state == NdimsType.IN_2D: | ||
state = NdimsType.IN_3D | ||
elif state == NdimsType.IN_3D: | ||
state = NdimsType.IN_2D | ||
else: | ||
print("although we should be inside ndims condition, state is OUT") | ||
sys.exit() | ||
elif "#endif" in line: | ||
if if_level == if_level_ndims: | ||
is_on_ndims_macro = True | ||
state = NdimsType.OUT | ||
# found "endif", reduce nest counter | ||
if_level -= 1 | ||
if not is_on_ndims_macro: | ||
# we do not include macro about ndims | ||
if ndims == 2 and state != NdimsType.IN_3D: | ||
newlines.append(line) | ||
if ndims == 3 and state != NdimsType.IN_2D: | ||
newlines.append(line) | ||
return newlines | ||
|
||
def modify_comment(lines): | ||
newlines = list() | ||
for line in lines: | ||
if "//" in line and "|" in line: | ||
line = line.split("|")[0] + "\n" | ||
newlines.append(line) | ||
return newlines | ||
|
||
def main(): | ||
argv = sys.argv | ||
# sanitise input | ||
assert(len(argv) == 2) | ||
ndims = int(argv[1]) | ||
# target scripts | ||
fnames = \ | ||
get_filenames("src") \ | ||
+ get_filenames("include") \ | ||
+ get_filenames("initial_conditions/src") \ | ||
+ get_filenames("initial_conditions/include") | ||
for fname in fnames: | ||
with open(fname, "r") as f: | ||
lines = f.readlines() | ||
lines = extract(ndims, lines) | ||
lines = modify_comment(lines) | ||
if 0 == len(lines): | ||
os.system(f"rm {fname}") | ||
continue | ||
if "extern int dummy" in "".join(lines): | ||
os.system(f"rm {fname}") | ||
continue | ||
with open(fname, "w") as f: | ||
for line in lines: | ||
f.write(line) | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[submodule "SimpleDecomp"] | ||
path = SimpleDecomp | ||
url = https://github.com/NaokiHori/SimpleDecomp | ||
branch = submodule | ||
[submodule "SimpleNpyIO"] | ||
path = SimpleNpyIO | ||
url = https://github.com/NaokiHori/SimpleNpyIO | ||
branch = submodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 NaokiHori | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
CC := mpicc | ||
CFLAG := -std=c99 -Wall -Wextra -O3 -DNDIMS=2 | ||
INC := -Iinclude -ISimpleDecomp/include -ISimpleNpyIO/include | ||
LIB := -lfftw3 -lm | ||
SRCDIR := src SimpleDecomp/src SimpleNpyIO/src | ||
OBJDIR := obj | ||
SRCS := $(shell find $(SRCDIR) -type f -name *.c) | ||
OBJS := $(patsubst %.c,obj/%.o,$(SRCS)) | ||
DEPS := $(patsubst %.c,obj/%.d,$(SRCS)) | ||
OUTDIR := output | ||
TARGET := a.out | ||
|
||
help: | ||
@echo "all : create \"$(TARGET)\"" | ||
@echo "clean : remove \"$(TARGET)\" and object files under \"$(OBJDIR)\"" | ||
@echo "output : create \"$(OUTDIR)\" to store output" | ||
@echo "datadel : clean-up \"$(OUTDIR)\"" | ||
@echo "help : show this message" | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(OBJS) | ||
$(CC) $(CFLAG) -o $@ $^ $(LIB) | ||
|
||
$(OBJDIR)/%.o: %.c | ||
@if [ ! -e $(dir $@) ]; then \ | ||
mkdir -p $(dir $@); \ | ||
fi | ||
$(CC) $(CFLAG) -MMD $(INC) -c $< -o $@ | ||
|
||
clean: | ||
$(RM) -r $(OBJDIR) $(TARGET) | ||
|
||
output: | ||
@if [ ! -e $(OUTDIR)/save ]; then \ | ||
mkdir -p $(OUTDIR)/save; \ | ||
fi | ||
@if [ ! -e $(OUTDIR)/log ]; then \ | ||
mkdir -p $(OUTDIR)/log; \ | ||
fi | ||
|
||
datadel: | ||
$(RM) -r $(OUTDIR)/save/* | ||
$(RM) -r $(OUTDIR)/log/* | ||
|
||
-include $(DEPS) | ||
|
||
.PHONY : all clean output datadel help | ||
|
Oops, something went wrong.