Skip to content
Browse files

Merge pull request #1 from robertdfrench/master

Fixed All the build issues
  • Loading branch information...
2 parents 0e29936 + dd9a1fa commit 5156b3e914160196649e30dcccb8a710610c54dc @calebwherry committed Aug 9, 2011
Showing with 582 additions and 370 deletions.
  1. +6 −3 src/jbamboo/IntervalExample.java
  2. +9 −2 src/jbamboo/JBambooMain.java
  3. +50 −0 src/jbamboo/basetypes/AbstractBoundedInteger.java
  4. +5 −0 src/jbamboo/basetypes/Functor.java
  5. +18 −0 src/jbamboo/basetypes/Index.java
  6. +80 −0 src/jbamboo/basetypes/IntegerRange.java
  7. +5 −26 src/jbamboo/basetypes/JBambooNamespace.java
  8. +8 −93 src/jbamboo/basetypes/Natural.java
  9. +5 −0 src/jbamboo/basetypes/Sequence.java
  10. +3 −3 src/jbamboo/elements/IntervalElement.java
  11. +1 −1 src/jbamboo/innerproducts/SobolevInnerProduct.java
  12. +1 −1 src/jbamboo/mesh/Mesh.java
  13. +2 −1 src/jbamboo/mesh/MeshSynthesizer.java
  14. +14 −0 tests/jbamboo/JBambooTests.java
  15. +16 −0 tests/jbamboo/basetypes/AllBasetypeTests.java
  16. +94 −0 tests/jbamboo/basetypes/IndexTest.java
  17. +96 −0 tests/jbamboo/basetypes/IntegerRangeTest.java
  18. +1 −16 tests/jbamboo/basetypes/{tests → }/JBambooNamespaceTest.java
  19. +94 −0 tests/jbamboo/basetypes/NaturalTest.java
  20. +1 −1 tests/jbamboo/basetypes/{tests → }/PointTest.java
  21. +2 −2 tests/jbamboo/basetypes/{tests → }/SymmetricPairIteratorTest.java
  22. +0 −9 tests/jbamboo/basetypes/tests/AllTests.java
  23. +0 −62 tests/jbamboo/basetypes/tests/NaturalTest.java
  24. +12 −0 tests/jbamboo/elements/AllElementTests.java
  25. +4 −4 tests/jbamboo/elements/{tests → }/FiniteElementTest.java
  26. +2 −2 tests/jbamboo/elements/{tests → }/IntervalElementTest.java
  27. +0 −9 tests/jbamboo/elements/tests/AllTests.java
  28. +2 −2 tests/jbamboo/functions/{tests/AllTests.java → AllFunctionTests.java}
  29. +1 −1 tests/jbamboo/functions/{tests → }/MonomialTest.java
  30. +1 −1 tests/jbamboo/functions/{tests → }/PolynomialTest.java
  31. +1 −1 tests/jbamboo/functions/{tests → }/ProductTest.java
  32. +1 −1 tests/jbamboo/functions/{tests → }/RealFunctionTest.java
  33. +1 −1 tests/jbamboo/functions/{tests → }/SumTest.java
  34. +1 −1 tests/jbamboo/functions/{tests → }/TentFunctionTest.java
  35. +20 −0 tests/jbamboo/mockobjects/MockFiniteElement.java
  36. +3 −10 tests/jbamboo/mockobjects/MockMeshNode.java
  37. +6 −0 tests/jbamboo/mockobjects/MockRealFunction.java
  38. +0 −102 tests/jbamboo/numerical/tests/NumericalStabilityTests.java
  39. +14 −0 tests/jbamboo/predicatefunctions/AllPredicateFunctionTests.java
  40. +1 −1 tests/jbamboo/predicatefunctions/{tests → }/ElementPredicateTest.java
  41. +1 −1 tests/jbamboo/predicatefunctions/{tests → }/PredicateFunctionTest.java
  42. +0 −13 tests/jbamboo/tests/JBambooTests.java
