JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
DisplacementField.java
Go to the documentation of this file.
1 package jarmos.geometry;
2 
7 
16 public class DisplacementField extends LogicSolutionField {
17 
18  private float[][] displ;
19  private float min, max;
20 
21  public DisplacementField(FieldDescriptor f, int size) {
22  super(f);
23  if (f.Mapping != FieldMapping.VERTEX) {
24  throw new RuntimeException("Invalid field mapping type " + f.Mapping + " for displacement fields!");
25  }
26  displ = new float[3][size];
27  min = Float.MAX_VALUE;
28  max = Float.MIN_VALUE;
29  }
30 
31  public DisplacementField(FieldDescriptor f, float[][] xyz) {
32  this(f, xyz[0].length);
33  if (xyz.length == 2) {
34  xyz[3] = new float[xyz[0].length];
35  }
36  this.displ = xyz;
37  }
38 
39  public void setDisplacement(int index, float x, float y, float z) {
40  displ[0][index] = x;
41  if (min > x)
42  min = x;
43  if (max < x)
44  max = x;
45  displ[1][index] = y;
46  if (min > y)
47  min = y;
48  if (max < y)
49  max = y;
50  displ[2][index] = z;
51  if (min > z)
52  min = z;
53  if (max < z)
54  max = z;
55  }
56 
57  public float getMin() {
58  return min;
59  }
60 
61  public float getMax() {
62  return max;
63  }
64 
65  public void setDisplacement(int index, float x, float y) {
66  setDisplacement(index, x, y, 0);
67  }
68 
69  public float[] getXDisplacements() {
70  return displ[0];
71  }
72 
73  public float[] getYDisplacements() {
74  return displ[1];
75  }
76 
77  public float[] getZDisplacements() {
78  return displ[2];
79  }
80 
81  @Override
82  public int getSize() {
83  return (displ != null) ? displ[0].length : 0;
84  }
85 
86  @Override
87  public boolean isConstant() {
88  return Math.abs(min - max) < 1e-8;
89  }
90 
91  @Override
93  boolean twodim = true;
94  for (int i = 0; i < displ[2].length; i++) {
95  twodim &= displ[2][i] == 0;
96  }
97  if (twodim) {
98  return new VisualFeature[] {
99  new VisualFeature(descriptor.Name + "x displ", cg.computeColors(displ[0]), this),
100  new VisualFeature(descriptor.Name + "y displ", cg.computeColors(displ[1]), this) };
101  } else {
102  return new VisualFeature[] {
103  new VisualFeature(descriptor.Name + "x displ", cg.computeColors(displ[0]), this),
104  new VisualFeature(descriptor.Name + "y displ", cg.computeColors(displ[1]), this),
105  new VisualFeature(descriptor.Name + "z displ", cg.computeColors(displ[2]), this) };
106  }
107 
108  }
109 }
The displacement field is a logical solution field describing displacements of geometry nodes/vertice...
Represents a logical solution field of a simulation.
VisualFeature[] getVisualFeatures(ColorGenerator cg)
Abstract method that returns all available visual features for a logical solution field...
FieldMapping Mapping
Unused so far, as mixed field mappings are not yet implemented.
VERTEX
The field variables are to be mapped to geometry vertices, e.g.
void setDisplacement(int index, float x, float y)
Simple class for feature that can be visualized.
DisplacementField(FieldDescriptor f, float[][] xyz)
float[] computeColors(float[] fieldValues)
Computes a 4-tuple color array with values R, G, B, Alpha for the given field values.
boolean isConstant()
Convenience method to determine if the solution field is constant in value.
The field mapping determines how the DoF of the solution are mapped into the given geometry...
DisplacementField(FieldDescriptor f, int size)
void setDisplacement(int index, float x, float y, float z)
The color generator is used to produce RGBA (RGB+Alpha) values from a given array of floats...
int getSize()
Returns the number of graphical elements (nodes/vertices or elements/faces) that this field contains ...
Contains information about the logical solution fields.