CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > Siemens > STAR-CCM+

Starccm+ Report Java macro error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 3, 2019, 20:02
Unhappy Starccm+ Report Java macro error
  #1
lzw
New Member
 
Zhengwei Long
Join Date: Oct 2019
Location: Tianjin, China
Posts: 8
Rep Power: 6
lzw is on a distinguished road
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.
lzw is offline   Reply With Quote

Old   October 7, 2019, 04:36
Default
  #2
Senior Member
 
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 566
Rep Power: 20
bluebase will become famous soon enough
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:
Has anyone the idea to read the area of a part surface in the Java program?
Starccm has an areareport which you could create and read out.
bluebase is offline   Reply With Quote

Old   October 7, 2019, 07:55
Default
  #3
lzw
New Member
 
Zhengwei Long
Join Date: Oct 2019
Location: Tianjin, China
Posts: 8
Rep Power: 6
lzw is on a distinguished road
Quote:
Originally Posted by bluebase View Post
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.

Starccm has an areareport which you could create and read out.

UI should be GUI. I need to build a new GUI in StarCCM. But the report function said wrong in the GUI model.
lzw is offline   Reply With Quote

Old   October 8, 2019, 11:43
Default
  #4
Senior Member
 
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 566
Rep Power: 20
bluebase will become famous soon enough
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
bluebase is offline   Reply With Quote

Old   October 8, 2019, 20:56
Default
  #5
lzw
New Member
 
Zhengwei Long
Join Date: Oct 2019
Location: Tianjin, China
Posts: 8
Rep Power: 6
lzw is on a distinguished road
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
}
lzw is offline   Reply With Quote

Old   October 9, 2019, 08:18
Default
  #6
Senior Member
 
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 566
Rep Power: 20
bluebase will become famous soon enough
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
bluebase is offline   Reply With Quote

Old   October 9, 2019, 20:30
Default
  #7
lzw
New Member
 
Zhengwei Long
Join Date: Oct 2019
Location: Tianjin, China
Posts: 8
Rep Power: 6
lzw is on a distinguished road
Thanks very much. Your solution is ok. I used the monitorVaue() ok.
lzw is offline   Reply With Quote

Reply

Tags
report, surface area


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[blockMesh] blockMesh with double grading. spwater OpenFOAM Meshing & Mesh Conversion 92 January 12, 2019 09:00
Compiling dynamicTopoFvMesh for OpenFOAM 2.1.x Saxwax OpenFOAM Installation 25 November 29, 2013 05:34
CGNS lib and Fortran compiler manaliac Main CFD Forum 2 November 29, 2010 06:25
checking the system setup and Qt version vivek070176 OpenFOAM Installation 22 June 1, 2010 12:34
error while compiling the USER Sub routine CFD user CFX 3 November 25, 2002 15:16


All times are GMT -4. The time now is 03:49.