VMTK
Loading...
Searching...
No Matches
vtkvmtkDolfinWriter2 Class Reference

Provides a lightly modified version of vtkvmtkDolfinWriter, with bug fixes and a new region indicators array. More...

#include <vtkvmtkDolfinWriter2.h>

Inheritance diagram for vtkvmtkDolfinWriter2:
[legend]
Collaboration diagram for vtkvmtkDolfinWriter2:
[legend]

Public Types

typedef vtkUnstructuredGridWriter Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkDolfinWriter2 * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetCellEntityIdsArrayName (const char *)
virtual char * GetCellEntityIdsArrayName ()
virtual void SetCellEntityIdsOffset (int)
virtual int GetCellEntityIdsOffset ()

Static Public Member Functions

static vtkvmtkDolfinWriter2 * New ()
static int IsTypeOf (const char *type)
static vtkvmtkDolfinWriter2 * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkDolfinWriter2 ()
 ~vtkvmtkDolfinWriter2 ()
void WriteData () override

Static Protected Member Functions

static void GetDolfinConnectivity (int cellType, vtkIdList *dolfinConnectivity)
static void GetDolfinFaceOrder (int cellType, vtkIdList *dolfinFaceOrder)
static void GetDolfinCellFaceOrder (vtkCell *cell, vtkIdList *dolfinFaceOrder)
static void GetDolfinCellConnectivity (vtkCell *cell, vtkIdList *dolfinConnectivity)

Protected Attributes

char * CellEntityIdsArrayName
int CellEntityIdsOffset

Detailed Description

Provides a lightly modified version of vtkvmtkDolfinWriter, with bug fixes and a new region indicators array.

Slightly modified version of vtkvmtkDolfinWriter Modifications include bug fixes, and a new region indicators array which corresponds to the different cell entity Ids of the tetrahedra.

Definition at line 39 of file vtkvmtkDolfinWriter2.h.

Member Typedef Documentation

◆ Superclass

typedef vtkUnstructuredGridWriter vtkvmtkDolfinWriter2::Superclass

Definition at line 43 of file vtkvmtkDolfinWriter2.h.

Constructor & Destructor Documentation

◆ vtkvmtkDolfinWriter2()

vtkvmtkDolfinWriter2::vtkvmtkDolfinWriter2 ( )
protected

Definition at line 44 of file vtkvmtkDolfinWriter2.cxx.

45{
46 this->CellEntityIdsArrayName = NULL;
47 this->CellEntityIdsOffset = 0;
48}

◆ ~vtkvmtkDolfinWriter2()

vtkvmtkDolfinWriter2::~vtkvmtkDolfinWriter2 ( )
protected

Definition at line 50 of file vtkvmtkDolfinWriter2.cxx.

51{
52 if (this->CellEntityIdsArrayName)
53 {
54 delete[] this->CellEntityIdsArrayName;
55 this->CellEntityIdsArrayName = NULL;
56 }
57}

Member Function Documentation

◆ New()

vtkvmtkDolfinWriter2 * vtkvmtkDolfinWriter2::New ( )
static

◆ IsTypeOf()

int vtkvmtkDolfinWriter2::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkDolfinWriter2::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkDolfinWriter2 * vtkvmtkDolfinWriter2::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkDolfinWriter2::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkDolfinWriter2 * vtkvmtkDolfinWriter2::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkDolfinWriter2::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 401 of file vtkvmtkDolfinWriter2.cxx.

402{
403 vtkUnstructuredGridWriter::PrintSelf(os,indent);
404}

◆ SetCellEntityIdsArrayName()

virtual void vtkvmtkDolfinWriter2::SetCellEntityIdsArrayName ( const char * )
virtual

Set/get the name of the input cell data array holding per-tetrahedron region/entity ids. When set, its values (offset by CellEntityIdsOffset) are written out as a Dolfin XML "mesh_function" region-indicator array, and are also used to tag the boundary faces inherited from the boundary triangle with the matching id. Commonly named "CellEntityIds".

◆ GetCellEntityIdsArrayName()

