Kaynağa Gözat

Added some catches for bad VTK files.

master
T-bone 8 yıl önce
ebeveyn
işleme
1e3a263483

+ 4
- 2
examples/ResampleWithDataset.cpp Dosyayı Görüntüle

@@ -56,7 +56,6 @@ int main(int argc, char**argv) {
56 56
         }
57 57
 
58 58
     } else {
59
-
60 59
         vtkXMLUnstructuredGridReader* Reader = vtkXMLUnstructuredGridReader::New();
61 60
             std::cout << "Reading" << argv[1] << std::endl;
62 61
             Reader->SetFileName(argv[1]);
@@ -82,7 +81,10 @@ int main(int argc, char**argv) {
82 81
         Resample->SetValidPointMaskArrayName("HomogeneousDirichlet");
83 82
         Resample->Update();
84 83
 
85
-    std::cout << *Resample << std::endl;
84
+    //std::cout << *Resample << std::endl;.
85
+
86
+   std::cout << "Resampled grid, ncells=" << Resample->GetOutput()->GetNumberOfCells()  
87
+             << " npoints=" << Resample->GetOutput()->GetNumberOfPoints() << std::endl; 
86 88
 
87 89
     vtkXMLUnstructuredGridWriter* Writer = vtkXMLUnstructuredGridWriter::New();
88 90
         Writer->SetInputData( Resample->GetOutput() );

+ 3
- 0
examples/VTKEdgeGsphere.cpp Dosyayı Görüntüle

@@ -184,11 +184,14 @@ int main(int argc, char**argv) {
184 184
         uGrid->GetPointData()->SetScalars( G );
185 185
     }
186 186
 
187
+    std::cout << "Writing file with ncells=" << uGrid->GetNumberOfCells() << "\tnpoints=" << uGrid->GetNumberOfPoints() << std::endl;
188
+
187 189
     // Write out new file
188 190
     vtkXMLUnstructuredGridWriter* Writer = vtkXMLUnstructuredGridWriter::New();
189 191
         //Writer->SetInputConnection(Reader->GetOutputPort());
190 192
         Writer->SetInputData( uGrid );
191 193
         Writer->SetFileName( argv[4] );
194
+        Writer->Update();
192 195
         Writer->Write();
193 196
 
194 197
     //Reader->Delete();

+ 11
- 3
src/FEM4EllipticPDE.cpp Dosyayı Görüntüle

@@ -129,7 +129,7 @@ namespace Lemma {
129 129
     //      Method:  SetVTUGridFile
130 130
     //--------------------------------------------------------------------------------------
131 131
     void FEM4EllipticPDE::SetVTUGridFile ( std::string& fname  ) {
132
-        std::cout  << "Loading VTK .vtu file " << fname << std::endl;
132
+        std::cout  << "Loading VTK .vtu file " << fname;
133 133
         vtkXMLUnstructuredGridReader* MeshReader = vtkXMLUnstructuredGridReader::New();
134 134
         MeshReader->SetFileName(fname.c_str());
135 135
         MeshReader->Update();
@@ -137,6 +137,7 @@ namespace Lemma {
137 137
         //vtkGrid->ShallowCopy( MeshReader->GetOutput() );
138 138
         vtkGrid = MeshReader->GetOutput();
139 139
         MeshReader->Delete();
140
+        std::cout  << " Finished! " << std::endl;
140 141
         return ;
141 142
     }		// -----  end of method FEM4EllipticPDE::SetVTKGridFile  -----
142 143
 
@@ -145,14 +146,21 @@ namespace Lemma {
145 146
     //      Method:  SetVTUGridFile
146 147
     //--------------------------------------------------------------------------------------
147 148
     void FEM4EllipticPDE::SetVTUGridFile ( char* fname  ) {
148
-        std::cout  << "Loading VTK .vtu file " << fname << std::endl;
149
+        std::cout  << "Loading VTK .vtu file " << fname;
149 150
         vtkXMLUnstructuredGridReader* MeshReader = vtkXMLUnstructuredGridReader::New();
150 151
         MeshReader->SetFileName(fname);
151 152
         MeshReader->Update();
152 153
         //vtkGrid->DeepCopy( MeshReader->GetOutput() );
153 154
         //vtkGrid->ShallowCopy( MeshReader->GetOutput() );
154 155
         vtkGrid = MeshReader->GetOutput();
155
-        MeshReader->Delete();
156
+        if (!vtkGrid->GetNumberOfCells()) {
157
+            throw std::runtime_error("In FEM4EllipticPDE::SetVTUGridFile NUMBER OF CELLS = 0");
158
+	}
159
+        if (!vtkGrid->GetNumberOfPoints()) {
160
+            throw std::runtime_error("In FEM4EllipticPDE::SetVTUGridFile NUMBER OF POINTS = 0");
161
+	}
162
+	MeshReader->Delete();
163
+        std::cout  << " Finished! " << std::endl;
156 164
         return ;
157 165
     }		// -----  end of method FEM4EllipticPDE::SetVTKGridFile  -----
158 166
 

+ 13
- 8
src/LinearMag.cpp Dosyayı Görüntüle

@@ -174,26 +174,32 @@ void LinearMag::ScaleB0 ( const MAGUNITS& U ) {
174 174
 //--------------------------------------------------------------------------------------
175 175
 void LinearMag::CalculateRHS ( const std::string& susName ) {
176 176
 
177
+    std::cout << "Calculating RHS...";
178
+    std::cout.flush();
179
+
177 180
     if ( !vtkGrid->GetCellData()->GetScalars(susName.c_str()) ) {
178 181
         std::string err("No cell data by name ");
179 182
         err.append(susName);
180 183
         throw std::runtime_error(err.c_str());
181 184
     }
182 185
 
186
+    if (!vtkGrid->GetNumberOfPoints()) {
187
+        throw std::runtime_error("Number of points zero in input grid!");
188
+    }
189
+
183 190
     vtkDoubleArray* G = vtkDoubleArray::New();
184 191
     G->SetNumberOfComponents(1);
185 192
     G->SetNumberOfTuples( vtkGrid->GetNumberOfPoints() );
186 193
     G->SetName("G");
187 194
     //g.resize(vtkGrid->GetNumberOfPoints());
188 195
     VectorXr GG = VectorXr::Zero( vtkGrid->GetNumberOfPoints() );
189
-
196
+    
190 197
     // Iterate over all the points or all of the cells?
191 198
     for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) {
192 199
 
193 200
         if ( vtkGrid->GetCell(ic)->GetNumberOfPoints() != 4 ) {
194 201
             throw std::runtime_error("Non-tetrahedral mesh encountered!");
195 202
         }
196
-
197 203
         Real cellSus = vtkGrid->GetCellData()->GetScalars(susName.c_str())->GetTuple(ic)[0];
198 204
 
199 205
         Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
@@ -221,8 +227,6 @@ void LinearMag::CalculateRHS ( const std::string& susName ) {
221 227
         */
222 228
         // Face 0, ID 0,1,2
223 229
         Eigen::Matrix<Real, 3, 2> CC = Eigen::Matrix<Real, 3, 2>::Ones() ;
224
-        {
225
-
226 230
             CC.col(1) = C.row(0).tail<3>() - C.row(1).tail<3>();
227 231
             CC.col(2) = C.row(0).tail<3>() - C.row(2).tail<3>();
228 232
             Vector3r nhat = CC.col(1).cross(CC.col(2));
@@ -231,8 +235,7 @@ void LinearMag::CalculateRHS ( const std::string& susName ) {
231 235
             GG(ID[0]) += flux;
232 236
             GG(ID[1]) += flux;
233 237
             GG(ID[2]) += flux;
234
-        }
235
-        // Face 1, ID 0,1,3
238
+	// Face 1, ID 0,1,3
236 239
         {
237 240
             CC.col(1) = C.row(0).tail<3>() - C.row(1).tail<3>();
238 241
             CC.col(2) = C.row(0).tail<3>() - C.row(3).tail<3>();
@@ -243,7 +246,7 @@ void LinearMag::CalculateRHS ( const std::string& susName ) {
243 246
             GG(ID[1]) += flux;
244 247
             GG(ID[3]) += flux;
245 248
         }
246
-        // Face 1, ID 0,2,3
249
+        // Face 2, ID 0,2,3
247 250
         {
248 251
             CC.col(1) = C.row(0).tail<3>() - C.row(2).tail<3>();
249 252
             CC.col(2) = C.row(0).tail<3>() - C.row(3).tail<3>();
@@ -254,7 +257,7 @@ void LinearMag::CalculateRHS ( const std::string& susName ) {
254 257
             GG(ID[2]) += flux;
255 258
             GG(ID[3]) += flux;
256 259
         }
257
-        // Face 1, ID 1,2,3
260
+        // Face 3, ID 1,2,3
258 261
         {
259 262
             CC.col(1) = C.row(1).tail<3>() - C.row(2).tail<3>();
260 263
             CC.col(2) = C.row(1).tail<3>() - C.row(3).tail<3>();
@@ -273,6 +276,8 @@ void LinearMag::CalculateRHS ( const std::string& susName ) {
273 276
 
274 277
     vtkGrid->GetPointData()->AddArray( G );
275 278
     vtkGrid->GetPointData()->SetScalars( G );
279
+    std::cout << "finished" << std::endl;
280
+
276 281
     return ;
277 282
 }		// -----  end of method LinearMag::CalculateRHS  -----
278 283
 

Loading…
İptal
Kaydet