Skip to content

Commit 12921a2

Browse files
committed
Switch to newer version of Autocmake (YAML based) Fixes also some issues with the code
1 parent c0477d8 commit 12921a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2050
-765
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@
2424
_NOT recommended_ The hook can be skipped by passing the `--no-verify` option to `git commit`
2525
- An `UNUSED` preprocessor macro to mark arguments as unused.
2626
- An `UNUSED_FUNCTION` preprocessor macro to mark functions as unused.
27+
- A set of preprocessor macros with Git information (`GIT_COMMIT_HASH`,
28+
`GIT_COMMIT_AUTHOR`, `GIT_COMMIT_DATE` and `GIT_BRANCH`) is automatically
29+
generated and saved in the `git_info.h` header file.
30+
- An API function to print the contents of a surface function to the host
31+
program output.
32+
- An API function to get the dipole moment, relative to the origin, due to the ASC
33+
on the cavity. Both the norm and the components can be obtained.
2734

2835
### Changed
2936

37+
- The Fortran bindings file has been renamed `pcmsolver.f90`.
3038
- The Green's function, solver and boundary integral operator classes have been
3139
radically redesigned. This avoids coupling between integrators and Green's
3240
function that existed in the previous design.
@@ -37,6 +45,11 @@
3745
The version bundled with the code has been accordingly updated.
3846
- The `PCMSOLVER_ERROR` macro now takes only one argument and prints out a more
3947
informative error message.
48+
- Switched to the latest version of
49+
[Autocmake](http://autocmake.readthedocs.io/) The configuration file is now YAML-based.
50+
The PyYAML module is thus required.
51+
- The standalone `run_pcm` executable now uses the API functions instead of the
52+
internal headers.
4053

4154
### Deprecated
4255

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This file is autogenerated by Autocmake http://autocmake.org
2-
# Copyright (c) 2015-2016 by Radovan Bast and Jonas Juselius
1+
# This file is autogenerated by Autocmake v1.0.0-alpha-x http://autocmake.org
2+
# Copyright (c) 2015-2016 by Radovan Bast, Jonas Juselius, and contributors.
33

44
# set minimum cmake version
55
cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
@@ -21,23 +21,24 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/custom/co
2121
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/downloaded)
2222

2323
# included cmake modules
24-
include(autocmake_cxx)
25-
include(autocmake_cc)
2624
include(autocmake_fc)
25+
include(autocmake_cc)
26+
include(autocmake_cxx)
2727
include(Fortran_C)
28-
include(extended_diagnostics)
2928
include(CXXFlags)
3029
include(CFlags)
3130
include(FortranFlags)
3231
include(autocmake_ccache)
3332
include(rpath)
3433
include(windows)
34+
include(autocmake_definitions)
3535
include(autocmake_code_coverage)
3636
include(autocmake_int64)
3737
include(autocmake_omp)
3838
include(autocmake_safeguards)
3939
include(autocmake_python_interpreter)
4040
include(pcmsolver)
41+
include(autocmake_git_info)
4142
include(autocmake_boost)
4243
include(version)
4344
include(static_library)

api/pcmsolver.F90 renamed to api/pcmsolver.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ module pcmsolver
4141
public pcmsolver_compute_asc
4242
public pcmsolver_compute_response_asc
4343
public pcmsolver_compute_polarization_energy
44+
public pcmsolver_get_asc_dipole
4445
public pcmsolver_get_surface_function
4546
public pcmsolver_set_surface_function
47+
public pcmsolver_print_surface_function
4648
public pcmsolver_save_surface_functions
4749
public pcmsolver_save_surface_function
4850
public pcmsolver_load_surface_function
@@ -178,6 +180,16 @@ function pcmsolver_compute_polarization_energy(context, mep_name, asc_name) resu
178180
end function pcmsolver_compute_polarization_energy
179181
end interface pcmsolver_compute_polarization_energy
180182

183+
interface pcmsolver_get_asc_dipole
184+
function pcmsolver_get_asc_dipole(context, asc_name, dipole) result(mu) bind(C)
185+
import
186+
type(c_ptr), value :: context
187+
character(kind=c_char, len=1), intent(in) :: asc_name(*)
188+
real(c_double), intent(inout) :: dipole(*)
189+
real(c_double) :: mu
190+
end function pcmsolver_get_asc_dipole
191+
end interface pcmsolver_get_asc_dipole
192+
181193
interface pcmsolver_get_surface_function
182194
subroutine pcmsolver_get_surface_function(context, f_size, values, name) bind(C)
183195
import
@@ -198,6 +210,14 @@ subroutine pcmsolver_set_surface_function(context, f_size, values, name) bind(C)
198210
end subroutine pcmsolver_set_surface_function
199211
end interface pcmsolver_set_surface_function
200212

213+
interface pcmsolver_print_surface_function
214+
subroutine pcmsolver_print_surface_function(context, name) bind(C)
215+
import
216+
type(c_ptr), value :: context
217+
character(c_char), intent(in) :: name
218+
end subroutine pcmsolver_print_surface_function
219+
end interface pcmsolver_print_surface_function
220+
201221
interface pcmsolver_save_surface_functions
202222
subroutine pcmsolver_save_surface_functions(context) bind(C)
203223
import

