Skip to content

Commit 7dbe3f9

Browse files
committed
add USER-BFIELD package/plugin
1 parent 3abfff9 commit 7dbe3f9

File tree

7 files changed

+891
-6
lines changed

7 files changed

+891
-6
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ include(LAMMPSInterfacePlugin)
2020
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
2121

2222
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
23-
add_custom_target(package DEPENDS package-USER-AEAM package-USER-REBOMOS)
23+
add_custom_target(package DEPENDS package-USER-AEAM package-USER-BFIELD package-USER-REBOMOS)
2424
endif()
2525
add_subdirectory(USER-AEAM)
26+
add_subdirectory(USER-BFIELD)
2627
add_subdirectory(USER-REBOMOS)

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
This repository contains source code written for LAMMPS from
22
various sources that is not part of the LAMMPS distribution
33
for a number of reasons, but ported to be compatible with the
4-
23 June 2022 LAMMPS release and converted to create plugins.
4+
2 August 2023 LAMMPS release and converted to create plugins.
55

6-
| Folders | Origin of source code |
7-
|--------------|----------------------------------------------------|
8-
| USER-AEAM | https://github.com/psaidi/AEAM |
9-
| USER-REBOMOS | https://matsci.org/t/pair-rebomos/30503 |
6+
| Folders | Origin of source code |
7+
|--------------|-----------------------------------------------------------------------------|
8+
| USER-AEAM | https://github.com/psaidi/AEAM |
9+
| USER-BFIELD | https://matsci.org/t/discrepency-beween-old-version-and-new-version/50014/5 |
10+
| USER-REBOMOS | https://matsci.org/t/pair-rebomos/30503 |
1011

1112
As of the 22 December 2022 LAMMPS release, the USER-VCSGC package
1213
code has been merged with upstream and the corresponding fix is now

USER-BFIELD/CMakeLists.txt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
##########################################
2+
# CMake build system for plugin examples.
3+
# The is meant to be used as a template for plugins that are
4+
# distributed independent from the LAMMPS package.
5+
##########################################
6+
7+
cmake_minimum_required(VERSION 3.10)
8+
if(POLICY CMP0077)
9+
cmake_policy(SET CMP0077 NEW)
10+
endif()
11+
12+
project(bfieldplugin VERSION 1.0 LANGUAGES CXX)
13+
14+
if(NOT LAMMPS_SOURCE_DIR)
15+
message(FATAL_ERROR "Must set LAMMPS_SOURCE_DIR variable")
16+
endif()
17+
set(CMAKE_MODULE_PATH "${LAMMPS_SOURCE_DIR}/../cmake/Modules")
18+
if (NOT TARGET lammps)
19+
include(CheckIncludeFileCXX)
20+
include(LAMMPSInterfacePlugin)
21+
endif()
22+
23+
##########################
24+
# building the plugins
25+
26+
add_library(bfieldplugin MODULE bfieldplugin.cpp ${CMAKE_CURRENT_SOURCE_DIR}/fix_bfield.cpp)
27+
target_link_libraries(bfieldplugin PRIVATE lammps)
28+
set_target_properties(bfieldplugin PROPERTIES PREFIX "" SUFFIX ".so")
29+
30+
# MacOS seems to need this
31+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
32+
set_target_properties(bfieldplugin PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup")
33+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
34+
# tell CMake to export all symbols to a .dll on Windows with special case for MinGW cross-compilers
35+
set_target_properties(bfieldplugin PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
36+
if(CMAKE_CROSSCOMPILING)
37+
set_target_properties(bfieldplugin PROPERTIES LINK_FLAGS "-Wl,--export-all-symbols")
38+
endif()
39+
40+
get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION)
41+
find_program(MAKENSIS_PATH makensis)
42+
if(MAKENSIS_PATH)
43+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/../lammps.ico
44+
${CMAKE_CURRENT_SOURCE_DIR}/../lammps-text-logo-wide.bmp ${CMAKE_CURRENT_SOURCE_DIR}/bfieldplugin.nsis ${CMAKE_BINARY_DIR})
45+
if(TARGET package)
46+
set(mytarget package-USER-BFIELD)
47+
else()
48+
set(mytarget package)
49+
endif()
50+
if(BUILD_MPI)
51+
if(USE_MSMPI AND CMAKE_CROSSCOMPILING)
52+
add_custom_target(${mytarget} ${MAKENSIS_PATH} -V1 -DVERSION=${LAMMPS_VERSION}-MSMPI bfieldplugin.nsis
53+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
54+
DEPENDS bfieldplugin ${CMAKE_BINARY_DIR}/lammps.ico ${CMAKE_BINARY_DIR}/lammps-text-logo-wide.bmp ${CMAKE_BINARY_DIR}/bfieldplugin.nsis
55+
BYPRODUCTS ${CMAKE_BINARY_DIR}/LAMMPS-USER-BFIELD-plugin-${LAMMPS_VERSION}-MSMPI.exe)
56+
else()
57+
add_custom_target(${mytarget} ${MAKENSIS_PATH} -V1 -DVERSION=${LAMMPS_VERSION}-MPI bfieldplugin.nsis
58+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
59+
DEPENDS bfieldplugin ${CMAKE_BINARY_DIR}/lammps.ico ${CMAKE_BINARY_DIR}/lammps-text-logo-wide.bmp ${CMAKE_BINARY_DIR}/bfieldplugin.nsis
60+
BYPRODUCTS ${CMAKE_BINARY_DIR}/LAMMPS-USER-BFIELD-plugin-${LAMMPS_VERSION}-MPI.exe)
61+
endif()
62+
else()
63+
add_custom_target(${mytarget} ${MAKENSIS_PATH} -V1 -DVERSION=${LAMMPS_VERSION} bfieldplugin.nsis
64+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
65+
DEPENDS bfieldplugin ${CMAKE_BINARY_DIR}/lammps.ico ${CMAKE_BINARY_DIR}/lammps-text-logo-wide.bmp ${CMAKE_BINARY_DIR}/bfieldplugin.nsis
66+
BYPRODUCTS LAMMPS-USER-BFIELD-plugin-${LAMMPS_VERSION}.exe)
67+
endif()
68+
endif()
69+
else()
70+
set_target_properties(bfieldplugin PROPERTIES LINK_FLAGS "-rdynamic")
71+
endif()

