0

I run this code {in a for loop} that is made up of helper functions created by the commercial company Remcom. When I export my data sets, my RAM slowly fills up and I have to close the program (XFdtd) and restart it and restart the export function where I ended. Is there something wrong with my code or a statement I could include to clear the heap after every iteration? This is my function:

function exportBandE(simId,name)
{
/////////////////////////////////////////////////////////////////////////////////////////////
// Now lets try and export a result or numerous results and mimic the export given by the GUI
// will need projectId, simulationId, and probably runId
var fullPathB = "E:/ACCRE/5652/Bfield/" + name + ".mat";
var fullPathE = "E:/ACCRE/5652/Efield/" + name + ".mat";
var simulationId = App.getActiveProject().getSimulation(simId)
var projectId = simulationId.getProjectId();
//Load B data from the simulation
var resultBrowser = App.getResultBrowser();

resultBrowser.addProject(App.getActiveProject().getProjectDirectory())
var Qx = new ResultQuery();
Qx.projectId = projectId;
Output.println(projectId)
Qx.simulationId = simId;
Qx.runId = simulationId.getRunId( 0 );
Qx.sensorType = ResultQuery.SolidVolumeSensor;
Qx.sensorId = Qx.getAvailableSensorIds()[ 0 ];
Qx.timeDependence = ResultQuery.SteadyState;
Qx.resultType = ResultQuery.B;
Qx.fieldScatter = ResultQuery.TotalField;
Qx.dataTransform = ResultQuery.NoTransform;
Qx.surfaceInterpolationResolution = ResultQuery.NoInterpolation;
Qx.setDimensionRange( "Frequency", 0, -1 );
Qx.setDimensionRange("X",0,-1);
Qx.setDimensionRange("Z",0,-1);
Qx.setDimensionRange("Y",0,-1);

//BX
Qx.resultComponent = ResultQuery.X;
Qx.complexPart = ResultQuery.RealPart;
var xds = new ResultDataSet( "Bx field real" );
xds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var xdsi = new ResultDataSet( "Bx field complex" );
xdsi.setQuery(Qx);

//BY
resultBrowser.FullRefreshType;
Qx.resultComponent = ResultQuery.Y;
Qx.complexPart = ResultQuery.RealPart;
var yds = new ResultDataSet( "By field real" );
yds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var ydsi = new ResultDataSet( "By field complex" );
ydsi.setQuery(Qx);

var exportedFile = new File(fullPathB);
exportedFile.open(IODevice.WriteOnly);
DataSetExportUtility.writeMatlabHeader(exportedFile);

//You can then pass exportedFile as the first parameter to the addMatlabVariable function.
DataSetExportUtility.addMatlabVariable(exportedFile, "BxField", false, xds,xdsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "ByField", false, yds,ydsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "Frequency", false, xds.getDimension("Frequency"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "xdim", true, xds.getDimension("X"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "ydim", true, xds.getDimension("Y"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "zdim", true, xds.getDimension("Z"),false );
//DataSetExportUtility.addMatlabVariable(exportedFile, "BzField", false, zds,zdsi );
exportedFile.close();

/////////////////
var Qx = new ResultQuery();
Qx.projectId = projectId;
Output.println(projectId)
Qx.simulationId = simId;
Qx.runId = simulationId.getRunId( 0 );
Qx.sensorType = ResultQuery.SolidVolumeSensor;
Qx.sensorId = Qx.getAvailableSensorIds()[ 0 ];
Qx.timeDependence = ResultQuery.SteadyState;
Qx.resultType = ResultQuery.E;
Qx.fieldScatter = ResultQuery.TotalField;
Qx.dataTransform = ResultQuery.NoTransform;
Qx.surfaceInterpolationResolution = ResultQuery.NoInterpolation;
Qx.setDimensionRange( "Frequency", 0, -1 );
Qx.setDimensionRange("X",0,-1);
Qx.setDimensionRange("Z",0,-1);
Qx.setDimensionRange("Y",0,-1);

//EX
Qx.resultComponent = ResultQuery.X;
Qx.complexPart = ResultQuery.RealPart;
var xds = new ResultDataSet( "Ex field real" );
xds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var xdsi = new ResultDataSet( "Ex field complex" );
xdsi.setQuery(Qx);

//EY
resultBrowser.FullRefreshType;
Qx.resultComponent = ResultQuery.Y;
Qx.complexPart = ResultQuery.RealPart;
var yds = new ResultDataSet( "Ey field real" );
yds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var ydsi = new ResultDataSet( "Ey field complex" );
ydsi.setQuery(Qx);

//EZ
Qx.resultComponent = ResultQuery.Z;
Qx.complexPart = ResultQuery.RealPart;
var zds = new ResultDataSet( "Ez field real" );
zds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var zdsi = new ResultDataSet( "Ez field complex" );
zdsi.setQuery(Qx);

// add to already existing matlab file
var exportedFile = new File(fullPathE);
exportedFile.open(IODevice.WriteOnly);
DataSetExportUtility.writeMatlabHeader(exportedFile);
DataSetExportUtility.addMatlabVariable(exportedFile, "ExField", false, xds,xdsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "EyField", false, yds,ydsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "EzField", false, zds,zdsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "Frequency", false, xds.getDimension("Frequency"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "xdim", true, xds.getDimension("X"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "ydim", true, xds.getDimension("Y"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "zdim", true, xds.getDimension("Z"),false );
exportedFile.close();
gc();
  • Welcome to StackOverflow. Have a look at [writing the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question). Create a minimal example removing unnecessary comments. Also investigate if the classes used implement the IDisposable interface. – Jeroen Heier Oct 08 '19 at 04:22
  • the classes do not implement the IDisposable interface – Blacbeanburgr Oct 08 '19 at 05:57
  • So it is JavaScript code. Then remove functionality 1 by 1 until the resource consumption is normal. – Jeroen Heier Oct 10 '19 at 03:54

0 Answers0