JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
RBSystem.java
Go to the documentation of this file.
1 package rb;
2 
5 import jarmos.Log;
6 import jarmos.ModelBase;
7 import jarmos.ModelType;
8 import jarmos.Parameters;
18 
19 import java.io.BufferedReader;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27 
28 import org.apache.commons.math.complex.Complex;
29 import org.apache.commons.math.linear.Array2DRowRealMatrix;
30 import org.apache.commons.math.linear.ArrayFieldVector;
31 import org.apache.commons.math.linear.ArrayRealVector;
32 import org.apache.commons.math.linear.DecompositionSolver;
33 import org.apache.commons.math.linear.FieldVector;
34 import org.apache.commons.math.linear.LUDecompositionImpl;
35 import org.apache.commons.math.linear.RealMatrix;
36 import org.apache.commons.math.linear.RealVector;
37 
41 
54 public class RBSystem extends ModelBase {
55 
56  // Logging tag
57  private static final String DEBUG_TAG = "RBSystem";
58 
62  private static final int MAX_SWEEP_POINTS = 10;
63 
69  public Class<IAffineFunctions> affineFunctionsClass;
76 
77  protected double[][][] Aq_Aq_representor_norms;
78 
79  // current N
80  protected int current_N;
81 
82  // The number of output functionals
83  private int fNumOutputs;
84 
85  protected double[][][] Fq_Aq_representor_norms;
86 
91  protected double[] Fq_representor_norms;
92 
93  // PUBLIC MEMBER VARIABLES
94 
98  private int fQa;
99 
103  private int fQf;
104 
110  private int fQuL = 0;
111 
112  // PRIVATE MEMBER VARIABLES
113 
114  protected float[][][] fullBasisVectors;
115 
119  public boolean isReal = true;
120 
125 
129  private double[][] mSweepParam;
130 
134  private int numBasisFuncs;
135 
139  public Class<?> oldAffFcnCl;
140 
144  public Object oldAffFcnObj;
145 
150  public double[][] output_dual_norms;
151 
155  private Parameters params;
156 
157  // The affine function expansion size for all outputs
158  private int[] Ql_values;
159 
163  protected RealMatrix[] RB_A_q_vector;
164 
168  protected RealVector[] RB_F_q_vector;
169 
173  private RealVector[] RB_initial_coeffs;
174 
178  public double[] RB_output_error_bounds;
179 
183  public double[][] RB_output_error_bounds_all_k;
187  protected RealVector[][] RB_output_vectors;
191  public double[] RB_outputs;
192 
193  // (those two below are moved from TransientRBSystem
197  public double[][] RB_outputs_all_k;
201  protected RealVector RB_solution;
202 
203  protected double[][][] RB_sweep_solution;
204 
209  public boolean return_rel_error_bound;
210 
211  private double sweepIncrement = 0;
212 
213  private double[][] sweepOutputBounds;
214  private double[][] sweepOutputs;
215 
216  private Method transformationMethod = null;
217 
218  protected float[][] uL_vector;
219 
220  protected List<MeshTransform> transforms;
221 
225  public RBSystem() {
226 
227  // Initialize n_bfs to 0
228  numBasisFuncs = 0;
229  transforms = new ArrayList<MeshTransform>();
230  }
231 
232  // PUBLIC FUNCTIONS
233 
238  public FieldVector<Complex> complex_eval_theta_q_a() {
239  Method meth;
240  // Complex c;
241 
242  try {
243  // Get a reference to get_n_L_functions, which does not
244  // take any arguments
245 
246  Class<?> partypes[] = new Class[1];
247  partypes[0] = double[].class;
248 
249  meth = oldAffFcnCl.getMethod("evaluateA_array", partypes);
250  } catch (NoSuchMethodException nsme) {
251  FieldVector<Complex> c = new ArrayFieldVector<Complex>(fQa, new Complex(0d, 0d));
252  for (int i = 0; i < fQa; i++)
253  c.setEntry(i, complex_eval_theta_q_a(i));
254  return c;
255  // throw new RuntimeException("getMethod for evaluateA failed",
256  // nsme);
257  }
258 
259  double[][] theta_val;
260  try {
261  Object arglist[] = new Object[1];
262  arglist[0] = params.getCurrent();
263  Object theta_obj = meth.invoke(oldAffFcnObj, arglist);
264  theta_val = (double[][]) theta_obj;
265  } catch (IllegalAccessException iae) {
266  throw new RuntimeException(iae);
267  } catch (InvocationTargetException ite) {
268  throw new RuntimeException(ite.getCause());
269  }
270  FieldVector<Complex> c = new ArrayFieldVector<Complex>(fQa, new Complex(0d, 0d));
271  for (int i = 0; i < fQa; i++)
272  c.setEntry(i, new Complex(theta_val[i][0], theta_val[i][1]));
273 
274  return c;
275  }
276 
277  public Complex complex_eval_theta_q_a(int q) {
278  Method meth;
279  // Complex c;
280 
281  try {
282  // Get a reference to get_n_L_functions, which does not
283  // take any arguments
284 
285  Class<?> partypes[] = new Class[3];
286  partypes[0] = Integer.TYPE;
287  partypes[1] = double[].class;
288  partypes[2] = boolean.class;
289 
290  meth = oldAffFcnCl.getMethod("evaluateA", partypes);
291  } catch (NoSuchMethodException nsme) {
292  throw new RuntimeException("getMethod for evaluateA failed", nsme);
293  }
294 
295  Double theta_val_r, theta_val_i;
296  try {
297  Object arglist[] = new Object[3];
298  arglist[0] = new Integer(q);
299  arglist[1] = params.getCurrent();
300  arglist[2] = true;
301 
302  Object theta_obj = meth.invoke(oldAffFcnObj, arglist);
303  theta_val_r = (Double) theta_obj;
304 
305  arglist[2] = false;
306  theta_val_i = (Double) meth.invoke(oldAffFcnObj, arglist);
307  } catch (IllegalAccessException iae) {
308  throw new RuntimeException(iae);
309  } catch (InvocationTargetException ite) {
310  throw new RuntimeException(ite.getCause());
311  }
312  Complex c = new Complex(theta_val_r.doubleValue(), theta_val_i.doubleValue());
313 
314  return c;
315  }
316 
317  public Complex complex_eval_theta_q_f(int q) {
318  Method meth;
319  // Complex c;
320 
321  try {
322  // Get a reference to get_n_L_functions, which does not
323  // take any arguments
324 
325  Class<?> partypes[] = new Class[3];
326  partypes[0] = Integer.TYPE;
327  partypes[1] = double[].class;
328  partypes[2] = boolean.class;
329 
330  meth = oldAffFcnCl.getMethod("evaluateF", partypes);
331  } catch (NoSuchMethodException nsme) {
332  throw new RuntimeException("getMethod for evaluateF failed", nsme);
333  }
334 
335  Double theta_val_r, theta_val_i;
336  try {
337  Object arglist[] = new Object[3];
338  arglist[0] = new Integer(q);
339  arglist[1] = params.getCurrent();
340  arglist[2] = true;
341 
342  Object theta_obj = meth.invoke(oldAffFcnObj, arglist);
343  theta_val_r = (Double) theta_obj;
344 
345  arglist[2] = false;
346  theta_val_i = (Double) meth.invoke(oldAffFcnObj, arglist);
347  } catch (IllegalAccessException iae) {
348  throw new RuntimeException(iae);
349  } catch (InvocationTargetException ite) {
350  throw new RuntimeException(ite.getCause());
351  }
352  Complex c = new Complex(theta_val_r.doubleValue(), theta_val_i.doubleValue());
353 
354  return c;
355  }
356 
357  public Complex complex_eval_theta_q_l(int n, int q) {
358  Method meth;
359  // Complex c;
360 
361  try {
362  // Get a reference to get_n_L_functions, which does not
363  // take any arguments
364 
365  Class<?> partypes[] = new Class[4];
366  partypes[0] = Integer.TYPE;
367  partypes[1] = Integer.TYPE;
368  partypes[2] = double[].class;
369  partypes[3] = boolean.class;
370 
371  meth = oldAffFcnCl.getMethod("evaluateL", partypes);
372  } catch (NoSuchMethodException nsme) {
373  throw new RuntimeException("getMethod for evaluateL failed", nsme);
374  }
375 
376  Double theta_val_r, theta_val_i;
377  try {
378  Object arglist[] = new Object[4];
379  arglist[0] = new Integer(n);
380  arglist[1] = new Integer(q);
381  arglist[2] = params.getCurrent();
382  arglist[3] = true;
383 
384  Object theta_obj = meth.invoke(oldAffFcnObj, arglist);
385  theta_val_r = (Double) theta_obj;
386 
387  arglist[3] = false;
388  theta_val_i = (Double) meth.invoke(oldAffFcnObj, arglist);
389  } catch (IllegalAccessException iae) {
390  throw new RuntimeException(iae);
391  } catch (InvocationTargetException ite) {
392  throw new RuntimeException(ite.getCause());
393  }
394  Complex c = new Complex(theta_val_r.doubleValue(), theta_val_i.doubleValue());
395 
396  return c;
397  }
398 
402  protected double compute_output_dual_norm(int i, double t) {
403 
404  // Use the stored representor inner product values
405  // to evaluate the output dual norm
406  double output_norm_sq = 0.;
407 
408  int q = 0;
409  for (int q_l1 = 0; q_l1 < getQl(i); q_l1++) {
410  for (int q_l2 = q_l1; q_l2 < getQl(i); q_l2++) {
411  double delta = (q_l1 == q_l2) ? 1. : 2.;
412  output_norm_sq += delta * thetaQl(i, q_l1, t) * thetaQl(i, q_l2, t) * output_dual_norms[i][q];
413  q++;
414  }
415  }
416 
417  return Math.sqrt(output_norm_sq);
418  }
419 
423  protected double compute_residual_dual_norm(int N) {
424 
425  // Use the stored representor inner product values
426  // to evaluate the residual norm
427  double residual_norm_sq = 0.;
428 
429  int q = 0;
430  for (int q_f1 = 0; q_f1 < getQf(); q_f1++) {
431  for (int q_f2 = q_f1; q_f2 < getQf(); q_f2++) {
432  double delta = (q_f1 == q_f2) ? 1. : 2.;
433  residual_norm_sq += delta * thetaQf(q_f1) * thetaQf(q_f2) * Fq_representor_norms[q];
434 
435  q++;
436  }
437  }
438 
439  for (int q_f = 0; q_f < getQf(); q_f++) {
440  for (int q_a = 0; q_a < getQa(); q_a++) {
441  for (int i = 0; i < N; i++) {
442  double delta = 2.;
443  residual_norm_sq += get_soln_coeff(i) * delta * thetaQf(q_f) * thetaQa(q_a)
444  * Fq_Aq_representor_norms[q_f][q_a][i];
445  }
446  }
447  }
448 
449  q = 0;
450  for (int q_a1 = 0; q_a1 < getQa(); q_a1++) {
451  for (int q_a2 = q_a1; q_a2 < getQa(); q_a2++) {
452  double delta = (q_a1 == q_a2) ? 1. : 2.;
453 
454  for (int i = 0; i < N; i++) {
455  for (int j = 0; j < N; j++) {
456  residual_norm_sq += get_soln_coeff(i) * get_soln_coeff(j) * delta * thetaQa(q_a1)
457  * thetaQa(q_a2) * Aq_Aq_representor_norms[q][i][j];
458  }
459  }
460 
461  q++;
462  }
463  }
464 
465  if (residual_norm_sq < 0.) {
466  // Sometimes this is negative due to rounding error,
467  // but error is on the order of 1.e-10, so shouldn't
468  // affect error bound much...
469  residual_norm_sq = Math.abs(residual_norm_sq);
470  }
471 
472  return Math.sqrt(residual_norm_sq);
473  }
474 
475  // /**
476  // * @param mu
477  // * @param gData
478  // */
479  // public void customMeshTransform(double[][] mu, GeometryData gData) {
480  // int numT = mu.length;
481  //
482  // gData.vertices = new float[numT * gData.getNumVertices() * 3];
483  // for (int i = 0; i < numT; i++) {
484  // // get current nodal data
485  // float[] tmpnode = rbappmitCustomMeshTransform(mu[i],
486  // gData.originalVertices.clone());
487  // // Log.d("GLRenderer", mu[i][0] + " " + mu[i][1]);
488  // // Log.d("GLRenderer", tmpnode[4] + " " + data.vertices[4]);
489  // // copy current nodal data into animation list
490  // for (int j = 0; j < gData.getNumVertices(); j++) {
491  // for (int k = 0; k < 3; k++) {
492  // gData.vertices[i * gData.getNumVertices() * 3 + j * 3 + k] = tmpnode[j *
493  // 3 + k];
494  // }
495  // }
496  // }
497  // }
498 
499  public int get_N() {
500  return current_N;
501  }
502 
503  public double get_RB_output(int n_output, boolean Rpart) {
504  return RB_outputs[n_output];
505  }
506 
507  public double get_RB_output_error_bound(int n_output, boolean Rpart) {
508  return RB_output_error_bounds[n_output];
509  }
510 
511  protected double[][] get_RBsolution() {
512  return new double[][] { RB_solution.toArray() };
513  }
514 
518  protected double get_SCM_from_AffineFunction() {
519  // we assume that an SCM LB function has been specified
520  // in AffineFunctions.jar
521  Method meth;
522 
523  try {
524  Class<?> partypes[] = new Class[1];
525  partypes[0] = double[].class;
526 
527  meth = oldAffFcnCl.getMethod("get_SCM_LB", partypes);
528  } catch (NoSuchMethodException nsme) {
529  throw new RuntimeException("getMethod for get_SCM_LB failed", nsme);
530  }
531 
532  Double SCM_val;
533  try {
534  Object arglist[] = new Object[1];
535  arglist[0] = getParams().getCurrent();
536 
537  Object SCM_obj = meth.invoke(oldAffFcnObj, arglist);
538  SCM_val = (Double) SCM_obj;
539  } catch (IllegalAccessException iae) {
540  throw new RuntimeException(iae);
541  } catch (InvocationTargetException ite) {
542  throw new RuntimeException(ite.getCause());
543  }
544 
545  return SCM_val.doubleValue();
546  }
547 
551  public double get_SCM_lower_bound() {
552  if (mRbScmSystem != null) {
553  // mRbScmSystem.setParams(getParams());
554  return mRbScmSystem.get_SCM_LB();
555  } else {
557  }
558  }
559 
564  if (mRbScmSystem != null) {
565  // mRbScmSystem.setParams(getParams());
566  return mRbScmSystem.get_SCM_UB();
567  } else {
569  }
570  }
571 
575  double get_soln_coeff(int i) {
576  return RB_solution.getEntry(i);
577  }
578 
588  public RealVector getInitialCoefficients(int N) {
589  if (affineFunctionsInstance instanceof IAffineInitials) {
590  RealVector res = new ArrayRealVector(N);
591  IAffineInitials a = (IAffineInitials) affineFunctionsInstance;
592  for (int i = 0; i < a.getQu0(); i++) {
593  res = res.add(RB_initial_coeffs[i].getSubVector(0, N).mapMultiply(
594  a.thetaQu0(i, getParams().getCurrent())));
595  }
596  return res;
597  } else {
598  return RB_initial_coeffs[0].getSubVector(0, N);
599  }
600  }
601 
605  public int getNBF() {
606  return numBasisFuncs;
607  }
608 
612  public int getNumOutputs() {
613  return fNumOutputs;
614  }
615 
622  return params;
623  }
624 
628  public int getQa() {
629  return fQa;
630  }
631 
638  public int getQf() {
639  return fQf;
640  }
641 
650  protected int getQl(int output_index) {
651  return Ql_values[output_index];
652  }
653 
654  public int getQuL() {
655  return fQuL;
656  }
657 
673  int N = RB_solution.getDimension();
674  SimulationResult res = new SimulationResult(1);
675  double co;
676  int fnumcnt = 0;
677  for (FieldDescriptor sftype : logicalFieldTypes) {
678  if (fnumcnt + sftype.Type.requiredDoFFields > getNumDoFFields()) {
679  throw new RuntimeException("Too many output fields used by current "
680  + "SolutionFieldTypes set in RBSystem. Check your model.xml.");
681  }
682  int numDoF = fullBasisVectors[fnumcnt][0].length;
683  switch (sftype.Type) {
684  case Displacement3D: {
685  DisplacementField d = new DisplacementField(sftype, numDoF);
686  for (int nodenr = 0; nodenr < numDoF; nodenr++) {
687  double x = 0, y = 0, z = 0;
688  for (int rbdim = 0; rbdim < N; rbdim++) {
689  co = get_soln_coeff(rbdim);
690  x += fullBasisVectors[fnumcnt][rbdim][nodenr] * co;
691  y += fullBasisVectors[fnumcnt + 1][rbdim][nodenr] * co;
692  z += fullBasisVectors[fnumcnt + 2][rbdim][nodenr] * co;
693  }
694  d.setDisplacement(nodenr, (float) x, (float) y, (float) z);
695  }
696  res.addField(d);
697  break;
698  }
699  case Displacement2D: {
700  DisplacementField d = new DisplacementField(sftype, numDoF);
701  for (int nodenr = 0; nodenr < numDoF; nodenr++) {
702  double x = 0, y = 0;
703  for (int rbdim = 0; rbdim < N; rbdim++) {
704  co = get_soln_coeff(rbdim);
705  x += fullBasisVectors[fnumcnt][rbdim][nodenr] * co;
706  y += fullBasisVectors[fnumcnt + 1][rbdim][nodenr] * co;
707  }
708  d.setDisplacement(nodenr, (float) x, (float) y);
709  }
710  res.addField(d);
711  break;
712  }
713  case RealValue: {
714  DefaultSolutionField f = new DefaultSolutionField(sftype, numDoF);
715  for (int nodenr = 0; nodenr < numDoF; nodenr++) {
716  double x = 0;
717  for (int rbdim = 0; rbdim < N; rbdim++) {
718  x += fullBasisVectors[fnumcnt][rbdim][nodenr] * get_soln_coeff(rbdim);
719  }
720  f.setValue(nodenr, (float) x);
721  }
722  res.addField(f);
723  break;
724  }
725  default: {
726  throw new RuntimeException("Invalid/unimplemented solution field type '" + sftype + "'");
727  }
728  }
729  /*
730  * Increase field counter by the amount the current solution field
731  * used
732  */
733  fnumcnt += sftype.Type.requiredDoFFields;
734  }
735  for (MeshTransform m : transforms) {
736  res.addTransform(m);
737  }
738  return res;
739  }
740 
746  public double getSweepIncrement() {
747  return sweepIncrement;
748  }
749 
750  public double[][] getSweepOutputBounds() {
751  return sweepOutputBounds;
752  }
753 
754  public double[][] getSweepOutputs() {
755  return sweepOutputs;
756  }
757 
759  int N = RB_sweep_solution[0][0].length;
760  int numSweeps = RB_sweep_solution.length;
761 
762  double tmpval;
763  SimulationResult res = new SimulationResult(numSweeps);
764 
765  int currentDoFField = 0;
766  for (FieldDescriptor sftype : logicalFieldTypes) {
767  if (currentDoFField + sftype.Type.requiredDoFFields > getNumDoFFields()) {
768  throw new RuntimeException("Too many output fields used by current "
769  + "SolutionFieldTypes set in RBSystem. Check your model.xml.");
770  }
771  int numDoFs = fullBasisVectors[currentDoFField][0].length;
772  Log.d("RBSystem", "Creating sweep solution field of type " + sftype.Type + ", sweeps:" + numSweeps
773  + ", Dofs: " + numDoFs);
774  switch (sftype.Type) {
775  case Displacement3D: {
776  DisplacementField d = new DisplacementField(sftype, numDoFs * numSweeps);
777  for (int iSweep = 0; iSweep < numSweeps; iSweep++) {
778  for (int nodenr = 0; nodenr < numDoFs; nodenr++) {
779  double x = 0, y = 0, z = 0;
780  for (int rbdim = 0; rbdim < N; rbdim++) {
781  x += fullBasisVectors[currentDoFField][rbdim][nodenr] * RB_sweep_solution[iSweep][0][rbdim];
782  y += fullBasisVectors[currentDoFField + 1][rbdim][nodenr]
783  * RB_sweep_solution[iSweep][0][rbdim];
784  z += fullBasisVectors[currentDoFField + 2][rbdim][nodenr]
785  * RB_sweep_solution[iSweep][0][rbdim];
786  }
787  d.setDisplacement(iSweep * numDoFs + nodenr, (float) x, (float) y, (float) z);
788  }
789  }
790  res.addField(d);
791  break;
792  }
793  case Displacement2D: {
794  DisplacementField d = new DisplacementField(sftype, numDoFs * numSweeps);
795  for (int iSweep = 0; iSweep < numSweeps; iSweep++) {
796  for (int nodenr = 0; nodenr < numDoFs; nodenr++) {
797  double x = 0, y = 0;
798  for (int rbdim = 0; rbdim < N; rbdim++) {
799  x += fullBasisVectors[currentDoFField][rbdim][nodenr] * RB_sweep_solution[iSweep][0][rbdim];
800  y += fullBasisVectors[currentDoFField + 1][rbdim][nodenr]
801  * RB_sweep_solution[iSweep][0][rbdim];
802  }
803  d.setDisplacement(iSweep * numDoFs + nodenr, (float) x, (float) y);
804  }
805  }
806  res.addField(d);
807  break;
808  }
809  case RealValue: {
810  DefaultSolutionField f = new DefaultSolutionField(sftype, numSweeps * numDoFs);
811  for (int sweepNr = 0; sweepNr < numSweeps; sweepNr++) {
812  for (int i = 0; i < numDoFs; i++) {
813  tmpval = 0;
814  for (int j = 0; j < N; j++) {
815  tmpval += fullBasisVectors[currentDoFField][j][i] * RB_sweep_solution[sweepNr][0][j];
816  }
817  f.setValue(sweepNr * numDoFs + i, (float) tmpval);
818  }
819  }
820  res.addField(f);
821  break;
822  }
823  default:
824  throw new RuntimeException("Invalid/unimplemented solution field type '" + sftype.Type + "' for sweep.");
825  }
826  }
827  for (MeshTransform m : transforms) {
828  res.addTransform(m);
829  }
830  return res;
831  }
832 
838  public int getTotalTimesteps() {
839  return 1;
840  }
841 
852  protected float[][] getAffLinTransformationData(double[] mu) {
853  assert transformationMethod != null;
854  if (transformationMethod != null) {
855  try {
856  return (float[][]) transformationMethod.invoke(oldAffFcnObj, new Object[] { mu });
857  } catch (IllegalAccessException iae) {
858  throw new RuntimeException(iae);
859  } catch (InvocationTargetException ite) {
860  throw new RuntimeException(ite.getCause());
861  }
862  }
863  return null;
864  }
865 
866  public int getVisualNumTimesteps() {
867  return 1;
868  }
869 
873  protected boolean hasCustomMeshTransform() {
874  Method meth;
875 
876  try {
877  Class<?> partypes[] = null;
878  meth = oldAffFcnCl.getMethod("is_custom_mesh_transform", partypes);
879  } catch (NoSuchMethodException nsme) {
880  return false;
881  }
882 
883  try {
884  Object arglist[] = null;
885  Object theta_obj = meth.invoke(oldAffFcnObj, arglist);
886  boolean val = (Boolean) theta_obj;
887  return val;
888  } catch (IllegalAccessException iae) {
889  throw new RuntimeException(iae);
890  } catch (InvocationTargetException ite) {
891  throw new RuntimeException(ite.getCause());
892  }
893  }
894 
895  protected boolean hasAffLinTransformationData() {
896  return transformationMethod != null;
897  }
898 
902  protected void initialize_data_vectors() {
903  // Also, resize RB_outputs and RB_output_error_error_bounds arrays
904  RB_outputs = new double[getNumOutputs()];
905  RB_output_error_bounds = new double[getNumOutputs()];
906  }
907 
914  @Override
916  super.loadOfflineData(m);
917  if (m.getModelType() == ModelType.rbappmit) {
919  } else {
921  }
922 
924  }
925 
931  protected void loadOfflineData_rbappmit(AModelManager m) throws IOException {
932 
933  {
934  BufferedReader reader = m.getBufReader("n_bfs.dat");
935 
936  String line = reader.readLine();
937  numBasisFuncs = Integer.parseInt(line);
938  reader.close();
939  reader = null;
940 
941  Log.d(DEBUG_TAG, "Finished reading n_bfs.dat");
942  }
943 
944  /*
945  * Load zero initial conditions for old @ref rbappmit models
946  */
947  RB_initial_coeffs = new RealVector[1];
948  RB_initial_coeffs[0] = new ArrayRealVector(numBasisFuncs);
949 
950  // Read in output data
951  if (getNumOutputs() > 0) {
952  // Get output dual norms
953  {
954  RB_output_vectors = new RealVector[getNumOutputs()][];
955  output_dual_norms = new double[getNumOutputs()][];
956  String[] dual_norms_tokens;
957  for (int i = 0; i < getNumOutputs(); i++) {
958  {
959  BufferedReader reader = m
960  .getBufReader("output_" + String.format("%03d", i) + "_dual_norms.dat");
961 
962  String line1 = reader.readLine();
963  reader.close();
964  reader = null;
965  dual_norms_tokens = line1.split(" ");
966  }
967 
968  {
969  int Q_l_hat = getQl(i) * (getQl(i) + 1) / 2;
970  output_dual_norms[i] = new double[Q_l_hat];
971  for (int q = 0; q < Q_l_hat; q++) {
972  output_dual_norms[i][q] = Double.parseDouble(dual_norms_tokens[q]);
973  }
974  }
975 
976  RB_output_vectors[i] = new RealVector[getQl(i)];
977  String[] output_i_tokens;
978  for (int q_l = 0; q_l < getQl(i); q_l++) {
979  // Now read in the RB output vectors
980  {
981  BufferedReader reader_i = m.getBufReader("output_" + String.format("%03d", i) + "_"
982  + String.format("%03d", q_l) + ".dat");
983 
984  String line_i = reader_i.readLine();
985  reader_i.close();
986  output_i_tokens = line_i.split(" ");
987  }
988 
989  RB_output_vectors[i][q_l] = new ArrayRealVector(numBasisFuncs);
990  for (int j = 0; j < numBasisFuncs; j++) {
991  RB_output_vectors[i][q_l].setEntry(j, Double.parseDouble(output_i_tokens[j]));
992  }
993 
994  }
995  }
996  }
997  }
998 
999  Log.d(DEBUG_TAG, "Finished reading output data");
1000 
1001  // Read in the F_q vectors
1002  {
1003  RB_F_q_vector = new RealVector[getQf()];
1004  String[] tokens;
1005  for (int q_f = 0; q_f < getQf(); q_f++) {
1006  {
1007  BufferedReader reader = m.getBufReader("RB_F_" + String.format("%03d", q_f) + ".dat");
1008  String line = reader.readLine();
1009  reader.close();
1010  reader = null;
1011  tokens = line.split(" ");
1012  }
1013 
1014  // Set the size of the inner product matrix
1015  RB_F_q_vector[q_f] = new ArrayRealVector(numBasisFuncs);
1016 
1017  // Fill the vector
1018  for (int i = 0; i < numBasisFuncs; i++) {
1019  RB_F_q_vector[q_f].setEntry(i, Double.parseDouble(tokens[i]));
1020  }
1021 
1022  }
1023  Log.d(DEBUG_TAG, "Finished reading RB_F_q data");
1024  }
1025 
1026  // Read in the A_q matrices
1027  {
1028  RB_A_q_vector = new RealMatrix[getQa()];
1029  String[] tokens;
1030  for (int q_a = 0; q_a < getQa(); q_a++) {
1031  {
1032  BufferedReader reader = m.getBufReader("RB_A_" + String.format("%03d", q_a) + ".dat");
1033  String line = reader.readLine();
1034  reader.close();
1035  reader = null;
1036  tokens = line.split(" ");
1037  }
1038 
1039  // Set the size of the inner product matrix
1040  RB_A_q_vector[q_a] = new Array2DRowRealMatrix(numBasisFuncs, numBasisFuncs);
1041 
1042  // Fill the vector
1043  int count = 0;
1044  for (int i = 0; i < numBasisFuncs; i++)
1045  for (int j = 0; j < numBasisFuncs; j++) {
1046  RB_A_q_vector[q_a].setEntry(i, j, Double.parseDouble(tokens[count]));
1047  count++;
1048  }
1049 
1050  }
1051  Log.d(DEBUG_TAG, "Finished reading RB_A_q data");
1052  }
1053 
1054  // Read in F_q representor norm data
1055  {
1056  BufferedReader reader = m.getBufReader("Fq_norms.dat");
1057 
1058  String line = reader.readLine();
1059  reader.close();
1060  reader = null;
1061  String[] tokens = line.split(" ");
1062 
1063  // Declare the array
1064  int Q_f_hat = getQf() * (getQf() + 1) / 2;
1065  Fq_representor_norms = new double[Q_f_hat];
1066 
1067  // Fill it
1068  for (int i = 0; i < Q_f_hat; i++) {
1069  Fq_representor_norms[i] = Double.parseDouble(tokens[i]);
1070  }
1071 
1072  Log.d(DEBUG_TAG, "Finished reading Fq_norms.dat");
1073  }
1074 
1075  // Read in Fq_Aq representor norm data
1076  {
1077  BufferedReader reader = m.getBufReader("Fq_Aq_norms.dat");
1078  String line = reader.readLine();
1079  reader.close();
1080  reader = null;
1081  String[] tokens = line.split(" ");
1082 
1083  // Declare the array
1084  Fq_Aq_representor_norms = new double[getQf()][getQa()][numBasisFuncs];
1085 
1086  // Fill it
1087  int count = 0;
1088  for (int q_f = 0; q_f < getQf(); q_f++)
1089  for (int q_a = 0; q_a < getQa(); q_a++)
1090  for (int i = 0; i < numBasisFuncs; i++) {
1091  Fq_Aq_representor_norms[q_f][q_a][i] = Double.parseDouble(tokens[count]);
1092  count++;
1093  }
1094 
1095  Log.d(DEBUG_TAG, "Finished reading Fq_Aq_norms.dat");
1096  }
1097 
1098  MathObjectReader mr = m.getMathObjReader();
1099 
1100  // Read in Aq_Aq representor norm data
1101  {
1102  // Declare the array
1103  int Q_a_hat = getQa() * (getQa() + 1) / 2;
1104  Aq_Aq_representor_norms = new double[Q_a_hat][][];
1105 
1106  int count = 0;
1107  String file;
1108  for (int i = 0; i < getQa(); i++) {
1109  for (int j = i; j < getQa(); j++) {
1110  file = "Aq_Aq_" + String.format("%03d", i) + "_" + String.format("%03d", j) + "_norms.bin";
1111  InputStream in = m.getInStream(file);
1112  try {
1113  Aq_Aq_representor_norms[count] = mr.readRawDoubleMatrix(in, numBasisFuncs, numBasisFuncs);
1114  } finally {
1115  in.close();
1116  }
1117  count++;
1118  }
1119  }
1120  Log.d(DEBUG_TAG, "Finished reading Aq_Aq_norms.dat");
1121  }
1122 
1123  // Read in Z data
1124  {
1125  int mf = getNumDoFFields();
1126  if (mf > 0) {
1127  fullBasisVectors = new float[mf][numBasisFuncs][];
1128  InputStream in;
1129  for (int imf = 0; imf < mf; imf++)
1130  for (int inbfs = 0; inbfs < numBasisFuncs; inbfs++) {
1131  in = m.getInStream("Z_" + String.format("%03d", imf) + "_" + String.format("%03d", inbfs)
1132  + ".bin");
1133  try {
1134  fullBasisVectors[imf][inbfs] = mr.readRawFloatVector(in, getGeometry().getNumVertices());
1135  } finally {
1136  in.close();
1137  }
1138  }
1139  }
1140 
1141  Log.d(DEBUG_TAG, "Finished reading Z.dat");
1142  }
1143 
1144  // Reading uL data
1145  {
1146  if (getQuL() > 0) {
1147  uL_vector = new float[getQuL()][];
1148  InputStream in;
1149  for (int q_uL = 0; q_uL < getQuL(); q_uL++) {
1150  in = m.getInStream("uL_" + String.format("%03d", q_uL) + ".bin");
1151  try {
1152  uL_vector[q_uL] = mr.readRawFloatVector(in, getGeometry().getNumVertices());
1153  } finally {
1154  in.close();
1155  }
1156  }
1157  }
1158  Log.d(DEBUG_TAG, "Finished reading uL.dat");
1159  }
1160 
1161  // See if theres a transformation
1162  try {
1163  // Get a reference to get_n_L_functions, which does not
1164  // take any argument
1165  transformationMethod = oldAffFcnCl.getMethod("get_local_transformation", new Class[] { double[].class });
1166  } catch (NoSuchMethodException nsme) {
1167  transformationMethod = null;
1168  }
1169 
1170  }
1171 
1172  protected void loadOfflineDataJRB(AModelManager m) throws IOException {
1173 
1174  MathObjectReader mr = m.getMathObjReader();
1175  String filename;
1176 
1177  /*
1178  * Get initial value coefficient vectors
1179  */
1180  int Qu0 = 1;
1181  if (affineFunctionsInstance instanceof IAffineInitials) {
1182  Qu0 = ((IAffineInitials) affineFunctionsInstance).getQu0();
1183  }
1184  RB_initial_coeffs = new RealVector[Qu0];
1185  for (int i = 0; i < Qu0; i++) {
1186  filename = "RB_initial_" + String.format("%03d", i) + ".bin";
1187  RB_initial_coeffs[i] = mr.readVector(m.getInStream(filename));
1188  }
1189  Log.d(DEBUG_TAG, "Finished initial value data");
1190 
1191  /*
1192  * Get output dual norms
1193  */
1194  RB_output_vectors = new RealVector[fNumOutputs][];
1195  output_dual_norms = new double[fNumOutputs][];
1196  for (int i = 0; i < fNumOutputs; i++) {
1197  filename = "output_" + String.format("%03d", i) + "_dual_norms.bin";
1198 
1199  output_dual_norms[i] = mr.readRawDoubleVector(m.getInStream(filename));
1200  // int Q_l_hat = getQl(i) * (getQl(i) + 1) / 2;
1201  // output_dual_norms[i] = new double[Q_l_hat];
1202  // for (int q = 0; q < Q_l_hat; q++) {
1203  // output_dual_norms[i][q] =
1204  // Double.parseDouble(dual_norms_tokens[q]);
1205  // }
1206 
1207  RB_output_vectors[i] = new RealVector[Ql_values[i]];
1208  for (int q_l = 0; q_l < Ql_values[i]; q_l++) {
1209  filename = "output_" + String.format("%03d", i) + "_" + String.format("%03d", q_l) + ".bin";
1210 
1211  RB_output_vectors[i][q_l] = mr.readVector(m.getInStream(filename));
1212  }
1213  }
1214  Log.d(DEBUG_TAG, "Finished reading output data");
1215 
1216  /*
1217  * Read in the F_q vectors
1218  */
1219  RB_F_q_vector = new RealVector[fQf];
1220  for (int q_f = 0; q_f < fQf; q_f++) {
1221  filename = "RB_F_" + String.format("%03d", q_f) + ".bin";
1222  RB_F_q_vector[q_f] = mr.readVector(m.getInStream(filename));
1223  }
1224  Log.d(DEBUG_TAG, "Finished reading RB_F_q data");
1225 
1226  /*
1227  * Read in the A_q matrices
1228  */
1229  RB_A_q_vector = new RealMatrix[getQa()];
1230  for (int q_a = 0; q_a < getQa(); q_a++) {
1231  filename = "RB_A_" + String.format("%03d", q_a) + ".bin";
1232  RB_A_q_vector[q_a] = mr.readMatrix(m.getInStream(filename));
1233  }
1234  Log.d(DEBUG_TAG, "Finished reading RB_A_q data");
1235 
1236  /*
1237  * Read in F_q representor norm data Contains the upper triangular
1238  * entries of the pairwise norm matrix
1239  */
1240  Fq_representor_norms = mr.readRawDoubleVector(m.getInStream("Fq_norms.bin"));
1241 
1242  // Read in Fq_Aq representor norm data
1243 
1244  // Declare the array
1245  Fq_Aq_representor_norms = new double[fQf][getQa()][numBasisFuncs];
1246  for (int q_a = 0; q_a < getQa(); q_a++) {
1247  for (int q_f = 0; q_f < fQf; q_f++) {
1248  filename = "Fq_Aq_" + String.format("%03d", q_f) + "_" + String.format("%03d", q_a) + ".bin";
1249  Fq_Aq_representor_norms[q_f][q_a] = mr.readRawDoubleVector(m.getInStream(filename));
1250  }
1251  }
1252  Log.d(DEBUG_TAG, "Finished reading Fq_Aq_norms.dat");
1253 
1254  /*
1255  * Read in Aq_Aq representor norm data
1256  */
1257  int triuQa = getQa() * (getQa() + 1) / 2;
1258  Aq_Aq_representor_norms = new double[triuQa][][];
1259  for (int i = 0; i < getQa(); i++) {
1260  for (int j = 0; j < getQa() - i; j++) {
1261  filename = "Aq_Aq_" + String.format("%03d", i) + "_" + String.format("%03d", j) + "_norms.bin";
1262  Aq_Aq_representor_norms[j + getQa() * i] = mr.readRawDoubleMatrix(m.getInStream(filename));
1263  }
1264  }
1265  Log.d(DEBUG_TAG, "Finished reading Aq_Aq_norms.dat");
1266 
1267  /*
1268  * Reading uL data, if some is present
1269  */
1270  if (fQuL > 0) {
1271  uL_vector = new float[fQuL][];
1272  for (int q_uL = 0; q_uL < fQuL; q_uL++) {
1273  filename = "uL_" + String.format("%03d", q_uL) + ".bin";
1274  uL_vector[q_uL] = mr.readRawFloatVector(m.getInStream(filename));
1275  }
1276  Log.d(DEBUG_TAG, "Finished reading uL.dat");
1277  }
1278 
1279  /*
1280  * Read in Z data
1281  */
1282  if (getNumDoFFields() > 0) {
1283  fullBasisVectors = new float[getNumDoFFields()][numBasisFuncs][];
1284  for (int fieldNr = 0; fieldNr < getNumDoFFields(); fieldNr++)
1285  for (int bfNr = 0; bfNr < numBasisFuncs; bfNr++) {
1286  filename = "Z_" + String.format("%03d", fieldNr) + "_" + String.format("%03d", bfNr) + ".bin";
1287  fullBasisVectors[fieldNr][bfNr] = mr.readRawFloatVector(m.getInStream(filename));
1288  }
1289  Log.d(DEBUG_TAG, "Finished reading Z data");
1290  }
1291  }
1292 
1300  public float[] rbappmitCustomMeshTransform(double[] mu, float[] x) {
1301  Method meth;
1302 
1303  try {
1304  // Get a reference to get_n_L_functions, which does not
1305  // take any arguments
1306 
1307  Class<?> partypes[] = new Class[2];
1308  partypes[0] = double[].class;
1309  partypes[1] = float[].class;
1310 
1311  meth = oldAffFcnCl.getMethod("mesh_transform", partypes);
1312  } catch (NoSuchMethodException nsme) {
1313  throw new RuntimeException("getMethod for mesh_transform failed", nsme);
1314  }
1315 
1316  float[] xt;
1317  try {
1318  Object arglist[] = new Object[2];
1319  arglist[0] = mu;
1320  arglist[1] = x;
1321 
1322  Object theta_obj = meth.invoke(oldAffFcnObj, arglist);
1323  xt = (float[]) theta_obj;
1324  } catch (IllegalAccessException iae) {
1325  throw new RuntimeException(iae);
1326  } catch (InvocationTargetException ite) {
1327  throw new RuntimeException(ite.getCause());
1328  }
1329 
1330  return xt;
1331  }
1332 
1340  public int performSweep(int sweepIndex, int N) {
1341  Log.d("RBSystem", "Starting sweep: sweepIdx:" + sweepIndex + ", N:" + N + ", NumDoFs:" + getNumDoFFields()
1342  + ", vertices:" + getGeometry().getNumVertices());
1343  return performSweep(sweepIndex, N, Math.round(100000 / (getNumDoFFields() * getGeometry().getNumVertices())));
1344  }
1345 
1357  public int performSweep(int sweepIndex, int N, int numSweepPts) {
1358  Parameters p = getParams();
1359  if (!isReal) {
1360  Log.d("RBSystem", "Dividing numSweepPts by three.");
1361  numSweepPts /= 3;
1362  }
1363  if (numSweepPts > MAX_SWEEP_POINTS) {
1364  Log.e("RBSystem", "Too large number of sweep points, allowed: " + MAX_SWEEP_POINTS + ", requested: "
1365  + numSweepPts);
1366  numSweepPts = MAX_SWEEP_POINTS;
1367  }
1368  int n_outputs = getNumOutputs();
1369 
1370  mSweepParam = new double[numSweepPts][];
1371 
1372  RB_sweep_solution = null;
1373  if (isReal) {
1374  RB_sweep_solution = new double[numSweepPts][1][current_N];
1375  } else {
1376  RB_sweep_solution = new double[numSweepPts][2][current_N];
1377  n_outputs *= 2;
1378  }
1379 
1380  sweepOutputs = new double[n_outputs][numSweepPts];
1381  sweepOutputBounds = new double[n_outputs][numSweepPts];
1382 
1383  double sweepParamRange = p.getMaxValue(sweepIndex) - p.getMinValue(sweepIndex);
1384  sweepIncrement = sweepParamRange / (numSweepPts - 1);
1385 
1386  transforms.clear();
1387  for (int sweepNr = 0; sweepNr < numSweepPts; sweepNr++) {
1388  double new_param = p.getMinValue(sweepIndex) + sweepNr * sweepIncrement;
1389  mSweepParam[sweepNr] = p.getCurrent().clone();
1390  Log.d(DEBUG_TAG, "ParamSweep: New param " + Arrays.toString(p.getCurrent()));
1391  p.setCurrent(sweepIndex, new_param);
1392  RB_solve(N);
1393 
1394  if (isReal) {
1395  for (int n = 0; n < n_outputs; n++) {
1396  sweepOutputs[n][sweepNr] = RB_outputs[n];
1397  sweepOutputBounds[n][sweepNr] = RB_output_error_bounds[n];
1398  }
1399  } else {
1400  for (int n = 0; n < n_outputs / 2; n++) {
1401  sweepOutputs[n][sweepNr] = get_RB_output(n, true);
1402  sweepOutputs[n + n_outputs / 2][sweepNr] = get_RB_output(n, false);
1403  sweepOutputBounds[n][sweepNr] = get_RB_output_error_bound(n, true);
1404  sweepOutputBounds[n + n_outputs / 2][sweepNr] = get_RB_output_error_bound(n, false);
1405  }
1406  }
1407 
1408  if (getNumDoFFields() > 0) {
1409  RB_sweep_solution[sweepNr] = get_RBsolution();
1410  if (!hasCustomMeshTransform()) {
1413  getGeometry().vertexLTFuncNr));
1414  } else {
1415  transforms.add(new DefaultTransform());
1416  }
1417  } else {
1418  transforms.add(new rbappmitCustomMeshTransform(mSweepParam[sweepNr], this));
1419  }
1420  }
1421  }
1422  return numSweepPts;
1423  }
1424 
1429  protected double RB_solve(int N) {
1430 
1431  current_N = N;
1432 
1433  if (N > getNBF()) {
1434  throw new RuntimeException("ERROR: N cannot be larger than the number " + "of basis functions in RB_solve");
1435  }
1436  if (N == 0) {
1437  throw new RuntimeException("ERROR: N must be greater than 0 in RB_solve");
1438  }
1439 
1440  // Assemble the RB system
1441  RealMatrix RB_system_matrix_N = new Array2DRowRealMatrix(N, N);
1442 
1443  for (int q_a = 0; q_a < getQa(); q_a++) {
1444  RB_system_matrix_N = RB_system_matrix_N.add(RB_A_q_vector[q_a].getSubMatrix(0, N - 1, 0, N - 1)
1445  .scalarMultiply(thetaQa(q_a)));
1446  }
1447 
1448  // Assemble the RB rhs
1449  RealVector RB_rhs_N = getInitialCoefficients(N);
1450 
1451  for (int q_f = 0; q_f < fQf; q_f++) {
1452  // Note getSubVector takes an initial index and the number of
1453  // entries
1454  // i.e. the interface is a bit different to getSubMatrix
1455  RB_rhs_N = RB_rhs_N.add(RB_F_q_vector[q_f].getSubVector(0, N).mapMultiplyToSelf(thetaQf(q_f)));
1456  }
1457 
1458  // Solve the linear system
1459  DecompositionSolver solver = new LUDecompositionImpl(RB_system_matrix_N).getSolver();
1460  RB_solution = solver.solve(RB_rhs_N);
1461 
1462  // Evaluate the dual norm of the residual for RB_solution_vector
1463  double epsilon_N = compute_residual_dual_norm(N);
1464 
1465  // Get lower bound for coercivity constant
1466  double alpha_LB = get_SCM_lower_bound();
1467 
1468  // If SCM lower bound is negative
1469  if (alpha_LB <= 0) { // Get an upper bound instead
1470  alpha_LB = get_SCM_upper_bound();
1471  }
1472 
1473  // Store (absolute) error bound
1474  double abs_error_bound = epsilon_N / residual_scaling_denom(alpha_LB);
1475 
1476  // Compute the norm of RB_solution
1477  double RB_solution_norm = RB_solution.getNorm();
1478 
1479  // Now compute the outputs and associated errors
1480  RealVector RB_output_vector_N = new ArrayRealVector(N);
1481  for (int i = 0; i < getNumOutputs(); i++) {
1482  RB_outputs[i] = 0.;
1483 
1484  for (int q_l = 0; q_l < getQl(i); q_l++) {
1485  RB_output_vector_N = RB_output_vectors[i][q_l].getSubVector(0, N);
1486  RB_outputs[i] += thetaQl(i, q_l) * RB_solution.dotProduct(RB_output_vector_N);
1487  }
1489  // is
1490  // current
1491  // time,
1492  // not
1493  // in
1494  // RBSystem
1495  * abs_error_bound;
1496  }
1497 
1498  return (return_rel_error_bound ? abs_error_bound / RB_solution_norm : abs_error_bound);
1499  }
1500 
1506  public final boolean readConfiguration(AModelManager m) {
1507  fQa = affineFunctionsInstance.getQa();
1508  Log.d("RBBase", "Q_a = " + fQa);
1509 
1510  if (m.getModelType() == ModelType.rbappmit) {
1511  try {
1513  Log.d("RBBase", "Created GetPot object");
1514  readConfigurationRBAppMIT(infile);
1515  } catch (IOException e) {
1516  Log.e("RBBase", "Error opening input.in", e);
1517  return false;
1518  }
1519  } else {
1521  }
1522  return true;
1523  }
1524 
1526  params = m.getParameters();
1527 
1528  // Number of basis functions
1529  numBasisFuncs = Integer.parseInt(m.getModelXMLAttribute("num_basisfcn", "rb_model"));
1530 
1531  // Number of output functionals
1532  fNumOutputs = affineFunctionsInstance.getNumOutputs();
1533 
1534  Ql_values = affineFunctionsInstance.getQl();
1535  fQf = affineFunctionsInstance.getQf();
1536  if (affineFunctionsInstance instanceof IWithuL) {
1537  fQuL = ((IWithuL) affineFunctionsInstance).getQuL();
1538  }
1539  }
1540 
1541  protected void readConfigurationRBAppMIT(GetPot infile) {
1542 
1543  int n_parameters = infile.call("n_parameters", 1);
1544  Log.d("RBBase", "n_parameters = " + n_parameters);
1545  if (n_parameters > 0) {
1546  params = new Parameters();
1547  for (int i = 0; i < n_parameters; i++) {
1548  String label = infile.call("param" + Integer.toString(i) + "_label", "mu_" + i);
1549  // Read in the min/max for the i^th parameter
1550  String min_string = new String("mu" + i + "_min");
1551  double mu_i_min = infile.call(min_string, 0.);
1552  String max_string = new String("mu" + i + "_max");
1553  double mu_i_max = infile.call(max_string, 0.);
1554  params.addParam(label, mu_i_min, mu_i_max);
1555  Log.d("RBBase", "Parameter " + i + ": Min = " + mu_i_min + ", Max = " + mu_i_max);
1556  }
1557  }
1558 
1559  /*
1560  * Read config values from the input.in file
1561  */
1562  Log.d(DEBUG_TAG, "Entered parse_parameters_file, filename = " + Const.parameters_filename);
1563 
1564  int return_rel_error_bound_in = infile.call("return_rel_error_bound", 1);
1565  return_rel_error_bound = (return_rel_error_bound_in != 0);
1566 
1567  Log.d(DEBUG_TAG, "return a relative error bound from RB_solve? " + return_rel_error_bound);
1568 
1569  /*
1570  * Read values using the new IAffineFunctions wrapper
1571  */
1572  Ql_values = affineFunctionsInstance.getQl();
1573  fQf = affineFunctionsInstance.getQf();
1574  Log.d(DEBUG_TAG, "Q_f = " + fQf);
1575  if (affineFunctionsInstance instanceof IWithuL) {
1576  fQuL = ((IWithuL) affineFunctionsInstance).getQuL();
1577  }
1578 
1579  fNumOutputs = affineFunctionsInstance.getNumOutputs();
1580  Log.d(DEBUG_TAG, "n_outputs = " + fNumOutputs);
1581  }
1582 
1587  protected double residual_scaling_denom(double alpha_LB) {
1588  return Math.sqrt(alpha_LB);
1589  }
1590 
1591  public void set_n_basis_functions(int _N) {
1592  numBasisFuncs = _N;
1593  }
1594 
1600  protected void setParams(Parameters p) {
1601  params = p;
1602  }
1603 
1607  public void setPrimarySCM(RBSCMSystem scm_system) {
1608  mRbScmSystem = scm_system;
1609  }
1610 
1617  public double computeRBSolution(int N) {
1622  transforms.clear();
1623  if (!(this instanceof TransientRBSystem)) {
1624  if (!hasCustomMeshTransform()) {
1626  float[][] tmp = getAffLinTransformationData(getParams().getCurrent());
1627  Log.d("RBSystem", "Storing AffLinTrafo: " + Log.dumpArr(tmp));
1628  transforms.add(new AffineLinearMeshTransform(tmp, getGeometry().vertexLTFuncNr));
1629  } else
1630  transforms.add(new DefaultTransform());
1631  } else {
1632  transforms.add(new rbappmitCustomMeshTransform(getParams().getCurrent(), this));
1633  }
1634  } else {
1635  transforms.add(new DefaultTransform());
1636  }
1637  return RB_solve(N);
1638  }
1639 
1640  // private void sweepUpdateGeometry(float[][][] RB_sweep_LTfuncs, int
1641  // numSweepPts) {
1642  // GeometryData geoData = getGeometry();
1643  // if (!hasCustomMeshTransform()) {
1644  // /*
1645  // * Apply affine-linear transformation according to sweeped parameter
1646  // * values if present
1647  // */
1648  // if (RB_sweep_LTfuncs != null) {
1649  // /*
1650  // * The number of sweeps os encoded in the length of the first
1651  // * dimension of the RB_sweep_LTfuncs array as there is a set for
1652  // * each sweep.
1653  // */
1654  // geoData.applyAffLinVertexTransformation(RB_sweep_LTfuncs);
1655  // /*
1656  // * otherwise just copy the nodes as often as there have been
1657  // * parameter sweeps
1658  // *
1659  // * @todo separate geometry / field value frames for less memory
1660  // * usage!
1661  // */
1662  // } else {
1663  // geoData.vertices = new float[numSweepPts * geoData.getNumVertices() * 3];
1664  // for (int sweep = 0; sweep < numSweepPts; sweep++) {
1665  // System.arraycopy(geoData.originalVertices, 0, geoData.vertices, sweep *
1666  // geoData.getNumVertices()
1667  // * 3, geoData.getNumVertices());
1668  // }
1669  // }
1670  // } else {
1671  // customMeshTransform(mSweepParam, geoData);
1672  // }
1673  // }
1674 
1681  public double thetaQa(int q) {
1682  return thetaQa(q, 0);
1683  }
1684 
1691  public double thetaQa(int q, double t) {
1692  return affineFunctionsInstance.thetaQa(q, params.getCurrent(), t);
1693  }
1694 
1700  public double thetaQf(int i) {
1701  return thetaQf(i, 0);
1702  }
1703 
1710  public double thetaQf(int i, double t) {
1711  return affineFunctionsInstance.thetaQf(i, params.getCurrent(), t);
1712  }
1713 
1720  public double thetaQl(int k, int i) {
1721  return thetaQl(k, i, 0);
1722  }
1723 
1731  public double thetaQl(int k, int i, double t) {
1732  return affineFunctionsInstance.thetaQl(k, i, getParams().getCurrent(), t);
1733  }
1734 }
Interface for models using the mQ_uL fields.
Definition: IWithuL.java:11
double computeRBSolution(int N)
Performs a reduced basis simulation and stores the results locally.
Definition: RBSystem.java:1617
GeometryData getGeometry()
The model&#39;s geometry data.
Definition: ModelBase.java:69
int getNumOutputs()
Definition: RBSystem.java:612
double[] RB_output_error_bounds
The vector storing the RB error bounds in the steady-state case.
Definition: RBSystem.java:178
The displacement field is a logical solution field describing displacements of geometry nodes/vertice...
double compute_output_dual_norm(int i, double t)
Compute the dual norm of the i^th output function at the current parameter value. ...
Definition: RBSystem.java:402
Complex complex_eval_theta_q_f(int q)
Definition: RBSystem.java:317
double[][] output_dual_norms
This array stores the dual norms for each output.
Definition: RBSystem.java:150
float[][][] fullBasisVectors
Definition: RBSystem.java:114
int getNumDoFFields()
Returns the number of degree-of-freedom fields generated/computed by the model.
Definition: ModelBase.java:78
double getSweepIncrement()
Returns the increment used during the last parameter sweep or zero if there hasn&#39;t been any...
Definition: RBSystem.java:746
Utility helper class from rbAppMIT included for compatibility of rbAppMIT model loading.
Definition: GetPot.java:31
int getVisualNumTimesteps()
Definition: RBSystem.java:866
Class< IAffineFunctions > affineFunctionsClass
The Class object for the affine functions class.
Definition: RBSystem.java:69
This class provides the Online stage for the reduced basis method for elliptic steady state problems...
Definition: RBSystem.java:54
double get_RB_output(int n_output, boolean Rpart)
Definition: RBSystem.java:503
The default solution field containing an array of real values.
int current_N
Definition: RBSystem.java:80
An affine linear mesh transformation.
double[][][] Fq_Aq_representor_norms
Definition: RBSystem.java:85
Represents the results of a simulation.
final boolean readConfiguration(AModelManager m)
Definition: RBSystem.java:1506
This class provides the Online reduced basis functionality for linear parabolic problems.
void loadOfflineData(AModelManager m)
Loads the offline data for the RBSystem.
Definition: RBSystem.java:915
An rbappmit-model of old data format, compatible with JRB models.
Definition: ModelType.java:28
double get_RB_output_error_bound(int n_output, boolean Rpart)
Definition: RBSystem.java:507
Reading matrices and vectors with a bunch of convenient overloads for different sources and output fo...
RealVector getInitialCoefficients(int N)
Returns the initial conditions solution coefficients for RB size N.
Definition: RBSystem.java:588
double RB_solve(int N)
Perform online solve with the N RB basis functions, for the set of parameters in current_params, where 1 &lt;= N &lt;= RB_size.
Definition: RBSystem.java:1429
void readConfigurationRBAppMIT(GetPot infile)
Definition: RBSystem.java:1541
double[] getCurrent()
Gets the current parameter.
Definition: Parameters.java:62
Parameters getParams()
Returns the system&#39;s parameters object.
Definition: RBSystem.java:621
double[][][] Aq_Aq_representor_norms
Definition: RBSystem.java:77
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...
void loadOfflineData_rbappmit(AModelManager m)
Definition: RBSystem.java:931
double getMinValue(int i)
final InputStream getInStream(String filename)
Returns an InputStream instance streaming the contents of the file given by filename.
double thetaQl(int k, int i)
Definition: RBSystem.java:1720
IAffineFunctions affineFunctionsInstance
The member object that defines the parameter-dependent functions for the affine expansion of the left...
Definition: RBSystem.java:75
boolean return_rel_error_bound
Boolean flag to indicate whether RB_solve returns an absolute or relative error bound.
Definition: RBSystem.java:209
FieldVector< Complex > complex_eval_theta_q_a()
Definition: RBSystem.java:238
double[] Fq_representor_norms
Arrays storing the residual representor inner products to be used in computing the residuals in the O...
Definition: RBSystem.java:91
double get_SCM_from_AffineFunction()
A private helper function to get the SCM from AffineFunctions in the case that SCM_TYPE = NONE...
Definition: RBSystem.java:518
void set_n_basis_functions(int _N)
Definition: RBSystem.java:1591
double thetaQa(int q)
Evaluate theta_q_a (for the q^th bilinear form) at the current parameter.
Definition: RBSystem.java:1681
Known model types within the JaRMoSBase project.
Definition: ModelType.java:9
double[] RB_outputs
The vector storing the RB output values in the steady-state case.
Definition: RBSystem.java:191
double thetaQf(int i)
Definition: RBSystem.java:1700
This class serves as base class for accessing various types of models at different locations...
A class for model parameters.
Definition: Parameters.java:17
int performSweep(int sweepIndex, int N, int numSweepPts)
Performs a parameter sweep for the current RB system.
Definition: RBSystem.java:1357
boolean hasCustomMeshTransform()
Definition: RBSystem.java:873
int getQf()
TODO: if all affine_functions implement the IAffineFunctions interface, just call the getQf method of...
Definition: RBSystem.java:638
void initialize_data_vectors()
Resize the vectors that store solution data and output data.
Definition: RBSystem.java:902
void setParams(Parameters p)
Only used to set the current parameters object for an SCMSystem, as this also inherits from the RBBas...
Definition: RBSystem.java:1600
SimulationResult getSimulationResults()
Constructs the true solution from the most recent RB reduced solution using the full Z data and curre...
Definition: RBSystem.java:672
double[][] getSweepOutputBounds()
Definition: RBSystem.java:750
Object oldAffFcnObj
Definition: RBSystem.java:144
RealVector RB_solution
The RB solution vector.
Definition: RBSystem.java:201
double[][] get_RBsolution()
Definition: RBSystem.java:511
FieldDescriptor[] logicalFieldTypes
The logical output fields of the model, each collecting one ore more model DoF&#39;s into a related unit...
Definition: ModelBase.java:26
double thetaQa(int q, double t)
Definition: RBSystem.java:1691
ModelType getModelType()
Returns the model type as given in the model.xml attribute &quot;type&quot; of the &quot;model&quot; tag.
void readConfigurationJRB(AModelManager m)
Definition: RBSystem.java:1525
boolean hasAffLinTransformationData()
Definition: RBSystem.java:895
int getTotalTimesteps()
TODO check where this is used.
Definition: RBSystem.java:838
Provides a Log class imitating the Android Log class when not used on android systems.
Definition: Log.java:11
RBSystem()
Constructor.
Definition: RBSystem.java:225
This Exception gets thrown when an error occurs regarding the functionality of the ModelManager...
double[][] RB_output_error_bounds_all_k
The output error bounds at all time levels.
Definition: RBSystem.java:183
float[][] getAffLinTransformationData(double[] mu)
Returns a float array of transformation data for each node, using the specified parameter mu...
Definition: RBSystem.java:852
double compute_residual_dual_norm(int N)
Compute the dual norm of the residual for the solution saved in RB_solution_vector.
Definition: RBSystem.java:423
void setPrimarySCM(RBSCMSystem scm_system)
Set the primary SCM.
Definition: RBSystem.java:1607
float[][] uL_vector
Definition: RBSystem.java:218
RealMatrix[] RB_A_q_vector
Dense matrices for the RB computations.
Definition: RBSystem.java:163
double get_SCM_upper_bound()
Definition: RBSystem.java:563
double[][][] RB_sweep_solution
Definition: RBSystem.java:203
double thetaQf(int i, double t)
Definition: RBSystem.java:1710
double[][] RB_outputs_all_k
The outputs at all time levels.
Definition: RBSystem.java:197
Complex complex_eval_theta_q_a(int q)
Definition: RBSystem.java:277
int getQa()
Definition: RBSystem.java:628
RealVector[][] RB_output_vectors
The vectors storing the RB output vectors.
Definition: RBSystem.java:187
boolean isReal
Definition: RBSystem.java:119
int getQuL()
Definition: RBSystem.java:654
static final String parameters_filename
Inherited from the rbAppMIT models to read the model parameters.
Definition: Const.java:13
double get_soln_coeff(int i)
Definition: RBSystem.java:575
RealVector[] RB_F_q_vector
Dense vector for the RHS.
Definition: RBSystem.java:168
double residual_scaling_denom(double alpha_LB)
Specifies the residual scaling on the denominator to be used in the a posteriori error bound...
Definition: RBSystem.java:1587
int get_N()
Definition: RBSystem.java:499
double[][] getSweepOutputs()
Definition: RBSystem.java:754
Interface for affinely decomposed initial value conditions.
int getNBF()
Definition: RBSystem.java:605
int performSweep(int sweepIndex, int N)
Performs a parameter sweep with automatic guess of the number of parameter sweeps.
Definition: RBSystem.java:1340
double thetaQu0(int i, double[] p)
Evaluates ^{u0}_i for the current parameter p.
RBSCMSystem mRbScmSystem
A reference to the SCM system.
Definition: RBSystem.java:124
Default mesh transformation.
Complex complex_eval_theta_q_l(int n, int q)
Definition: RBSystem.java:357
A common interface for classes providing a mesh transformation.
float[] rbappmitCustomMeshTransform(double[] mu, float[] x)
Custom mesh transformation method of old rbappmit-models.
Definition: RBSystem.java:1300
List< MeshTransform > transforms
Definition: RBSystem.java:220
Contains information about the logical solution fields.
double thetaQl(int k, int i, double t)
Definition: RBSystem.java:1731
Class with constants used throughout JRB.
Definition: Const.java:9
int getQl(int output_index)
TODO: if all affine_functions implement the IAffineFunctions interface, just call the getQl method of...
Definition: RBSystem.java:650
Class<?> oldAffFcnCl
Definition: RBSystem.java:139
Base class for all JaRMoSBase models.
Definition: ModelBase.java:18
SimulationResult getSweepSimResults()
Definition: RBSystem.java:758
double get_SCM_lower_bound()
Definition: RBSystem.java:551
void loadOfflineDataJRB(AModelManager m)
Definition: RBSystem.java:1172