Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions cpp/lammpsweb/lammpsweb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "error.h"
#include "neigh_list.h"
#include "fix_atomify.h"
#include "fix_wall.h"

using namespace std;

Expand Down Expand Up @@ -674,3 +675,73 @@ void LAMMPSWeb::step() {
void LAMMPSWeb::runCommand(std::string command) {
lammps_commands_string((void *)m_lmp, command.c_str());
}

int LAMMPSWeb::getDimension() {
if (!m_lmp) {
return 3; // default to 3D
}
return m_lmp->domain->dimension;
}

std::vector<WallInfo> LAMMPSWeb::getWalls() {
std::vector<WallInfo> walls;

if (!m_lmp) {
return walls;
}

LAMMPS_NS::Domain *domain = m_lmp->domain;
domain->box_corners();

// Loop through all fixes to find FixWall instances
for (int i = 0; i < m_lmp->modify->nfix; i++) {
LAMMPS_NS::Fix *lmpFix = m_lmp->modify->fix[i];
LAMMPS_NS::FixWall *fixWall = dynamic_cast<LAMMPS_NS::FixWall*>(lmpFix);

if (!fixWall) {
continue;
}

// Extract wall data from this FixWall instance
for (int m = 0; m < fixWall->nwall; m++) {
int which = fixWall->wallwhich[m];
int style = fixWall->xstyle[m];

// Skip NONE and VARIABLE styles
// NONE=0, EDGE=1, CONSTANT=2, VARIABLE=3
if (style == 0 || style == 3) { // NONE or VARIABLE
continue;
}

double position;
if (style == 1) { // EDGE style
int dim = which / 2;
int side = which % 2;
if (side == 0) {
position = domain->boxlo[dim];
} else {
position = domain->boxhi[dim];
}
} else if (style == 2) { // CONSTANT style
position = fixWall->coord0[m];
} else {
// Unknown style, skip
continue;
}

// Get cutoff (it's protected, so we'll use 0 as default)
// For visualization, the exact cutoff isn't critical
double wallCutoff = 0.0;

WallInfo wall;
wall.which = which;
wall.style = style;
wall.position = position;
wall.cutoff = wallCutoff;

walls.push_back(wall);
}
}

return walls;
}
23 changes: 22 additions & 1 deletion cpp/lammpsweb/lammpsweb.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include "atomify_compute.h"
#include "atomify_fix.h"
#include "atomify_variable.h"
#include "fix_wall.h"
#include <iostream>
#include <string>
#include <map>
#include <vector>

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
Expand All @@ -18,6 +20,13 @@
using namespace emscripten;
#endif

struct WallInfo {
int which; // 0-5 (XLO, XHI, YLO, YHI, ZLO, ZHI)
int style; // 0-3 (NONE, EDGE, CONSTANT, VARIABLE)
double position; // current wall position
double cutoff; // interaction range
};

class LAMMPSWeb
{
private:
Expand Down Expand Up @@ -90,6 +99,9 @@ class LAMMPSWeb
void syncFixes();
void syncVariables();

int getDimension();
std::vector<WallInfo> getWalls();

LAMMPS_NS::Fix* findFixByIdentifier(std::string identifier);
LAMMPS_NS::Compute* findComputeByIdentifier(std::string identifier);
int findFixIndex(std::string identifier);
Expand Down Expand Up @@ -145,7 +157,15 @@ EMSCRIPTEN_BINDINGS(LAMMPSWeb)
.function("runCommand", &LAMMPSWeb::runCommand)

.function("computeBonds", &LAMMPSWeb::computeBonds)
.function("computeParticles", &LAMMPSWeb::computeParticles);
.function("computeParticles", &LAMMPSWeb::computeParticles)
.function("getDimension", &LAMMPSWeb::getDimension)
.function("getWalls", &LAMMPSWeb::getWalls);
class_<WallInfo>("WallInfo")
.constructor<>()
.property("which", &WallInfo::which)
.property("style", &WallInfo::style)
.property("position", &WallInfo::position)
.property("cutoff", &WallInfo::cutoff);
class_<Modify>("Modify")
.function("getName", &Modify::getName)
.function("getClearPerSync", &Modify::getClearPerSync)
Expand Down Expand Up @@ -179,6 +199,7 @@ EMSCRIPTEN_BINDINGS(LAMMPSWeb)
register_vector<Fix>("vector<Fix>");
register_vector<Compute>("vector<Compute>");
register_vector<float>("vector<float>");
register_vector<WallInfo>("vector<WallInfo>");
}
#endif
#endif
38 changes: 38 additions & 0 deletions public/examples/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,44 @@
"url": "reaxff/ZnOH2/param.qeq"
}
]
},
{
"id": "2d-lj-walls",
"title": "2D LJ particles with walls",
"description": "Lennard-Jones particles confined by LJ93 potential walls in 2D. Demonstrates wall rendering as thick slabs visible from the side view.",
"imageUrl": "walls/2d-lj-walls/2d-lj-walls.png",
"inputScript": "2d-lj-walls.in",
"keywords": [
"lennard jones",
"wall",
"lj93",
"2d"
],
"files": [
{
"fileName": "2d-lj-walls.in",
"url": "walls/2d-lj-walls/2d-lj-walls.in"
}
]
},
{
"id": "3d-lj-walls",
"title": "3D LJ particles with walls",
"description": "Lennard-Jones particles confined by LJ93 potential walls in 3D. Demonstrates transparent wall rendering in 3D mode.",
"imageUrl": "walls/3d-lj-walls/3d-lj-walls.png",
"inputScript": "3d-lj-walls.in",
"keywords": [
"lennard jones",
"wall",
"lj93",
"3d"
],
"files": [
{
"fileName": "3d-lj-walls.in",
"url": "walls/3d-lj-walls/3d-lj-walls.in"
}
]
}
]
}
46 changes: 46 additions & 0 deletions public/examples/walls/2d-lj-walls/2d-lj-walls.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#/camera position 3.0 1.5 60.1
#/camera target 4.1 -0.7 -2.6
#/atom 1 1.0 #a1a1a1
#/atom 2 3.0 #6EBFC0