virtual char * vtkvmtkDolfinWriter2::GetCellEntityIdsArrayName ( )
virtual

Set/get the name of the input cell data array holding per-tetrahedron region/entity ids. When set, its values (offset by CellEntityIdsOffset) are written out as a Dolfin XML "mesh_function" region-indicator array, and are also used to tag the boundary faces inherited from the boundary triangle with the matching id. Commonly named "CellEntityIds".

◆ SetCellEntityIdsOffset()

virtual void vtkvmtkDolfinWriter2::SetCellEntityIdsOffset ( int )
virtual

Set/get the offset added to the values read from CellEntityIdsArrayName before they are written to the Dolfin region-indicator array. Default: 0.

◆ GetCellEntityIdsOffset()

virtual int vtkvmtkDolfinWriter2::GetCellEntityIdsOffset ( )
virtual

Set/get the offset added to the values read from CellEntityIdsArrayName before they are written to the Dolfin region-indicator array. Default: 0.

◆ WriteData()

void vtkvmtkDolfinWriter2::WriteData ( )
overrideprotected

Definition at line 59 of file vtkvmtkDolfinWriter2.cxx.

60{
61 vtkUnstructuredGrid *input= vtkUnstructuredGrid::SafeDownCast(this->GetInput());
62
63 if (!this->FileName)
64 {
65 vtkErrorMacro(<<"FileName not set.");
66 return;
67 }
68
69 std::ofstream out (this->FileName);
70
71 if (!out.good())
72 {
73 vtkErrorMacro(<<"Could not open file for writing.");
74 return;
75 }
76
77 input->BuildLinks();
78
79 int numberOfPoints = input->GetNumberOfPoints();
80 int numberOfCells = input->GetNumberOfCells();
81
82 vtkIdTypeArray* cellEntityIdsArray = NULL;
83 if (this->CellEntityIdsArrayName)
84 {
85 if (input->GetCellData()->GetArray(this->CellEntityIdsArrayName))
86 {
87 cellEntityIdsArray = vtkIdTypeArray::New();
88 cellEntityIdsArray->DeepCopy(input->GetCellData()->GetArray(this->CellEntityIdsArrayName));
89 }
90 else
91 {
92 vtkErrorMacro(<<"BoundaryDataArray with name specified does not exist");
93 }
94 }
95
96 vtkIdTypeArray* tetraCellIdArray = vtkIdTypeArray::New();
97 input->GetIdsOfCellsOfType(VTK_TETRA,tetraCellIdArray);
98 int numberOfTetras = tetraCellIdArray->GetNumberOfTuples();
99
100 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl << endl;
101 out << "<dolfin xmlns:dolfin=\"http://www.phi.chalmers.se/dolfin/\">" << endl;
102 out << " <mesh celltype=\"tetrahedron\" dim=\"3\">" << endl;
103 out << " <vertices size=\""<< numberOfPoints << "\">" << endl;
104
105 int i;
106 double point[3];
107 for (i=0; i<numberOfPoints; i++)
108 {
109 input->GetPoint(i,point);
110 out << " <vertex index=\"" << i << "\" ";
111 out << "x=\"" << point[0] << "\" ";
112 out << "y=\"" << point[1] << "\" ";
113 out << "z=\"" << point[2] << "\" ";
114 out << "/>" <<endl;
115 }
116
117 out << " </vertices>" << endl;
118 out << " <cells size=\"" << numberOfTetras << "\">" << endl;
119
120 vtkIdList* dolfinConnectivity = vtkIdList::New();
121// this->GetDolfinConnectivity(VTK_TETRA,dolfinConnectivity);
122
123 vtkIdList* volumeCellIdMap = vtkIdList::New();
124 volumeCellIdMap->SetNumberOfIds(numberOfCells);
125 int numberOfCellPoints = 4;
126 int k;
127
128 for (i=0; i<numberOfTetras; i++)
129 {
130 vtkIdType tetraCellId = tetraCellIdArray->GetValue(i);
131 volumeCellIdMap->SetId(tetraCellId,i);
132 vtkCell* tetra = input->GetCell(tetraCellId);
133 this->GetDolfinCellConnectivity(tetra,dolfinConnectivity);
134 vtkIdList* cellPointIds = input->GetCell(tetraCellId)->GetPointIds();
135
136 out << " <tetrahedron index=\"" << i << "\" ";
137 for (k=0; k<numberOfCellPoints; k++)
138 {
139 out << "v" << k << "=\"" << cellPointIds->GetId(dolfinConnectivity->GetId(k)) << "\" ";
140 }
141 out << "/>" << endl;
142 }
143
144 out << " </cells>" << endl;
145
146 if (cellEntityIdsArray)
147 {
148
149
150 out << " <data>" << endl;
151
152 //Set the id of the tetrahedra
153 out << " <array name=\"region indicators\" type=\"uint\" size=\"" << numberOfTetras << "\">" << endl;
154
155 for (i=0; i<numberOfTetras; i++)
156 {
157 vtkIdType tetraCellId = tetraCellIdArray->GetValue(i);
158 out << " <element index=\"" << i << "\" ";
159 out << "value=\"" << cellEntityIdsArray->GetValue(tetraCellId) + this->CellEntityIdsOffset << "\" ";
160 out << "/>" << endl;
161 }
162 out << " </array>" << endl;
163
164 vtkIdTypeArray* triangleCellIdArray = vtkIdTypeArray::New();
165 input->GetIdsOfCellsOfType(VTK_TRIANGLE,triangleCellIdArray);
166 int numberOfTriangles = triangleCellIdArray->GetNumberOfTuples();
167 vtkIdList* boundaryFaceCells = vtkIdList::New();
168// boundaryFaceCells->SetNumberOfIds(numberOfTriangles);
169 vtkIdList* boundaryFaceIds = vtkIdList::New();
170// boundaryFaceIds->SetNumberOfIds(numberOfTriangles);
171 vtkIdList* boundaryFaceIndicators = vtkIdList::New();
172
173 vtkIdType triangleCellId;
174 for (i=0; i<numberOfTriangles; i++)
175 {
176 triangleCellId = triangleCellIdArray->GetValue(i);
177 vtkIdList* faceCellPoints = vtkIdList::New();
178 input->GetCellPoints(triangleCellId,faceCellPoints);
179
180 vtkIdList* cellIds = vtkIdList::New();
181 input->GetCellNeighbors(triangleCellId,faceCellPoints,cellIds);
182 vtkIdType nNeighbors = cellIds->GetNumberOfIds();
183
184 for (int j=0; j<nNeighbors; j++)
185 {
186 vtkIdType cellId = cellIds->GetId(j);
187 vtkCell* cell = input->GetCell(cellId);
188 int cellType = cell->GetCellType();
189
190 if (cellType != VTK_TETRA)
191 {
192 vtkErrorMacro(<<"Volume cell adjacent to triangle is not tetrahedron (volume cell id: "<<cellId <<") and it is unsupported by Dolfin. Skipping face.");
193 continue;
194 }
195
196
197 int numberOfFaces = cell->GetNumberOfFaces();
198 vtkIdType faceId = -1;
199 int k;
200 for (k=0; k<numberOfFaces; k++)
201 {
202 vtkCell* face = cell->GetFace(k);
203 vtkIdList* matchingPointIds = vtkIdList::New();
204 matchingPointIds->DeepCopy(face->GetPointIds());
205 matchingPointIds->IntersectWith(faceCellPoints);
206 int numberOfNonMatching = face->GetNumberOfPoints() - matchingPointIds->GetNumberOfIds();
207 matchingPointIds->Delete();
208
209 if (numberOfNonMatching==0)
210 {
211 faceId = k;
212 break;
213 }
214 }
215
216 vtkIdList* dolfinFaceOrder = vtkIdList::New();
217// this->GetDolfinFaceOrder(cellType,dolfinFaceOrder);
218 this->GetDolfinCellFaceOrder(cell,dolfinFaceOrder);
219 vtkIdType dolfinFaceId = dolfinFaceOrder->GetId(faceId);
220 dolfinFaceOrder->Delete();
221
222 boundaryFaceCells->InsertNextId(volumeCellIdMap->GetId(cellId));
223 boundaryFaceIds->InsertNextId(dolfinFaceId);
224 boundaryFaceIndicators->InsertNextId(cellEntityIdsArray->GetValue(triangleCellId) + this->CellEntityIdsOffset);
225 }
226
227 faceCellPoints->Delete();
228 cellIds->Delete();
229 }
230
231 vtkIdType numberOfBoundaryFacets = boundaryFaceCells->GetNumberOfIds();
232
233
234 out << " <array name=\"boundary facet cells\" type=\"uint\" size=\"" << numberOfBoundaryFacets << "\">" << endl;
235 for (i=0; i<numberOfBoundaryFacets; i++)
236 {
237 out << " <element index=\"" << i << "\" ";
238 out << "value=\"" << boundaryFaceCells->GetId(i) << "\" ";
239 out << "/>" << endl;
240 }
241 out << " </array>" << endl;
242
243 out << " <array name=\"boundary facet numbers\" type=\"uint\" size=\"" << numberOfBoundaryFacets << "\">" << endl;
244 for (i=0; i<numberOfBoundaryFacets; i++)
245 {
246 out << " <element index=\"" << i << "\" ";
247 out << "value=\"" << boundaryFaceIds->GetId(i) << "\" ";
248 out << "/>" << endl;
249 }
250 out << " </array>" << endl;
251
252 out << " <array name=\"boundary indicators\" type=\"uint\" size=\"" << numberOfBoundaryFacets << "\">" << endl;
253 for (i=0; i<numberOfBoundaryFacets; i++)
254 {
255 out << " <element index=\"" << i << "\" ";
256 out << "value=\"" << boundaryFaceIndicators->GetId(i) << "\" ";
257 out << "/>" << endl;
258 }
259 out << " </array>" << endl;
260
261 out << " </data>" << endl;
262
263 triangleCellIdArray->Delete();
264 boundaryFaceCells->Delete();
265 boundaryFaceIds->Delete();
266 boundaryFaceIndicators->Delete();
267 }
268
269 out << " </mesh>" << endl;
270 out << "</dolfin>" << endl;
271
272 tetraCellIdArray->Delete();
273 dolfinConnectivity->Delete();
274 volumeCellIdMap->Delete();
275
276 if (cellEntityIdsArray)
277 {
278 cellEntityIdsArray->Delete();
279 }
280}
static void GetDolfinCellConnectivity(vtkCell *cell, vtkIdList *dolfinConnectivity)
static void GetDolfinCellFaceOrder(vtkCell *cell, vtkIdList *dolfinFaceOrder)

