PR: downward connectivity

This commit is contained in:
prascle 2010-07-01 14:46:31 +00:00
parent aa67cc96d7
commit a399364c85
26 changed files with 3614 additions and 703 deletions

View File

@ -40,6 +40,7 @@ STRIP_FROM_PATH = @top_srcdir@ @top_builddir@
STRIP_FROM_INC_PATH = STRIP_FROM_INC_PATH =
SHORT_NAMES = NO SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = YES JAVADOC_AUTOBRIEF = YES
QT_AUTOBRIEF = YES
MULTILINE_CPP_IS_BRIEF = NO MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO DETAILS_AT_TOP = NO
INHERIT_DOCS = YES INHERIT_DOCS = YES

View File

@ -1,17 +1,17 @@
/*========================================================================= /*=========================================================================
Program: ParaView Program: ParaView
Module: $RCSfile$ Module: $RCSfile$
Copyright (c) Kitware, Inc. Copyright (c) Kitware, Inc.
All rights reserved. All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details. See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information. PURPOSE. See the above copyright notice for more information.
=========================================================================*/ =========================================================================*/
#include "SMESH_vtkPVUpdateSuppressor.h" #include "SMESH_vtkPVUpdateSuppressor.h"
#include "vtkAlgorithmOutput.h" #include "vtkAlgorithmOutput.h"
@ -40,8 +40,10 @@
# define vtkMyDebug(x) # define vtkMyDebug(x)
#endif #endif
vtkCxxRevisionMacro(vtkPVUpdateSuppressor, "$Revision$"); vtkCxxRevisionMacro(vtkPVUpdateSuppressor, "$Revision$")
vtkStandardNewMacro(vtkPVUpdateSuppressor); ;
vtkStandardNewMacro(vtkPVUpdateSuppressor)
;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
vtkPVUpdateSuppressor::vtkPVUpdateSuppressor() vtkPVUpdateSuppressor::vtkPVUpdateSuppressor()
{ {
@ -51,16 +53,15 @@ vtkPVUpdateSuppressor::vtkPVUpdateSuppressor()
this->UpdateTime = 0.0; this->UpdateTime = 0.0;
this->UpdateTimeInitialized = false; this->UpdateTimeInitialized = false;
this->Enabled = 1; this->Enabled = 1;
// vtkProcessModule* pm = vtkProcessModule::GetProcessModule(); // vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
// //
// if (pm) // if (pm)
// { // {
// this->UpdateNumberOfPieces = pm->GetNumberOfLocalPartitions(); // this->UpdateNumberOfPieces = pm->GetNumberOfLocalPartitions();
// this->UpdatePiece = pm->GetPartitionId(); // this->UpdatePiece = pm->GetPartitionId();
// } // }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -74,8 +75,8 @@ void vtkPVUpdateSuppressor::SetUpdateTime(double utime)
this->UpdateTimeInitialized = true; this->UpdateTimeInitialized = true;
if (this->UpdateTime != utime) if (this->UpdateTime != utime)
{ {
this->Modified(); this->Modified();
this->UpdateTime = utime; this->UpdateTime = utime;
} }
} }
@ -84,29 +85,29 @@ void vtkPVUpdateSuppressor::SetEnabled(int enable)
{ {
if (this->Enabled == enable) if (this->Enabled == enable)
{ {
return; return;
} }
this->Enabled = enable; this->Enabled = enable;
this->Modified(); this->Modified();
// vtkUpdateSuppressorPipeline* executive = // vtkUpdateSuppressorPipeline* executive =
// vtkUpdateSuppressorPipeline::SafeDownCast(this->GetExecutive()); // vtkUpdateSuppressorPipeline::SafeDownCast(this->GetExecutive());
// if (executive) // if (executive)
// { // {
// executive->SetEnabled(enable); // executive->SetEnabled(enable);
// } // }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void vtkPVUpdateSuppressor::ForceUpdate() void vtkPVUpdateSuppressor::ForceUpdate()
{ {
// Make sure that output type matches input type // Make sure that output type matches input type
this->UpdateInformation(); this->UpdateInformation();
vtkDataObject *input = this->GetInput(); vtkDataObject *input = this->GetInput();
if (input == 0) if (input == 0)
{ {
vtkErrorMacro("No valid input."); vtkErrorMacro("No valid input.");
return; return;
} }
vtkDataObject *output = this->GetOutput(); vtkDataObject *output = this->GetOutput();
@ -115,41 +116,38 @@ void vtkPVUpdateSuppressor::ForceUpdate()
// Client needs to modify the collection filter because it is not // Client needs to modify the collection filter because it is not
// connected to a pipeline. // connected to a pipeline.
vtkAlgorithm *source = input->GetProducerPort()->GetProducer(); vtkAlgorithm *source = input->GetProducerPort()->GetProducer();
if (source && if (source && (source->IsA("vtkMPIMoveData")
(source->IsA("vtkMPIMoveData") || || source->IsA("vtkCollectPolyData") || source->IsA("vtkM2NDuplicate")
source->IsA("vtkCollectPolyData") || || source->IsA("vtkM2NCollect")
source->IsA("vtkM2NDuplicate") || || source->IsA("vtkOrderedCompositeDistributor")
source->IsA("vtkM2NCollect") || || source->IsA("vtkClientServerMoveData")))
source->IsA("vtkOrderedCompositeDistributor") ||
source->IsA("vtkClientServerMoveData")))
{ {
source->Modified(); source->Modified();
} }
vtkInformation* info = input->GetPipelineInformation(); vtkInformation* info = input->GetPipelineInformation();
vtkStreamingDemandDrivenPipeline* sddp = vtkStreamingDemandDrivenPipeline
vtkStreamingDemandDrivenPipeline::SafeDownCast( * sddp =
vtkExecutive::PRODUCER()->GetExecutive(info)); vtkStreamingDemandDrivenPipeline::SafeDownCast(
vtkExecutive::PRODUCER()->GetExecutive(
info));
if (sddp) if (sddp)
{ {
sddp->SetUpdateExtent(info, sddp->SetUpdateExtent(info, this->UpdatePiece,
this->UpdatePiece, this->UpdateNumberOfPieces, 0);
this->UpdateNumberOfPieces,
0);
} }
else else
{ {
input->SetUpdatePiece(this->UpdatePiece); input->SetUpdatePiece(this->UpdatePiece);
input->SetUpdateNumberOfPieces(this->UpdateNumberOfPieces); input->SetUpdateNumberOfPieces(this->UpdateNumberOfPieces);
input->SetUpdateGhostLevel(0); input->SetUpdateGhostLevel(0);
} } vtkMyDebug("ForceUpdate ");
vtkMyDebug("ForceUpdate ");
if (this->UpdateTimeInitialized) if (this->UpdateTimeInitialized)
{ {
info->Set(vtkCompositeDataPipeline::UPDATE_TIME_STEPS(), &this->UpdateTime, 1); info->Set(vtkCompositeDataPipeline::UPDATE_TIME_STEPS(),
vtkMyDebug(this->UpdateTime); &this->UpdateTime, 1);
} vtkMyDebug(this->UpdateTime);
vtkMyDebug(endl); } vtkMyDebug(endl);
input->Update(); input->Update();
// Input may have changed, we obtain the pointer again. // Input may have changed, we obtain the pointer again.
@ -159,7 +157,6 @@ void vtkPVUpdateSuppressor::ForceUpdate()
this->PipelineUpdateTime.Modified(); this->PipelineUpdateTime.Modified();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
vtkExecutive* vtkPVUpdateSuppressor::CreateDefaultExecutive() vtkExecutive* vtkPVUpdateSuppressor::CreateDefaultExecutive()
{ {
@ -170,35 +167,36 @@ vtkExecutive* vtkPVUpdateSuppressor::CreateDefaultExecutive()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
int vtkPVUpdateSuppressor::RequestDataObject( int vtkPVUpdateSuppressor::RequestDataObject(
vtkInformation* vtkNotUsed(reqInfo), vtkInformation* vtkNotUsed(reqInfo),
vtkInformationVector** inputVector , vtkInformationVector** inputVector,
vtkInformationVector* outputVector) vtkInformationVector* outputVector)
{ {
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
if (!inInfo) if (!inInfo)
{ {
return 0; return 0;
} }
vtkDataObject *input = inInfo->Get(vtkDataObject::DATA_OBJECT()); vtkDataObject *input = inInfo->Get(vtkDataObject::DATA_OBJECT());
if (input) if (input)
{ {
// for each output // for each output
for(int i=0; i < this->GetNumberOfOutputPorts(); ++i) for (int i = 0; i < this->GetNumberOfOutputPorts(); ++i)
{
vtkInformation* outInfo = outputVector->GetInformationObject(i);
vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
if (!output || !output->IsA(input->GetClassName()))
{ {
vtkDataObject* newOutput = input->NewInstance(); vtkInformation* outInfo = outputVector->GetInformationObject(i);
newOutput->SetPipelineInformation(outInfo); vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
newOutput->Delete();
this->GetOutputPortInformation(i)->Set( if (!output || !output->IsA(input->GetClassName()))
vtkDataObject::DATA_EXTENT_TYPE(), newOutput->GetExtentType()); {
vtkDataObject* newOutput = input->NewInstance();
newOutput->SetPipelineInformation(outInfo);
newOutput->Delete();
this->GetOutputPortInformation(i)->Set(
vtkDataObject::DATA_EXTENT_TYPE(),
newOutput->GetExtentType());
}
} }
} return 1;
return 1;
} }
return 0; return 0;
@ -223,9 +221,10 @@ int vtkPVUpdateSuppressor::RequestData(vtkInformation* vtkNotUsed(reqInfo),
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void vtkPVUpdateSuppressor::PrintSelf(ostream& os, vtkIndent indent) void vtkPVUpdateSuppressor::PrintSelf(ostream& os, vtkIndent indent)
{ {
this->Superclass::PrintSelf(os,indent); this->Superclass::PrintSelf(os, indent);
os << indent << "UpdatePiece: " << this->UpdatePiece << endl; os << indent << "UpdatePiece: " << this->UpdatePiece << endl;
os << indent << "UpdateNumberOfPieces: " << this->UpdateNumberOfPieces << endl; os << indent << "UpdateNumberOfPieces: " << this->UpdateNumberOfPieces
<< endl;
os << indent << "Enabled: " << this->Enabled << endl; os << indent << "Enabled: " << this->Enabled << endl;
os << indent << "UpdateTime: " << this->UpdateTime << endl; os << indent << "UpdateTime: " << this->UpdateTime << endl;
} }

View File

@ -1,17 +1,17 @@
/*========================================================================= /*=========================================================================
Program: ParaView Program: ParaView
Module: $RCSfile$ Module: $RCSfile$
Copyright (c) Kitware, Inc. Copyright (c) Kitware, Inc.
All rights reserved. All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details. See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information. PURPOSE. See the above copyright notice for more information.
=========================================================================*/ =========================================================================*/
// .NAME vtkPVUpdateSuppressor - prevents propagation of update // .NAME vtkPVUpdateSuppressor - prevents propagation of update
// .SECTION Description // .SECTION Description
// vtkPVUpdateSuppressor now uses the vtkProcessModule singleton to set up the // vtkPVUpdateSuppressor now uses the vtkProcessModule singleton to set up the
@ -25,10 +25,11 @@
#include "vtkDataObjectAlgorithm.h" #include "vtkDataObjectAlgorithm.h"
class VTK_EXPORT vtkPVUpdateSuppressor : public vtkDataObjectAlgorithm class VTK_EXPORT vtkPVUpdateSuppressor: public vtkDataObjectAlgorithm
{ {
public: public:
vtkTypeRevisionMacro(vtkPVUpdateSuppressor,vtkDataObjectAlgorithm); vtkTypeRevisionMacro(vtkPVUpdateSuppressor,vtkDataObjectAlgorithm)
;
void PrintSelf(ostream& os, vtkIndent indent); void PrintSelf(ostream& os, vtkIndent indent);
// Description: // Description:
@ -44,30 +45,37 @@ public:
// This causes the filter to ingore the request from the output. // This causes the filter to ingore the request from the output.
// It is here because the user may not have celled update on the output // It is here because the user may not have celled update on the output
// before calling force update (it is an easy fix). // before calling force update (it is an easy fix).
vtkSetMacro(UpdatePiece, int); vtkSetMacro(UpdatePiece, int)
vtkGetMacro(UpdatePiece, int); ;
vtkSetMacro(UpdateNumberOfPieces, int); vtkGetMacro(UpdatePiece, int)
vtkGetMacro(UpdateNumberOfPieces, int); ;
vtkSetMacro(UpdateNumberOfPieces, int)
;
vtkGetMacro(UpdateNumberOfPieces, int)
;
// Description: // Description:
// Get/Set if the update suppressor is enabled. If the update suppressor // Get/Set if the update suppressor is enabled. If the update suppressor
// is not enabled, it won't supress any updates. Enabled by default. // is not enabled, it won't supress any updates. Enabled by default.
void SetEnabled(int); void SetEnabled(int);
vtkGetMacro(Enabled, int); vtkGetMacro(Enabled, int)
;
// Description: // Description:
// Get/Set the update time that is sent up the pipeline. // Get/Set the update time that is sent up the pipeline.
void SetUpdateTime(double utime); void SetUpdateTime(double utime);
vtkGetMacro(UpdateTime, double); vtkGetMacro(UpdateTime, double)
;
protected: protected:
vtkPVUpdateSuppressor(); vtkPVUpdateSuppressor();
~vtkPVUpdateSuppressor(); ~vtkPVUpdateSuppressor();
int RequestDataObject(vtkInformation* request, vtkInformationVector **inputVector, int RequestDataObject(vtkInformation* request,
vtkInformationVector *outputVector); vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
int RequestData(vtkInformation* request, vtkInformationVector **inputVector, int RequestData(vtkInformation* request, vtkInformationVector **inputVector,
vtkInformationVector *outputVector); vtkInformationVector *outputVector);
int UpdatePiece; int UpdatePiece;
int UpdateNumberOfPieces; int UpdateNumberOfPieces;
@ -79,13 +87,12 @@ protected:
vtkTimeStamp PipelineUpdateTime; vtkTimeStamp PipelineUpdateTime;
// Create a default executive. // Create a default executive.
virtual vtkExecutive* CreateDefaultExecutive(); virtual vtkExecutive* CreateDefaultExecutive();
private: private:
vtkPVUpdateSuppressor(const vtkPVUpdateSuppressor&); // Not implemented. vtkPVUpdateSuppressor(const vtkPVUpdateSuppressor&); // Not implemented.
void operator=(const vtkPVUpdateSuppressor&); // Not implemented. void operator=(const vtkPVUpdateSuppressor&); // Not implemented.
}; };
#endif #endif

View File

@ -27,6 +27,7 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am
# header files # header files
salomeinclude_HEADERS = \ salomeinclude_HEADERS = \
chrono.hxx \
ObjectPool.hxx \ ObjectPool.hxx \
SMDS_TypeOfPosition.hxx \ SMDS_TypeOfPosition.hxx \
SMDSAbs_ElementType.hxx \ SMDSAbs_ElementType.hxx \
@ -71,6 +72,7 @@ salomeinclude_HEADERS = \
SMESH_SMDS.hxx \ SMESH_SMDS.hxx \
SMDS_MeshInfo.hxx \ SMDS_MeshInfo.hxx \
SMDS_UnstructuredGrid.hxx \ SMDS_UnstructuredGrid.hxx \
SMDS_Downward.hxx \
SMDS_StdIterator.hxx SMDS_StdIterator.hxx
@ -78,6 +80,7 @@ salomeinclude_HEADERS = \
lib_LTLIBRARIES = libSMDS.la lib_LTLIBRARIES = libSMDS.la
dist_libSMDS_la_SOURCES = \ dist_libSMDS_la_SOURCES = \
chrono.cxx \
SMDS_MeshObject.cxx \ SMDS_MeshObject.cxx \
SMDS_MeshElement.cxx \ SMDS_MeshElement.cxx \
SMDS_MeshCell.cxx \ SMDS_MeshCell.cxx \
@ -112,7 +115,8 @@ dist_libSMDS_la_SOURCES = \
SMDS_QuadraticEdge.cxx \ SMDS_QuadraticEdge.cxx \
SMDS_QuadraticFaceOfNodes.cxx \ SMDS_QuadraticFaceOfNodes.cxx \
SMDS_QuadraticVolumeOfNodes.cxx \ SMDS_QuadraticVolumeOfNodes.cxx \
SMDS_UnstructuredGrid.cxx SMDS_UnstructuredGrid.cxx \
SMDS_Downward.cxx
# additionnal information to compil and link file # additionnal information to compil and link file
libSMDS_la_CPPFLAGS = \ libSMDS_la_CPPFLAGS = \

View File

@ -19,10 +19,10 @@ private:
{ {
for (int i = _nextFree; i < _maxAvail; i++) for (int i = _nextFree; i < _maxAvail; i++)
if (_freeList[i] == true) if (_freeList[i] == true)
{ {
return i; return i;
break; break;
} }
return _maxAvail; return _maxAvail;
} }
@ -60,21 +60,21 @@ public:
X *obj = 0; X *obj = 0;
_nextFree = getNextFree(); _nextFree = getNextFree();
if (_nextFree == _maxAvail) if (_nextFree == _maxAvail)
{ {
X* newChunk = new X[_chunkSize]; X* newChunk = new X[_chunkSize];
_chunkList.push_back(newChunk); _chunkList.push_back(newChunk);
_freeList.insert(_freeList.end(), _chunkSize, true); _freeList.insert(_freeList.end(), _chunkSize, true);
_maxAvail += _chunkSize; _maxAvail += _chunkSize;
_freeList[_nextFree] = false; _freeList[_nextFree] = false;
obj = newChunk; // &newChunk[0]; obj = newChunk; // &newChunk[0];
} }
else else
{ {
int chunkId = _nextFree / _chunkSize; int chunkId = _nextFree / _chunkSize;
int rank = _nextFree - chunkId * _chunkSize; int rank = _nextFree - chunkId * _chunkSize;
_freeList[_nextFree] = false; _freeList[_nextFree] = false;
obj = _chunkList[chunkId] + rank; // &_chunkList[chunkId][rank]; obj = _chunkList[chunkId] + rank; // &_chunkList[chunkId][rank];
} }
//obj->init(); //obj->init();
return obj; return obj;
} }
@ -83,32 +83,32 @@ public:
{ {
long adrobj = (long) (obj); long adrobj = (long) (obj);
for (int i = 0; i < _chunkList.size(); i++) for (int i = 0; i < _chunkList.size(); i++)
{ {
X* chunk = _chunkList[i]; X* chunk = _chunkList[i];
long adrmin = (long) (chunk); long adrmin = (long) (chunk);
if (adrobj < adrmin) if (adrobj < adrmin)
continue; continue;
long adrmax = (long) (chunk + _chunkSize); long adrmax = (long) (chunk + _chunkSize);
if (adrobj >= adrmax) if (adrobj >= adrmax)
continue; continue;
int rank = (adrobj - adrmin) / sizeof(X); int rank = (adrobj - adrmin) / sizeof(X);
int toFree = i * _chunkSize + rank; int toFree = i * _chunkSize + rank;
_freeList[toFree] = true; _freeList[toFree] = true;
if (toFree < _nextFree) if (toFree < _nextFree)
_nextFree = toFree; _nextFree = toFree;
//obj->clean(); //obj->clean();
//checkDelete(i); compactage non fait //checkDelete(i); compactage non fait
break; break;
} }
} }
// void destroy(int toFree) // void destroy(int toFree)
// { // {
// // no control 0<= toFree < _freeList.size() // // no control 0<= toFree < _freeList.size()
// _freeList[toFree] = true; // _freeList[toFree] = true;
// if (toFree < _nextFree) // if (toFree < _nextFree)
// _nextFree = toFree; // _nextFree = toFree;
// } // }
}; };

1889
src/SMDS/SMDS_Downward.cxx Normal file

File diff suppressed because it is too large Load Diff

327
src/SMDS/SMDS_Downward.hxx Normal file
View File

@ -0,0 +1,327 @@
/*
* SMDS_Downward.hxx
*
* Created on: Jun 3, 2010
* Author: prascle
*/
#ifndef SMDS_DOWNWARD_HXX_
#define SMDS_DOWNWARD_HXX_
#include "SMDS_UnstructuredGrid.hxx"
#include <vector>
#include <set>
typedef struct
{
int nodeIds[8]; //!< max number of nodes in a face or edge: quad quad = 8
int nbNodes;
unsigned char vtkType;
} ElemByNodesType; // TODO resize for polyhedrons
typedef struct
{
ElemByNodesType elems[6]; //!< max number of faces in a volume or edges in a face : hexahedron = 6
int nbElems;
} ListElemByNodesType; // TODO resize for polyhedrons
class SMDS_Downward
{
friend class SMDS_UnstructuredGrid;
friend class SMDS_Down2D;
friend class SMDS_Down3D;
public:
virtual int getNumberOfDownCells(int cellId);
virtual const int* getDownCells(int cellId);
virtual const unsigned char* getDownTypes(int cellId);
virtual int getNumberOfUpCells(int cellId) = 0;
virtual const int* getUpCells(int cellId) = 0;
virtual const unsigned char* getUpTypes(int cellId) = 0;
int getVtkCellId(int cellId)
{
return _vtkCellIds[cellId];
}
int getMaxId()
{
return _maxId;
}
static int getCellDimension(unsigned char cellType);
protected:
SMDS_Downward(SMDS_UnstructuredGrid *grid, int nbDownCells);
~SMDS_Downward();
int addCell(int vtkId = -1);
virtual void initCell(int cellId);
virtual void allocate(int nbElems) = 0;
virtual void compactStorage() = 0;
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
virtual void addUpCell(int cellId, int upCellId, unsigned char aType); //!< Id's are downward connectivity id's
virtual int getNodeSet(int cellId, int* nodeSet);
SMDS_UnstructuredGrid* _grid;
int _maxId;
int _nbDownCells; //!< the same number for all cells of a derived class
std::vector<int> _cellIds; //!< growing size: all the down cell id's, size = _maxId * _nbDownCells
std::vector<int> _vtkCellIds; //!< growing size: size = _maxId, either vtkId or -1
std::vector<unsigned char> _cellTypes; //!< fixed size: the same vector for all cells of a derived class
static std::vector<int> _cellDimension; //!< conversion table: type --> dimension
};
class SMDS_Down1D: public SMDS_Downward
{
friend class SMDS_UnstructuredGrid;
public:
virtual int getNumberOfUpCells(int cellId);
virtual const int* getUpCells(int cellId);
virtual const unsigned char* getUpTypes(int cellId);
protected:
SMDS_Down1D(SMDS_UnstructuredGrid *grid, int nbDownCells);
~SMDS_Down1D();
virtual void initCell(int cellId);
virtual void allocate(int nbElems);
virtual void compactStorage();
virtual void addUpCell(int cellId, int upCellId, unsigned char aType); //!< Id's are downward connectivity id's
virtual int getNodeSet(int cellId, int* nodeSet);
void setNodes(int cellId, int vtkId);
void setNodes(int cellId, const int* nodeIds);
int computeVtkCells(int cellId, std::vector<int>& vtkIds);
int computeVtkCells(int* pts, std::vector<int>& vtkIds);
int computeFaces(int cellId, int* vtkIds, int nbcells, int* downFaces, unsigned char* downTypes);
int computeFaces(int* pts, int* vtkIds, int nbcells, int* downFaces, unsigned char* downTypes);
std::vector<std::vector<int> > _upCellIdsVector; //!< the number of faces sharing an edge is not known
std::vector<std::vector<unsigned char> > _upCellTypesVector; //!< the number of faces sharing an edge is not known
std::vector<int> _upCellIds; //!< compacted storage after connectivity calculation
std::vector<unsigned char> _upCellTypes; //!< compacted storage after connectivity calculation
std::vector<int> _upCellIndex; //!< compacted storage after connectivity calculation
};
class SMDS_Down2D: public SMDS_Downward
{
friend class SMDS_UnstructuredGrid;
friend class SMDS_Down1D;
public:
virtual int getNumberOfUpCells(int cellId);
virtual const int* getUpCells(int cellId);
virtual const unsigned char* getUpTypes(int cellId);
protected:
SMDS_Down2D(SMDS_UnstructuredGrid *grid, int nbDownCells);
~SMDS_Down2D();
virtual void allocate(int nbElems);
virtual void compactStorage();
virtual void addUpCell(int cellId, int upCellId, unsigned char aType);
virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& facesWithNodes) = 0;
virtual int getNodeSet(int cellId, int* nodeSet);
int computeVolumeIds(int cellId, int* ids);
int computeVolumeIds(ElemByNodesType& faceByNodes, int* ids);
int computeVolumeIdsFromNodesFace(int* nodes, int nbNodes, int* ids);
void setTempNodes(int cellId, int vtkId);
void setTempNodes(int cellId, ElemByNodesType& faceByNodes);
bool isInFace(int cellId, int *pts, int npts);
int FindEdgeByNodes(int cellId, ElemByNodesType& edgeByNodes);
std::vector<int> _upCellIds; //!< 2 volumes max. per face
std::vector<unsigned char> _upCellTypes; //!< 2 volume types per face
std::vector<int> _tempNodes; //!< temporary storage of nodes, until downward connectivity completion
int _nbNodes; //!< number of nodes in a face
};
class SMDS_Down3D: public SMDS_Downward
{
friend class SMDS_UnstructuredGrid;
public:
virtual int getNumberOfUpCells(int cellId);
virtual const int* getUpCells(int cellId);
virtual const unsigned char* getUpTypes(int cellId);
protected:
SMDS_Down3D(SMDS_UnstructuredGrid *grid, int nbDownCells);
~SMDS_Down3D();
virtual void allocate(int nbElems);
virtual void compactStorage();
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes) = 0;
int FindFaceByNodes(int cellId, ElemByNodesType& faceByNodes);
};
class SMDS_DownEdge: public SMDS_Down1D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownEdge(SMDS_UnstructuredGrid *grid);
~SMDS_DownEdge();
};
class SMDS_DownQuadEdge: public SMDS_Down1D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownQuadEdge(SMDS_UnstructuredGrid *grid);
~SMDS_DownQuadEdge();
};
class SMDS_DownTriangle: public SMDS_Down2D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownTriangle(SMDS_UnstructuredGrid *grid);
~SMDS_DownTriangle();
virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
};
class SMDS_DownQuadTriangle: public SMDS_Down2D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownQuadTriangle(SMDS_UnstructuredGrid *grid);
~SMDS_DownQuadTriangle();
virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
};
class SMDS_DownQuadrangle: public SMDS_Down2D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownQuadrangle(SMDS_UnstructuredGrid *grid);
~SMDS_DownQuadrangle();
virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
};
class SMDS_DownQuadQuadrangle: public SMDS_Down2D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownQuadQuadrangle(SMDS_UnstructuredGrid *grid);
~SMDS_DownQuadQuadrangle();
virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
};
//class SMDS_DownPolygon: public SMDS_Down2D
//{
//public:
// SMDS_DownPolygon(SMDS_UnstructuredGrid *grid);
// ~SMDS_DownPolygon();
//protected:
//};
//class SMDS_DownQuadPolygon: public SMDS_Down2D
//{
//public:
// SMDS_DownQuadPolygon(SMDS_UnstructuredGrid *grid);
// ~SMDS_DownQuadPolygon();
//protected:
//};
class SMDS_DownTetra: public SMDS_Down3D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownTetra(SMDS_UnstructuredGrid *grid);
~SMDS_DownTetra();
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
};
class SMDS_DownQuadTetra: public SMDS_Down3D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownQuadTetra(SMDS_UnstructuredGrid *grid);
~SMDS_DownQuadTetra();
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
};
class SMDS_DownPyramid: public SMDS_Down3D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownPyramid(SMDS_UnstructuredGrid *grid);
~SMDS_DownPyramid();
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
};
class SMDS_DownQuadPyramid: public SMDS_Down3D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownQuadPyramid(SMDS_UnstructuredGrid *grid);
~SMDS_DownQuadPyramid();
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
};
class SMDS_DownPenta: public SMDS_Down3D
{
public:
SMDS_DownPenta(SMDS_UnstructuredGrid *grid);
~SMDS_DownPenta();
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
protected:
};
class SMDS_DownQuadPenta: public SMDS_Down3D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownQuadPenta(SMDS_UnstructuredGrid *grid);
~SMDS_DownQuadPenta();
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
};
class SMDS_DownHexa: public SMDS_Down3D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownHexa(SMDS_UnstructuredGrid *grid);
~SMDS_DownHexa();
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
};
class SMDS_DownQuadHexa: public SMDS_Down3D
{
friend class SMDS_UnstructuredGrid;
public:
protected:
SMDS_DownQuadHexa(SMDS_UnstructuredGrid *grid);
~SMDS_DownQuadHexa();
virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
};
//class SMDS_DownPolyhedra: public SMDS_Down3D
//{
//public:
// SMDS_DownPolyhedra(SMDS_UnstructuredGrid *grid);
// ~SMDS_DownPolyhedra();
//protected:
//};
//class SMDS_DownQuadPolyhedra: public SMDS_Down3D
//{
//public:
// SMDS_DownQuadPolyhedra(SMDS_UnstructuredGrid *grid);
// ~SMDS_DownQuadPolyhedra();
//protected:
//};
#endif /* SMDS_DOWNWARD_HXX_ */

