add support to also build an extended tcl shell as opposed to dynamically loading the extension

This commit is contained in:
Axel Kohlmeyer
2020-10-20 18:29:16 -04:00
parent 515f1d9ead
commit 7db669df40
5 changed files with 75 additions and 11 deletions

View File

@ -84,5 +84,9 @@ if(BUILD_SWIG_TCL)
target_include_directories(tcllammps PRIVATE ${TCL_INCLUDE_PATH})
swig_link_libraries(tcllammps PRIVATE lammps ${TCL_LIBRARY})
configure_file(run_tcl_example.sh run_tcl_example.sh COPYONLY)
swig_add_library(libtcllammps TYPE STATIC LANGUAGE tcl SOURCES lammps.i)
add_executable(tcllmpsh tcldummy.c)
target_include_directories(tcllmpsh PRIVATE ${TCL_INCLUDE_PATH})
target_link_libraries(tcllmpsh PRIVATE libtcllammps lammps ${TCL_LIBRARY})
endif()

View File

@ -3,6 +3,10 @@
%include "cdata.i"
%include "cstring.i"
#ifdef SWIGTCL
%include "tclsh.i"
#endif
%pointer_functions(int, int_p);
%pointer_functions(int, int64_p);
%pointer_functions(double, double_p);

View File

@ -53,3 +53,65 @@ lammps_close \$lmp
EOF
tclsh example.tcl
# now try again with static extended shell
echo '====================================================================='
if [ ! -f tcllmpsh ]
then \
echo "Need to compile 'tcllmpsh' first for this script to work"
exit 1
fi
cat > example.tcllmp <<EOF
set osinfo [lammps_get_os_info 512]
puts "[lindex \$osinfo 0] [lindex \$osinfo 1]"
set lmp [lammps_open_no_mpi 0 NULL NULL ]
set ver [lammps_version \$lmp]
set npair_styles [lammps_style_count \$lmp "pair"]
puts "LAMMPS includes \$npair_styles pair styles"
for {set i 0} {\$i < 10} {incr i} {
set style [lammps_style_name \$lmp "pair" \$i 128]
if {[lindex \$style 0]} {puts "Style \$i: [lindex \$style 1]"}
}
lammps_command \$lmp "units real"
lammps_command \$lmp "lattice fcc 2.5"
lammps_command \$lmp "region box block -5 5 -5 5 -5 5"
lammps_command \$lmp "create_box 1 box"
lammps_command \$lmp "create_atoms 1 box"
set boxlo_p [new_double_1d 3]
set boxhi_p [new_double_1d 3]
set xy_p [new_double_p]
set yz_p [new_double_p]
set xz_p [new_double_p]
set pflags_p [new_int_1d 3]
set boxflag_p [new_int_p]
lammps_extract_box \$lmp \$boxlo_p \$boxhi_p \$xy_p \$yz_p \$xz_p \$pflags_p \$boxflag_p
puts [format "boxlo: %g %g %g" [double_1d_getitem \$boxlo_p 0] [double_1d_getitem \$boxlo_p 1] [double_1d_getitem \$boxlo_p 2]]
puts [format "boxhi: %g %g %g" [double_1d_getitem \$boxhi_p 0] [double_1d_getitem \$boxhi_p 1] [double_1d_getitem \$boxhi_p 2]]
puts [format "xy/yz/xz: %g %g %g" [double_p_value \$xy_p] [double_p_value \$yz_p] [double_p_value \$xz_p]]
puts [format "periodicity: %d %d %d" [int_1d_getitem \$pflags_p 0] [int_1d_getitem \$pflags_p 1] [int_1d_getitem \$pflags_p 2]]
puts [format "boxflag: %d" [int_p_value \$boxflag_p]]
delete_double_1d \$boxlo_p
delete_double_1d \$boxhi_p
delete_int_1d \$pflags_p
delete_double_p \$xy_p
delete_double_p \$yz_p
delete_double_p \$xz_p
delete_int_p \$boxflag_p
set dt [double_p_value [void_p_to_double_p [lammps_extract_global \$lmp dt]]]
puts "LAMMPS version \$ver"
puts [format "Number of created atoms: %g" [lammps_get_natoms \$lmp]]
puts "Current size of timestep: \$dt"
lammps_close \$lmp
EOF
${PWD}/tcllmpsh example.tcllmp

5
tools/swig/tcldummy.c Normal file
View File

@ -0,0 +1,5 @@
int i_am_a_dummy_function()
{
return 0;
}

View File

@ -1,11 +0,0 @@
#include <tcl.h>
int AppInit(Tcl_Interp *interp) {
if (Tcl_Init(interp) == TCL_ERROR) return TCL_ERROR;
Tcl_SetVar(interp,"tcl_rcFileName","~/.wishrc",TCL_GLOBAL_ONLY);
return TCL_OK;
}
int main(int argc, char *argv[]) {
Tcl_Main(argc, argv, AppInit);
return 0;
}