-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
430 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "emscripten.h" | ||
#include "epanet2_2.h" | ||
|
||
EMSCRIPTEN_KEEPALIVE | ||
int getversion() | ||
{ | ||
int i; | ||
EN_getversion(&i); | ||
return i; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
|
||
|
||
echo "=============================================" | ||
echo "Compiling wasm " | ||
echo "=============================================" | ||
( | ||
|
||
mkdir -p build | ||
|
||
emcc epanet_version.c -o epanet_version.js \ | ||
-I /opt/epanet/src/include \ | ||
/opt/epanet/build/lib/libepanet2.a \ | ||
-s WASM=1 -s "EXPORTED_FUNCTIONS=['_getversion']" | ||
|
||
mkdir -p dist | ||
mv epanet_version.js dist | ||
mv epanet_version.wasm dist | ||
|
||
) | ||
echo "=============================================" | ||
echo "Compiling wasm bindings done" | ||
echo "=============================================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const Benchmark = require('benchmark'); | ||
const { epanetEngine } = require('../../epanet-engine/dist/index.js'); | ||
|
||
const _instance = epanetEngine; | ||
const _FS = _instance.FS; | ||
|
||
_FS.writeFile( | ||
'test.inp', | ||
`[TITLE] | ||
Minimal EPANET Example | ||
[JUNCTIONS] | ||
;ID Elev Demand Pattern | ||
J1 100 10 ; | ||
[RESERVOIRS] | ||
;ID Head Pattern | ||
R1 150 ; | ||
[PIPES] | ||
;ID Node1 Node2 Length Diameter Roughness MinorLoss Status | ||
P1 R1 J1 1000 12 100 0 OPEN | ||
[COORDINATES] | ||
;Node X-Coord Y-Coord | ||
R1 1 1 | ||
J1 2 1 | ||
[TAGS] | ||
[END]` | ||
); | ||
|
||
//console.log(_instance); | ||
|
||
let projectPtr = _instance._create_project(); | ||
let errorCode = _instance._loadinp(projectPtr); | ||
|
||
let nodeId = 'J1'; | ||
let nodeIdPtr = _instance._malloc(nodeId.length + 1); // +1 for the null-terminator. | ||
_instance.stringToUTF8(nodeId, nodeIdPtr, nodeId.length + 1); | ||
|
||
let index = _instance._getNodeIndex(projectPtr, nodeIdPtr); | ||
console.log('Node index for', nodeId, 'is', index); | ||
|
||
const intPointer = _instance._malloc(4); | ||
_instance._free(intPointer); | ||
// | ||
//_instance._getversion2(intPointer); | ||
//const returnValue = _instance.getValue(intPointer, 'i32'); | ||
// | ||
//console.log(_instance._loadinp()); | ||
//console.log(_instance._getNodeIndex()); | ||
|
||
let index2 = _instance.ccall( | ||
'getNodeIndex', // C function name | ||
'number', // Return type | ||
['number', 'string'], // Argument types | ||
[projectPtr, nodeId] // Arguments | ||
); | ||
|
||
console.log('Node index for', nodeId, 'is', index2); | ||
|
||
_instance.stringToUTF8(nodeId, nodeIdPtr, nodeId.length + 1); | ||
|
||
const suite = new Benchmark.Suite(); | ||
|
||
suite | ||
.add('_getversion2', function() { | ||
let index = _instance._getNodeIndex(projectPtr, nodeIdPtr); | ||
}) | ||
|
||
.add('ccall', function() { | ||
let index2 = _instance.ccall( | ||
'getNodeIndex', // C function name | ||
'number', // Return type | ||
['number', 'string'], // Argument types | ||
[projectPtr, nodeId] // Arguments | ||
); | ||
}) | ||
|
||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
}) | ||
.run({ async: false }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const Benchmark = require('benchmark'); | ||
const { Project, Workspace } = require('../dist/index.js'); | ||
const fs = require('fs'); | ||
|
||
const tankTestInp = fs.readFileSync( | ||
__dirname + '/../test/data/tankTest.inp', | ||
'utf8' | ||
); | ||
const ws = new Workspace(); | ||
ws.writeFile('tankTestInp.inp', tankTestInp); | ||
const epanet = ws._instance.getversion(1); | ||
console.log(epanet); | ||
const model = new Project(ws); | ||
model.open('tankTestInp.inp', 'tankTestInp.rpt', 'tankTestInp.bin'); | ||
|
||
//const suite = new Benchmark.Suite(); | ||
// | ||
//const intPointer = ws._instance._malloc(4); | ||
// | ||
//suite | ||
// .add('getNodeIndex', function() { | ||
// const junctionIndexLookup = model.getNodeIndex('J1'); | ||
// //const version = ws.version; | ||
// //ws._instance.getversion(intPointer); | ||
// //const returnValue = ws._instance.getValue(intPointer, 'i32'); | ||
// //ws.version; | ||
// }) | ||
// .add('getNodeIndex2', function() { | ||
// //const junctionIndexLookup = model.getNodeIndex2('J1'); | ||
// //const version = ws.version; | ||
// //ws._instance.getversion(intPointer); | ||
// //const returnValue = ws._instance.getValue(intPointer, 'i32'); | ||
// //ws.version; | ||
// }) | ||
// .on('cycle', function(event) { | ||
// console.log(String(event.target)); | ||
// }) | ||
// .on('complete', function() { | ||
// console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
// }) | ||
// .run({ async: false }); |
Oops, something went wrong.