View File

@ -41,11 +41,11 @@ using namespace std;
//======================================================================= //=======================================================================
SMDS_LinearEdge::SMDS_LinearEdge(const SMDS_MeshNode * node1, SMDS_LinearEdge::SMDS_LinearEdge(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2) const SMDS_MeshNode * node2)
{ {
//MESSAGE("SMDS_LinearEdge " << GetID()); //MESSAGE("SMDS_LinearEdge " << GetID());
myNodes[0]=node1; myNodes[0] = node1;
myNodes[1]=node2; myNodes[1] = node2;
} }
//======================================================================= //=======================================================================
@ -55,80 +55,88 @@ SMDS_LinearEdge::SMDS_LinearEdge(const SMDS_MeshNode * node1,
void SMDS_LinearEdge::Print(ostream & OS) const void SMDS_LinearEdge::Print(ostream & OS) const
{ {
OS << "edge <" << GetID() << "> : (" << myNodes[0] << " , " << myNodes[1] << OS << "edge <" << GetID() << "> : (" << myNodes[0] << " , " << myNodes[1]
") " << endl; << ") " << endl;
} }
int SMDS_LinearEdge::NbNodes() const int SMDS_LinearEdge::NbNodes() const
{ {
return 2; return 2;
} }
int SMDS_LinearEdge::NbEdges() const int SMDS_LinearEdge::NbEdges() const
{ {
return 1; return 1;
} }
class SMDS_LinearEdge_MyNodeIterator:public SMDS_ElemIterator class SMDS_LinearEdge_MyNodeIterator: public SMDS_ElemIterator
{ {
const SMDS_MeshNode *const* myNodes; const SMDS_MeshNode * const * myNodes;
int myIndex; int myIndex;
public: public:
SMDS_LinearEdge_MyNodeIterator(const SMDS_MeshNode * const* nodes): SMDS_LinearEdge_MyNodeIterator(const SMDS_MeshNode * const * nodes) :
myNodes(nodes),myIndex(0) {} myNodes(nodes), myIndex(0)
{
}
bool more() bool more()
{ {
return myIndex<2; return myIndex < 2;
} }
const SMDS_MeshElement* next() const SMDS_MeshElement* next()
{ {
myIndex++; myIndex++;
return myNodes[myIndex-1]; return myNodes[myIndex - 1];
} }
}; };
SMDS_ElemIteratorPtr SMDS_LinearEdge:: SMDS_ElemIteratorPtr SMDS_LinearEdge::elementsIterator(SMDSAbs_ElementType type) const
elementsIterator(SMDSAbs_ElementType type) const
{ {
switch(type) switch (type)
{ {
case SMDSAbs_Edge: case SMDSAbs_Edge:
return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge);
case SMDSAbs_Node: case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_LinearEdge_MyNodeIterator(myNodes)); return SMDS_ElemIteratorPtr(new SMDS_LinearEdge_MyNodeIterator(myNodes));
default: default:
return SMDS_ElemIteratorPtr return SMDS_ElemIteratorPtr(
(new SMDS_IteratorOfElements new SMDS_IteratorOfElements(
(this,type, SMDS_ElemIteratorPtr(new SMDS_LinearEdge_MyNodeIterator(myNodes)))); this,
type,
SMDS_ElemIteratorPtr(
new SMDS_LinearEdge_MyNodeIterator(
myNodes))));
} }
} }
bool operator<(const SMDS_LinearEdge & e1, const SMDS_LinearEdge & e2) bool operator<(const SMDS_LinearEdge & e1, const SMDS_LinearEdge & e2)
{ {
int id11=e1.myNodes[0]->GetID(); int id11 = e1.myNodes[0]->GetID();
int id21=e2.myNodes[0]->GetID(); int id21 = e2.myNodes[0]->GetID();
int id12=e1.myNodes[1]->GetID(); int id12 = e1.myNodes[1]->GetID();
int id22=e2.myNodes[1]->GetID(); int id22 = e2.myNodes[1]->GetID();
int tmp; int tmp;
if(id11>=id12) if (id11 >= id12)
{ {
tmp=id11; tmp = id11;
id11=id12; id11 = id12;
id12=tmp; id12 = tmp;
} }
if(id21>=id22) if (id21 >= id22)
{ {
tmp=id21; tmp = id21;
id21=id22; id21 = id22;
id22=tmp; id22 = tmp;
} }
if(id11<id21) return true; if (id11 < id21)
else if(id11==id21) return (id21<id22); return true;
else return false; else if (id11 == id21)
return (id21 < id22);
else
return false;
} }
/*! /*!
@ -138,7 +146,7 @@ bool operator<(const SMDS_LinearEdge & e1, const SMDS_LinearEdge & e2)
*/ */
const SMDS_MeshNode* SMDS_LinearEdge::GetNode(const int ind) const const SMDS_MeshNode* SMDS_LinearEdge::GetNode(const int ind) const
{ {
return myNodes[ ind ]; return myNodes[ind];
} }
//======================================================================= //=======================================================================
@ -147,9 +155,9 @@ const SMDS_MeshNode* SMDS_LinearEdge::GetNode(const int ind) const
//======================================================================= //=======================================================================
bool SMDS_LinearEdge::ChangeNodes(const SMDS_MeshNode * node1, bool SMDS_LinearEdge::ChangeNodes(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2) const SMDS_MeshNode * node2)
{ {
myNodes[0]=node1; myNodes[0] = node1;
myNodes[1]=node2; myNodes[1] = node2;
return true; return true;
} }

