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

[Do not merge yet] Add 'Mizuki', an SPH/Nbody code based on FDPS #942

Open
wants to merge 21 commits into
base: main
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
75 changes: 75 additions & 0 deletions src/amuse/community/mizuki/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# standard amuse configuration include
# config.mk will be made after ./configure has run
ifeq ($(origin AMUSE_DIR), undefined)
AMUSE_DIR := $(shell amusifier --get-amuse-dir)
endif
-include $(AMUSE_DIR)/config.mk

MPICXX ?= mpicxx

use_phantom_grape_x86 = no # speedup from ~1M particles or so?

FDPS_PATH = src/FDPS/src
SUI_PATH = src/mizuki

INCLUDE += -I $(FDPS_PATH) -I $(SUI_PATH)

MPIFLAGS += -DPARTICLE_SIMULATOR_MPI_PARALLEL

CXXFLAGS = $(INCLUDE) -fPIC -O3 -Wall -std=c++20 -fopenmp


CXXFLAGS += -DPARTICLE_SIMULATOR_THREAD_PARALLEL
CXXFLAGS += -DENABLE_HYDRO_INTERACT
# CXXFLAGS += -DPARTICLE_SIMULATOR_MPI_PARALLEL
CXXFLAGS += -DENABLE_VARIABLE_SMOOTHING_LENGTH
# CXXFLAGS += -DUSE_ENTROPY
# CXXFLAGS += -DUSE_BALSARA_SWITCH
# CXXFLAGS += -DUSE_PRESCR_OF_THOMAS_COUCHMAN_1992
# CXXFLAGS += -DISOTHERMAL_EOS

ifeq ($(use_phantom_grape_x86),yes)
PG_ROOT = $(FDPS_PATH)/phantom_grape_x86/G5/newton/libpg5
CXXFLAGS += -I $(PG_ROOT)
CXXFLAGS += -DENABLE_PHANTOM_GRAPE_X86
CXXFLAGS += -L$(PG_ROOT) -lpg5
PG_BUILD = make -C $(PG_ROOT) distclean libpg5.a
PG_CLEAN = make -C $(PG_ROOT) distclean
else
PG_BUILD =
PG_CLEAN =
endif

LDFLAGS += -lm $(MUSE_LD_FLAGS)

OBJS = interface.o


all: mizuki_worker $(CODELIB)

$(CODELIB):
$(PG_BUILD)
#amusi $(MPICXX) $(CXXFLAGS)
#$(PG_BUILD)
#$(AR) $@

clean:
$(RM) -rf __pycache__
$(RM) -f *.so *.o *.pyc worker_code.cc worker_code.h
$(RM) *~ mizuki_worker worker_code.cc
make -C src clean

distclean: clean
make -C src distclean

worker_code.cc: interface.py
$(CODE_GENERATOR) --type=c interface.py MizukiInterface -o $@

worker_code.h: interface.py
$(CODE_GENERATOR) --type=H -i amuse.support.codes.stopping_conditions.StoppingConditionInterface interface.py MizukiInterface -o $@

mizuki_worker: worker_code.cc worker_code.h $(CODELIB) $(OBJS) interface.hpp
$(MPICXX) $(CXXFLAGS) $(SC_FLAGS) $(LDFLAGS) $< $(OBJS) -o $@

interface.o: interface.cc
$(MPICXX) $(CXXFLAGS) $(SC_FLAGS) -c -o $@ $<
1 change: 1 addition & 0 deletions src/amuse/community/mizuki/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .interface import Mizuki
108 changes: 108 additions & 0 deletions src/amuse/community/mizuki/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env python

import subprocess
import os
import urllib.request
import urllib.parse
import urllib.error
from shutil import which
from optparse import OptionParser


class GetCodeFromHttp:
filename_template = "{version}.tar.gz"
name = ["FDPS"]
url_template = [
"https://github.com/FDPS/FDPS/archive/{version}.tar.gz",
]
version = [
"",
]

def directory(self):
return os.path.abspath(os.path.dirname(__file__))

def src_directory(self):
return os.path.join(self.directory(), 'src')

def unpack_downloaded_file(self, filename, name, version):
print("unpacking", filename)
arguments = ['tar', '-xf']
arguments.append(filename)
subprocess.call(
arguments,
cwd=os.path.join(self.src_directory())
)
subprocess.call(
[
'mv', '{name}-{version}'.format(name=name, version=version),
name
],
cwd=os.path.join(self.src_directory())
)
print("done")

def start(self):
# if os.path.exists('src'):
# counter = 0
# while os.path.exists('src.{0}'.format(counter)):
# counter += 1
# if counter > 100:
# print("too many backup directories")
# break
# os.rename('src', 'src.{0}'.format(counter))

# os.mkdir('src')

for i, url_template in enumerate(self.url_template):
url = url_template.format(version=self.version[i])
filename = self.filename_template.format(version=self.version[i])
filepath = os.path.join(self.src_directory(), filename)
print(
"downloading version", self.version[i],
"from", url, "to", filename
)
if which('wget') is not None:
arguments = ['wget', url]
subprocess.call(
arguments,
cwd=os.path.join(self.src_directory())
)
elif which('curl') is not None:
arguments = ['curl', '-L', '-O', url]
subprocess.call(
arguments,
cwd=os.path.join(self.src_directory())
)
else:
urllib.request.urlretrieve(url, filepath)
print("downloading finished")
self.unpack_downloaded_file(
filename, self.name[i], self.version[i]
)


def main(fdps_version=''):
version = [
fdps_version,
]
instance = GetCodeFromHttp()
instance.version = version
instance.start()


def new_option_parser():
result = OptionParser()
result.add_option(
"--fdps-version",
default='57c73ed2213bfbd9dbd05700fd60c8922be22103',
dest="fdps_version",
help="FDPS commit hash to download",
type="string"
)
return result


if __name__ == "__main__":
options, arguments = new_option_parser().parse_args()
main(**options.__dict__)
Loading