33 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /*
 | |
|   Generate a set of samples with different damage positions
 | |
|   One transducer (top) and one sensor (bottom, x-centered, 30mm from bottom)
 | |
| */
 | |
| var fs = require('fs'),
 | |
|     cp = require('child_process')
 | |
|     
 | |
| var plate = [500,500],
 | |
|     damx = [100,400],
 | |
|     damy = [100,400],
 | |
|     sampleN = 1000,
 | |
|     simu = '../../bin/simndt2b',
 | |
|     configFile = 'simndt_alu_plate_hole_20mm_sensorshape.json'
 | |
| function randomInt( range) {
 | |
|   return range[0]+Math.floor(Math.random()*(range[1]-range[0]))
 | |
| }
 | |
| function readJSON(file) {
 | |
|   return JSON.parse(fs.readFileSync(file,'utf8'))
 | |
| }    
 | |
| function writeJSON(file,config) {
 | |
|   return fs.writeFileSync(file,JSON.stringify(config),'utf8')
 | |
| }
 | |
| for(var i=0;i<sampleN;i++) {
 | |
|   var config = readJSON(configFile)
 | |
|   config.GeometricObjects[0].x0=randomInt(damx);
 | |
|   config.GeometricObjects[0].y0=randomInt(damy);
 | |
|   config.Export.Filename = 'sample-x'+config.GeometricObjects[0].x0+'-y'+config.GeometricObjects[0].y0;
 | |
|   writeJSON('config.json',config)
 | |
|   console.log(config.Export.Filename)
 | |
|   cp.spawnSync(simu,['config.json'])
 | |
| }
 | |
| 
 |