Customize output variables : Différence entre versions

De Wiki
Aller à : navigation, rechercher
(Implementing the addNewVars() method =)
(Giving information to PSIMU!)
 
(14 révisions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
TBW (for V11.4 version)
+
''<font color=#FF0000>'''Warning: this section is only relevant for PSIMU version 11.4 (or more recent ones).'''</font>''
  
''<font color=#FF0000>'''Warning: this section is only relevant for PSIMU version 11.4 (and or more recent ones).'''</font>''
+
Create new specific variables in the output list is relatively simple. As an example, we are going to show how to add two additional variables '''HPM''' and '''HAM''', corresponding respectively the mean perigee and apogee altitudes considering the mean semi-major axis and eccentricity already computed by <font color=#556B2F>'''PSIMU'''</font>.
 
+
Create new specific variables in the output list is relatively simple. As an example, we are goinf to show how to add twoo additional variables '''HPM''' and '''HAM''', corresponding respectively the the perigee and apogee mean altitudes considering the mean semi-major axis and eccentricity already computed by <font color=#556B2F>'''PSIMU'''</font>.
+
  
 
== Creating a class implementing the INewVarsFunction interface ==
 
== Creating a class implementing the INewVarsFunction interface ==
  
As explained in the title of this paragraph, we have to create a new class implementing the <font color=#4169E1>INewVarsFunction</font> interface where we will be able to compute the new variables. On the code below, we see that this interface forces us to have the <font color=#4169E1>addNewVars()</font>, <font color=#4169E1>computeNewVars()</font> and <font color=#4169E1>getNames()</font> methods:
+
As explained in the title of this paragraph, we have to create a new class implementing the [{{PathCurrentJavaDoc}}/calc/output/INewVarsFunction.html INewVarsFunction] interface where we will be able to compute the new variables. On the code below, we see that this interface forces us to have the <font color=#4169E1>addNewVars()</font>, <font color=#4169E1>computeNewVars()</font> and <font color=#4169E1>getNames()</font> methods:
  
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
Ligne 35 : Ligne 33 :
 
=== Adding a constructor ===
 
=== Adding a constructor ===
  
As we will need information on the equatorial radius, we will add a constructor allowing to store a <font color=#4169E1>ExtendedOneAxisEllipsoid</font> object as well as a list including the names of the new variables (this list will be returned by the <font color=#4169E1>getNames()</font> method:
+
As we will need information on the equatorial radius, we will add a constructor allowing to store a <font color=#4169E1>ExtendedOneAxisEllipsoid</font> object. We will also add a list including the names of the new variables (this list will be returned by the <font color=#4169E1>getNames()</font> method:
  
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
Ligne 68 : Ligne 66 :
 
* its unit (String)
 
* its unit (String)
 
* its gap threshold (for plotting; may be null)
 
* its gap threshold (for plotting; may be null)
* a boolean to kpow if it will be visible or not
+
* a boolean to know if it will be visible or not
  
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
    public void addNewVars ( final ResultWriter resultWriter ) throws SqliteException {
+
public void addNewVars ( final ResultWriter resultWriter ) throws SqliteException {
  
        if ( resultWriter != null) {
+
    if ( resultWriter != null) {
  
            // Mean perigee altitude creation
+
        // Mean perigee altitude creation
            String varName = listOfNames.get(0);
+
        String varName = listOfNames.get(0);
            String varDesc = "Mean perigee altitude";
+
        String varDesc = "Mean perigee altitude";
            String varUnit = "km";
+
        String varUnit = "km";
 
              
 
              
            // Adding a column in the ephemeris table
+
        // Adding a column in the ephemeris table
            resultWriter.addColumn(PsimuUtils.EPH_TABLE, varName, varDesc,
+
        resultWriter.addColumn(PsimuUtils.EPH_TABLE, varName, varDesc, ColumnType.REAL, varUnit, null, true);
                    ColumnType.REAL, varUnit, null, true);
+
 
      
 
      
            // Adding a column in the event table
+
        // Adding a column in the event table
            resultWriter.addColumn(PsimuUtils.EVENT_TABLE, varName,
+
        resultWriter.addColumn(PsimuUtils.EVENT_TABLE, varName, varDesc, ColumnType.REAL, varUnit, null, true);
                    varDesc, ColumnType.REAL, varUnit, null, true);
+
 
      
 
      
            // Mean apogee altitude creation
+
        // Mean apogee altitude creation
            varName = listOfNames.get(1);
+
        varName = listOfNames.get(1);
            varDesc = "Mean apogee altitude";
+
        varDesc = "Mean apogee altitude";
 
              
 
              
            // Adding a column in the ephemeris table
+
        // Adding a column in the ephemeris table
            resultWriter.addColumn(PsimuUtils.EPH_TABLE, varName, varDesc,
+
        resultWriter.addColumn(PsimuUtils.EPH_TABLE, varName, varDesc, ColumnType.REAL, varUnit, null, true);
                    ColumnType.REAL, varUnit, null, true);
+
 
      
 
      
            // Adding a column in the event table
+
        // Adding a column in the event table
            resultWriter.addColumn(PsimuUtils.EVENT_TABLE, varName,
+
        resultWriter.addColumn(PsimuUtils.EVENT_TABLE, varName, varDesc, ColumnType.REAL, varUnit, null, true);
                    varDesc, ColumnType.REAL, varUnit, null, true);
+
 
          
 
          
        }
+
    }
  
 +
}
 +
</syntaxhighlight>
 +
 +
=== Implementing the computeNewVars() method ===
 +
 +
Using the data previously computed as included in the '''currentState''' and '''listOfCurrentVars''' objects, we have just to compute the new variables then to store them using the <font color=#4169E1>addValue()</font> method of the <font color=#4169E1>ResultWriter</font> object.
 +
 +
<syntaxhighlight lang="java">
 +
public void computeNewVars(final ResultWriter resultWriter, final String tableName,
 +
        final SpacecraftState currentState,
 +
        final HashMap<String, Object> listOfCurrentVars) throws SqliteException {
 +
       
 +
    // Getting previously computed mean semi major axis and eccentricity
 +
    final double am = (Double)listOfCurrentVars.get("AM");
 +
    final double em = (Double)listOfCurrentVars.get("EM");
 +
    // Computation of the mean perigee and apogee altitude
 +
    final double hpm = am*(1. - em) - earth.getEquatorialRadius();
 +
    final double ham = am*(1. + em) - earth.getEquatorialRadius();
 +
       
 +
    // Storing in the table
 +
    if ( resultWriter != null) {
 +
        resultWriter.addValue(tableName, listOfNames.get(0), hpm);
 +
        resultWriter.addValue(tableName, listOfNames.get(1), ham);
 
     }
 
     }
 +
       
 +
    // Storing in the current list
 +
    if ( listOfCurrentVars != null ) {
 +
        listOfCurrentVars.put("HPM", hpm);
 +
        listOfCurrentVars.put("HAM", ham);
 +
    }
 +
       
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== Implementing the computeNewVars() method ===
+
== Giving information to PSIMU! ==
 +
 
 +
All we need now is to call for the <font color=#4169E1>addOutputVarsFunction()</font> method of the [{{PathCurrentJavaDoc}}/calc/output/OutputConfig.html OutputConfig] class with the object issued from our <font color=#4169E1>MyNewMeanVars</font> class !
  
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
 +
    final OutputConfig output = new OutputConfig(...); 
 +
    output.addOutputVarsFunction(new MyNewMeanVars(EARTH));
 
</syntaxhighlight>
 
</syntaxhighlight>

Version actuelle en date du 8 novembre 2019 à 09:38

Warning: this section is only relevant for PSIMU version 11.4 (or more recent ones).

Create new specific variables in the output list is relatively simple. As an example, we are going to show how to add two additional variables HPM and HAM, corresponding respectively the mean perigee and apogee altitudes considering the mean semi-major axis and eccentricity already computed by PSIMU.

Creating a class implementing the INewVarsFunction interface

As explained in the title of this paragraph, we have to create a new class implementing the INewVarsFunction interface where we will be able to compute the new variables. On the code below, we see that this interface forces us to have the addNewVars(), computeNewVars() and getNames() methods:

public class MyNewMeanVars implements INewVarsFunction {
 
    @Override
    public void addNewVars(ResultWriter resultWriter) throws SqliteException {
        // TODO Auto-generated method stub
    }
 
    @Override
    public void computeNewVars(ResultWriter resultWriter, String tableName,
            SpacecraftState currentState,
            HashMap<String, Object> currentVarsList) throws SqliteException {
        // TODO Auto-generated method stub
    }
 
    @Override
    public List<String> getNames() {
        // TODO Auto-generated method stub
        return null;
    }
 
}

Adding a constructor

As we will need information on the equatorial radius, we will add a constructor allowing to store a ExtendedOneAxisEllipsoid object. We will also add a list including the names of the new variables (this list will be returned by the getNames() method:

public class MyNewMeanVars implements INewVarsFunction {
 
    private final ExtendedOneAxisEllipsoid earth;
    private final ArrayList<String> listOfNames;
 
    public MyNewMeanVars ( final ExtendedOneAxisEllipsoid earth ) {
 
       this.earth = earth;
       // List initialization
       listOfNames = new ArrayList<String>();
       listOfNames.add("HPM");
       listOfNames.add("HAM");
 
    }
 
    …
 
    @Override
    public List<String> getNames() {
        return listOfNames;
    }

Implementing the addNewVars() method

To fill the addNewVars() method, we will have to call for the addColumn() method giving for each variable and each table (ephemeris and events ones) as inputs:

  • its name (String)
  • its description (String)
  • its unit (String)
  • its gap threshold (for plotting; may be null)
  • a boolean to know if it will be visible or not
public void addNewVars ( final ResultWriter resultWriter ) throws SqliteException {
 
    if ( resultWriter != null) {
 
        // Mean perigee altitude creation
        String varName = listOfNames.get(0);
        String varDesc = "Mean perigee altitude";
        String varUnit = "km";
 
        // Adding a column in the ephemeris table
        resultWriter.addColumn(PsimuUtils.EPH_TABLE, varName, varDesc, ColumnType.REAL, varUnit, null, true);
 
        // Adding a column in the event table
        resultWriter.addColumn(PsimuUtils.EVENT_TABLE, varName, varDesc, ColumnType.REAL, varUnit, null, true);
 
        // Mean apogee altitude creation
        varName = listOfNames.get(1);
        varDesc = "Mean apogee altitude";
 
        // Adding a column in the ephemeris table
        resultWriter.addColumn(PsimuUtils.EPH_TABLE, varName, varDesc, ColumnType.REAL, varUnit, null, true);
 
        // Adding a column in the event table
        resultWriter.addColumn(PsimuUtils.EVENT_TABLE, varName, varDesc, ColumnType.REAL, varUnit, null, true);
 
    }
 
}

Implementing the computeNewVars() method

Using the data previously computed as included in the currentState and listOfCurrentVars objects, we have just to compute the new variables then to store them using the addValue() method of the ResultWriter object.

public void computeNewVars(final ResultWriter resultWriter, final String tableName,
        final SpacecraftState currentState,
        final HashMap<String, Object> listOfCurrentVars) throws SqliteException {
 
    // Getting previously computed mean semi major axis and eccentricity
    final double am = (Double)listOfCurrentVars.get("AM");
    final double em = (Double)listOfCurrentVars.get("EM");
    // Computation of the mean perigee and apogee altitude
    final double hpm = am*(1. - em) - earth.getEquatorialRadius();
    final double ham = am*(1. + em) - earth.getEquatorialRadius();
 
    // Storing in the table
    if ( resultWriter != null) {
        resultWriter.addValue(tableName, listOfNames.get(0), hpm);
        resultWriter.addValue(tableName, listOfNames.get(1), ham);
    }
 
    // Storing in the current list
    if ( listOfCurrentVars != null ) {
        listOfCurrentVars.put("HPM", hpm);
        listOfCurrentVars.put("HAM", ham);
    }
 
}

Giving information to PSIMU!

All we need now is to call for the addOutputVarsFunction() method of the OutputConfig class with the object issued from our MyNewMeanVars class !

    final OutputConfig output = new OutputConfig(...);   
    output.addOutputVarsFunction(new MyNewMeanVars(EARTH));