|
[Sponsors] |
October 3, 2019, 21:02 |
Starccm+ Report Java macro error
|
#1 |
New Member
Zhengwei Long
Join Date: Oct 2019
Location: Tianjin, China
Posts: 8
Rep Power: 7 |
I wanted to read the area of a part surface. I used the report function "getReportMonitorValue()".
The macro is ok if the macro is played in the Starccm+. But when I used the same macro in my UI program, the function "getReportMonitorValue" always had error of NullPointerException. Has anyone the idea to read the area of a part surface in the Java program? Thanks a lot. |
|
October 7, 2019, 05:36 |
|
#2 | |
Senior Member
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 567
Rep Power: 21 |
what do you mean with "UI program"?
Is it a simulation assistant? Or is it an external one, which controls starccm? The later might not have loaded the starccm library to use starccm specific functions such as getReportMonitorValue. Quote:
|
||
October 7, 2019, 08:55 |
|
#3 | |
New Member
Zhengwei Long
Join Date: Oct 2019
Location: Tianjin, China
Posts: 8
Rep Power: 7 |
Quote:
UI should be GUI. I need to build a new GUI in StarCCM. But the report function said wrong in the GUI model. |
||
October 8, 2019, 12:43 |
|
#4 |
Senior Member
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 567
Rep Power: 21 |
would you mind sharing your code?
The NullPointerException indicates, there is an object gone or not available during the executing. But you can probably tell by yourself already that's the case... The method "getReportMonitorValue" always returns a double value according to the api. Does your report object already have such a value? If the regions/boundaries are not set, such a double value cannot be computed... You might try monitoredValue() instead of getReportMonitorValue() on the report object. What type of report are you using to compute the surface? Are you using an IDE such as Netbeans to develop your code? It can do basic syntax check, apart from many other things. Unfortunately, the statement "wrong" might not be enough for me to determine the source of that error. with regards, Sebastian |
|
October 8, 2019, 21:56 |
|
#5 |
New Member
Zhengwei Long
Join Date: Oct 2019
Location: Tianjin, China
Posts: 8
Rep Power: 7 |
I used a simple GUI from the NetBean.
The main java is : /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ccmdebug; import java.io.ByteArrayOutputStream; import java.util.Collection; import java.util.Iterator; import star.base.report.SurfaceIntegralReport; import star.common.*; import star.meshing.MeshPart; /** * * @author lzw */ public class ReportGUI extends javax.swing.JFrame { /** * Creates new form ReportGUI */ private Simulation simulation_0; public ReportGUI(Simulation sim) { initComponents(); simulation_0 = sim; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jButton1 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE); jButton1.setText("打印边界面积"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(330, 330, 330) .addComponent(jButton1)) .addGroup(layout.createSequentialGroup() .addGap(67, 67, 67) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 715, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(80, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(36, 36, 36) .addComponent(jButton1) .addGap(43, 43, 43) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(78, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: // Region region_1 = simulation_0.getRegionManager().getRegion("Region" ); // Collection<Boundary> boundary_list = region_1.getBoundaryManager().getBoundaries(); MeshPart meshPart_0 = (MeshPart) simulation_0.get(SimulationPartManager.class).getP arts().toArray()[0]; Collection<PartSurface> boundary_list = meshPart_0.getPartSurfaceManager().getPartSurfaces (); Iterator bi = boundary_list.iterator(); String area_0; while (bi.hasNext()) { //向下转型 PartSurface aim_b_0 = (PartSurface)bi.next(); //if(aim_b_0.toString().contains("inlet")) { // for(int i = 0; i< 100; i++){ area_0 = GetArea(aim_b_0); jTextArea1.append(aim_b_0.toString()+":"+ area_0 +"\n"); //if(Double.parseDouble(area_0) > 0) break; }// } }//GEN-LAST:event_jButton1ActionPerformed public String GetArea(PartSurface aim_b) { double fa = -1; UserFieldFunction userFieldFunction_1 = simulation_0.getFieldFunctionManager().createField Function(); userFieldFunction_1.getTypeOption().setSelected(Fi eldFunctionTypeOption.Type.SCALAR); // userFieldFunction_1.setFunctionName("inlet_area"); userFieldFunction_1.setDefinition("1"); SurfaceIntegralReport surfaceIntegralReport_1 = simulation_0.getReportManager().createReport(Surfa ceIntegralReport.class); surfaceIntegralReport_1.setFieldFunction(userField Function_1); //userFieldFunction_1.setPresentationName("get_area" ); surfaceIntegralReport_1.getParts().setQuery(null); surfaceIntegralReport_1.getParts().setObjects(aim_ b); surfaceIntegralReport_1.setPresentationName(aim_b. toString() + "_area"); for(int i = 0 ; i < 100; i++){ try { fa = surfaceIntegralReport_1.getReportMonitorValue(); } catch (Exception e) { //simulation_0.println("get area error\n");// + getStackTrace(e)); // throw e; } } if(fa < 0) simulation_0.println("get area error\n"); return String.format("%.4f", fa); } public String getStackTrace(Exception e) { ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream(); e.printStackTrace(new java.io.PrintWriter(buf, true)); String expMessage = buf.toString(); try { buf.close(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return expMessage; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; // End of variables declaration//GEN-END:variables } |
|
October 9, 2019, 09:18 |
|
#6 |
Senior Member
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 567
Rep Power: 21 |
Hi Zhengwei,
thanks for sharing the code. I could confirm the issue you reported. There likely is a solution/workaround: use .monitoredValue() instead of .getReportMonitorValue(). It could resolve the issue in my environment. Though i am not entirely sure what's the cause. It seems .getReportMonitorValue() is not waiting for the connectivity to be loaded. While .monitoredValue() seems to get a different type of value which is waiting for StarCCM. I find it difficult to follow the methods in the compiled code, and i am unfamiliar how the GUI is communicating with the server "behind" the scene. best regards, Sebastian |
|
October 9, 2019, 21:30 |
|
#7 |
New Member
Zhengwei Long
Join Date: Oct 2019
Location: Tianjin, China
Posts: 8
Rep Power: 7 |
Thanks very much. Your solution is ok. I used the monitorVaue() ok.
|
|
Tags |
report, surface area |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[blockMesh] blockMesh with double grading. | spwater | OpenFOAM Meshing & Mesh Conversion | 92 | January 12, 2019 10:00 |
Compiling dynamicTopoFvMesh for OpenFOAM 2.1.x | Saxwax | OpenFOAM Installation | 25 | November 29, 2013 06:34 |
CGNS lib and Fortran compiler | manaliac | Main CFD Forum | 2 | November 29, 2010 07:25 |
checking the system setup and Qt version | vivek070176 | OpenFOAM Installation | 22 | June 1, 2010 13:34 |
error while compiling the USER Sub routine | CFD user | CFX | 3 | November 25, 2002 16:16 |