+// Copyright (C) 2010-2011 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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
+//
+
#define CHRONODEF
#include "SMDS_UnstructuredGrid.hxx"
#include "SMDS_Mesh.hxx"
#include "SMDS_MeshInfo.hxx"
#include "SMDS_Downward.hxx"
+#include "SMDS_MeshVolume.hxx"
#include "utilities.h"
#include <vtkUnsignedCharArray.h>
#include <list>
+#include <climits>
using namespace std;
int SMDS_UnstructuredGrid::CellIdToDownId(int vtkCellId)
{
- // ASSERT((vtkCellId >= 0) && (vtkCellId < _cellIdToDownId.size()));
+ if((vtkCellId < 0) || (vtkCellId >= _cellIdToDownId.size()))
+ {
+ //MESSAGE("SMDS_UnstructuredGrid::CellIdToDownId structure not up to date: vtkCellId="
+ // << vtkCellId << " max="<< _cellIdToDownId.size());
+ return -1;
+ }
return _cellIdToDownId[vtkCellId];
}
_cellIdToDownId[vtkCellId] = downId;
}
+void SMDS_UnstructuredGrid::CleanDownwardConnectivity()
+{
+ for (int i = 0; i < _downArray.size(); i++)
+ {
+ if (_downArray[i])
+ delete _downArray[i];
+ _downArray[i] = 0;
+ }
+ _cellIdToDownId.clear();
+}
+
/*! Build downward connectivity: to do only when needed because heavy memory load.
* Downward connectivity is no more valid if vtkUnstructuredGrid is modified.
*
// --- erase previous data if any
- for (int i = 0; i < _downArray.size(); i++)
- {
- if (_downArray[i])
- delete _downArray[i];
- _downArray[i] = 0;
- }
- _cellIdToDownId.clear();
+ this->CleanDownwardConnectivity();
// --- create SMDS_Downward structures (in _downArray vector[vtkCellType])
return nb;
}
+/*! get the volumes containing a face or an edge of the grid
+ * The edge or face belongs to the vtkUnstructuredGrid
+ * @param volVtkIds vector of parent volume ids to fill (reserve enough space!)
+ * @param vtkId vtk id of the face or edge
+ */
+int SMDS_UnstructuredGrid::GetParentVolumes(int* volVtkIds, int vtkId)
+{
+ int vtkType = this->GetCellType(vtkId);
+ int dim = SMDS_Downward::getCellDimension(vtkType);
+ int nbFaces = 0;
+ unsigned char cellTypes[1000];
+ int downCellId[1000];
+ if (dim == 1)
+ {
+ int downId = this->CellIdToDownId(vtkId);
+ if (downId < 0)
+ {
+ MESSAGE("Downward structure not up to date: new edge not taken into account");
+ return 0;
+ }
+ nbFaces = _downArray[vtkType]->getNumberOfUpCells(downId);
+ const int *upCells = _downArray[vtkType]->getUpCells(downId);
+ const unsigned char* upTypes = _downArray[vtkType]->getUpTypes(downId);
+ for (int i=0; i< nbFaces; i++)
+ {
+ cellTypes[i] = upTypes[i];
+ downCellId[i] = upCells[i];
+ }
+ }
+ else if (dim == 2)
+ {
+ nbFaces = 1;
+ cellTypes[0] = this->GetCellType(vtkId);
+ int downId = this->CellIdToDownId(vtkId);
+ if (downId < 0)
+ {
+ MESSAGE("Downward structure not up to date: new face not taken into account");
+ return 0;
+ }
+ downCellId[0] = downId;
+ }
+
+ int nbvol =0;
+ for (int i=0; i<nbFaces; i++)
+ {
+ int vtkTypeFace = cellTypes[i];
+ int downId = downCellId[i];
+ int nv = _downArray[vtkTypeFace]->getNumberOfUpCells(downId);
+ const int *upCells = _downArray[vtkTypeFace]->getUpCells(downId);
+ const unsigned char* upTypes = _downArray[vtkTypeFace]->getUpTypes(downId);
+ for (int j=0; j<nv; j++)
+ {
+ int vtkVolId = _downArray[upTypes[j]]->getVtkCellId(upCells[j]);
+ if (vtkVolId >= 0)
+ volVtkIds[nbvol++] = vtkVolId;
+ }
+ }
+ return nbvol;
+}
+
+/*! get the volumes containing a face or an edge of the downward structure
+ * The edge or face does not necessary belong to the vtkUnstructuredGrid
+ * @param volVtkIds vector of parent volume ids to fill (reserve enough space!)
+ * @param downId id in the downward structure
+ * @param downType type of cell
+ */
+int SMDS_UnstructuredGrid::GetParentVolumes(int* volVtkIds, int downId, unsigned char downType)
+{
+ int vtkType = downType;
+ int dim = SMDS_Downward::getCellDimension(vtkType);
+ int nbFaces = 0;
+ unsigned char cellTypes[1000];
+ int downCellId[1000];
+ if (dim == 1)
+ {
+ nbFaces = _downArray[vtkType]->getNumberOfUpCells(downId);
+ const int *upCells = _downArray[vtkType]->getUpCells(downId);
+ const unsigned char* upTypes = _downArray[vtkType]->getUpTypes(downId);
+ for (int i=0; i< nbFaces; i++)
+ {
+ cellTypes[i] = upTypes[i];
+ downCellId[i] = upCells[i];
+ }
+ }
+ else if (dim == 2)
+ {
+ nbFaces = 1;
+ cellTypes[0] = vtkType;
+ downCellId[0] = downId;
+ }
+
+ int nbvol =0;
+ for (int i=0; i<nbFaces; i++)
+ {
+ int vtkTypeFace = cellTypes[i];
+ int downId = downCellId[i];
+ int nv = _downArray[vtkTypeFace]->getNumberOfUpCells(downId);
+ const int *upCells = _downArray[vtkTypeFace]->getUpCells(downId);
+ const unsigned char* upTypes = _downArray[vtkTypeFace]->getUpTypes(downId);
+ for (int j=0; j<nv; j++)
+ {
+ int vtkVolId = _downArray[upTypes[j]]->getVtkCellId(upCells[j]);
+ if (vtkVolId >= 0)
+ volVtkIds[nbvol++] = vtkVolId;
+ }
+ }
+ return nbvol;
+}
+
/*! get the node id's of a cell.
* The cell is defined by it's downward connectivity id and type.
* @param nodeSet set of of vtk node id's to fill.
this->Links->BuildLinks(this, this->Connectivity);
this->Links->Delete();
}
+
+/*! Create a volume (prism or hexahedron) by duplication of a face.
+ * Designed for use in creation of flat elements separating volume domains.
+ * A face separating two domains is shared by two volume cells.
+ * All the nodes are already created (for the two faces).
+ * Each original Node is associated to corresponding nodes in the domains.
+ * Some nodes may be duplicated for more than two domains, when domain separations intersect.
+ * In that case, even some of the nodes to use for the original face may be changed.
+ * @param vtkVolId: vtk id of a volume containing the face, to get an orientation for the face.
+ * @param domain1: domain of the original face
+ * @param domain2: domain of the duplicated face
+ * @param originalNodes: the vtk node ids of the original face
+ * @param nodeDomains: map(original id --> map(domain --> duplicated node id))
+ * @return ok if success.
+ */
+SMDS_MeshVolume* SMDS_UnstructuredGrid::extrudeVolumeFromFace(int vtkVolId,
+ int domain1,
+ int domain2,
+ std::set<int>& originalNodes,
+ std::map<int, std::map<int, int> >& nodeDomains,
+ std::map<int, std::map<long, int> >& nodeQuadDomains)
+{
+ //MESSAGE("extrudeVolumeFromFace " << vtkVolId);
+ vector<vtkIdType> orderedOriginals;
+ orderedOriginals.clear();
+ set<int>::const_iterator it = originalNodes.begin();
+ for (; it != originalNodes.end(); ++it)
+ orderedOriginals.push_back(*it);
+
+ int nbNodes = this->getOrderedNodesOfFace(vtkVolId, orderedOriginals);
+ vector<vtkIdType> orderedNodes;
+
+ switch (orderedOriginals.size())
+ {
+ case 3:
+ case 4:
+ for (int i = 0; i < nbNodes; i++)
+ orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
+ for (int i = 0; i < nbNodes; i++)
+ orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
+ break;
+ case 6:
+ case 8:
+ {
+ long dom1 = domain1;
+ long dom2 = domain2;
+ long dom1_2; // for nodeQuadDomains
+ if (domain1 < domain2)
+ dom1_2 = dom1 + INT_MAX * dom2;
+ else
+ dom1_2 = dom2 + INT_MAX * dom1;
+ //cerr << "dom1=" << dom1 << " dom2=" << dom2 << " dom1_2=" << dom1_2 << endl;
+ int ima = orderedOriginals.size();
+ int mid = orderedOriginals.size() / 2;
+ //cerr << "ima=" << ima << " mid=" << mid << endl;
+ for (int i = 0; i < mid; i++)
+ orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
+ for (int i = 0; i < mid; i++)
+ orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
+ for (int i = mid; i < ima; i++)
+ orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
+ for (int i = mid; i < ima; i++)
+ orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
+ for (int i = 0; i < mid; i++)
+ {
+ int oldId = orderedOriginals[i];
+ int newId;
+ if (nodeQuadDomains.count(oldId) && nodeQuadDomains[oldId].count(dom1_2))
+ newId = nodeQuadDomains[oldId][dom1_2];
+ else
+ {
+ double *coords = this->GetPoint(oldId);
+ SMDS_MeshNode *newNode = _mesh->AddNode(coords[0], coords[1], coords[2]);
+ newId = newNode->getVtkId();
+ std::map<long, int> emptyMap;
+ nodeQuadDomains[oldId] = emptyMap;
+ nodeQuadDomains[oldId][dom1_2] = newId;
+ }
+ orderedNodes.push_back(newId);
+ }
+ }
+ break;
+ default:
+ ASSERT(0);
+ }
+
+ SMDS_MeshVolume *vol = _mesh->AddVolumeFromVtkIds(orderedNodes);
+
+ // TODO update subshape list of elements and nodes
+ return vol;
+}