View File

@ -31,34 +31,35 @@
#include "SMDS_MeshEdge.hxx" #include "SMDS_MeshEdge.hxx"
#include <iostream> #include <iostream>
class SMDS_EXPORT SMDS_LinearEdge:public SMDS_MeshEdge class SMDS_EXPORT SMDS_LinearEdge: public SMDS_MeshEdge
{ {
public: public:
SMDS_LinearEdge(const SMDS_MeshNode * node1, SMDS_LinearEdge(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2);
const SMDS_MeshNode * node2); bool ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2);
bool ChangeNodes(const SMDS_MeshNode * node1, void Print(std::ostream & OS) const;
const SMDS_MeshNode * node2);
void Print(std::ostream & OS) const;
virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Edge; } virtual SMDSAbs_EntityType GetEntityType() const
int NbNodes() const; {
int NbEdges() const; return SMDSEntity_Edge;
friend bool operator<(const SMDS_LinearEdge& e1, const SMDS_LinearEdge& e2); }
int NbNodes() const;
int NbEdges() const;
friend bool operator<(const SMDS_LinearEdge& e1, const SMDS_LinearEdge& e2);
/*! /*!
* \brief Return node by its index * \brief Return node by its index
* \param ind - node index * \param ind - node index
* \retval const SMDS_MeshNode* - the node * \retval const SMDS_MeshNode* - the node
*/ */
virtual const SMDS_MeshNode* GetNode(const int ind) const; virtual const SMDS_MeshNode* GetNode(const int ind) const;
protected: protected:
SMDS_ElemIteratorPtr SMDS_ElemIteratorPtr
elementsIterator(SMDSAbs_ElementType type) const; elementsIterator(SMDSAbs_ElementType type) const;
protected: protected:
const SMDS_MeshNode* myNodes[3]; const SMDS_MeshNode* myNodes[3];
}; };
#endif #endif

View File

@ -148,6 +148,7 @@ SMDS_Mesh::SMDS_Mesh()
myIDElements.clear(); myIDElements.clear();
myVtkIndex.clear(); myVtkIndex.clear();
myGrid = SMDS_UnstructuredGrid::New(); myGrid = SMDS_UnstructuredGrid::New();
myGrid->setSMDS_mesh(this);
myGrid->Initialize(); myGrid->Initialize();
myGrid->Allocate(); myGrid->Allocate();
vtkPoints* points = vtkPoints::New(); vtkPoints* points = vtkPoints::New();

View File

