JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
rbappmitAffineFunctions.java
Go to the documentation of this file.
1 package rb.affinefcn;
2 
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
5 
14 
15  /*
16  * The wrapped classes.
17  */
18  private Class<?> affineFunctionsClass;
19  private Object affineFunctionsInstance;
20 
27  public rbappmitAffineFunctions(Class<?> theclass, Object inst) {
28  affineFunctionsClass = theclass;
29  affineFunctionsInstance = inst;
30  }
31 
35  @Override
36  public int getQuL() {
37  /*
38  * Extra for QuL, as it checks via exception if function is there
39  */
40  Method meth;
41  boolean noQ_uLdefined = false;
42  try {
43  // Get a reference to get_n_A_functions, which does not
44  // take any arguments
45  meth = affineFunctionsClass.getMethod("get_n_uL_functions", (Class<?>[]) null);
46  } catch (NoSuchMethodException nsme) {
47  // throw new
48  // RuntimeException("getMethod for get_n_uL_functions failed",
49  // nsme);
50  noQ_uLdefined = true;
51  meth = null;
52  }
53 
54  if (noQ_uLdefined)
55  return 0;
56  else {
57  Integer Q_uL;
58  try {
59  Object Q_uL_obj = meth.invoke(affineFunctionsInstance, (Object[]) null);
60  Q_uL = (Integer) Q_uL_obj;
61  } catch (IllegalAccessException iae) {
62  throw new RuntimeException(iae);
63  } catch (InvocationTargetException ite) {
64  throw new RuntimeException(ite.getCause());
65  }
66  return Q_uL.intValue();
67  }
68  }
69 
74  @Override
75  public double thetaQm(int i, double[] p, double t) {
76  Method meth;
77 
78  try {
79  // Get a reference to get_n_M_functions, which does not
80  // take any arguments
81 
82  Class<?> partypes[] = new Class[2];
83  partypes[0] = Integer.TYPE;
84  partypes[1] = double[].class;
85 
86  meth = affineFunctionsClass.getMethod("evaluateM", partypes);
87  } catch (NoSuchMethodException nsme) {
88  throw new RuntimeException("getMethod for evaluateM failed", nsme);
89  }
90 
91  Double theta_val;
92  try {
93  Object arglist[] = new Object[2];
94  arglist[0] = new Integer(i);
95  arglist[1] = p;
96 
97  Object theta_obj = meth.invoke(affineFunctionsInstance, arglist);
98  theta_val = (Double) theta_obj;
99  } catch (IllegalAccessException iae) {
100  throw new RuntimeException(iae);
101  } catch (InvocationTargetException ite) {
102  throw new RuntimeException(ite.getCause());
103  }
104 
105  return theta_val.doubleValue();
106  }
107 
111  @Override
112  public int getQm() {
113  Method meth;
114  try {
115  // Get a reference to get_n_A_functions, which does not
116  // take any arguments
117  meth = affineFunctionsClass.getMethod("get_n_M_functions", (Class<?>[]) null);
118  } catch (NoSuchMethodException nsme) {
119  throw new RuntimeException("getMethod for get_n_M_functions failed", nsme);
120  }
121  try {
122  Object Q_m_obj = meth.invoke(affineFunctionsInstance, (Object[]) null);
123  return (Integer) Q_m_obj;
124  } catch (IllegalAccessException iae) {
125  throw new RuntimeException(iae);
126  } catch (InvocationTargetException ite) {
127  throw new RuntimeException(ite.getCause());
128  }
129  }
130 
134  @Override
135  public boolean isTimeDependentL() {
136  // TODO Auto-generated method stub
137  return false;
138  }
139 
143  @Override
144  public boolean isTimeDependentA() {
145  // TODO Auto-generated method stub
146  return false;
147  }
148 
152  @Override
153  public int[] getQl() {
154  Method meth;
155  try {
156  Class<?> partypes[] = new Class[1];
157  partypes[0] = Integer.TYPE;
158  meth = affineFunctionsClass.getMethod("get_Q_l", partypes);
159  int no = getNumOutputs();
160  int[] Ql_values = new int[no];
161  Object arglist[] = new Object[1];
162  for (int i = 0; i < no; i++) {
163  arglist[0] = i;
164  Ql_values[i] = (Integer) meth.invoke(affineFunctionsInstance, arglist);
165  }
166  return Ql_values;
167  } catch (NoSuchMethodException nsme) {
168  throw new RuntimeException("getMethod failed: " + nsme.getMessage(), nsme);
169  } catch (IllegalAccessException iae) {
170  throw new RuntimeException(iae);
171  } catch (InvocationTargetException ite) {
172  throw new RuntimeException(ite.getCause());
173  }
174  }
175 
179  @Override
180  public double thetaQl(int i, int q_l, double[] p, double t) {
181  Method meth;
182 
183  try {
184  // Get a reference to get_n_L_functions, which does not
185  // take any arguments
186 
187  Class<?> partypes[] = new Class[3];
188  partypes[0] = Integer.TYPE;
189  partypes[1] = Integer.TYPE;
190  partypes[2] = double[].class;
191 
192  meth = affineFunctionsClass.getMethod("evaluateL", partypes);
193  } catch (NoSuchMethodException nsme) {
194  throw new RuntimeException("getMethod for evaluateL failed", nsme);
195  }
196 
197  Double theta_val;
198  try {
199  Object arglist[] = new Object[3];
200  arglist[0] = new Integer(i);
201  arglist[1] = new Integer(q_l);
202  arglist[2] = p;
203 
204  Object theta_obj = meth.invoke(affineFunctionsInstance, arglist);
205  theta_val = (Double) theta_obj;
206  } catch (IllegalAccessException iae) {
207  throw new RuntimeException(iae);
208  } catch (InvocationTargetException ite) {
209  throw new RuntimeException(ite.getCause());
210  }
211 
212  return theta_val.doubleValue();
213  }
214 
218  @Override
219  public int getQf() {
220  try {
221  Method meth = affineFunctionsClass.getMethod("get_n_F_functions", (Class<?>[]) null);
222  return (Integer) meth.invoke(affineFunctionsInstance, (Object[]) null);
223  } catch (NoSuchMethodException nsme) {
224  throw new RuntimeException("getMethod failed: " + nsme.getMessage(), nsme);
225  } catch (IllegalAccessException iae) {
226  throw new RuntimeException(iae);
227  } catch (InvocationTargetException ite) {
228  throw new RuntimeException(ite.getCause());
229  }
230  }
231 
235  @Override
236  public double thetaQf(int i, double[] p, double t) {
237  Method meth;
238 
239  try {
240  // Get a reference to get_n_L_functions, which does not
241  // take any arguments
242 
243  Class<?> partypes[] = new Class[2];
244  partypes[0] = Integer.TYPE;
245  partypes[1] = double[].class;
246 
247  meth = affineFunctionsClass.getMethod("evaluateF", partypes);
248  } catch (NoSuchMethodException nsme) {
249  throw new RuntimeException("getMethod for evaluateF failed", nsme);
250  }
251 
252  Double theta_val;
253  try {
254  Object arglist[] = new Object[2];
255  arglist[0] = i;
256  arglist[1] = p;
257 
258  Object theta_obj = meth.invoke(affineFunctionsInstance, arglist);
259  theta_val = (Double) theta_obj;
260  } catch (IllegalAccessException iae) {
261  throw new RuntimeException(iae);
262  } catch (InvocationTargetException ite) {
263  throw new RuntimeException(ite.getCause());
264  }
265 
266  return theta_val.doubleValue();
267  }
268 
272  @Override
273  public int getQa() {
274  Method meth;
275 
276  try {
277  // Get a reference to get_n_A_functions, which does not
278  // take any arguments
279  meth = affineFunctionsClass.getMethod("get_n_A_functions", (Class<?>[]) null);
280  } catch (NoSuchMethodException nsme) {
281  throw new RuntimeException("getMethod for get_n_A_functions failed", nsme);
282  }
283 
284  Integer Q_a;
285  try {
286  Object Q_a_obj = meth.invoke(affineFunctionsInstance, (Object[]) null);
287  Q_a = (Integer) Q_a_obj;
288  } catch (IllegalAccessException iae) {
289  throw new RuntimeException(iae);
290  } catch (InvocationTargetException ite) {
291  throw new RuntimeException(ite.getCause());
292  }
293 
294  return Q_a.intValue();
295  }
296 
300  @Override
301  public double thetaQa(int i, double[] p, double t) {
302  Method meth;
303 
304  try {
305  // Get a reference to get_n_L_functions, which does not
306  // take any arguments
307 
308  Class<?> partypes[] = new Class[2];
309  partypes[0] = Integer.TYPE;
310  partypes[1] = double[].class;
311 
312  meth = affineFunctionsClass.getMethod("evaluateA", partypes);
313  } catch (NoSuchMethodException nsme) {
314  throw new RuntimeException("getMethod for evaluateA failed", nsme);
315  }
316 
317  Double theta_val;
318  try {
319  Object arglist[] = new Object[2];
320  arglist[0] = i;
321  arglist[1] = p;
322 
323  Object theta_obj = meth.invoke(affineFunctionsInstance, arglist);
324  theta_val = (Double) theta_obj;
325  } catch (IllegalAccessException iae) {
326  throw new RuntimeException(iae);
327  } catch (InvocationTargetException ite) {
328  throw new RuntimeException(ite.getCause());
329  }
330 
331  return theta_val.doubleValue();
332  }
333 
337  @Override
338  public int getNumOutputs() {
339  try {
340  // Get a reference to get_n_L_functions, which does not
341  // take any arguments
342  Method meth = affineFunctionsClass.getMethod("get_n_outputs", (Class<?>[]) null);
343  Object n_outputs_obj = meth.invoke(affineFunctionsInstance, (Object[]) null);
344  Integer n_outputs = (Integer) n_outputs_obj;
345  return n_outputs.intValue();
346  } catch (NoSuchMethodException nsme) {
347  throw new RuntimeException("getMethod failed: " + nsme.getMessage(), nsme);
348  } catch (IllegalAccessException iae) {
349  throw new RuntimeException(iae);
350  } catch (InvocationTargetException ite) {
351  throw new RuntimeException(ite.getCause());
352  }
353  }
354 
358  @Override
359  public boolean isTimeDependentM() {
360  return false;
361  }
362 
363 }
Interface for models using the mQ_uL fields.
Definition: IWithuL.java:11
Compatibility class for old rbAppMIT affine functions.
Interface for AffineFunctions in unsteady rb systems.
Definition: ITransient.java:12
double thetaQl(int i, int q_l, double[] p, double t)
Base interface for any affine functions used as an externally loaded class.
double thetaQf(int i, double[] p, double t)
rbappmitAffineFunctions(Class<?> theclass, Object inst)
Creates a wrapper for the old rbAppMIT affine functions classes.
double thetaQm(int i, double[] p, double t)
double thetaQa(int i, double[] p, double t)