[cig-commits] r22021 - in short/3D/PyLith/trunk/libsrc/pylith: meshio topology
brad at geodynamics.org
brad at geodynamics.org
Thu May 9 17:51:33 PDT 2013
Author: brad
Date: 2013-05-09 17:51:32 -0700 (Thu, 09 May 2013)
New Revision: 22021
Modified:
short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterVTK.cc
short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterVTK.hh
short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc
Log:
Small cleanup for opening/closing VTK files.
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterVTK.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterVTK.cc 2013-05-09 23:46:43 UTC (rev 22020)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterVTK.cc 2013-05-10 00:51:32 UTC (rev 22021)
@@ -38,6 +38,8 @@
_timeFormat("%f"),
_viewer(NULL),
_dm(NULL),
+ _isOpen(false),
+ _isOpenTimeStep(false),
_wroteVertexHeader(false),
_wroteCellHeader(false),
_precision(6)
@@ -49,8 +51,8 @@
template<typename mesh_type, typename field_type>
pylith::meshio::DataWriterVTK<mesh_type,field_type>::~DataWriterVTK(void)
{ // destructor
- closeTimeStep(); // Just in case
- close(); // Just in case
+ closeTimeStep(); // Insure time step is closed.
+ close(); // Insure clean up.
deallocate();
} // destructor
@@ -77,6 +79,8 @@
_timeFormat(w._timeFormat),
_viewer(NULL),
_dm(NULL),
+ _isOpen(w._isOpen),
+ _isOpenTimeStep(w._isOpenTimeStep),
_wroteVertexHeader(w._wroteVertexHeader),
_wroteCellHeader(w._wroteCellHeader)
{ // copy constructor
@@ -136,22 +140,23 @@
// Save handle for actions required in closeTimeStep() and close();
PetscErrorCode err = 0;
err = DMDestroy(&_dm);PYLITH_CHECK_ERROR(err);
- PetscDM dmMesh = mesh.dmMesh();assert(dmMesh);
- _dm = dmMesh;assert(_dm);
+ _dm = mesh.dmMesh();assert(_dm);
err = PetscObjectReference((PetscObject) _dm);PYLITH_CHECK_ERROR(err);
// Create VTK label in DM: Cleared in close().
if (label) {
- topology::StratumIS cellsIS(dmMesh, label, labelId);
+ topology::StratumIS cellsIS(_dm, label, labelId);
const PetscInt ncells = cellsIS.size();
const PetscInt* cells = cellsIS.points();
for (PetscInt c=0; c < ncells; ++c) {
- err = DMPlexSetLabelValue(dmMesh, "vtk", cells[c], 1);PYLITH_CHECK_ERROR(err);
+ err = DMPlexSetLabelValue(_dm, "vtk", cells[c], 1);PYLITH_CHECK_ERROR(err);
} // for
} // if
+ _isOpen = true;
+
PYLITH_METHOD_END;
} // open
@@ -163,7 +168,8 @@
{ // close
PYLITH_METHOD_BEGIN;
- if (_dm) {
+ if (_isOpen) {
+ assert(_dm);
PetscBool hasLabel = PETSC_FALSE;
PetscErrorCode err = DMPlexHasLabel(_dm, "vtk", &hasLabel);PYLITH_CHECK_ERROR(err);
if (hasLabel) {
@@ -172,6 +178,7 @@
} // if
err = DMDestroy(&_dm);PYLITH_CHECK_ERROR(err);
} // if
+ _isOpen = false;
DataWriter<mesh_type, field_type>::close();
@@ -189,6 +196,9 @@
{ // openTimeStep
PYLITH_METHOD_BEGIN;
+ assert(_dm && _dm == mesh.dmMesh());
+ assert(_isOpen && !_isOpenTimeStep);
+
PetscErrorCode err = 0;
const std::string& filename = _vtkFilename(t);
@@ -199,9 +209,11 @@
err = PetscViewerFileSetName(_viewer, filename.c_str());PYLITH_CHECK_ERROR(err);
// Increment reference count on mesh DM, because the viewer destroys the DM.
- assert(_dm && _dm == mesh.dmMesh());
+ assert(_dm);
err = PetscObjectReference((PetscObject) _dm);PYLITH_CHECK_ERROR(err);
+ _isOpenTimeStep = true;
+
PYLITH_METHOD_END;
} // openTimeStep
@@ -214,12 +226,13 @@
PYLITH_METHOD_BEGIN;
// Account for possibility that no fields were written, so viewer doesn't have handle to DM.
- if (_dm && _viewer && !_wroteVertexHeader && !_wroteCellHeader) {
+ if (_isOpenTimeStep && !_wroteVertexHeader && !_wroteCellHeader) {
// No fields written, so must manually dereference the mesh DM.
PetscErrorCode err = PetscObjectDereference((PetscObject) _dm);PYLITH_CHECK_ERROR(err);
} // if
PetscErrorCode err = PetscViewerDestroy(&_viewer);PYLITH_CHECK_ERROR(err);
+ _isOpenTimeStep = false;
_wroteVertexHeader = false;
_wroteCellHeader = false;
@@ -236,8 +249,8 @@
{ // writeVertexField
PYLITH_METHOD_BEGIN;
- assert(_dm);
- PetscDM dmMesh = mesh.dmMesh();assert(dmMesh);
+ assert(_dm && _dm == mesh.dmMesh());
+ assert(_isOpen && _isOpenTimeStep);
// Could check the field.petscSection() matches the default section from VecGetDM().
Vec v = field.localVector();assert(v);
@@ -247,7 +260,7 @@
// Will change to just VecView() once I setup the vectors correctly
// (use VecSetOperation() to change the view method).
PetscViewerVTKFieldType ft = field.vectorFieldType() != topology::FieldBase::VECTOR ? PETSC_VTK_POINT_FIELD : PETSC_VTK_POINT_VECTOR_FIELD;
- PetscErrorCode err = PetscViewerVTKAddField(_viewer, (PetscObject) dmMesh, DMPlexVTKWriteAll, ft, (PetscObject) v);PYLITH_CHECK_ERROR(err);
+ PetscErrorCode err = PetscViewerVTKAddField(_viewer, (PetscObject) _dm, DMPlexVTKWriteAll, ft, (PetscObject) v);PYLITH_CHECK_ERROR(err);
err = PetscObjectReference((PetscObject) v);PYLITH_CHECK_ERROR(err); /* Needed because viewer destroys the Vec */
_wroteVertexHeader = true;
@@ -266,8 +279,8 @@
{ // writeCellField
PYLITH_METHOD_BEGIN;
- assert(_dm);
- PetscDM dmMesh = field.mesh().dmMesh();assert(dmMesh);
+ assert(_dm && _dm == field.mesh().dmMesh());
+ assert(_isOpen && _isOpenTimeStep);
PetscVec v = field.localVector();assert(v);
// :KLUDGE: MATT You have a note that this is not fully implemented!
@@ -275,7 +288,7 @@
// Will change to just VecView() once I setup the vectors correctly
// (use VecSetOperation() to change the view).
PetscViewerVTKFieldType ft = field.vectorFieldType() != topology::FieldBase::VECTOR ? PETSC_VTK_CELL_FIELD : PETSC_VTK_CELL_VECTOR_FIELD;
- PetscErrorCode err = PetscViewerVTKAddField(_viewer, (PetscObject) dmMesh, DMPlexVTKWriteAll, ft, (PetscObject) v); PYLITH_CHECK_ERROR(err);
+ PetscErrorCode err = PetscViewerVTKAddField(_viewer, (PetscObject) _dm, DMPlexVTKWriteAll, ft, (PetscObject) v); PYLITH_CHECK_ERROR(err);
err = PetscObjectReference((PetscObject) v);PYLITH_CHECK_ERROR(err); /* Needed because viewer destroys the Vec */
_wroteCellHeader = true;
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterVTK.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterVTK.hh 2013-05-09 23:46:43 UTC (rev 22020)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterVTK.hh 2013-05-10 00:51:32 UTC (rev 22021)
@@ -173,6 +173,8 @@
int _precision; ///< Precision of floating point values in output.
+ bool _isOpen; ///< True if called open().
+ bool _isOpenTimeStep; ///< true if called openTimeStep().
bool _wroteVertexHeader; ///< True if wrote header for vertex data.
bool _wroteCellHeader; ///< True if wrote header for cell data
Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc 2013-05-09 23:46:43 UTC (rev 22020)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc 2013-05-10 00:51:32 UTC (rev 22021)
@@ -971,21 +971,20 @@
PYLITH_METHOD_END;
} // if
- PetscInt localSize, globalSize;
-
-
+ err = DMDestroy(&sinfo.dm);PYLITH_CHECK_ERROR(err);
+ sinfo.dm = _dm;
err = PetscObjectReference((PetscObject) _dm);PYLITH_CHECK_ERROR(err);
+
+ err = VecDestroy(&sinfo.vector);PYLITH_CHECK_ERROR(err);
+ sinfo.vector = _globalVec;
err = PetscObjectReference((PetscObject) _globalVec);PYLITH_CHECK_ERROR(err);
err = PetscObjectSetName((PetscObject) _globalVec, _metadata["default"].label.c_str());PYLITH_CHECK_ERROR(err);
- err = VecGetSize(_localVec, &localSize);PYLITH_CHECK_ERROR(err);
- err = VecGetSize(_globalVec, &globalSize);PYLITH_CHECK_ERROR(err);
+
+ //PetscInt localSize, globalSize;
+ //err = VecGetSize(_localVec, &localSize);PYLITH_CHECK_ERROR(err);
+ //err = VecGetSize(_globalVec, &globalSize);PYLITH_CHECK_ERROR(err);
//assert(order->getLocalSize() == localSize);
//assert(order->getGlobalSize() == globalSize);
-
- err = DMDestroy(&sinfo.dm);PYLITH_CHECK_ERROR(err);
- err = VecDestroy(&sinfo.vector);PYLITH_CHECK_ERROR(err);
- sinfo.vector = _globalVec;
- sinfo.dm = _dm;
PYLITH_METHOD_END;
} // createScatter
More information about the CIG-COMMITS
mailing list