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"
59 // vtkCxxRevisionMacro(vtkMedDriver30, "$Revision$")
60 vtkStandardNewMacro(vtkMedDriver30)
62 vtkMedDriver30::vtkMedDriver30() : vtkMedDriver()
66 vtkMedDriver30::~vtkMedDriver30()
71 // load all Information data associated with this cartesian grid.
72 void vtkMedDriver30::ReadRegularGridInformation(vtkMedRegularGrid* grid)
76 grid->SetDimension(grid->GetParentMesh()->GetNumberOfAxis());
78 for(int axis=0; axis < grid->GetDimension(); axis++)
81 med_bool coordinatechangement, geotransformation;
83 if ((size = MEDmeshnEntity(
85 grid->GetParentMesh()->GetName(),
86 grid->GetComputeStep().TimeIt,
87 grid->GetComputeStep().IterationIt,
90 (med_data_type)(MED_COORDINATE_AXIS1 + axis),
92 &coordinatechangement,
93 &geotransformation)) < 0)
95 vtkErrorMacro("ERROR : number of coordinates on X axis ...");
98 grid->SetAxisSize(axis, size);
102 if(grid->GetAxisSize(0) > 1)
103 ncell *= grid->GetAxisSize(0)-1;
104 if(grid->GetAxisSize(1) > 1)
105 ncell *= grid->GetAxisSize(1)-1;
106 if(grid->GetAxisSize(2) > 1)
107 ncell *= grid->GetAxisSize(2)-1;
110 entity.EntityType = MED_CELL;
112 switch(grid->GetDimension())
115 entity.GeometryType = MED_POINT1;
118 entity.GeometryType = MED_SEG2;
121 entity.GeometryType = MED_QUAD4;
124 entity.GeometryType = MED_HEXA8;
127 vtkErrorMacro("Unsupported dimension for curvilinear grid : "
128 << grid->GetDimension());
132 vtkMedEntityArray* array = vtkMedEntityArray::New();
133 array->SetParentGrid(grid);
134 array->SetNumberOfEntity(ncell);
135 array->SetEntity(entity);
136 array->SetConnectivity(MED_NODAL);
137 grid->AppendEntityArray(array);
139 // this triggers the creation of undefined families
140 this->LoadFamilyIds(array);
144 void vtkMedDriver30::LoadRegularGridCoordinates(vtkMedRegularGrid* grid)
148 for(int axis=0; axis < grid->GetParentMesh()->GetNumberOfAxis(); axis++)
151 vtkDataArray* coords = vtkMedUtilities::NewCoordArray();
152 grid->SetAxisCoordinate(axis, coords);
155 coords->SetNumberOfComponents(1);
156 coords->SetNumberOfTuples(grid->GetAxisSize(axis));
158 if (MEDmeshGridIndexCoordinateRd(
160 grid->GetParentMesh()->GetName(),
161 grid->GetComputeStep().TimeIt,
162 grid->GetComputeStep().IterationIt,
164 (med_float*)coords->GetVoidPointer(0)) < 0)
166 vtkErrorMacro("ERROR : read axis " << axis << " coordinates ...");
167 grid->SetAxisCoordinate(axis, NULL);
175 // load all Information data associated with this standard grid.
176 void vtkMedDriver30::ReadCurvilinearGridInformation(vtkMedCurvilinearGrid* grid)
180 grid->SetDimension(grid->GetParentMesh()->GetNumberOfAxis());
183 med_bool coordinatechangement, geotransformation;
185 if ((size = MEDmeshnEntity(
187 grid->GetParentMesh()->GetName(),
188 grid->GetComputeStep().TimeIt,
189 grid->GetComputeStep().IterationIt,
194 &coordinatechangement,
195 &geotransformation)) < 0)
197 vtkErrorMacro("ReadCurvilinearGridInformation MEDmeshnEntity");
200 grid->SetNumberOfPoints(size);
204 if(MEDmeshGridStructRd(
206 grid->GetParentMesh()->GetName(),
207 grid->GetComputeStep().TimeIt,
208 grid->GetComputeStep().IterationIt,
211 vtkErrorMacro("ReadCurvilinearGridInformation MEDmeshGridStructRd");
214 switch(grid->GetDimension())
219 grid->SetAxisSize(0, (axissize[0] <= 0 ? 1: axissize[0]));
222 grid->SetAxisSize(0, (axissize[0] <= 0 ? 1: axissize[0]));
223 grid->SetAxisSize(1, (axissize[1] <= 0 ? 1: axissize[1]));
226 grid->SetAxisSize(0, (axissize[0] <= 0 ? 1: axissize[0]));
227 grid->SetAxisSize(1, (axissize[1] <= 0 ? 1: axissize[1]));
228 grid->SetAxisSize(2, (axissize[2] <= 0 ? 1: axissize[2]));
231 vtkErrorMacro("Unsupported dimension for curvilinear grid : "
232 << grid->GetDimension());
236 // A test to verify the number of points : total number of
237 // points should be equal to the product of each axis size
240 if (grid->GetDimension() == 1)
242 size2 = grid->GetAxisSize(0);
245 if (grid->GetDimension() == 2)
247 size2 = grid->GetAxisSize(0)*grid->GetAxisSize(1);
250 if (grid->GetDimension() == 3)
252 size2 = grid->GetAxisSize(0)*grid->GetAxisSize(1)*grid->GetAxisSize(2);
257 vtkErrorMacro("The total number of points of a Curvilinear grid should "
258 << "be the product of each axis size!");
262 if ((grid->GetDimension() >= 1) && (grid->GetAxisSize(0) > 1))
263 ncell *= grid->GetAxisSize(0)-1;
264 if ((grid->GetDimension() >= 2) && (grid->GetAxisSize(1) > 1))
265 ncell *= grid->GetAxisSize(1)-1;
266 if ((grid->GetDimension() >= 3) && (grid->GetAxisSize(2) > 1))
267 ncell *= grid->GetAxisSize(2)-1;
270 entity.EntityType = MED_CELL;
272 switch(grid->GetDimension())
275 entity.GeometryType = MED_POINT1;
278 entity.GeometryType = MED_SEG2;
281 entity.GeometryType = MED_QUAD4;
284 entity.GeometryType = MED_HEXA8;
287 vtkErrorMacro("Unsupported dimension for curvilinear grid : "
288 << grid->GetDimension());
292 vtkMedEntityArray* array = vtkMedEntityArray::New();
293 array->SetParentGrid(grid);
294 array->SetNumberOfEntity(ncell);
295 array->SetEntity(entity);
296 array->SetConnectivity(MED_NODAL);
297 grid->AppendEntityArray(array);
299 // this triggers the creation of undefined families
300 this->LoadFamilyIds(array);
303 // Description : read the number of entity of all geometry type
304 // for a given entity type and a given connectivity mode
305 void vtkMedDriver30::ReadNumberOfEntity(
306 vtkMedUnstructuredGrid* grid,
307 med_entity_type entityType,
308 med_connectivity_mode connectivity)
312 med_bool changement, transformation;
314 const char* meshName = grid->GetParentMesh()->GetName();
316 const vtkMedComputeStep& cs = grid->GetComputeStep();
318 med_int nentity = MEDmeshnEntity(
330 for(med_int geotypeit = 1; geotypeit <= nentity; geotypeit++)
332 // read cell informations
334 entity.EntityType = entityType;
336 char geometryName[MED_NAME_SIZE+1] = "";
338 // this gives us the med_geometry_type
339 if( MEDmeshEntityInfo( FileId, meshName,
345 &entity.GeometryType) < 0)
347 vtkErrorMacro("MEDmeshEntityInfo");
351 entity.GeometryName = geometryName;
354 if(entity.GeometryType == MED_POLYGON)
356 // read the number of cells of this type
357 ncell = MEDmeshnEntity(this->FileId,
366 &transformation ) - 1;
368 else if(entity.GeometryType == MED_POLYHEDRON)
370 // read the number of cells of this type
371 ncell = MEDmeshnEntity(this->FileId,
380 &transformation ) - 1;
384 ncell = MEDmeshnEntity(this->FileId,
398 vtkMedEntityArray* array = vtkMedEntityArray::New();
399 array->SetParentGrid(grid);
400 array->SetNumberOfEntity(ncell);
401 array->SetEntity(entity);
402 array->SetConnectivity(connectivity);
403 grid->AppendEntityArray(array);
405 // this triggers the creation of undefined families
406 this->LoadFamilyIds(array);
412 // load all Information data associated with this unstructured grid.
413 void vtkMedDriver30::ReadUnstructuredGridInformation(
414 vtkMedUnstructuredGrid* grid)
418 vtkMedMesh *mesh = grid->GetParentMesh();
420 const char *meshName = mesh->GetName();
421 med_connectivity_mode connectivity;
424 med_bool transformation;
427 char profilename[MED_NAME_SIZE+1];
428 memset(profilename, '\0', MED_NAME_SIZE+1);
430 vtkMedComputeStep cs = grid->GetComputeStep();
432 // first check if we have points
433 vtkIdType npoints = MEDmeshnEntityWithProfile(
450 grid->SetNumberOfPoints(npoints);
454 if(grid->GetPreviousGrid() == NULL)
456 vtkErrorMacro("No point and no previous grid");
458 grid->SetUsePreviousCoordinates(true);
459 grid->SetNumberOfPoints(grid->GetPreviousGrid()->GetNumberOfPoints());
463 this->ReadNumberOfEntity(grid, MED_CELL, MED_NODAL);
464 this->ReadNumberOfEntity(grid, MED_CELL, MED_DESCENDING);
465 this->ReadNumberOfEntity(grid, MED_DESCENDING_FACE, MED_NODAL);
466 this->ReadNumberOfEntity(grid, MED_DESCENDING_FACE, MED_DESCENDING);
467 this->ReadNumberOfEntity(grid, MED_DESCENDING_EDGE, MED_NODAL);
468 this->ReadNumberOfEntity(grid, MED_DESCENDING_EDGE, MED_DESCENDING);
469 this->ReadNumberOfEntity(grid, MED_STRUCT_ELEMENT, MED_NODAL);
470 this->ReadNumberOfEntity(grid, MED_STRUCT_ELEMENT, MED_DESCENDING);
472 // create the point vtkMedEntityArray support
474 entity.EntityType = MED_NODE;
475 entity.GeometryType = MED_POINT1;
476 vtkMedEntityArray* pea = vtkMedEntityArray::New();
477 pea->SetEntity(entity);
478 pea->SetParentGrid(grid);
479 pea->SetNumberOfEntity(grid->GetNumberOfPoints());
480 grid->AppendEntityArray(pea);
483 this->LoadFamilyIds(pea);
486 void vtkMedDriver30::ReadFamilyInformation(vtkMedMesh* mesh, vtkMedFamily* family)
492 char* groupNames = NULL;
493 const char* meshName = mesh->GetName();
495 ngroup = MEDnFamilyGroup(FileId, meshName, family->GetMedIterator());
497 bool has_no_group = false;
502 vtkErrorMacro("Error while reading the number of groups");
508 groupNames = new char[ngroup * MED_LNAME_SIZE + 1];
509 memset(groupNames, '\0', ngroup * MED_LNAME_SIZE + 1);
511 // special case for files written by med < 3,
512 // I have to use the 23 interface
513 if(mesh->GetParentFile()->GetVersionMajor() < 3)
515 med_int *attributenumber = NULL;
516 med_int *attributevalue = NULL;
517 char *attributedes = NULL;
519 med_int nattr = MEDnFamily23Attribute(
522 family->GetMedIterator());
526 vtkErrorMacro("MEDnFamily23Attribute");
531 attributenumber = new med_int[nattr];
532 attributevalue = new med_int[nattr];
533 attributedes = new char[nattr*MED_COMMENT_SIZE+1];
534 memset(attributedes, '\0', nattr*MED_COMMENT_SIZE+1);
537 char familyName[MED_NAME_SIZE+1] = "";
539 if(MEDfamily23Info (this->FileId,
541 family->GetMedIterator(),
549 vtkDebugMacro("MEDfamily23Info");
552 family->SetName(familyName);
554 if(attributenumber != NULL)
555 delete[] attributenumber;
556 if(attributevalue != NULL)
557 delete[] attributevalue;
558 if(attributedes != NULL)
559 delete[] attributedes;
563 char familyName[MED_NAME_SIZE+1] = "";
564 if(MEDfamilyInfo( this->FileId,
566 family->GetMedIterator(),
572 "vtkMedDriver30::ReadInformation(vtkMedFamily* family)"
573 << " cannot read family informations.");
576 family->SetName(familyName);
579 family->SetId(familyid);
583 family->SetPointOrCell(vtkMedUtilities::OnCell);
584 mesh->AppendCellFamily(family);
588 family->SetPointOrCell(vtkMedUtilities::OnPoint);
589 mesh->AppendPointFamily(family);
592 family->AllocateNumberOfGroup(ngroup);
593 // if there where no group, set the name to the default value
596 memcpy(groupNames, vtkMedUtilities::NoGroupName,
597 strlen(vtkMedUtilities::NoGroupName));
600 for(int index = 0; index < ngroup; index++)
602 char realGroupName[MED_LNAME_SIZE + 1];
603 memset(realGroupName, '\0', MED_LNAME_SIZE + 1);
604 memcpy(realGroupName, groupNames + index * MED_LNAME_SIZE,
605 MED_LNAME_SIZE * sizeof(char));
606 vtkMedGroup* group = mesh->GetOrCreateGroup(family->GetPointOrCell(),
609 family->SetGroup(index, group);
616 vtkMedFamily* famzero = vtkMedFamily::New();
617 mesh->AppendPointFamily(famzero);
620 famzero->SetName(family->GetName());
621 famzero->SetMedIterator(family->GetMedIterator());
622 famzero->SetId(family->GetId());
623 famzero->SetPointOrCell(vtkMedUtilities::OnPoint);
624 famzero->AllocateNumberOfGroup(family->GetNumberOfGroup());
625 for(int gid=0; gid<family->GetNumberOfGroup(); gid++)
627 vtkMedGroup* group = mesh->GetOrCreateGroup(
628 vtkMedUtilities::OnPoint,
629 family->GetGroup(gid)->GetName());
630 famzero->SetGroup(gid, group);
631 mesh->AppendPointGroup(group);
636 void vtkMedDriver30::ReadLinkInformation(vtkMedLink* link)
639 char linkMeshName[MED_NAME_SIZE+1] = "";
640 if(MEDlinkInfo(this->FileId,
641 link->GetMedIterator(),
645 vtkErrorMacro("MEDlinkInfo");
648 link->SetMeshName(linkMeshName);
652 char* path = new char[size + 1];
653 memset(path, '\0', size+1);
654 if(MEDlinkRd(this->FileId, link->GetMeshName(), path) < 0)
656 vtkErrorMacro("MEDlinkRd");
657 memset(path, '\0', size+1);
665 void vtkMedDriver30::ReadFileInformation(vtkMedFile* file)
669 char comment[MED_COMMENT_SIZE+1] = "";
671 MEDfileCommentRd(this->FileId,
674 file->SetComment(comment);
676 med_int major, minor, release;
677 MEDfileNumVersionRd(this->FileId, &major, &minor, &release);
678 file->SetVersionMajor(major);
679 file->SetVersionMinor(minor);
680 file->SetVersionRelease(release);
682 int nlink = MEDnLink(this->FileId);
683 file->AllocateNumberOfLink(nlink);
684 for(int linkid=0; linkid<nlink; linkid++)
686 vtkMedLink* link = file->GetLink(linkid);
687 link->SetMedIterator(linkid+1);
688 this->ReadLinkInformation(link);
691 int nprof = MEDnProfile(FileId);
692 // Reading id s not possible in parallel if the file contains Profiles
693 vtkMultiProcessController* controller = vtkMultiProcessController::GetGlobalController();
694 if (controller != NULL)
695 if ((nprof != 0) && (controller->GetNumberOfProcesses() > 1))
697 vtkWarningMacro("ATTENTION: The MED Reader cannot read profiles when used in parallel");
700 file->AllocateNumberOfProfile(nprof);
701 for(int i = 0; i < nprof; i++)
703 vtkMedProfile* profile = file->GetProfile(i);
704 profile->SetMedIterator(i + 1);
705 profile->SetParentFile(file);
706 this->ReadProfileInformation(profile);
709 int nloc = MEDnLocalization(this->FileId);
710 file->AllocateNumberOfLocalization(nloc);
711 for(int i = 0; i < nloc; i++)
713 vtkMedLocalization* loc = file->GetLocalization(i);
714 loc->SetMedIterator(i + 1);
715 loc->SetParentFile(file);
716 this->ReadLocalizationInformation(loc);
719 int nsupportmesh = MEDnSupportMesh(this->FileId);
720 file->AllocateNumberOfSupportMesh(nsupportmesh);
721 for(int i = 0; i < nsupportmesh; i++)
723 vtkMedMesh* supportmesh = file->GetSupportMesh(i);
724 supportmesh->SetMedIterator(i + 1);
725 supportmesh->SetParentFile(file);
726 this->ReadSupportMeshInformation(supportmesh);
729 int nmesh = MEDnMesh(this->FileId);
730 file->AllocateNumberOfMesh(nmesh);
731 for(int i = 0; i < nmesh; i++)
733 vtkMedMesh* mesh = file->GetMesh(i);
734 mesh->SetMedIterator(i + 1);
735 mesh->SetParentFile(file);
736 this->ReadMeshInformation(mesh);
739 int nfields = MEDnField(this->FileId);
740 file->AllocateNumberOfField(nfields);
741 for(int i = 0; i < nfields; i++)
743 vtkMedField* field = file->GetField(i);
744 field->SetMedIterator(i + 1);
745 field->SetParentFile(file);
746 this->ReadFieldInformation(field);
747 field->ComputeFieldType();
748 while(field->HasManyFieldTypes())
750 vtkMedField* newfield = vtkMedField::New();
751 int type = field->GetFirstType();
752 newfield->ExtractFieldType(field, type);
753 file->AppendField(newfield);
758 int nstruct = MEDnStructElement(this->FileId);
760 file->AllocateNumberOfStructElement(nstruct);
761 for(int i = 0; i < nstruct; i++)
763 vtkMedStructElement* structelem = file->GetStructElement(i);
764 structelem->SetMedIterator(i+1);
765 structelem->SetParentFile(file);
766 this->ReadStructElementInformation(structelem);
771 void vtkMedDriver30::ReadStructElementInformation(
772 vtkMedStructElement* structelem)
777 char modelname[MED_NAME_SIZE+1] = "";
778 med_geometry_type mgeotype;
780 char supportmeshname[MED_NAME_SIZE+1] = "";
781 med_entity_type sentitytype;
784 med_geometry_type sgeotype;
785 med_int nbofconstantattribute;
787 med_int nbofvariableattribute;
789 if(MEDstructElementInfo (this->FileId,
790 structelem->GetMedIterator(),
799 &nbofconstantattribute,
801 &nbofvariableattribute) < 0)
803 vtkErrorMacro("Error in MEDstructElementInfo");
806 structelem->SetName(modelname);
807 structelem->SetGeometryType(mgeotype);
808 structelem->SetModelDimension(modeldim);
809 structelem->SetSupportMeshName(supportmeshname);
810 structelem->SetSupportEntityType(sentitytype);
811 structelem->SetSupportNumberOfNode(snbofnode);
812 structelem->SetSupportNumberOfCell(snbofcell);
813 structelem->SetSupportGeometryType(sgeotype);
814 structelem->AllocateNumberOfConstantAttribute(nbofconstantattribute);
815 structelem->AllocateNumberOfVariableAttribute(nbofvariableattribute);
816 structelem->SetAnyProfile(anyprofile);
818 for(int attit = 0; attit < nbofconstantattribute; attit ++)
820 vtkMedConstantAttribute* constatt = structelem->GetConstantAttribute(attit);
821 constatt->SetMedIterator(attit+1);
822 constatt->SetParentStructElement(structelem);
823 this->ReadConstantAttributeInformation(constatt);
826 for(int attit = 0; attit < nbofvariableattribute; attit ++)
828 vtkMedVariableAttribute* varatt = structelem->GetVariableAttribute(attit);
829 varatt->SetMedIterator(attit+1);
830 varatt->SetParentStructElement(structelem);
831 this->ReadVariableAttributeInformation(varatt);
835 void vtkMedDriver30::ReadConstantAttributeInformation(
836 vtkMedConstantAttribute* constAttr)
841 char constattname[MED_NAME_SIZE+1] = "";
842 med_attribute_type constatttype;
843 med_int nbofcomponent;
844 med_entity_type sentitytype;
845 char profilename[MED_NAME_SIZE+1] = "";
848 if(MEDstructElementConstAttInfo(
850 constAttr->GetParentStructElement()->GetName(),
851 constAttr->GetMedIterator(),
859 vtkErrorMacro("MEDstructElementConstAttInfo error");
863 constAttr->SetName(constattname);
864 constAttr->SetAttributeType(constatttype);
865 constAttr->SetNumberOfComponent(nbofcomponent);
866 constAttr->SetSupportEntityType(sentitytype);
867 constAttr->SetProfileName(profilename);
868 constAttr->SetProfileSize(profilesize);
870 vtkAbstractArray* values = vtkMedUtilities::NewArray(constatttype);
873 constAttr->SetValues(values);
876 values->SetNumberOfComponents(nbofcomponent);
877 vtkIdType ntuple = 0;
878 if((strcmp(profilename, MED_NO_PROFILE) != 0) &&
879 (strcmp(profilename, "\0") != 0))
881 ntuple = profilesize;
883 else if(constAttr->GetSupportEntityType() == MED_CELL)
885 ntuple = constAttr->GetParentStructElement()->GetSupportNumberOfCell();
889 ntuple = constAttr->GetParentStructElement()->GetSupportNumberOfNode();
891 values->SetNumberOfTuples(ntuple);
894 vtkSmartPointer<vtkCharArray> buffer = vtkSmartPointer<vtkCharArray>::New();
895 if(constatttype != MED_ATT_NAME)
897 ptr = values->GetVoidPointer(0);
901 buffer->SetNumberOfValues(MED_NAME_SIZE*nbofcomponent*ntuple);
902 ptr = buffer->GetVoidPointer(0);
905 if(MEDstructElementConstAttRd (this->FileId,
906 constAttr->GetParentStructElement()->GetName(),
907 constAttr->GetName(), ptr) < 0)
909 vtkErrorMacro("MEDstructElementConstAttRd");
913 if(constatttype == MED_ATT_NAME)
915 char name[MED_NAME_SIZE+1] = "";
916 char* nameptr = (char*) ptr;
917 vtkStringArray* names = vtkStringArray::SafeDownCast(values);
918 for(vtkIdType id = 0; id < nbofcomponent*ntuple; id++)
920 memset(name, '\0', MED_NAME_SIZE+1);
921 strncpy(name, nameptr + id * MED_NAME_SIZE, MED_NAME_SIZE);
922 names->SetValue(id, name);
929 void vtkMedDriver30::ReadVariableAttributeInformation(
930 vtkMedVariableAttribute* varAttr)
935 char varattname[MED_NAME_SIZE+1] = "";
936 med_attribute_type varatttype;
937 med_int nbofcomponent;
939 if(MEDstructElementVarAttInfo (
941 varAttr->GetParentStructElement()->GetName(),
942 varAttr->GetMedIterator(),
947 vtkErrorMacro("MEDstructElementVarAttInfo");
951 varAttr->SetName(varattname);
952 varAttr->SetAttributeType(varatttype);
953 varAttr->SetNumberOfComponent(nbofcomponent);
958 void vtkMedDriver30::ReadProfileInformation(vtkMedProfile* profile)
963 char profileName[MED_NAME_SIZE+1] = "";
965 if(MEDprofileInfo(this->FileId,
966 profile->GetMedIterator(),
970 vtkErrorMacro("cannot read information on profile"
971 << profile->GetMedIterator());
973 profile->SetName(profileName);
974 profile->SetNumberOfElement(nelem);
977 void vtkMedDriver30::ReadFieldInformation(vtkMedField* field)
981 if (field->GetMedIterator() == 0)
984 int ncomp = MEDfieldnComponent(FileId, field->GetMedIterator());
988 field->SetNumberOfComponent(-1);
989 vtkErrorMacro("cannot read the number of component of field "
990 << field->GetMedIterator())
994 field->SetNumberOfComponent(ncomp);
996 char* units = new char[MED_SNAME_SIZE * ncomp + 1];
997 char* componentNames = new char[MED_SNAME_SIZE * ncomp + 1];
998 memset(units, '\0', MED_SNAME_SIZE * ncomp + 1);
999 memset(componentNames, '\0', MED_SNAME_SIZE * ncomp + 1);
1001 //med_type_champ dataType;
1002 med_field_type dataType;
1006 char name[MED_NAME_SIZE+1] = "";
1007 char meshName[MED_NAME_SIZE+1] = "";
1008 char unit[MED_SNAME_SIZE+1] = "";
1010 if( MEDfieldInfo( FileId,
1011 field->GetMedIterator(),
1021 vtkErrorMacro("cannot read the informations on field "
1022 << field->GetMedIterator())
1026 field->SetName(name);
1027 field->SetMeshName(meshName);
1028 field->SetTimeUnit(unit);
1029 field->SetDataType(dataType);
1030 field->SetLocal(localmesh);
1032 for(int comp = 0; comp < ncomp; comp++)
1034 char unit[MED_NAME_SIZE + 1] = "";
1035 memcpy(unit, units + MED_SNAME_SIZE * comp, MED_SNAME_SIZE * sizeof(char));
1036 field->GetUnit()->SetValue(comp, unit);
1038 char compName[MED_SNAME_SIZE + 1] = "";
1039 memcpy(compName, componentNames + MED_SNAME_SIZE * comp, MED_SNAME_SIZE
1041 field->GetComponentName()->SetValue(comp, compName);
1045 delete[] componentNames;
1047 med_int ninterp = MEDfieldnInterp(FileId, field->GetName());
1050 vtkErrorMacro("Error in MEDfieldnInterp");
1054 field->AllocateNumberOfInterpolation(ninterp);
1056 for(med_int interpit=0; interpit<ninterp; interpit++)
1058 vtkMedInterpolation* interp = field->GetInterpolation(interpit);
1059 interp->SetMedIterator(interpit + 1);
1060 this->ReadInterpolationInformation(interp);
1063 vtkMedFieldStep* previousStep = NULL;
1065 for(med_int csit = 0; csit < nstep; csit++)
1067 vtkMedFieldStep* step = vtkMedFieldStep::New();
1068 step->SetMedIterator(csit + 1);
1069 step->SetParentField(field);
1070 this->ReadFieldStepInformation(step, csit == 0);
1071 field->AddFieldStep(step);
1072 step->SetPreviousStep(previousStep);
1073 previousStep = step;
1078 void vtkMedDriver30::ReadFieldStepInformation(vtkMedFieldStep* step, bool readAllEntityInfo)
1080 vtkMedComputeStep cs;
1081 vtkMedComputeStep meshcs;
1082 vtkMedField* field = step->GetParentField();
1084 FileOpen open(this);
1086 if( MEDfieldComputingStepMeshInfo(
1089 step->GetMedIterator(),
1092 &cs.TimeOrFrequency,
1094 &meshcs.IterationIt) < 0)
1096 vtkErrorMacro("Error in MEDfieldComputingStepMeshInfo");
1100 step->SetComputeStep(cs);
1101 step->SetMeshComputeStep(meshcs);
1103 if(!readAllEntityInfo || step->GetEntityInfoLoaded())
1106 step->SetEntityInfoLoaded(1);
1108 vtkMedFile* file = field->GetParentFile();
1109 vtkMedMesh* mesh = file->GetMesh(field->GetMeshName());
1114 //rnv begin: fix the "22335: [CEA 954] Paravis 7.2.0 doesn't read ELNO fields" regression.
1115 // this piece of code needed for the reading ELNO fields
1116 std::set<vtkMedEntity> tmp_entities;
1117 std::set<vtkMedEntity> entities;
1118 mesh->GatherMedEntities(tmp_entities);
1120 std::set<vtkMedEntity>::iterator tmp_entity_it = tmp_entities.begin();
1121 while(tmp_entity_it != tmp_entities.end())
1123 vtkMedEntity entity = *tmp_entity_it;
1125 entities.insert(entity);
1126 if(entity.EntityType == MED_CELL)
1128 vtkMedEntity newEntity;
1129 newEntity.EntityType = MED_NODE_ELEMENT;
1130 newEntity.GeometryType = entity.GeometryType;
1131 newEntity.GeometryName = entity.GeometryName;
1132 entities.insert(newEntity);
1137 std::set<vtkMedEntity>::iterator entity_it = entities.begin();
1138 while(entity_it != entities.end())
1140 vtkMedEntity entity = *entity_it;
1143 med_int nvalues = 0;
1145 char profilename[MED_NAME_SIZE+1] = "";
1146 char localizationname[MED_NAME_SIZE+1] = "";
1148 nprofile = MEDfieldnProfile(
1151 step->GetComputeStep().TimeIt,
1152 step->GetComputeStep().IterationIt,
1154 entity.GeometryType,
1159 vtkErrorMacro("MEDfieldnProfile");
1163 bool hasprofile = (nprofile > 0);
1169 med_int profilesize;
1170 med_int nintegrationpoint;
1172 for(int pid=0; pid<nprofile; pid++)
1174 med_int medid = (hasprofile ? pid+1 : -1);
1175 nvalues = MEDfieldnValueWithProfile(
1178 step->GetComputeStep().TimeIt,
1179 step->GetComputeStep().IterationIt,
1181 entity.GeometryType,
1183 MED_COMPACT_PFLMODE,
1187 &nintegrationpoint);
1191 vtkErrorMacro("MEDfieldnValueWithProfile");
1194 else if(nvalues > 0)
1196 // I have found a profile with values, stop the loop here
1203 vtkMedFieldOverEntity* fieldOverEntity = vtkMedFieldOverEntity::New();
1204 step->AppendFieldOverEntity(fieldOverEntity);
1205 fieldOverEntity->Delete();
1207 fieldOverEntity->SetParentStep(step);
1208 fieldOverEntity->SetEntity(entity);
1210 this->ReadFieldOverEntityInformation(fieldOverEntity);
1215 void vtkMedDriver30::ReadFieldOverEntityInformation(vtkMedFieldOverEntity* fieldOverEntity)
1217 FileOpen open(this);
1219 vtkMedFieldStep* step = fieldOverEntity->GetParentStep();
1220 vtkMedField* field = step->GetParentField();
1221 vtkMedEntity entity = fieldOverEntity->GetEntity();
1223 const char* fieldName = field->GetName();
1224 const vtkMedComputeStep& cs = step->GetComputeStep();
1226 char profilename[MED_NAME_SIZE+1] = "";
1227 char localizationname[MED_NAME_SIZE+1] = "";
1229 med_int nProfiles = MEDfieldnProfile(
1235 entity.GeometryType,
1241 vtkErrorMacro("MEDfieldnProfile");
1243 else if(nProfiles == 0)
1245 fieldOverEntity->SetHasProfile(0);
1250 fieldOverEntity->SetHasProfile(1);
1252 fieldOverEntity->AllocateNumberOfFieldOnProfile(nProfiles);
1253 for(int profit = 0; profit < nProfiles; profit++)
1255 vtkMedFieldOnProfile* fop = fieldOverEntity->GetFieldOnProfile(profit);
1256 med_int medid = (fieldOverEntity->GetHasProfile()? profit+1: -1);
1257 fop->SetMedIterator(medid);
1258 fop->SetParentFieldOverEntity(fieldOverEntity);
1259 this->ReadFieldOnProfileInformation(fop);
1263 void vtkMedDriver30::ReadFieldOnProfileInformation(vtkMedFieldOnProfile* fop)
1265 vtkMedFieldOverEntity* fieldOverEntity = fop->GetParentFieldOverEntity();
1266 vtkMedFieldStep* step = fieldOverEntity->GetParentStep();
1267 vtkMedField* field = step->GetParentField();
1269 const vtkMedComputeStep& cs = step->GetComputeStep();
1270 med_int profilesize;
1271 med_int nbofintegrationpoint;
1273 char profileName[MED_NAME_SIZE+1] = "";
1274 char localizationName[MED_NAME_SIZE+1] = "";
1276 med_int nvalue = MEDfieldnValueWithProfile(FileId,
1280 fieldOverEntity->GetEntity().EntityType,
1281 fieldOverEntity->GetEntity().GeometryType,
1282 fop->GetMedIterator(),
1287 &nbofintegrationpoint);
1291 vtkErrorMacro("Error while reading MEDfieldnValueWithProfile");
1294 fop->SetProfileName(profileName);
1295 fop->SetLocalizationName(localizationName);
1296 fop->SetNumberOfValues(nvalue);
1297 fop->SetNumberOfIntegrationPoint(nbofintegrationpoint);
1298 fop->SetProfileSize(profilesize);
1301 void vtkMedDriver30::ReadMeshInformation(vtkMedMesh* mesh)
1303 FileOpen open(this);
1307 med_mesh_type meshtype;
1309 med_sorting_type sortingtype;
1311 med_axis_type axistype;
1314 if ( (naxis=MEDmeshnAxis(this->FileId, mesh->GetMedIterator())) <0 )
1316 vtkDebugMacro("Error reading mesh axis number");
1320 naxis=MEDmeshnAxis(this->FileId, mesh->GetMedIterator());
1322 char axisname[3*MED_SNAME_SIZE+1] = "";
1323 char axisunit[3*MED_SNAME_SIZE+1] = "";
1324 char name[MED_NAME_SIZE+1] = "";
1325 char description[MED_COMMENT_SIZE+1] = "";
1326 char timeUnit[MED_SNAME_SIZE+1] = "";
1328 if( MEDmeshInfo( this->FileId,
1329 mesh->GetMedIterator(),
1342 vtkErrorMacro("Error reading mesh");
1345 mesh->SetName(name);
1346 mesh->SetDescription(description);
1347 mesh->SetTimeUnit(timeUnit);
1348 mesh->SetSpaceDimension(sdim);
1349 mesh->SetMeshDimension(mdim);
1350 mesh->SetMeshType(meshtype);
1351 mesh->SetSortingType(sortingtype);
1352 mesh->SetAxisType(axistype);
1353 mesh->SetNumberOfAxis(naxis);
1355 for(int axis = 0; axis < naxis; axis++)
1357 char theaxisname[MED_SNAME_SIZE+1] = "";
1358 char theaxisunit[MED_SNAME_SIZE+1] = "";
1359 strncpy(theaxisname, axisname + axis*MED_SNAME_SIZE, MED_SNAME_SIZE);
1360 strncpy(theaxisunit, axisunit + axis*MED_SNAME_SIZE, MED_SNAME_SIZE);
1361 mesh->GetAxisName()->SetValue(axis, theaxisname);
1362 mesh->GetAxisUnit()->SetValue(axis, theaxisunit);
1365 char universalName[MED_LNAME_SIZE+1] = "";
1367 if(MEDmeshUniversalNameRd(this->FileId, name,
1370 vtkDebugMacro("MEDmeshUniversalNameRd < 0");
1372 mesh->SetUniversalName(universalName);
1374 // read the Information data of all families.
1375 // writing the family 0 is optional,
1376 // but I need it, so add it if it is not here.
1378 med_int nfam = MEDnFamily(this->FileId, name);
1380 for(int index = 0; index < nfam; index++)
1382 vtkMedFamily* family = vtkMedFamily::New();
1383 family->SetMedIterator(index + 1);
1384 this->ReadFamilyInformation(mesh, family);
1388 // this creates a family 0 if none has been read
1389 vtkMedFamily* familyZeroOnCell = mesh->GetOrCreateCellFamilyById(0);
1390 vtkMedFamily* familyZeroOnPoint = mesh->GetOrCreatePointFamilyById(0);
1392 // Load Information regarding the grid type
1393 if(meshtype == MED_STRUCTURED_MESH)
1395 // Do it for structured data
1397 if(MEDmeshGridTypeRd(FileId, name, &mtg) < 0)
1399 vtkErrorMacro("Error during structured grid Information loading.");
1402 mesh->SetStructuredGridType(mtg);
1405 vtkMedGrid* previousGrid = NULL;
1406 for(int gid=1; gid <= nstep; gid++)
1408 vtkMedComputeStep cs;
1409 if(MEDmeshComputationStepInfo(FileId,
1414 &cs.TimeOrFrequency) < 0)
1416 vtkErrorMacro("MEDmeshComputationStepInfo error");
1418 // Load Information regarding the grid type
1419 vtkMedGrid* grid = NULL;
1420 if(meshtype == MED_STRUCTURED_MESH)
1422 switch(mesh->GetStructuredGridType())
1424 case MED_CARTESIAN_GRID:
1425 grid = vtkMedCartesianGrid::New();
1427 case MED_POLAR_GRID:
1428 grid = vtkMedPolarGrid::New();
1430 case MED_CURVILINEAR_GRID:
1431 grid = vtkMedCurvilinearGrid::New();
1434 vtkErrorMacro("Unknown structured grid type " << mesh->GetStructuredGridType());
1438 else //(mesh->GetType() == MED_STRUCTURED_MESH)
1440 grid = vtkMedUnstructuredGrid::New();
1442 grid->SetParentMesh(mesh);
1443 grid->SetComputeStep(cs);
1444 this->ReadGridInformation(grid);
1445 mesh->AddGridStep(grid);
1447 grid->SetPreviousGrid(previousGrid);
1448 previousGrid = grid;
1452 void vtkMedDriver30::ReadLocalizationInformation(vtkMedLocalization* loc)
1454 FileOpen open(this);
1457 med_int spaceDimension;
1458 med_geometry_type type_geo;
1459 med_geometry_type sectiongeotype;
1460 med_int nsectionmeshcell;
1462 char name[MED_NAME_SIZE+1] = "";
1463 char interpolationName[MED_NAME_SIZE+1] = "";
1464 char sectionName[MED_NAME_SIZE+1] = "";
1466 if(MEDlocalizationInfo(
1468 loc->GetMedIterator(),
1476 §iongeotype ) < 0)
1478 vtkErrorMacro("Reading information on quadrature points definition : "
1479 << loc->GetMedIterator());
1483 loc->SetInterpolationName(interpolationName);
1484 loc->SetSectionName(sectionName);
1485 loc->SetNumberOfQuadraturePoint(ngp);
1486 loc->SetGeometryType(type_geo);
1487 loc->SetSpaceDimension(spaceDimension);
1488 loc->SetNumberOfCellInSection(nsectionmeshcell);
1489 loc->SetSectionGeometryType(sectiongeotype);
1491 med_float *localCoordinates = new med_float[loc->GetSizeOfPointLocalCoordinates()];
1492 med_float *pqLocalCoordinates = new med_float[loc->GetSizeOfQuadraturePointLocalCoordinates()];
1493 med_float *weights = new med_float[loc->GetSizeOfWeights()];
1495 if(MEDlocalizationRd(FileId,
1502 vtkErrorMacro("MEDlocalizationRd : " << loc->GetName());
1505 vtkDoubleArray* lc = loc->GetPointLocalCoordinates();
1506 vtkDoubleArray *pqlc = loc->GetQuadraturePointLocalCoordinates();
1507 vtkDoubleArray *w = loc->GetWeights();
1509 lc->SetNumberOfValues(loc->GetSizeOfPointLocalCoordinates());
1510 for(int i=0; i<loc->GetSizeOfPointLocalCoordinates(); i++)
1512 lc->SetValue(i, localCoordinates[i]);
1515 pqlc->SetNumberOfValues(loc->GetSizeOfQuadraturePointLocalCoordinates());
1516 for(int i=0; i<loc->GetSizeOfQuadraturePointLocalCoordinates(); i++)
1518 pqlc->SetValue(i, pqLocalCoordinates[i]);
1521 w->SetNumberOfValues(loc->GetSizeOfWeights());
1522 for(int i=0; i<loc->GetSizeOfWeights(); i++)
1524 w->SetValue(i, weights[i]);
1528 void vtkMedDriver30::ReadInterpolationInformation(vtkMedInterpolation* interp)
1531 med_geometry_type geotype;
1533 med_int nbofbasisfunc;
1534 med_int nbofvariable;
1538 char name[MED_NAME_SIZE+1] = "";
1540 if(MEDinterpInfo (this->FileId,
1541 interp->GetMedIterator(),
1543 &geotype, &cellnode, &nbofbasisfunc,
1544 &nbofvariable, &maxdegree, &nmaxcoef) < 0)
1546 vtkErrorMacro("MEDinterpInfo");
1550 interp->SetName(name);
1551 interp->SetGeometryType(geotype);
1552 interp->SetIsCellNode(cellnode);
1553 interp->SetNumberOfVariable(nbofvariable);
1554 interp->SetMaximumDegree(maxdegree);
1555 interp->SetMaximumNumberOfCoefficient(nmaxcoef);
1556 interp->AllocateNumberOfBasisFunction(nbofbasisfunc);
1558 for(int basisid=0; basisid < nbofbasisfunc; basisid++)
1560 vtkMedFraction* func = interp->GetBasisFunction(basisid);
1561 func->SetNumberOfVariable(nbofvariable);
1563 med_int ncoef = MEDinterpBaseFunctionCoefSize (
1567 func->SetNumberOfCoefficients(ncoef);
1569 if(ncoef <= 0 || nbofvariable <= 0)
1572 med_int *power = new med_int[nbofvariable * ncoef];
1573 med_float *coefficient = new med_float[ncoef];
1575 if(MEDinterpBaseFunctionRd (
1583 vtkErrorMacro("MEDinterpBaseFunctionRd");
1586 vtkDoubleArray* coeffs = func->GetCoefficients();
1587 for(int cid=0; cid < ncoef; cid++)
1589 coeffs->SetValue(cid, coefficient[cid]);
1591 vtkIntArray* powers = func->GetPowers();
1592 for(int pid=0; pid < ncoef*nbofvariable; pid++)
1594 powers->SetValue(pid, power[pid]);
1598 delete[] coefficient;
1602 void vtkMedDriver30::ReadSupportMeshInformation(
1603 vtkMedMesh* supportMesh)
1605 FileOpen open(this);
1607 char supportmeshname[MED_NAME_SIZE+1] = "";
1608 char description[MED_COMMENT_SIZE+1] = "";
1611 med_axis_type axistype;
1612 char axisname[3*MED_SNAME_SIZE+1] = "";
1613 char axisunit[3*MED_SNAME_SIZE+1] = "";
1615 if(MEDsupportMeshInfo (this->FileId,
1616 supportMesh->GetMedIterator(),
1625 vtkErrorMacro("MEDsupportMeshInfo");
1628 supportMesh->SetName(supportmeshname);
1629 supportMesh->SetDescription(description);
1630 supportMesh->SetSpaceDimension(spacedim);
1631 supportMesh->SetMeshDimension(meshdim);
1632 supportMesh->SetAxisType(axistype);
1633 for(int dim = 0; dim < 3; dim++)
1635 char axisname_dim[MED_SNAME_SIZE+1] = "";
1636 char axisunit_dim[MED_SNAME_SIZE+1] = "";
1638 strncpy(axisname_dim, axisname+dim*MED_SNAME_SIZE, MED_SNAME_SIZE);
1639 strncpy(axisunit_dim, axisunit+dim*MED_SNAME_SIZE, MED_SNAME_SIZE);
1641 supportMesh->GetAxisName()->SetValue(dim, axisname_dim);
1642 supportMesh->GetAxisUnit()->SetValue(dim, axisunit_dim);
1648 void vtkMedDriver30::LoadFamilyIds(vtkMedEntityArray* array)
1650 if(array->IsFamilyIdsLoaded())
1653 FileOpen open(this);
1655 vtkMedGrid* grid = array->GetParentGrid();
1657 vtkMedComputeStep cs = grid->GetComputeStep();
1659 // first, find if the family ids are implicit or explicit
1660 med_bool changement, transformation;
1662 med_int nfamid = MEDmeshnEntity(this->FileId,
1663 grid->GetParentMesh()->GetName(),
1666 array->GetEntity().EntityType,
1667 array->GetEntity().GeometryType,
1673 if(nfamid == array->GetNumberOfEntity())
1676 vtkMedIntArray* famIds = vtkMedIntArray::New();
1677 array->SetFamilyIds(famIds);
1680 famIds->SetNumberOfTuples(nfamid);
1682 if ( MEDmeshEntityFamilyNumberRd(
1684 grid->GetParentMesh()->GetName(),
1687 array->GetEntity().EntityType,
1688 array->GetEntity().GeometryType,
1689 famIds->GetPointer(0) ) < 0)
1691 vtkWarningMacro("Error loading the family ids of entity "
1692 << array->GetEntity().EntityType
1693 << " " << array->GetEntity().GeometryType
1694 << " on mesh " << grid->GetParentMesh()->GetName());
1695 array->SetFamilyIds(NULL);
1700 vtkDebugMacro("NumberOfEntity != Number of family ids");
1701 array->SetFamilyIds(NULL);
1704 array->ComputeFamilies();
1707 void vtkMedDriver30::LoadPointGlobalIds(vtkMedGrid* grid)
1709 if(grid->IsPointGlobalIdsLoaded())
1712 FileOpen open(this);
1714 vtkMedIntArray* globalIds = vtkMedIntArray::New();
1715 grid->SetPointGlobalIds(globalIds);
1716 globalIds->Delete();
1718 globalIds->SetNumberOfTuples(grid->GetNumberOfPoints());
1720 if( MEDmeshEntityNumberRd (
1722 grid->GetParentMesh()->GetName(),
1723 grid->GetComputeStep().TimeIt,
1724 grid->GetComputeStep().IterationIt,
1727 globalIds->GetPointer(0) ) < 0)
1729 grid->SetPointGlobalIds(NULL);
1733 void vtkMedDriver30::LoadCoordinates(vtkMedGrid* grid)
1735 if(grid->IsCoordinatesLoaded())
1738 vtkMedRegularGrid* rgrid = vtkMedRegularGrid::SafeDownCast(grid);
1741 this->LoadRegularGridCoordinates(rgrid);
1745 vtkMedUnstructuredGrid* ugrid = vtkMedUnstructuredGrid::SafeDownCast(grid);
1746 vtkMedCurvilinearGrid* cgrid = vtkMedCurvilinearGrid::SafeDownCast(grid);
1747 if(ugrid == NULL && cgrid == NULL)
1749 //TODO : deal with structured grids
1750 vtkWarningMacro("this kind of grid is not yet supported");
1754 if(grid->GetUsePreviousCoordinates())
1756 vtkMedGrid* previousgrid = grid->GetPreviousGrid();
1757 if(previousgrid == NULL)
1759 vtkErrorMacro("coordiantes have not changed, "
1760 << "but there is no previous grid!");
1764 this->LoadCoordinates(previousgrid);
1766 ugrid->SetCoordinates(vtkMedUnstructuredGrid::SafeDownCast(previousgrid)
1767 ->GetCoordinates());
1769 cgrid->SetCoordinates(vtkMedCurvilinearGrid::SafeDownCast(previousgrid)
1770 ->GetCoordinates());
1775 FileOpen open(this);
1777 vtkDataArray* coords = vtkMedUtilities::NewCoordArray();
1779 ugrid->SetCoordinates(coords);
1781 cgrid->SetCoordinates(coords);
1784 vtkMedComputeStep cs = grid->GetComputeStep();
1786 coords->SetNumberOfComponents(grid->GetParentMesh()->GetSpaceDimension());
1787 coords->SetNumberOfTuples(grid->GetNumberOfPoints());
1789 if ( MEDmeshNodeCoordinateRd( this->FileId,
1790 grid->GetParentMesh()->GetName(),
1794 (med_float*) coords->GetVoidPointer(0) ) < 0)
1796 vtkErrorMacro("Load Coordinates for mesh "
1797 << grid->GetParentMesh()->GetName());
1802 void vtkMedDriver30::LoadProfile(vtkMedProfile* profile)
1804 if(!profile || profile->IsLoaded())
1807 FileOpen open(this);
1809 vtkMedIntArray* indices = vtkMedIntArray::New();
1810 profile->SetIds(indices);
1813 indices->SetNumberOfTuples(profile->GetNumberOfElement());
1815 char name[MED_NAME_SIZE+1] = "";
1817 if( MEDprofileRd(this->FileId,
1819 indices->GetPointer(0) ) < 0)
1821 vtkErrorMacro("Reading profile indices ");
1825 void vtkMedDriver30::LoadConnectivity(vtkMedEntityArray* array)
1827 if(array->IsConnectivityLoaded())
1830 FileOpen open(this);
1832 vtkMedGrid* grid = array->GetParentGrid();
1834 grid = array->GetParentGrid();
1836 const char* meshName = grid->GetParentMesh()->GetName();
1838 vtkMedIntArray* conn = vtkMedIntArray::New();
1839 array->SetConnectivityArray(conn);
1842 vtkMedComputeStep cs = grid->GetComputeStep();
1845 med_bool transformation;
1847 if(array->GetEntity().GeometryType == MED_POLYGON)
1849 // first check if we have points
1850 med_int connSize = MEDmeshnEntity(
1855 array->GetEntity().EntityType,
1858 array->GetConnectivity(),
1864 vtkErrorMacro(<< "Error while reading polygons connectivity size."
1869 conn->SetNumberOfTuples(connSize);
1871 // How many polygon in the mesh in nodal connectivity mode
1872 // For the polygons, we get the size of array index
1874 if ((indexsize = MEDmeshnEntity(this->FileId,
1878 array->GetEntity().EntityType,
1881 array->GetConnectivity(),
1883 &transformation )) < 0)
1885 vtkErrorMacro(<< "Error while reading polygons array index." << endl );
1889 vtkMedIntArray* index = vtkMedIntArray::New();
1890 array->SetFaceIndex(index);
1893 index->SetNumberOfTuples( indexsize );
1895 if ( MEDmeshPolygonRd(this->FileId,
1899 array->GetEntity().EntityType,
1900 array->GetConnectivity(),
1901 index->GetPointer(0),
1902 conn->GetPointer(0) ) < 0)
1904 vtkErrorMacro(<< "MEDmeshPolygonRd");
1908 else if(array->GetEntity().GeometryType == MED_POLYHEDRON)
1911 vtkIdType connSize = MEDmeshnEntity(this->FileId,
1913 grid->GetComputeStep().TimeIt,
1914 grid->GetComputeStep().IterationIt,
1915 array->GetEntity().EntityType,
1918 array->GetConnectivity(),
1923 vtkErrorMacro(<< "Error while reading polyhedrons connectivity size."
1928 conn->SetNumberOfTuples(connSize);
1930 vtkMedIntArray* faceIndex = vtkMedIntArray::New();
1931 array->SetFaceIndex(faceIndex);
1932 faceIndex->Delete();
1934 vtkMedIntArray* nodeIndex = vtkMedIntArray::New();
1935 array->SetNodeIndex(nodeIndex);
1936 nodeIndex->Delete();
1938 vtkIdType np = array->GetNumberOfEntity() + 1;
1939 faceIndex->SetNumberOfTuples(np);
1941 med_int nodeIndexSize;
1943 if ((nodeIndexSize = MEDmeshnEntity(this->FileId,
1945 grid->GetComputeStep().TimeIt,
1946 grid->GetComputeStep().IterationIt,
1947 array->GetEntity().EntityType,
1950 array->GetConnectivity(),
1952 &transformation )) < 0)
1954 vtkErrorMacro(<< "Error while reading polygons array index." << endl );
1958 nodeIndex->SetNumberOfTuples(nodeIndexSize);
1960 if (MEDmeshPolyhedronRd(this->FileId,
1964 array->GetEntity().EntityType,
1965 array->GetConnectivity(),
1966 faceIndex->GetPointer(0),
1967 nodeIndex->GetPointer(0),
1968 conn->GetPointer(0) ) < 0)
1970 vtkErrorMacro("Error while reading connectivity of polyhedrons");
1977 bool doReadConnectivity = true;
1978 if(array->GetConnectivity() == MED_NODAL)
1980 if(array->GetEntity().EntityType == MED_STRUCT_ELEMENT)
1982 std::cout << " -- MED_STRUCT_ELEMENT --" << std::endl;
1983 if(array->GetStructElement() == NULL)
1985 vtkErrorMacro("Entity type = MED_STRUCT_ELEMENT, but StructElement is not set!");
1988 vtkIdType ntuple = array->GetNumberOfEntity()
1989 * array->GetStructElement()->GetConnectivitySize();
1991 conn->SetNumberOfTuples(ntuple);
1992 // particles are special : connectivity is not stored in the med file
1993 if(strcmp(array->GetStructElement()->GetName(), MED_PARTICLE_NAME) == 0 )
1995 for(vtkIdType cellId = 0; cellId < ntuple; cellId++)
1997 conn->SetValue(cellId, cellId+1);
1999 doReadConnectivity = false;
2004 conn->SetNumberOfTuples(array->GetNumberOfEntity()
2005 * vtkMedUtilities::GetNumberOfPoint(
2006 array->GetEntity().GeometryType));
2011 conn->SetNumberOfTuples(array->GetNumberOfEntity()
2012 * vtkMedUtilities::GetNumberOfSubEntity(
2013 array->GetEntity().GeometryType));
2016 if (this->ParallelFileId == -1) // also (array->GetFilter() == NULL)
2018 if ( (MEDmeshElementConnectivityRd(
2023 array->GetEntity().EntityType,
2024 array->GetEntity().GeometryType,
2025 array->GetConnectivity(),
2027 conn->GetPointer(0)) ) < 0)
2029 vtkErrorMacro("Error while load connectivity of cells "
2030 << array->GetEntity().GeometryType);
2035 med_filter filter = MED_FILTER_INIT;
2042 array->GetFilter()->GetFilterSizes(start, stride, count,
2043 blocksize, lastblocksize );
2045 med_int nbofconstituentpervalue = vtkMedUtilities::GetNumberOfNodes(
2046 array->GetEntity().GeometryType);
2048 if ( MEDfilterBlockOfEntityCr( this->ParallelFileId,
2049 array->GetNumberOfEntity(),
2050 1, // one is for mesh elements, more than 1 is for fields
2051 nbofconstituentpervalue,
2052 MED_ALL_CONSTITUENT,
2059 (med_size)blocksize,
2060 (med_size)lastblocksize,
2063 vtkErrorMacro("Filter creation ");
2066 if ( (MEDmeshElementConnectivityAdvancedRd(
2067 this->ParallelFileId,
2071 array->GetEntity().EntityType,
2072 array->GetEntity().GeometryType,
2073 array->GetConnectivity(),
2075 conn->GetPointer(0)) ) < 0)
2077 vtkErrorMacro("Error while load connectivity of cells "
2078 << array->GetEntity().GeometryType);
2081 if ( MEDfilterClose( &filter ) < 0)
2083 vtkErrorMacro("ERROR : filter closing ...");
2090 void vtkMedDriver30::LoadCellGlobalIds(vtkMedEntityArray* array)
2092 if(array->IsGlobalIdsLoaded())
2095 FileOpen open(this);
2097 vtkMedIntArray* globalIds = vtkMedIntArray::New();
2098 array->SetGlobalIds(globalIds);
2099 globalIds->Delete();
2101 globalIds->SetNumberOfTuples(array->GetNumberOfEntity());
2103 vtkMedGrid* grid = array->GetParentGrid();
2104 vtkMedComputeStep cs = grid->GetComputeStep();
2106 if( MEDmeshEntityNumberRd (
2108 grid->GetParentMesh()->GetName(),
2111 array->GetEntity().EntityType,
2112 array->GetEntity().GeometryType,
2113 globalIds->GetPointer(0) ) < 0)
2115 array->SetGlobalIds(NULL);
2119 void vtkMedDriver30::LoadField(vtkMedFieldOnProfile* fop, med_storage_mode mode)
2121 FileOpen open(this);
2123 vtkMedFieldOverEntity* fieldOverEntity = fop->GetParentFieldOverEntity();
2124 vtkMedFieldStep *step = fieldOverEntity->GetParentStep();
2125 vtkMedField* field = step->GetParentField();
2126 const vtkMedComputeStep& cs = step->GetComputeStep();
2128 vtkDataArray* data = vtkMedUtilities::NewArray(field->GetDataType());
2133 if(mode == MED_COMPACT_STMODE)
2135 size = fop->GetNumberOfValues();
2139 med_int profilesize;
2140 med_int nbofintegrationpoint;
2141 char profileName[MED_NAME_SIZE+1] = "";
2142 char localizationName[MED_NAME_SIZE+1] = "";
2143 size = MEDfieldnValueWithProfile(this->FileId,
2147 fieldOverEntity->GetEntity().EntityType,
2148 fieldOverEntity->GetEntity().GeometryType,
2149 fop->GetMedIterator(),
2154 &nbofintegrationpoint);
2157 if(fop->GetNumberOfIntegrationPoint() > 1)
2159 size *= fop->GetNumberOfIntegrationPoint();
2162 data->SetNumberOfComponents(field->GetNumberOfComponent());
2163 data->SetNumberOfTuples(size);
2164 if (this->ParallelFileId == -1)
2166 if ( MEDfieldValueWithProfileRd(
2171 fieldOverEntity->GetEntity().EntityType,
2172 fieldOverEntity->GetEntity().GeometryType,
2174 fop->GetProfileName(),
2176 MED_ALL_CONSTITUENT,
2177 (unsigned char*) data->GetVoidPointer(0) ) < 0)
2179 vtkErrorMacro("Error on MEDfieldValueWithProfileRd");
2184 if (field->GetFieldType() == vtkMedField::CellField)
2186 med_filter filter = MED_FILTER_INIT;
2193 fop->GetFilter()->GetFilterSizes(start, stride, count,
2194 blocksize, lastblocksize );
2196 if ( MEDfilterBlockOfEntityCr( this->ParallelFileId,
2197 fop->GetNumberOfValues(),
2198 1, // one is for mesh elements, more than 1 is for fields
2199 field->GetNumberOfComponent(),
2200 MED_ALL_CONSTITUENT,
2207 (med_size)blocksize,
2208 (med_size)lastblocksize,
2211 vtkErrorMacro("Filter creation ");
2214 if ( MEDfieldValueAdvancedRd(
2215 this->ParallelFileId,
2219 fieldOverEntity->GetEntity().EntityType,
2220 fieldOverEntity->GetEntity().GeometryType,
2222 (unsigned char*) data->GetVoidPointer(0) ) < 0)
2224 vtkErrorMacro("Error on MEDfieldValueAdvancedRd");
2227 if ( MEDfilterClose( &filter ) < 0)
2229 vtkErrorMacro("ERROR : filter closing ...");
2233 {//TODO : option utilisateur pour desactiver ou non les champs avec profile en //
2234 if ( MEDfieldValueWithProfileRd(
2239 fieldOverEntity->GetEntity().EntityType,
2240 fieldOverEntity->GetEntity().GeometryType,
2242 fop->GetProfileName(),
2244 MED_ALL_CONSTITUENT,
2245 (unsigned char*) data->GetVoidPointer(0) ) < 0)
2247 vtkErrorMacro("Error on MEDfieldValueWithProfileRd");
2253 void vtkMedDriver30::LoadVariableAttribute(vtkMedVariableAttribute* varatt,
2254 vtkMedEntityArray* array)
2256 FileOpen open(this);
2260 vtkAbstractArray* valuearray = array->GetVariableAttributeValue(varatt);
2261 // first test if this is already loaded
2262 if(valuearray != NULL && valuearray->GetNumberOfTuples() > 0)
2265 if(valuearray == NULL)
2267 valuearray = vtkMedUtilities::NewArray(varatt->GetAttributeType());
2268 array->SetVariableAttributeValues(varatt, valuearray);
2269 valuearray->Delete();
2272 valuearray->SetNumberOfComponents(varatt->GetNumberOfComponent());
2273 valuearray->SetNumberOfTuples(array->GetNumberOfEntity());
2274 valuearray->SetName(varatt->GetName());
2276 vtkSmartPointer<vtkCharArray> chararray = vtkSmartPointer<vtkCharArray>::New();
2278 if(varatt->GetAttributeType() != MED_ATT_NAME)
2280 value = valuearray->GetVoidPointer(0);
2284 chararray->SetNumberOfValues(varatt->GetNumberOfComponent() *
2285 array->GetNumberOfEntity() *
2288 value = chararray->GetVoidPointer(0);
2291 vtkMedComputeStep cs = array->GetParentGrid()->GetComputeStep();
2293 if(MEDmeshStructElementVarAttRd(
2295 array->GetParentGrid()->GetParentMesh()->GetName(),
2298 varatt->GetParentStructElement()->GetGeometryType(),
2303 if(cs.IterationIt == MED_NO_IT && cs.TimeIt == MED_NO_DT && cs.TimeOrFrequency == MED_UNDEF_DT)
2305 vtkErrorMacro("MEDmeshStructElementVarAttRd");
2308 // try to see if I can reuse
2309 // the variable attributes of the NO_DT, NO_IT compute step
2310 vtkMedComputeStep nocs;
2311 nocs.IterationIt = MED_NO_IT;
2312 nocs.TimeIt = MED_NO_DT;
2313 nocs.TimeOrFrequency = MED_UNDEF_DT;
2314 vtkMedEntityArray* nocs_array =
2315 array->GetParentGrid()->GetParentMesh()->GetGridStep(nocs)->GetEntityArray(array->GetEntity());
2316 if(nocs_array == NULL)
2318 nocs_array = array->GetParentGrid()->GetParentMesh()->GetGridStep(0)->GetEntityArray(array->GetEntity());
2321 if(nocs_array == NULL || nocs_array == array)
2323 // try to force load the default compute step.
2324 if(MEDmeshStructElementVarAttRd(
2326 array->GetParentGrid()->GetParentMesh()->GetName(),
2329 varatt->GetParentStructElement()->GetGeometryType(),
2333 vtkErrorMacro("MEDmeshStructElementVarAttRd");
2339 this->LoadVariableAttribute(varatt, nocs_array);
2340 array->SetVariableAttributeValues(varatt, nocs_array->GetVariableAttributeValue(varatt));
2345 // If I am here, it means that I read the values
2346 if(varatt->GetAttributeType() == MED_ATT_NAME)
2348 char current_name[MED_NAME_SIZE+1] = "";
2349 vtkStringArray* sarray = vtkStringArray::SafeDownCast(valuearray);
2350 for(vtkIdType id = 0; id < varatt->GetNumberOfComponent() *
2351 array->GetNumberOfEntity(); id++)
2353 memset(current_name, '\0', MED_NAME_SIZE+1);
2354 strncpy(current_name, ((char*)value) + id*MED_NAME_SIZE, MED_NAME_SIZE);
2355 sarray->SetValue(id, current_name);
2362 void vtkMedDriver30::PrintSelf(ostream& os, vtkIndent indent)
2364 this->Superclass::PrintSelf(os, indent);