1 package jarmos.app.activity.rb;
14 import java.nio.FloatBuffer;
15 import java.nio.ShortBuffer;
16 import java.text.DecimalFormat;
17 import java.util.Arrays;
24 import android.app.Activity;
25 import android.app.AlertDialog;
26 import android.app.Dialog;
27 import android.app.ProgressDialog;
28 import android.content.DialogInterface;
29 import android.content.DialogInterface.OnCancelListener;
30 import android.content.Intent;
31 import android.os.Bundle;
32 import android.os.Handler;
33 import android.os.Message;
34 import android.util.Log;
35 import android.view.View;
36 import android.widget.Button;
37 import android.widget.LinearLayout;
38 import android.widget.SeekBar;
39 import android.widget.TableLayout;
40 import android.widget.TextView;
73 private ProgressDialog pd;
115 private String dexFileName =
"AffineFunctions.dex";
134 private Bundle bundle = null;
139 super.onCreate(savedInstanceState);
140 setContentView(
R.layout.rb_main);
144 mng = jarmos.app.Const.getModelManager(getApplicationContext(), getIntent());
146 Log.e(
"RBActivity",
"Creation of ModelManager failed", e);
157 floatBuf = VisualizationData.createFloatBuffer();
158 shortBuf = VisualizationData.createShortBuffer();
161 Button solveButton = (Button) findViewById(
R.id.solveButton);
162 solveButton.setOnClickListener(
new View.OnClickListener() {
163 public void onClick(View view) {
164 pd = ProgressDialog.show(RBActivity.this,
"",
"Solving...");
165 new SolveThread().start();
171 SeekBar onlineNSeekBar = (SeekBar) findViewById(
R.id.onlineNSeekbar);
172 onlineNSeekBar.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
173 public void onProgressChanged(SeekBar seekBar,
int progress,
boolean fromUser) {
175 TextView currentOnlineNView = (TextView) findViewById(
R.id.currentOnlineN);
179 public void onStartTrackingTouch(SeekBar seekBar) {
182 public void onStopTrackingTouch(SeekBar seekBar) {
198 public void handleMessage(Message msg) {
199 pd.setMessage(msg.getData().getString(
"file") +
"...");
204 Log.d(
"DEBUG_TAG",
"Loading model " + m.getModelDir());
205 String op =
"Loading";
211 String title = op +
" " + m.getModelDir() +
"...";
213 pd = ProgressDialog.show(RBActivity.this, title,
"",
true,
true,
new OnCancelListener() {
215 public void onCancel(DialogInterface dialog) {
230 getParent().onBackPressed();
248 AlertDialog.Builder builder;
255 String title =
"Failed loading the model.";
256 Log.d(
DEBUG_TAG,
"Error loading model, modeldir: " + mng.getModelDir());
257 builder =
new AlertDialog.Builder(
this);
258 builder.setMessage(title).setCancelable(
false)
259 .setNeutralButton(
"OK",
new DialogInterface.OnClickListener() {
260 public void onClick(DialogInterface dialog,
int id) {
261 RBActivity.this.finish();
264 dialog = builder.create();
270 dialog =
new Dialog(
this);
271 dialog.setContentView(R.layout.rb_result_dialog);
272 dialog.setTitle(
"RB Solve Results");
273 dialog.setCancelable(
false);
275 Button okButton = (Button) dialog.findViewById(
R.id.okButton);
276 okButton.setOnClickListener(
new View.OnClickListener() {
278 public void onClick(View view) {
285 Button visButton = (Button) dialog.findViewById(
R.id.steadyVisButton);
286 visButton.setOnClickListener(
new View.OnClickListener() {
288 public void onClick(View view) {
292 intent.putExtras(bundle);
293 RBActivity.this.startActivity(intent);
299 String rb_solve_message =
"Online N = " +
mOnlineNForGui +
"\n\u00B5 = [ "
300 + Arrays.toString(s.getParams().getCurrent()) +
"]\n\n";
302 DecimalFormat twoPlaces =
new DecimalFormat(
"0.###E0");
306 for (
int i = 0; i < s.getNumOutputs(); i++) {
308 double output_i = s.RB_outputs[i];
309 double output_bound_i = s.RB_output_error_bounds[i];
311 rb_solve_message +=
"Output " + (i + 1) +
":\n" +
"Value = " + twoPlaces.format(output_i) +
"\n"
312 +
"Error bound = " + twoPlaces.format(output_bound_i) +
"\n\n";
315 for (
int i = 0; i < s.getNumOutputs(); i++) {
317 double output_i_r = s.get_RB_output(i,
true);
318 double output_bound_i_r = s.get_RB_output_error_bound(i,
true);
319 double output_i_i = s.get_RB_output(i,
false);
320 double output_bound_i_i = s.get_RB_output_error_bound(i,
false);
322 rb_solve_message +=
"Output " + (i + 1) +
":\n" +
"Value = " + twoPlaces.format(output_i_r) +
" + "
323 + twoPlaces.format(output_i_i) +
"i\n" +
"Error bound = "
324 + twoPlaces.format(output_bound_i_r) +
" + " + twoPlaces.format(output_bound_i_i) +
"i\n\n";
328 TextView outputView = (TextView) dialog.findViewById(
R.id.rb_solve_output);
329 outputView.setText(rb_solve_message);
342 deleteFile(dexFileName);
381 private void initializeOnlineNBar() {
383 SeekBar onlineNSeekBar = (SeekBar) findViewById(
R.id.onlineNSeekbar);
384 onlineNSeekBar.setMax(rb.mRbSystem.getNBF() - 1);
390 onlineNSeekBar.setProgress(1);
391 onlineNSeekBar.setProgress(0);
563 public void handleMessage(Message msg) {
565 boolean downloadSuccessful = msg.getData().getBoolean(
"loadsuccess");
566 Log.d(
DEBUG_TAG,
"Model loading successful = " + downloadSuccessful +
", model dir: " + mng.getModelDir());
568 if (!downloadSuccessful) {
575 RBActivity.this.initializeOnlineNBar();
579 pb.createBars((TableLayout) findViewById(
R.id.paramLayout));
590 pb.createSweepButton((LinearLayout) findViewById(
R.id.sweepButtonHolder));
594 TextView problemTitleView = (TextView) findViewById(
R.id.problemTitle);
595 problemTitleView.setText(rb.problemTitle);
603 private class ModelLoader
extends Thread {
609 private Handler mHandler;
621 ModelLoader(Handler h) {
630 boolean success =
true;
633 success &= rb.loadModel(m);
637 ((CachingModelManager) m).deleteCachedFiles();
640 Message msg = mHandler.obtainMessage();
641 Bundle b =
new Bundle();
642 b.putBoolean(
"loadsuccess", success);
644 mHandler.sendMessage(msg);
648 private class SolveThread
extends Thread {
650 RBSystem s = rb.mRbSystem;
651 Parameters p = s.getParams();
654 bundle =
new Bundle();
659 case LINEAR_COMPLEX_STEADY:
661 if (pb.getSweepIndex() == -1) {
664 bundle.putBoolean(
"isSweep",
false);
666 handler.sendEmptyMessage(0);
673 bundle.putBoolean(
"isSweep",
true);
675 bundle.putInt(
"sweepIndex", pb.getSweepIndex());
677 bundle.putDouble(
"dt", s.getSweepIncrement());
678 bundle.putDouble(
"xMin", p.getMinValue(pb.getSweepIndex()));
679 bundle.putDouble(
"xMax", p.getMaxValue(pb.getSweepIndex()));
680 bundle.putString(
"xLabel", Integer.toString(pb.getSweepIndex() + 1));
681 bundle.putInt(
"n_time_steps", pts);
682 bundle.putInt(
"n_outputs", s.getNumOutputs());
683 for (
int i = 0; i < s.getNumOutputs(); i++) {
684 bundle.putDoubleArray(
"output_data_" + i, s.getSweepOutputs()[i]);
685 bundle.putDoubleArray(
"output_bound_" + i, s.getSweepOutputBounds()[i]);
688 Intent intent =
new Intent(RBActivity.this, OutputPlotterActivity.class);
689 intent.putExtras(bundle);
690 RBActivity.this.startActivity(intent);
694 case LINEAR_UNSTEADY:
700 bundle.putBoolean(
"isReal", s.isReal);
704 bundle.putBoolean(
"isSweep",
false);
705 bundle.putString(
"title",
706 "Online N = " +
mOnlineNForGui +
", parameter = " + Arrays.toString(p.getCurrent()));
707 bundle.putDouble(
"dt", ((TransientRBSystem) s).getdt());
708 bundle.putDouble(
"xMin", 0);
709 bundle.putDouble(
"xMax", ((TransientRBSystem) s).getdt() * s.getTotalTimesteps());
710 bundle.putString(
"xLabel",
"time");
711 bundle.putInt(
"n_time_steps", ((TransientRBSystem) s).n_plotting_steps);
712 bundle.putInt(
"n_outputs", s.getNumOutputs());
714 for (
int i = 0; i < s.getNumOutputs(); i++) {
715 bundle.putDoubleArray(
"output_data_" + i, s.RB_outputs_all_k[i]);
716 bundle.putDoubleArray(
"output_bound_" + i, s.RB_output_error_bounds_all_k[i]);
720 Intent intent =
new Intent(RBActivity.this, OutputPlotterActivity.class);
721 intent.putExtras(bundle);
722 RBActivity.this.startActivity(intent);
726 throw new RuntimeException(
"Invalid/unknown RB system type for solve: " +
rb.
getSystemType());
730 handler.sendEmptyMessage(-1);
733 private final Handler handler =
new Handler() {
734 public void handleMessage(Message msg) {
static final int RB_SOLVE_DIALOG_ID
SystemType getSystemType()
void delete_downloaded_files()
Linear, complex valued time-independent/steady state rb system.
static int mOnlineNForGui
Array of TextViews and SeekBars for constructing the parameter selection.
int getNumDoFFields()
Returns the number of degree-of-freedom fields generated/computed by the model.
A helper class for a collection of UI elements regarding model parameter display. ...
This class provides the Online stage for the reduced basis method for elliptic steady state problems...
RBSystem mRbSystem
The RBSystem object.
static final int DOWNLOAD_DIALOG_ID
String jarFileName
The current parameter constructed by the GUI.
Dialog onCreateDialog(int id)
This function takes care of constructing the dialogs that pop up.
This class provides the Online reduced basis functionality for linear parabolic problems.
This is the main Activity class for the app.
Main RB visualization activity.
static final int SWEEP_DIALOG_ID
static RBContainer rb
The RB Container with all the system and model data (from JRB)
Parameters getParams()
Returns the system's parameters object.
Base class for RB models and systems.
void onCreate(Bundle savedInstanceState)
Called when the activity is first created.
static final String DEBUG_TAG
static final int DOWNLOAD_FAILED_DIALOG_ID
This class serves as base class for accessing various types of models at different locations...
A class for model parameters.
static ColorGenerator cg
The color generator used to color the field values.
static final int PARAM_DIALOG_ID
void onDestroy()
Called when the activity is destroyed.
LINEAR_STEADY
Linear, time-invariant/steady state rb system.
A container class for all model visual data.
static ShortBuffer shortBuf
A model manager reading models from a remote web location.
static final int PROGRESS_DIALOG_ID
This Exception gets thrown when an error occurs regarding the functionality of the ModelManager...
static final String parameters_filename
Inherited from the rbAppMIT models to read the model parameters.
static FloatBuffer floatBuf
The color generator is used to produce RGBA (RGB+Alpha) values from a given array of floats...
static final int SELECT_PROBLEM_TYPE
final Handler downloadHandler
Initialize the list view depending on the number of parameters in the system and on the parameter ran...
A wrapper class that takes any AModelManager as source and a FileModelManager as target.
Class with constants used throughout JRB.
static final int LOAD_DEMO_DIALOG_ID
A progress notification handler implementation for android platforms.
Enum for known RB system types in JRB.