36 #ifndef OPM_IMPLICITASSEMBLY_HPP_HEADER
37 #define OPM_IMPLICITASSEMBLY_HPP_HEADER
44 template <
class Model>
46 enum { DofPerCell = Model::DofPerCell };
55 template <
class Grid ,
59 JacobianSystem& sys)
const {
61 ::std::size_t m = g.number_of_cells;
62 ::std::size_t nnz = g.number_of_cells
63 + countConnections(g);
66 sys.setSize(DofPerCell, m, nnz);
68 for (
int c = 0; c < g.number_of_cells; ++c) {
69 this->createRowStructure(g, c, sys);
82 sys.matasm().finalizeStructure();
85 template <
class ReservoirState,
92 const SourceTerms* src ,
94 JacobianSystem& sys ) {
96 for (
int c = 0; c < g.number_of_cells; ++c) {
97 this->computeCellContrib(state, g, dt, c);
98 this->assembleCellContrib(g, c, sys);
102 this->assembleSourceContrib(g, src, dt, sys);
107 template <
class Gr
id>
109 countConnections(
const Grid& g,
int c)
const {
112 for (i = g.cell_facepos[c + 0], n = 0;
113 i < g.cell_facepos[c + 1]; ++i) {
115 c1 = g.face_cells[2*f + 0];
116 c2 = g.face_cells[2*f + 1];
118 n += (c1 >= 0) && (c2 >= 0);
124 template <
class Gr
id>
126 countConnections(
const Grid& g)
const {
129 for (
int c = 0; c < g.number_of_cells; ++c) {
130 n += countConnections(g, c);
136 template <
class Gr
id,
class System>
138 createRowStructure(
const Grid& g ,
142 int nconn = countConnections(g, c);
144 ::std::vector<int> connections;
145 connections.reserve (nconn + 1);
146 connections.push_back(c);
148 for (
int i = g.cell_facepos[c + 0];
149 i < g.cell_facepos[c + 1]; ++i) {
150 int f = g.cell_faces[i];
151 int c1 = g.face_cells[2*f + 0];
152 int c2 = g.face_cells[2*f + 1];
154 if ((c1 >= 0) && (c2 >= 0)) {
155 connections.push_back((c1 == c) ? c2 : c1);
158 sys.matasm().createBlockRow(c, connections, DofPerCell);
162 template <
class ReservoirState,
class Gr
id>
164 computeCellContrib(
const ReservoirState& state,
168 const int ndof = DofPerCell;
169 const int ndof2 = ndof * ndof;
171 nconn_ = countConnections(g, c);
173 asm_buffer_.resize((2*nconn_ + 1)*ndof2 + (nconn_ + 2)*ndof);
174 std::fill(asm_buffer_.begin(), asm_buffer_.end(), 0.0);
176 double* F = &asm_buffer_[(2*nconn_ + 1) * ndof2];
177 double* J1 = &asm_buffer_[(0*nconn_ + 1) * ndof2];
178 double* J2 = J1 + (1*nconn_ + 0) * ndof2 ;
180 model_.initResidual(c, F);
183 for (
int i = g.cell_facepos[c + 0];
184 i < g.cell_facepos[c + 1]; ++i) {
185 int f = g.cell_faces[i];
186 int c1 = g.face_cells[2*f + 0];
187 int c2 = g.face_cells[2*f + 1];
189 if ((c1 >= 0) && (c2 >= 0)) {
190 model_.fluxConnection(state, g, dt, c, f, J1, J2, F);
191 J1 += ndof2; J2 += ndof2; F += ndof;
195 model_.accumulation(g, c, &asm_buffer_[0], F);
200 template <
class Gr
id,
class System>
202 assembleCellContrib(
const Grid& g ,
205 const int ndof = DofPerCell;
206 const int ndof2 = ndof * ndof;
208 const double* J1 = &asm_buffer_[0];
209 const double* J2 = J1 + ((1*nconn_ + 1) * ndof2);
212 sys.matasm().assembleBlock(ndof, c, c, J1); J1 += ndof2;
215 for (
int i = g.cell_facepos[c + 0];
216 i < g.cell_facepos[c + 1]; ++i) {
217 int f = g.cell_faces[i];
218 int c1 = g.face_cells[2*f + 0];
219 int c2 = g.face_cells[2*f + 1];
221 c2 = (c1 == c) ? c2 : c1;
224 sys.matasm().assembleBlock(ndof, c, c , J1);
225 sys.matasm().assembleBlock(ndof, c, c2, J2);
232 const double* F = &asm_buffer_[(2*nconn_ + 1) * ndof2];
233 for (
int conn = 0; conn < nconn_ + 2; ++conn, F += ndof) {
234 sys.vector().assembleBlock(ndof, c, F);
238 template <
class Gr
id,
class SourceTerms,
class System>
240 assembleSourceContrib(
const Grid& g,
241 const SourceTerms* src,
244 const int ndof = DofPerCell;
245 const int ndof2 = ndof * ndof;
247 for (
int i = 0; i < src->nsrc; ++i) {
248 std::fill_n(asm_buffer_.begin(), ndof2 + ndof, 0.0);
250 double *J = &asm_buffer_[0];
251 double *F = J + ndof2;
253 model_.sourceTerms(g, src, i, dt, J, F);
255 const int c = src->cell[i];
257 sys.matasm().assembleBlock(ndof, c, c, J);
258 sys.vector().assembleBlock(ndof, c, F);
264 std::vector<double> asm_buffer_;
Definition: AnisotropicEikonal.hpp:43
ImplicitAssembly(Model &model)
Definition: ImplicitAssembly.hpp:49
void assemble(const ReservoirState &state, const Grid &g, const SourceTerms *src, const double dt, JacobianSystem &sys)
Definition: ImplicitAssembly.hpp:90
void createSystem(const Grid &g, JacobianSystem &sys) const
Definition: ImplicitAssembly.hpp:58
Definition: ImplicitAssembly.hpp:45