1 // Copyright (C) 2010-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "vtkMedDriver30.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkStringArray.h"
24 #include "vtkDataArray.h"
25 #include "vtkIdTypeArray.h"
26 #include "vtkDoubleArray.h"
27 #include "vtkIntArray.h"
28 #include "vtkCharArray.h"
30 #include "vtkMedFile.h"
31 #include "vtkMedCartesianGrid.h"
32 #include "vtkMedPolarGrid.h"
33 #include "vtkMedCurvilinearGrid.h"
34 #include "vtkMedUnstructuredGrid.h"
35 #include "vtkMedField.h"
36 #include "vtkMedMesh.h"
37 #include "vtkMedFamily.h"
38 #include "vtkMedUtilities.h"
39 #include "vtkMedEntityArray.h"
40 #include "vtkMedLocalization.h"
41 #include "vtkMedProfile.h"
42 #include "vtkMedFieldOverEntity.h"
43 #include "vtkMedFieldStep.h"
44 #include "vtkMedGroup.h"
45 #include "vtkMedIntArray.h"
46 #include "vtkMedInterpolation.h"
47 #include "vtkMedFieldOnProfile.h"
48 #include "vtkMedFraction.h"
49 #include "vtkMedLink.h"
50 #include "vtkMedStructElement.h"
51 #include "vtkMedConstantAttribute.h"
52 #include "vtkMedVariableAttribute.h"
54 #include "vtkMultiProcessController.h"
61 // vtkCxxRevisionMacro(vtkMedDriver30, "$Revision$")
62 vtkStandardNewMacro(vtkMedDriver30)
64 vtkMedDriver30::vtkMedDriver30() : vtkMedDriver()
68 vtkMedDriver30::~vtkMedDriver30()
73 // load all Information data associated with this cartesian grid.
74 void vtkMedDriver30::ReadRegularGridInformation(vtkMedRegularGrid* grid)
78 grid->SetDimension(grid->GetParentMesh()->GetNumberOfAxis());
80 for(int axis=0; axis < grid->GetDimension(); axis++)
83 med_bool coordinatechangement, geotransformation;
85 if ((size = MEDmeshnEntity(
87 grid->GetParentMesh()->GetName(),
88 grid->GetComputeStep().TimeIt,
89 grid->GetComputeStep().IterationIt,
92 (med_data_type)(MED_COORDINATE_AXIS1 + axis),
94 &coordinatechangement,
95 &geotransformation)) < 0)
97 vtkErrorMacro("ERROR : number of coordinates on X axis ...");
100 grid->SetAxisSize(axis, size);
104 if(grid->GetAxisSize(0) > 1)
105 ncell *= grid->GetAxisSize(0)-1;
106 if(grid->GetAxisSize(1) > 1)
107 ncell *= grid->GetAxisSize(1)-1;
108 if(grid->GetAxisSize(2) > 1)
109 ncell *= grid->GetAxisSize(2)-1;
112 entity.EntityType = MED_CELL;
114 switch(grid->GetDimension())
117 entity.GeometryType = MED_POINT1;
120 entity.GeometryType = MED_SEG2;
123 entity.GeometryType = MED_QUAD4;
126 entity.GeometryType = MED_HEXA8;
129 vtkErrorMacro("Unsupported dimension for curvilinear grid : "
130 << grid->GetDimension());
134 vtkMedEntityArray* array = vtkMedEntityArray::New();
135 array->SetParentGrid(grid);
136 array->SetNumberOfEntity(ncell);
137 array->SetEntity(entity);
138 array->SetConnectivity(MED_NODAL);
139 grid->AppendEntityArray(array);
141 // this triggers the creation of undefined families
142 this->LoadFamilyIds(array);
146 void vtkMedDriver30::LoadRegularGridCoordinates(vtkMedRegularGrid* grid)
150 for(int axis=0; axis < grid->GetParentMesh()->GetNumberOfAxis(); axis++)
153 vtkDataArray* coords = vtkMedUtilities::NewCoordArray();
154 grid->SetAxisCoordinate(axis, coords);
157 coords->SetNumberOfComponents(1);
158 coords->SetNumberOfTuples(grid->GetAxisSize(axis));
160 if (MEDmeshGridIndexCoordinateRd(
162 grid->GetParentMesh()->GetName(),
163 grid->GetComputeStep().TimeIt,
164 grid->GetComputeStep().IterationIt,
166 (med_float*)coords->GetVoidPointer(0)) < 0)
168 vtkErrorMacro("ERROR : read axis " << axis << " coordinates ...");
169 grid->SetAxisCoordinate(axis, NULL);
177 // load all Information data associated with this standard grid.
178 void vtkMedDriver30::ReadCurvilinearGridInformation(vtkMedCurvilinearGrid* grid)
182 grid->SetDimension(grid->GetParentMesh()->GetNumberOfAxis());
185 med_bool coordinatechangement, geotransformation;
187 if ((size = MEDmeshnEntity(
189 grid->GetParentMesh()->GetName(),
190 grid->GetComputeStep().TimeIt,
191 grid->GetComputeStep().IterationIt,
196 &coordinatechangement,
197 &geotransformation)) < 0)
199 vtkErrorMacro("ReadCurvilinearGridInformation MEDmeshnEntity");
202 grid->SetNumberOfPoints(size);
206 if(MEDmeshGridStructRd(
208 grid->GetParentMesh()->GetName(),
209 grid->GetComputeStep().TimeIt,
210 grid->GetComputeStep().IterationIt,
213 vtkErrorMacro("ReadCurvilinearGridInformation MEDmeshGridStructRd");
216 switch(grid->GetDimension())
221 grid->SetAxisSize(0, (axissize[0] <= 0 ? 1: axissize[0]));
224 grid->SetAxisSize(0, (axissize[0] <= 0 ? 1: axissize[0]));
225 grid->SetAxisSize(1, (axissize[1] <= 0 ? 1: axissize[1]));
228 grid->SetAxisSize(0, (axissize[0] <= 0 ? 1: axissize[0]));
229 grid->SetAxisSize(1, (axissize[1] <= 0 ? 1: axissize[1]));
230 grid->SetAxisSize(2, (axissize[2] <= 0 ? 1: axissize[2]));
233 vtkErrorMacro("Unsupported dimension for curvilinear grid : "
234 << grid->GetDimension());
238 // A test to verify the number of points : total number of
239 // points should be equal to the product of each axis size
242 if (grid->GetDimension() == 1)
244 size2 = grid->GetAxisSize(0);
247 if (grid->GetDimension() == 2)
249 size2 = grid->GetAxisSize(0)*grid->GetAxisSize(1);
252 if (grid->GetDimension() == 3)
254 size2 = grid->GetAxisSize(0)*grid->GetAxisSize(1)*grid->GetAxisSize(2);
259 vtkErrorMacro("The total number of points of a Curvilinear grid should "
260 << "be the product of each axis size!");
264 if ((grid->GetDimension() >= 1) && (grid->GetAxisSize(0) > 1))
265 ncell *= grid->GetAxisSize(0)-1;
266 if ((grid->GetDimension() >= 2) && (grid->GetAxisSize(1) > 1))
267 ncell *= grid->GetAxisSize(1)-1;
268 if ((grid->GetDimension() >= 3) && (grid->GetAxisSize(2) > 1))
269 ncell *= grid->GetAxisSize(2)-1;
272 entity.EntityType = MED_CELL;
274 switch(grid->GetDimension())
277 entity.GeometryType = MED_POINT1;
280 entity.GeometryType = MED_SEG2;
283 entity.GeometryType = MED_QUAD4;
286 entity.GeometryType = MED_HEXA8;
289 vtkErrorMacro("Unsupported dimension for curvilinear grid : "
290 << grid->GetDimension());
294 vtkMedEntityArray* array = vtkMedEntityArray::New();
295 array->SetParentGrid(grid);
296 array->SetNumberOfEntity(ncell);
297 array->SetEntity(entity);
298 array->SetConnectivity(MED_NODAL);
299 grid->AppendEntityArray(array);
301 // this triggers the creation of undefined families
302 this->LoadFamilyIds(array);
305 // Description : read the number of entity of all geometry type
306 // for a given entity type and a given connectivity mode
307 void vtkMedDriver30::ReadNumberOfEntity(
308 vtkMedUnstructuredGrid* grid,
309 med_entity_type entityType,
310 med_connectivity_mode connectivity)
314 med_bool changement, transformation;
316 const char* meshName = grid->GetParentMesh()->GetName();
318 const vtkMedComputeStep& cs = grid->GetComputeStep();
320 med_int nentity = MEDmeshnEntity(
332 for(med_int geotypeit = 1; geotypeit <= nentity; geotypeit++)
334 // read cell informations
336 entity.EntityType = entityType;
338 char geometryName[MED_NAME_SIZE+1] = "";
340 // this gives us the med_geometry_type
341 if( MEDmeshEntityInfo( FileId, meshName,
347 &entity.GeometryType) < 0)
349 vtkErrorMacro("MEDmeshEntityInfo");
353 entity.GeometryName = geometryName;
356 if(entity.GeometryType == MED_POLYGON)
358 // read the number of cells of this type
359 ncell = MEDmeshnEntity(this->FileId,
368 &transformation ) - 1;
370 else if(entity.GeometryType == MED_POLYHEDRON)
372 // read the number of cells of this type
373 ncell = MEDmeshnEntity(this->FileId,
382 &transformation ) - 1;
386 ncell = MEDmeshnEntity(this->FileId,
400 vtkMedEntityArray* array = vtkMedEntityArray::New();
401 array->SetParentGrid(grid);
402 array->SetNumberOfEntity(ncell);
403 array->SetEntity(entity);
404 array->SetConnectivity(connectivity);
405 grid->AppendEntityArray(array);
407 // this triggers the creation of undefined families
408 this->LoadFamilyIds(array);
414 // load all Information data associated with this unstructured grid.
415 void vtkMedDriver30::ReadUnstructuredGridInformation(
416 vtkMedUnstructuredGrid* grid)
420 vtkMedMesh *mesh = grid->GetParentMesh();
422 const char *meshName = mesh->GetName();
423 med_connectivity_mode connectivity;
426 med_bool transformation;
429 char profilename[MED_NAME_SIZE+1];
430 memset(profilename, '\0', MED_NAME_SIZE+1);
432 vtkMedComputeStep cs = grid->GetComputeStep();
434 // first check if we have points
435 vtkIdType npoints = MEDmeshnEntityWithProfile(
452 grid->SetNumberOfPoints(npoints);
456 if(grid->GetPreviousGrid() == NULL)
458 vtkErrorMacro("No point and no previous grid");
460 grid->SetUsePreviousCoordinates(true);
461 grid->SetNumberOfPoints(grid->GetPreviousGrid()->GetNumberOfPoints());
465 this->ReadNumberOfEntity(grid, MED_CELL, MED_NODAL);
466 this->ReadNumberOfEntity(grid, MED_CELL, MED_DESCENDING);
467 this->ReadNumberOfEntity(grid, MED_DESCENDING_FACE, MED_NODAL);
468 this->ReadNumberOfEntity(grid, MED_DESCENDING_FACE, MED_DESCENDING);
469 this->ReadNumberOfEntity(grid, MED_DESCENDING_EDGE, MED_NODAL);
470 this->ReadNumberOfEntity(grid, MED_DESCENDING_EDGE, MED_DESCENDING);
471 this->ReadNumberOfEntity(grid, MED_STRUCT_ELEMENT, MED_NODAL);
472 this->ReadNumberOfEntity(grid, MED_STRUCT_ELEMENT, MED_DESCENDING);
474 // create the point vtkMedEntityArray support
476 entity.EntityType = MED_NODE;
477 entity.GeometryType = MED_POINT1;
478 vtkMedEntityArray* pea = vtkMedEntityArray::New();
479 pea->SetEntity(entity);
480 pea->SetParentGrid(grid);
481 pea->SetNumberOfEntity(grid->GetNumberOfPoints());
482 grid->AppendEntityArray(pea);
485 this->LoadFamilyIds(pea);
488 void vtkMedDriver30::ReadFamilyInformation(vtkMedMesh* mesh, vtkMedFamily* family)
494 char* groupNames = NULL;
495 const char* meshName = mesh->GetName();
497 ngroup = MEDnFamilyGroup(FileId, meshName, family->GetMedIterator());
499 bool has_no_group = false;
504 vtkErrorMacro("Error while reading the number of groups");
510 groupNames = new char[ngroup * MED_LNAME_SIZE + 1];
511 memset(groupNames, '\0', ngroup * MED_LNAME_SIZE + 1);
513 // special case for files written by med < 3,
514 // I have to use the 23 interface
515 if(mesh->GetParentFile()->GetVersionMajor() < 3)
517 med_int *attributenumber = NULL;
518 med_int *attributevalue = NULL;
519 char *attributedes = NULL;
521 med_int nattr = MEDnFamily23Attribute(
524 family->GetMedIterator());
528 vtkErrorMacro("MEDnFamily23Attribute");
533 attributenumber = new med_int[nattr];
534 attributevalue = new med_int[nattr];
535 attributedes = new char[nattr*MED_COMMENT_SIZE+1];
536 memset(attributedes, '\0', nattr*MED_COMMENT_SIZE+1);
539 char familyName[MED_NAME_SIZE+1] = "";
541 if(MEDfamily23Info (this->FileId,
543 family->GetMedIterator(),
551 vtkDebugMacro("MEDfamily23Info");
554 family->SetName(familyName);
556 if(attributenumber != NULL)
557 delete[] attributenumber;
558 if(attributevalue != NULL)
559 delete[] attributevalue;
560 if(attributedes != NULL)
561 delete[] attributedes;
565 char familyName[MED_NAME_SIZE+1] = "";
566 if(MEDfamilyInfo( this->FileId,
568 family->GetMedIterator(),
574 "vtkMedDriver30::ReadInformation(vtkMedFamily* family)"
575 << " cannot read family informations.");
578 family->SetName(familyName);
581 family->SetId(familyid);
583 // Fix for the issue "0021721: [CEA 590] Invalid groups on cells
584 if( familyid == 0 ) {
585 family->SetPointOrCell( vtkMedUtilities::OnCell );
586 mesh->AppendCellFamily( family );
588 //rnv: improve algorithm to determine entity of the family:
590 // 2) Read families of the nodes
591 // 3) If list of the families of the nodes contains familyid => vtkMedUtilities::OnPoint
592 // otherwise => vtkMedUtilities::OnCell
594 med_int size = MEDmeshnEntity(
606 vtkErrorMacro( "vtkMedDriver30::ReadInformation(vtkMedFamily* family)"
607 <<" cannot read nb Nodes" );
611 vector<med_int> n_fams;
612 n_fams.resize( size );
614 med_int ret_val = MEDmeshEntityFamilyNumberRd( this->FileId,
621 // Remove ZERO FAMILY
622 remove( n_fams.begin(),n_fams.end(), 0 );
624 bool isOnPoints = ( ret_val >= 0) && (find( n_fams.begin(), n_fams.end(), familyid ) != n_fams.end() );
626 family->SetPointOrCell(vtkMedUtilities::OnPoint);
627 mesh->AppendPointFamily(family);
629 family->SetPointOrCell(vtkMedUtilities::OnCell);
630 mesh->AppendCellFamily(family);
634 family->AllocateNumberOfGroup(ngroup);
635 // if there where no group, set the name to the default value
638 memcpy(groupNames, vtkMedUtilities::NoGroupName,
639 strlen(vtkMedUtilities::NoGroupName));
642 for(int index = 0; index < ngroup; index++)
644 char realGroupName[MED_LNAME_SIZE + 1];
645 memset(realGroupName, '\0', MED_LNAME_SIZE + 1);
646 memcpy(realGroupName, groupNames + index * MED_LNAME_SIZE,
647 MED_LNAME_SIZE * sizeof(char));
648 vtkMedGroup* group = mesh->GetOrCreateGroup(family->GetPointOrCell(),
651 family->SetGroup(index, group);
658 vtkMedFamily* famzero = vtkMedFamily::New();
659 mesh->AppendPointFamily(famzero);
662 famzero->SetName(family->GetName());
663 famzero->SetMedIterator(family->GetMedIterator());
664 famzero->SetId(family->GetId());
665 famzero->SetPointOrCell(vtkMedUtilities::OnPoint);
666 famzero->AllocateNumberOfGroup(family->GetNumberOfGroup());
667 for(int gid=0; gid<family->GetNumberOfGroup(); gid++)
669 vtkMedGroup* group = mesh->GetOrCreateGroup(
670 vtkMedUtilities::OnPoint,
671 family->GetGroup(gid)->GetName());
672 famzero->SetGroup(gid, group);
673 mesh->AppendPointGroup(group);
678 void vtkMedDriver30::ReadLinkInformation(vtkMedLink* link)
681 char linkMeshName[MED_NAME_SIZE+1] = "";
682 if(MEDlinkInfo(this->FileId,
683 link->GetMedIterator(),
687 vtkErrorMacro("MEDlinkInfo");
690 link->SetMeshName(linkMeshName);
694 char* path = new char[size + 1];
695 memset(path, '\0', size+1);
696 if(MEDlinkRd(this->FileId, link->GetMeshName(), path) < 0)
698 vtkErrorMacro("MEDlinkRd");
699 memset(path, '\0', size+1);
707 void vtkMedDriver30::ReadFileInformation(vtkMedFile* file)
711 char comment[MED_COMMENT_SIZE+1] = "";
713 MEDfileCommentRd(this->FileId,
716 file->SetComment(comment);
718 med_int major, minor, release;
719 MEDfileNumVersionRd(this->FileId, &major, &minor, &release);
720 file->SetVersionMajor(major);
721 file->SetVersionMinor(minor);
722 file->SetVersionRelease(release);
724 int nlink = MEDnLink(this->FileId);
725 file->AllocateNumberOfLink(nlink);
726 for(int linkid=0; linkid<nlink; linkid++)
728 vtkMedLink* link = file->GetLink(linkid);
729 link->SetMedIterator(linkid+1);
730 this->ReadLinkInformation(link);
733 int nprof = MEDnProfile(FileId);
734 // Reading id s not possible in parallel if the file contains Profiles
735 vtkMultiProcessController* controller = vtkMultiProcessController::GetGlobalController();
736 if (controller != NULL)
737 if ((nprof != 0) && (controller->GetNumberOfProcesses() > 1))
739 vtkWarningMacro("ATTENTION: The MED Reader cannot read profiles when used in parallel");
742 file->AllocateNumberOfProfile(nprof);
743 for(int i = 0; i < nprof; i++)
745 vtkMedProfile* profile = file->GetProfile(i);
746 profile->SetMedIterator(i + 1);
747 profile->SetParentFile(file);
748 this->ReadProfileInformation(profile);
751 int nloc = MEDnLocalization(this->FileId);
752 file->AllocateNumberOfLocalization(nloc);
753 for(int i = 0; i < nloc; i++)
755 vtkMedLocalization* loc = file->GetLocalization(i);
756 loc->SetMedIterator(i + 1);
757 loc->SetParentFile(file);
758 this->ReadLocalizationInformation(loc);
761 int nsupportmesh = MEDnSupportMesh(this->FileId);
762 file->AllocateNumberOfSupportMesh(nsupportmesh);
763 for(int i = 0; i < nsupportmesh; i++)
765 vtkMedMesh* supportmesh = file->GetSupportMesh(i);
766 supportmesh->SetMedIterator(i + 1);
767 supportmesh->SetParentFile(file);
768 this->ReadSupportMeshInformation(supportmesh);
771 int nmesh = MEDnMesh(this->FileId);
772 file->AllocateNumberOfMesh(nmesh);
773 for(int i = 0; i < nmesh; i++)
775 vtkMedMesh* mesh = file->GetMesh(i);
776 mesh->SetMedIterator(i + 1);
777 mesh->SetParentFile(file);
778 this->ReadMeshInformation(mesh);
781 int nfields = MEDnField(this->FileId);
782 file->AllocateNumberOfField(nfields);
783 for(int i = 0; i < nfields; i++)
785 vtkMedField* field = file->GetField(i);
786 field->SetMedIterator(i + 1);
787 field->SetParentFile(file);
788 this->ReadFieldInformation(field);
789 field->ComputeFieldType();
790 while(field->HasManyFieldTypes())
792 vtkMedField* newfield = vtkMedField::New();
793 int type = field->GetFirstType();
794 newfield->ExtractFieldType(field, type);
795 file->AppendField(newfield);
800 int nstruct = MEDnStructElement(this->FileId);
802 file->AllocateNumberOfStructElement(nstruct);
803 for(int i = 0; i < nstruct; i++)
805 vtkMedStructElement* structelem = file->GetStructElement(i);
806 structelem->SetMedIterator(i+1);
807 structelem->SetParentFile(file);
808 this->ReadStructElementInformation(structelem);
813 void vtkMedDriver30::ReadStructElementInformation(
814 vtkMedStructElement* structelem)
819 char modelname[MED_NAME_SIZE+1] = "";
820 med_geometry_type mgeotype;
822 char supportmeshname[MED_NAME_SIZE+1] = "";
823 med_entity_type sentitytype;
826 med_geometry_type sgeotype;
827 med_int nbofconstantattribute;
829 med_int nbofvariableattribute;
831 if(MEDstructElementInfo (this->FileId,
832 structelem->GetMedIterator(),
841 &nbofconstantattribute,
843 &nbofvariableattribute) < 0)
845 vtkErrorMacro("Error in MEDstructElementInfo");
848 structelem->SetName(modelname);
849 structelem->SetGeometryType(mgeotype);
850 structelem->SetModelDimension(modeldim);
851 structelem->SetSupportMeshName(supportmeshname);
852 structelem->SetSupportEntityType(sentitytype);
853 structelem->SetSupportNumberOfNode(snbofnode);
854 structelem->SetSupportNumberOfCell(snbofcell);
855 structelem->SetSupportGeometryType(sgeotype);
856 structelem->AllocateNumberOfConstantAttribute(nbofconstantattribute);
857 structelem->AllocateNumberOfVariableAttribute(nbofvariableattribute);
858 structelem->SetAnyProfile(anyprofile);
860 for(int attit = 0; attit < nbofconstantattribute; attit ++)
862 vtkMedConstantAttribute* constatt = structelem->GetConstantAttribute(attit);
863 constatt->SetMedIterator(attit+1);
864 constatt->SetParentStructElement(structelem);
865 this->ReadConstantAttributeInformation(constatt);
868 for(int attit = 0; attit < nbofvariableattribute; attit ++)
870 vtkMedVariableAttribute* varatt = structelem->GetVariableAttribute(attit);
871 varatt->SetMedIterator(attit+1);
872 varatt->SetParentStructElement(structelem);
873 this->ReadVariableAttributeInformation(varatt);
877 void vtkMedDriver30::ReadConstantAttributeInformation(
878 vtkMedConstantAttribute* constAttr)
883 char constattname[MED_NAME_SIZE+1] = "";
884 med_attribute_type constatttype;
885 med_int nbofcomponent;
886 med_entity_type sentitytype;
887 char profilename[MED_NAME_SIZE+1] = "";
890 if(MEDstructElementConstAttInfo(
892 constAttr->GetParentStructElement()->GetName(),
893 constAttr->GetMedIterator(),
901 vtkErrorMacro("MEDstructElementConstAttInfo error");
905 constAttr->SetName(constattname);
906 constAttr->SetAttributeType(constatttype);
907 constAttr->SetNumberOfComponent(nbofcomponent);
908 constAttr->SetSupportEntityType(sentitytype);
909 constAttr->SetProfileName(profilename);
910 constAttr->SetProfileSize(profilesize);
912 vtkAbstractArray* values = vtkMedUtilities::NewArray(constatttype);
915 constAttr->SetValues(values);
918 values->SetNumberOfComponents(nbofcomponent);
919 vtkIdType ntuple = 0;
920 if((strcmp(profilename, MED_NO_PROFILE) != 0) &&
921 (strcmp(profilename, "\0") != 0))
923 ntuple = profilesize;
925 else if(constAttr->GetSupportEntityType() == MED_CELL)
927 ntuple = constAttr->GetParentStructElement()->GetSupportNumberOfCell();
931 ntuple = constAttr->GetParentStructElement()->GetSupportNumberOfNode();
933 values->SetNumberOfTuples(ntuple);
936 vtkSmartPointer<vtkCharArray> buffer = vtkSmartPointer<vtkCharArray>::New();
937 if(constatttype != MED_ATT_NAME)
939 ptr = values->GetVoidPointer(0);
943 buffer->SetNumberOfValues(MED_NAME_SIZE*nbofcomponent*ntuple);
944 ptr = buffer->GetVoidPointer(0);
947 if(MEDstructElementConstAttRd (this->FileId,
948 constAttr->GetParentStructElement()->GetName(),
949 constAttr->GetName(), ptr) < 0)
951 vtkErrorMacro("MEDstructElementConstAttRd");
955 if(constatttype == MED_ATT_NAME)
957 char name[MED_NAME_SIZE+1] = "";
958 char* nameptr = (char*) ptr;
959 vtkStringArray* names = vtkStringArray::SafeDownCast(values);
960 for(vtkIdType id = 0; id < nbofcomponent*ntuple; id++)
962 memset(name, '\0', MED_NAME_SIZE+1);
963 strncpy(name, nameptr + id * MED_NAME_SIZE, MED_NAME_SIZE);
964 names->SetValue(id, name);
971 void vtkMedDriver30::ReadVariableAttributeInformation(
972 vtkMedVariableAttribute* varAttr)
977 char varattname[MED_NAME_SIZE+1] = "";
978 med_attribute_type varatttype;
979 med_int nbofcomponent;
981 if(MEDstructElementVarAttInfo (
983 varAttr->GetParentStructElement()->GetName(),
984 varAttr->GetMedIterator(),
989 vtkErrorMacro("MEDstructElementVarAttInfo");
993 varAttr->SetName(varattname);
994 varAttr->SetAttributeType(varatttype);
995 varAttr->SetNumberOfComponent(nbofcomponent);
1000 void vtkMedDriver30::ReadProfileInformation(vtkMedProfile* profile)
1002 FileOpen open(this);
1005 char profileName[MED_NAME_SIZE+1] = "";
1007 if(MEDprofileInfo(this->FileId,
1008 profile->GetMedIterator(),
1012 vtkErrorMacro("cannot read information on profile"
1013 << profile->GetMedIterator());
1015 profile->SetName(profileName);
1016 profile->SetNumberOfElement(nelem);
1019 void vtkMedDriver30::ReadFieldInformation(vtkMedField* field)
1021 FileOpen open(this);
1023 if (field->GetMedIterator() == 0)
1026 int ncomp = MEDfieldnComponent(FileId, field->GetMedIterator());
1030 field->SetNumberOfComponent(-1);
1031 vtkErrorMacro("cannot read the number of component of field "
1032 << field->GetMedIterator())
1036 field->SetNumberOfComponent(ncomp);
1038 char* units = new char[MED_SNAME_SIZE * ncomp + 1];
1039 char* componentNames = new char[MED_SNAME_SIZE * ncomp + 1];
1040 memset(units, '\0', MED_SNAME_SIZE * ncomp + 1);
1041 memset(componentNames, '\0', MED_SNAME_SIZE * ncomp + 1);
1043 //med_type_champ dataType;
1044 med_field_type dataType;
1048 char name[MED_NAME_SIZE+1] = "";
1049 char meshName[MED_NAME_SIZE+1] = "";
1050 char unit[MED_SNAME_SIZE+1] = "";
1052 if( MEDfieldInfo( FileId,
1053 field->GetMedIterator(),
1063 vtkErrorMacro("cannot read the informations on field "
1064 << field->GetMedIterator())
1068 field->SetName(name);
1069 field->SetMeshName(meshName);
1070 field->SetTimeUnit(unit);
1071 field->SetDataType(dataType);
1072 field->SetLocal(localmesh);
1074 for(int comp = 0; comp < ncomp; comp++)
1076 char unit[MED_NAME_SIZE + 1] = "";
1077 memcpy(unit, units + MED_SNAME_SIZE * comp, MED_SNAME_SIZE * sizeof(char));
1078 field->GetUnit()->SetValue(comp, unit);
1080 char compName[MED_SNAME_SIZE + 1] = "";
1081 memcpy(compName, componentNames + MED_SNAME_SIZE * comp, MED_SNAME_SIZE
1083 field->GetComponentName()->SetValue(comp, compName);
1087 delete[] componentNames;
1089 med_int ninterp = MEDfieldnInterp(FileId, field->GetName());
1092 vtkErrorMacro("Error in MEDfieldnInterp");
1096 field->AllocateNumberOfInterpolation(ninterp);
1098 for(med_int interpit=0; interpit<ninterp; interpit++)
1100 vtkMedInterpolation* interp = field->GetInterpolation(interpit);
1101 interp->SetMedIterator(interpit + 1);
1102 this->ReadInterpolationInformation(interp);
1105 vtkMedFieldStep* previousStep = NULL;
1107 for(med_int csit = 0; csit < nstep; csit++)
1109 vtkMedFieldStep* step = vtkMedFieldStep::New();
1110 step->SetMedIterator(csit + 1);
1111 step->SetParentField(field);
1112 this->ReadFieldStepInformation(step, csit == 0);
1113 field->AddFieldStep(step);
1114 step->SetPreviousStep(previousStep);
1115 previousStep = step;
1120 void vtkMedDriver30::ReadFieldStepInformation(vtkMedFieldStep* step, bool readAllEntityInfo)
1122 vtkMedComputeStep cs;
1123 vtkMedComputeStep meshcs;
1124 vtkMedField* field = step->GetParentField();
1126 FileOpen open(this);
1128 if( MEDfieldComputingStepMeshInfo(
1131 step->GetMedIterator(),
1134 &cs.TimeOrFrequency,
1136 &meshcs.IterationIt) < 0)
1138 vtkErrorMacro("Error in MEDfieldComputingStepMeshInfo");
1142 step->SetComputeStep(cs);
1143 step->SetMeshComputeStep(meshcs);
1145 if(!readAllEntityInfo || step->GetEntityInfoLoaded())
1148 step->SetEntityInfoLoaded(1);
1150 vtkMedFile* file = field->GetParentFile();
1151 vtkMedMesh* mesh = file->GetMesh(field->GetMeshName());
1156 //rnv begin: fix the "22335: [CEA 954] Paravis 7.2.0 doesn't read ELNO fields" regression.
1157 // this piece of code needed for the reading ELNO fields
1158 std::set<vtkMedEntity> tmp_entities;
1159 std::set<vtkMedEntity> entities;
1160 mesh->GatherMedEntities(tmp_entities);
1162 std::set<vtkMedEntity>::iterator tmp_entity_it = tmp_entities.begin();
1163 while(tmp_entity_it != tmp_entities.end())
1165 vtkMedEntity entity = *tmp_entity_it;
1167 entities.insert(entity);
1168 if(entity.EntityType == MED_CELL)
1170 vtkMedEntity newEntity;
1171 newEntity.EntityType = MED_NODE_ELEMENT;
1172 newEntity.GeometryType = entity.GeometryType;
1173 newEntity.GeometryName = entity.GeometryName;
1174 entities.insert(newEntity);
1179 std::set<vtkMedEntity>::iterator entity_it = entities.begin();
1180 while(entity_it != entities.end())
1182 vtkMedEntity entity = *entity_it;
1185 med_int nvalues = 0;
1187 char profilename[MED_NAME_SIZE+1] = "";
1188 char localizationname[MED_NAME_SIZE+1] = "";
1190 nprofile = MEDfieldnProfile(
1193 step->GetComputeStep().TimeIt,
1194 step->GetComputeStep().IterationIt,
1196 entity.GeometryType,
1201 vtkErrorMacro("MEDfieldnProfile");
1205 bool hasprofile = (nprofile > 0);
1211 med_int profilesize;
1212 med_int nintegrationpoint;
1214 for(int pid=0; pid<nprofile; pid++)
1216 med_int medid = (hasprofile ? pid+1 : -1);
1217 nvalues = MEDfieldnValueWithProfile(
1220 step->GetComputeStep().TimeIt,
1221 step->GetComputeStep().IterationIt,
1223 entity.GeometryType,
1225 MED_COMPACT_PFLMODE,
1229 &nintegrationpoint);
1233 vtkErrorMacro("MEDfieldnValueWithProfile");
1236 else if(nvalues > 0)
1238 // I have found a profile with values, stop the loop here
1245 vtkMedFieldOverEntity* fieldOverEntity = vtkMedFieldOverEntity::New();
1246 step->AppendFieldOverEntity(fieldOverEntity);
1247 fieldOverEntity->Delete();
1249 fieldOverEntity->SetParentStep(step);
1250 fieldOverEntity->SetEntity(entity);
1252 this->ReadFieldOverEntityInformation(fieldOverEntity);
1257 void vtkMedDriver30::ReadFieldOverEntityInformation(vtkMedFieldOverEntity* fieldOverEntity)
1259 FileOpen open(this);
1261 vtkMedFieldStep* step = fieldOverEntity->GetParentStep();
1262 vtkMedField* field = step->GetParentField();
1263 vtkMedEntity entity = fieldOverEntity->GetEntity();
1265 const char* fieldName = field->GetName();
1266 const vtkMedComputeStep& cs = step->GetComputeStep();
1268 char profilename[MED_NAME_SIZE+1] = "";
1269 char localizationname[MED_NAME_SIZE+1] = "";
1271 med_int nProfiles = MEDfieldnProfile(
1277 entity.GeometryType,
1283 vtkErrorMacro("MEDfieldnProfile");
1285 else if(nProfiles == 0)
1287 fieldOverEntity->SetHasProfile(0);
1292 fieldOverEntity->SetHasProfile(1);
1294 fieldOverEntity->AllocateNumberOfFieldOnProfile(nProfiles);
1295 for(int profit = 0; profit < nProfiles; profit++)
1297 vtkMedFieldOnProfile* fop = fieldOverEntity->GetFieldOnProfile(profit);
1298 med_int medid = (fieldOverEntity->GetHasProfile()? profit+1: -1);
1299 fop->SetMedIterator(medid);
1300 fop->SetParentFieldOverEntity(fieldOverEntity);
1301 this->ReadFieldOnProfileInformation(fop);
1305 void vtkMedDriver30::ReadFieldOnProfileInformation(vtkMedFieldOnProfile* fop)
1307 vtkMedFieldOverEntity* fieldOverEntity = fop->GetParentFieldOverEntity();
1308 vtkMedFieldStep* step = fieldOverEntity->GetParentStep();
1309 vtkMedField* field = step->GetParentField();
1311 const vtkMedComputeStep& cs = step->GetComputeStep();
1312 med_int profilesize;
1313 med_int nbofintegrationpoint;
1315 char profileName[MED_NAME_SIZE+1] = "";
1316 char localizationName[MED_NAME_SIZE+1] = "";
1318 med_int nvalue = MEDfieldnValueWithProfile(FileId,
1322 fieldOverEntity->GetEntity().EntityType,
1323 fieldOverEntity->GetEntity().GeometryType,
1324 fop->GetMedIterator(),
1329 &nbofintegrationpoint);
1333 vtkErrorMacro("Error while reading MEDfieldnValueWithProfile");
1336 fop->SetProfileName(profileName);
1337 fop->SetLocalizationName(localizationName);
1338 fop->SetNumberOfValues(nvalue);
1339 fop->SetNumberOfIntegrationPoint(nbofintegrationpoint);
1340 fop->SetProfileSize(profilesize);
1343 void vtkMedDriver30::ReadMeshInformation(vtkMedMesh* mesh)
1345 FileOpen open(this);
1349 med_mesh_type meshtype;
1351 med_sorting_type sortingtype;
1353 med_axis_type axistype;
1356 if ( (naxis=MEDmeshnAxis(this->FileId, mesh->GetMedIterator())) <0 )
1358 vtkDebugMacro("Error reading mesh axis number");
1362 naxis=MEDmeshnAxis(this->FileId, mesh->GetMedIterator());
1364 char axisname[3*MED_SNAME_SIZE+1] = "";
1365 char axisunit[3*MED_SNAME_SIZE+1] = "";
1366 char name[MED_NAME_SIZE+1] = "";
1367 char description[MED_COMMENT_SIZE+1] = "";
1368 char timeUnit[MED_SNAME_SIZE+1] = "";
1370 if( MEDmeshInfo( this->FileId,
1371 mesh->GetMedIterator(),
1384 vtkErrorMacro("Error reading mesh");
1387 mesh->SetName(name);
1388 mesh->SetDescription(description);
1389 mesh->SetTimeUnit(timeUnit);
1390 mesh->SetSpaceDimension(sdim);
1391 mesh->SetMeshDimension(mdim);
1392 mesh->SetMeshType(meshtype);
1393 mesh->SetSortingType(sortingtype);
1394 mesh->SetAxisType(axistype);
1395 mesh->SetNumberOfAxis(naxis);
1397 for(int axis = 0; axis < naxis; axis++)
1399 char theaxisname[MED_SNAME_SIZE+1] = "";
1400 char theaxisunit[MED_SNAME_SIZE+1] = "";
1401 strncpy(theaxisname, axisname + axis*MED_SNAME_SIZE, MED_SNAME_SIZE);
1402 strncpy(theaxisunit, axisunit + axis*MED_SNAME_SIZE, MED_SNAME_SIZE);
1403 mesh->GetAxisName()->SetValue(axis, theaxisname);
1404 mesh->GetAxisUnit()->SetValue(axis, theaxisunit);
1407 char universalName[MED_LNAME_SIZE+1] = "";
1409 if(MEDmeshUniversalNameRd(this->FileId, name,
1412 vtkDebugMacro("MEDmeshUniversalNameRd < 0");
1414 mesh->SetUniversalName(universalName);
1416 // read the Information data of all families.
1417 // writing the family 0 is optional,
1418 // but I need it, so add it if it is not here.
1420 med_int nfam = MEDnFamily(this->FileId, name);
1422 for(int index = 0; index < nfam; index++)
1424 vtkMedFamily* family = vtkMedFamily::New();
1425 family->SetMedIterator(index + 1);
1426 this->ReadFamilyInformation(mesh, family);
1430 // this creates a family 0 if none has been read
1431 vtkMedFamily* familyZeroOnCell = mesh->GetOrCreateCellFamilyById(0);
1432 vtkMedFamily* familyZeroOnPoint = mesh->GetOrCreatePointFamilyById(0);
1434 // Load Information regarding the grid type
1435 if(meshtype == MED_STRUCTURED_MESH)
1437 // Do it for structured data
1439 if(MEDmeshGridTypeRd(FileId, name, &mtg) < 0)
1441 vtkErrorMacro("Error during structured grid Information loading.");
1444 mesh->SetStructuredGridType(mtg);
1447 vtkMedGrid* previousGrid = NULL;
1448 for(int gid=1; gid <= nstep; gid++)
1450 vtkMedComputeStep cs;
1451 if(MEDmeshComputationStepInfo(FileId,
1456 &cs.TimeOrFrequency) < 0)
1458 vtkErrorMacro("MEDmeshComputationStepInfo error");
1460 // Load Information regarding the grid type
1461 vtkMedGrid* grid = NULL;
1462 if(meshtype == MED_STRUCTURED_MESH)
1464 switch(mesh->GetStructuredGridType())
1466 case MED_CARTESIAN_GRID:
1467 grid = vtkMedCartesianGrid::New();
1469 case MED_POLAR_GRID:
1470 grid = vtkMedPolarGrid::New();
1472 case MED_CURVILINEAR_GRID:
1473 grid = vtkMedCurvilinearGrid::New();
1476 vtkErrorMacro("Unknown structured grid type " << mesh->GetStructuredGridType());
1480 else //(mesh->GetType() == MED_STRUCTURED_MESH)
1482 grid = vtkMedUnstructuredGrid::New();
1484 grid->SetParentMesh(mesh);
1485 grid->SetComputeStep(cs);
1486 this->ReadGridInformation(grid);
1487 mesh->AddGridStep(grid);
1489 grid->SetPreviousGrid(previousGrid);
1490 previousGrid = grid;
1494 void vtkMedDriver30::ReadLocalizationInformation(vtkMedLocalization* loc)
1496 FileOpen open(this);
1499 med_int spaceDimension;
1500 med_geometry_type type_geo;
1501 med_geometry_type sectiongeotype;
1502 med_int nsectionmeshcell;
1504 char name[MED_NAME_SIZE+1] = "";
1505 char interpolationName[MED_NAME_SIZE+1] = "";
1506 char sectionName[MED_NAME_SIZE+1] = "";
1508 if(MEDlocalizationInfo(
1510 loc->GetMedIterator(),
1518 §iongeotype ) < 0)
1520 vtkErrorMacro("Reading information on quadrature points definition : "
1521 << loc->GetMedIterator());
1525 loc->SetInterpolationName(interpolationName);
1526 loc->SetSectionName(sectionName);
1527 loc->SetNumberOfQuadraturePoint(ngp);
1528 loc->SetGeometryType(type_geo);
1529 loc->SetSpaceDimension(spaceDimension);
1530 loc->SetNumberOfCellInSection(nsectionmeshcell);
1531 loc->SetSectionGeometryType(sectiongeotype);
1533 med_float *localCoordinates = new med_float[loc->GetSizeOfPointLocalCoordinates()];
1534 med_float *pqLocalCoordinates = new med_float[loc->GetSizeOfQuadraturePointLocalCoordinates()];
1535 med_float *weights = new med_float[loc->GetSizeOfWeights()];
1537 if(MEDlocalizationRd(FileId,
1544 vtkErrorMacro("MEDlocalizationRd : " << loc->GetName());
1547 vtkDoubleArray* lc = loc->GetPointLocalCoordinates();
1548 vtkDoubleArray *pqlc = loc->GetQuadraturePointLocalCoordinates();
1549 vtkDoubleArray *w = loc->GetWeights();
1551 lc->SetNumberOfValues(loc->GetSizeOfPointLocalCoordinates());
1552 for(int i=0; i<loc->GetSizeOfPointLocalCoordinates(); i++)
1554 lc->SetValue(i, localCoordinates[i]);
1557 pqlc->SetNumberOfValues(loc->GetSizeOfQuadraturePointLocalCoordinates());
1558 for(int i=0; i<loc->GetSizeOfQuadraturePointLocalCoordinates(); i++)
1560 pqlc->SetValue(i, pqLocalCoordinates[i]);
1563 w->SetNumberOfValues(loc->GetSizeOfWeights());
1564 for(int i=0; i<loc->GetSizeOfWeights(); i++)
1566 w->SetValue(i, weights[i]);
1570 void vtkMedDriver30::ReadInterpolationInformation(vtkMedInterpolation* interp)
1573 med_geometry_type geotype;
1575 med_int nbofbasisfunc;
1576 med_int nbofvariable;
1580 char name[MED_NAME_SIZE+1] = "";
1582 if(MEDinterpInfo (this->FileId,
1583 interp->GetMedIterator(),
1585 &geotype, &cellnode, &nbofbasisfunc,
1586 &nbofvariable, &maxdegree, &nmaxcoef) < 0)
1588 vtkErrorMacro("MEDinterpInfo");
1592 interp->SetName(name);
1593 interp->SetGeometryType(geotype);
1594 interp->SetIsCellNode(cellnode);
1595 interp->SetNumberOfVariable(nbofvariable);
1596 interp->SetMaximumDegree(maxdegree);
1597 interp->SetMaximumNumberOfCoefficient(nmaxcoef);
1598 interp->AllocateNumberOfBasisFunction(nbofbasisfunc);
1600 for(int basisid=0; basisid < nbofbasisfunc; basisid++)
1602 vtkMedFraction* func = interp->GetBasisFunction(basisid);
1603 func->SetNumberOfVariable(nbofvariable);
1605 med_int ncoef = MEDinterpBaseFunctionCoefSize (
1609 func->SetNumberOfCoefficients(ncoef);
1611 if(ncoef <= 0 || nbofvariable <= 0)
1614 med_int *power = new med_int[nbofvariable * ncoef];
1615 med_float *coefficient = new med_float[ncoef];
1617 if(MEDinterpBaseFunctionRd (
1625 vtkErrorMacro("MEDinterpBaseFunctionRd");
1628 vtkDoubleArray* coeffs = func->GetCoefficients();
1629 for(int cid=0; cid < ncoef; cid++)
1631 coeffs->SetValue(cid, coefficient[cid]);
1633 vtkIntArray* powers = func->GetPowers();
1634 for(int pid=0; pid < ncoef*nbofvariable; pid++)
1636 powers->SetValue(pid, power[pid]);
1640 delete[] coefficient;
1644 void vtkMedDriver30::ReadSupportMeshInformation(
1645 vtkMedMesh* supportMesh)
1647 FileOpen open(this);
1649 char supportmeshname[MED_NAME_SIZE+1] = "";
1650 char description[MED_COMMENT_SIZE+1] = "";
1653 med_axis_type axistype;
1654 char axisname[3*MED_SNAME_SIZE+1] = "";
1655 char axisunit[3*MED_SNAME_SIZE+1] = "";
1657 if(MEDsupportMeshInfo (this->FileId,
1658 supportMesh->GetMedIterator(),
1667 vtkErrorMacro("MEDsupportMeshInfo");
1670 supportMesh->SetName(supportmeshname);
1671 supportMesh->SetDescription(description);
1672 supportMesh->SetSpaceDimension(spacedim);
1673 supportMesh->SetMeshDimension(meshdim);
1674 supportMesh->SetAxisType(axistype);
1675 for(int dim = 0; dim < 3; dim++)
1677 char axisname_dim[MED_SNAME_SIZE+1] = "";
1678 char axisunit_dim[MED_SNAME_SIZE+1] = "";
1680 strncpy(axisname_dim, axisname+dim*MED_SNAME_SIZE, MED_SNAME_SIZE);
1681 strncpy(axisunit_dim, axisunit+dim*MED_SNAME_SIZE, MED_SNAME_SIZE);
1683 supportMesh->GetAxisName()->SetValue(dim, axisname_dim);
1684 supportMesh->GetAxisUnit()->SetValue(dim, axisunit_dim);
1690 void vtkMedDriver30::LoadFamilyIds(vtkMedEntityArray* array)
1692 if(array->IsFamilyIdsLoaded())
1695 FileOpen open(this);
1697 vtkMedGrid* grid = array->GetParentGrid();
1699 vtkMedComputeStep cs = grid->GetComputeStep();
1701 // first, find if the family ids are implicit or explicit
1702 med_bool changement, transformation;
1704 med_int nfamid = MEDmeshnEntity(this->FileId,
1705 grid->GetParentMesh()->GetName(),
1708 array->GetEntity().EntityType,
1709 array->GetEntity().GeometryType,
1715 if(nfamid == array->GetNumberOfEntity())
1718 vtkMedIntArray* famIds = vtkMedIntArray::New();
1719 array->SetFamilyIds(famIds);
1722 famIds->SetNumberOfTuples(nfamid);
1724 if ( MEDmeshEntityFamilyNumberRd(
1726 grid->GetParentMesh()->GetName(),
1729 array->GetEntity().EntityType,
1730 array->GetEntity().GeometryType,
1731 famIds->GetPointer(0) ) < 0)
1733 vtkWarningMacro("Error loading the family ids of entity "
1734 << array->GetEntity().EntityType
1735 << " " << array->GetEntity().GeometryType
1736 << " on mesh " << grid->GetParentMesh()->GetName());
1737 array->SetFamilyIds(NULL);
1742 vtkDebugMacro("NumberOfEntity != Number of family ids");
1743 array->SetFamilyIds(NULL);
1746 array->ComputeFamilies();
1749 void vtkMedDriver30::LoadPointGlobalIds(vtkMedGrid* grid)
1751 if(grid->IsPointGlobalIdsLoaded())
1754 FileOpen open(this);
1756 vtkMedIntArray* globalIds = vtkMedIntArray::New();
1757 grid->SetPointGlobalIds(globalIds);
1758 globalIds->Delete();
1760 globalIds->SetNumberOfTuples(grid->GetNumberOfPoints());
1762 if( MEDmeshEntityNumberRd (
1764 grid->GetParentMesh()->GetName(),
1765 grid->GetComputeStep().TimeIt,
1766 grid->GetComputeStep().IterationIt,
1769 globalIds->GetPointer(0) ) < 0)
1771 grid->SetPointGlobalIds(NULL);
1775 void vtkMedDriver30::LoadCoordinates(vtkMedGrid* grid)
1777 if(grid->IsCoordinatesLoaded())
1780 vtkMedRegularGrid* rgrid = vtkMedRegularGrid::SafeDownCast(grid);
1783 this->LoadRegularGridCoordinates(rgrid);
1787 vtkMedUnstructuredGrid* ugrid = vtkMedUnstructuredGrid::SafeDownCast(grid);
1788 vtkMedCurvilinearGrid* cgrid = vtkMedCurvilinearGrid::SafeDownCast(grid);
1789 if(ugrid == NULL && cgrid == NULL)
1791 //TODO : deal with structured grids
1792 vtkWarningMacro("this kind of grid is not yet supported");
1796 if(grid->GetUsePreviousCoordinates())
1798 vtkMedGrid* previousgrid = grid->GetPreviousGrid();
1799 if(previousgrid == NULL)
1801 vtkErrorMacro("coordiantes have not changed, "
1802 << "but there is no previous grid!");
1806 this->LoadCoordinates(previousgrid);
1808 ugrid->SetCoordinates(vtkMedUnstructuredGrid::SafeDownCast(previousgrid)
1809 ->GetCoordinates());
1811 cgrid->SetCoordinates(vtkMedCurvilinearGrid::SafeDownCast(previousgrid)
1812 ->GetCoordinates());
1817 FileOpen open(this);
1819 vtkDataArray* coords = vtkMedUtilities::NewCoordArray();
1821 ugrid->SetCoordinates(coords);
1823 cgrid->SetCoordinates(coords);
1826 vtkMedComputeStep cs = grid->GetComputeStep();
1828 coords->SetNumberOfComponents(grid->GetParentMesh()->GetSpaceDimension());
1829 coords->SetNumberOfTuples(grid->GetNumberOfPoints());
1831 if ( MEDmeshNodeCoordinateRd( this->FileId,
1832 grid->GetParentMesh()->GetName(),
1836 (med_float*) coords->GetVoidPointer(0) ) < 0)
1838 vtkErrorMacro("Load Coordinates for mesh "
1839 << grid->GetParentMesh()->GetName());
1844 void vtkMedDriver30::LoadProfile(vtkMedProfile* profile)
1846 if(!profile || profile->IsLoaded())
1849 FileOpen open(this);
1851 vtkMedIntArray* indices = vtkMedIntArray::New();
1852 profile->SetIds(indices);
1855 indices->SetNumberOfTuples(profile->GetNumberOfElement());
1857 char name[MED_NAME_SIZE+1] = "";
1859 if( MEDprofileRd(this->FileId,
1861 indices->GetPointer(0) ) < 0)
1863 vtkErrorMacro("Reading profile indices ");
1867 void vtkMedDriver30::LoadConnectivity(vtkMedEntityArray* array)
1869 if(array->IsConnectivityLoaded())
1872 FileOpen open(this);
1874 vtkMedGrid* grid = array->GetParentGrid();
1876 grid = array->GetParentGrid();
1878 const char* meshName = grid->GetParentMesh()->GetName();
1880 vtkMedIntArray* conn = vtkMedIntArray::New();
1881 array->SetConnectivityArray(conn);
1884 vtkMedComputeStep cs = grid->GetComputeStep();
1887 med_bool transformation;
1889 if(array->GetEntity().GeometryType == MED_POLYGON)
1891 // first check if we have points
1892 med_int connSize = MEDmeshnEntity(
1897 array->GetEntity().EntityType,
1900 array->GetConnectivity(),
1906 vtkErrorMacro(<< "Error while reading polygons connectivity size."
1911 conn->SetNumberOfTuples(connSize);
1913 // How many polygon in the mesh in nodal connectivity mode
1914 // For the polygons, we get the size of array index
1916 if ((indexsize = MEDmeshnEntity(this->FileId,
1920 array->GetEntity().EntityType,
1923 array->GetConnectivity(),
1925 &transformation )) < 0)
1927 vtkErrorMacro(<< "Error while reading polygons array index." << endl );
1931 vtkMedIntArray* index = vtkMedIntArray::New();
1932 array->SetFaceIndex(index);
1935 index->SetNumberOfTuples( indexsize );
1937 if ( MEDmeshPolygonRd(this->FileId,
1941 array->GetEntity().EntityType,
1942 array->GetConnectivity(),
1943 index->GetPointer(0),
1944 conn->GetPointer(0) ) < 0)
1946 vtkErrorMacro(<< "MEDmeshPolygonRd");
1950 else if(array->GetEntity().GeometryType == MED_POLYHEDRON)
1953 vtkIdType connSize = MEDmeshnEntity(this->FileId,
1955 grid->GetComputeStep().TimeIt,
1956 grid->GetComputeStep().IterationIt,
1957 array->GetEntity().EntityType,
1960 array->GetConnectivity(),
1965 vtkErrorMacro(<< "Error while reading polyhedrons connectivity size."
1970 conn->SetNumberOfTuples(connSize);
1972 vtkMedIntArray* faceIndex = vtkMedIntArray::New();
1973 array->SetFaceIndex(faceIndex);
1974 faceIndex->Delete();
1976 vtkMedIntArray* nodeIndex = vtkMedIntArray::New();
1977 array->SetNodeIndex(nodeIndex);
1978 nodeIndex->Delete();
1980 vtkIdType np = array->GetNumberOfEntity() + 1;
1981 faceIndex->SetNumberOfTuples(np);
1983 med_int nodeIndexSize;
1985 if ((nodeIndexSize = MEDmeshnEntity(this->FileId,
1987 grid->GetComputeStep().TimeIt,
1988 grid->GetComputeStep().IterationIt,
1989 array->GetEntity().EntityType,
1992 array->GetConnectivity(),
1994 &transformation )) < 0)
1996 vtkErrorMacro(<< "Error while reading polygons array index." << endl );
2000 nodeIndex->SetNumberOfTuples(nodeIndexSize);
2002 if (MEDmeshPolyhedronRd(this->FileId,
2006 array->GetEntity().EntityType,
2007 array->GetConnectivity(),
2008 faceIndex->GetPointer(0),
2009 nodeIndex->GetPointer(0),
2010 conn->GetPointer(0) ) < 0)
2012 vtkErrorMacro("Error while reading connectivity of polyhedrons");
2019 bool doReadConnectivity = true;
2020 if(array->GetConnectivity() == MED_NODAL)
2022 if(array->GetEntity().EntityType == MED_STRUCT_ELEMENT)
2024 std::cout << " -- MED_STRUCT_ELEMENT --" << std::endl;
2025 if(array->GetStructElement() == NULL)
2027 vtkErrorMacro("Entity type = MED_STRUCT_ELEMENT, but StructElement is not set!");
2030 vtkIdType ntuple = array->GetNumberOfEntity()
2031 * array->GetStructElement()->GetConnectivitySize();
2033 conn->SetNumberOfTuples(ntuple);
2034 // particles are special : connectivity is not stored in the med file
2035 if(strcmp(array->GetStructElement()->GetName(), MED_PARTICLE_NAME) == 0 )
2037 for(vtkIdType cellId = 0; cellId < ntuple; cellId++)
2039 conn->SetValue(cellId, cellId+1);
2041 doReadConnectivity = false;
2046 conn->SetNumberOfTuples(array->GetNumberOfEntity()
2047 * vtkMedUtilities::GetNumberOfPoint(
2048 array->GetEntity().GeometryType));
2053 conn->SetNumberOfTuples(array->GetNumberOfEntity()
2054 * vtkMedUtilities::GetNumberOfSubEntity(
2055 array->GetEntity().GeometryType));
2058 if (this->ParallelFileId == -1) // also (array->GetFilter() == NULL)
2060 if ( (MEDmeshElementConnectivityRd(
2065 array->GetEntity().EntityType,
2066 array->GetEntity().GeometryType,
2067 array->GetConnectivity(),
2069 conn->GetPointer(0)) ) < 0)
2071 vtkErrorMacro("Error while load connectivity of cells "
2072 << array->GetEntity().GeometryType);
2077 med_filter filter = MED_FILTER_INIT;
2084 array->GetFilter()->GetFilterSizes(start, stride, count,
2085 blocksize, lastblocksize );
2087 med_int nbofconstituentpervalue = vtkMedUtilities::GetNumberOfNodes(
2088 array->GetEntity().GeometryType);
2090 if ( MEDfilterBlockOfEntityCr( this->ParallelFileId,
2091 array->GetNumberOfEntity(),
2092 1, // one is for mesh elements, more than 1 is for fields
2093 nbofconstituentpervalue,
2094 MED_ALL_CONSTITUENT,
2101 (med_size)blocksize,
2102 (med_size)lastblocksize,
2105 vtkErrorMacro("Filter creation ");
2108 if ( (MEDmeshElementConnectivityAdvancedRd(
2109 this->ParallelFileId,
2113 array->GetEntity().EntityType,
2114 array->GetEntity().GeometryType,
2115 array->GetConnectivity(),
2117 conn->GetPointer(0)) ) < 0)
2119 vtkErrorMacro("Error while load connectivity of cells "
2120 << array->GetEntity().GeometryType);
2123 if ( MEDfilterClose( &filter ) < 0)
2125 vtkErrorMacro("ERROR : filter closing ...");
2132 void vtkMedDriver30::LoadCellGlobalIds(vtkMedEntityArray* array)
2134 if(array->IsGlobalIdsLoaded())
2137 FileOpen open(this);
2139 vtkMedIntArray* globalIds = vtkMedIntArray::New();
2140 array->SetGlobalIds(globalIds);
2141 globalIds->Delete();
2143 globalIds->SetNumberOfTuples(array->GetNumberOfEntity());
2145 vtkMedGrid* grid = array->GetParentGrid();
2146 vtkMedComputeStep cs = grid->GetComputeStep();
2148 if( MEDmeshEntityNumberRd (
2150 grid->GetParentMesh()->GetName(),
2153 array->GetEntity().EntityType,
2154 array->GetEntity().GeometryType,
2155 globalIds->GetPointer(0) ) < 0)
2157 array->SetGlobalIds(NULL);
2161 void vtkMedDriver30::LoadField(vtkMedFieldOnProfile* fop, med_storage_mode mode)
2163 FileOpen open(this);
2165 vtkMedFieldOverEntity* fieldOverEntity = fop->GetParentFieldOverEntity();
2166 vtkMedFieldStep *step = fieldOverEntity->GetParentStep();
2167 vtkMedField* field = step->GetParentField();
2168 const vtkMedComputeStep& cs = step->GetComputeStep();
2170 vtkDataArray* data = vtkMedUtilities::NewArray(field->GetDataType());
2175 if(mode == MED_COMPACT_STMODE)
2177 size = fop->GetNumberOfValues();
2181 med_int profilesize;
2182 med_int nbofintegrationpoint;
2183 char profileName[MED_NAME_SIZE+1] = "";
2184 char localizationName[MED_NAME_SIZE+1] = "";
2185 size = MEDfieldnValueWithProfile(this->FileId,
2189 fieldOverEntity->GetEntity().EntityType,
2190 fieldOverEntity->GetEntity().GeometryType,
2191 fop->GetMedIterator(),
2196 &nbofintegrationpoint);
2199 if(fop->GetNumberOfIntegrationPoint() > 1)
2201 size *= fop->GetNumberOfIntegrationPoint();
2204 data->SetNumberOfComponents(field->GetNumberOfComponent());
2205 data->SetNumberOfTuples(size);
2206 if (this->ParallelFileId == -1)
2208 if ( MEDfieldValueWithProfileRd(
2213 fieldOverEntity->GetEntity().EntityType,
2214 fieldOverEntity->GetEntity().GeometryType,
2216 fop->GetProfileName(),
2218 MED_ALL_CONSTITUENT,
2219 (unsigned char*) data->GetVoidPointer(0) ) < 0)
2221 vtkErrorMacro("Error on MEDfieldValueWithProfileRd");
2226 if (field->GetFieldType() == vtkMedField::CellField)
2228 med_filter filter = MED_FILTER_INIT;
2235 fop->GetFilter()->GetFilterSizes(start, stride, count,
2236 blocksize, lastblocksize );
2238 if ( MEDfilterBlockOfEntityCr( this->ParallelFileId,
2239 fop->GetNumberOfValues(),
2240 1, // one is for mesh elements, more than 1 is for fields
2241 field->GetNumberOfComponent(),
2242 MED_ALL_CONSTITUENT,
2249 (med_size)blocksize,
2250 (med_size)lastblocksize,
2253 vtkErrorMacro("Filter creation ");
2256 if ( MEDfieldValueAdvancedRd(
2257 this->ParallelFileId,
2261 fieldOverEntity->GetEntity().EntityType,
2262 fieldOverEntity->GetEntity().GeometryType,
2264 (unsigned char*) data->GetVoidPointer(0) ) < 0)
2266 vtkErrorMacro("Error on MEDfieldValueAdvancedRd");
2269 if ( MEDfilterClose( &filter ) < 0)
2271 vtkErrorMacro("ERROR : filter closing ...");
2275 {//TODO : option utilisateur pour desactiver ou non les champs avec profile en //
2276 if ( MEDfieldValueWithProfileRd(
2281 fieldOverEntity->GetEntity().EntityType,
2282 fieldOverEntity->GetEntity().GeometryType,
2284 fop->GetProfileName(),
2286 MED_ALL_CONSTITUENT,
2287 (unsigned char*) data->GetVoidPointer(0) ) < 0)
2289 vtkErrorMacro("Error on MEDfieldValueWithProfileRd");
2295 void vtkMedDriver30::LoadVariableAttribute(vtkMedVariableAttribute* varatt,
2296 vtkMedEntityArray* array)
2298 FileOpen open(this);
2302 vtkAbstractArray* valuearray = array->GetVariableAttributeValue(varatt);
2303 // first test if this is already loaded
2304 if(valuearray != NULL && valuearray->GetNumberOfTuples() > 0)
2307 if(valuearray == NULL)
2309 valuearray = vtkMedUtilities::NewArray(varatt->GetAttributeType());
2310 array->SetVariableAttributeValues(varatt, valuearray);
2311 valuearray->Delete();
2314 valuearray->SetNumberOfComponents(varatt->GetNumberOfComponent());
2315 valuearray->SetNumberOfTuples(array->GetNumberOfEntity());
2316 valuearray->SetName(varatt->GetName());
2318 vtkSmartPointer<vtkCharArray> chararray = vtkSmartPointer<vtkCharArray>::New();
2320 if(varatt->GetAttributeType() != MED_ATT_NAME)
2322 value = valuearray->GetVoidPointer(0);
2326 chararray->SetNumberOfValues(varatt->GetNumberOfComponent() *
2327 array->GetNumberOfEntity() *
2330 value = chararray->GetVoidPointer(0);
2333 vtkMedComputeStep cs = array->GetParentGrid()->GetComputeStep();
2335 if(MEDmeshStructElementVarAttRd(
2337 array->GetParentGrid()->GetParentMesh()->GetName(),
2340 varatt->GetParentStructElement()->GetGeometryType(),
2345 if(cs.IterationIt == MED_NO_IT && cs.TimeIt == MED_NO_DT && cs.TimeOrFrequency == MED_UNDEF_DT)
2347 vtkErrorMacro("MEDmeshStructElementVarAttRd");
2350 // try to see if I can reuse
2351 // the variable attributes of the NO_DT, NO_IT compute step
2352 vtkMedComputeStep nocs;
2353 nocs.IterationIt = MED_NO_IT;
2354 nocs.TimeIt = MED_NO_DT;
2355 nocs.TimeOrFrequency = MED_UNDEF_DT;
2356 vtkMedEntityArray* nocs_array =
2357 array->GetParentGrid()->GetParentMesh()->GetGridStep(nocs)->GetEntityArray(array->GetEntity());
2358 if(nocs_array == NULL)
2360 nocs_array = array->GetParentGrid()->GetParentMesh()->GetGridStep(0)->GetEntityArray(array->GetEntity());
2363 if(nocs_array == NULL || nocs_array == array)
2365 // try to force load the default compute step.
2366 if(MEDmeshStructElementVarAttRd(
2368 array->GetParentGrid()->GetParentMesh()->GetName(),
2371 varatt->GetParentStructElement()->GetGeometryType(),
2375 vtkErrorMacro("MEDmeshStructElementVarAttRd");
2381 this->LoadVariableAttribute(varatt, nocs_array);
2382 array->SetVariableAttributeValues(varatt, nocs_array->GetVariableAttributeValue(varatt));
2387 // If I am here, it means that I read the values
2388 if(varatt->GetAttributeType() == MED_ATT_NAME)
2390 char current_name[MED_NAME_SIZE+1] = "";
2391 vtkStringArray* sarray = vtkStringArray::SafeDownCast(valuearray);
2392 for(vtkIdType id = 0; id < varatt->GetNumberOfComponent() *
2393 array->GetNumberOfEntity(); id++)
2395 memset(current_name, '\0', MED_NAME_SIZE+1);
2396 strncpy(current_name, ((char*)value) + id*MED_NAME_SIZE, MED_NAME_SIZE);
2397 sarray->SetValue(id, current_name);
2404 void vtkMedDriver30::PrintSelf(ostream& os, vtkIndent indent)
2406 this->Superclass::PrintSelf(os, indent);