mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
BaseOutputModule: replace copy-pasted code with helper
This commit is contained in:
parent
a28f76c83e
commit
63d707a67f
@ -162,17 +162,7 @@ protected:
|
|||||||
void resizeScalarBuffer_(ScalarBuffer& buffer,
|
void resizeScalarBuffer_(ScalarBuffer& buffer,
|
||||||
BufferType bufferType = DofBuffer)
|
BufferType bufferType = DofBuffer)
|
||||||
{
|
{
|
||||||
size_t n;
|
buffer.resize(this->getBufferSize(bufferType));
|
||||||
if (bufferType == VertexBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(dim));
|
|
||||||
else if (bufferType == ElementBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(0));
|
|
||||||
else if (bufferType == DofBuffer)
|
|
||||||
n = simulator_.model().numGridDof();
|
|
||||||
else
|
|
||||||
throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
|
|
||||||
|
|
||||||
buffer.resize(n);
|
|
||||||
std::fill(buffer.begin(), buffer.end(), 0.0);
|
std::fill(buffer.begin(), buffer.end(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,17 +172,7 @@ protected:
|
|||||||
void resizeTensorBuffer_(TensorBuffer& buffer,
|
void resizeTensorBuffer_(TensorBuffer& buffer,
|
||||||
BufferType bufferType = DofBuffer)
|
BufferType bufferType = DofBuffer)
|
||||||
{
|
{
|
||||||
size_t n;
|
buffer.resize(this->getBufferSize(bufferType));
|
||||||
if (bufferType == VertexBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(dim));
|
|
||||||
else if (bufferType == ElementBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(0));
|
|
||||||
else if (bufferType == DofBuffer)
|
|
||||||
n = simulator_.model().numGridDof();
|
|
||||||
else
|
|
||||||
throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
|
|
||||||
|
|
||||||
buffer.resize(n);
|
|
||||||
Tensor nullMatrix(dimWorld, dimWorld, 0.0);
|
Tensor nullMatrix(dimWorld, dimWorld, 0.0);
|
||||||
std::fill(buffer.begin(), buffer.end(), nullMatrix);
|
std::fill(buffer.begin(), buffer.end(), nullMatrix);
|
||||||
}
|
}
|
||||||
@ -200,17 +180,7 @@ protected:
|
|||||||
void resizeVectorBuffer_(VectorBuffer& buffer,
|
void resizeVectorBuffer_(VectorBuffer& buffer,
|
||||||
BufferType bufferType = DofBuffer)
|
BufferType bufferType = DofBuffer)
|
||||||
{
|
{
|
||||||
size_t n;
|
buffer.resize(this->getBufferSize(bufferType));
|
||||||
if (bufferType == VertexBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(dim));
|
|
||||||
else if (bufferType == ElementBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(0));
|
|
||||||
else if (bufferType == DofBuffer)
|
|
||||||
n = simulator_.model().numGridDof();
|
|
||||||
else
|
|
||||||
throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
|
|
||||||
|
|
||||||
buffer.resize(n);
|
|
||||||
Vector zerovector(dimWorld,0.0);
|
Vector zerovector(dimWorld,0.0);
|
||||||
zerovector = 0.0;
|
zerovector = 0.0;
|
||||||
std::fill(buffer.begin(), buffer.end(), zerovector);
|
std::fill(buffer.begin(), buffer.end(), zerovector);
|
||||||
@ -223,16 +193,7 @@ protected:
|
|||||||
void resizeEqBuffer_(EqBuffer& buffer,
|
void resizeEqBuffer_(EqBuffer& buffer,
|
||||||
BufferType bufferType = DofBuffer)
|
BufferType bufferType = DofBuffer)
|
||||||
{
|
{
|
||||||
size_t n;
|
const std::size_t n = this->getBufferSize(bufferType);
|
||||||
if (bufferType == VertexBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(dim));
|
|
||||||
else if (bufferType == ElementBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(0));
|
|
||||||
else if (bufferType == DofBuffer)
|
|
||||||
n = simulator_.model().numGridDof();
|
|
||||||
else
|
|
||||||
throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < numEq; ++i) {
|
for (unsigned i = 0; i < numEq; ++i) {
|
||||||
buffer[i].resize(n);
|
buffer[i].resize(n);
|
||||||
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
|
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
|
||||||
@ -246,16 +207,7 @@ protected:
|
|||||||
void resizePhaseBuffer_(PhaseBuffer& buffer,
|
void resizePhaseBuffer_(PhaseBuffer& buffer,
|
||||||
BufferType bufferType = DofBuffer)
|
BufferType bufferType = DofBuffer)
|
||||||
{
|
{
|
||||||
size_t n;
|
const std::size_t n = this->getBufferSize(bufferType);
|
||||||
if (bufferType == VertexBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(dim));
|
|
||||||
else if (bufferType == ElementBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(0));
|
|
||||||
else if (bufferType == DofBuffer)
|
|
||||||
n = simulator_.model().numGridDof();
|
|
||||||
else
|
|
||||||
throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < numPhases; ++i) {
|
for (unsigned i = 0; i < numPhases; ++i) {
|
||||||
buffer[i].resize(n);
|
buffer[i].resize(n);
|
||||||
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
|
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
|
||||||
@ -269,16 +221,7 @@ protected:
|
|||||||
void resizeComponentBuffer_(ComponentBuffer& buffer,
|
void resizeComponentBuffer_(ComponentBuffer& buffer,
|
||||||
BufferType bufferType = DofBuffer)
|
BufferType bufferType = DofBuffer)
|
||||||
{
|
{
|
||||||
size_t n;
|
const std::size_t n = this->getBufferSize(bufferType);
|
||||||
if (bufferType == VertexBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(dim));
|
|
||||||
else if (bufferType == ElementBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(0));
|
|
||||||
else if (bufferType == DofBuffer)
|
|
||||||
n = simulator_.model().numGridDof();
|
|
||||||
else
|
|
||||||
throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < numComponents; ++i) {
|
for (unsigned i = 0; i < numComponents; ++i) {
|
||||||
buffer[i].resize(n);
|
buffer[i].resize(n);
|
||||||
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
|
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
|
||||||
@ -292,16 +235,7 @@ protected:
|
|||||||
void resizePhaseComponentBuffer_(PhaseComponentBuffer& buffer,
|
void resizePhaseComponentBuffer_(PhaseComponentBuffer& buffer,
|
||||||
BufferType bufferType = DofBuffer)
|
BufferType bufferType = DofBuffer)
|
||||||
{
|
{
|
||||||
size_t n;
|
const std::size_t n = this->getBufferSize(bufferType);
|
||||||
if (bufferType == VertexBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(dim));
|
|
||||||
else if (bufferType == ElementBuffer)
|
|
||||||
n = static_cast<size_t>(simulator_.gridView().size(0));
|
|
||||||
else if (bufferType == DofBuffer)
|
|
||||||
n = simulator_.model().numGridDof();
|
|
||||||
else
|
|
||||||
throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < numPhases; ++i) {
|
for (unsigned i = 0; i < numPhases; ++i) {
|
||||||
for (unsigned j = 0; j < numComponents; ++j) {
|
for (unsigned j = 0; j < numComponents; ++j) {
|
||||||
buffer[i][j].resize(n);
|
buffer[i][j].resize(n);
|
||||||
@ -516,6 +450,16 @@ protected:
|
|||||||
const char *name)
|
const char *name)
|
||||||
{ baseWriter.attachTensorVertexData(buffer, name); }
|
{ baseWriter.attachTensorVertexData(buffer, name); }
|
||||||
|
|
||||||
|
std::size_t getBufferSize(BufferType bufferType) const
|
||||||
|
{
|
||||||
|
switch (bufferType) {
|
||||||
|
case VertexBuffer: return simulator_.gridView().size(dim);
|
||||||
|
case ElementBuffer: return simulator_.gridView().size(0);
|
||||||
|
case DofBuffer: return simulator_.model().numGridDof();
|
||||||
|
default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Simulator& simulator_;
|
const Simulator& simulator_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user