My Project
MultisegmentWellContribution.hpp
1 /*
2  Copyright 2020 Equinor ASA
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef MULTISEGMENTWELLCONTRIBUTION_HEADER_INCLUDED
21 #define MULTISEGMENTWELLCONTRIBUTION_HEADER_INCLUDED
22 
23 #include <vector>
24 
25 #if HAVE_CUDA
26 #include <cuda_runtime.h>
27 #endif
28 
29 #if HAVE_SUITESPARSE_UMFPACK
30 #include<umfpack.h>
31 #endif
32 #include <dune/common/version.hh>
33 
34 namespace Opm
35 {
36 
43 
45 {
46 
47 private:
48  unsigned int dim; // size of blockvectors in vectors x and y, equal to MultisegmentWell::numEq
49  unsigned int dim_wells; // size of blocks in C, B and D, equal to MultisegmentWell::numWellEq
50  unsigned int M; // number of rows, M == dim_wells*Mb
51  unsigned int Mb; // number of blockrows in C, D and B
52 
53 #if HAVE_CUDA
54  cudaStream_t stream; // not actually used yet, will be when MultisegmentWellContribution are applied on GPU
55 #endif
56 
57  // C and B are stored in BCRS format, D is stored in CSC format (Dune::UMFPack)
58  // Sparsity pattern for C is not stored, since it is the same as B
59  unsigned int DnumBlocks; // number of blocks in D
60  std::vector<double> Cvals;
61  std::vector<double> Dvals;
62  std::vector<double> Bvals;
63  std::vector<int> Dcols; // Columnpointers, contains M+1 entries
64  std::vector<unsigned int> Bcols;
65  std::vector<int> Drows; // Rowindicies, contains DnumBlocks*dim*dim_wells entries
66  std::vector<unsigned int> Brows;
67  std::vector<double> z1; // z1 = B * x
68  std::vector<double> z2; // z2 = D^-1 * B * x
69  void *UMFPACK_Symbolic, *UMFPACK_Numeric;
70 
71  int *toOrder = nullptr;
72  bool reorder = false;
73 
76  unsigned int getColIdx(unsigned int idx);
77 
78 public:
79 
80 #if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 7)
81  using UMFPackIndex = SuiteSparse_long;
82 #else
83  using UMFPackIndex = int;
84 #endif
85 
86 #if HAVE_CUDA
89  void setCudaStream(cudaStream_t stream);
90 #endif
91 
106  MultisegmentWellContribution(unsigned int dim, unsigned int dim_wells,
107  unsigned int Mb,
108  std::vector<double> &Bvalues, std::vector<unsigned int> &BcolIndices, std::vector<unsigned int> &BrowPointers,
109  unsigned int DnumBlocks, double *Dvalues, UMFPackIndex *DcolPointers,
110  UMFPackIndex *DrowIndices, std::vector<double> &Cvalues);
111 
114 
119  void apply(double *h_x, double *h_y);
120 
125  void setReordering(int *toOrder, bool reorder);
126 };
127 
128 } //namespace Opm
129 
130 #endif
This class serves to duplicate the functionality of the MultisegmentWell A MultisegmentWell uses C,...
Definition: MultisegmentWellContribution.hpp:45
~MultisegmentWellContribution()
Destroy a MultisegmentWellContribution, and free memory.
Definition: MultisegmentWellContribution.cpp:60
void apply(double *h_x, double *h_y)
Apply the MultisegmentWellContribution on CPU performs y -= (C^T * (D^-1 * (B*x))) for MultisegmentWe...
Definition: MultisegmentWellContribution.cpp:70
MultisegmentWellContribution(unsigned int dim, unsigned int dim_wells, unsigned int Mb, std::vector< double > &Bvalues, std::vector< unsigned int > &BcolIndices, std::vector< unsigned int > &BrowPointers, unsigned int DnumBlocks, double *Dvalues, UMFPackIndex *DcolPointers, UMFPackIndex *DrowIndices, std::vector< double > &Cvalues)
Create a new MultisegmentWellContribution Matrices C and B are passed in Blocked CSR,...
Definition: MultisegmentWellContribution.cpp:32
void setReordering(int *toOrder, bool reorder)
Since the rows of the matrix are reordered, the columnindices of the matrixdata is incorrect Those in...
Definition: MultisegmentWellContribution.cpp:128
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27