JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
RBContainer.java
Go to the documentation of this file.
1 package rb;
2 
3 import jarmos.Log;
4 import jarmos.ModelType;
6 
7 import java.io.IOException;
8 
11 
27 public class RBContainer {
28 
29  // String for log printing
30  static final String DEBUG_TAG = "RBContainer";
31 
35  public String descriptionURL;
36  private SCMType fSCMType = SCMType.NONE;
37 
38  private SystemType fSystemType = SystemType.NONE;
42  public RBSCMSystem mRbScmSystem = null;
46  public RBSystem mRbSystem = null;
47 
52 
56  public String problemDescription;
60  public String problemTitle;
61 
65  public SCMType getSCMType() {
66  return fSCMType;
67  }
68 
73  return fSystemType;
74  }
75 
76  @SuppressWarnings("unchecked")
77  private void loadAffineFunctions(AModelManager m) throws Exception {
78 
79  ClassLoader cl = m.getClassLoader();
80  Class<?> af = cl.loadClass(m.getModelPackageStr() + "AffineFunctions");
81 
82  Log.d(DEBUG_TAG, "Loaded AffineFunctions class");
83 
84  if (mRbSystem != null) {
85  mRbSystem.oldAffFcnCl = af;
86  mRbSystem.oldAffFcnObj = af.newInstance();
87  if (m.getModelType() == ModelType.rbappmit) {
88  mRbSystem.affineFunctionsClass = IAffineFunctions.class;
89  mRbSystem.affineFunctionsInstance = new rbappmitAffineFunctions(af, af.newInstance());
90  } else {
91  mRbSystem.affineFunctionsClass = (Class<IAffineFunctions>) af;
92  mRbSystem.affineFunctionsInstance = mRbSystem.affineFunctionsClass.newInstance();
93  }
94  }
95 
96  // if (mRbScmSystem != null) {
97  // mRbScmSystem.oldAffFcnCl = af;
98  // mRbScmSystem.oldAffFcnObj = af.newInstance();
99  // if (m.getModelType() == ModelType.rbappmit) {
100  // mRbScmSystem.affineFunctionsClass = IAffineFunctions.class;
101  // mRbScmSystem.affineFunctionsInstance = new rbappmitAffineFunctions(
102  // af, af.newInstance());
103  // } else {
104  // mRbScmSystem.affineFunctionsClass = (Class<IAffineFunctions>) af;
105  // mRbScmSystem.affineFunctionsInstance = mRbSystem.affineFunctionsClass
106  // .newInstance();
107  // }
108  // }
109  }
110 
118  public boolean loadModel(AModelManager m) {
119 
120  // First, clear all the systems in case we're doing a new (different)
121  // problem
122  mRbScmSystem = null;
123  mRbSystem = null;
124 
125  // Read system types and misc data into RBContainer
126  if (m.getModelType() == ModelType.rbappmit) {
127  if (!readSystemDescriptionsRBAppMit(m))
128  return false;
129  } else {
130  readSystemDescriptionsJRB(m);
131  }
132 
133  // Init the main systems
134  mRbSystem = fSystemType.getNewRBSystem();
135  mRbScmSystem = fSCMType.getNewRBSCMSystem(mRbSystem);
136 
137  // Assign SCM system
138  mRbSystem.setPrimarySCM(mRbScmSystem);
139 
140  try {
141  /*
142  * Requires the system configurations to be set already for
143  * backwards compatibility! See rbappmitAffineFunctions class.
144  */
145  loadAffineFunctions(m);
146  } catch (Exception e) {
147  Log.e(DEBUG_TAG, "Exception occurred while loading affine functions: " + e.getMessage(), e);
148  return false;
149  }
150 
151  // Finally, load the RB and SCM system offline data
152  try {
153  if (mRbSystem != null) {
154  // Read parameters into RB systems
156  return false;
157  mRbSystem.loadOfflineData(m);
158  Log.d(DEBUG_TAG, "Finished reading offline data for RBSystem.");
159  }
160 
161  if (mRbScmSystem != null) {
162  // Read parameters into SCM systems
163  mRbScmSystem.readConfiguration(m);
164  mRbScmSystem.loadOfflineData(m);
165  Log.d(DEBUG_TAG, "Finished reading offline data for RBSCMSystem.");
166  }
167 
168  /*
169  * A second SCM system seems not to be used within any of the
170  * current demos. If needed, uncomment this and one line in the
171  * loadSecondSCMSystem method to enable its use. Even so, it seems
172  * the second SCM system does not get loaded any offline data at the
173  * current state of the code.
174  */
175  // loadSecondSCMSystem(m);
176 
177  } catch (Exception e) {
178  Log.e(DEBUG_TAG, "Exception occurred while reading offline data: " + e.getMessage(), e);
179  return false;
180  }
181  return true;
182  }
183 
184  // @SuppressWarnings("unused")
185  // private boolean loadSecondSCMSystem(AModelManager m)
186  // throws InstantiationException, IllegalAccessException {
187  // mSecondRbScmSystem = null;
188  // if (fSCMType == SCMType.COERCIVE_ALPHASIGMA) {
189  // mSecondRbScmSystem = fSCMType.getNewRBSCMSystem();
190  //
191  // if (mSecondRbScmSystem != null) {
192  // if (fSystemType == SystemType.LINEAR_UNSTEADY) {
193  // /*
194  // * Uncomment this line to restore previous status using an
195  // * optional second SCM system.
196  // */
197  // // ((TransientRBSystem)
198  // // mRbSystem).setSecondarySCM(mSecondRbScmSystem);
199  // }
200  //
201  // if (!mSecondRbScmSystem.readConfiguration(m))
202  // return false;
203  //
204  // // Attach AffineFunctions class also to this system
205  // mSecondRbScmSystem.affineFunctionsClass = mRbScmSystem.affineFunctionsClass;
206  // mSecondRbScmSystem.oldAffFcnCl = mRbSystem.oldAffFcnCl;
207  // mSecondRbScmSystem.affineFunctionsInstance = mRbSystem.affineFunctionsClass
208  // .newInstance();
209  // mSecondRbScmSystem.oldAffFcnObj = mRbSystem.oldAffFcnObj;
210  // }
211  // }
212  // return true;
213  // }
214 
215  private void readSystemDescriptionsJRB(AModelManager m) {
216  problemTitle = m.getModelXMLTagValue("description.name");
217 
218  // TODO: Dont know where this value is used
219  descriptionURL = m.getModelXMLTagValue("description.infohtml");
220 
221  fSystemType = SystemType.parse(m.getModelXMLTagValue("rb_model.systype"));
222  fSCMType = SCMType.parse(m.getModelXMLTagValue("rb_model.scmtype"));
223 
224  Log.d(DEBUG_TAG, "RB system type = " + fSystemType);
225  Log.d(DEBUG_TAG, "SCM type = " + fSCMType);
226  }
227 
228  private boolean readSystemDescriptionsRBAppMit(AModelManager m) {
229  // GetPot infile = m.getParamFileGetPot();
230  GetPot infile = null;
231  try {
232  infile = new GetPot(m.getInStream(Const.parameters_filename), Const.parameters_filename);
233  } catch (IOException e) {
234  Log.e("RBContainer", "Exception loading infile.in", e);
235  e.printStackTrace();
236  return false;
237  }
238 
239  problemTitle = infile.call("title", "RB Online");
240  descriptionURL = infile.call("descriptionURL", "");
241 
242  String SystemTypeEnum_in = infile.call("system_type", "NONE");
243  fSystemType = SystemType.parse(SystemTypeEnum_in);
244 
245  String SCMTypeEnum_in = infile.call("scm_type", "NONE");
246  fSCMType = SCMType.parse(SCMTypeEnum_in);
247 
248  Log.d(DEBUG_TAG, "RB system type = " + fSystemType);
249  Log.d(DEBUG_TAG, "SCM type = " + fSCMType);
250  return true;
251  }
252 
253 }
Compatibility class for old rbAppMIT affine functions.
SystemType getSystemType()
String problemTitle
Descriptive member variables for the problem title, variable names, and general info.
This class provides the Online stage for the reduced basis method for elliptic steady state problems...
Definition: RBSystem.java:54
RBSystem mRbSystem
The RBSystem object.
final boolean readConfiguration(AModelManager m)
Definition: RBSystem.java:1506
An rbappmit-model of old data format, compatible with JRB models.
Definition: ModelType.java:28
SCMType getSCMType()
Base class for RB models and systems.
Base interface for any affine functions used as an externally loaded class.
This class implements the Online stage of the Successive Constraint Method for coercive problems...
Known model types within the JaRMoSBase project.
Definition: ModelType.java:9
This class serves as base class for accessing various types of models at different locations...
NONE
Not an SCM system.
Definition: SCMType.java:16
Enum containing the known SCM (successive constraint method) model types in JRB.
Definition: SCMType.java:12
boolean loadModel(AModelManager m)
Loads an rb/rbappmit type model using a provided ModelManager.
ModelType getModelType()
Returns the model type as given in the model.xml attribute &quot;type&quot; of the &quot;model&quot; tag.
Provides a Log class imitating the Android Log class when not used on android systems.
Definition: Log.java:11
String descriptionURL
Some url :-)
static final String parameters_filename
Inherited from the rbAppMIT models to read the model parameters.
Definition: Const.java:13
String problemDescription
A short problem description.
static final String DEBUG_TAG
NONE
No system type.
Definition: SystemType.java:17
RBSCMSystem mSecondRbScmSystem
The second RBSCMSystem object, needed in some time-dependent problems.
Enum for known RB system types in JRB.
Definition: SystemType.java:13
RBSCMSystem mRbScmSystem
The main RBSCMSystem object.