16#ifndef TPFA_LINEARIZER_STRUCTS_HH
17#define TPFA_LINEARIZER_STRUCTS_HH
27#include <opm/common/Exceptions.hpp>
28#include <opm/grid/utility/SparseTable.hpp>
29#include <opm/input/eclipse/Schedule/BCProp.hpp>
31#include <opm/common/utility/gpuistl_if_available.hpp>
32#include <opm/common/utility/pointerArithmetic.hpp>
36template <
class Storage = std::vector<
int>>
42#if HAVE_CUDA && OPM_IS_COMPILING_WITH_GPU_COMPILER
45 if (CPUDomain.
cells.size() == 0) {
46 OPM_THROW(std::runtime_error,
"Cannot copy empty full domain to GPU.");
48 return FullDomain<gpuistl::GpuBuffer<int>>{
49 gpuistl::GpuBuffer<int>(CPUDomain.
cells)
53inline FullDomain<gpuistl::GpuView<int>>
make_view(FullDomain<gpuistl::GpuBuffer<int>>& buffer)
55 if (buffer.cells.size() == 0) {
56 OPM_THROW(std::runtime_error,
"Cannot make view of empty full domain buffer.");
58 return FullDomain<gpuistl::GpuView<int>>{
64template <
class Res
idualNBInfoType,
class BlockType>
71 template <
class PtrType>
88template <
class VectorBlock,
class ScalarFlu
idState>
99template <
class BoundaryConditionData>
107#if HAVE_CUDA && OPM_IS_COMPILING_WITH_GPU_COMPILER
110 template <
class MiniMatrixType,
113 class MatrixBlockType,
114 class ResidualNBInfoType>
116 cpuNeighborInfoTable,
117 GpuMatrixType& gpuJacobian,
118 CpuMatrixType& cpuJacobian)
122 using Scalar =
typename GpuMatrixType::field_type;
123 std::vector<StructWithMinimatrix> minimatrices(cpuNeighborInfoTable.dataSize());
124 Scalar* gpuBufStart = gpuJacobian.getNonZeroValues().data();
125 Scalar* cpuBufStart = &(cpuJacobian[0][0][0][0]);
129 using CpuBlockType =
typename CpuMatrixType::block_type::BaseType;
131 const size_t gpuBufferSize
132 = gpuJacobian.nonzeroes() * gpuJacobian.blockSize() * gpuJacobian.blockSize();
133 const size_t cpuBufferSize
134 = cpuJacobian.nonzeroes() * CpuBlockType::rows * CpuBlockType::cols;
135 assert(gpuBufferSize == cpuBufferSize);
137 const auto& dataStorage = cpuNeighborInfoTable.dataStorage();
138 const size_t dataSize = cpuNeighborInfoTable.dataSize();
140#pragma omp parallel for
142 for (
size_t idx = 0; idx < dataSize; ++idx) {
143 const auto& e = dataStorage[idx];
144 Scalar* cpuPtr = &((*e.matBlockAddress)[0][0]);
147 Scalar* gpuPtr = ComputePtrBasedOnOffsetInOtherBuffer(
148 gpuBufStart, gpuBufferSize, cpuBufStart, cpuBufferSize, cpuPtr);
150 minimatrices[idx] = StructWithMinimatrix(
151 e.neighbor, e.res_nbinfo,
reinterpret_cast<MiniMatrixType*
>(gpuPtr));
155 gpuistl::GpuBuffer<StructWithMinimatrix>(minimatrices),
156 gpuistl::GpuBuffer<int>(cpuNeighborInfoTable.rowStarts())
161 template <
class GpuVecBlock,
163 class BoundaryInfoTypeGPU,
164 class BoundaryInfoTypeCPU,
165 typename GpuFluidSystemPtr>
166 auto copy_to_gpu(
const std::vector<BoundaryInfoTypeCPU>& cpu_boundary_info,
167 const GpuFluidSystemPtr& dynamicGpuFluidSystemPtr)
169 std::vector<BoundaryInfoTypeGPU> gpu_boundary_info;
170 for (
const auto& info : cpu_boundary_info) {
171 gpu_boundary_info.push_back(BoundaryInfoTypeGPU {
175 BoundaryConditionData<GpuVecBlock, GpuFluidState> {
177 GpuVecBlock(info.bcdata.massRate),
178 info.bcdata.pvtRegionIdx,
179 info.bcdata.boundaryFaceIndex,
180 info.bcdata.faceArea,
181 info.bcdata.faceZCoord,
182 info.bcdata.exFluidState.withOtherFluidSystem(dynamicGpuFluidSystemPtr)}});
185 return gpuistl::GpuBuffer<BoundaryInfoTypeGPU>(gpu_boundary_info);
190 template <
class CPURes
idualType,
class GpuMiniVector>
191 auto copy_to_gpu_residual(CPUResidualType& residual)
193 std::vector<GpuMiniVector> vectorOfMiniVectors;
194 for (
const auto& minivec : residual) {
195 vectorOfMiniVectors.emplace_back(minivec);
198 return gpuistl::GpuBuffer<GpuMiniVector>(vectorOfMiniVectors);
Definition: BlackoilWellModel.hpp:88
ThermalGasWaterFlowProblem< Scalar, GpuView > make_view(ThermalGasWaterFlowProblem< Scalar, GpuBuffer > &buffer)
Definition: ThermalGasWaterFlowProblem.hpp:111
ThermalGasWaterFlowProblem< Scalar, GpuBuffer > copy_to_gpu(ThermalGasWaterFlowProblem< Scalar, Opm::VectorWithDefaultAllocator > &cpuProblem)
Definition: ThermalGasWaterFlowProblem.hpp:99
Definition: blackoilbioeffectsmodules.hh:45
Definition: tpfalinearizerstructs.hh:89
double faceArea
Definition: tpfalinearizerstructs.hh:94
VectorBlock massRate
Definition: tpfalinearizerstructs.hh:91
BCType type
Definition: tpfalinearizerstructs.hh:90
unsigned boundaryFaceIndex
Definition: tpfalinearizerstructs.hh:93
double faceZCoord
Definition: tpfalinearizerstructs.hh:95
ScalarFluidState exFluidState
Definition: tpfalinearizerstructs.hh:96
unsigned pvtRegionIdx
Definition: tpfalinearizerstructs.hh:92
Definition: tpfalinearizerstructs.hh:100
unsigned int cell
Definition: tpfalinearizerstructs.hh:101
unsigned int bfIndex
Definition: tpfalinearizerstructs.hh:103
BoundaryConditionData bcdata
Definition: tpfalinearizerstructs.hh:104
int dir
Definition: tpfalinearizerstructs.hh:102
Definition: tpfalinearizerstructs.hh:38
Storage cells
Definition: tpfalinearizerstructs.hh:39
Definition: tpfalinearizerstructs.hh:66
NeighborInfoStruct(unsigned int n, const ResidualNBInfoType &r, PtrType ptr)
Definition: tpfalinearizerstructs.hh:72
NeighborInfoStruct()
Definition: tpfalinearizerstructs.hh:80
BlockType * matBlockAddress
Definition: tpfalinearizerstructs.hh:69
ResidualNBInfoType res_nbinfo
Definition: tpfalinearizerstructs.hh:68
unsigned int neighbor
Definition: tpfalinearizerstructs.hh:67