api/pcmsolver.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define PCMSOLVER_H_INCLUDED
2626

2727
#include <stddef.h>
28+
#include "PCMInput.h"
2829

2930
#ifndef PCMSOLVER_API
3031
#ifdef _WIN32
@@ -207,6 +208,16 @@ PCMSOLVER_API void pcmsolver_compute_response_asc(pcmsolver_context_t * context,
207208
PCMSOLVER_API double pcmsolver_compute_polarization_energy(
208209
pcmsolver_context_t * context, const char * mep_name, const char * asc_name);
209210

211+
/*! \brief Getter for the ASC dipole
212+
* \param[in, out] context the PCM context object
213+
* \param[in] asc_name label of the ASC surface function
214+
* \param[out] dipole the Cartesian components of the ASC dipole moment
215+
* \return the ASC dipole, i.e. \sqrt{\sum_i \mu_i^2}
216+
*/
217+
PCMSOLVER_API double pcmsolver_get_asc_dipole(pcmsolver_context_t * context,
218+
const char * asc_name,
219+
double dipole[]);
220+
210221
/*! \brief Retrieves data wrapped in a given surface function
211222
* \param[in, out] context the PCM context object
212223
* \param[in] size the size of the surface function
@@ -227,6 +238,13 @@ PCMSOLVER_API void pcmsolver_set_surface_function(pcmsolver_context_t * context,
227238
int size, double values[],
228239
const char * name);
229240

241+
/*! \brief Prints surface function contents to host output
242+
* \param[in, out] context the PCM context object
243+
* \param[in] name label of the surface function
244+
*/
245+
PCMSOLVER_API void pcmsolver_print_surface_function(pcmsolver_context_t * context,
246+
const char * name);
247+
230248
/*! \brief Dumps all currently saved surface functions to NumPy arrays in .npy files
231249
* \param[in, out] context the PCM context object
232250
*/

cmake/autocmake.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: PCMSolver
2+
min_cmake_version: 2.8.10
3+
setup_script: setup.py
4+
url_root: https://github.com/coderefinery/autocmake/raw/master/
5+
6+
modules:
7+
- compilers:
8+
- source:
9+
- '%(url_root)modules/fc.cmake'
10+
- '%(url_root)modules/cc.cmake'
11+
- '%(url_root)modules/cxx.cmake'
12+
- flags:
13+
- source:
14+
- 'custom/compilers/Fortran_C.cmake'
15+
- 'custom/compilers/CXXFlags.cmake'
16+
- 'custom/compilers/CFlags.cmake'
17+
- 'custom/compilers/FortranFlags.cmake'
18+
- plugins:
19+
- source:
20+
- '%(url_root)modules/ccache.cmake'
21+
- 'custom/rpath.cmake'
22+
- 'custom/windows.cmake'
23+
- '%(url_root)modules/definitions.cmake'
24+
- '%(url_root)modules/code_coverage.cmake'
25+
- '%(url_root)modules/int64.cmake'
26+
- '%(url_root)modules/omp.cmake'
27+
- '%(url_root)modules/safeguards.cmake'
28+
- '%(url_root)modules/python_interpreter.cmake'
29+
- 'custom/pcmsolver.cmake'
30+
- '%(url_root)modules/git_info/git_info.cmake'
31+
- boost:
32+
- major: 1
33+
- minor: 54
34+
- patch: 0
35+
- source: '%(url_root)modules/boost/boost.cmake'
36+
- general:
37+
- source:
38+
- 'custom/version.cmake'
39+
- 'custom/static_library.cmake'
40+
- 'custom/catch.cmake'
41+
- 'custom/eigen.cmake'
42+
- 'custom/libtaylor.cmake'
43+
- 'custom/zlib.cmake'
44+
- 'custom/autogenerated.cmake'
45+
- 'custom/documentation.cmake'
46+
- 'custom/api.cmake'
47+
- src:
48+
- source: '%(url_root)modules/src.cmake'
49+
- custom:
50+
- source:
51+
- 'custom/test.cmake'
52+
- 'custom/summary.cmake'

cmake/autocmake/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '1.0.0-alpha-x'

cmake/autocmake/configure.py

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import os
2+
import sys
3+
4+
5+
def module_exists(module_name):
6+
try:
7+
__import__(module_name)
8+
except ImportError:
9+
return False
10+
else:
11+
return True
12+
13+
14+
def check_cmake_exists(cmake_command):
15+
"""
16+
Check whether CMake is installed. If not, print
17+
informative error message and quits.
18+
"""
19+
from subprocess import Popen, PIPE
20+
21+
p = Popen('{0} --version'.format(cmake_command),
22+
shell=True,
23+
stdin=PIPE,
24+
stdout=PIPE)
25+
if not ('cmake version' in p.communicate()[0].decode('UTF-8')):
26+
sys.stderr.write(' This code is built using CMake\n\n')
27+
sys.stderr.write(' CMake is not found\n')
28+
sys.stderr.write(' get CMake at http://www.cmake.org/\n')
29+
sys.stderr.write(' on many clusters CMake is installed\n')
30+
sys.stderr.write(' but you have to load it first:\n')
31+
sys.stderr.write(' $ module load cmake\n')
32+
sys.exit(1)
33+
34+
35+
def setup_build_path(build_path):
36+
"""
37+
Create build directory. If this already exists, print informative
38+
error message and quit.
39+
"""
40+
if os.path.isdir(build_path):
41+
fname = os.path.join(build_path, 'CMakeCache.txt')
42+
if os.path.exists(fname):
43+
sys.stderr.write('aborting setup\n')
44+
sys.stderr.write('build directory {0} which contains CMakeCache.txt already exists\n'.format(build_path))
45+
sys.stderr.write('remove the build directory and then rerun setup\n')
46+
sys.exit(1)
47+
else:
48+
os.makedirs(build_path, 0o755)
49+
50+
51+
def test_adapt_cmake_command_to_platform():
52+
53+
cmake_command = "FC=foo CC=bar CXX=RABOOF cmake -DTHIS -DTHAT='this and that cmake' .."
54+
res = adapt_cmake_command_to_platform(cmake_command, 'linux')
55+
assert res == cmake_command
56+
res = adapt_cmake_command_to_platform(cmake_command, 'win32')
57+
assert res == "set FC=foo && set CC=bar && set CXX=RABOOF && cmake -DTHIS -DTHAT='this and that cmake' .."
58+
59+
cmake_command = "cmake -DTHIS -DTHAT='this and that cmake' .."
60+
res = adapt_cmake_command_to_platform(cmake_command, 'linux')
61+
assert res == cmake_command
62+
res = adapt_cmake_command_to_platform(cmake_command, 'win32')
63+
assert res == cmake_command
64+
65+
66+
def adapt_cmake_command_to_platform(cmake_command, platform):
67+
"""
68+
Adapt CMake command to MS Windows platform.
69+
"""
70+
if platform == 'win32':
71+
pos = cmake_command.find('cmake')
72+
s = ['set {0} &&'.format(e) for e in cmake_command[:pos].split()]
73+
s.append(cmake_command[pos:])
74+
return ' '.join(s)
75+
else:
76+
return cmake_command
77+
78+
79+
def run_cmake(command, build_path, default_build_path):
80+
"""
81+
Execute CMake command.
82+
"""
83+
from subprocess import Popen, PIPE
84+
from shutil import rmtree
85+
86+
topdir = os.getcwd()
87+
os.chdir(build_path)
88+
p = Popen(command,
89+
shell=True,
90+
stdin=PIPE,
91+
stdout=PIPE,
92+
stderr=PIPE)
93+
stdout_coded, stderr_coded = p.communicate()
94+
stdout = stdout_coded.decode('UTF-8')
95+
stderr = stderr_coded.decode('UTF-8')
96+
97+
# print cmake output to screen
98+
print(stdout)
99+
100+
if stderr:
101+
sys.stderr.write(stderr)
102+
sys.exit(1)
103+
104+
# write cmake output to file
105+
with open('cmake_output', 'w') as f:
106+
f.write(stdout)
107+
108+
# change directory and return
109+
os.chdir(topdir)
110+
111+
if 'Configuring incomplete' in stdout:
112+
# configuration was not successful
113+
if (build_path == default_build_path):
114+
# remove build_path iff not set by the user
115+
# otherwise removal can be dangerous
116+
rmtree(default_build_path)
117+
else:
118+
# configuration was successful
119+
save_setup_command(sys.argv, build_path)
120+
print_build_help(build_path, default_build_path)
121+
122+
123+
def print_build_help(build_path, default_build_path):
124+
"""
125+
Print help text after configuration step is done.
126+
"""
127+
print(' configure step is done')
128+
print(' now you need to compile the sources:')
129+
if (build_path == default_build_path):
130+
print(' $ cd build')
131+
else:
132+
print(' $ cd ' + build_path)
133+
print(' $ make')
134+
135+
136+
def save_setup_command(argv, build_path):
137+
"""
138+
Save setup command to a file.
139+
"""
140+
file_name = os.path.join(build_path, 'setup_command')
141+
with open(file_name, 'w') as f:
142+
f.write(' '.join(argv[:]) + '\n')
143+
144+
145+
def configure(root_directory, build_path, cmake_command, only_show):
146+
"""
147+
Main configure function.
148+
"""
149+
default_build_path = os.path.join(root_directory, 'build')
150+
151+
# check that CMake is available, if not stop
152+
check_cmake_exists('cmake')
153+
154+
# deal with build path
155+
if build_path is None:
156+
build_path = default_build_path
157+
if not only_show:
158+
setup_build_path(build_path)
159+
160+
cmake_command = adapt_cmake_command_to_platform(cmake_command, sys.platform)
161+
162+
print('{0}\n'.format(cmake_command))
163+
if only_show:
164+
sys.exit(0)
165+
166+
run_cmake(cmake_command, build_path, default_build_path)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty - this line is here to avoid problem when fetching empty files from web

0 commit comments

Comments
 (0)