CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   STAR-CCM+ (https://www.cfd-online.com/Forums/star-ccm/)
-   -   Java code to get the current residuals values (https://www.cfd-online.com/Forums/star-ccm/201711-java-code-get-current-residuals-values.html)

Élio Pereira May 8, 2018 19:37

Java code to get the current residuals values
 
From the forum topic https://www.cfd-online.com/Forums/st...tion-step.html, I learnt that the current iteration number can be accessed through the following command:

getActiveSimulation().getSimulationIterator().getC urrentIteration()


I wonder if there's a similar command to get the current residual values ( Continuity, X-momentum, Y-momentum and Energy). I tried, for example, the following command for the continuity:

getActiveSimulation().getSimulationIterator().getC urrentContinuity()


but I wasn't successful. Star CCM+ doesn't aknowledge this one. Which commands should be used to get the current residuals values?

bluebase May 12, 2018 17:19

Quote:

Originally Posted by Élio Pereira (Post 691699)
I wonder if there's a similar command to get the current residual values ( Continuity, X-momentum, Y-momentum and Energy).


Yes, sure there is way.


However, you'll not find the residual values in the SimulationIterator class.
Instead, you can get the latest resdiual value from their respective monitors.


I don't recall the way to directly get the current residual value, but below is a working example. For more information and alternative way, check the java api guide to get an overview what the ResidualMonitor (or PlotableMonitor) class can do.



Code:

import java.util.*;

import star.common.*;
import star.base.neo.*;
import star.base.report.*;

public class printConti extends StarMacro {
  public void execute() {

    Simulation sim = getActiveSimulation();

    ResidualMonitor residualMonitor_0 =
      ((ResidualMonitor) sim.getMonitorManager().getMonitor("Continuity"));

    double[] conti = residualMonitor_0.getPlotYValues() ;
   
    sim.println("The current continuity residual is " + conti[conti.length-1]);
  }
}


Best regards,
Sebastian

Élio Pereira May 14, 2018 03:29

Thank you for your answer!


All times are GMT -4. The time now is 20:54.