Commits

Matthew Turk committed 30a27e2

Fixing Face field tests and adding Edge field tests.

  • Participants
  • Parent commits f86b137

Comments (0)

Files changed (4)

 LDFLAGS=-L$(GTEST_DIR)/lib 
 TEST_SRC=tests/TestFieldDescriptors.C \
 		 tests/TestGrid.C \
-		 tests/TestFieldCenterings.C
+		 tests/TestFieldCenterings.C \
+		 tests/TestFaceCenteredFields.C \
+		 tests/TestEdgeCenteredFields.C
 TEST_OBJ=$(TEST_SRC:.C=.o)
 SRC=field_objects/FieldDescriptor.C \
 	field_objects/Grid.C

File field_objects/FieldDescriptor.C

 
 int FieldDescriptor::GetSize() {
   int dim, Dimensions[MAX_DIMENSIONS], size = 1;
+  assert(this->Rank == 3);
   this->GetFieldDimensions(Dimensions);
   for (dim = 0; dim < this->Rank; dim++) {
     size *= Dimensions[dim];
     int LeftEdgeThis[MAX_DIMENSIONS], // These are out values
     int LeftEdgeOther[MAX_DIMENSIONS],
     int CopyDims[MAX_DIMENSIONS]) {
+      // Only CelL overlap
       int OtherDims[MAX_DIMENSIONS];
       long long OverlapStart, OverlapEnd;
       long long GlobalLeftEdgeThis[MAX_DIMENSIONS];
       int dim;
       this->GetLeftEdge(GlobalLeftEdgeThis);
       Other->GetLeftEdge(GlobalLeftEdgeOther);
-      Other->GetFieldDimensions(OtherDims);
+      Other->GetCellDimensions(OtherDims);
       for (dim = 0; dim < this->Rank; dim++) {
         OverlapStart = MAX(GlobalLeftEdgeThis[dim], GlobalLeftEdgeOther[dim]);
         OverlapEnd = MIN(GlobalLeftEdgeThis[dim] + this->CellDimensions[dim],
   this->GetFieldExtension(Extension);
 
   for (i = 0, i1 = LeftEdge[0]; i < CopyDims[0] + Extension[0]; i++, i1++) {
-    for (j = 0, j1 = LeftEdge[1]; j < CopyDims[1] + Extension[0]; j++, j1++) {
-      for (k = 0, k1 = LeftEdge[2]; k < CopyDims[2] + Extension[0]; k++, k1++) {
+    for (j = 0, j1 = LeftEdge[1]; j < CopyDims[1] + Extension[1]; j++, j1++) {
+      for (k = 0, k1 = LeftEdge[2]; k < CopyDims[2] + Extension[2]; k++, k1++) {
         ind1 = this->Index(i1, j1, k1);
         v1[ind1] = function(v1[ind1], OtherValue);
       }

File tests/TestEdgeCenteredFields.C

+//
+// Field Descriptor Tests for Edge centering
+//
+// Authors: Matthew Turk
+//          Greg Bryan
+
+#include "gtest/gtest.h"
+#include "FieldObjects.h"
+
+namespace {
+  class EdgeCenteredFieldsTest : public ::testing::Test {
+    protected:
+      virtual void SetUp() {
+        dims[0] = 7;
+        dims[1] = 8;
+        dims[2] = 9;
+        long long le[MAX_DIMENSIONS] = {0, 0, 0};
+        int fdi = 0;
+        sdims[0] = 3;
+        sdims[1] = 4;
+        sdims[2] = 5;
+        long long sle[MAX_DIMENSIONS] = {1, 1, 1};
+
+        this->fds[fdi++] = new FieldDescriptor(
+            EdgeCenteredX, 3,
+            dims, le, FirstOrderA,
+            "Density", "g/cc", NULL);
+        this->fds[fdi++] = new FieldDescriptor(
+            EdgeCenteredY, 3,
+            dims, le, FirstOrderA,
+            "Density", "g/cc", NULL);
+        this->fds[fdi++] = new FieldDescriptor(
+            EdgeCenteredZ, 3,
+            dims, le, FirstOrderA,
+            "Density", "g/cc", NULL);
+
+        this->fds[fdi++] = new FieldDescriptor(
+            EdgeCenteredX, 3,
+            sdims, sle, FirstOrderA,
+            "Density", "g/cc", NULL);
+        this->fds[fdi++] = new FieldDescriptor(
+            EdgeCenteredY, 3,
+            sdims, sle, FirstOrderA,
+            "Density", "g/cc", NULL);
+        this->fds[fdi++] = new FieldDescriptor(
+            EdgeCenteredZ, 3,
+            sdims, sle, FirstOrderA,
+            "Density", "g/cc", NULL);
+
+      }
+
+      virtual void TearDown() {
+        int i;
+        for (i = 0; i < 6; i++) {
+          delete this->fds[i];
+        }
+      }
+
+      FieldDescriptor *fds[6];
+      int dims[MAX_DIMENSIONS];
+      int sdims[MAX_DIMENSIONS];
+  };
+
+}
+
+TEST_F(EdgeCenteredFieldsTest, TestOperateCorrectly) {
+  int i, j, dims[MAX_DIMENSIONS], sdims[MAX_DIMENSIONS],
+      total, etotal, stotal;
+  FieldDescriptor *fd1, *fd2;
+  for (i = 0; i < 3; i++) {
+    fd1 = this->fds[i];
+    fd1->GetCellDimensions(dims);
+    fd1->CopyFrom(1.0);
+    EXPECT_EQ(fd1->sum(), fd1->GetSize());
+
+    fd2 = this->fds[i + 3];
+    fd2->GetCellDimensions(sdims);
+    fd2->CopyFrom(1.0);
+    EXPECT_EQ(fd2->sum(), fd2->GetSize());
+
+    fd1->Add(fd2);
+    
+    total = fd1->sum();
+    etotal = stotal = 1;
+
+    for (j = 0; j < 3; j++) {
+      if (i != j) {
+        etotal *= dims[j] + 1;
+        stotal *= sdims[j] + 1;
+      } else {
+        etotal *= dims[j];
+        stotal *= sdims[j];
+      }
+    }
+    EXPECT_EQ(etotal, fd1->GetSize());
+    EXPECT_EQ(stotal, fd2->GetSize());
+
+    EXPECT_EQ(total, etotal+stotal);
+
+    fd1->CopyFrom(1.0);
+    fd1->Add(fd1);
+
+    dims[(i +1)%3] += 1;
+    dims[(i +2)%3] += 1;
+    total = dims[0] * dims[1] * dims[2];
+    EXPECT_EQ(total * 2, fd1->sum());
+  }
+}
+

File tests/TestFaceCenteredFields.C

 
 //
-// Field Descriptor Tests
+// Field Descriptor Tests for Face centering
 //
 // Authors: Matthew Turk
 //          Greg Bryan
         dims[1] = 8;
         dims[2] = 9;
         long long le[MAX_DIMENSIONS] = {0, 0, 0};
-        int fdi = 0;
         sdims[0] = 3;
         sdims[1] = 4;
         sdims[2] = 5;
         long long sle[MAX_DIMENSIONS] = {1, 1, 1};
 
+        int fdi = 0;
         this->fds[fdi++] = new FieldDescriptor(
             FaceCenteredX, 3,
             dims, le, FirstOrderA,
       virtual void TearDown() {
         int i;
         for (i = 0; i < 6; i++) {
-          delete this->fds[i];
+          //delete this->fds[i];
         }
       }
 
 
 }
 
-TEST_F(FieldCenteringSimpleTest, TestOperateCorrectly) {
-  int i, j, dims, sdims, total, etotal, stotal;
+TEST_F(FaceCenteredFieldsTest, TestOperateCorrectly) {
+  int i, j, dims[MAX_DIMENSIONS], sdims[MAX_DIMENSIONS],
+      total, etotal, stotal;
   FieldDescriptor *fd1, *fd2;
   for (i = 0; i < 3; i++) {
     fd1 = this->fds[i];
     fd1->GetCellDimensions(dims);
     fd1->CopyFrom(1.0);
+    EXPECT_EQ(fd1->sum(), fd1->GetSize());
 
-    fd2 = this->fds[i];
-    fd2->GetCellDimensions(dims);
+    fd2 = this->fds[i + 3];
+    fd2->GetCellDimensions(sdims);
     fd2->CopyFrom(1.0);
+    EXPECT_EQ(fd2->sum(), fd2->GetSize());
 
     fd1->Add(fd2);
     
 
     for (j = 0; j < 3; j++) {
       if (i == j) {
+        // We get an extra zone in every direction
         etotal *= dims[j] + 1;
         stotal *= sdims[j] + 1;
       } else {
         stotal *= sdims[j];
       }
     }
+    EXPECT_EQ(etotal, fd1->GetSize());
+    EXPECT_EQ(stotal, fd2->GetSize());
 
-    ASSERT_EQ(total, etotal+stotal);
+    EXPECT_EQ(total, etotal+stotal);
 
     fd1->CopyFrom(1.0);
     fd1->Add(fd1);
 
     dims[i] += 1;
     total = dims[0] * dims[1] * dims[2];
-    ASSERT_EQ(total * 2, fd1->Sum());
+    EXPECT_EQ(total * 2, fd1->sum());
   }
 }