@ -1,4 +1,3 @@
#include "SMDS_MeshCell.hxx" #include "SMDS_MeshCell.hxx"
#include "utilities.h" #include "utilities.h"
@ -6,12 +5,12 @@ using namespace std;
int SMDS_MeshCell::nbCells = 0; int SMDS_MeshCell::nbCells = 0;
SMDS_MeshCell::SMDS_MeshCell() :
SMDS_MeshCell::SMDS_MeshCell() : SMDS_MeshElement(-1) SMDS_MeshElement(-1)
{ {
nbCells++; nbCells++;
myVtkID = -1; myVtkID = -1;
}; }
SMDS_MeshCell::~SMDS_MeshCell() SMDS_MeshCell::~SMDS_MeshCell()
{ {

View File

@ -7,13 +7,21 @@
* \brief Base class for all cells * \brief Base class for all cells
*/ */
class SMDS_EXPORT SMDS_MeshCell:public SMDS_MeshElement class SMDS_EXPORT SMDS_MeshCell: public SMDS_MeshElement
{ {
public: public:
SMDS_MeshCell(); SMDS_MeshCell();
virtual ~SMDS_MeshCell(); virtual ~SMDS_MeshCell();
inline void setVtkId(int vtkId) { myVtkID = vtkId; }; inline void setVtkId(int vtkId)
inline int getVtkId() const {return myVtkID; }; {
myVtkID = vtkId;
}
inline int getVtkId() const
{
return myVtkID;
}
static int nbCells; static int nbCells;
protected: protected:
int myVtkID; int myVtkID;

View File

@ -41,9 +41,8 @@ using namespace std;
//function : SMDS_MeshNodeIDFactory //function : SMDS_MeshNodeIDFactory
//purpose : //purpose :
//======================================================================= //=======================================================================
SMDS_MeshNodeIDFactory::SMDS_MeshNodeIDFactory(): SMDS_MeshNodeIDFactory::SMDS_MeshNodeIDFactory() :
SMDS_MeshIDFactory(), SMDS_MeshIDFactory(), myMin(0), myMax(0)
myMin(0), myMax(0)
{ {
} }
@ -53,7 +52,7 @@ SMDS_MeshNodeIDFactory::SMDS_MeshNodeIDFactory():
//======================================================================= //=======================================================================
bool SMDS_MeshNodeIDFactory::BindID(int ID, SMDS_MeshElement * elem) bool SMDS_MeshNodeIDFactory::BindID(int ID, SMDS_MeshElement * elem)
{ {
updateMinMax (ID); updateMinMax(ID);
return true; return true;
} }
@ -63,10 +62,10 @@ bool SMDS_MeshNodeIDFactory::BindID(int ID, SMDS_MeshElement * elem)
//======================================================================= //=======================================================================
SMDS_MeshElement* SMDS_MeshNodeIDFactory::MeshElement(int ID) SMDS_MeshElement* SMDS_MeshNodeIDFactory::MeshElement(int ID)
{ {
if ((ID<0) || (ID>myMax)) if ((ID < 0) || (ID > myMax))
return NULL; return NULL;
const SMDS_MeshElement* elem = GetMesh()->FindNode(ID); const SMDS_MeshElement* elem = GetMesh()->FindNode(ID);
return (SMDS_MeshElement*)(elem); return (SMDS_MeshElement*) (elem);
} }
//======================================================================= //=======================================================================
@ -77,9 +76,9 @@ void SMDS_MeshNodeIDFactory::ReleaseID(const int ID)
{ {
SMDS_MeshIDFactory::ReleaseID(ID); SMDS_MeshIDFactory::ReleaseID(ID);
if (ID == myMax) if (ID == myMax)
myMax = 0; // --- force updateMinMax myMax = 0; // --- force updateMinMax
if (ID == myMin) if (ID == myMin)
myMax = 0; // --- force updateMinMax myMax = 0; // --- force updateMinMax
} }
//======================================================================= //=======================================================================
@ -120,7 +119,7 @@ void SMDS_MeshNodeIDFactory::updateMinMax() const
SMDS_ElemIteratorPtr SMDS_MeshNodeIDFactory::elementsIterator() const SMDS_ElemIteratorPtr SMDS_MeshNodeIDFactory::elementsIterator() const
{ {
return myMesh->elementsIterator(SMDSAbs_Node); return myMesh->elementsIterator(SMDSAbs_Node);
} }
void SMDS_MeshNodeIDFactory::Clear() void SMDS_MeshNodeIDFactory::Clear()

View File

@ -35,7 +35,7 @@
class SMDS_MeshElement; class SMDS_MeshElement;
class SMDS_EXPORT SMDS_MeshNodeIDFactory:public SMDS_MeshIDFactory class SMDS_EXPORT SMDS_MeshNodeIDFactory: public SMDS_MeshIDFactory
{ {
public: public:
SMDS_MeshNodeIDFactory(); SMDS_MeshNodeIDFactory();
@ -51,8 +51,10 @@ protected:
void updateMinMax() const; void updateMinMax() const;
void updateMinMax(int id) const void updateMinMax(int id) const
{ {
if (id > myMax) myMax = id; if (id > myMax)
if (id < myMin) myMin = id; myMax = id;
if (id < myMin)
myMin = id;
} }
mutable int myMin, myMax; mutable int myMin, myMax;

View File

@ -1,6 +1,9 @@
#define CHRONODEF
#include "SMDS_UnstructuredGrid.hxx" #include "SMDS_UnstructuredGrid.hxx"
#include "SMDS_Mesh.hxx"
#include "SMDS_MeshInfo.hxx"
#include "SMDS_Downward.hxx"
#include "utilities.h" #include "utilities.h"
#include <vtkCellArray.h> #include <vtkCellArray.h>
@ -14,261 +17,651 @@ using namespace std;
SMDS_UnstructuredGrid* SMDS_UnstructuredGrid::New() SMDS_UnstructuredGrid* SMDS_UnstructuredGrid::New()
{ {
MESSAGE("SMDS_UnstructuredGrid::New"); MESSAGE("SMDS_UnstructuredGrid::New");
return new SMDS_UnstructuredGrid(); return new SMDS_UnstructuredGrid();
} }
SMDS_UnstructuredGrid::SMDS_UnstructuredGrid() : vtkUnstructuredGrid() SMDS_UnstructuredGrid::SMDS_UnstructuredGrid() :
vtkUnstructuredGrid()
{ {
_cellIdToDownId.clear();
_downTypes.clear();
_downArray.clear();
_mesh = 0;
_counters = new counters(100);
} }
SMDS_UnstructuredGrid::~SMDS_UnstructuredGrid() SMDS_UnstructuredGrid::~SMDS_UnstructuredGrid()
{ {
} }
unsigned long SMDS_UnstructuredGrid::GetMTime() unsigned long SMDS_UnstructuredGrid::GetMTime()
{ {
unsigned long mtime = vtkUnstructuredGrid::GetMTime(); unsigned long mtime = vtkUnstructuredGrid::GetMTime();
MESSAGE("vtkUnstructuredGrid::GetMTime: " << mtime); MESSAGE("vtkUnstructuredGrid::GetMTime: " << mtime);
return mtime; return mtime;
} }
void SMDS_UnstructuredGrid::Update() void SMDS_UnstructuredGrid::Update()
{ {
MESSAGE("SMDS_UnstructuredGrid::Update"); MESSAGE("SMDS_UnstructuredGrid::Update");
return vtkUnstructuredGrid::Update(); return vtkUnstructuredGrid::Update();
} }
void SMDS_UnstructuredGrid::UpdateInformation() void SMDS_UnstructuredGrid::UpdateInformation()
{ {
MESSAGE("SMDS_UnstructuredGrid::UpdateInformation"); MESSAGE("SMDS_UnstructuredGrid::UpdateInformation");
return vtkUnstructuredGrid::UpdateInformation(); return vtkUnstructuredGrid::UpdateInformation();
}
void SMDS_UnstructuredGrid::setSMDS_mesh(SMDS_Mesh *mesh)
{
_mesh = mesh;
} }
void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int newNodeSize, void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int newNodeSize,
std::vector<int>& idCellsOldToNew, int newCellSize) std::vector<int>& idCellsOldToNew, int newCellSize)
{ {
MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize); MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize);CHRONO(1);
int startHole = 0;
int endHole = 0;
int startBloc = 0;
int endBloc = 0;
int alreadyCopied = 0;
int holes = 0;
int startHole = 0; typedef enum
int endHole = 0; {
int startBloc = 0; lookHoleStart, lookHoleEnd, lookBlocEnd
int endBloc = 0; } enumState;
int alreadyCopied = 0; enumState compactState = lookHoleStart;
int holes = 0;
typedef enum {lookHoleStart, lookHoleEnd, lookBlocEnd} enumState; // if (this->Links)
enumState compactState = lookHoleStart; // {
// this->Links->UnRegister(this);
// this->Links = 0;
// }
// if (this->Links) // --- if newNodeSize, create a new compacted vtkPoints
// {
// this->Links->UnRegister(this);
// this->Links = 0;
// }
// --- if newNodeSize, create a new compacted vtkPoints vtkPoints *newPoints = 0;
if (newNodeSize)
vtkPoints *newPoints = 0;
if (newNodeSize)
{
MESSAGE("-------------- compactGrid, newNodeSize " << newNodeSize);
newPoints = vtkPoints::New();
newPoints->Initialize();
newPoints->Allocate(newNodeSize);
newPoints->SetNumberOfPoints(newNodeSize);
int oldNodeSize = idNodesOldToNew.size();
for (int i=0; i< oldNodeSize; i++)
{
switch(compactState)
{
case lookHoleStart:
if (idNodesOldToNew[i] < 0)
{
MESSAGE("-------------- newNodeSize, startHole " << i << " " << oldNodeSize);
startHole = i;
if (!alreadyCopied) // copy the first bloc
{
MESSAGE("--------- copy first nodes before hole " << i << " " << oldNodeSize);
copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, startHole);
}
compactState = lookHoleEnd;
}
break;
case lookHoleEnd:
if (idNodesOldToNew[i] >= 0)
{
MESSAGE("-------------- newNodeSize, endHole " << i << " " << oldNodeSize);
endHole = i;
startBloc = i;
compactState = lookBlocEnd;
}
break;
case lookBlocEnd:
if (idNodesOldToNew[i] < 0) endBloc = i; // see nbPoints below
else if (i == (oldNodeSize-1)) endBloc = i+1;
if (endBloc)
{
MESSAGE("-------------- newNodeSize, endbloc " << endBloc << " " << oldNodeSize);
copyNodes(newPoints, idNodesOldToNew, alreadyCopied, startBloc, endBloc);
compactState = lookHoleStart;
startHole = i;
endHole = 0;
startBloc = 0;
endBloc = 0;
}
break;
}
}
if (!alreadyCopied) // no hole, but shorter, no need to modify idNodesOldToNew
{
MESSAGE("------------- newNodeSize, shorter " << oldNodeSize);
copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, newNodeSize);
}
newPoints->Squeeze();
}
// --- create new compacted Connectivity, Locations and Types
int oldCellSize = this->Types->GetNumberOfTuples();
vtkCellArray *newConnectivity = vtkCellArray::New();
newConnectivity->Initialize();
int oldCellDataSize = this->Connectivity->GetData()->GetSize();
newConnectivity->Allocate(oldCellDataSize);
MESSAGE("oldCellSize="<< oldCellSize << " oldCellDataSize=" << oldCellDataSize);
vtkUnsignedCharArray *newTypes = vtkUnsignedCharArray::New();
newTypes->Initialize();
//newTypes->Allocate(oldCellSize);
newTypes->SetNumberOfValues(newCellSize);
vtkIdTypeArray *newLocations = vtkIdTypeArray::New();
newLocations->Initialize();
//newLocations->Allocate(oldCellSize);
newLocations->SetNumberOfValues(newCellSize);
startHole = 0;
endHole = 0;
startBloc = 0;
endBloc = 0;
alreadyCopied = 0;
holes = 0;
compactState = lookHoleStart;
vtkIdType tmpid[50];
vtkIdType *pointsCell =&tmpid[0]; // --- points id to fill a new cell
for (int i=0; i<oldCellSize; i++)
{ {
switch(compactState) MESSAGE("-------------- compactGrid, newNodeSize " << newNodeSize);
{ newPoints = vtkPoints::New();
case lookHoleStart: newPoints->Initialize();
if (this->Types->GetValue(i) == VTK_EMPTY_CELL) newPoints->Allocate(newNodeSize);
{ newPoints->SetNumberOfPoints(newNodeSize);
MESSAGE(" -------- newCellSize, startHole " << i << " " << oldCellSize); int oldNodeSize = idNodesOldToNew.size();
startHole = i;
compactState = lookHoleEnd; for (int i = 0; i < oldNodeSize; i++)
if (!alreadyCopied) // copy the first bloc {
{ switch (compactState)
MESSAGE("--------- copy first bloc before hole " << i << " " << oldCellSize); {
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, alreadyCopied, 0, startHole); case lookHoleStart:
} if (idNodesOldToNew[i] < 0)
} {
break; MESSAGE("-------------- newNodeSize, startHole " << i << " " << oldNodeSize);
case lookHoleEnd: startHole = i;
if (this->Types->GetValue(i) != VTK_EMPTY_CELL) if (!alreadyCopied) // copy the first bloc
{ {
MESSAGE(" -------- newCellSize, EndHole " << i << " " << oldCellSize); MESSAGE("--------- copy first nodes before hole " << i << " " << oldNodeSize);
endHole = i; copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, startHole);
startBloc = i; }
compactState = lookBlocEnd; compactState = lookHoleEnd;
holes += endHole - startHole; }
//alreadyCopied = startBloc -holes; break;
} case lookHoleEnd:
break; if (idNodesOldToNew[i] >= 0)
case lookBlocEnd: {
endBloc =0; MESSAGE("-------------- newNodeSize, endHole " << i << " " << oldNodeSize);
if (this->Types->GetValue(i) == VTK_EMPTY_CELL) endBloc =i; endHole = i;
else if (i == (oldCellSize-1)) endBloc = i+1; startBloc = i;
if (endBloc) compactState = lookBlocEnd;
{ }
MESSAGE(" -------- newCellSize, endBloc " << endBloc << " " << oldCellSize); break;
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, alreadyCopied, startBloc, endBloc); case lookBlocEnd:
compactState = lookHoleStart; if (idNodesOldToNew[i] < 0)
} endBloc = i; // see nbPoints below
break; else if (i == (oldNodeSize - 1))
} endBloc = i + 1;
} if (endBloc)
if (!alreadyCopied) // no hole, but shorter {
{ MESSAGE("-------------- newNodeSize, endbloc " << endBloc << " " << oldNodeSize);
MESSAGE(" -------- newCellSize, shorter " << oldCellSize); copyNodes(newPoints, idNodesOldToNew, alreadyCopied, startBloc, endBloc);
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, alreadyCopied, 0, oldCellSize); compactState = lookHoleStart;
startHole = i;
endHole = 0;
startBloc = 0;
endBloc = 0;
}
break;
}
}
if (!alreadyCopied) // no hole, but shorter, no need to modify idNodesOldToNew
{
MESSAGE("------------- newNodeSize, shorter " << oldNodeSize);
copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, newNodeSize);
}
newPoints->Squeeze();
} }
newConnectivity->Squeeze(); // --- create new compacted Connectivity, Locations and Types
//newTypes->Squeeze();
//newLocations->Squeeze();
if (newNodeSize) int oldCellSize = this->Types->GetNumberOfTuples();
vtkCellArray *newConnectivity = vtkCellArray::New();
newConnectivity->Initialize();
int oldCellDataSize = this->Connectivity->GetData()->GetSize();
newConnectivity->Allocate(oldCellDataSize);
MESSAGE("oldCellSize="<< oldCellSize << " oldCellDataSize=" << oldCellDataSize);
vtkUnsignedCharArray *newTypes = vtkUnsignedCharArray::New();
newTypes->Initialize();
//newTypes->Allocate(oldCellSize);
newTypes->SetNumberOfValues(newCellSize);
vtkIdTypeArray *newLocations = vtkIdTypeArray::New();
newLocations->Initialize();
//newLocations->Allocate(oldCellSize);
newLocations->SetNumberOfValues(newCellSize);
startHole = 0;
endHole = 0;
startBloc = 0;
endBloc = 0;
alreadyCopied = 0;
holes = 0;
compactState = lookHoleStart;
vtkIdType tmpid[50];
vtkIdType *pointsCell = &tmpid[0]; // --- points id to fill a new cell
for (int i = 0; i < oldCellSize; i++)
{ {
MESSAGE("------- newNodeSize, setPoints"); switch (compactState)
this->SetPoints(newPoints); {
MESSAGE("NumberOfPoints: " << this->GetNumberOfPoints()); case lookHoleStart:
if (this->Types->GetValue(i) == VTK_EMPTY_CELL)
{
MESSAGE(" -------- newCellSize, startHole " << i << " " << oldCellSize);
startHole = i;
compactState = lookHoleEnd;
if (!alreadyCopied) // copy the first bloc
{
MESSAGE("--------- copy first bloc before hole " << i << " " << oldCellSize);
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell,
alreadyCopied, 0, startHole);
}
}
break;
case lookHoleEnd:
if (this->Types->GetValue(i) != VTK_EMPTY_CELL)
{
MESSAGE(" -------- newCellSize, EndHole " << i << " " << oldCellSize);
endHole = i;
startBloc = i;
compactState = lookBlocEnd;
holes += endHole - startHole;
//alreadyCopied = startBloc -holes;
}
break;
case lookBlocEnd:
endBloc = 0;
if (this->Types->GetValue(i) == VTK_EMPTY_CELL)
endBloc = i;
else if (i == (oldCellSize - 1))
endBloc = i + 1;
if (endBloc)
{
MESSAGE(" -------- newCellSize, endBloc " << endBloc << " " << oldCellSize);
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell,
alreadyCopied, startBloc, endBloc);
compactState = lookHoleStart;
}
break;
}
} }
this->SetCells(newTypes, newLocations, newConnectivity); if (!alreadyCopied) // no hole, but shorter
this->BuildLinks(); {
MESSAGE(" -------- newCellSize, shorter " << oldCellSize);
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, alreadyCopied, 0,
oldCellSize);
}
newConnectivity->Squeeze();
//newTypes->Squeeze();
//newLocations->Squeeze();
if (newNodeSize)
{
MESSAGE("------- newNodeSize, setPoints");
this->SetPoints(newPoints);
MESSAGE("NumberOfPoints: " << this->GetNumberOfPoints());
}
this->SetCells(newTypes, newLocations, newConnectivity);
this->BuildLinks();
} }
void SMDS_UnstructuredGrid::copyNodes(vtkPoints *newPoints, void SMDS_UnstructuredGrid::copyNodes(vtkPoints *newPoints, std::vector<int>& idNodesOldToNew, int& alreadyCopied,
std::vector<int>& idNodesOldToNew, int start, int end)
int& alreadyCopied,
int start,
int end)
{ {
MESSAGE("copyNodes " << alreadyCopied << " " << start << " " << end << " size: " << end - start << " total: " << alreadyCopied + end - start); MESSAGE("copyNodes " << alreadyCopied << " " << start << " " << end << " size: " << end - start << " total: " << alreadyCopied + end - start);
void *target = newPoints->GetVoidPointer(3*alreadyCopied); void *target = newPoints->GetVoidPointer(3 * alreadyCopied);
void *source = this->Points->GetVoidPointer(3*start); void *source = this->Points->GetVoidPointer(3 * start);
int nbPoints = end - start; int nbPoints = end - start;
if (nbPoints >0) if (nbPoints > 0)
{ {
memcpy(target, source, 3*sizeof(float)*nbPoints); memcpy(target, source, 3 * sizeof(float) * nbPoints);
for (int j=start; j<end; j++) for (int j = start; j < end; j++)
idNodesOldToNew[j] = alreadyCopied++; idNodesOldToNew[j] = alreadyCopied++;
} }
} }
void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes, void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes, std::vector<int>& idCellsOldToNew,
std::vector<int>& idCellsOldToNew, std::vector<int>& idNodesOldToNew, vtkCellArray* newConnectivity,
std::vector<int>& idNodesOldToNew, vtkIdTypeArray* newLocations, vtkIdType* pointsCell, int& alreadyCopied,
vtkCellArray* newConnectivity, int start, int end)
vtkIdTypeArray* newLocations,
vtkIdType* pointsCell,
int& alreadyCopied,
int start,
int end)
{ {
MESSAGE("copyBloc " << alreadyCopied << " " << start << " " << end << " size: " << end - start << " total: " << alreadyCopied + end - start); MESSAGE("copyBloc " << alreadyCopied << " " << start << " " << end << " size: " << end - start << " total: " << alreadyCopied + end - start);
for (int j=start; j<end; j++) for (int j = start; j < end; j++)
{ {
newTypes->SetValue(alreadyCopied, this->Types->GetValue(j)); newTypes->SetValue(alreadyCopied, this->Types->GetValue(j));
idCellsOldToNew[j] = alreadyCopied; idCellsOldToNew[j] = alreadyCopied;
vtkIdType oldLoc = this->Locations->GetValue(j); vtkIdType oldLoc = this->Locations->GetValue(j);
vtkIdType nbpts; vtkIdType nbpts;
vtkIdType *oldPtsCell = 0; vtkIdType *oldPtsCell = 0;
this->Connectivity->GetCell(oldLoc, nbpts, oldPtsCell); this->Connectivity->GetCell(oldLoc, nbpts, oldPtsCell);
//MESSAGE(j << " " << alreadyCopied << " " << (int)this->Types->GetValue(j) << " " << oldLoc << " " << nbpts ); //MESSAGE(j << " " << alreadyCopied << " " << (int)this->Types->GetValue(j) << " " << oldLoc << " " << nbpts );
for (int l=0; l<nbpts; l++) for (int l = 0; l < nbpts; l++)
{ {
int oldval = oldPtsCell[l]; int oldval = oldPtsCell[l];
pointsCell[l] = idNodesOldToNew[oldval]; pointsCell[l] = idNodesOldToNew[oldval];
//MESSAGE(" " << oldval << " " << pointsCell[l]); //MESSAGE(" " << oldval << " " << pointsCell[l]);
} }
int newcnt = newConnectivity->InsertNextCell(nbpts, pointsCell); int newcnt = newConnectivity->InsertNextCell(nbpts, pointsCell);
int newLoc = newConnectivity->GetInsertLocation(nbpts); int newLoc = newConnectivity->GetInsertLocation(nbpts);
//MESSAGE(newcnt << " " << newLoc); //MESSAGE(newcnt << " " << newLoc);
newLocations->SetValue(alreadyCopied, newLoc); newLocations->SetValue(alreadyCopied, newLoc);
alreadyCopied++; alreadyCopied++;
} }
}
int SMDS_UnstructuredGrid::CellIdToDownId(int vtkCellId)
{
// ASSERT((vtkCellId >= 0) && (vtkCellId < _cellIdToDownId.size()));
return _cellIdToDownId[vtkCellId];
}
void SMDS_UnstructuredGrid::setCellIdToDownId(int vtkCellId, int downId)
{
// ASSERT((vtkCellId >= 0) && (vtkCellId < _cellIdToDownId.size()));
_cellIdToDownId[vtkCellId] = downId;
}
/*! Build downward connectivity: to do only when needed because heavy memory load.
* Downward connectivity is no more valid if vtkUnstructuredGrid is modified.
*
*/
void SMDS_UnstructuredGrid::BuildDownwardConnectivity()
{
MESSAGE("SMDS_UnstructuredGrid::BuildDownwardConnectivity");CHRONO(2);
// --- erase previous data if any
for (int i = 0; i < _downArray.size(); i++)
{
if (_downArray[i])
delete _downArray[i];
_downArray[i] = 0;
}
_cellIdToDownId.clear();
// --- create SMDS_Downward structures (in _downArray vector[vtkCellType])
_downArray.resize(VTK_QUADRATIC_PYRAMID + 1, 0); // --- max. type value = VTK_QUADRATIC_PYRAMID
_downArray[VTK_LINE] = new SMDS_DownEdge(this);
_downArray[VTK_QUADRATIC_EDGE] = new SMDS_DownQuadEdge(this);
_downArray[VTK_TRIANGLE] = new SMDS_DownTriangle(this);
_downArray[VTK_QUADRATIC_TRIANGLE] = new SMDS_DownQuadTriangle(this);
_downArray[VTK_QUAD] = new SMDS_DownQuadrangle(this);
_downArray[VTK_QUADRATIC_QUAD] = new SMDS_DownQuadQuadrangle(this);
_downArray[VTK_TETRA] = new SMDS_DownTetra(this);
_downArray[VTK_QUADRATIC_TETRA] = new SMDS_DownQuadTetra(this);
_downArray[VTK_PYRAMID] = new SMDS_DownPyramid(this);
_downArray[VTK_QUADRATIC_PYRAMID] = new SMDS_DownQuadPyramid(this);
_downArray[VTK_WEDGE] = new SMDS_DownPenta(this);
_downArray[VTK_QUADRATIC_WEDGE] = new SMDS_DownQuadPenta(this);
_downArray[VTK_HEXAHEDRON] = new SMDS_DownHexa(this);
_downArray[VTK_QUADRATIC_HEXAHEDRON] = new SMDS_DownQuadHexa(this);
// --- get detailed info of number of cells of each type, allocate SMDS_downward structures
const SMDS_MeshInfo &meshInfo = _mesh->GetMeshInfo();
int nbLinTetra = meshInfo.NbTetras(ORDER_LINEAR);
int nbQuadTetra = meshInfo.NbTetras(ORDER_QUADRATIC);
int nbLinPyra = meshInfo.NbPyramids(ORDER_LINEAR);
int nbQuadPyra = meshInfo.NbPyramids(ORDER_QUADRATIC);
int nbLinPrism = meshInfo.NbPrisms(ORDER_LINEAR);
int nbQuadPrism = meshInfo.NbPrisms(ORDER_QUADRATIC);
int nbLinHexa = meshInfo.NbHexas(ORDER_LINEAR);
int nbQuadHexa = meshInfo.NbHexas(ORDER_QUADRATIC);
int nbLineGuess = int((4.0 / 3.0) * nbLinTetra + 2 * nbLinPrism + 2.5 * nbLinPyra + 3 * nbLinHexa);
int nbQuadEdgeGuess = int((4.0 / 3.0) * nbQuadTetra + 2 * nbQuadPrism + 2.5 * nbQuadPyra + 3 * nbQuadHexa);
int nbLinTriaGuess = 2 * nbLinTetra + nbLinPrism + 2 * nbLinPyra;
int nbQuadTriaGuess = 2 * nbQuadTetra + nbQuadPrism + 2 * nbQuadPyra;
int nbLinQuadGuess = int((2.0 / 3.0) * nbLinPrism + (1.0 / 2.0) * nbLinPyra + 3 * nbLinHexa);
int nbQuadQuadGuess = int((2.0 / 3.0) * nbQuadPrism + (1.0 / 2.0) * nbQuadPyra + 3 * nbQuadHexa);
int GuessSize[VTK_QUADRATIC_TETRA];
GuessSize[VTK_LINE] = nbLineGuess;
GuessSize[VTK_QUADRATIC_EDGE] = nbQuadEdgeGuess;
GuessSize[VTK_TRIANGLE] = nbLinTriaGuess;
GuessSize[VTK_QUADRATIC_TRIANGLE] = nbQuadTriaGuess;
GuessSize[VTK_QUAD] = nbLinQuadGuess;
GuessSize[VTK_QUADRATIC_QUAD] = nbQuadQuadGuess;
GuessSize[VTK_TETRA] = nbLinTetra;
GuessSize[VTK_QUADRATIC_TETRA] = nbQuadTetra;
GuessSize[VTK_PYRAMID] = nbLinPyra;
GuessSize[VTK_QUADRATIC_PYRAMID] = nbQuadPyra;
GuessSize[VTK_WEDGE] = nbLinPrism;
GuessSize[VTK_QUADRATIC_WEDGE] = nbQuadPrism;
GuessSize[VTK_HEXAHEDRON] = nbLinHexa;
GuessSize[VTK_QUADRATIC_HEXAHEDRON] = nbQuadHexa;
_downArray[VTK_LINE]->allocate(nbLineGuess);
_downArray[VTK_QUADRATIC_EDGE]->allocate(nbQuadEdgeGuess);
_downArray[VTK_TRIANGLE]->allocate(nbLinTriaGuess);
_downArray[VTK_QUADRATIC_TRIANGLE]->allocate(nbQuadTriaGuess);
_downArray[VTK_QUAD]->allocate(nbLinQuadGuess);
_downArray[VTK_QUADRATIC_QUAD]->allocate(nbQuadQuadGuess);
_downArray[VTK_TETRA]->allocate(nbLinTetra);
_downArray[VTK_QUADRATIC_TETRA]->allocate(nbQuadTetra);
_downArray[VTK_PYRAMID]->allocate(nbLinPyra);
_downArray[VTK_QUADRATIC_PYRAMID]->allocate(nbQuadPyra);
_downArray[VTK_WEDGE]->allocate(nbLinPrism);
_downArray[VTK_QUADRATIC_WEDGE]->allocate(nbQuadPrism);
_downArray[VTK_HEXAHEDRON]->allocate(nbLinHexa);
_downArray[VTK_QUADRATIC_HEXAHEDRON]->allocate(nbQuadHexa);
// --- iteration on vtkUnstructuredGrid cells, only faces
// for each vtk face:
// create a downward face entry with its downward id.
// compute vtk volumes, create downward volumes entry.
// mark face in downward volumes
// mark volumes in downward face
MESSAGE("--- iteration on vtkUnstructuredGrid cells, only faces");CHRONO(20);
int cellSize = this->Types->GetNumberOfTuples();
_cellIdToDownId.resize(cellSize, -1);
for (int i = 0; i < cellSize; i++)
{
int vtkFaceType = this->GetCellType(i);
if (SMDS_Downward::getCellDimension(vtkFaceType) == 2)
{
int vtkFaceId = i;
//ASSERT(_downArray[vtkFaceType]);
int connFaceId = _downArray[vtkFaceType]->addCell(vtkFaceId);
SMDS_Down2D* downFace = static_cast<SMDS_Down2D*> (_downArray[vtkFaceType]);
downFace->setTempNodes(connFaceId, vtkFaceId);
int vols[2] = { -1, -1 };
int nbVolumes = downFace->computeVolumeIds(vtkFaceId, vols);
//MESSAGE("nbVolumes="<< nbVolumes);
for (int ivol = 0; ivol < nbVolumes; ivol++)
{
int vtkVolId = vols[ivol];
int vtkVolType = this->GetCellType(vtkVolId);
//ASSERT(_downArray[vtkVolType]);
int connVolId = _downArray[vtkVolType]->addCell(vtkVolId);
_downArray[vtkVolType]->addDownCell(connVolId, connFaceId, vtkFaceType);
_downArray[vtkFaceType]->addUpCell(connFaceId, connVolId, vtkVolType);
// MESSAGE("Face " << vtkFaceId << " belongs to volume " << vtkVolId);
}
}
}
// --- iteration on vtkUnstructuredGrid cells, only volumes
// for each vtk volume:
// create downward volumes entry if not already done
// build a temporary list of faces described with their nodes
// for each face
// compute the vtk volumes containing this face
// check if the face is already listed in the volumes (comparison of ordered list of nodes)
// if not, create a downward face entry (resizing of structure required)
// (the downward faces store a temporary list of nodes to ease the comparison)
// create downward volumes entry if not already done
// mark volumes in downward face
// mark face in downward volumes
CHRONOSTOP(20);
MESSAGE("--- iteration on vtkUnstructuredGrid cells, only volumes");CHRONO(21);
for (int i = 0; i < cellSize; i++)
{
int vtkType = this->GetCellType(i);
if (SMDS_Downward::getCellDimension(vtkType) == 3)
{
//CHRONO(31);
int vtkVolId = i;
// MESSAGE("vtk volume " << vtkVolId);
//ASSERT(_downArray[vtkType]);
int connVolId = _downArray[vtkType]->addCell(vtkVolId);
// --- find all the faces of the volume, describe the faces by their nodes
SMDS_Down3D* downVol = static_cast<SMDS_Down3D*> (_downArray[vtkType]);
ListElemByNodesType facesWithNodes;
downVol->computeFacesWithNodes(vtkVolId, facesWithNodes);
// MESSAGE("vtk volume " << vtkVolId << " contains " << facesWithNodes.nbElems << " faces");
//CHRONOSTOP(31);
for (int iface = 0; iface < facesWithNodes.nbElems; iface++)
{
// --- find the volumes containing the face
//CHRONO(32);
int vtkFaceType = facesWithNodes.elems[iface].vtkType;
SMDS_Down2D* downFace = static_cast<SMDS_Down2D*> (_downArray[vtkFaceType]);
int vols[2] = { -1, -1 };
int *nodes = &facesWithNodes.elems[iface].nodeIds[0];
int lg = facesWithNodes.elems[iface].nbNodes;
int nbVolumes = downFace->computeVolumeIdsFromNodesFace(nodes, lg, vols);
// MESSAGE("vtk volume " << vtkVolId << " face " << iface << " belongs to " << nbVolumes << " volumes");
// --- check if face is registered in the volumes
//CHRONOSTOP(32);
//CHRONO(33);
int connFaceId = -1;
for (int ivol = 0; ivol < nbVolumes; ivol++)
{
int vtkVolId2 = vols[ivol];
int vtkVolType = this->GetCellType(vtkVolId2);
//ASSERT(_downArray[vtkVolType]);
int connVolId2 = _downArray[vtkVolType]->addCell(vtkVolId2);
SMDS_Down3D* downVol2 = static_cast<SMDS_Down3D*> (_downArray[vtkVolType]);
connFaceId = downVol2->FindFaceByNodes(connVolId2, facesWithNodes.elems[iface]);
if (connFaceId >= 0)
break; // --- face already created
}//CHRONOSTOP(33);
// --- if face is not registered in the volumes, create face
//CHRONO(34);
if (connFaceId < 0)
{
connFaceId = _downArray[vtkFaceType]->addCell();
downFace->setTempNodes(connFaceId, facesWithNodes.elems[iface]);
}//CHRONOSTOP(34);
// --- mark volumes in downward face and mark face in downward volumes
//CHRONO(35);
for (int ivol = 0; ivol < nbVolumes; ivol++)
{
int vtkVolId2 = vols[ivol];
int vtkVolType = this->GetCellType(vtkVolId2);
//ASSERT(_downArray[vtkVolType]);
int connVolId2 = _downArray[vtkVolType]->addCell(vtkVolId2);
_downArray[vtkVolType]->addDownCell(connVolId2, connFaceId, vtkFaceType);
_downArray[vtkFaceType]->addUpCell(connFaceId, connVolId2, vtkVolType);
// MESSAGE(" From volume " << vtkVolId << " face " << connFaceId << " belongs to volume " << vtkVolId2);
}//CHRONOSTOP(35);
}
}
}
// --- iteration on vtkUnstructuredGrid cells, only edges
// for each vtk edge:
// create downward edge entry
// store the nodes id's in downward edge (redundant with vtkUnstructuredGrid)
// find downward faces
// (from vtk faces or volumes, get downward faces, they have a temporary list of nodes)
// mark edge in downward faces
// mark faces in downward edge
CHRONOSTOP(21);
MESSAGE("--- iteration on vtkUnstructuredGrid cells, only edges");CHRONO(22);
for (int i = 0; i < cellSize; i++)
{
int vtkEdgeType = this->GetCellType(i);
if (SMDS_Downward::getCellDimension(vtkEdgeType) == 1)
{
int vtkEdgeId = i;
//ASSERT(_downArray[vtkEdgeType]);
int connEdgeId = _downArray[vtkEdgeType]->addCell(vtkEdgeId);
SMDS_Down1D* downEdge = static_cast<SMDS_Down1D*> (_downArray[vtkEdgeType]);
downEdge->setNodes(connEdgeId, vtkEdgeId);
vector<int> vtkIds;
int nbVtkCells = downEdge->computeVtkCells(connEdgeId, vtkIds);
int downFaces[100];
unsigned char downTypes[100];
int nbDownFaces = downEdge->computeFaces(connEdgeId, &vtkIds[0], nbVtkCells, downFaces, downTypes);
for (int n = 0; n < nbDownFaces; n++)
{
_downArray[downTypes[n]]->addDownCell(downFaces[n], connEdgeId, vtkEdgeType);
_downArray[vtkEdgeType]->addUpCell(connEdgeId, downFaces[n], downTypes[n]);
}
}
}
// --- iteration on downward faces (they are all listed now)
// for each downward face:
// build a temporary list of edges with their ordered list of nodes
// for each edge:
// find all the vtk cells containing this edge
// then identify all the downward faces containing the edge, from the vtk cells
// check if the edge is already listed in the faces (comparison of ordered list of nodes)
// if not, create a downward edge entry with the node id's
// mark edge in downward faces
// mark downward faces in edge (size of list unknown, to be allocated)
CHRONOSTOP(22);CHRONO(23);
for (int vtkFaceType = 0; vtkFaceType < VTK_QUADRATIC_PYRAMID; vtkFaceType++)
{
if (SMDS_Downward::getCellDimension(vtkFaceType) != 2)
continue;
// --- find all the edges of the face, describe the edges by their nodes
SMDS_Down2D* downFace = static_cast<SMDS_Down2D*> (_downArray[vtkFaceType]);
int maxId = downFace->getMaxId();
for (int faceId = 0; faceId < maxId; faceId++)
{
//CHRONO(40);
ListElemByNodesType edgesWithNodes;
downFace->computeEdgesWithNodes(faceId, edgesWithNodes);
// MESSAGE("downward face type " << vtkFaceType << " num " << faceId << " contains " << edgesWithNodes.nbElems << " edges");
//CHRONOSTOP(40);
for (int iedge = 0; iedge < edgesWithNodes.nbElems; iedge++)
{
// --- check if the edge is already registered by exploration of the faces
//CHRONO(41);
vector<int> vtkIds;
unsigned char vtkEdgeType = edgesWithNodes.elems[iedge].vtkType;
int *pts = &edgesWithNodes.elems[iedge].nodeIds[0];
SMDS_Down1D* downEdge = static_cast<SMDS_Down1D*> (_downArray[vtkEdgeType]);
int nbVtkCells = downEdge->computeVtkCells(pts, vtkIds);
//CHRONOSTOP(41);CHRONO(42);
int downFaces[100];
unsigned char downTypes[100];
int nbDownFaces = downEdge->computeFaces(pts, &vtkIds[0], nbVtkCells, downFaces, downTypes);
//CHRONOSTOP(42);
//CHRONO(43);
int connEdgeId = -1;
for (int idf = 0; idf < nbDownFaces; idf++)
{
int faceId2 = downFaces[idf];
int faceType = downTypes[idf];
//ASSERT(_downArray[faceType]);
SMDS_Down2D* downFace2 = static_cast<SMDS_Down2D*> (_downArray[faceType]);
connEdgeId = downFace2->FindEdgeByNodes(faceId2, edgesWithNodes.elems[iedge]);
if (connEdgeId >= 0)
break; // --- edge already created
}//CHRONOSTOP(43);
// --- if edge is not registered in the faces, create edge
if (connEdgeId < 0)
{
//CHRONO(44);
connEdgeId = _downArray[vtkEdgeType]->addCell();
downEdge->setNodes(connEdgeId, edgesWithNodes.elems[iedge].nodeIds);
//CHRONOSTOP(44);
}
// --- mark faces in downward edge and mark edge in downward faces
//CHRONO(45);
for (int idf = 0; idf < nbDownFaces; idf++)
{
int faceId2 = downFaces[idf];
int faceType = downTypes[idf];
//ASSERT(_downArray[faceType]);
SMDS_Down2D* downFace2 = static_cast<SMDS_Down2D*> (_downArray[faceType]);
_downArray[vtkEdgeType]->addUpCell(connEdgeId, faceId2, faceType);
_downArray[faceType]->addDownCell(faceId2, connEdgeId, vtkEdgeType);
// MESSAGE(" From face t:" << vtkFaceType << " " << faceId <<
// " edge " << connEdgeId << " belongs to face t:" << faceType << " " << faceId2);
}//CHRONOSTOP(45);
}
}
}
CHRONOSTOP(23);CHRONO(24);
// compact downward connectivity structure: adjust downward arrays size, replace vector<vector int>> by a single vector<int>
// 3D first then 2D and last 1D to release memory before edge upCells reorganization, (temporary memory use)
for (int vtkType = VTK_QUADRATIC_PYRAMID; vtkType >= 0; vtkType--)
{
if (SMDS_Downward *down = _downArray[vtkType])
{
down->compactStorage();
}
}
// --- Statistics
for (int vtkType = 0; vtkType <= VTK_QUADRATIC_PYRAMID; vtkType++)
{
if (SMDS_Downward *down = _downArray[vtkType])
{
if (down->getMaxId())
{
MESSAGE("Cells of Type " << vtkType << " : number of entities, est: "
<< GuessSize[vtkType] << " real: " << down->getMaxId());
}
}
}CHRONOSTOP(24);CHRONOSTOP(2);
_counters->stats();
} }

