Class FWSimSolution
java.lang.Object
net.simplace.sim.FWSimSolution
- All Implemented Interfaces:
FWObserver, FWSimFieldContainer
A solution is the configuration of a simulation read from a solution file (
.sol.xml, grammar
SimSolution.dtd). It contains:
- the interfaces for reading and writing external data (
interfaces) - the solution variables (
variables, elementsvaranddyn) - the resources, transformers and aliases (
resources) - the template model with its SimComponents and links (
simmodel) - the outputs (
outputs)
FWSimMigrator); init() then sets up the parts
in this order. Each simulation runs on a clone of the template model.
Values are initialized hierarchically: solution variables overwrite defaults, project data overwrite solution
variables, and links from resources overwrite constants in the first simulation step. As
FWSimFieldContainer the solution provides its variables (named Initial_Values).
- Author:
- Andreas Enders
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe individual class the simulation is checked with while runningname of the default database connection pool; afterinit()<pool id>_<session id> -
Constructor Summary
ConstructorsConstructorDescriptionFWSimSolution(FWSimSession aSession, FWSimSolution aFwSimSolution) Copy constructor for a new session: uses the same solution element, a clone of the variable map for the session and a clone of the template model.FWSimSolution(org.jdom2.Element aSimSolutionElement, FWSimVarMap aVarMap, String aSolutionName) Creates a solution from its XML element. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLink(SimVarLink aSimVarLink) Adds a link created in the graph panel: links the destination variable to the source variable in the template variable map and registers the source as input of the destination SimComponent.voidaddVariable(FWSimVariable<?> aVariable) Adds a variable to the solution variables only (not to the variable map) - use with care.voidcheckCondition(Boolean aCheckResult, String aMessage) Passes the check to the checker of the session.voidRemembers the XML of all containers (variables, interfaces, resources, components, outputs) as they are now, e.g.HashMap<String, FWSimVariable<?>> Returns the solution variables (nothing is created).Returnsvar, the content type of solution variables.org.jdom2.ElementReturnsnull; a solution cannot be created by a form.org.jdom2.ElementgetDynamicForm(FWObservable aObservable) Creates the form for the dynamic solution variables (dyn), sorted by their order (or by name if an order is missing).org.jdom2.ElementgetDynamicForm(FWObservable aObservable, Set<String> aSetByProject) LikegetDynamicForm(FWObservable), but the variables set by a project (project data columns, calibration/sensitivity targets) are shown disabled with the note "set by project": a project overwrites them, so a change in the form would have no effect.org.jdom2.ElementgetEditFormXML(boolean aEnabled) Returns a form with a choice of the solution variables to edit.HashMap<String, FWSimVariable<?>> Returns the solution variables (the live map).ReturnsFWSimIOAdapter.FREQUENCE.NON; the solution is not processed during the simulation.Returns an empty list; the solution has no input variables.getInterface(String aInterface) getName()Always returnsInitial_Values, the name of the solution as field container (e.g.intReturns all solution variables.org.jdom2.ElementgetTitle()getVariable(String aID) Returns a solution variable, ornullif unknown.Returns the template variable map.booleanbooleanvoidinit()Sets up the parts of the solution in this order: interfaces, solution variables (the elementsimulationof versions before 2.0 is renamed tovariables), resources, template model (only if not yet present) with the skip rule, and outputs.booleanAsks the checker of the session.voidremoveLink(SimVarLink aSimVarLink) Removes a link created in the graph panel: from the header of an output adapter, or from the template variable map and the inputs of the destination SimComponent.voidremoveSimFieldContainer(FWSimFieldContainer aFieldContainer, Collection<ArrayList<SimFieldLink>> aSimFieldLinks) Removes a SimComponent, output adapter or resource adapter/transformer from the solution, including all links from and to it.voidremoveVariable(String aID) Removes a variable from the solution variables only (not from the variable map) - use with care.voidsetCheckerClassName(String aClassNameString) voidsetInputSource(FWSimComponent aComponent, String aInputId, String aSource) Links an input of a SimComponent to a source variable, replaces or removes its link (e.g.voidsetInterface(FWSimInterface<?> aInterface) Sets an interface.voidCreates an HTML overview of the solution (description, variables, resources, SimComponents with links to their documentation on simplace.net, outputs), writes it to a temporary file and opens it in the external browser.org.jdom2.DocumentReturns the solution document for saving after editing (#62): the file as read, in which only the containers are replaced whose XML has changed sincecreateSaveBaseline()(in place), containers removed since are deleted and new ones are appended to their section.toString()Returns the name, seegetName().org.jdom2.ElementtoXML()Rebuilds the solution element from the current state: the content ofdescription,variables,interfaces,resources,simmodelandoutputsis replaced by the XML of the description text, the solution variables (varanddyn), interfaces, resource adapters, SimComponents and output adapters.voidupdate(FWObservable aFormObservable, Object aArg) Writes a changed form value to the variable of the same name in the template variable map.
-
Field Details
-
CONNECTION_POOL_DEFAULT
-
CHECKER_CLASS
The individual class the simulation is checked with while running
-
-
Constructor Details
-
FWSimSolution
Copy constructor for a new session: uses the same solution element, a clone of the variable map for the session and a clone of the template model.init()has to be called afterwards; the model is not created again.- Parameters:
aSession- the new sessionaFwSimSolution- the solution to copy
-
FWSimSolution
public FWSimSolution(org.jdom2.Element aSimSolutionElement, FWSimVarMap aVarMap, String aSolutionName) Creates a solution from its XML element. Solutions older thanFWConstants.SOLUTION_VERSIONare migrated in place. If the engine has no check level yet, it is taken from the attributecheck(default LAZY); if the check level is CUSTOM, the checker class is taken from the attributeclass. The description is read. The parts of the solution are set up byinit().- Parameters:
aSimSolutionElement- root element of the solutionaVarMap- variable map with the system parameters; becomes the template variable mapaSolutionName- name of the solution (the solution file name)
-
-
Method Details
-
init
public void init()Sets up the parts of the solution in this order: interfaces, solution variables (the elementsimulationof versions before 2.0 is renamed tovariables), resources, template model (only if not yet present) with the skip rule, and outputs. Errors in variables and model links are logged. -
getInterface
- Parameters:
aInterface- name of the interface- Returns:
- the interface, or
nullif unknown
-
getInterfaces
- Returns:
- all interfaces of the solution (read only)
-
setInterface
Sets an interface. If an interface with the same name exists, it is replaced in the resource adapters or, if no resource uses it, in the output adapters.- Parameters:
aInterface- the interface
-
getModelTemplate
- Returns:
- the template model
-
getResourceAdapters
- Returns:
- a collection of all resource adapters including transformer adapters
-
getOutputAdapters
- Returns:
- the output adapters
-
createVariables
Returns the solution variables (nothing is created).- Specified by:
createVariablesin interfaceFWSimFieldContainer- Returns:
- the variables, keyed by name
- See Also:
-
addVariable
Adds a variable to the solution variables only (not to the variable map) - use with care.- Specified by:
addVariablein interfaceFWSimFieldContainer- Parameters:
aVariable- the variable to add- See Also:
-
getVariable
Returns a solution variable, ornullif unknown.- Specified by:
getVariablein interfaceFWSimFieldContainer- Parameters:
aID- id of the variable- Returns:
- the variable
- See Also:
-
removeVariable
Removes a variable from the solution variables only (not from the variable map) - use with care.- Specified by:
removeVariablein interfaceFWSimFieldContainer- Parameters:
aID- id of the variable- See Also:
-
getName
Always returnsInitial_Values, the name of the solution as field container (e.g. in the graph panel and as name of the description file).- Specified by:
getNamein interfaceFWSimFieldContainer- Returns:
- the name of the container
- See Also:
-
getOrderNumber
public int getOrderNumber()- Specified by:
getOrderNumberin interfaceFWSimFieldContainer- Returns:
- position of this container in the order of execution
- See Also:
-
getAuthor
- Returns:
- the author from the description, or
null
-
getDescription
- Returns:
- the description text, or
null
-
getTitle
- Returns:
- the title from the description, or
null
-
getSkipSimulation
- Returns:
- the variable with the skip rule, or
nullif the model has noskipattribute
-
getOutputVariables
Returns all solution variables.- Specified by:
getOutputVariablesin interfaceFWSimFieldContainer- Returns:
- the output variables of the field map
- See Also:
-
getInputVariables
Returns an empty list; the solution has no input variables.- Specified by:
getInputVariablesin interfaceFWSimFieldContainer- Returns:
- the input variables of the field map
- See Also:
-
getFieldMap
Returns the solution variables (the live map).- Specified by:
getFieldMapin interfaceFWSimFieldContainer- Returns:
- the whole field map as created in
FWSimFieldContainer.createVariables() - See Also:
-
toString
-
getContentType
Returnsvar, the content type of solution variables.- Specified by:
getContentTypein interfaceFWSimFieldContainer- Returns:
- the content type of the variables of this container (e.g.
sys,mgm) - See Also:
-
setCheckerClassName
- Parameters:
aClassNameString- name of the checker class used in check level CUSTOM
-
getCheckerClassName
- Returns:
- name of the checker class used in check level CUSTOM, or
null
-
toXML
public org.jdom2.Element toXML()Rebuilds the solution element from the current state: the content ofdescription,variables,interfaces,resources,simmodelandoutputsis replaced by the XML of the description text, the solution variables (varanddyn), interfaces, resource adapters, SimComponents and output adapters. Missing elements are created in the order of the DTD; parts without XML are left out.- Specified by:
toXMLin interfaceFWSimFieldContainer- Returns:
- the solution element (changed in place)
-
createSaveBaseline
public void createSaveBaseline()Remembers the XML of all containers (variables, interfaces, resources, components, outputs) as they are now, e.g. after the solution was opened for editing.toSavedDocument()then writes only the containers whose XML has changed since. -
hasSaveBaseline
public boolean hasSaveBaseline()- Returns:
trueifcreateSaveBaseline()was called
-
hasUnsavedChanges
public boolean hasUnsavedChanges()- Returns:
trueif a container was changed, added or removed sincecreateSaveBaseline(), i.e. the solution has to be saved;falsewithout baseline
-
toSavedDocument
public org.jdom2.Document toSavedDocument()Returns the solution document for saving after editing (#62): the file as read, in which only the containers are replaced whose XML has changed sincecreateSaveBaseline()(in place), containers removed since are deleted and new ones are appended to their section. Everything else - unchanged containers, comments, formatting, parts unknown to the object model - stays as in the file. (Writing the whole solution withtoXML()loses information, e.g. the interface of transformers.) Without baseline,toXML()is used.- Returns:
- the document to write
-
setInputSource
public void setInputSource(FWSimComponent aComponent, String aInputId, String aSource) throws SimLinkInvalidException Links an input of a SimComponent to a source variable, replaces or removes its link (e.g. from the input dialog of the GUI, Redmine #62). The source is a name of the template (solution variable, resource or component variable, e.g.CURRENT.DOY).- Parameters:
aComponent- the componentaInputId- id of the input (without component name)aSource- name of the source variable, ornull/empty to remove the link- Throws:
SimLinkInvalidException- if the input or the source does not exist or the data types differ (the old link is kept then)
-
addLink
Adds a link created in the graph panel: links the destination variable to the source variable in the template variable map and registers the source as input of the destination SimComponent.- Parameters:
aSimVarLink- the link; its destination must belong to aFWSimComponent- Throws:
SimLinkInvalidException- if the link is invalid
-
removeLink
Removes a link created in the graph panel: from the header of an output adapter, or from the template variable map and the inputs of the destination SimComponent.- Parameters:
aSimVarLink- the link
-
removeSimFieldContainer
public void removeSimFieldContainer(FWSimFieldContainer aFieldContainer, Collection<ArrayList<SimFieldLink>> aSimFieldLinks) Removes a SimComponent, output adapter or resource adapter/transformer from the solution, including all links from and to it.- Parameters:
aFieldContainer- the field container to removeaSimFieldLinks- the links of the graph panel (grouped by field container)
-
getFrequence
ReturnsFWSimIOAdapter.FREQUENCE.NON; the solution is not processed during the simulation.- Specified by:
getFrequencein interfaceFWSimFieldContainer- Returns:
- the frequency in which this container is called, or
nullif not applicable - See Also:
-
getCreateFormXML
public org.jdom2.Element getCreateFormXML()Returnsnull; a solution cannot be created by a form.- Specified by:
getCreateFormXMLin interfaceFWSimFieldContainer- Returns:
- the XML form definition used by the GUI to create this container
- See Also:
-
getEditFormXML
public org.jdom2.Element getEditFormXML(boolean aEnabled) Returns a form with a choice of the solution variables to edit.aEnabledis not used.- Specified by:
getEditFormXMLin interfaceFWSimFieldContainer- Parameters:
aEnabled- iffalse, the form fields are read-only- Returns:
- the XML form definition used by the GUI to edit the settings of this container
- See Also:
-
getDynamicForm
Creates the form for the dynamic solution variables (dyn), sorted by their order (or by name if an order is missing). Values already present in the observable are set to the variables first. The solution registers itself as observer, so changes in the form are written to the variables (seeupdate(FWObservable, Object)).- Parameters:
aObservable- the form data- Returns:
- the form element, or
nullif there are no dynamic variables
-
getDynamicForm
LikegetDynamicForm(FWObservable), but the variables set by a project (project data columns, calibration/sensitivity targets) are shown disabled with the note "set by project": a project overwrites them, so a change in the form would have no effect.- Parameters:
aObservable- the form dataaSetByProject- names of the variables the project sets- Returns:
- the form element, or
nullif there is no dynamic variable left to change
-
update
Writes a changed form value to the variable of the same name in the template variable map.- Specified by:
updatein interfaceFWObserver- Parameters:
aFormObservable- the form dataaArg- name of the changed field
-
showDescription
public void showDescription()Creates an HTML overview of the solution (description, variables, resources, SimComponents with links to their documentation on simplace.net, outputs), writes it to a temporary file and opens it in the external browser. Errors are logged. The description is converted withcreateHTML(String)(TracWiki parts); the description of the solution itself is not changed. -
getVarMap
Returns the template variable map.- Specified by:
getVarMapin interfaceFWSimFieldContainer- Returns:
- the var map this container belongs to
- See Also:
-
getSolutionElement
public org.jdom2.Element getSolutionElement()- Returns:
- the root element of the solution
-
checkCondition
Passes the check to the checker of the session.- Specified by:
checkConditionin interfaceFWSimFieldContainer- Parameters:
aCheckResult- result of the check;falsemeans the condition is violatedaMessage- message describing the condition- See Also:
-
isConditionCheck
public boolean isConditionCheck()Asks the checker of the session.- Specified by:
isConditionCheckin interfaceFWSimFieldContainer- Returns:
trueif conditions are checked with the current check level of the session- See Also:
-