Skip to content

Commit

Permalink
[init]
Browse files Browse the repository at this point in the history
  • Loading branch information
NaokiHori committed Jun 27, 2024
0 parents commit bc6e3b5
Show file tree
Hide file tree
Showing 181 changed files with 14,677 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

on:

push:
branches:
- main
paths:
- include/**
- src/**
workflow_dispatch:

jobs:

main:
name: Create branch 2D and 3D which only contains the dimension and compile each
permissions:
contents: write
strategy:
matrix:
dimension: [2, 3]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@main
with:
repository: "NaokiHori/SimpleBubblyFlowSolver"
ref: "main"
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: |
set -x
set -e
python .github/workflows/extract_nd.py ${{ matrix.dimension }}
- name: Modify Makefile
run: |
set -x
set -e
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 "[email protected]"
git config --local user.name "NaokiHori"
# add, commit, and push
git add Makefile
git add src
git add include
git commit -m "Extract ${{ matrix.dimension }}d sources" -a || true
git push -f origin ${{ matrix.dimension }}d
49 changes: 49 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Documentation

on:

push:
branches:
- main
paths:
- docs/source/**

jobs:

main:
name: Build and 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
steps:
- name: Checkout repository
uses: actions/checkout@main
with:
repository: "NaokiHori/SimpleBubblyFlowSolver"
ref: "main"
- name: Build documentation using Sphinx
run: |
docker run \
--rm \
--volume ${PWD}:/project \
--workdir /project \
sphinxdoc/sphinx:latest \
sphinx-build "docs/source" "docs/build"
- name: Setup GitHub Pages
uses: actions/configure-pages@main
- name: Upload HTML
uses: actions/upload-pages-artifact@main
with:
path: docs/build
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@main

132 changes: 132 additions & 0 deletions .github/workflows/extract_nd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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):
IN_2D = enum.auto()
IN_3D = enum.auto()
OTHER = enum.auto()


def extract_given_dim(ndims, lines):
state = NdimsType.OTHER
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("else found but if not found beforehand")
sys.exit()
elif "#endif" in line:
if if_level == if_level_ndims:
is_on_ndims_macro = True
state = NdimsType.OTHER
# 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_comments(lines):
"""
there are weird comments which are used by Sphinx, which look like
// <comment> | <number of lines><cr>
I use this function to modify this kind of stuffs as
// <comment><cr>
"""
delim = " | "
newlines = list()
for line in lines:
if "//" in line and delim in line:
line = line.split(delim)[0] + "\n"
newlines.append(line)
return newlines


def adjust_blank_lines(lines):
"""
this function merges two (and more) successive blank lines
into one blank
"""
nitems = len(lines)
flags = [True for _ in range(nitems)]
for n in range(1, nitems):
# check two neighbouring lines
l0 = lines[n - 1]
l1 = lines[n]
if "\n" == l0 and "\n" == l1:
flags[n] = False
newlines = list()
for line, flag in zip(lines, flags):
if flag:
newlines.append(line)
return newlines


def main():
argv = sys.argv
# sanitise input
assert 2 == len(argv)
ndims = int(argv[1])
# input source files
fnames = list()
fnames += get_filenames("src")
fnames += get_filenames("include")
for fname in fnames:
with open(fname, "r") as f:
lines = f.readlines()
lines = extract_given_dim(ndims, lines)
lines = modify_comments(lines)
lines = adjust_blank_lines(lines)
if 0 == len(lines):
# nothing remains, delete file
os.system(f"rm {fname}")
continue
# dump
lines = "".join(lines)
with open(fname, "w") as f:
f.write(lines)


if __name__ == "__main__":
main()
8 changes: 8 additions & 0 deletions .gitmodules
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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 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.
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
CC := mpicc
CFLAG := -std=c99 -Wall -Wextra -Werror -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)/log ]; then \
mkdir -p $(OUTDIR)/log; \
fi
@if [ ! -e $(OUTDIR)/save ]; then \
mkdir -p $(OUTDIR)/save; \
fi
@if [ ! -e $(OUTDIR)/stat ]; then \
mkdir -p $(OUTDIR)/stat; \
fi

datadel:
$(RM) -r $(OUTDIR)/log/*
$(RM) -r $(OUTDIR)/save/*
$(RM) -r $(OUTDIR)/stat/*

-include $(DEPS)

.PHONY : all clean output datadel help

Loading

0 comments on commit bc6e3b5

Please sign in to comment.