View
9 src/jbamboo/IntervalExample.java
@@ -1,6 +1,7 @@
package jbamboo;
import jbamboo.basetypes.JBambooNamespace;
+import jbamboo.basetypes.Natural;
import jbamboo.exceptions.IntegrationException;
import jbamboo.exceptions.InvalidElementException;
import jbamboo.exceptions.InvalidElementType;
@@ -23,7 +24,8 @@
@Override
public String toString() {
- return "Interval Example";
+ throw new IllegalArgumentException();
+ //return "Interval Example";
}
/**
@@ -40,7 +42,8 @@ public static void doIntervalExample(Integer numElements, RealFunction f, InnerP
timestamps[0] = System.currentTimeMillis();
Integer numNodes = numElements + 1;
- Mesh m = uniformIntervalMesh(0.0,1.0,natural(numElements));
+ Mesh m = uniformIntervalMesh(0.0,1.0,Natural.get(numElements));
+
timestamps[1] = System.currentTimeMillis();
applyDefaultBasisScheme(m);
@@ -77,7 +80,7 @@ public static void doIntervalExample(Integer numElements, RealFunction f, InnerP
System.out.println(stiffnessMatrix);
System.out.println("Solution:");
- for(Integer i : natural(numNodes)) {
+ for(Integer i : Natural.get(numNodes)) {
MeshNode n = m.getNode(i);
Double value = solution.get(i - 1);
System.out.format("%s,%s\n", n.getPoint().x(),value);
View
11 src/jbamboo/JBambooMain.java
@@ -2,14 +2,15 @@
import no.uib.cipr.matrix.sparse.IterativeSolverNotConvergedException;
import jbamboo.basetypes.JBambooNamespace;
+import jbamboo.basetypes.Natural;
import jbamboo.exceptions.BadTentConfigurationException;
import jbamboo.exceptions.IntegrationException;
import jbamboo.exceptions.InvalidElementException;
import jbamboo.exceptions.InvalidElementType;
import jbamboo.functions.Polynomial;
import jbamboo.functions.RealFunction;
-import jbamboo.functions.Zero;
+
import jbamboo.innerproducts.*;
/**
@@ -40,6 +41,12 @@ public static void main(String[] args) throws InvalidElementException, Integrati
numElements = 100;
precision = 10000;
f = new Polynomial(-6.0,4.0);
+ loadIP = new StandardRealInnerProduct(Natural.get(precision));
+ stiffnessIP = new SobolevInnerProduct(Natural.get(precision));
+ IntervalExample.doIntervalExample(numElements,f,loadIP,stiffnessIP);
+
+
+ /**System.out.println("Solving -u'' + u = 0 on [0,1] with bd=0");
loadIP = new StandardRealInnerProduct(natural(precision));
stiffnessIP = new SobolevInnerProduct(natural(precision));
IntervalExample.doIntervalExample(numElements,f,loadIP,stiffnessIP);
@@ -51,7 +58,7 @@ public static void main(String[] args) throws InvalidElementException, Integrati
f = new Zero();
loadIP = new StandardRealInnerProduct(natural(precision));
stiffnessIP = new SuperSobolevInnerProduct(natural(precision));
- IntervalExample.doIntervalExample(numElements,f,loadIP,stiffnessIP);*/
+ IntervalExample.doIntervalExample(numElements,f,loadIP,stiffnessIP);**/
}
View
50 src/jbamboo/basetypes/AbstractBoundedInteger.java
@@ -0,0 +1,50 @@
+package jbamboo.basetypes;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Abstract wrapper class that portrays an IntegerRange as a "Bounded" integer type, that is
+ * something like Natural or Index.
+ * @author robert
+ *
+ */
+abstract class AbstractBoundedInteger implements Iterable<Integer> {
+
+ private IntegerRange ir;
+
+ protected AbstractBoundedInteger(IntegerRange ir) {
+ this.ir = ir;
+ }
+
+ public int toInt() {
+ return ir.upperBound();
+ }
+
+ public double toDouble() {
+ return ir.upperBound();
+ }
+
+ public Iterator<Integer> iterator() {
+ return ir.iterator();
+ }
+
+ public List<Integer> asList() {
+ return ir.asList();
+ }
+
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof AbstractBoundedInteger)) return false;
+ AbstractBoundedInteger bi = (AbstractBoundedInteger) o;
+ return (this.toInt() == bi.toInt());
+ }
+
+ public int hashcode() {
+ return 31 * 17 + this.toInt();
+ }
+
+ public String toString() {
+ return String.format("%d",toInt());
+ }
+}
View
5 src/jbamboo/basetypes/Functor.java
@@ -0,0 +1,5 @@
+package jbamboo.basetypes;
+
+public interface Functor<Domain,Range> {
+ public Range exectue(Domain x);
+}
View
18 src/jbamboo/basetypes/Index.java
@@ -0,0 +1,18 @@
+package jbamboo.basetypes;
+
+import java.util.HashMap;
+
+
+public class Index extends AbstractBoundedInteger {
+
+ private static HashMap<Integer,Index> cache = new HashMap<Integer,Index>();
+
+ private Index(int number) {
+ super(new IntegerRange(0,number));
+ }
+
+ public static Index get(int number) {
+ if (!cache.containsKey(number)) cache.put(number, new Index(number));
+ return cache.get(number);
+ }
+}
View
80 src/jbamboo/basetypes/IntegerRange.java
@@ -0,0 +1,80 @@
+package jbamboo.basetypes;
+
+import java.util.AbstractList;
+import java.util.Iterator;
+import java.util.List;
+
+public class IntegerRange implements Iterable<Integer> {
+
+ private final int lowerBound;
+ private final int upperBound;
+
+ protected IntegerRange(int lowerBound, int upperBound) {
+ if (lowerBound > upperBound) throw new IllegalArgumentException();
+ this.lowerBound = lowerBound;
+ this.upperBound = upperBound;
+ }
+
+ public int lowerBound() {
+ return lowerBound;
+ }
+
+ public int upperBound() {
+ return upperBound;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof IntegerRange)) return false;
+ IntegerRange ir = (IntegerRange) o;
+ return
+ (
+ this.lowerBound == ir.lowerBound &&
+ this.upperBound == ir.upperBound
+ );
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 31 * result + lowerBound;
+ result = 31 * result + upperBound;
+ return result;
+ }
+
+ /**
+ * For printing
+ */
+ public String toString() {
+ return String.format("[%d...%d]", lowerBound, upperBound);
+ }
+
+ /**
+ * Idiom to help iterate {1,2,...,<code>toInt()</code>}
+ */
+ public Iterator<Integer> iterator() {
+ return asList().iterator();
+ }
+
+ /**
+ * Create a fake list of integers from 1 to <code>number</code>
+ * @return
+ */
+ public List<Integer> asList() {
+ return new AbstractList<Integer>() {
+ @Override
+ public Integer get(int index) {
+ if (index < 0 || index > upperBound) throw new IndexOutOfBoundsException();
+ return index + lowerBound;
+ }
+
+ @Override
+ public int size() {
+ return (upperBound - lowerBound) + 1;
+ }
+
+ };
+ }
+
+}
View
31 src/jbamboo/basetypes/JBambooNamespace.java
@@ -14,7 +14,6 @@
import jbamboo.functions.TentFunction2D;
import jbamboo.functions.Zero;
import jbamboo.innerproducts.InnerProduct;
-import jbamboo.integration.IntegrationStrategyMatrix;
import jbamboo.mesh.Mesh;
import jbamboo.mesh.MeshNode;
import jbamboo.mesh.MeshSynthesizer;
@@ -38,30 +37,12 @@
*/
public static Point point(Double... coordinates) {
Point p = new Point();
- Natural n = new Natural(coordinates.length);
+ Index n = Index.get(coordinates.length - 1);
for(Integer i : n) {
- p.setCoordinate(i, coordinates[i - 1]);
+ p.setCoordinate(i + 1, coordinates[i]);
}
return p;
}
-
- /**
- * Idiom for creating a new natural from an arbitrary int
- * @param number
- * @return new Natural representing the absolute value of <b>number</b>
- */
- public static Natural natural(int number) {
- return new Natural(number);
- }
-
- /**
- * Idiom for creating a new Natural from an arbitrary double
- * @param number
- * @return new Natural representing the absolute value of <b>(int) number</b>
- */
- public static Natural natural(double number) {
- return new Natural(number);
- }
/**
* Gets the 2nd derivative
@@ -80,7 +61,7 @@ public static Mesh uniformIntervalMesh(Double lowerBound, Double upperBound, Nat
int numNodes = numIntervals.toInt() + 1;
Double totalIntervalLength = upperBound - lowerBound;
Double subIntervalLength = totalIntervalLength / numIntervals.toDouble();
- for(Integer i : natural(numNodes)) {
+ for(Integer i : Natural.get(numNodes)) {
Point p = point(lowerBound + (i - 1)*subIntervalLength);
ms.createNode(p, i);
}
@@ -141,6 +122,7 @@ public static DenseVector computeLoadVector(Mesh m, InnerProduct loadIP, RealFun
}
/**
+
* Computes the stiffness matrix
* @param m
* @param stiffnessIP
@@ -158,7 +140,7 @@ public static DenseMatrix computeStiffnessMatrix(Mesh m, InnerProduct stiffnessI
Set<FiniteElement> commonElements = mi.getCommonElements(mj);
Double innerProduct = 0.0;
try {
- innerProduct = stiffnessIP.computeNumerically(phi_i,phi_j,commonElements);
+ innerProduct = stiffnessIP.computeGeometrically(phi_i,phi_j,commonElements);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -191,7 +173,4 @@ public static DenseMatrix computeStiffnessMatrix(Mesh m, InnerProduct stiffnessI
return stiffnessMatrix;
}
- public static Double integrate(RealFunction f, FiniteElement e) {
- IntegrationStrategyMatrix.get().get(functionType, elementType)
- }
}
View
101 src/jbamboo/basetypes/Natural.java
@@ -1,6 +1,6 @@
package jbamboo.basetypes;
-import java.util.Iterator;
+import java.util.HashMap;
/**
* Class that forces ints to act like Natural numbers.
@@ -9,102 +9,17 @@
* @author robert
*
*/
-public class Natural implements Iterable<Integer> {
+public class Natural extends AbstractBoundedInteger {
- private int number;
+ private static HashMap<Integer,Natural> cache = new HashMap<Integer,Natural>();
- /**
- * Note, passing 0 as an argument will force Natural to
- * take on the internal value 1. (0 is not a standard
- * issue Natural number)
- * @param number
- */
- public Natural(int number) {
- this.number = Math.abs(number);
- this.number = (this.number == 0) ? 1 : this.number;
+ private Natural(int number) {
+ super(new IntegerRange(1,number));
}
- /**
- * basically a shortcut for <code>new Natural((int) number)</code>.
- * @param number
- */
- public Natural(double number) {
- this((int) number);
- }
-
- /**
- * Since Java doesn't do operator overloading...
- * @return the int value
- */
- public int toInt() {
- return number;
- }
-
- /**
- * Returns it as a double to help ease division woes
- * @return
- */
- public Double toDouble() {
- return (double) number;
- }
-
- /**
- * For printing
- */
- public String toString() {
- return String.format("%d", number);
- }
-
- /**
- * Idiom to help iterate {1,2,...,<code>toInt()</code>}
- */
- public Iterator<Integer> iterator() {
- return new NaturalIterator(this);
- }
-
- /**
- * Idiom to help iterate {1,2,...,<code>toInt()</code>}
- * @author robertdfrench
- *
- */
- public class NaturalIterator implements Iterator<Integer> {
-
- private int max;
- private int current;
-
- /**
- * Ye olde constructor. Constructs an iterator that runs from 1 to <b>n</b>.
- * @param n
- */
- public NaturalIterator(Natural n) {
- this.max = n.toInt();
- this.current = 0;
- }
-
- /**
- * Ye olde hasNext(), tells us whether we have numbers remaining
- */
- public boolean hasNext() {
- // TODO Auto-generated method stub
- return (current < max);
- }
-
- /**
- * returns the next number in the sequence
- */
- public Integer next() {
- // TODO Auto-generated method stub
- current++;
- return current;
- }
+ public static Natural get(int number) {
+ if (!cache.containsKey(number)) cache.put(number, new Natural(number));
+ return cache.get(number);
- /**
- * Not implemented
- */
- public void remove() {
- // TODO Auto-generated method stub
-
- }
-
}
}
View
5 src/jbamboo/basetypes/Sequence.java
@@ -0,0 +1,5 @@
+package jbamboo.basetypes;
+
+public interface Sequence<Range> extends Functor<Natural, Range> {
+
+}
View
6 src/jbamboo/elements/IntervalElement.java
@@ -31,13 +31,13 @@ protected IntervalElement() {
*/
public IntervalElement(Point p, Point q) throws InvalidIntervalException {
if (p.getCoordinate(1) >= q.getCoordinate(1)) throw new InvalidIntervalException();
- initializePoints(new Natural(2));
+ initializePoints(Natural.get(2));
lowerBound = p;
- setPoint(new Natural(1),p);
+ setPoint(Natural.get(1),p);
upperBound = q;
- setPoint(new Natural(2),q);
+ setPoint(Natural.get(2),q);
}
@Override
View
2 src/jbamboo/innerproducts/SobolevInnerProduct.java
@@ -61,4 +61,4 @@ public String toString() {
return null;
}
-}
+}
View
2 src/jbamboo/mesh/Mesh.java
@@ -73,7 +73,7 @@ public String toString() {
* @return
*/
public Natural getNumNodes() {
- return natural(nodes.size());
+ return Natural.get(nodes.size());
}
/**
View
3 src/jbamboo/mesh/MeshSynthesizer.java
@@ -1,6 +1,7 @@
package jbamboo.mesh;
import jbamboo.basetypes.JBambooNamespace;
+import jbamboo.basetypes.Natural;
import jbamboo.basetypes.Point;
import jbamboo.elements.ElementFactory;
import jbamboo.elements.FiniteElement;
@@ -49,7 +50,7 @@ public void createNode(Point p, Integer nodeId) {
public void createElement(String elementType, Integer ... nodeIds) throws InvalidElementType, InvalidElementException {
MeshNode[] requestedNodes = new MeshNode[nodeIds.length];
Point[] associatedPoints = new Point[nodeIds.length];
- for (Integer i : natural(nodeIds.length)) {
+ for (Integer i : Natural.get(nodeIds.length)) {
requestedNodes[i - 1] = mesh.getNode(nodeIds[i - 1]);
associatedPoints[i - 1] = requestedNodes[i - 1].getPoint();
}
View
14 tests/jbamboo/JBambooTests.java
@@ -0,0 +1,14 @@
+package jbamboo;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+ jbamboo.functions.AllFunctionTests.class,
+ jbamboo.basetypes.AllBasetypeTests.class,
+ jbamboo.elements.AllElementTests.class,
+ jbamboo.predicatefunctions.AllPredicateFunctionTests.class
+})
+public class JBambooTests {
+}
View
16 tests/jbamboo/basetypes/AllBasetypeTests.java
@@ -0,0 +1,16 @@
+package jbamboo.basetypes;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+ JBambooNamespaceTest.class,
+ NaturalTest.class,
+ PointTest.class,
+ IndexTest.class,
+ SymmetricPairIteratorTest.class,
+ IntegerRangeTest.class
+ })
+public class AllBasetypeTests {
+}
View
94 tests/jbamboo/basetypes/IndexTest.java
@@ -0,0 +1,94 @@
+package jbamboo.basetypes;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import jbamboo.basetypes.Index;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class IndexTest {
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+
+ @Test
+ public final void testAsList() {
+ int size = 10;
+ Index n = Index.get(size);
+ List<Integer> l = n.asList();
+ for (int i = 0; i <= size; i++) {
+ assertTrue(String.format("%d == %d", l.get(i),i),l.get(i) == i);
+ }
+
+ boolean sizeIsOOB = false;
+ try {
+ l.get(size + 1);
+ } catch (IndexOutOfBoundsException e) {
+ sizeIsOOB = true;
+ }
+ assertTrue(sizeIsOOB);
+ }
+
+ @Test
+ public final void testEquals() {
+ assertEquals(Index.get(5),Index.get(5));
+ }
+
+ @Test
+ public final void testGet() {
+ assertTrue(Index.get(0) == Index.get(0));
+
+ boolean negativeOneIsOOB = false;
+ try {
+ Index.get(-1);
+ } catch (IllegalArgumentException e) {
+ negativeOneIsOOB = true;
+ }
+ assertTrue(negativeOneIsOOB);
+ }
+
+ @Test
+ public final void testIterator() {
+ Index n = Index.get(9);
+ Integer[] ints = new Integer[10];
+ for(Integer i : n) {
+ ints[i] = i;
+ }
+ for (int i = 0; i < 10; i++) {
+ assertEquals(ints[i],new Integer(i));
+ }
+ }
+
+ @Test
+ public final void testToDouble() {
+ Index n = Index.get(5);
+ assertTrue(n.toDouble() == (double) 5);
+ }
+
+ @Test
+ public final void testToInt() {
+ Index n = Index.get(5);
+ assertTrue(n.toInt() == 5);
+ }
+
+}
View
96 tests/jbamboo/basetypes/IntegerRangeTest.java
@@ -0,0 +1,96 @@
+package jbamboo.basetypes;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import jbamboo.basetypes.IntegerRange;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class IntegerRangeTest {
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testHashCode() {
+ IntegerRange ir = new IntegerRange(1,12);
+ assertEquals(ir.hashCode(), 16380);
+ }
+
+ @Test
+ public final void testIntegerRange() {
+ boolean badArgsThrowException = false;
+ try {
+ new IntegerRange(12,1);
+ } catch (IllegalArgumentException e) {
+ badArgsThrowException = true;
+ }
+ assertTrue(badArgsThrowException);
+ }
+
+ @Test
+ public final void testLowerBound() {
+ IntegerRange ir = new IntegerRange(1,12);
+ assertEquals(ir.lowerBound(),1);
+ }
+
+ @Test
+ public final void testUpperBound() {
+ IntegerRange ir = new IntegerRange(1,12);
+ assertEquals(ir.upperBound(),12);
+ }
+
+ @Test
+ public final void testEqualsObject() {
+ IntegerRange ir1 = new IntegerRange(1,12);
+ IntegerRange ir2 = new IntegerRange(1,12);
+ assertEquals(ir1,ir2);
+ }
+
+ @Test
+ public final void testToString() {
+ IntegerRange ir = new IntegerRange(1,12);
+ assertEquals(ir.toString(), "[1...12]");
+ }
+
+ @Test
+ public final void testIterator() {
+ IntegerRange ir = new IntegerRange(0,11);
+ Integer j = 0;
+ for (Integer i : ir) {
+ assertEquals(i,j);
+ j++;
+ }
+ assertTrue(j == 12);
+ }
+
+ @Test
+ public final void testAsList() {
+ IntegerRange ir = new IntegerRange(0,11);
+ List<Integer> ints = ir.asList();
+ for (int i = 0; i < 12; i++) {
+ assertEquals(ints.get(i),new Integer(i));
+ }
+
+ }
+
+}
View
17 ...basetypes/tests/JBambooNamespaceTest.java → ...amboo/basetypes/JBambooNamespaceTest.java
@@ -1,8 +1,7 @@
-package jbamboo.basetypes.tests;
+package jbamboo.basetypes;
import static org.junit.Assert.*;
import jbamboo.basetypes.JBambooNamespace;
-import jbamboo.basetypes.Natural;
import jbamboo.basetypes.Point;
import org.junit.After;
@@ -39,18 +38,4 @@ public final void testPoint() {
assertTrue(p.getCoordinate(5) == 34.56);
}
- @Test
- public final void testNaturalInt() {
- Natural n = JBambooNamespace.natural(5);
- Natural m = JBambooNamespace.natural(-5);
- assertTrue(n.toInt() == m.toInt());
- }
-
- @Test
- public final void testNaturalDouble() {
- Natural n = JBambooNamespace.natural(5);
- Natural m = JBambooNamespace.natural(-5.7);
- assertTrue(n.toInt() == m.toInt());
- }
-
}
View
94 tests/jbamboo/basetypes/NaturalTest.java
@@ -0,0 +1,94 @@
+package jbamboo.basetypes;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import jbamboo.basetypes.Natural;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class NaturalTest {
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testAsList() {
+ int size = 10;
+ Natural n = Natural.get(size);
+ List<Integer> l = n.asList();
+ for (int i = 0; i < size; i++) {
+ assertTrue(String.format("%d == %d", l.get(i),i + 1),l.get(i) == i + 1);
+ }
+
+ boolean sizeIsOOB = false;
+ try {
+ l.get(size + 1);
+ } catch (IndexOutOfBoundsException e) {
+ sizeIsOOB = true;
+ }
+ assertTrue(sizeIsOOB);
+ }
+
+ @Test
+ public final void testEquals() {
+ Natural i = Natural.get(5);
+ Natural j = Natural.get(5);
+ assertEquals(i,j);
+ }
+
+ @Test
+ public final void testGet() {
+ assertTrue(Natural.get(1) == Natural.get(1));
+
+ boolean zeroIsOOB = false;
+ try {
+ Natural.get(0);
+ } catch (IllegalArgumentException e) {
+ zeroIsOOB = true;
+ }
+ assertTrue(zeroIsOOB);
+ }
+
+ @Test
+ public final void testIterator() {
+ Natural n = Natural.get(10);
+ Integer[] ints = new Integer[10];
+ for(Integer i : n) {
+ ints[i - 1] = i;
+ }
+ for (int i = 1; i <= 10; i++) {
+ assertEquals(ints[i - 1],new Integer(i));
+ }
+ }
+
+ @Test
+ public final void testToDouble() {
+ Natural n = Natural.get(5);
+ assertTrue(n.toDouble() == (double) 5);
+ }
+
+ @Test
+ public final void testToInt() {
+ Natural n = Natural.get(5);
+ assertTrue(n.toInt() == 5);
+ }
+}
View
2 tests/jbamboo/basetypes/tests/PointTest.java → tests/jbamboo/basetypes/PointTest.java
@@ -1,4 +1,4 @@
-package jbamboo.basetypes.tests;
+package jbamboo.basetypes;
import static org.junit.Assert.*;
import jbamboo.basetypes.Point;
View
4 ...ypes/tests/SymmetricPairIteratorTest.java → .../basetypes/SymmetricPairIteratorTest.java
@@ -1,4 +1,4 @@
-package jbamboo.basetypes.tests;
+package jbamboo.basetypes;
import static org.junit.Assert.*;
@@ -51,7 +51,7 @@ public final void testWholeFuckinThing() {
for(Pair<Integer> p : spi) {
sb.append(p);
}
- String controlString = "Pair (1,1)Pair (1,2)Pair (1,3)Pair (2,2)Pair (2,3)Pair (3,3)";
+ String controlString = "Pair {1,1}Pair {1,2}Pair {1,3}Pair {2,2}Pair {2,3}Pair {3,3}";
assertEquals(sb.toString(),controlString);
}
View
9 tests/jbamboo/basetypes/tests/AllTests.java
@@ -1,9 +0,0 @@
-package jbamboo.basetypes.tests;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses( { JBambooNamespaceTest.class, NaturalTest.class, PointTest.class })
-public class AllTests {
-}
View
62 tests/jbamboo/basetypes/tests/NaturalTest.java
@@ -1,62 +0,0 @@
-package jbamboo.basetypes.tests;
-
-import static org.junit.Assert.*;
-import jbamboo.basetypes.Natural;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class NaturalTest {
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public final void testNatural() {
- assertTrue((new Natural(5)).toInt() == 5);
- assertTrue((new Natural(0)).toInt() == 1);
- assertTrue((new Natural(-1)).toInt() == 1);
- assertTrue((new Natural(-5.7)).toInt() == 5);
- }
-
- @Test
- public final void testToInt() {
- Natural n = new Natural(-5);
- assertTrue(n.toInt() == 5);
- }
-
- @Test
- public final void testToDouble() {
- Natural n = new Natural(-5.7);
- assertTrue(n.toDouble() == 5.0);
- }
-
- @Test
- public final void testIterator() {
- Natural n = new Natural(10);
- Integer[] ints = new Integer[10];
- for(Integer i : n) {
- ints[i - 1] = i;
- }
- for (int i = 1; i <= 10; i++) {
- assertTrue(ints[i - 1] == i);
- }
- }
-
-}
View
12 tests/jbamboo/elements/AllElementTests.java
@@ -0,0 +1,12 @@
+package jbamboo.elements;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+ FiniteElementTest.class,
+ IntervalElementTest.class
+})
+public class AllElementTests {
+}
View
8 ...boo/elements/tests/FiniteElementTest.java → ...s/jbamboo/elements/FiniteElementTest.java
@@ -1,4 +1,4 @@
-package jbamboo.elements.tests;
+package jbamboo.elements;
import static org.junit.Assert.*;
import jbamboo.basetypes.Natural;
@@ -38,16 +38,16 @@ public final void testGetPoints() {
@Test
public final void testInitializePoints() {
MockFiniteElement e = new MockFiniteElement();
- e.initializePoints(new Natural(5));
+ e.initializePoints(Natural.get(5));
assertTrue(e.getPoints().length == 5);
}
@Test
public final void testSetPoint() {
MockFiniteElement e = new MockFiniteElement();
- e.initializePoints(new Natural(5));
+ e.initializePoints(Natural.get(5));
Point p = new Point(1.0,2.0);
- e.setPoint(new Natural(4), p);
+ e.setPoint(Natural.get(4), p);
}
}
View
4 ...o/elements/tests/IntervalElementTest.java → ...jbamboo/elements/IntervalElementTest.java
@@ -1,4 +1,4 @@
-package jbamboo.elements.tests;
+package jbamboo.elements;
import static org.junit.Assert.*;
import jbamboo.basetypes.Natural;
@@ -49,7 +49,7 @@ public final void testToString() throws InvalidIntervalException {
@Test
public final void testIntegrate() throws InvalidIntervalException {
IntervalElement e = new IntervalElement(a,b);
- Double integral = e.integrate(new MockRealFunction(), new Natural(100));
+ Double integral = e.integrate(new MockRealFunction(), Natural.get(100));
assertTrue (
String.format("Got\t %f\nExp\t %f", integral, 2.0),
Math.abs(integral - 2.0) < 0.00001
View
9 tests/jbamboo/elements/tests/AllTests.java
@@ -1,9 +0,0 @@
-package jbamboo.elements.tests;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses( { FiniteElementTest.class, IntervalElementTest.class})
-public class AllTests {
-}
View
4 tests/jbamboo/functions/tests/AllTests.java → ...s/jbamboo/functions/AllFunctionTests.java
@@ -1,4 +1,4 @@
-package jbamboo.functions.tests;
+package jbamboo.functions;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -12,5 +12,5 @@
SumTest.class,
TentFunctionTest.class
})
-public class AllTests {
+public class AllFunctionTests {
}
View
2 ...jbamboo/functions/tests/MonomialTest.java → tests/jbamboo/functions/MonomialTest.java
@@ -1,4 +1,4 @@
-package jbamboo.functions.tests;
+package jbamboo.functions;
import static org.junit.Assert.*;
import jbamboo.basetypes.Point;
View
2 ...amboo/functions/tests/PolynomialTest.java → tests/jbamboo/functions/PolynomialTest.java
@@ -1,4 +1,4 @@
-package jbamboo.functions.tests;
+package jbamboo.functions;
import static org.junit.Assert.*;
View
2 .../jbamboo/functions/tests/ProductTest.java → tests/jbamboo/functions/ProductTest.java
@@ -1,4 +1,4 @@
-package jbamboo.functions.tests;
+package jbamboo.functions;
import static org.junit.Assert.*;
import jbamboo.basetypes.Point;
View
2 ...boo/functions/tests/RealFunctionTest.java → ...s/jbamboo/functions/RealFunctionTest.java
@@ -1,4 +1,4 @@
-package jbamboo.functions.tests;
+package jbamboo.functions;
import static org.junit.Assert.*;
import jbamboo.basetypes.Point;
View
2 tests/jbamboo/functions/tests/SumTest.java → tests/jbamboo/functions/SumTest.java
@@ -1,4 +1,4 @@
-package jbamboo.functions.tests;
+package jbamboo.functions;
import static org.junit.Assert.*;
import jbamboo.basetypes.Point;
View
2 ...boo/functions/tests/TentFunctionTest.java → ...s/jbamboo/functions/TentFunctionTest.java
@@ -1,4 +1,4 @@
-package jbamboo.functions.tests;
+package jbamboo.functions;
import static org.junit.Assert.*;
import jbamboo.basetypes.Point;
View
20 tests/jbamboo/mockobjects/MockFiniteElement.java
@@ -3,6 +3,7 @@
import jbamboo.basetypes.Natural;
import jbamboo.basetypes.Point;
import jbamboo.elements.FiniteElement;
+import jbamboo.exceptions.InvalidElementException;
import jbamboo.functions.RealFunction;
public class MockFiniteElement extends FiniteElement {
@@ -44,4 +45,23 @@ public void initializePoints(Natural numPoints) {
public void setPoint(Natural i, Point p) {
super.setPoint(i, p);
}
+
+ @Override
+ public boolean equals(Object o) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public Double[] apply(RealFunction f, Natural numPoints) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected FiniteElement semiconstructor(Point... points)
+ throws InvalidElementException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
View
13 tests/jbamboo/mockobjects/MockMeshNode.java
@@ -1,26 +1,19 @@
package jbamboo.mockobjects;
import jbamboo.basetypes.Point;
-import jbamboo.elements.FiniteElement;
-import jbamboo.elements.IntervalElement;
import jbamboo.exceptions.InvalidIntervalException;
import jbamboo.mesh.MeshNode;
public class MockMeshNode extends MeshNode {
- public MockMeshNode(Point p, FiniteElement[] elements, Integer meshNodeId) {
- super(p, elements, meshNodeId);
+ public MockMeshNode(Point p, Integer meshNodeId) {
+ super(p, meshNodeId);
// TODO Auto-generated constructor stub
}
public static MeshNode make() throws InvalidIntervalException {
- Point L = new Point(-1.0);
Point C = new Point(0.0);
- Point R = new Point(1.0);
- IntervalElement LC = new IntervalElement(L,C);
- IntervalElement CR = new IntervalElement(C,R);
- FiniteElement[] elements = {LC, CR};
- return new MockMeshNode(C, elements, 1);
+ return new MockMeshNode(C, 1);
// TODO Auto-generated constructor stub
}
View
6 tests/jbamboo/mockobjects/MockRealFunction.java
@@ -15,5 +15,11 @@ public String toString() {
// TODO Auto-generated method stub
return "mock(p)";
}
+
+ @Override
+ public RealFunction getDerivative() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
View
102 tests/jbamboo/numerical/tests/NumericalStabilityTests.java
@@ -1,102 +0,0 @@
-package jbamboo.numerical.tests;
-
-
-import java.util.Set;
-
-import jbamboo.basetypes.JBambooNamespace;
-import jbamboo.basetypes.Point;
-import jbamboo.elements.FiniteElement;
-import jbamboo.elements.IntervalElement;
-import jbamboo.exceptions.BadTentConfigurationException;
-import jbamboo.exceptions.IntegrationException;
-import jbamboo.exceptions.InvalidElementException;
-import jbamboo.exceptions.InvalidElementType;
-import jbamboo.functions.Polynomial;
-import jbamboo.functions.RealFunction;
-import jbamboo.functions.TentFunction2D;
-import jbamboo.functions.Zero;
-import jbamboo.innerproducts.InnerProduct;
-import jbamboo.innerproducts.SobolevInnerProduct;
-import jbamboo.innerproducts.StandardRealInnerProduct;
-import jbamboo.mesh.Mesh;
-import jbamboo.mesh.MeshNode;
-import jbamboo.mesh.MeshSynthesizer;
-import no.uib.cipr.matrix.DenseMatrix;
-import no.uib.cipr.matrix.DenseVector;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class NumericalStabilityTests {
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testStiffnessMatrix() throws InvalidElementException, IntegrationException, InvalidElementType {
- Integer numNodes = 51;
- Integer numElements = numNodes - 1;
- Double height = 1.0;
- Integer precision = 100;
- RealFunction f = new Polynomial(-6.0,4.0);
-
- MeshSynthesizer ms = new MeshSynthesizer();
- Double h = 1.0 / (double) numElements;
- for(Integer i : JBambooNamespace.natural(numNodes)) {
- Point p = JBambooNamespace.point((i - 1)*h);
- ms.createNode(p, i);
- }
- for(Integer i : JBambooNamespace.natural(numElements)) {
- ms.createElement(IntervalElement.class.getName(),i,i + 1);
- }
- Mesh m = ms.getMesh();
- DenseMatrix stiffnessMatrix = new DenseMatrix(numNodes,numNodes);
- DenseVector loadVector = new DenseVector(numNodes);
- InnerProduct loadIP = new StandardRealInnerProduct(JBambooNamespace.natural(precision));
- InnerProduct stiffnessIP = new SobolevInnerProduct(JBambooNamespace.natural(precision));
- for (MeshNode n : m) {
- RealFunction phi_n;
- try {
- phi_n = TentFunction2D.forNode(n, height);
- } catch (BadTentConfigurationException e) {
- phi_n = new Zero();
- }
- n.attachBasisFunction(phi_n);
- Double innerProduct = loadIP.compute(f, phi_n, n.getCommonElements(n));
- loadVector.set(n.getNodeId() - 1, innerProduct);
- }
- System.out.println("Load Vector:");
- System.out.println(loadVector);
-
-
- for (Integer i : JBambooNamespace.natural(numNodes)) {
- for (Integer j : JBambooNamespace.natural(numNodes)) {
- MeshNode mi = m.getNode(i);
- MeshNode mj = m.getNode(j);
- RealFunction phi_i = mi.getBasisFunction();
- RealFunction phi_j = mj.getBasisFunction();
- Set<FiniteElement> commonElements = mi.getCommonElements(mj);
- Double innerProduct = stiffnessIP.compute(phi_i,phi_j,commonElements);
- stiffnessMatrix.set(i - 1,j - 1,innerProduct);
- }
- }
-
-
- }
-}
View
14 tests/jbamboo/predicatefunctions/AllPredicateFunctionTests.java
@@ -0,0 +1,14 @@
+package jbamboo.predicatefunctions;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+ ElementPredicateTest.class,
+ PredicateFunctionTest.class
+})
+
+public class AllPredicateFunctionTests {
+
+}
View
2 ...functions/tests/ElementPredicateTest.java → ...dicatefunctions/ElementPredicateTest.java
@@ -1,4 +1,4 @@
-package jbamboo.predicatefunctions.tests;
+package jbamboo.predicatefunctions;
import static org.junit.Assert.*;
import jbamboo.basetypes.Point;
View
2 ...unctions/tests/PredicateFunctionTest.java → ...icatefunctions/PredicateFunctionTest.java
@@ -1,4 +1,4 @@
-package jbamboo.predicatefunctions.tests;
+package jbamboo.predicatefunctions;
import static org.junit.Assert.*;
View
13 tests/jbamboo/tests/JBambooTests.java
@@ -1,13 +0,0 @@
-package jbamboo.tests;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses( {
- jbamboo.functions.tests.AllTests.class,
- jbamboo.basetypes.tests.AllTests.class,
- jbamboo.elements.tests.AllTests.class
-})
-public class JBambooTests {
-}

0 comments on commit 5156b3e

Please sign in to comment.
Something went wrong with that request. Please try again.