View File

@ -11,36 +11,47 @@
#include <vector> #include <vector>
#include <vtkUnstructuredGrid.h> #include <vtkUnstructuredGrid.h>
#include "chrono.hxx"
class SMDS_Downward;
class SMDS_Mesh;
class SMDS_UnstructuredGrid: public vtkUnstructuredGrid class SMDS_UnstructuredGrid: public vtkUnstructuredGrid
{ {
public: public:
void compactGrid(std::vector<int>& idNodesOldToNew, int newNodeSize, void setSMDS_mesh(SMDS_Mesh *mesh);
std::vector<int>& idCellsOldToNew, int newCellSize); void compactGrid(std::vector<int>& idNodesOldToNew, int newNodeSize, std::vector<int>& idCellsOldToNew,
int newCellSize);
virtual unsigned long GetMTime(); virtual unsigned long GetMTime();
virtual void Update(); virtual void Update();
virtual void UpdateInformation(); virtual void UpdateInformation();
static SMDS_UnstructuredGrid* New(); int CellIdToDownId(int vtkCellId);
void setCellIdToDownId(int vtkCellId, int downId);
void BuildDownwardConnectivity();
vtkCellLinks* GetLinks()
{
return Links;
}
SMDS_Downward* getDownArray(unsigned char vtkType)
{
return _downArray[vtkType];
}
static SMDS_UnstructuredGrid* New();
protected: protected:
SMDS_UnstructuredGrid(); SMDS_UnstructuredGrid();
~SMDS_UnstructuredGrid(); ~SMDS_UnstructuredGrid();
void copyNodes(vtkPoints *newPoints, void copyNodes(vtkPoints *newPoints, std::vector<int>& idNodesOldToNew, int& alreadyCopied, int start, int end);
std::vector<int>& idNodesOldToNew, void copyBloc(vtkUnsignedCharArray *newTypes, std::vector<int>& idCellsOldToNew, std::vector<int>& idNodesOldToNew,
int& alreadyCopied, vtkCellArray* newConnectivity, vtkIdTypeArray* newLocations, vtkIdType* pointsCell, int& alreadyCopied,
int start, int start, int end);
int end);
void copyBloc(vtkUnsignedCharArray *newTypes,
std::vector<int>& idCellsOldToNew,
std::vector<int>& idNodesOldToNew,
vtkCellArray* newConnectivity,
vtkIdTypeArray* newLocations,
vtkIdType* pointsCell,
int& alreadyCopied,
int start,
int end);
SMDS_Mesh *_mesh;
std::vector<int> _cellIdToDownId; //!< convert vtk Id to downward[vtkType] id, initialized with -1
std::vector<unsigned char> _downTypes;
std::vector<SMDS_Downward*> _downArray;
counters *_counters;
}; };
#endif /* _SMDS_UNSTRUCTUREDGRID_HXX */ #endif /* _SMDS_UNSTRUCTUREDGRID_HXX */