USER-BFIELD/bfieldplugin.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
#include "lammpsplugin.h"
3+
4+
#include "version.h"
5+
6+
#include "fix_bfield.h"
7+
8+
using namespace LAMMPS_NS;
9+
10+
static Fix *bfieldcreator(LAMMPS *lmp, int argc, char **argv)
11+
{
12+
return new FixBfield(lmp, argc, argv);
13+
}
14+
15+
extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc)
16+
{
17+
lammpsplugin_t plugin;
18+
lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc;
19+
20+
// register bfield fix style
21+
plugin.version = LAMMPS_VERSION;
22+
plugin.style = "fix";
23+
plugin.name = "bfield";
24+
plugin.info = "fix bfield plugin v1.0";
25+
plugin.author = "Axel Kohlmeyer ([email protected])";
26+
plugin.creator.v2 = (lammpsplugin_factory2 *) &bfieldcreator;
27+
plugin.handle = handle;
28+
(*register_plugin)(&plugin, lmp);
29+
}

USER-BFIELD/bfieldplugin.nsis

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!Nsis Installer Command Script
2+
#
3+
# The following external defines are recognized:
4+
# ${VERSION} = YYYYMMDD
5+
6+
!include "MUI2.nsh"
7+
!include "FileFunc.nsh"
8+
9+
!define MUI_ICON "lammps.ico"
10+
!define MUI_UNICON "lammps.ico"
11+
!define MUI_HEADERIMAGE
12+
!define MUI_HEADERIMAGE_BITMAP "lammps-text-logo-wide.bmp"
13+
!define MUI_HEADERIMAGE_RIGHT
14+
15+
Unicode true
16+
XPStyle on
17+
18+
!include "LogicLib.nsh"
19+
!addplugindir "envvar/Plugins/x86-unicode"
20+
!include "x64.nsh"
21+
22+
RequestExecutionLevel user
23+
24+
!macro VerifyUserIsAdmin
25+
UserInfo::GetAccountType
26+
pop $0
27+
${If} $0 != "admin"
28+
messageBox mb_iconstop "Administrator rights required!"
29+
setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
30+
quit
31+
${EndIf}
32+
!macroend
33+
34+
!define BFIELDPLUGIN "LAMMPS USER-BFIELD Plugin ${VERSION}"
35+
OutFile "LAMMPS-USER-BFIELD-plugin-${VERSION}.exe"
36+
37+
Name "${BFIELDPLUGIN}"
38+
InstallDir "$LOCALAPPDATA\${BFIELDPLUGIN}"
39+
40+
ShowInstDetails show
41+
ShowUninstDetails show
42+
SetCompressor lzma
43+
44+
!define MUI_ABORTWARNING
45+
46+
!insertmacro MUI_PAGE_DIRECTORY
47+
!insertmacro MUI_PAGE_INSTFILES
48+
49+
!insertmacro MUI_UNPAGE_CONFIRM
50+
!insertmacro MUI_UNPAGE_INSTFILES
51+
52+
!insertmacro MUI_LANGUAGE "English"
53+
54+
function .onInit
55+
# Determine if LAMMPS was already installed and check whether it was in 32-bit
56+
# or 64-bit. Then look up path to uninstaller and offer to uninstall or quit
57+
SetRegView 32
58+
ReadRegDWORD $0 HKCU "Software\LAMMPS-USER-BFIELD" "Bits"
59+
SetRegView LastUsed
60+
${If} $0 == "32"
61+
SetRegView 32
62+
${ElseIf} $0 == "64"
63+
SetRegView 64
64+
${Else}
65+
SetRegView 64
66+
${EndIf}
67+
ClearErrors
68+
ReadRegStr $R0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" "UninstallString"
69+
SetRegView LastUsed
70+
${If} ${Errors}
71+
DetailPrint "LAMMPS USER-BFIELD plugin not (yet) installed"
72+
${Else}
73+
MessageBox MB_YESNO "LAMMPS USER-BFIELD plugin ($0 bit) is already installed. Uninstall existing version?" /SD IDYES IDNO Quit
74+
Pop $R1
75+
StrCmp $R1 2 Quit +1
76+
Exec $R0
77+
Quit:
78+
Quit
79+
${EndIf}
80+
setShellVarContext all
81+
functionEnd
82+
83+
Section "${BFIELDPLUGIN}" SecPaceplugin
84+
SectionIn RO
85+
# Write LAMMPS installation bitness marker. Always use 32-bit registry view
86+
SetRegView 32
87+
IntFmt $0 "0x%08X" 64
88+
WriteRegDWORD HKCU "Software\LAMMPS-USER-BFIELD" "Bits" $0
89+
90+
# Switch to "native" registry view
91+
SetRegView 64
92+
SetShellVarContext current
93+
94+
SetOutPath "$INSTDIR"
95+
File lammps.ico
96+
File bfieldplugin.so
97+
98+
# Register Application and its uninstaller
99+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
100+
"DisplayName" "${BFIELDPLUGIN}"
101+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
102+
"Publisher" "The LAMMPS and USER-BFIELD Developers"
103+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
104+
"URLInfoAbout" "lammps.org"
105+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
106+
"DisplayIcon" "$INSTDIR\lammps.ico"
107+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
108+
"DisplayVersion" "${VERSION}"
109+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
110+
"InstallLocation" "$INSTDIR"
111+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
112+
"UninstallString" "$\"$INSTDIR\uninstall.exe$\""
113+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
114+
"QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
115+
116+
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
117+
IntFmt $0 "0x%08X" $0
118+
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD" \
119+
"EstimatedSize" "$0"
120+
121+
# update path variables
122+
EnVar::SetHKCU
123+
# add to LAMMPS plugin search path
124+
EnVar::AddValue "LAMMPS_PLUGIN_PATH" "$INSTDIR"
125+
126+
WriteUninstaller "$INSTDIR\Uninstall.exe"
127+
SectionEnd
128+
129+
function un.onInit
130+
SetShellVarContext current
131+
functionEnd
132+
133+
Section "Uninstall"
134+
# remove LAMMPS bitness/installation indicator always in 32-bit registry view
135+
SetRegView 32
136+
DeleteRegKey HKCU "Software\LAMMPS-USER-BFIELD"
137+
138+
# unregister extension, and uninstall info
139+
SetRegView 64
140+
SetShellVarContext current
141+
# unregister installation
142+
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-BFIELD"
143+
144+
# update path variables
145+
EnVar::SetHKCU
146+
# remove entry from LAMMPS plugin search path
147+
EnVar::DeleteValue "LAMMPS_PLUGIN_PATH" "$INSTDIR"
148+
149+
Delete /REBOOTOK "$INSTDIR\bfieldplugin.so"
150+
Delete /REBOOTOK "$INSTDIR\Uninstall.exe"
151+
Delete /REBOOTOK "$INSTDIR\lammps.ico"
152+
RMDir /REBOOTOK "$INSTDIR"
153+
SectionEnd
154+
155+
# Local Variables:
156+
# mode: sh
157+
# End:

0 commit comments

Comments
 (0)