diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d4dcdcff88..aaa0885072 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -135,13 +135,11 @@ set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Use compiler extensions") # ugly hacks for MSVC which by default always reports an old C++ standard in the __cplusplus macro # and prints lots of pointless warnings about "unsafe" functions if(MSVC) - if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")) add_compile_options(/Zc:__cplusplus) add_compile_options(/wd4244) add_compile_options(/wd4267) - if(LAMMPS_EXCEPTIONS) - add_compile_options(/EHsc) - endif() + add_compile_options(/EHsc) endif() add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() diff --git a/doc/src/Developer_utils.rst b/doc/src/Developer_utils.rst index 43f12ef377..e1a5f7741d 100644 --- a/doc/src/Developer_utils.rst +++ b/doc/src/Developer_utils.rst @@ -208,7 +208,7 @@ Argument processing Convenience functions ^^^^^^^^^^^^^^^^^^^^^ -.. doxygenfunction:: logmesg(LAMMPS *lmp, const S &format, Args&&... args) +.. doxygenfunction:: logmesg(LAMMPS *lmp, const std::string &format, Args&&... args) :project: progguide .. doxygenfunction:: logmesg(LAMMPS *lmp, const std::string &mesg) diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index fef2ec8def..dd848a812e 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -38,11 +38,11 @@ found together with equivalent examples in C and C++ in the .. note:: - A contributed (and complete!) Fortran interface that more - closely resembles the C-library interface is available - in the ``examples/COUPLE/fortran2`` folder. Please see the - ``README`` file in that folder for more information about it - and how to contact its author and maintainer. + A contributed (and more complete!) Fortran interface that more + closely resembles the C-library interface is available in the + ``examples/COUPLE/fortran2`` folder. Please see the ``README`` file + in that folder for more information about it and how to contact its + author and maintainer. ---------- @@ -65,8 +65,9 @@ the optional logical argument set to ``.true.``. Here is a simple example: PROGRAM testlib USE LIBLAMMPS ! include the LAMMPS library interface + IMPLICIT NONE TYPE(lammps) :: lmp ! derived type to hold LAMMPS instance - CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = & + CHARACTER(len=*), PARAMETER :: args(3) = & [ CHARACTER(len=12) :: 'liblammps', '-log', 'none' ] ! create a LAMMPS instance (and initialize MPI) @@ -78,6 +79,41 @@ the optional logical argument set to ``.true.``. Here is a simple example: END PROGRAM testlib +It is also possible to pass command line flags from Fortran to C/C++ and +thus make the resulting executable behave similar to the standalone +executable (it will ignore the `-in/-i` flag, though). This allows to +use the command line to configure accelerator and suffix settings, +configure screen and logfile output, or to set index style variables +from the command line and more. Here is a correspondingly adapted +version of the previous example: + +.. code-block:: fortran + + PROGRAM testlib2 + USE LIBLAMMPS ! include the LAMMPS library interface + IMPLICIT NONE + TYPE(lammps) :: lmp ! derived type to hold LAMMPS instance + CHARACTER(len=128), ALLOCATABLE :: command_args(:) + INTEGER :: i, argc + + ! copy command line flags to `command_args()` + argc = COMMAND_ARGUMENT_COUNT() + ALLOCATE(command_args(0:argc)) + DO i=0, argc + CALL GET_COMMAND_ARGUMENT(i, command_args(i)) + END DO + + ! create a LAMMPS instance (and initialize MPI) + lmp = lammps(command_args) + ! get and print numerical version code + PRINT*, 'Program name: ', command_args(0) + PRINT*, 'LAMMPS Version: ', lmp%version() + ! delete LAMMPS instance (and shuts down MPI) + CALL lmp%close(.TRUE.) + DEALLOCATE(command_args) + + END PROGRAM testlib2 + -------------------- Executing LAMMPS commands @@ -102,7 +138,7 @@ Below is a small demonstration of the uses of the different functions: USE LIBLAMMPS TYPE(lammps) :: lmp CHARACTER(len=512) :: cmds - CHARACTER(len=40),ALLOCATABLE :: cmdlist(:) + CHARACTER(len=40), ALLOCATABLE :: cmdlist(:) CHARACTER(len=10) :: trimmed INTEGER :: i @@ -111,10 +147,10 @@ Below is a small demonstration of the uses of the different functions: CALL lmp%command('variable zpos index 1.0') ! define 10 groups of 10 atoms each ALLOCATE(cmdlist(10)) - DO i=1,10 + DO i=1, 10 WRITE(trimmed,'(I10)') 10*i WRITE(cmdlist(i),'(A,I1,A,I10,A,A)') & - 'group g',i-1,' id ',10*(i-1)+1,':',ADJUSTL(trimmed) + 'group g', i-1, ' id ', 10*(i-1)+1, ':', ADJUSTL(trimmed) END DO CALL lmp%commands_list(cmdlist) ! run multiple commands from multi-line string @@ -123,7 +159,7 @@ Below is a small demonstration of the uses of the different functions: 'create_box 1 box' // NEW_LINE('A') // & 'create_atoms 1 single 1.0 1.0 ${zpos}' CALL lmp%commands_string(cmds) - CALL lmp%close() + CALL lmp%close(.TRUE.) END PROGRAM testcmd @@ -137,9 +173,9 @@ of the contents of the ``LIBLAMMPS`` Fortran interface to LAMMPS. .. f:type:: lammps - Derived type that is the general class of the Fortran interface. - It holds a reference to the :cpp:class:`LAMMPS ` class instance - that any of the included calls are forwarded to. + Derived type that is the general class of the Fortran interface. It + holds a reference to the :cpp:class:`LAMMPS ` + class instance that any of the included calls are forwarded to. :f c_ptr handle: reference to the LAMMPS class :f close: :f:func:`close` @@ -202,7 +238,7 @@ of the contents of the ``LIBLAMMPS`` Fortran interface to LAMMPS. This method will call :cpp:func:`lammps_commands_list` to have LAMMPS execute a list of input lines. - :p character(len=*) cmd(*): list of LAMMPS input lines + :p character(len=*) cmd(:): list of LAMMPS input lines .. f:subroutine:: commands_string(str) @@ -210,4 +246,3 @@ of the contents of the ``LIBLAMMPS`` Fortran interface to LAMMPS. execute a block of commands from a string. :p character(len=*) str: LAMMPS input in string - diff --git a/doc/src/Manual.rst b/doc/src/Manual.rst index 962810181f..14d4862c40 100644 --- a/doc/src/Manual.rst +++ b/doc/src/Manual.rst @@ -49,12 +49,12 @@ descriptions of all commands included in the LAMMPS code. ---------- +.. _user_documentation: ************ User Guide ************ -.. _user_documentation: .. toctree:: :maxdepth: 2 :numbered: 3 @@ -75,11 +75,12 @@ User Guide Errors +.. _programmer_documentation: + ****************** Programmer Guide ****************** -.. _programmer_documentation: .. toctree:: :maxdepth: 2 :numbered: 3 diff --git a/doc/src/Packages_details.rst b/doc/src/Packages_details.rst index 5b309f9f53..1da162a3c1 100644 --- a/doc/src/Packages_details.rst +++ b/doc/src/Packages_details.rst @@ -158,7 +158,7 @@ AMOEBA package **Contents:** Implementation of the AMOEBA and HIPPO polarized force fields -orginally developed by Jay Ponder's group at the U Washington at St +originally developed by Jay Ponder's group at the U Washington at St Louis. The LAMMPS implementation is based on Fortran 90 code provided by the Ponder group in their `Tinker MD software `_. diff --git a/doc/src/variable.rst b/doc/src/variable.rst index d5c05a205e..3986624c3b 100644 --- a/doc/src/variable.rst +++ b/doc/src/variable.rst @@ -66,7 +66,7 @@ Syntax bound(group,dir,region), gyration(group,region), ke(group,reigon), angmom(group,dim,region), torque(group,dim,region), inertia(group,dimdim,region), omega(group,dim,region) - special functions = sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x), is_file(name), extract_setting(name) + special functions = sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x), is_file(name), is_os(name), extract_setting(name) feature functions = is_active(category,feature), is_available(category,feature), is_defined(category,id) atom value = id[i], mass[i], type[i], mol[i], x[i], y[i], z[i], vx[i], vy[i], vz[i], fx[i], fy[i], fz[i], q[i] atom vector = id, mass, type, mol, x, y, z, vx, vy, vz, fx, fy, fz, q @@ -939,6 +939,20 @@ The is_file(name) function is a test whether *name* is a (readable) file and returns 1 in this case, otherwise it returns 0. For that *name* is taken as a literal string and must not have any blanks in it. +The is_os(name) function is a test whether *name* is part of the OS +information that LAMMPS collects and provides in the +:cpp:func:`platform::os_info() ` function. +The argument *name* is interpreted as a regular expression as documented +for the :cpp:func:`utils::strmatch() ` +function. This allows to adapt LAMMPS inputs to the OS it runs on: + +.. code-block:: LAMMPS + + if $(is_os(^Windows)) then & + "shell copy ${input_dir}\some_file.txt ." & + else & + "shell cp ${input_dir}/some_file.txt ." + The extract_setting(name) function enables access to basic settings for the LAMMPS executable and the running simulation via calling the :cpp:func:`lammps_extract_setting` library function. For example, the @@ -1002,7 +1016,7 @@ step .. code-block:: LAMMPS - timestep $(2.0*(1.0+2.0*is_active(pair,respa)) + timestep $(2.0*(1.0+2.0*is_active(pair,respa))) if $(is_active(pair,respa)) then "run_style respa 4 3 2 2 improper 1 inner 2 5.5 7.0 outer 3 kspace 4" else "run_style respa 3 3 2 improper 1 pair 2 kspace 3" The *is_available(category,name)* function allows to query whether diff --git a/doc/utils/sphinx-config/_static/css/lammps.css b/doc/utils/sphinx-config/_static/css/lammps.css index 900054eeeb..cbf08c3da1 100644 --- a/doc/utils/sphinx-config/_static/css/lammps.css +++ b/doc/utils/sphinx-config/_static/css/lammps.css @@ -39,6 +39,18 @@ hr { display: none; } +#userdoc.toctree-wrapper.compound p { + display: none; +} + +#progdoc.toctree-wrapper.compound p { + display: none; +} + +#reference.toctree-wrapper.compound p { + display: none; +} + .ui.tabular.menu .item { padding-right: 1em; padding-left: 1em; diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index 2e78cdd00b..144fd15652 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -54,20 +54,18 @@ MODULE LIBLAMMPS ! interface definitions for calling functions in library.cpp INTERFACE - FUNCTION lammps_open(argc,argv,comm) & - BIND(C, name='lammps_open_fortran') + FUNCTION lammps_open(argc, argv, comm) BIND(C, name='lammps_open_fortran') IMPORT :: c_ptr, c_int INTEGER(c_int), VALUE, INTENT(in) :: argc, comm TYPE(c_ptr), DIMENSION(*), INTENT(in) :: argv TYPE(c_ptr) :: lammps_open END FUNCTION lammps_open - FUNCTION lammps_open_no_mpi(argc,argv,handle) & - BIND(C, name='lammps_open_no_mpi') + FUNCTION lammps_open_no_mpi(argc, argv, handle) BIND(C, name='lammps_open_no_mpi') IMPORT :: c_ptr, c_int INTEGER(c_int), VALUE, INTENT(in) :: argc TYPE(c_ptr), DIMENSION(*), INTENT(in) :: argv - TYPE(c_ptr), INTENT(out) :: handle + TYPE(c_ptr), VALUE, INTENT(in) :: handle TYPE(c_ptr) :: lammps_open_no_mpi END FUNCTION lammps_open_no_mpi @@ -85,28 +83,26 @@ MODULE LIBLAMMPS SUBROUTINE lammps_kokkos_finalize() BIND(C, name='lammps_kokkos_finalize') END SUBROUTINE lammps_kokkos_finalize - SUBROUTINE lammps_file(handle,filename) BIND(C, name='lammps_file') + SUBROUTINE lammps_file(handle, filename) BIND(C, name='lammps_file') IMPORT :: c_ptr TYPE(c_ptr), VALUE :: handle TYPE(c_ptr), VALUE :: filename END SUBROUTINE lammps_file - SUBROUTINE lammps_command(handle,cmd) BIND(C, name='lammps_command') + SUBROUTINE lammps_command(handle, cmd) BIND(C, name='lammps_command') IMPORT :: c_ptr TYPE(c_ptr), VALUE :: handle TYPE(c_ptr), VALUE :: cmd END SUBROUTINE lammps_command - SUBROUTINE lammps_commands_list(handle,ncmd,cmds) & - BIND(C, name='lammps_commands_list') + SUBROUTINE lammps_commands_list(handle, ncmd, cmds) BIND(C, name='lammps_commands_list') IMPORT :: c_ptr, c_int TYPE(c_ptr), VALUE :: handle INTEGER(c_int), VALUE, INTENT(in) :: ncmd TYPE(c_ptr), DIMENSION(*), INTENT(in) :: cmds END SUBROUTINE lammps_commands_list - SUBROUTINE lammps_commands_string(handle,str) & - BIND(C, name='lammps_commands_string') + SUBROUTINE lammps_commands_string(handle, str) BIND(C, name='lammps_commands_string') IMPORT :: c_ptr TYPE(c_ptr), VALUE :: handle TYPE(c_ptr), VALUE :: str @@ -137,24 +133,22 @@ MODULE LIBLAMMPS END INTERFACE CONTAINS - ! Fortran wrappers and helper functions. ! Constructor for the LAMMPS class. ! Combined wrapper around lammps_open_fortran() and lammps_open_no_mpi() - TYPE(lammps) FUNCTION lmp_open(args,comm) + TYPE(lammps) FUNCTION lmp_open(args, comm) IMPLICIT NONE - INTEGER,INTENT(in), OPTIONAL :: comm + INTEGER, INTENT(in), OPTIONAL :: comm CHARACTER(len=*), INTENT(in), OPTIONAL :: args(:) TYPE(c_ptr), ALLOCATABLE :: argv(:) - TYPE(c_ptr) :: dummy=c_null_ptr - INTEGER :: i,argc + INTEGER(c_int) :: i, c_comm, argc IF (PRESENT(args)) THEN - ! convert argument list to c style + ! convert fortran argument list to c style argc = SIZE(args) ALLOCATE(argv(argc)) - DO i=1,argc + DO i=1, argc argv(i) = f2c_string(args(i)) END DO ELSE @@ -164,23 +158,24 @@ CONTAINS ENDIF IF (PRESENT(comm)) THEN - lmp_open%handle = lammps_open(argc,argv,comm) + c_comm = comm + lmp_open%handle = lammps_open(argc, argv, c_comm) ELSE - lmp_open%handle = lammps_open_no_mpi(argc,argv,dummy) + lmp_open%handle = lammps_open_no_mpi(argc, argv, c_null_ptr) END IF ! Clean up allocated memory - DO i=1,argc + DO i=1, argc CALL lammps_free(argv(i)) END DO DEALLOCATE(argv) END FUNCTION lmp_open ! Combined Fortran wrapper around lammps_close() and lammps_mpi_finalize() - SUBROUTINE lmp_close(self,finalize) + SUBROUTINE lmp_close(self, finalize) IMPLICIT NONE CLASS(lammps) :: self - LOGICAL,INTENT(in),OPTIONAL :: finalize + LOGICAL, INTENT(in), OPTIONAL :: finalize CALL lammps_close(self%handle) @@ -206,68 +201,69 @@ CONTAINS lmp_get_natoms = lammps_get_natoms(self%handle) END FUNCTION lmp_get_natoms - SUBROUTINE lmp_file(self,filename) + SUBROUTINE lmp_file(self, filename) IMPLICIT NONE CLASS(lammps) :: self CHARACTER(len=*) :: filename TYPE(c_ptr) :: str str = f2c_string(filename) - CALL lammps_file(self%handle,str) + CALL lammps_file(self%handle, str) CALL lammps_free(str) END SUBROUTINE lmp_file ! equivalent function to lammps_command() - SUBROUTINE lmp_command(self,cmd) + SUBROUTINE lmp_command(self, cmd) IMPLICIT NONE CLASS(lammps) :: self CHARACTER(len=*) :: cmd TYPE(c_ptr) :: str str = f2c_string(cmd) - CALL lammps_command(self%handle,str) + CALL lammps_command(self%handle, str) CALL lammps_free(str) END SUBROUTINE lmp_command ! equivalent function to lammps_commands_list() - SUBROUTINE lmp_commands_list(self,cmds) + SUBROUTINE lmp_commands_list(self, cmds) IMPLICIT NONE CLASS(lammps) :: self CHARACTER(len=*), INTENT(in), OPTIONAL :: cmds(:) TYPE(c_ptr), ALLOCATABLE :: cmdv(:) - INTEGER :: i,ncmd + INTEGER :: i, ncmd ! convert command list to c style ncmd = SIZE(cmds) ALLOCATE(cmdv(ncmd)) - DO i=1,ncmd + DO i=1, ncmd cmdv(i) = f2c_string(cmds(i)) END DO - CALL lammps_commands_list(self%handle,ncmd,cmdv) + CALL lammps_commands_list(self%handle, ncmd, cmdv) ! Clean up allocated memory - DO i=1,ncmd + DO i=1, ncmd CALL lammps_free(cmdv(i)) END DO DEALLOCATE(cmdv) END SUBROUTINE lmp_commands_list ! equivalent function to lammps_commands_string() - SUBROUTINE lmp_commands_string(self,str) + SUBROUTINE lmp_commands_string(self, str) IMPLICIT NONE CLASS(lammps) :: self CHARACTER(len=*) :: str TYPE(c_ptr) :: tmp tmp = f2c_string(str) - CALL lammps_commands_string(self%handle,tmp) + CALL lammps_commands_string(self%handle, tmp) CALL lammps_free(tmp) END SUBROUTINE lmp_commands_string ! ---------------------------------------------------------------------- ! local helper functions ! copy fortran string to zero terminated c string + ! ---------------------------------------------------------------------- FUNCTION f2c_string(f_string) RESULT(ptr) CHARACTER (len=*), INTENT(in) :: f_string CHARACTER (len=1, kind=c_char), POINTER :: c_string(:) @@ -276,8 +272,8 @@ CONTAINS n = LEN_TRIM(f_string) ptr = lammps_malloc(n+1) - CALL C_F_POINTER(ptr,c_string,[1]) - DO i=1,n + CALL C_F_POINTER(ptr, c_string, [1]) + DO i=1, n c_string(i) = f_string(i:i) END DO c_string(n+1) = c_null_char diff --git a/src/fix_store_peratom.h b/src/fix_store_peratom.h index 7e288a6c54..fcabae75b7 100644 --- a/src/fix_store_peratom.h +++ b/src/fix_store_peratom.h @@ -54,8 +54,6 @@ class FixStorePeratom : public Fix { int n2, n3; // size of 3d dims of per-atom data struct int nvalues; // number of per-atom values int nbytes; // number of per-atom bytes - - double *rbuf; // restart buffer for GLOBAL vec/array/tensor }; } // namespace LAMMPS_NS diff --git a/src/library.cpp b/src/library.cpp index cdc0a812c5..584504599e 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -234,7 +234,7 @@ fails a null pointer is returned. void *lammps_open_no_mpi(int argc, char **argv, void **ptr) { - return lammps_open(argc,argv,MPI_COMM_WORLD,ptr); + return lammps_open(argc, argv, MPI_COMM_WORLD, ptr); } /* ---------------------------------------------------------------------- */ diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 03e22f46c5..b6b095ddf4 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1354,7 +1354,7 @@ void Neighbor::morph_granular() void Neighbor::morph_halffull() { - int i,j,jj,jmin; + int i,j,jj; NeighRequest *irq,*jrq; double icut,jcut; @@ -1438,7 +1438,7 @@ void Neighbor::morph_halffull() void Neighbor::morph_copy_trim() { - int i,j,jj,jmin,inewton,jnewton; + int i,j,jj,inewton,jnewton; NeighRequest *irq,*jrq; double icut,jcut; diff --git a/src/npair_trim.cpp b/src/npair_trim.cpp index 5d854b745e..01abeed636 100644 --- a/src/npair_trim.cpp +++ b/src/npair_trim.cpp @@ -33,7 +33,7 @@ void NPairTrim::build(NeighList *list) double cutsq_custom = cutoff_custom * cutoff_custom; - int i,j,ii,jj,n,jnum,joriginal; + int ii,jj,n,jnum,joriginal; int *neighptr,*jlist; double xtmp,ytmp,ztmp; double delx,dely,delz,rsq; @@ -71,7 +71,7 @@ void NPairTrim::build(NeighList *list) for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; - j = joriginal & NEIGHMASK; + const int j = joriginal & NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; diff --git a/src/variable.cpp b/src/variable.cpp index 168ccfa1cd..a564847b68 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -3942,7 +3942,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree, Tree **t strcmp(word,"trap") != 0 && strcmp(word,"slope") != 0 && strcmp(word,"gmask") != 0 && strcmp(word,"rmask") != 0 && strcmp(word,"grmask") != 0 && strcmp(word,"next") != 0 && strcmp(word,"is_active") != 0 && strcmp(word,"is_defined") != 0 && strcmp(word,"is_available") != 0 && strcmp(word,"is_file") != 0 && - strcmp(word,"extract_setting") != 0) + strcmp(word,"is_os") != 0 && strcmp(word,"extract_setting") != 0) return 0; // parse contents for comma-separated args @@ -4340,6 +4340,19 @@ int Variable::special_function(char *word, char *contents, Tree **tree, Tree **t treestack[ntreestack++] = newtree; } else argstack[nargstack++] = value; + } else if (strcmp(word,"is_os") == 0) { + if (narg != 1) print_var_error(FLERR,"Invalid is_os() function in variable formula",ivar); + value = utils::strmatch(platform::os_info(), args[0]) ? 1.0 : 0.0; + + // save value in tree or on argstack + + if (tree) { + auto newtree = new Tree(); + newtree->type = VALUE; + newtree->value = value; + treestack[ntreestack++] = newtree; + } else argstack[nargstack++] = value; + } else if (strcmp(word,"extract_setting") == 0) { if (narg != 1) print_var_error(FLERR,"Invalid extract_setting() function in variable formula",ivar); diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 29b985927d..cf124eeafd 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -144,12 +144,14 @@ TEST_F(VariableTest, CreateDelete) command("variable ten3 uloop 4 pad"); command("variable dummy index 0"); command("variable file equal is_file(MYFILE)"); + command("variable iswin equal is_os(^Windows)"); + command("variable islin equal is_os(^Linux)"); END_HIDE_OUTPUT(); - ASSERT_EQ(variable->nvar, 18); + ASSERT_EQ(variable->nvar, 20); BEGIN_HIDE_OUTPUT(); command("variable dummy delete"); END_HIDE_OUTPUT(); - ASSERT_EQ(variable->nvar, 17); + ASSERT_EQ(variable->nvar, 19); ASSERT_THAT(variable->retrieve("three"), StrEq("three")); variable->set_string("three", "four"); ASSERT_THAT(variable->retrieve("three"), StrEq("four")); @@ -168,6 +170,17 @@ TEST_F(VariableTest, CreateDelete) platform::unlink("MYFILE"); ASSERT_THAT(variable->retrieve("file"), StrEq("0")); +#if defined(_WIN32) + ASSERT_THAT(variable->retrieve("iswin"), StrEq("1")); + ASSERT_THAT(variable->retrieve("islin"), StrEq("0")); +#elif defined(__linux__) + ASSERT_THAT(variable->retrieve("iswin"), StrEq("0")); + ASSERT_THAT(variable->retrieve("islin"), StrEq("1")); +#else + ASSERT_THAT(variable->retrieve("iswin"), StrEq("0")); + ASSERT_THAT(variable->retrieve("islin"), StrEq("0")); +#endif + BEGIN_HIDE_OUTPUT(); command("variable seven delete"); command("variable seven getenv TEST_VARIABLE"); diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 85546c1510..d2345ceaa7 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -36,7 +36,11 @@ if(Python_EXECUTABLE) COMMENT "Check completeness of force style tests") endif() -set(TEST_INPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/tests) +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + string(REPLACE "/" "\\\\" TEST_INPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/tests") +else() + set(TEST_INPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/tests) +endif() add_library(style_tests STATIC yaml_writer.cpp error_stats.cpp test_config_reader.cpp test_main.cpp) if(YAML_FOUND) target_compile_definitions(style_tests PRIVATE TEST_INPUT_FOLDER=${TEST_INPUT_FOLDER}) diff --git a/unittest/force-styles/tests/atomic-pair-sw_angle_table.yaml b/unittest/force-styles/tests/atomic-pair-sw_angle_table.yaml index 7229a3cd26..0f8ca18eec 100644 --- a/unittest/force-styles/tests/atomic-pair-sw_angle_table.yaml +++ b/unittest/force-styles/tests/atomic-pair-sw_angle_table.yaml @@ -10,7 +10,7 @@ pre_commands: ! | variable units index real variable newton_pair delete variable newton_pair index on - shell cp ${input_dir}/table_CG_CG_CG.txt . + if $(is_os(^Windows)) then "shell copy ${input_dir}\table_CG_CG_CG.txt ." else "shell cp ${input_dir}/table_CG_CG_CG.txt ." post_commands: ! "" input_file: in.metal pair_style: hybrid/overlay table linear 1200 sw/angle/table diff --git a/unittest/force-styles/tests/atomic-pair-threebody_table.yaml b/unittest/force-styles/tests/atomic-pair-threebody_table.yaml index bb3c8c1c1b..cf3566490e 100644 --- a/unittest/force-styles/tests/atomic-pair-threebody_table.yaml +++ b/unittest/force-styles/tests/atomic-pair-threebody_table.yaml @@ -10,8 +10,8 @@ pre_commands: ! | variable units index real variable newton_pair delete variable newton_pair index on - shell cp ${input_dir}/1-1-1.table . - shell cp ${input_dir}/1-1-2.table . + if $(is_os(^Windows)) then "shell copy ${input_dir}\1-1-1.table ." else "shell cp ${input_dir}/1-1-1.table ." + if $(is_os(^Windows)) then "shell copy ${input_dir}\1-1-2.table ." else "shell cp ${input_dir}/1-1-2.table ." post_commands: ! "" input_file: in.metal pair_style: hybrid/overlay table linear 1200 threebody/table diff --git a/unittest/fortran/CMakeLists.txt b/unittest/fortran/CMakeLists.txt index 047dcf3207..1062766e43 100644 --- a/unittest/fortran/CMakeLists.txt +++ b/unittest/fortran/CMakeLists.txt @@ -17,7 +17,7 @@ if(CMAKE_Fortran_COMPILER) get_filename_component(LAMMPS_FORTRAN_MODULE ${LAMMPS_SOURCE_DIR}/../fortran/lammps.f90 ABSOLUTE) if(BUILD_MPI) find_package(MPI REQUIRED) - if((NOT MPI_Fortran) OR (NOT MPI_Fortran_HAVE_F77_HEADER) OR (NOT MPI_Fortran_HAVE_F90_MODULE)) + if((NOT MPI_Fortran_FOUND) OR (NOT MPI_Fortran_HAVE_F77_HEADER)) message(STATUS "Skipping Tests for the LAMMPS Fortran Module: no MPI support for Fortran") return() endif() @@ -29,7 +29,8 @@ if(CMAKE_Fortran_COMPILER) add_library(flammps STATIC ${LAMMPS_FORTRAN_MODULE}) add_executable(test_fortran_create wrap_create.cpp test_fortran_create.f90) - target_link_libraries(test_fortran_create PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTestMain) + target_link_libraries(test_fortran_create PRIVATE lammps MPI::MPI_Fortran GTest::GTestMain) + target_include_directories(test_fortran_create PRIVATE "${LAMMPS_SOURCE_DIR}/../fortran") add_test(NAME FortranOpen COMMAND test_fortran_create) add_executable(test_fortran_commands wrap_commands.cpp test_fortran_commands.f90) diff --git a/unittest/fortran/test_fortran_create.f90 b/unittest/fortran/test_fortran_create.f90 index e1df7502cb..73fc83aef4 100644 --- a/unittest/fortran/test_fortran_create.f90 +++ b/unittest/fortran/test_fortran_create.f90 @@ -1,3 +1,5 @@ +include 'lammps.f90' + MODULE keepcreate USE liblammps TYPE(LAMMPS) :: lmp @@ -75,10 +77,11 @@ SUBROUTINE f_lammps_close() BIND(C, name="f_lammps_close") END SUBROUTINE f_lammps_close FUNCTION f_lammps_get_comm() BIND(C, name="f_lammps_get_comm") + USE ISO_C_BINDING, ONLY: c_int USE liblammps USE keepcreate, ONLY: mycomm IMPLICIT NONE - INTEGER :: f_lammps_get_comm + INTEGER(c_int) :: f_lammps_get_comm f_lammps_get_comm = mycomm END FUNCTION f_lammps_get_comm