# Volume for QuadHexahedrons incorrect

**URL:** https://discourse.vtk.org/t/volume-for-quadhexahedrons-incorrect/16358
**Category:** Development
**Tags:** bug, c, code
**Created:** [March 25, 2026, 2:42pm UTC](https://discourse.vtk.org/t/volume-for-quadhexahedrons-incorrect/16358 "2026-03-25T14:42:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![magicmangoman](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@magicmangoman](https://discourse.vtk.org/u/magicmangoman)
#### Post date: [March 25, 2026, 2:42pm UTC](https://discourse.vtk.org/t/volume-for-quadhexahedrons-incorrect/16358/1 "2026-03-25T14:42:12Z")

</div>

# Incorrect Volume for QuadraticHexahedron ?!

Hi, it appears that vtk gives out an incorrect volume for QuadraticHexahedrons, i.e. for the Cell defined in vtkQuadraticHexahedron.h.

This is verified by the failure of the following test ‘test\_volume.cpp’

```
	#define BOOST_TEST_MODULE test_volume
	#include <boost/test/unit_test.hpp>
	#include <vtkCellData.h>
	#include <vtkIntegrateAttributes.h>
	#include <vtkQuadraticHexahedron.h>
	#include <vtkQuadraticTetra.h>
	#include <vtkUnstructuredGrid.h>
	#include <vtkXMLUnstructuredGridWriter.h>
	#include <iostream>

	const std::string root = PROJECT_ROOT;

	double vtk_volume(vtkSmartPointer<vtkUnstructuredGrid> grid)
	{
	  vtkNew<vtkIntegrateAttributes> integrator;
	  integrator->SetInputData(grid);
	  integrator->Update();

	  vtkUnstructuredGrid* output = integrator->GetOutput();

	  double volume = output->GetCellData()->GetArray("Volume")->GetComponent(0, 0);
	  return volume;
	}

	BOOST_AUTO_TEST_CASE(test_quadratic_hex)
	{
	  std::map<int, std::array<double, 3>> nodes = {{486, {80.0, 80.0, 80.0}},
		{491, {80.0, 100.0, 80.0}}, {492, {80.0, 90.0, 80.0}},
		{508, {100.0, 80.0, 80.0}}, {511, {90.0, 80.0, 80.0}},
		{512, {110.0, 100.0, 80.0}}, {513, {100.0, 90.0, 80.0}},
		{515, {90.0, 100.0, 80.0}}, {592, {80.0, 80.0, 100.0}},
		{596, {80.0, 80.0, 90.0}}, {599, {80.0, 100.0, 100.0}},
		{601, {80.0, 90.0, 100.0}}, {603, {80.0, 100.0, 90.0}},
		{713, {100.0, 80.0, 100.0}}, {715, {100.0, 80.0, 90.0}},
		{716, {90.0, 80.0, 100.0}}, {717, {110.0, 100.0, 100.0}},
		{718, {100.0, 90.0, 100.0}}, {719, {110.0, 100.0, 90.0}},
		{720, {90.0, 100.0, 100.0}}};

	  std::vector<int> elem = {
		486, 592, 713, 508, 491, 599, 717, 512, // 8 corners
		596, 716, 715, 511, 603, 720, 719, // mids
		515, 492, 601, 718, 513 // mids
	  };

	  auto points = vtkSmartPointer<vtkPoints>::New();
	  std::map<int, vtkIdType> idMap;

	  vtkIdType vtkId = 0;
	  for (auto& p : nodes) {
		points->InsertNextPoint(p.second[0], p.second[1], p.second[2]);
		idMap[p.first] = vtkId++;
	  }

	  auto hex = vtkSmartPointer<vtkQuadraticHexahedron>::New();

	  for (unsigned int i = 0; i < elem.size(); ++i) {
		hex->GetPointIds()->SetId(i, idMap[elem[i]]);
	  }

	  auto ug = vtkSmartPointer<vtkUnstructuredGrid>::New();
	  ug->SetPoints(points);
	  ug->InsertNextCell(hex->GetCellType(), hex->GetPointIds());

	  // One calculates by hand that the correct volume is 8666.666
	  // The method vtk_volume gives out 9333.333
	  BOOST_CHECK_CLOSE(vtk_volume(ug), 8666.666, 1e-4);
	}

```

By integrating over the quadratic function for the ‘pulled out’ node, one easily verifies that the correct volume is 8666.666!  
The same result is obtained by passing this Hexahedron to [**Calculix (cgx)**](https://www.calculix.de/) or [**Paraview**](https://www.paraview.org/) and using their volume functions. Both cgx and paraview give out **8666.666**.

Follow this procedure to verify the volume with [**Calculix (cgx)**](https://www.calculix.de/):

1. Consider the following .inp file:

2. You may save this .inp file as ‘hex.inp’.

3. Open the file in cgx:  
cgx -c ‘hex.inp’

4. In the cgx-Viewer left-click and hold to select `Toggle-Commandline`. You should see `:` at the bottom of the window now. This is the cgx-commandline

5. At the cgx-commandline type `volu cube` and hit enter

6. At the window you launched cgx from you should now see the output

The last line indicates that the volume is **8666.666…**