◆ GetDolfinConnectivity()

void vtkvmtkDolfinWriter2::GetDolfinConnectivity ( int cellType,
vtkIdList * dolfinConnectivity )
staticprotected

Definition at line 285 of file vtkvmtkDolfinWriter2.cxx.

286{
287 dolfinConnectivity->Initialize();
288
289 switch(cellType)
290 {
291 case VTK_TETRA:
292 dolfinConnectivity->SetNumberOfIds(4);
293 dolfinConnectivity->SetId(0,0);
294 dolfinConnectivity->SetId(1,1);
295 dolfinConnectivity->SetId(2,2);
296 dolfinConnectivity->SetId(3,3);
297 break;
298 default:
299 std::cerr<<"Element type not currently supported in dolfin. Skipping element for connectivity."<<std::endl;
300 break;
301 }
302}

◆ GetDolfinFaceOrder()

void vtkvmtkDolfinWriter2::GetDolfinFaceOrder ( int cellType,
vtkIdList * dolfinFaceOrder )
staticprotected

Definition at line 304 of file vtkvmtkDolfinWriter2.cxx.

305{
306 dolfinFaceOrder->Initialize();
307
308 switch(cellType)
309 {
310 case VTK_TETRA:
311 dolfinFaceOrder->SetNumberOfIds(4);
312 dolfinFaceOrder->SetId(0,2);
313 dolfinFaceOrder->SetId(1,0);
314 dolfinFaceOrder->SetId(2,1);
315 dolfinFaceOrder->SetId(3,3);
316 break;
317 default:
318 std::cerr<<"Element type not currently supported in dolfin. Skipping element for face ordering."<<std::endl;
319 break;
320 }
321}

