Commit f452abe1 authored by Robert Smith's avatar Robert Smith
Browse files

Templates added to VIBE Key-Value Pair Item



The VIBE Key-Value Pair Item's Form now features a section to select a
template for either NTG or DualFoil problems, which will reset the table
to the correct format for that problem type.
Signed-off-by: Robert Smith's avatarRobert Smith <smithrw@ornl.gov>
parent d322eefa
BIN_DIR= $CAEBAT_ROOT/bin
OUTPUT_PREFIX =
SIM_NAME = case10 # Name of current simulation
SIM_ROOT =$CAEBAT_ROOT/../examples/$SIM_NAME # Where to put results from this simulation
PLASMA_STATE_WORK_DIR = $SIM_ROOT/work/battery_state # Where to put state files as the simulation evolves
CURRENT_STATE = cphit.cgns
PRINT_DEBUG = 0
RUN_COMMENT = Coupled CAEBAT Module simulation # A run comment picked up by the portal
TAG = ElectroChemElectricalThermal # A tag that enables related runs to be retrieved together
USER = batsim # Optional, if missing the unix username is used
NUM_CCP_ZONES = 84
NUM_CCN_ZONES = 80
NUM_CHARTRAN_ZONES = 136
NUM_POUCH_ZONES = 8
NUM_ZONES = 308
PLASMA_STATE_FILES = $CURRENT_STATE
SIMULATION_MODE = NORMAL # Simulation mode
LOG_LEVEL = WARNING
LOG_FILE = $SIM_ROOT/${SIM_NAME}.log
[PORTS]
NAMES = INIT DRIVER CHARTRAN THERMAL
[[DRIVER]] # REQUIRED Port section
IMPLEMENTATION = CHARTRAN_THERMAL_DRIVER
# How is the simulation initialized
# (generate the very first state - if needed)
[[INIT]] # REQUIRED Port section (check currently
IMPLEMENTATION = INIT_STATE
[[THERMAL]]
IMPLEMENTATION = AMPERES_THERMAL
[[CHARTRAN]]
IMPLEMENTATION = DUALFOIL
# Individual configuration sections
# Component sepcification (entries similar for all components)
# NAME entry MUST match the name of the python class that implements the component
[INIT_STATE]
CLASS = DRIVERS
SUB_CLASS =
NAME = InitialState
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR =
INPUT_FILES =
OUTPUT_FILES = $CURRENT_STATE
VARIABLES = 'lumped_source', 'lumped_temperature'
INIT_VALUES = '0.0', '298.0'
SCRIPT = $BIN_PATH/init_state.py
[CHARTRAN_THERMAL_DRIVER]
CLASS = DRIVERS
SUB_CLASS = CHARTRAN_THERMAL
NAME = Driver
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR =
INPUT_FILES =
OUTPUT_FILES = $CURRENT_STATE
SCRIPT = $BIN_PATH/thermal_chartran_driver_n.py
[AMPERES_THERMAL]
CLASS = THERMAL
SUB_CLASS =
NAME = Amperes
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR = $SIM_ROOT/input
INPUT_FILES = 'input_keyvalue', 'FarasisModule_4P.e'
OUTPUT_FILES = $CURRENT_STATE
INPUT_VAR = 'lumped_source'
OUTPUT_VAR = 'lumped_temperature'
SCRIPT = $BIN_PATH/amperes_thermal.py
[DUALFOIL]
CLASS = CHARTRAN
SUB_CLASS =
NAME = DualFoil
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR = $SIM_ROOT/input
INPUT_FILES = 'input_keyvalue', 'dualfoil5.in' , 'li-ion-ebar.in'
OUTPUT_FILES = 'df_caebat.out'
INPUT_VAR = 'lumped_temperature'
OUTPUT_VAR = 'lumped_source', 'lumped_resistance'
SCRIPT = $BIN_PATH/dualfoil_chartran.py
# Time loop sepecification (two modes for now) EXPLICIT | REGULAR
# For MODE = REGULAR, the framework uses the variables START, FINISH, and NSTEP
# For MODE = EXPLICIT, the frame work uses the variable VALUES (space separated list of time values)
[TIME_LOOP]
MODE = EXPLICIT
START = 0.0
FINISH = 0.0
NSTEP = 0
VALUES = 0.0 0.4 0.8 1.2 1.6
ELECTRICAL=1
XCONDUCTIVITY=3.07
YCONDUCTIVITY=3.07
ZCONDUCTIVITY=1.7899
HEATCAPACITY=1100
ICSHORT=0
NUMBCS=2
BCTYPE=1,1
BCIDS=3,4
AMBIENTTEMP=320,298
CONVECTIVERATE=15.0,55.0
ICSHORT=0
CurrentFlux=268750000.00
CRATE=1
NUMSEG=5
CURRDEN=0.0,30.0,0.0,-22.,0.
MODESEG=1,1,0,1,0
CUTOFFL=2.0,2.0,2.0,2.0,2.0
CUTOFFH=4.3,4.3,4.3,4.3,4.3
THICKNESS=135e-6
YPolyCoefficients =3.6433e+02,-2.0629e+03,1.1248e+04,-2.8978e+04,4.0999e+04,-3.1353e+04,9.8589e+03
UPolyCoefficients =4.1210,-1.0206,-1.1902,8.2938,-20.6735,24.8684,-11.0442
YPolyDegrees =6,0
UPolyDegrees =6,0
BIN_DIR = $CAEBAT_ROOT/bin
OUTPUT_PREFIX =
RUN_ID = prismatic_cell_20141110060439
SIM_NAME = case6
SIM_ROOT = $CAEBAT_ROOT/../examples/${SIM_NAME}
PLASMA_STATE_WORK_DIR = $SIM_ROOT/work/battery_state
CURRENT_STATE = cphit.cgns
RUN_COMMENT = A run comment picked up by the portal.
TAG = ElectroChemElectricalThermal
USER = <username>
NUM_CHARTRAN_ZONES = 34
NUM_CCP_ZONES = 19
NUM_CCN_ZONES = 18
NUM_ZONES = 73
NUM_POUCH_ZONES = 2
PLASMA_STATE_FILES = $CURRENT_STATE
SIMULATION_MODE = NORMAL
LOG_LEVEL = WARNING
LOG_FILE = $SIM_ROOT/${SIM_NAME}.log
PRINT_DEBUG = 0
[PORTS]
NAMES = INIT DRIVER THERMAL ELECTRICAL CHARTRAN
[[INIT]]
IMPLEMENTATION = INIT_STATE
[[DRIVER]]
IMPLEMENTATION = CHARTRAN_ELECTRICAL_THERMAL_DRIVER
[[THERMAL]]
IMPLEMENTATION = AMPERES_THERMAL
[[ELECTRICAL]]
IMPLEMENTATION = AMPERES_ELECTRICAL
[[CHARTRAN]]
IMPLEMENTATION = NTG
[CHARTRAN_ELECTRICAL_THERMAL_DRIVER]
CLASS = DRIVERS
SUB_CLASS = CHARTRAN_THERMAL
NAME = Driver
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR = $SIM_ROOT/
INPUT_FILES =
OUTPUT_FILES = $CURRENT_STATE
SCRIPT = $BIN_PATH/thermal_electrical_chartran_driver_n.py
[AMPERES_THERMAL]
CLASS = THERMAL
SUB_CLASS =
NAME = Amperes
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR = $SIM_ROOT/input
INPUT_FILES = 'input_keyvalue','FarasisWSingleTab.e'
OUTPUT_FILES = $CURRENT_STATE
SCRIPT = $BIN_PATH/amperes_thermal.py
INPUT_VAR = 'lumped_source'
OUTPUT_VAR = 'lumped_temperature'
[AMPERES_ELECTRICAL]
CLASS = ELECTRICAL
SUB_CLASS =
NAME = Amperes
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR = $SIM_ROOT/input
INPUT_FILES = 'input_keyvalue','FarasisWSingleTab.e'
OUTPUT_FILES = $CURRENT_STATE
SCRIPT = $BIN_PATH/amperes_electrical.py
INPUT_VAR = 'lumped_resistance'
OUTPUT_VAR = 'lumped_source'
[NTG]
CLASS = CHARTAN
SUB_CLASS =
NAME = NTG
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR = $SIM_ROOT/input
INPUT_FILES = 'input_keyvalue'
OUTPUT_FILES = $CURRENT_STATE
SCRIPT = $BIN_PATH/ntg_chartran.py
INPUT_VAR = 'lumped_temperature'
OUTPUT_VAR = 'lumped_source','lumped_resistance'
[INIT_STATE]
CLASS = DRIVERS
SUB_CLASS =
NAME = InitialState
NPROC = 1
BIN_PATH = $CAEBAT_ROOT/bin
INPUT_DIR = $SIM_ROOT/
INPUT_FILES =
OUTPUT_FILES = $CURRENT_STATE
SCRIPT = $BIN_PATH/init_state.py
VARIABLES = 'lumped_source', 'lumped_resistance', 'lumped_temperature'
INIT_VALUES = '0.0', '0.0', '298.'
[TIME_LOOP]
MODE = REGULAR
START = 0.0
FINISH = 10.0
NSTEP = 3
VALUES = 0.1 0.2 0.3 0.4 0.5 0.6 1.5 3.5 6.5 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5
ELECTRICAL=1
XCONDUCTIVITY=1.7899
YCONDUCTIVITY=1.7899
ZCONDUCTIVITY=1.7899
HEATCAPACITY=1100
ICSHORT=0
NUMBCS=6
BCTYPE=1,1,2,2,1,1
BCIDS=3,4,5,6,7,8
AMBIENTTEMP=300,300,298,328,300,300
CONVECTIVERATE=0.0,0.0,5.0,5.0,1.0,1.0
ICSHORT=0
CurrentFlux=3602431.
CRATE=5
CURRDEN=79.26
CUTOFF=2.8
THICKNESS=135e-6
YPolyCoefficients = 3.6433e+02, -2.0629e+03, 1.1248e+04, -2.8978e+04, 4.0999e+04, -3.1353e+04, 9.8589e+03
UPolyCoefficients = 4.1210, -1.0206, -1.1902, 8.2938, -20.6735, 24.8684, -11.0442
YPolyDegrees = 6, 0
UPolyDegrees = 6, 0
......@@ -37,8 +37,11 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.ice.datastructures.ICEObject.Component;
import org.eclipse.ice.datastructures.ICEObject.IUpdateable;
import org.eclipse.ice.datastructures.entry.DiscreteEntry;
import org.eclipse.ice.datastructures.entry.IEntry;
import org.eclipse.ice.datastructures.entry.StringEntry;
import org.eclipse.ice.datastructures.form.DataComponent;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.FormStatus;
import org.eclipse.ice.datastructures.form.TableComponent;
......@@ -52,27 +55,51 @@ import org.eclipse.ice.item.Item;
* This class is a Model Item that configures a set of data components that
* represent key-value pairs for VIBE input.
*
* @author Jay Jay Billings, Andrew Bennett
* @author Jay Jay Billings, Andrew Bennett, Robert Smith
*
*/
@XmlRootElement(name = "VibeKVPair")
public class VibeKVPair extends Item implements IReader, IWriter {
/**
* The index for the template component in the list of components.
*/
private static final int TEMPLATE_COMPONENT_ID = 0;
/**
* Keep track of everything that we can do with the KV Pair Item
*/
private ArrayList<String> actionItems;
/**
* The name of the default template to load.
*/
private static String defaultTemplate = "NTG";
/**
* The tag that indicates this file should be exported to kv pairs.
*/
private String customTaggedExportString = "Export to key-value pair output";
/**
* The component for the table of editable key value pairs.
*/
TableComponent kvTable;
/**
* The name of the last template used to initialize the table component.
*/
private String templateName;
/**
* The nullary constructor.
*/
public VibeKVPair() {
this(null);
// Initialize the template name
templateName = defaultTemplate;
return;
}
......@@ -85,9 +112,60 @@ public class VibeKVPair extends Item implements IReader, IWriter {
public VibeKVPair(IProject projectSpace) {
// Punt to the base class.
super(projectSpace);
// Initialize the template name
templateName = defaultTemplate;
return;
}
/**
* This operation returns a data component that contains the list of
* reafiles that may be selected by a user from the Nek5000_Model_Builder
* directory. This component will be empty if there are no files and contain
* an Entry that says "No problems available."
*
* @param files
* The set of Nek reafiles available to be loaded
* @return the data component
*/
private DataComponent createSelectorComponent() {
// Local Declaration
DataComponent caseComp = new DataComponent();
// The list of available templates
ArrayList<String> templateNames = new ArrayList<String>();
templateNames.add("NTG");
templateNames.add("DualFoil");
// Setup the data component
caseComp.setName("Problem Type Templates");
caseComp.setDescription("The following is a list of VIBE Key-Value "
+ "Pair input type templates for editing.");
caseComp.setId(0);
// Create an Entry for the template names
DiscreteEntry templatesEntry = new DiscreteEntry();
templatesEntry.setAllowedValues(templateNames);
templatesEntry.setDefaultValue(defaultTemplate);
templatesEntry.setValue(defaultTemplate);
// Setup the file Entry's descriptive information
templatesEntry.setName("Available Templates");
templatesEntry.setDescription("A list of the templates available "
+ "for populating the VIBE Key-Value Pair table component");
templatesEntry.setId(1);
// Add the Entry to the Component
caseComp.addEntry(templatesEntry);
// Register this Item as a listener of templatesEntry
templatesEntry.register(this);
return caseComp;
}
/**
* This operation overrides the base class' operation to create a Form with
* Entries that will be used to generate the VIBEkey-value pair file. It has
......@@ -98,10 +176,13 @@ public class VibeKVPair extends Item implements IReader, IWriter {
// Create the form
form = new Form();
// Add the template selector component
form.addComponent(createSelectorComponent());
// If loading from the new item button we should just
// load up the default case 6 file by passing in null
if (project != null) {
loadDefault();
loadDefault(defaultTemplate);
}
}
......@@ -153,6 +234,12 @@ public class VibeKVPair extends Item implements IReader, IWriter {
+ "Could not find any data to write out");
retStatus = FormStatus.InfoError;
}
// Get the selection from the template component
DataComponent templateComp = (DataComponent) components
.get(TEMPLATE_COMPONENT_ID);
String template = templateComp.retrieveAllEntries().get(0).getValue();
return retStatus;
}
......@@ -203,7 +290,7 @@ public class VibeKVPair extends Item implements IReader, IWriter {
// Complain
System.err.println("VibeKVPair Generator Message: "
+ "Failed to refresh the project space.");
logger.error(getClass().getName() + " Exception!",e);
logger.error(getClass().getName() + " Exception!", e);
}
// return a success
retStatus = FormStatus.Processed;
......@@ -233,7 +320,8 @@ public class VibeKVPair extends Item implements IReader, IWriter {
@Override
public void loadInput(String name) {
IFile inputFile = inputFile = project.getFile(name);
logger.info("VibeKVPair Message: Loading" + inputFile.getFullPath().toOSString());
logger.info("VibeKVPair Message: Loading"
+ inputFile.getFullPath().toOSString());
form = read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
......@@ -244,8 +332,12 @@ public class VibeKVPair extends Item implements IReader, IWriter {
/**
* Loads a default dataset that's embedded in the plugin
*
* @param caseName
* The name of the file containing the default case that will be
* used to populate the table
*/
public void loadDefault() {
public void loadDefault(String caseName) {
IFile inputFile = null;
File temp = null;
try {
......@@ -254,13 +346,13 @@ public class VibeKVPair extends Item implements IReader, IWriter {
// Create a filepath for the default file
if (project != null) {
defaultFilePath = project.getLocation().toOSString()
+ System.getProperty("file.separator")
+ "case_6.dat";
+ System.getProperty("file.separator") + caseName
+ ".dat";
} else {
defaultFilePath = ResourcesPlugin.getWorkspace().getRoot()
.getLocation().toOSString()
+ System.getProperty("file.separator")
+ "case_6.dat";
+ System.getProperty("file.separator") + caseName
+ ".dat";
}
// Create a temporary location to load the default file
......@@ -270,8 +362,8 @@ public class VibeKVPair extends Item implements IReader, IWriter {
}
// Pull the default file from inside the plugin
URI uri = new URI(
"platform:/plugin/org.eclipse.ice.vibe/data/case_6.dat");
URI uri = new URI("platform:/plugin/org.eclipse.ice.vibe/data/"
+ caseName + ".dat");
InputStream reader = uri.toURL().openStream();
FileOutputStream outStream = new FileOutputStream(temp);
......@@ -283,13 +375,15 @@ public class VibeKVPair extends Item implements IReader, IWriter {
}
outStream.close();
if (project != null) {
inputFile = project.getFile("case_6.dat");
inputFile = project.getFile(caseName + ".dat");
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} else {
inputFile = ResourcesPlugin.getWorkspace().getRoot()
.getFile(new Path(defaultFilePath));
}
logger.info("VibeKVPair Message: Loading" + inputFile.getFullPath().toOSString());
logger.info("VibeKVPair Message: Loading"
+ inputFile.getFullPath().toOSString());
form = read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
......@@ -310,10 +404,10 @@ public class VibeKVPair extends Item implements IReader, IWriter {
+ " Vibe case data!");
} catch (CoreException e) {
// TODO Auto-generated catch block
logger.error(getClass().getName() + " Exception!",e);
logger.error(getClass().getName() + " Exception!", e);
}
}
/**
* Reads in the KV Pair file to a form.
*
......@@ -328,14 +422,18 @@ public class VibeKVPair extends Item implements IReader, IWriter {
if (ifile == null) {
return null;
}
Form form = new Form();
// Initialize the form if it does not exist
if (form == null) {
form = new Form();
}
// Read in the ini file to an ArrayList<String>
ArrayList<String> lines = new ArrayList<String>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(
ifile.getContents()));
reader = new BufferedReader(
new InputStreamReader(ifile.getContents()));
// Read the FileInputStream and append to a StringBuffer
StringBuffer buffer = new StringBuffer();
......@@ -358,8 +456,8 @@ public class VibeKVPair extends Item implements IReader, IWriter {
+ "Error! Could not find file for loading.");
return null;
} catch (IOException e) {
logger.error("VibeKVPair Message: "
+ "Error! Trouble reading file.");
logger.error(
"VibeKVPair Message: " + "Error! Trouble reading file.");
return null;
} catch (CoreException e) {
logger.error("VibeKVPair Message: "
......@@ -367,8 +465,14 @@ public class VibeKVPair extends Item implements IReader, IWriter {
return null;
}
//
TableComponent kvTable = new TableComponent();
// Create the table if it doesn't exist or empty it if it does
if (kvTable == null) {
kvTable = new TableComponent();
} else {
for (int i : kvTable.getRowIds()) {
kvTable.deleteRow(0);
}
}
ArrayList<IEntry> row;
ArrayList<IEntry> kvEntries = new ArrayList<IEntry>();
IEntry key = new StringEntry();
......@@ -379,16 +483,145 @@ public class VibeKVPair extends Item implements IReader, IWriter {
kvEntries.add(value);
kvTable.setRowTemplate(kvEntries);
// The list of keys whose rows will be dependent on another row
ArrayList<String> dependentKeys = new ArrayList<String>();
dependentKeys.add("MODESEG");
dependentKeys.add("CUTOFFL");
dependentKeys.add("CUTOFFH");
// The list of rows dependent on another row
ArrayList<VibeKVPairRow> dependentRows = new ArrayList<VibeKVPairRow>();
// The row for the NUMSEG key
VibeKVPairRow numsegRow = null;
for (String line : lines) {
if (line.contains("=")) {
String[] keyValue = line.split("=");
int rowID = kvTable.addRow();
row = kvTable.getRow(rowID);
row.get(0).setValue(keyValue[0]);
row.get(1).setValue(keyValue[1]);
// The new row under construction
VibeKVPairRow entryRow = null;
// For most keys, create a standard row
if (!dependentKeys.contains(keyValue[0])) {
entryRow = new VibeKVPairRow((StringEntry) row.get(0),
(StringEntry) row.get(1));
if ("NUMSEG".equals(keyValue[0])) {
numsegRow = entryRow;
// The prescence of NUMSEG means that this is a DualFoil
// problem. We must set the template name appropriately,
// in case this function was invoked by importing a
// key-value file directly.
templateName = "DualFoil";
((DataComponent) form
.getComponent(TEMPLATE_COMPONENT_ID))
.retrieveAllEntries().get(0)
.setValue("DualFoil");
}
}
else {
// TODO If we ever want to create more complex relationships
// between rows,