Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
vtkparser.cpp
Go to the documentation of this file.
1/* =============================================================================
2** This file is part of the mmg software package for the tetrahedral
3** mesh modification.
4** Copyright (c) Bx INP/CNRS/Inria/UBordeaux/UPMC, 2004-
5**
6** mmg is free software: you can redistribute it and/or modify it
7** under the terms of the GNU Lesser General Public License as published
8** by the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** mmg is distributed in the hope that it will be useful, but WITHOUT
12** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14** License for more details.
15**
16** You should have received a copy of the GNU Lesser General Public
17** License and of the GNU General Public License along with mmg (in
18** files COPYING.LESSER and COPYING). If not, see
19** <http://www.gnu.org/licenses/>. Please read their terms carefully and
20** use this copy of the mmg distribution only if you accept them.
21** =============================================================================
22*/
23
32#include <vtkSmartPointer.h>
33#include <vtkXMLReader.h>
34#include <vtkXMLWriter.h>
35#include <vtkXMLUnstructuredGridReader.h>
36#include <vtkXMLPolyDataReader.h>
37#include <vtkDataSetReader.h>
38#include <vtkDataSet.h>
39#include <vtkUnstructuredGrid.h>
40#include <vtkPolyData.h>
41#include <vtkStructuredGrid.h>
42#include <vtkPointData.h>
43#include <vtkCellData.h>
44#include <vtkFieldData.h>
45#include <vtkCellTypes.h>
46#include <vtkDataArray.h>
47
48#include "vtkparser.hpp"
49
60template<class TReader>
61vtkDataSet *MMG5_load_vtkXMLFile(const char*fileName)
62{
63 vtkSmartPointer<TReader> reader =
64 vtkSmartPointer<TReader>::New();
65 reader->SetFileName(fileName);
66
67 reader->Update();
68 if ( !reader->GetOutput() ) {
69 throw "Unable to open file.";
70 }
71
72 reader->GetOutput()->Register(reader);
73
74 return vtkDataSet::SafeDownCast(reader->GetOutput());
75}
76
99static
100int MMG5_count_vtkEntities ( vtkDataSet *dataset, MMG5_pMesh mesh,
101 int8_t *ptMeditRef, int8_t *eltMeditRef,
102 int *nsols, int8_t *metricData ) {
103
104 static int8_t mmgWarn0 = 0;
105 static int8_t mmgWarn1 = 0;
106
107 // Count the number of entities in the mesh
108 assert ( !mesh->np );
109 assert ( !mesh->nt );
110 assert ( !mesh->na );
111 assert ( !mesh->nquad );
112 assert ( !mesh->nprism );
113
114 mesh->np = dataset->GetNumberOfPoints();
115 vtkIdType numCells = dataset->GetNumberOfCells();
116
117 assert ( !mesh->npi );
118 for ( vtkIdType i = 0; i < numCells; i++ ) {
119 int typ = dataset->GetCellType(i);
120 switch ( typ ) {
121 case ( VTK_VERTEX ):
122 ++mesh->npi;
123 break;
124 case ( VTK_POLY_LINE ):
125 printf( "polylin %lld \n", dataset->GetCell(i)->GetNumberOfPoints() - 1 );
126
127 printf( "%lld %lld %lld\n", dataset->GetCell(i)->GetPointId(0)+1,
128 dataset->GetCell(i)->GetPointId(1)+1,dataset->GetCell(i)->GetPointId(2)+1);
129 mesh->na += dataset->GetCell(i)->GetNumberOfPoints() - 1;
130 break;
131 case ( VTK_LINE ):
132 ++mesh->na;
133 break;
134 case ( VTK_TRIANGLE ):
135 ++mesh->nt;
136 break;
137 case ( VTK_QUAD):
138 ++mesh->nquad;
139 break;
140 case ( VTK_TETRA):
141 ++mesh->ne;
142 break;
143 case ( VTK_WEDGE):
144 ++mesh->nprism;
145 break;
146 default:
147 if ( !mmgWarn1 ) {
148 printf( " ## Warning:%s: unexpected element type (%d).",__func__,typ);
149 mmgWarn1 = 1;
150 }
151 }
152 }
153 assert ( mesh->npi == mesh->np || !mesh->npi );
154 mesh->npi = 0;
155
156 // Count the number of point data and detect point references
157 auto *pd = dataset->GetPointData();
158 int npointData = 0;
159 int npointRef = 0;
160 int nmetricField = 0;
161
162 *ptMeditRef = -1;
163 if ( pd ) {
164 npointData = pd->GetNumberOfArrays();
165 for (int k = 0; k < npointData; k++) {
166 if ( strstr(pd->GetArrayName(k),":metric" ) ) {
167 ++nmetricField;
168 }
169 else if ( strstr(pd->GetArrayName(k),"medit:ref" ) ) {
170 (*ptMeditRef) = k;
171 ++npointRef;
172 }
173 }
174
175 if ( npointRef > 1 ) {
176 printf( " ## Warning:%s: %d reference fields detected (labelled 'medit:ref')."
177 " Only the last is used, others are ignored.", __func__, npointRef);
178 }
179 if ( nmetricField > 1 ) {
180 printf(" ## Error:%s: %d metric fields detected (labelled with a string"
181 " containing the 'metric' keyword).\n"
182 " Exit Program.\n",__func__,nmetricField);
183 return -1;
184 }
185 }
186
187 // Count the number of cell data and detect cell references
188 auto *cd = dataset->GetCellData();
189 int ncellData = 0;
190 int ncellRef = 0;
191
192 *eltMeditRef = -1;
193 if ( cd ) {
194 ncellData = cd->GetNumberOfArrays();
195 for (int k = 0; k < ncellData; k++) {
196 if ( strstr(cd->GetArrayName(k),"medit:ref" ) ) {
197 *eltMeditRef = k;
198 ++ncellRef;
199 }
200 }
201 }
202
203 // Count the number of field data
204 auto *fd = dataset->GetFieldData();
205 if ( fd->GetNumberOfArrays() ) {
206 printf( " ## Warning:%s: VTK field data not used in Mmg."
207 " Ignored.\n",__func__ );
208 }
209
210 *nsols = npointData + ncellData - npointRef - ncellRef;
211 *metricData = ( nmetricField > 0 );
212
213 return 1;
214}
215
230int MMG5_loadVtpMesh_part1(MMG5_pMesh mesh,const char *filename,vtkDataSet **dataset,
231 int8_t *ptMeditRef,int8_t *eltMeditRef,int *nsols,
232 int8_t *metricData) {
233
234 (*nsols) = 0;
235 (*ptMeditRef) = (*eltMeditRef) = -1;
236
237 // Read all the data from the file
238 try {
239 (*dataset) = MMG5_load_vtkXMLFile<vtkXMLPolyDataReader> ( filename );
240 }
241 catch( ... ) {
242 return 0;
243 }
244
245 // count the number of entities of each type
246 int ier = MMG5_count_vtkEntities ( (*dataset),mesh,ptMeditRef,eltMeditRef,
247 nsols,metricData );
248
249 if ( ier != 1 ) {
250 return -1;
251 }
252 return 1;
253}
254
269int MMG5_loadVtkMesh_part1(MMG5_pMesh mesh,const char *filename,vtkDataSet **dataset,
270 int8_t *ptMeditRef,int8_t *eltMeditRef,int *nsols,
271 int8_t *metricData ) {
272
273 (*nsols) = 0;
274 (*ptMeditRef) = (*eltMeditRef) = -1;
275
276 // Read all the data from the file
277 try {
278 (*dataset) = MMG5_load_vtkXMLFile<vtkDataSetReader> ( filename );
279 }
280 catch( ... ) {
281 return 0;
282 }
283
284 // count the number of entities of each type
285 int ier = MMG5_count_vtkEntities ( (*dataset),mesh,ptMeditRef,eltMeditRef,
286 nsols,metricData );
287
288 if ( ier != 1 ) {
289 return -1;
290 }
291 return 1;
292}
293
308int MMG5_loadVtuMesh_part1(MMG5_pMesh mesh,const char *filename,vtkDataSet **dataset,
309 int8_t *ptMeditRef,int8_t *eltMeditRef,int *nsols,
310 int8_t *metricData) {
311
312 (*nsols) = 0;
313 (*ptMeditRef) = (*eltMeditRef) = -1;
314 (*metricData) = 0;
315
316 // Read all the data from the file
317 try {
318 (*dataset) = MMG5_load_vtkXMLFile<vtkXMLUnstructuredGridReader> ( filename );
319 }
320 catch ( ... ) {
321 return 0;
322 }
323
324 // count the number of entities of each type
325 int ier = MMG5_count_vtkEntities ( (*dataset),mesh,ptMeditRef,eltMeditRef,
326 nsols,metricData );
327
328 if ( ier != 1 ) {
329 return -1;
330 }
331
332 return 1;
333}
334
335
336
347 int8_t ptMeditRef,int8_t eltMeditRef,int nsols) {
348 vtkSmartPointer<vtkDataArray> ptar = NULL, car = NULL;
349 int ier;
350 MMG5_int nref = 0;
351 static int8_t mmgWarn1 = 0;
352
353 // Point transfers in Mmg data structure
354 if ( ptMeditRef > -1 ) {
355 auto *pd = (*dataset)->GetPointData();
356 ptar = pd->GetArray(ptMeditRef);
357
358 // Check the field name
359 assert ( strstr( ptar->GetName(), "medit:ref" ) );
360
361 // Check that we get 1 data only
362 assert ( ptar->GetNumberOfComponents() == 1 );
363
364 MMG5_int np = ptar->GetNumberOfTuples();
365 if ( np != mesh->np ) {
366 printf( " ## Error: Point data size (%" MMG5_PRId ") differs from the number of"
367 " vertices (%" MMG5_PRId ")\n",np,mesh->np);
368 return -1;
369 }
370 // read vertices and vertices refs
371 for ( vtkIdType k = 0; k < (*dataset)->GetNumberOfPoints(); k++ ) {
372 MMG5_pPoint ppt = &mesh->point[k+1];
373 (*dataset)->GetPoint(k,mesh->point[k+1].c);
374 ppt->tag = MG_NUL;
375 ppt->tmp = 0;
376 ppt->ref = ptar->GetTuple1(k);
377 if ( ppt->ref < 0 ) {
378 ppt->ref = -ppt->ref;
379 ++nref;
380 }
381 }
382 }
383 else {
384 // read vertices only
385 for ( vtkIdType k = 0; k < (*dataset)->GetNumberOfPoints(); k++ ) {
386 MMG5_pPoint ppt = &mesh->point[k+1];
387 (*dataset)->GetPoint(k,mesh->point[k+1].c);
388 ppt->tag = MG_NUL;
389 ppt->tmp = 0;
390 ppt->ref = 0;
391 }
392 }
393
394 // Cells transfer toward Mmg data structure
395 assert ( !mesh->nei );
396 assert ( !mesh->nti );
397 assert ( !mesh->nai );
398 assert ( (mesh->npi == mesh->np) || !mesh->npi );
399
400 mesh->npi = 0;
401 MMG5_int nqi = 0;
402 MMG5_int npri = 0;
403 MMG5_int na = 0;
404 MMG5_int nbl_a = 0;
405 MMG5_int nt = 0;
406 MMG5_int nbl_t = 0;
407
408 // Get pointer toward cells data containing element refs
409 vtkIdType numCells = (*dataset)->GetNumberOfCells();
410
411 if ( eltMeditRef > -1 ) {
412 // If present, read elements references
413 car = (*dataset)->GetCellData()->GetArray(eltMeditRef);
414
415 // Check the field name
416 assert ( strstr( car->GetName(), "medit:ref" ) );
417 // Check that we get 1 data only
418 assert ( car->GetNumberOfComponents() == 1 );
419
420 MMG5_int ne = car->GetNumberOfTuples();
421 if ( ne != numCells ) {
422 printf( " ## Error: Cell data size (%" MMG5_PRId ") differs from the number of"
423 " cells (%lld)\n",ne,numCells);
424 return -1;
425 }
426 }
427
428 // Transfer cells to Mmg
429 for ( vtkIdType k = 0; k < numCells; k++ ) {
430 MMG5_pPoint ppt = NULL;
431 MMG5_pEdge pa = NULL;
432 MMG5_pTria ptt = NULL;
433 MMG5_pQuad pq = NULL;
434 MMG5_pTetra pt = NULL;
435 MMG5_pPrism ppr = NULL;
436
437 int typ = (*dataset)->GetCellType(k);
438 MMG5_int ref = 0;
439
440 switch ( typ ) {
441 case ( VTK_VERTEX ):
442 ppt = &mesh->point[++mesh->npi];
443 ppt->ref = car ? car->GetTuple1(k) : 0;
444 if ( ppt->ref < 0 ) {
445 ppt->ref = -ppt->ref;
446 ++nref;
447 }
448 break;
449 case ( VTK_POLY_LINE ):
450 int n;
451 n = (*dataset)->GetCell(k)->GetNumberOfPoints() - 1;
452
453 for ( int i=0; i<n; ++i ) {
454 ++mesh->nai;
455 ref = car ? car->GetTuple1(k) : 0;
456 }
457 /* Skip edges with iso ref */
458 if ( mesh->info.iso && MMG5_abs(ref) == mesh->info.isoref ) {
459 /* Skip this edge */
460 ++nbl_a;
461 }
462 else {
463 for ( int i=0; i < n; ++i ) {
464 pa = &mesh->edge[++na];
465 pa->a = (*dataset)->GetCell(k)->GetPointId(i) +1;
466 pa->b = (*dataset)->GetCell(k)->GetPointId(i+1)+1;
467 }
468 pa->ref = ref;
469 pa->tag |= MG_REF;
470 if ( pa->ref < 0 ) {
471 pa->ref = -pa->ref;
472 ++nref;
473 }
474 }
475
476 break;
477 case ( VTK_LINE ):
478
479 ++mesh->nai;
480 ref = car ? car->GetTuple1(k) : 0;
481
482 // Skip edges with iso ref
483 if ( mesh->info.iso && MMG5_abs(ref) == mesh->info.isoref ) {
484 /* Skip this edge */
485 ++nbl_a;
486 }
487 else {
488 pa = &mesh->edge[++na];
489 pa->a = (*dataset)->GetCell(k)->GetPointId(0)+1;
490 pa->b = (*dataset)->GetCell(k)->GetPointId(1)+1;
491 pa->ref = ref;
492 pa->tag |= MG_REF;
493 if ( pa->ref < 0 ) {
494 pa->ref = -pa->ref;
495 ++nref;
496 }
497 }
498 assert( na+nbl_a <= mesh->na );
499 break;
500
501 case ( VTK_TRIANGLE ):
502 ++mesh->nti;
503 ref = car ? car->GetTuple1(k) : 0;
504
505 // skip tria with iso ref in 3D
506 if ( mesh->info.iso && MMG5_abs(ref) == mesh->info.isoref && mesh->dim == 3 ) {
507 /* Skip this edge */
508 ++nbl_t;
509 }
510 else {
511 ptt = &mesh->tria[++nt];
512 for ( int i=0; i<3; ++i ) {
513 ptt->v[i] = (*dataset)->GetCell(k)->GetPointId(i)+1;
514 }
515 ptt->ref = ref;
516
517 if ( ptt->ref < 0 ) {
518 ptt->ref = -ptt->ref;
519 ++nref;
520 }
521 }
522 break;
523
524 case ( VTK_QUAD ):
525 pq = &mesh->quadra[++nqi];
526 pq->ref = car ? car->GetTuple1(k) : 0;
527 for ( int i=0; i<4; ++i ) {
528 pq->v[i] = (*dataset)->GetCell(k)->GetPointId(i)+1;
529 }
530 if ( pq->ref < 0 ) {
531 pq->ref = -pq->ref;
532 ++nref;
533 }
534 break;
535
536 case ( VTK_TETRA ):
537 // Skip volume elts if called from mmgs
538 if ( !mesh->tetra ) continue;
539
540 pt = &mesh->tetra[++mesh->nei];
541 pt->ref = car ? car->GetTuple1(k) : 0;
542 for ( int i=0; i<4; ++i ) {
543 pt->v[i] = (*dataset)->GetCell(k)->GetPointId(i)+1;
544 }
545 if ( pt->ref < 0 ) {
546 pt->ref = -pt->ref;
547 ++nref;
548 }
549 break;
550
551 case ( VTK_WEDGE ):
552 // Skip volume elts if called from mmgs
553 if ( !mesh->prism ) continue;
554
555 ppr = &mesh->prism[++npri];
556 ppr->ref = car ? car->GetTuple1(k) : 0;
557 for ( int i=0; i<6; ++i ) {
558 ppr->v[i] = (*dataset)->GetCell(k)->GetPointId(i)+1;
559 }
560 if ( ppr->ref < 0 ) {
561 ppr->ref = -ppr->ref;
562 ++nref;
563 }
564 break;
565
566 default:
567 if ( !mmgWarn1 ) {
568 printf(" ## Warning:%s: unexpected element type (%d).\n",
569 __func__,typ);
570 mmgWarn1 = 1;
571 }
572 }
573 }
574
575 // Checks
576 assert ( mesh->nai == mesh->na );
577 assert ( mesh->nti == mesh->nt );
578 assert ( mesh->nei == mesh->ne );
579 assert ( nqi == mesh->nquad );
580 assert ( npri == mesh->nprism );
581 assert ( na + nbl_a == mesh->na );
582 assert ( nt + nbl_t == mesh->nt );
583
584 // Array reallocation if ISO refs has been skipped
585 if ( mesh->info.iso ) {
586 if ( mesh->nt ) {
587 if( !nt )
589
590 else if ( nt < mesh->nt ) {
591 MMG5_ADD_MEM(mesh,(nt-mesh->nt)*sizeof(MMG5_Tria),"triangles",
592 fprintf(stderr," Exit program.\n");
593 return -1);
594 MMG5_SAFE_RECALLOC(mesh->tria,mesh->nt+1,(nt+1),MMG5_Tria,"triangles",
595 return -1);
596 }
597 mesh->nt = nt;
598 }
599 if ( mesh->na ) {
600 if( !na )
602 else if ( na < mesh->na ) {
603 MMG5_ADD_MEM(mesh,(na-mesh->na)*sizeof(MMG5_Edge),"edges",
604 fprintf(stderr," Exit program.\n");
605 return -1);
606 MMG5_SAFE_RECALLOC(mesh->edge,mesh->na+1,(na+1),MMG5_Edge,"edges",
607 return -1);
608 }
609 mesh->na = na;
610 }
611 }
612
614 if ( ier < 1 ) return ier;
615
616 if ( sol && *sol ) {
617 // Read the solution at nodes
618 // Init (*sol)[0] for the case where nsols=0
619 MMG5_pSol psl = *sol;
620 psl->ver = mesh->ver;
621 psl->dim = mesh->dim;
622 psl->type = 1;
623
624 int isol = 0;
625 if ( nsols ) {
626 auto *pd = (*dataset)->GetPointData();
627
628 auto *cd = (*dataset)->GetCellData();
629
630 if ( pd ) {
631 int npointData = pd->GetNumberOfArrays();
632
633 for (int j = 0; j < npointData; j++) {
634 char *ptr = NULL;
635 bool metricData = 0;
636 char chaine[MMG5_FILESTR_LGTH];
637 strcpy(chaine,pd->GetArrayName(j));
638
639 if ( strstr(chaine,"medit:ref" ) ) {
640 continue;
641 }
642 else if ( (ptr = strstr(chaine,":metric")) ) {
643 *ptr = '\0';
644 metricData = 1;
645 }
646
647 psl = *sol + isol;
648 psl->ver = mesh->ver;
649 psl->dim = mesh->dim;
650 psl->type = 1;
651 psl->entities = MMG5_Vertex;
652
653 if ( !MMG5_Set_inputSolName(mesh,psl,chaine) ) {
654 if ( !mmgWarn1 ) {
655 mmgWarn1 = 1;
656 fprintf(stderr,"\n ## Warning: %s: unable to set solution name for"
657 " at least 1 solution.\n",__func__);
658 }
659 }
660
661 auto ar = pd->GetArray(j);
662
663 psl->np = ar->GetNumberOfTuples();
664 if ( mesh->np != psl->np ) {
665 fprintf(stderr," ** MISMATCHES DATA: THE NUMBER OF VERTICES IN "
666 "THE MESH (%" MMG5_PRId ") DIFFERS FROM THE NUMBER OF VERTICES IN "
667 "THE SOLUTION (%" MMG5_PRId ") \n",mesh->np,psl->np);
668 return -1;
669 }
670
671 int ncp = ar->GetNumberOfComponents();
672
673 if ( ncp == 1 ) {
674 psl->size = 1;
675 psl->type = 1;
676 }
677 else if ( ncp == 2 || ncp == 3 ) {
678 assert ( ncp == mesh->dim );
679 psl->size = ncp;
680 psl->type = 2;
681 }
682 else if ( ncp == (mesh->dim * mesh->dim) ) {
683 if ( metricData ) {
684 psl->size = (psl->dim*(psl->dim+1))/2;
685 psl->type = 3;
686 }
687 else {
688 psl->size = ncp;
689 psl->type = 4;
690 }
691 }
692 else {
693 fprintf(stderr," ** UNEXPECTED NUMBER OF COMPONENTS (%d). IGNORED \n",ncp);
694 return -1;
695 }
696
697 // mem alloc
698 if ( psl->m ) MMG5_DEL_MEM(mesh,psl->m);
699 psl->npmax = mesh->npmax;
700
701 MMG5_ADD_MEM(mesh,(psl->size*(psl->npmax+1))*sizeof(double),"initial solution",
702 fprintf(stderr," Exit program.\n");
703 return -1);
704 MMG5_SAFE_CALLOC(psl->m,psl->size*(psl->npmax+1),double,return -1);
705
706 switch ( psl->type ) {
707 case ( 1 ): case ( 2 ):
708 for (MMG5_int k=1; k<=psl->np; k++) {
709 MMG5_int iadr = k*psl->size;
710 ar->GetTuple ( k-1, &psl->m[iadr] );
711 }
712 break;
713
714 case ( 3 ):
715 // anisotropic sol
716 double dbuf[9];
717
718 for (MMG5_int k=1; k<=psl->np; k++) {
719 ar->GetTuple ( k-1, dbuf );
720 MMG5_int iadr = psl->size*k;
721
722 if ( !metricData ) {
723 // Non symmetric tensor
724 if ( psl->dim ==2 ) {
725 psl->m[iadr] = dbuf[0];
726 psl->m[iadr+1] = dbuf[1];
727 psl->m[iadr+2] = dbuf[3];
728 psl->m[iadr+3] = dbuf[4];
729 }
730 else {
731 for ( int i=0 ; i<9 ; i++ ) {
732 psl->m[iadr+i] = dbuf[i];
733 }
734 }
735 }
736 else {
737 // Symmetric tensor
738 if ( psl->dim ==2 ) {
739 assert ( dbuf[1] == dbuf[2] );
740
741 psl->m[iadr] = dbuf[0];
742 psl->m[iadr+1] = dbuf[1];
743 psl->m[iadr+2] = dbuf[3];
744 }
745 else {
746 assert ( dbuf[1]==dbuf[3] || dbuf[2]==dbuf[6] || dbuf[5]==dbuf[7] );
747
748 psl->m[iadr+0] = dbuf[0];
749 psl->m[iadr+1] = dbuf[1];
750 psl->m[iadr+2] = dbuf[2];
751 psl->m[iadr+3] = dbuf[4];
752 psl->m[iadr+4] = dbuf[5];
753 psl->m[iadr+5] = dbuf[8];
754 }
755 }
756 }
757
758 break;
759 default:
760 fprintf(stderr," ** UNEXPECTED METRIC TYPE (%d). EXIT PROGRAM \n",psl->type);
761 return -1;
762 }
763 ++isol;
764 }
765 }
766
767 if ( cd ) {
768 int ncellData = cd->GetNumberOfArrays();
769
770 for (int j = 0; j < ncellData; j++) {
771 char *ptr = NULL;
772 char chaine[MMG5_FILESTR_LGTH];
773 strcpy(chaine,cd->GetArrayName(j));
774
775 if ( strstr(chaine,"medit:ref" ) ) {
776 continue;
777 }
778
779 psl = *sol + isol;
780 psl->ver = mesh->ver;
781 psl->dim = mesh->dim;
782 psl->type = 1;
784
785 if ( !MMG5_Set_inputSolName(mesh,psl,chaine) ) {
786 if ( !mmgWarn1 ) {
787 mmgWarn1 = 1;
788 fprintf(stderr,"\n ## Warning: %s: unable to set solution name for"
789 " at least 1 solution.\n",__func__);
790 }
791 }
792
793 auto ar = cd->GetArray(j);
794
795 psl->np = ar->GetNumberOfTuples();
796 if ( numCells != psl->np ) {
797 fprintf(stderr," ** MISMATCHES DATA: THE NUMBER OF ELEMENTS IN "
798 "THE MESH (%" MMG5_PRId ") DIFFERS FROM THE NUMBER OF CELLS DATA IN "
799 "THE SOLUTION (%" MMG5_PRId ") \n",mesh->ne,psl->np);
800 return -1;
801 }
802
803 int ncp = ar->GetNumberOfComponents();
804
805 if ( ncp == 1 ) {
806 psl->size = 1;
807 psl->type = 1;
808 }
809 else if ( ncp == 2 || ncp == 3 ) {
810 assert ( ncp == mesh->dim );
811 psl->size = ncp;
812 psl->type = 2;
813 }
814 else if ( ncp == (mesh->dim * mesh->dim) ) {
815 psl->size = ncp;
816 psl->type = 3;
817 }
818 else {
819 fprintf(stderr," ** UNEXPECTED NUMBER OF COMPONENTS (%d). IGNORED \n",ncp);
820 return -1;
821 }
822
823 // mem alloc
824 if ( psl->m ) MMG5_DEL_MEM(mesh,psl->m);
825 psl->npmax = mesh->nemax;
826
827 MMG5_ADD_MEM(mesh,(psl->size*(psl->npmax+1))*sizeof(double),"initial solution",
828 fprintf(stderr," Exit program.\n");
829 return -1);
830 MMG5_SAFE_CALLOC(psl->m,psl->size*(psl->npmax+1),double,return -1);
831
832 switch ( psl->type ) {
833 case ( 1 ): case ( 2 ):
834 for (MMG5_int k=1; k<=psl->np; k++) {
835 MMG5_int iadr = k*psl->size;
836 ar->GetTuple ( k-1, &psl->m[iadr] );
837 }
838 break;
839
840 case ( 3 ):
841 // anisotropic sol
842 double dbuf[9];
843
844 for (MMG5_int k=1; k<=psl->np; k++) {
845 ar->GetTuple ( k-1, dbuf );
846 MMG5_int iadr = psl->size*k;
847
848 // Non symmetric tensor
849 if ( psl->dim ==2 ) {
850 psl->m[iadr] = dbuf[0];
851 psl->m[iadr+1] = dbuf[1];
852 psl->m[iadr+2] = dbuf[3];
853 psl->m[iadr+3] = dbuf[4];
854 }
855 else {
856 for ( int i=0 ; i<9 ; i++ ) {
857 psl->m[iadr+i] = dbuf[i];
858 }
859 }
860 }
861
862 break;
863 default:
864 fprintf(stderr," ** UNEXPECTED METRIC TYPE (%d). EXIT PROGRAM \n",psl->type);
865 return -1;
866 }
867
868 ++isol;
869 }
870 }
871 }
872 }
873
874
875 (*dataset)->Delete();
876
877 return 1;
878}
int MMG5_Set_inputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solin)
int ier
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
MMG5_pMesh char * filename
int MMG5_check_readedMesh(MMG5_pMesh mesh, MMG5_int nref)
Definition: inout.c:526
@ MMG5_Vertex
Definition: libmmgtypes.h:224
@ MMG5_Tetrahedron
Definition: libmmgtypes.h:227
#define MMG5_SAFE_CALLOC(ptr, size, type, law)
#define MG_NUL
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MMG5_FILESTR_LGTH
#define MG_REF
#define MMG5_DEL_MEM(mesh, ptr)
#define MMG5_SAFE_RECALLOC(ptr, prevSize, newSize, type, message, law)
Structure to store edges of a MMG mesh.
Definition: libmmgtypes.h:305
MMG5_int b
Definition: libmmgtypes.h:306
MMG5_int ref
Definition: libmmgtypes.h:307
int16_t tag
Definition: libmmgtypes.h:310
MMG5_int a
Definition: libmmgtypes.h:306
int8_t iso
Definition: libmmgtypes.h:534
MMG5_int isoref
Definition: libmmgtypes.h:521
MMG mesh structure.
Definition: libmmgtypes.h:605
MMG5_pQuad quadra
Definition: libmmgtypes.h:648
MMG5_Info info
Definition: libmmgtypes.h:651
MMG5_int ne
Definition: libmmgtypes.h:612
MMG5_pPoint point
Definition: libmmgtypes.h:641
MMG5_pPrism prism
Definition: libmmgtypes.h:645
MMG5_int nquad
Definition: libmmgtypes.h:613
MMG5_int nemax
Definition: libmmgtypes.h:612
MMG5_int npmax
Definition: libmmgtypes.h:612
MMG5_int nei
Definition: libmmgtypes.h:612
MMG5_pTetra tetra
Definition: libmmgtypes.h:643
MMG5_int nt
Definition: libmmgtypes.h:612
MMG5_pTria tria
Definition: libmmgtypes.h:647
MMG5_int np
Definition: libmmgtypes.h:612
MMG5_pEdge edge
Definition: libmmgtypes.h:649
MMG5_int nti
Definition: libmmgtypes.h:612
MMG5_int npi
Definition: libmmgtypes.h:612
MMG5_int nai
Definition: libmmgtypes.h:612
MMG5_int nprism
Definition: libmmgtypes.h:613
MMG5_int na
Definition: libmmgtypes.h:612
Structure to store points of a MMG mesh.
Definition: libmmgtypes.h:270
int16_t tag
Definition: libmmgtypes.h:284
MMG5_int tmp
Definition: libmmgtypes.h:280
double c[3]
Definition: libmmgtypes.h:271
MMG5_int ref
Definition: libmmgtypes.h:278
MMG5_int v[6]
Definition: libmmgtypes.h:463
MMG5_int ref
Definition: libmmgtypes.h:464
MMG5_int ref
Definition: libmmgtypes.h:368
MMG5_int v[4]
Definition: libmmgtypes.h:367
int entities
Definition: libmmgtypes.h:670
MMG5_int npmax
Definition: libmmgtypes.h:666
double * m
Definition: libmmgtypes.h:671
MMG5_int np
Definition: libmmgtypes.h:665
MMG5_int v[4]
Definition: libmmgtypes.h:403
MMG5_int ref
Definition: libmmgtypes.h:404
MMG5_int ref
Definition: libmmgtypes.h:335
MMG5_int v[3]
Definition: libmmgtypes.h:334
int MMG5_loadVtkMesh_part2(MMG5_pMesh mesh, MMG5_pSol *sol, vtkDataSet **dataset, int8_t ptMeditRef, int8_t eltMeditRef, int nsols)
Definition: vtkparser.cpp:346
int MMG5_loadVtpMesh_part1(MMG5_pMesh mesh, const char *filename, vtkDataSet **dataset, int8_t *ptMeditRef, int8_t *eltMeditRef, int *nsols, int8_t *metricData)
Definition: vtkparser.cpp:230
static int MMG5_count_vtkEntities(vtkDataSet *dataset, MMG5_pMesh mesh, int8_t *ptMeditRef, int8_t *eltMeditRef, int *nsols, int8_t *metricData)
Definition: vtkparser.cpp:100
int MMG5_loadVtuMesh_part1(MMG5_pMesh mesh, const char *filename, vtkDataSet **dataset, int8_t *ptMeditRef, int8_t *eltMeditRef, int *nsols, int8_t *metricData)
Definition: vtkparser.cpp:308
vtkDataSet * MMG5_load_vtkXMLFile(const char *fileName)
I/O at VTK format.
Definition: vtkparser.cpp:61
int MMG5_loadVtkMesh_part1(MMG5_pMesh mesh, const char *filename, vtkDataSet **dataset, int8_t *ptMeditRef, int8_t *eltMeditRef, int *nsols, int8_t *metricData)
Definition: vtkparser.cpp:269