◆ GetDolfinCellConnectivity()

void vtkvmtkDolfinWriter2::GetDolfinCellConnectivity ( vtkCell * cell,
vtkIdList * dolfinConnectivity )
staticprotected

Get the connectivity for a specific cell. The point ids are sorted in increasing order.

Definition at line 323 of file vtkvmtkDolfinWriter2.cxx.

324{
325 dolfinConnectivity->Initialize();
326 int cellType = cell->GetCellType();
327 vtkIdTypeArray* pointIds = vtkIdTypeArray::New();
328 switch(cellType)
329 {
330 case VTK_TETRA:
331 pointIds->SetNumberOfTuples(4);
332 pointIds->SetValue(0,cell->GetPointId(0));
333 pointIds->SetValue(1,cell->GetPointId(1));
334 pointIds->SetValue(2,cell->GetPointId(2));
335 pointIds->SetValue(3,cell->GetPointId(3));
336 dolfinConnectivity->SetNumberOfIds(4);
337 dolfinConnectivity->SetId(0,0);
338 dolfinConnectivity->SetId(1,1);
339 dolfinConnectivity->SetId(2,2);
340 dolfinConnectivity->SetId(3,3);
341 vtkSortDataArray::Sort(pointIds,dolfinConnectivity);
342 break;
343 default:
344 std::cerr<<"Element type not currently supported in dolfin. Skipping element for connectivity."<<std::endl;
345 break;
346 }
347 pointIds->Delete();
348}