View File

@ -1,6 +1,7 @@
#include "SMDS_VtkCellIterator.hxx" #include "SMDS_VtkCellIterator.hxx"
SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) : SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId,
SMDSAbs_EntityType aType) :
_mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType) _mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType)
{ {
vtkUnstructuredGrid* grid = _mesh->getGrid(); vtkUnstructuredGrid* grid = _mesh->getGrid();
@ -11,62 +12,62 @@ SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSA
switch (_type) switch (_type)
{ {
case SMDSEntity_Tetra: case SMDSEntity_Tetra:
{ {
this->exchange(1, 2); this->exchange(1, 2);
break; break;
} }
case SMDSEntity_Pyramid: case SMDSEntity_Pyramid:
{ {
this->exchange(1, 3); this->exchange(1, 3);
break; break;
} }
case SMDSEntity_Penta: case SMDSEntity_Penta:
{ {
//this->exchange(1, 2); //this->exchange(1, 2);
//this->exchange(4, 5); //this->exchange(4, 5);
break; break;
} }
case SMDSEntity_Hexa: case SMDSEntity_Hexa:
{ {
this->exchange(1, 3); this->exchange(1, 3);
this->exchange(5, 7); this->exchange(5, 7);
break; break;
} }
case SMDSEntity_Quad_Tetra: case SMDSEntity_Quad_Tetra:
{ {
this->exchange(1, 2); this->exchange(1, 2);
this->exchange(4, 6); this->exchange(4, 6);
this->exchange(8, 9); this->exchange(8, 9);
break; break;
} }
case SMDSEntity_Quad_Pyramid: case SMDSEntity_Quad_Pyramid:
{ {
this->exchange(1, 3); this->exchange(1, 3);
this->exchange(5, 8); this->exchange(5, 8);
this->exchange(6, 7); this->exchange(6, 7);
this->exchange(10, 12); this->exchange(10, 12);
break; break;
} }
case SMDSEntity_Quad_Penta: case SMDSEntity_Quad_Penta:
{ {
//this->exchange(1, 2); //this->exchange(1, 2);
//this->exchange(4, 5); //this->exchange(4, 5);
//this->exchange(6, 8); //this->exchange(6, 8);
//this->exchange(9, 11); //this->exchange(9, 11);
//this->exchange(13, 14); //this->exchange(13, 14);
break; break;
} }
case SMDSEntity_Quad_Hexa: case SMDSEntity_Quad_Hexa:
{ {
this->exchange(1, 3); this->exchange(1, 3);
this->exchange(5, 7); this->exchange(5, 7);
this->exchange(8, 11); this->exchange(8, 11);
this->exchange(9, 10); this->exchange(9, 10);
this->exchange(12, 15); this->exchange(12, 15);
this->exchange(13, 14); this->exchange(13, 14);
this->exchange(17, 19); this->exchange(17, 19);
break; break;
} }
default: default:
break; break;
} }

View File

@ -8,16 +8,21 @@
#include <vtkCell.h> #include <vtkCell.h>
#include <vtkIdList.h> #include <vtkIdList.h>
class SMDS_VtkCellIterator : public SMDS_ElemIterator class SMDS_VtkCellIterator: public SMDS_ElemIterator
{ {
public: public:
SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType); SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId,
SMDSAbs_EntityType aType);
virtual ~SMDS_VtkCellIterator(); virtual ~SMDS_VtkCellIterator();
virtual bool more(); virtual bool more();
virtual const SMDS_MeshElement* next(); virtual const SMDS_MeshElement* next();
inline void exchange(vtkIdType a, vtkIdType b) { vtkIdType t = _vtkIdList->GetId(a); inline void exchange(vtkIdType a, vtkIdType b)
_vtkIdList->SetId(a, _vtkIdList->GetId(b)); {
_vtkIdList->SetId(b, t); }; vtkIdType t = _vtkIdList->GetId(a);
_vtkIdList->SetId(a, _vtkIdList->GetId(b));
_vtkIdList->SetId(b, t);
}
protected: protected:
SMDS_Mesh* _mesh; SMDS_Mesh* _mesh;
int _cellId; int _cellId;

View File

@ -16,7 +16,7 @@ SMDS_VtkEdge::SMDS_VtkEdge()
SMDS_VtkEdge::SMDS_VtkEdge(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh) SMDS_VtkEdge::SMDS_VtkEdge(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{ {
init(nodeIds, mesh); init(nodeIds, mesh);
} }
SMDS_VtkEdge::~SMDS_VtkEdge() SMDS_VtkEdge::~SMDS_VtkEdge()
@ -25,53 +25,53 @@ SMDS_VtkEdge::~SMDS_VtkEdge()
void SMDS_VtkEdge::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh) void SMDS_VtkEdge::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{ {
vtkUnstructuredGrid* grid = mesh->getGrid(); vtkUnstructuredGrid* grid = mesh->getGrid();
myIdInShape = -1; myIdInShape = -1;
myMeshId = mesh->getMeshId(); myMeshId = mesh->getMeshId();
vtkIdType aType = VTK_LINE; vtkIdType aType = VTK_LINE;
if (nodeIds.size() == 3) if (nodeIds.size() == 3)
aType = VTK_QUADRATIC_EDGE; aType = VTK_QUADRATIC_EDGE;
myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]); myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
} }
bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1, bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2) const SMDS_MeshNode * node2)
{ {
return true; return true;
} }
void SMDS_VtkEdge::Print(std::ostream & OS) const void SMDS_VtkEdge::Print(std::ostream & OS) const
{ {
OS << "edge <" << GetID() << "> : "; OS << "edge <" << GetID() << "> : ";
} }
int SMDS_VtkEdge::NbNodes() const int SMDS_VtkEdge::NbNodes() const
{ {
vtkUnstructuredGrid* grid =SMDS_Mesh::_meshList[myMeshId]->getGrid(); vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints(); int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
assert(nbPoints >=2); assert(nbPoints >= 2);
return nbPoints; return nbPoints;
} }
int SMDS_VtkEdge::NbEdges() const int SMDS_VtkEdge::NbEdges() const
{ {
return 1; return 1;
} }
SMDSAbs_EntityType SMDS_VtkEdge::GetEntityType() const SMDSAbs_EntityType SMDS_VtkEdge::GetEntityType() const
{ {
if (NbNodes() == 2) if (NbNodes() == 2)
return SMDSEntity_Edge; return SMDSEntity_Edge;
else else
return SMDSEntity_Quad_Edge; return SMDSEntity_Quad_Edge;
} }
vtkIdType SMDS_VtkEdge::GetVtkType() const vtkIdType SMDS_VtkEdge::GetVtkType() const
{ {
if (NbNodes() == 2) if (NbNodes() == 2)
return VTK_LINE; return VTK_LINE;
else else
return VTK_QUADRATIC_EDGE; return VTK_QUADRATIC_EDGE;
} }
@ -89,20 +89,24 @@ SMDS_VtkEdge::GetNode(const int ind) const
bool SMDS_VtkEdge::IsQuadratic() const bool SMDS_VtkEdge::IsQuadratic() const
{ {
if (this->NbNodes() > 2) if (this->NbNodes() > 2)
return true; return true;
else else
return false; return false;
} }
SMDS_ElemIteratorPtr SMDS_VtkEdge::elementsIterator(SMDSAbs_ElementType type) const SMDS_ElemIteratorPtr SMDS_VtkEdge::elementsIterator(SMDSAbs_ElementType type) const
{ {
switch (type) switch (type)
{ {
case SMDSAbs_Node: case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator( return SMDS_ElemIteratorPtr(
SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); new SMDS_VtkCellIterator(
default: SMDS_Mesh::_meshList[myMeshId],
MESSAGE("ERROR : Iterator not implemented"); myVtkID,
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); GetEntityType()));
} default:
MESSAGE("ERROR : Iterator not implemented")
;
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
}
} }

