[cig-commits] r1375 - in branches/s-wang: for_deal.II/examples/step-32 for_deal.II/source/lac source/simulator

s-wang at dealii.org s-wang at dealii.org
Fri Nov 16 18:59:54 PST 2012


Author: s-wang
Date: 2012-11-16 19:59:53 -0700 (Fri, 16 Nov 2012)
New Revision: 1375

Modified:
   branches/s-wang/for_deal.II/examples/step-32/test-step-32.cc
   branches/s-wang/for_deal.II/source/lac/trilinos_sparse_matrix.cc
   branches/s-wang/source/simulator/assembly.cc
   branches/s-wang/source/simulator/core.cc
   branches/s-wang/source/simulator/initial_conditions.cc
Log:
modified the output format of SparseMatrix::write_ascii() in trilinos_sparse_matrix.cc so that the matrix output format is the same as those in petsc.


Modified: branches/s-wang/for_deal.II/examples/step-32/test-step-32.cc
===================================================================
--- branches/s-wang/for_deal.II/examples/step-32/test-step-32.cc	2012-11-16 23:20:33 UTC (rev 1374)
+++ branches/s-wang/for_deal.II/examples/step-32/test-step-32.cc	2012-11-17 02:59:53 UTC (rev 1375)
@@ -157,6 +157,7 @@
 	vector.reinit(block_sizes,MPI_COMM_WORLD);
 	vector.block(0).reinit(MPI_COMM_WORLD,partitioning[0],relevant_partitioning[0]);
 	vector.block(1).reinit(MPI_COMM_WORLD,partitioning[1],relevant_partitioning[1]);
+	vector.collect_sizes();
 }
 
 template <class VectorType>

Modified: branches/s-wang/for_deal.II/source/lac/trilinos_sparse_matrix.cc
===================================================================
--- branches/s-wang/for_deal.II/source/lac/trilinos_sparse_matrix.cc	2012-11-16 23:20:33 UTC (rev 1374)
+++ branches/s-wang/for_deal.II/source/lac/trilinos_sparse_matrix.cc	2012-11-17 02:59:53 UTC (rev 1375)
@@ -1337,7 +1337,53 @@
       }
   }
 
+/**
+ * 	remove the zeros before 'e' in the scientific notation of a floating point value.
+ */
+  static void simplify_scientific_string(int len, const char inStr[20], char outStr[20])
+  {
+	  int i, j;
+	  for(i=0; i<len; i++)
+		  outStr[i] = inStr[i];
 
+	  // looking for "e" or "E" from the end
+	  for(i=len-1; i>=0; i--)
+		  if(outStr[i]=='e' || outStr[i]=='E')
+		  {
+			  i--;
+			  break;
+		  }
+
+	  // replace every leading 0 with \0
+	  for(; i>=0; i--)
+	  {
+		  if(outStr[i]=='0')
+			  outStr[i]='\0';
+		  else
+			  break;
+	  }
+
+	  // now output
+	  bool bPassedE = false;
+	  j = 0;
+	  for(i=0; i<len; i++)
+	  {
+		  if(outStr[i]=='e' || outStr[i]=='E')
+			  bPassedE = true;
+		  if(bPassedE)
+		  {
+			  outStr[j] = outStr[i];
+			  j++;
+		  }
+		  else if(outStr[i]!='\0')
+		  {
+			  outStr[j] = outStr[i];
+			  j++;
+		  }
+	  }
+	  outStr[j] = '\0';
+  }
+
   /**
    * shuqiangwang: output to be the same as petsc style.
    */
@@ -1349,12 +1395,22 @@
 	  int * indices;
 	  int num_entries;
 
+	  const int len = 20;
+	  char inStr[len], outStr[len];
+
 	  for (int i=0; i<matrix->NumMyRows(); ++i)
 	  {
 		  std::cout << "row " << matrix->GRID(i) << ":";
 		  matrix->ExtractMyRowView (i, num_entries, values, indices);
 		  for (int j=0; j<num_entries; ++j)
-			  std::cout << " (" << matrix->GCID(indices[j]) << ", " << values[j] << ") ";
+		  {
+			  std::cout << " (" << matrix->GCID(indices[j]);
+			  snprintf(inStr, len, "%.5e", values[j]);
+			  simplify_scientific_string(len,inStr,outStr);
+//			  std::cout << ", " << std::scientific << values[j];
+			  std::cout << ", " << outStr;
+			  std::cout << ") ";
+		  }
 		  std::cout << std::endl;
 	  }
   }

Modified: branches/s-wang/source/simulator/assembly.cc
===================================================================
--- branches/s-wang/source/simulator/assembly.cc	2012-11-16 23:20:33 UTC (rev 1374)
+++ branches/s-wang/source/simulator/assembly.cc	2012-11-17 02:59:53 UTC (rev 1375)
@@ -1549,7 +1549,7 @@
               }
           }
       }
-    data.local_matrix.print(std::cout);
+//    data.local_matrix.print(std::cout);
   }
 
   template <int dim>

Modified: branches/s-wang/source/simulator/core.cc
===================================================================
--- branches/s-wang/source/simulator/core.cc	2012-11-16 23:20:33 UTC (rev 1374)
+++ branches/s-wang/source/simulator/core.cc	2012-11-17 02:59:53 UTC (rev 1375)
@@ -117,6 +117,7 @@
 	vector.reinit(block_sizes,mpi_communicator);
 	for(unsigned int i=0; i<block_sizes.size(); i++)
 		vector.block(i).reinit(mpi_communicator,partitioning[i],relevant_partitioning[i]);
+	vector.collect_sizes();
 }
 }
 

Modified: branches/s-wang/source/simulator/initial_conditions.cc
===================================================================
--- branches/s-wang/source/simulator/initial_conditions.cc	2012-11-16 23:20:33 UTC (rev 1374)
+++ branches/s-wang/source/simulator/initial_conditions.cc	2012-11-17 02:59:53 UTC (rev 1375)
@@ -197,15 +197,15 @@
                                   system_tmp);
 
         system_tmp.compress();
-        system_tmp.print(std::cout,7,false,false);
+//        system_tmp.print(std::cout,7,false,false);
         // we may have hanging nodes, so apply constraints
         constraints.distribute (system_tmp);
-        constraints.print(std::cout);
+//        constraints.print(std::cout);
 //        exit(0);
 
         system_tmp.compress();
-        system_tmp.print(std::cout,7,false,false);
-        exit(0);
+//        system_tmp.print(std::cout,7,false,false);
+//        exit(0);
 
         old_solution.block(1) = system_tmp.block(1);
       }
@@ -298,8 +298,8 @@
       }
 
     old_solution.compress();
-    old_solution.print(std::cout,7,false,false);
-    exit(0);
+//    old_solution.print(std::cout,7,false,false);
+//    exit(0);
     // normalize the pressure in such a way that the surface pressure
     // equals a known and desired value
     normalize_pressure(old_solution);
@@ -307,8 +307,8 @@
     // set the current solution to the same value as the previous solution
     solution = old_solution;
 
-    solution.print(std::cout,7,false,false);
-    exit(0);
+//    solution.print(std::cout,7,false,false);
+//    exit(0);
   }
 
 }



More information about the CIG-COMMITS mailing list