// Amira Abdel-Rahman // (c) Massachusetts Institute of Technology 2020 const { exec } = require("child_process"); var express = require('express'); var fs = require('fs'); var app = express(); var path = require('path'); var setup,cmods; // will parse incoming JSON data and convert it into an object literal for you app.use(express.json({limit: '50mb', extended: true})); app.use(express.urlencoded({limit: '50mb', extended: true})); //serve the html app.use(express.static(__dirname + '/../')); // exposes index.html, per below app.post("/", function(req, res) { // each key in req.body will match the keys in the data object that you passed in var myObject = req.body.data; setup=JSON.parse(myObject.foo); cmods=setup.cmods; if(setup.run){ console.log("run CMODS!"); runCMODS(); }else{ console.log("reading data"); } // console.log(setup); // myObject.foo === "bar" res.send("I am done"); }); port = 8080; app.listen(port); console.log(`Open http://localhost:${port}/demos/indexCMODS.html in your browser`); function runCMODS(){ var STL_particles_command= "./STL_particles "+cmods.STL_particles.nlattice+" < "+cmods.STL_particles.stlName+".stl"; var particles_bonds_command= " | ./particles_bonds "+cmods.particles_bonds.grid+" "+cmods.particles_bonds.block+""; var bonds_stress_strain_command1= " | ./bonds_stress_strain1 "+cmods.bonds_stress_strain.grid+" "+cmods.bonds_stress_strain.block+" "+cmods.bonds_stress_strain.spring+" " +cmods.bonds_stress_strain.mass+" "+cmods.bonds_stress_strain.dissipation +" "+cmods.bonds_stress_strain.dt+" "+cmods.bonds_stress_strain.nloop +" "+cmods.bonds_stress_strain.fraction+" "+cmods.bonds_stress_strain.fraction+" "+cmods.bonds_stress_strain.step +" "+cmods.bonds_stress_strain.bond+""; var bonds_stress_strain_command= " | ./bonds_stress_strain "+cmods.bonds_stress_strain.grid+" "+cmods.bonds_stress_strain.block+" "+cmods.bonds_stress_strain.spring+" " +cmods.bonds_stress_strain.mass+" "+cmods.bonds_stress_strain.dissipation +" "+cmods.bonds_stress_strain.dt+" "+cmods.bonds_stress_strain.nloop +" "+cmods.bonds_stress_strain.fraction+" "+cmods.bonds_stress_strain.step +" "+cmods.bonds_stress_strain.bond+""; var strain_GL_command= " | ./strain_GL "+cmods.strain_GL.size+" "+cmods.strain_GL.scale+" "+cmods.strain_GL.rx+" "+cmods.strain_GL.ry+" "+cmods.strain_GL.rz+" "+cmods.strain_GL.sxyz+" "+cmods.strain_GL.perspective+""; var command= STL_particles_command+ particles_bonds_command+bonds_stress_strain_command +strain_GL_command; console.log(command) // var command= "./STL_particles 100 < "+stlName+".stl | ./particles_bonds 1024 1024 | ./bonds_stress_strain 512 512 30000000 1 100 0.0001 1000 0.04 -0.0002 15 | ./strain_GL 1.5 200 1.55 0. -0.0 0.25 0.05"; exec(command, (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); }