View File

@ -15,7 +15,7 @@ SMDS_VtkFace::SMDS_VtkFace()
SMDS_VtkFace::SMDS_VtkFace(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh) SMDS_VtkFace::SMDS_VtkFace(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{ {
init(nodeIds, mesh); init(nodeIds, mesh);
} }
SMDS_VtkFace::~SMDS_VtkFace() SMDS_VtkFace::~SMDS_VtkFace()
@ -24,54 +24,68 @@ SMDS_VtkFace::~SMDS_VtkFace()
void SMDS_VtkFace::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh) void SMDS_VtkFace::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{ {
vtkUnstructuredGrid* grid = mesh->getGrid(); vtkUnstructuredGrid* grid = mesh->getGrid();
myIdInShape = -1; myIdInShape = -1;
myMeshId = mesh->getMeshId(); myMeshId = mesh->getMeshId();
vtkIdType aType = VTK_TRIANGLE; vtkIdType aType = VTK_TRIANGLE;
switch(nodeIds.size()) switch (nodeIds.size())
{ {
case 3: aType = VTK_TRIANGLE; break; case 3:
case 4: aType = VTK_QUAD; break; aType = VTK_TRIANGLE;
case 6: aType = VTK_QUADRATIC_TRIANGLE; break; break;
case 8: aType = VTK_QUADRATIC_QUAD; break; case 4:
default: aType = VTK_TRIANGLE; break; aType = VTK_QUAD;
} break;
myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]); case 6:
aType = VTK_QUADRATIC_TRIANGLE;
break;
case 8:
aType = VTK_QUADRATIC_QUAD;
break;
default:
aType = VTK_TRIANGLE;
break;
}
myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
} }
bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
{ {
return true; return true;
} }
void SMDS_VtkFace::Print(std::ostream & OS) const void SMDS_VtkFace::Print(std::ostream & OS) const
{ {
OS << "edge <" << GetID() << "> : "; OS << "edge <" << GetID() << "> : ";
} }
int SMDS_VtkFace::NbEdges() const int SMDS_VtkFace::NbEdges() const
{ {
switch(NbNodes()) switch (NbNodes())
{ {
case 3: case 3:
case 6: return 3; case 6:
case 4: return 3;
case 8: return 4; case 4:
default: MESSAGE("invalid number of nodes"); case 8:
} return 4;
return 0; default:
MESSAGE("invalid number of nodes")
;
}
return 0;
} }
int SMDS_VtkFace::NbFaces() const int SMDS_VtkFace::NbFaces() const
{ {
return 1; return 1;
} }
int SMDS_VtkFace::NbNodes() const int SMDS_VtkFace::NbNodes() const
{ {
vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints(); int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
return nbPoints; return nbPoints;
} }
/*! /*!
@ -88,44 +102,57 @@ SMDS_VtkFace::GetNode(const int ind) const
bool SMDS_VtkFace::IsQuadratic() const bool SMDS_VtkFace::IsQuadratic() const
{ {
if (this->NbNodes() > 5) if (this->NbNodes() > 5)
return true; return true;
else else
return false; return false;
} }
SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
{ {
SMDSAbs_EntityType aType = SMDSEntity_Triangle; SMDSAbs_EntityType aType = SMDSEntity_Triangle;
switch(NbNodes()) switch (NbNodes())
{ {
case 3: case 3:
case 6: aType = SMDSEntity_Triangle; break; case 6:
case 4: aType = SMDSEntity_Triangle;
case 8: aType = SMDSEntity_Quadrangle; break; break;
} case 4:
return aType; case 8:
aType = SMDSEntity_Quadrangle;
break;
}
return aType;
} }
vtkIdType SMDS_VtkFace::GetVtkType() const vtkIdType SMDS_VtkFace::GetVtkType() const
{ {
switch(NbNodes()) switch (NbNodes())
{ {
case 3: return VTK_TRIANGLE; case 3:
case 6: return VTK_QUADRATIC_TRIANGLE; return VTK_TRIANGLE;
case 4: return VTK_QUAD; case 6:
case 8: return VTK_QUADRATIC_QUAD; return VTK_QUADRATIC_TRIANGLE;
} case 4:
return VTK_QUAD;
case 8:
return VTK_QUADRATIC_QUAD;
}
} }
SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
{ {
switch (type) switch (type)
{ {
case SMDSAbs_Node: case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); return SMDS_ElemIteratorPtr(
default: new SMDS_VtkCellIterator(
MESSAGE("ERROR : Iterator not implemented"); SMDS_Mesh::_meshList[myMeshId],
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); myVtkID,
} GetEntityType()));
default:
MESSAGE("ERROR : Iterator not implemented")
;
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
}
} }

View File

@ -1,4 +1,3 @@
#include "SMDS_VtkVolume.hxx" #include "SMDS_VtkVolume.hxx"
#include "SMDS_MeshNode.hxx" #include "SMDS_MeshNode.hxx"
#include "SMDS_Mesh.hxx" #include "SMDS_Mesh.hxx"
@ -8,7 +7,6 @@
#include <vector> #include <vector>
SMDS_VtkVolume::SMDS_VtkVolume() SMDS_VtkVolume::SMDS_VtkVolume()
{ {
} }
@ -27,23 +25,41 @@ void SMDS_VtkVolume::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
myIdInShape = -1; myIdInShape = -1;
myMeshId = mesh->getMeshId(); myMeshId = mesh->getMeshId();
vtkIdType aType = VTK_TETRA; vtkIdType aType = VTK_TETRA;
switch(nodeIds.size()) switch (nodeIds.size())
{ {
case 4: aType = VTK_TETRA; break; case 4:
case 5: aType = VTK_PYRAMID; break; aType = VTK_TETRA;
case 6: aType = VTK_WEDGE; break; break;
case 8: aType = VTK_HEXAHEDRON; break; case 5:
case 10: aType = VTK_QUADRATIC_TETRA; break; aType = VTK_PYRAMID;
case 13: aType = VTK_QUADRATIC_PYRAMID; break; break;
case 15: aType = VTK_QUADRATIC_WEDGE; break; case 6:
case 20: aType = VTK_QUADRATIC_HEXAHEDRON; break; aType = VTK_WEDGE;
default: aType = VTK_HEXAHEDRON; break; break;
} case 8:
aType = VTK_HEXAHEDRON;
break;
case 10:
aType = VTK_QUADRATIC_TETRA;
break;
case 13:
aType = VTK_QUADRATIC_PYRAMID;
break;
case 15:
aType = VTK_QUADRATIC_WEDGE;
break;
case 20:
aType = VTK_QUADRATIC_HEXAHEDRON;
break;
default:
aType = VTK_HEXAHEDRON;
break;
}
myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]); myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
} }
bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[], bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[],
const int nbNodes) const int nbNodes)
{ {
// utilise dans SMDS_Mesh // utilise dans SMDS_Mesh
return true; return true;
@ -60,55 +76,72 @@ void SMDS_VtkVolume::Print(ostream & OS) const
int SMDS_VtkVolume::NbFaces() const int SMDS_VtkVolume::NbFaces() const
{ {
switch(NbNodes()) switch (NbNodes())
{ {
case 4: case 4:
case 10: return 4; case 10:
case 5: return 4;
case 13: return 5; case 5:
case 6: case 13:
case 15: return 5; return 5;
case 8: case 6:
case 20: return 6; case 15:
default: MESSAGE("invalid number of nodes"); return 5;
} case 8:
case 20:
return 6;
default:
MESSAGE("invalid number of nodes")
;
}
return 0; return 0;
} }
int SMDS_VtkVolume::NbNodes() const int SMDS_VtkVolume::NbNodes() const
{ {
vtkUnstructuredGrid* grid =SMDS_Mesh::_meshList[myMeshId]->getGrid(); vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints(); int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
return nbPoints; return nbPoints;
} }
int SMDS_VtkVolume::NbEdges() const int SMDS_VtkVolume::NbEdges() const
{ {
switch(NbNodes()) switch (NbNodes())
{ {
case 4: case 4:
case 10: return 6; case 10:
case 5: return 6;
case 13: return 8; case 5:
case 6: case 13:
case 15: return 9; return 8;
case 8: case 6:
case 20: return 12; case 15:
default: MESSAGE("invalid number of nodes"); return 9;
} case 8:
case 20:
return 12;
default:
MESSAGE("invalid number of nodes")
;
}
return 0; return 0;
} }
SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) const SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) const
{ {
switch(type) switch (type)
{ {
case SMDSAbs_Node: case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); return SMDS_ElemIteratorPtr(
new SMDS_VtkCellIterator(
SMDS_Mesh::_meshList[myMeshId],
myVtkID,
GetEntityType()));
default: default:
MESSAGE("ERROR : Iterator not implemented"); MESSAGE("ERROR : Iterator not implemented")
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); ;
} return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
}
} }
SMDSAbs_ElementType SMDS_VtkVolume::GetType() const SMDSAbs_ElementType SMDS_VtkVolume::GetType() const
@ -129,43 +162,79 @@ const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const
bool SMDS_VtkVolume::IsQuadratic() const bool SMDS_VtkVolume::IsQuadratic() const
{ {
if (this->NbNodes() > 9) if (this->NbNodes() > 9)
return true; return true;
else else
return false; return false;
} }
SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const
{ {
SMDSAbs_EntityType aType = SMDSEntity_Tetra; SMDSAbs_EntityType aType = SMDSEntity_Tetra;
switch(NbNodes()) switch (NbNodes())
{ {
case 4: aType = SMDSEntity_Tetra; break; case 4:
case 5: aType = SMDSEntity_Pyramid; break; aType = SMDSEntity_Tetra;
case 6: aType = SMDSEntity_Penta; break; break;
case 8: aType = SMDSEntity_Hexa; break; case 5:
case 10: aType = SMDSEntity_Quad_Tetra; break; aType = SMDSEntity_Pyramid;
case 13: aType = SMDSEntity_Quad_Pyramid; break; break;
case 15: aType = SMDSEntity_Quad_Penta; break; case 6:
case 20: aType = SMDSEntity_Quad_Hexa; break; aType = SMDSEntity_Penta;
default: aType = SMDSEntity_Hexa; break; break;
} case 8:
aType = SMDSEntity_Hexa;
break;
case 10:
aType = SMDSEntity_Quad_Tetra;
break;
case 13:
aType = SMDSEntity_Quad_Pyramid;
break;
case 15:
aType = SMDSEntity_Quad_Penta;
break;
case 20:
aType = SMDSEntity_Quad_Hexa;
break;
default:
aType = SMDSEntity_Hexa;
break;
}
return aType; return aType;
} }
vtkIdType SMDS_VtkVolume::GetVtkType() const vtkIdType SMDS_VtkVolume::GetVtkType() const
{ {
vtkIdType aType = VTK_TETRA; vtkIdType aType = VTK_TETRA;
switch(NbNodes()) switch (NbNodes())
{ {
case 4: aType = VTK_TETRA; break; case 4:
case 5: aType = VTK_PYRAMID; break; aType = VTK_TETRA;
case 6: aType = VTK_WEDGE; break; break;
case 8: aType = VTK_HEXAHEDRON; break; case 5:
case 10: aType = VTK_QUADRATIC_TETRA; break; aType = VTK_PYRAMID;
case 13: aType = VTK_QUADRATIC_PYRAMID; break; break;
case 15: aType = VTK_QUADRATIC_WEDGE; break; case 6:
case 20: aType = VTK_QUADRATIC_HEXAHEDRON; break; aType = VTK_WEDGE;
default: aType = VTK_HEXAHEDRON; break; break;
} case 8:
return aType; aType = VTK_HEXAHEDRON;
break;
case 10:
aType = VTK_QUADRATIC_TETRA;
break;
case 13:
aType = VTK_QUADRATIC_PYRAMID;
break;
case 15:
aType = VTK_QUADRATIC_WEDGE;
break;
case 20:
aType = VTK_QUADRATIC_HEXAHEDRON;
break;
default:
aType = VTK_HEXAHEDRON;
break;
}
return aType;
} }

View File

@ -7,15 +7,14 @@
#include <vtkUnstructuredGrid.h> #include <vtkUnstructuredGrid.h>
#include <vector> #include <vector>
class SMDS_EXPORT SMDS_VtkVolume:public SMDS_MeshVolume class SMDS_EXPORT SMDS_VtkVolume: public SMDS_MeshVolume
{ {
public: public:
SMDS_VtkVolume(); SMDS_VtkVolume();
SMDS_VtkVolume(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh); SMDS_VtkVolume(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh);
~SMDS_VtkVolume(); ~SMDS_VtkVolume();
void init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh); void init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh);
bool ChangeNodes(const SMDS_MeshNode* nodes[], bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes);
const int nbNodes);
void Print(std::ostream & OS) const; void Print(std::ostream & OS) const;
int NbFaces() const; int NbFaces() const;

85
src/SMDS/chrono.cxx Normal file
View File

@ -0,0 +1,85 @@
// Copyright (C) 2006-2010 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "chrono.hxx"
#include "utilities.h"
using namespace std;
cntStruct* counters::_ctrs = 0;
counters::counters(int nb)
{
MESSAGE("counters::counters(int nb)");
_nbChrono = nb;
_ctrs = new cntStruct[_nbChrono];
for (int i=0; i< _nbChrono; i++)
{
_ctrs[i]._ctrNames = 0;
_ctrs[i]._ctrLines = 0;
_ctrs[i]._ctrOccur = 0;
_ctrs[i]._ctrCumul = 0;
}
MESSAGE("counters::counters()");
}
counters::~counters()
{
stats();
}
void counters::stats()
{
MESSAGE("counters::stats()");
for (int i=0; i < _nbChrono; i++)
if (_ctrs[i]._ctrOccur)
{
MESSAGE("Compteur[" << i << "]: "<< _ctrs[i]._ctrNames << "[" << _ctrs[i]._ctrLines << "]");
MESSAGE(" " << _ctrs[i]._ctrOccur);
MESSAGE(" " << _ctrs[i]._ctrCumul);
}
}
chrono::chrono(int i) : _ctr(i), _run(true)
{
//MESSAGE("chrono::chrono " << _ctr << " " << _run);
_start = clock();
}
chrono::~chrono()
{
if (_run) stop();
}
void chrono::stop()
{
//MESSAGE("chrono::stop " << _ctr << " " << _run);
if (_run)
{
_run = false;
_end = clock();
double elapse = double(_end - _start)/double(CLOCKS_PER_SEC);
counters::_ctrs[_ctr]._ctrOccur++;
counters::_ctrs[_ctr]._ctrCumul += elapse;
}
}

73
src/SMDS/chrono.hxx Normal file
View File

@ -0,0 +1,73 @@
// Copyright (C) 2006-2010 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#ifndef _CHRONO_HXX_
#define _CHRONO_HXX_
#include <vector>
#include <string>
#include <iostream>
#include <ctime>
typedef struct acnt
{
char* _ctrNames;
int _ctrLines;
int _ctrOccur;
double _ctrCumul;
} cntStruct;
class counters
{
public:
static cntStruct *_ctrs;
counters(int nb);
~counters();
void stats();
protected:
int _nbChrono;
};
class chrono
{
public:
chrono(int i);
~chrono();
void stop();
protected:
bool _run;
int _ctr;
clock_t _start, _end;
};
#ifdef CHRONODEF
#define CHRONO(i) counters::_ctrs[i]._ctrNames = (char *)__FILE__; \
counters::_ctrs[i]._ctrLines = __LINE__; \
chrono aChrono##i(i);
#define CHRONOSTOP(i) aChrono##i.stop();
#else // CHRONODEF
#define CHRONO(i)
#define CHRONOSTOP(i)
#endif // CHRONODEF
#endif // _CHRONO_HXX_

View File

@ -1,19 +1,18 @@
#ifndef _MEMOIRE_H_ #ifndef _MEMOIRE_H_
#define _MEMOIRE_H_ #define _MEMOIRE_H_
#include <malloc.h> #include <malloc.h>
#include <iostream> #include <iostream>
void memostat( const char* f, int l); void memostat(const char* f, int l);
void memostat( const char* f, int l) void memostat(const char* f, int l)
{ {
/* struct mallinfo mem = mallinfo(); */ /* struct mallinfo mem = mallinfo(); */
/* std::cerr << f << ":"<< l << " " << mem.arena << " " << mem.ordblks << " " << mem.hblks << " " << mem.hblkhd << " " << mem.uordblks << " " << mem.fordblks << " " << mem.keepcost << std::endl; */ /* std::cerr << f << ":"<< l << " " << mem.arena << " " << mem.ordblks << " " << mem.hblks << " " << mem.hblkhd << " " << mem.uordblks << " " << mem.fordblks << " " << mem.keepcost << std::endl; */
std::cerr << f << ":"<< l << " --------------------------"<< std::endl; std::cerr << f << ":" << l << " --------------------------" << std::endl;
malloc_stats(); malloc_stats();
std::cerr << f << ":"<< l << " --------------------------"<< std::endl; std::cerr << f << ":" << l << " --------------------------" << std::endl;
} }
#define MEMOSTAT memostat( __FILE__, __LINE__ ) #define MEMOSTAT memostat( __FILE__, __LINE__ )

View File

@ -1914,7 +1914,7 @@ void SMESHDS_Mesh::compactMesh()
myVtkIndex.swap(newVtkToSmds); myVtkIndex.swap(newVtkToSmds);
MESSAGE("myCells.size()=" << myCells.size() << " myIDElements.size()=" << myIDElements.size() << " myVtkIndex.size()=" << myVtkIndex.size() ); MESSAGE("myCells.size()=" << myCells.size() << " myIDElements.size()=" << myIDElements.size() << " myVtkIndex.size()=" << myVtkIndex.size() );
myGrid->BuildDownwardConnectivity();
// ---TODO: myNodes, myElements in submeshes // ---TODO: myNodes, myElements in submeshes