JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
Main.java
Go to the documentation of this file.
1 package jarmos.pc;
2 
12 
13 import java.awt.Frame;
14 import java.awt.event.MouseEvent;
15 import java.awt.event.MouseListener;
16 import java.awt.event.MouseMotionListener;
17 import java.awt.event.MouseWheelEvent;
18 import java.awt.event.MouseWheelListener;
19 import java.io.File;
20 import java.net.MalformedURLException;
21 
22 import javax.media.opengl.awt.GLCanvas;
23 import javax.swing.JFileChooser;
24 
25 import rb.RBContainer;
26 import rb.RBSystem;
27 
28 import com.jogamp.opengl.util.Animator;
29 
35 public class Main {
36 
37  private float x = 0, y = 0;
38 
43  public static void main(String[] args) throws ModelManagerException {
44 
45  // Create a file chooser
46  JFileChooser fc = new JFileChooser();
47  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
48 
49  AModelManager f = null;
50  if (args != null && args.length == 1) {
51  File dir = new File(args[0]);
52  if (dir.exists() && dir.isDirectory()) {
53  f = new FileModelManager(dir.getParent());
54  f.useModel(dir.getName());
55  } else {
56  throw new RuntimeException("Directory not found or invalid: " + args[0]);
57  }
58  } else if (fc.showDialog(null, "Select model directory") == JFileChooser.APPROVE_OPTION) {
59  File file = fc.getSelectedFile();
60  if (file.exists() && file.isDirectory()) {
61  f = new FileModelManager(file.getParent());
62  f.useModel(file.getName());
63  }
64  } else {
65  try {
66  f = new WebModelManager("http://www.agh.ians.uni-stuttgart.de/jarmosa");
67  f.useModel("rbm_advec");
68  } catch (MalformedURLException e) {
69  e.printStackTrace();
70  return;
71  }
72  }
73 
74  RBContainer rb = new RBContainer();
75  rb.loadModel(f);
76 
77  // Perform the solve
78  RBSystem s = rb.mRbSystem;
79  double[] par = s.getParams().getRandomParam();
80  s.getParams().setCurrent(par);
81  s.computeRBSolution(s.getNBF());
82  SimulationResult res = s.getSimulationResults();
83 
84  // s.performSweep(0, 4);
85  // SimulationResult res = s.getSweepSimResults();
86 
87  GeometryData g = rb.mRbSystem.getGeometry();
89 
90  v.useResult(res);
91  v.computeVisualFeatures(new ColorGenerator());
92 
93  Main m = new Main();
94  m.visualize(v);
95  }
96 
97  public void visualize(VisualizationData vData) {
98  final Frame frame = new java.awt.Frame("Model visualization");
99  frame.setSize(400, 600);
100  frame.setLayout(new java.awt.BorderLayout());
101 
102  final Animator animator = new Animator();
103  frame.addWindowListener(new java.awt.event.WindowAdapter() {
104  public void windowClosing(java.awt.event.WindowEvent e) {
105  // Run this on another thread than the AWT event queue to
106  // make sure the call to Animator.stop() completes before
107  // exiting
108  new Thread(new Runnable() {
109  public void run() {
110  animator.stop();
111  System.exit(0);
112  }
113  }).start();
114  }
115  });
116 
117  GLCanvas canvas = new GLCanvas();
118  animator.add(canvas);
119  // GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
120  // GLCanvas canvas = new GLCanvas(caps);
121 
122  final JOGLRenderer rend = new JOGLRenderer(vData, 700, 400);
123  canvas.addGLEventListener(rend);
124 
125  canvas.addMouseListener(new MouseListener() {
126 
127  @Override
128  public void mouseClicked(MouseEvent e) {
129  switch (e.getButton()) {
130  case MouseEvent.BUTTON1:
131  rend.nextColorField();
132  break;
133  case MouseEvent.BUTTON3:
134  rend.isFrontFace = !rend.isFrontFace;
135  break;
136  }
137  }
138 
139  @Override
140  public void mouseEntered(MouseEvent e) {
141  }
142 
143  @Override
144  public void mouseExited(MouseEvent e) {
145  }
146 
147  @Override
148  public void mousePressed(MouseEvent e) {
149  x = e.getX();
150  y = e.getY();
151  }
152 
153  @Override
154  public void mouseReleased(MouseEvent e) {
155  // TODO Auto-generated method stub
156  // isDown = false;
157  }
158  });
159 
160  canvas.addMouseWheelListener(new MouseWheelListener() {
161 
162  @Override
163  public void mouseWheelMoved(MouseWheelEvent e) {
164  if (e.getWheelRotation() > 0)
165  rend.zoomIn();
166  else
167  rend.zoomOut();
168  }
169  });
170 
171  canvas.addMouseMotionListener(new MouseMotionListener() {
172 
173  @Override
174  public void mouseDragged(MouseEvent e) {
175  float smooth = 40;
176  rend.addPos((e.getX() - x) / smooth, (y - e.getY()) / smooth);
177  rend.isContinuousRotation = true;
178  x = e.getX();
179  y = e.getY();
180  }
181 
182  @Override
183  public void mouseMoved(MouseEvent e) {
184  }
185  });
186 
187  frame.add(canvas, java.awt.BorderLayout.CENTER);
188  frame.validate();
189 
190  frame.setVisible(true);
191  animator.start();
192  }
193 
194 }
void visualize(VisualizationData vData)
Definition: Main.java:97
This class provides the Online stage for the reduced basis method for elliptic steady state problems...
Definition: RBSystem.java:54
static void main(String[] args)
Definition: Main.java:43
Represents the results of a simulation.
Manages models loaded from the file system available via the java.io classes.
Base class for RB models and systems.
This class serves as base class for accessing various types of models at different locations...
Main program for desktop-based reduced model simulation using Java.
Definition: Main.java:35
A container class for all model visual data.
Provides the OpenGL rendering routines for the JOGL package.
A model manager reading models from a remote web location.
This Exception gets thrown when an error occurs regarding the functionality of the ModelManager...
This is a container class for all geometry-related data of a reduced model.
float y
Definition: Main.java:37
The color generator is used to produce RGBA (RGB+Alpha) values from a given array of floats...