From f946a83c8cb929dd0021d8a5a2a0a1d99ba2e47d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 6 Jul 2018 14:19:30 +0200 Subject: precice: new package (issue #8643) (#8644) preCICE (Precise Code Interaction Coupling Environment) is a coupling library for partitioned multi-physics simulations. Partitioned means that preCICE couples existing programs (solvers) capable of simulating a subpart of the complete physics involved in a simulation. of-precice: new package preCICE adapter for OpenFOAM --- .../repos/builtin/packages/of-precice/package.py | 104 +++++++++++++++++++++ .../repos/builtin/packages/precice/package.py | 77 +++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 var/spack/repos/builtin/packages/of-precice/package.py create mode 100644 var/spack/repos/builtin/packages/precice/package.py (limited to 'var') diff --git a/var/spack/repos/builtin/packages/of-precice/package.py b/var/spack/repos/builtin/packages/of-precice/package.py new file mode 100644 index 0000000000..2b3f64aaea --- /dev/null +++ b/var/spack/repos/builtin/packages/of-precice/package.py @@ -0,0 +1,104 @@ +############################################################################## +# Copyright (c) 2018 Mark Olesen, OpenCFD Ltd. +# +# This file was authored by Mark Olesen +# and is released as part of spack under the LGPL license. +# LLNL-CODE-647188 +# +# For details, see https://github.com/spack/spack +# Please also see the NOTICE and LICENSE files for the LLNL notice and LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +import os + +import llnl.util.tty as tty + +from spack import * +from spack.pkg.builtin.openfoam_com import add_extra_files + + +class OfPrecice(Package): + """preCICE adapter for OpenFOAM""" + + homepage = 'https://www.precice.org' + gitrepo = 'https://github.com/precice/openfoam-adapter.git' + + # Currently develop only + version('develop', branch='master', git=gitrepo) + + depends_on('openfoam+source') + depends_on('precice') + depends_on('yaml-cpp') + + # General patches + common = ['change-userdir.sh', 'spack-derived-Allwmake'] + assets = [] + + build_script = './spack-derived-Allwmake' + build_userdir = 'spack-userdir' # Build user APPBIN, LIBBIN into here + + phases = ['configure', 'build', 'install'] + + # + # - End of definitions / setup - + # + + def patch(self): + """Copy additional files or other patching.""" + add_extra_files(self, self.common, self.assets) + # Emit openfoam version immediately, if we resolved the wrong version + # it takes a very long time to rebuild! + tty.info('Build for ' + self.spec['openfoam'].format('$_$@$%@+$+')) + + def configure(self, spec, prefix): + """Generate spack-config.sh file.""" + # Local tweaks + # This is ugly, but otherwise it only looks for src/precice, + # not the installed include files + config = join_path(self.stage.source_path, 'spack-config.sh') + with open(config, 'w') as out: + out.write( + """# Local tweaks for building +CPLUS_INCLUDE_PATH="{precice_dir}/include/precice${{CPLUS_INCLUDE_PATH:+:}}$CPLUS_INCLUDE_PATH" ## noqa: E501 +export CPLUS_INCLUDE_PATH +# Local build (for user appbin, libbin) +. ./change-userdir.sh $PWD/{user_dir} +# +""" + .format( + precice_dir=spec['precice'].prefix, + user_dir=self.build_userdir)) + + def build(self, spec, prefix): + """Build with Allwmake script, wrapped to source environment first.""" + args = [] + if self.parallel: # Parallel build? - pass via environment + os.environ['WM_NCOMPPROCS'] = str(make_jobs) + builder = Executable(self.build_script) + builder(*args) + + def install(self, spec, prefix): + """Install under the prefix directory""" + + for f in ['README.md', 'LICENSE']: + if os.path.isfile(f): + install(f, join_path(self.prefix, f)) + + install_tree('tutorials', join_path(self.prefix, 'tutorials')) + + # Place directly under 'lib' (no bin) + install_tree( + join_path(self.build_userdir, 'lib'), + join_path(self.prefix, 'lib')) diff --git a/var/spack/repos/builtin/packages/precice/package.py b/var/spack/repos/builtin/packages/precice/package.py new file mode 100644 index 0000000000..69e7d16592 --- /dev/null +++ b/var/spack/repos/builtin/packages/precice/package.py @@ -0,0 +1,77 @@ +############################################################################## +# Copyright (c) 2018 Mark Olesen, OpenCFD Ltd. +# +# This file was authored by Mark Olesen +# and is released as part of spack under the LGPL license. +# LLNL-CODE-647188 +# +# For details, see https://github.com/spack/spack +# Please also see the NOTICE and LICENSE files for the LLNL notice and LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +from spack import * + + +class Precice(CMakePackage): + """preCICE (Precise Code Interaction Coupling Environment) is a + coupling library for partitioned multi-physics simulations. + Partitioned means that preCICE couples existing programs (solvers) + capable of simulating a subpart of the complete physics involved in + a simulation.""" + + homepage = 'https://www.precice.org' + gitrepo = 'https://github.com/precice/precice.git' + + # Skip version 1.1.1 entirely, the cmake was lacking install. + version('develop', branch='develop', git=gitrepo) + + variant('mpi', default=True, description='Enable MPI support') + variant('petsc', default=False, description='Enable PETSc support') + variant('python', default=False, description='Enable Python support') + variant('shared', default=True, description='Build shared libraries') + + # Not yet +# variant( +# 'float', default=False, +# description='Use single precision for field data exchange') +# variant( +# 'int64', +# default=False, description='Use 64-bit integers for indices') + + depends_on('cmake@3.5:', type='build') + depends_on('boost@1.60.0:') + depends_on('eigen@3.2:') + # Implicit via eigen, don't over-constrain: depends_on('libxml2') + depends_on('mpi', when='+mpi') + depends_on('petsc', when='+petsc') + depends_on('python@2.7', when='+python', type=('build', 'run')) + + def cmake_args(self): + """Populate cmake arguments for precice.""" + spec = self.spec + + def variant_bool(feature, on='ON', off='OFF'): + """Ternary for spec variant to ON/OFF string""" + if feature in spec: + return on + return off + + cmake_args = [ + '-DMPI:BOOL=%s' % variant_bool('+mpi'), + '-DPETSC:BOOL=%s' % variant_bool('+petsc'), + '-DPYTHON:BOOL=%s' % variant_bool('+python'), + '-DBUILD_SHARED_LIBS:BOOL=%s' % variant_bool('+shared'), + ] + return cmake_args -- cgit v1.2.3-60-g2f50