Skip to content

Commit

Permalink
Create zero vector on the fly in Xdmf files instead of in HDF5 file.
Browse files Browse the repository at this point in the history
For 2-D vector fields, create the zero z-component on the fly in the Xdmf file rather than creating a zero vector in the HDF5 file.
  • Loading branch information
baagaard-usgs committed May 23, 2017
1 parent fee9ed1 commit 862d200
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 122 deletions.
37 changes: 0 additions & 37 deletions libsrc/pylith/meshio/DataWriterHDF5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,43 +239,6 @@ pylith::meshio::DataWriterHDF5::open(const topology::Mesh& mesh,
const int cellDim = mesh.dimension();
HDF5::writeAttribute(h5, "/topology/cells", "cell_dim", (void*)&cellDim, H5T_NATIVE_INT);

// If 2-D, write zero vector for z components
if (2 == cs->spaceDim()) {
err = PetscViewerHDF5PushGroup(_viewer, "/zero"); PYLITH_CHECK_ERROR(err);

const char* vlabel = "vertex_zero";
topology::Field vzeroField(mesh);
vzeroField.newSection(coordinatesField, 1);
vzeroField.allocate();
vzeroField.zeroAll();
vzeroField.label(vlabel);
vzeroField.vectorFieldType(topology::FieldBase::SCALAR);
vzeroField.createScatterWithBC(mesh, "", 0, vlabel);
vzeroField.scatterLocalToGlobal(vlabel);

PetscVec vzeroVector = vzeroField.vector(vlabel); assert(vzeroVector);
err = PetscObjectTypeCompare((PetscObject) vzeroVector, VECSEQ, &isseq); PYLITH_CHECK_ERROR(err);
if (isseq) {err = VecView_Seq(vzeroVector, _viewer); PYLITH_CHECK_ERROR(err); }
else {err = VecView_MPI(vzeroVector, _viewer); PYLITH_CHECK_ERROR(err); }

const char* clabel = "cell_zero";
topology::Field czeroField(mesh);
czeroField.newSection(cStart, cEnd, 1);
czeroField.allocate();
czeroField.zeroAll();
czeroField.label(clabel);
czeroField.vectorFieldType(topology::FieldBase::SCALAR);
czeroField.createScatterWithBC(mesh, "", 0, clabel);
czeroField.scatterLocalToGlobal(clabel);

PetscVec czeroVector = czeroField.vector(clabel); assert(czeroVector);
err = PetscObjectTypeCompare((PetscObject) czeroVector, VECSEQ, &isseq); PYLITH_CHECK_ERROR(err);
if (isseq) {err = VecView_Seq(czeroVector, _viewer); PYLITH_CHECK_ERROR(err); }
else {err = VecView_MPI(czeroVector, _viewer); PYLITH_CHECK_ERROR(err); }

err = PetscViewerHDF5PopGroup(_viewer); PYLITH_CHECK_ERROR(err);
} // if

} catch (const std::exception& err) {
std::ostringstream msg;
msg << "Error while opening HDF5 file " << _hdf5Filename() << ".\n" << err.what();
Expand Down
62 changes: 0 additions & 62 deletions libsrc/pylith/meshio/DataWriterHDF5Ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,68 +288,6 @@ pylith::meshio::DataWriterHDF5Ext::open(const topology::Mesh& mesh,
_h5->writeAttribute("/topology/cells", "cell_dim", (void*)&cellDim, H5T_NATIVE_INT);
} // if

// If 2-D, write zero vector for z coordinate and z component in vectors
if (2 == cs->spaceDim()) {
if (!commRank) _h5->createGroup("/zero");
const char* vlabel = "vertex_zero";
const std::string& vfilenameZero = _datasetFilename(vlabel);
err = PetscViewerBinaryOpen(comm, vfilenameZero.c_str(), FILE_MODE_WRITE, &binaryViewer); PYLITH_CHECK_ERROR(err);
err = PetscViewerBinarySetSkipHeader(binaryViewer, PETSC_TRUE); PYLITH_CHECK_ERROR(err);
topology::Field vzeroField(mesh);
vzeroField.newSection(coordinatesField, 1);
vzeroField.allocate();
vzeroField.zeroAll();
vzeroField.label(vlabel);
vzeroField.vectorFieldType(topology::FieldBase::SCALAR);
vzeroField.createScatterWithBC(mesh, "", 0, vlabel);
vzeroField.scatterLocalToGlobal(vlabel);

PetscVec vzeroVector = vzeroField.vector(vlabel); assert(vzeroVector);
err = PetscObjectTypeCompare((PetscObject) vzeroVector, VECSEQ, &isseq); PYLITH_CHECK_ERROR(err);
if (isseq) {err = VecView_Seq(vzeroVector, binaryViewer); PYLITH_CHECK_ERROR(err); }
else {err = VecView_MPI(vzeroVector, binaryViewer); PYLITH_CHECK_ERROR(err); }

err = PetscViewerDestroy(&binaryViewer); PYLITH_CHECK_ERROR(err);

// Create external dataset for vertex_zero field
if (!commRank) {
const hsize_t ndims = 2;
hsize_t dims[ndims];
dims[0] = numVertices;
dims[1] = 1;
_h5->createDatasetRawExternal("/zero", vlabel, vfilenameZero.c_str(), dims, ndims, scalartype);
} // if

const char* clabel = "cell_zero";
const std::string& cfilenameZero = _datasetFilename(clabel);
err = PetscViewerBinaryOpen(comm, cfilenameZero.c_str(), FILE_MODE_WRITE, &binaryViewer); PYLITH_CHECK_ERROR(err);
err = PetscViewerBinarySetSkipHeader(binaryViewer, PETSC_TRUE); PYLITH_CHECK_ERROR(err);
topology::Field czeroField(mesh);
czeroField.newSection(cStart, cEnd, 1);
czeroField.allocate();
czeroField.zeroAll();
czeroField.label(clabel);
czeroField.vectorFieldType(topology::FieldBase::SCALAR);
czeroField.createScatterWithBC(mesh, "", 0, clabel);
czeroField.scatterLocalToGlobal(clabel);

PetscVec czeroVector = czeroField.vector(clabel); assert(czeroVector);
err = PetscObjectTypeCompare((PetscObject) czeroVector, VECSEQ, &isseq); PYLITH_CHECK_ERROR(err);
if (isseq) {err = VecView_Seq(czeroVector, binaryViewer); PYLITH_CHECK_ERROR(err); }
else {err = VecView_MPI(czeroVector, binaryViewer); PYLITH_CHECK_ERROR(err); }

err = PetscViewerDestroy(&binaryViewer); PYLITH_CHECK_ERROR(err);

// Create external dataset for vertex_zero field
if (!commRank) {
const hsize_t ndims = 2;
hsize_t dims[ndims];
dims[0] = numCells;
dims[1] = 1;
_h5->createDatasetRawExternal("/zero", clabel, cfilenameZero.c_str(), dims, ndims, scalartype);
} // if
} // if

} catch (const std::exception& err) {
std::ostringstream msg;
msg << "Error while opening HDF5 file " << _filename << ".\n" << err.what();
Expand Down
13 changes: 9 additions & 4 deletions libsrc/pylith/meshio/Xdmf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,10 @@ pylith::meshio::Xdmf::_writeDomainVertices(const int numVertices,
<< " &HeavyData;:/geometry/vertices\n"
<< " </DataItem>\n"
<< " </DataItem>\n"
<< " <DataItem Name=\"verticesZ\" ItemType=\"Uniform\" Dimensions=\"" << numVertices << " 1\" Format=\"HDF\">\n"
<< " &HeavyData;:/zero/vertex_zero\n"
<< " <DataItem Name=\"verticesZ\" ItemType=\"Function\" Dimensions=\"" << numVertices << " 1\" Function=\"0*$0\">\n"
<< " <DataItem Reference=\"XML\">\n"
<< " /Xdmf/Domain/DataItem[@Name=\"vertices\"]/DataItem[@Name=\"verticesX\"]\n"
<< " </DataItem>\n"
<< " </DataItem>\n"
<< " </DataItem>\n";
} else {
Expand Down Expand Up @@ -563,9 +565,12 @@ pylith::meshio::Xdmf::_writeGridAttribute(const FieldMetadata& metadata,
<< " </DataItem>\n"
<< " </DataItem>\n"
// z component
<< " <DataItem ItemType=\"Uniform\" Dimensions=\"" << metadata.numPoints << " 1\" Format=\"HDF\">\n"
<< " &HeavyData;:" << h5ZeroName << "\n"
<< " <DataItem ItemType=\"Function\" Dimensions=\"" << metadata.numPoints << " 1\" Function=\"0*$0\">\n"
<< " <DataItem Reference=\"XML\">\n"
<< " /Xdmf/Domain/Grid/Attribute[@Name=\"" << metadata.name << "\"]/DataItem[1]/DataItem[1]\n"
<< " </DataItem>\n"
<< " </DataItem>\n"
// close
<< " </DataItem>\n"
<< " </Attribute>\n";
} else {
Expand Down
2 changes: 1 addition & 1 deletion m4
Submodule m4 updated 1 files
+0 −1 ax_lib_netcdf4.m4
2 changes: 1 addition & 1 deletion templates/friction/m4
2 changes: 1 addition & 1 deletion templates/materials/m4
12 changes: 8 additions & 4 deletions unittests/libtests/meshio/data/quad4_cell.xmf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
&HeavyData;:/geometry/vertices
</DataItem>
</DataItem>
<DataItem Name="verticesZ" ItemType="Uniform" Dimensions="6 1" Format="HDF">
&HeavyData;:/zero/vertex_zero
<DataItem Name="verticesZ" ItemType="Function" Dimensions="6 1" Function="0*$0">
<DataItem Reference="XML">
/Xdmf/Domain/DataItem[@Name="vertices"]/DataItem[@Name="verticesX"]
</DataItem>
</DataItem>
</DataItem>
<!-- ============================================================ -->
Expand Down Expand Up @@ -119,8 +121,10 @@
&HeavyData;:/cell_fields/traction
</DataItem>
</DataItem>
<DataItem ItemType="Uniform" Dimensions="2 1" Format="HDF">
&HeavyData;:/zero/cell_zero
<DataItem ItemType="Function" Dimensions="2 1" Function="0*$0">
<DataItem Reference="XML">
/Xdmf/Domain/Grid/Attribute[@Name="traction"]/DataItem[1]/DataItem[1]
</DataItem>
</DataItem>
</DataItem>
</Attribute>
Expand Down
Binary file modified unittests/libtests/meshio/data/quad4_points.h5
Binary file not shown.
Binary file modified unittests/libtests/meshio/data/quad4_points_vertex.h5
Binary file not shown.
12 changes: 8 additions & 4 deletions unittests/libtests/meshio/data/quad4_vertex.xmf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
&HeavyData;:/geometry/vertices
</DataItem>
</DataItem>
<DataItem Name="verticesZ" ItemType="Uniform" Dimensions="6 1" Format="HDF">
&HeavyData;:/zero/vertex_zero
<DataItem Name="verticesZ" ItemType="Function" Dimensions="6 1" Function="0*$0">
<DataItem Reference="XML">
/Xdmf/Domain/DataItem[@Name="vertices"]/DataItem[@Name="verticesX"]
</DataItem>
</DataItem>
</DataItem>
<!-- ============================================================ -->
Expand Down Expand Up @@ -59,8 +61,10 @@
&HeavyData;:/vertex_fields/displacement
</DataItem>
</DataItem>
<DataItem ItemType="Uniform" Dimensions="6 1" Format="HDF">
&HeavyData;:/zero/vertex_zero
<DataItem ItemType="Function" Dimensions="6 1" Function="0*$0">
<DataItem Reference="XML">
/Xdmf/Domain/Grid/Attribute[@Name="displacement"]/DataItem[1]/DataItem[1]
</DataItem>
</DataItem>
</DataItem>
</Attribute>
Expand Down
12 changes: 8 additions & 4 deletions unittests/libtests/meshio/data/tri3_cell.xmf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
&HeavyData;:/geometry/vertices
</DataItem>
</DataItem>
<DataItem Name="verticesZ" ItemType="Uniform" Dimensions="6 1" Format="HDF">
&HeavyData;:/zero/vertex_zero
<DataItem Name="verticesZ" ItemType="Function" Dimensions="6 1" Function="0*$0">
<DataItem Reference="XML">
/Xdmf/Domain/DataItem[@Name="vertices"]/DataItem[@Name="verticesX"]
</DataItem>
</DataItem>
</DataItem>
<!-- ============================================================ -->
Expand Down Expand Up @@ -119,8 +121,10 @@
&HeavyData;:/cell_fields/traction
</DataItem>
</DataItem>
<DataItem ItemType="Uniform" Dimensions="2 1" Format="HDF">
&HeavyData;:/zero/cell_zero
<DataItem ItemType="Function" Dimensions="2 1" Function="0*$0">
<DataItem Reference="XML">
/Xdmf/Domain/Grid/Attribute[@Name="traction"]/DataItem[1]/DataItem[1]
</DataItem>
</DataItem>
</DataItem>
</Attribute>
Expand Down
Binary file modified unittests/libtests/meshio/data/tri3_points.h5
Binary file not shown.
Binary file modified unittests/libtests/meshio/data/tri3_points_vertex.h5
Binary file not shown.
12 changes: 8 additions & 4 deletions unittests/libtests/meshio/data/tri3_vertex.xmf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
&HeavyData;:/geometry/vertices
</DataItem>
</DataItem>
<DataItem Name="verticesZ" ItemType="Uniform" Dimensions="6 1" Format="HDF">
&HeavyData;:/zero/vertex_zero
<DataItem Name="verticesZ" ItemType="Function" Dimensions="6 1" Function="0*$0">
<DataItem Reference="XML">
/Xdmf/Domain/DataItem[@Name="vertices"]/DataItem[@Name="verticesX"]
</DataItem>
</DataItem>
</DataItem>
<!-- ============================================================ -->
Expand Down Expand Up @@ -59,8 +61,10 @@
&HeavyData;:/vertex_fields/displacement
</DataItem>
</DataItem>
<DataItem ItemType="Uniform" Dimensions="6 1" Format="HDF">
&HeavyData;:/zero/vertex_zero
<DataItem ItemType="Function" Dimensions="6 1" Function="0*$0">
<DataItem Reference="XML">
/Xdmf/Domain/Grid/Attribute[@Name="displacement"]/DataItem[1]/DataItem[1]
</DataItem>
</DataItem>
</DataItem>
</Attribute>
Expand Down

0 comments on commit 862d200

Please sign in to comment.