# This LAMMPS input script simulates LJ particles with reflecting walls in 2D
# Demonstrates wall rendering in 2D mode

# main parameters
units lj
dimension 2
atom_style atomic
pair_style lj/cut 2.5
boundary f f p # Fixed X and Y (for walls), periodic Z (required for 2D)

# create system and insert atoms
region myreg block -30 30 -30 30 -0.5 0.5
create_box 2 myreg
create_atoms 1 random 1500 341341 myreg
create_atoms 2 random 100 127569 myreg

# atom settings
mass 1 1
mass 2 1
pair_coeff 1 1 1.0 1.0
pair_coeff 2 2 0.5 3.0
neigh_modify every 1 delay 5 check yes

# Add walls before minimization to prevent atoms from escaping
fix mywalls all wall/lj93 xlo EDGE 1.0 1.0 2.5 xhi EDGE 1.0 1.0 2.5 ylo EDGE 1.0 1.0 2.5 yhi EDGE 1.0 1.0 2.5

# minimisation
minimize 1.0e-4 1.0e-6 1000 10000

# dynamics
fix mynve all nve
fix mylgv all langevin 1.0 1.0 0.1 1530917
fix myefn all enforce2d
timestep 0.005

# outputs
thermo 10
thermo_style one

# run
run 1000
41 changes: 41 additions & 0 deletions public/examples/walls/3d-lj-walls/3d-lj-walls.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#/atom 1 2.0 #a1a1a1

#/camera position -20 20 20
#/camera target 0 0 0

# This LAMMPS input script demonstrates wall collisions with 5 non-interacting particles
# Particles bounce off LJ93 potential walls in 3D

# main parameters
units lj
dimension 3
atom_style atomic
pair_style none # No pair interactions - particles only interact with walls
boundary f f f # Fixed boundaries (non-periodic) for walls

# create system and insert atoms
# Smaller box for easier visualization
region myreg block -10 10 -10 10 -10 10
create_box 1 myreg
region atomreg block -8 8 -8 8 -8 8 # Leave gap for wall cutoff
create_atoms 1 random 5 341341 atomreg

# atom settings
mass 1 1

# Add walls before setting velocities
fix mywalls all wall/lj93 xlo EDGE 1.0 1.0 2.5 xhi EDGE 1.0 1.0 2.5 ylo EDGE 1.0 1.0 2.5 yhi EDGE 1.0 1.0 2.5 zlo EDGE 1.0 1.0 2.5 zhi EDGE 1.0 1.0 2.5

# Set random initial velocities so particles bounce off walls
velocity all create 2.0 341341 rot yes dist gaussian

# dynamics
fix mynve all nve
timestep 0.005

# outputs
thermo 100
thermo_style one

# run
run 10000
Binary file modified public/lammps.wasm
Binary file not shown.
15 changes: 15 additions & 0 deletions src/containers/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ const Settings = ({ open, onClose }: SettingsProps) => {
Show simulation box
</Checkbox>

<div style={{ marginTop: "8px" }}>
<Checkbox
checked={renderSettings.showWalls}
onChange={(e) =>
handleSettingChange(
"showWalls",
e.target.checked,
"Settings.Render.ShowWalls",
)
}
>
Show walls
</Checkbox>
</div>

<div style={{ marginTop: "8px" }}>
<Checkbox
checked={renderSettings.orthographic}
Expand Down
Loading