◆ GetDolfinCellFaceOrder()

void vtkvmtkDolfinWriter2::GetDolfinCellFaceOrder ( vtkCell * cell,
vtkIdList * dolfinFaceOrder )
staticprotected

Get the face order for a specific cell.

Definition at line 351 of file vtkvmtkDolfinWriter2.cxx.

352{
353 dolfinFaceOrder->Initialize();
354
355 int cellType = cell->GetCellType();
356
357 vtkIdList* dolfinConnectivity = vtkIdList::New();
358 GetDolfinCellConnectivity(cell,dolfinConnectivity);
359 vtkIdList* inverseDolfinConnectivity = vtkIdList::New();
360 inverseDolfinConnectivity->SetNumberOfIds(dolfinConnectivity->GetNumberOfIds());
361 for (int i=0; i<dolfinConnectivity->GetNumberOfIds(); i++)
362 {
363 inverseDolfinConnectivity->SetId(dolfinConnectivity->GetId(i),i);
364 }
365
366
367 const vtkIdType *faceArray;
368 switch(cellType)
369 {
370 case VTK_TETRA:
371 dolfinFaceOrder->SetNumberOfIds(4);
372 for (int i=0; i<4; i++)
373 {
374 faceArray = vtkTetra::GetFaceArray(i);
375 for (int j=0; j<4;j++)
376 {
377 bool inFaceArray = false;
378 for (int k=0;k<3;k++)
379 {
380 if (inverseDolfinConnectivity->GetId(faceArray[k])==j)
381 {
382 inFaceArray = true;
383 }
384 }
385 if (!inFaceArray)
386 {
387 dolfinFaceOrder->SetId(i,j);
388 break;
389 }
390 }
391 }
392 break;
393 default:
394 std::cerr<<"Element type not currently supported in dolfin. Skipping element for face ordering."<<std::endl;
395 break;
396 }
397
398 dolfinConnectivity->Delete();
399}

Member Data Documentation

◆ CellEntityIdsArrayName

char* vtkvmtkDolfinWriter2::CellEntityIdsArrayName
protected

Definition at line 89 of file vtkvmtkDolfinWriter2.h.

◆ CellEntityIdsOffset

int vtkvmtkDolfinWriter2::CellEntityIdsOffset
protected

Definition at line 90 of file vtkvmtkDolfinWriter2.h.


The documentation for this class was generated from the following files: