Flow123d  jenkins-Flow123d-linux-release-multijob-282
transport.h
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file
26  * @brief ???
27  *
28  *
29  * TODO:
30  * - remove transport_sources
31  * - in create_transport_matric_mpi, there there is condition edge_flow > ZERO
32  * this makes matrix sparser, but can lead to elements without outflow and other problems
33  * when there are big differences in fluxes, more over it doesn't work if overall flow is very small
34  *
35  */
36 
37 #ifndef TRANSPORT_H_
38 #define TRANSPORT_H_
39 
40 #include <petscmat.h>
41 #include "coupling/equation.hh"
42 #include "input/accessors.hh"
43 #include "flow/mh_dofhandler.hh"
45 
47 #include "fields/field_values.hh"
48 #include "fields/multi_field.hh"
49 #include "fields/vec_seq_double.hh"
50 
51 
52 class SorptionImmob;
53 class OutputTime;
54 class Mesh;
55 class Distribution;
57 
58 //=============================================================================
59 // TRANSPORT
60 //=============================================================================
61 
62 /**
63  * TODO:
64  * - doxy documentation
65  * - make separate method for changing time step (rescaling only), reassembly matrix only when data are changed
66  *
67  * - needs support from EqData to determine next change of the data for 1) transport matrix 2) source vector
68  * this allows us precisely choose interval where to fix timestep
69  * : field->next_change_time() - returns time jump or actual time in case of time dep. field
70  */
71 
72 
73 
74 /**
75  * Class that implements explicit finite volumes scheme with upwind. The timestep is given by CFL condition.
76  *
77  */
79 public:
80 
82  public:
84 
86 
87  EqData();
88  virtual ~EqData() {};
89 
90  /// Override generic method in order to allow specification of the boundary conditions through the old bcd files.
92 
93  /**
94  * Boundary conditions (Dirichlet) for concentrations.
95  * They are applied only on water inflow part of the boundary.
96  */
98 
99  /// Initial concentrations.
101 
103  MultiField<3, FieldValue<3>::Scalar> conc_mobile; ///< Calculated concentrations in the mobile zone.
104 
105 
106  /// Fields indended for output, i.e. all input fields plus those representing solution.
108  };
109 
110  /**
111  * Constructor.
112  */
113  ConvectionTransport(Mesh &init_mesh, const Input::Record &in_rec);
114  /**
115  * TODO: destructor
116  */
117  virtual ~ConvectionTransport();
118 
119  /**
120  * Initialize solution at zero time.
121  */
122  void zero_time_step() override;
123  /**
124  * Calculates one time step of explicit transport.
125  */
126  void update_solution() override;
127 
128  /**
129  * Set time interval which is considered as one time step by TransportOperatorSplitting.
130  * In particular the velocity field dosn't change over this interval.
131  *
132  * Dependencies:
133  *
134  * velocity, porosity -> matrix, source_vector
135  * matrix -> time_step
136  *
137  * data_read_times -> time_step (not necessary if we won't stick to jump times)
138  * data -> source_vector
139  * time_step -> scaling
140  *
141  *
142  *
143  */
144  void set_target_time(double target_time);
145 
146  /**
147  * Use Balance object from upstream equation (e.g. in various couplings) instead of own instance.
148  */
149  void set_balance_object(boost::shared_ptr<Balance> balance)
150  {
151  balance_ = balance;
152  subst_idx = balance_->add_quantities(substances_.names());
153  }
154 
156  { return subst_idx; }
157 
158  /**
159  * Calculate quantities necessary for cumulative balance (over time).
160  * This method is called at each (sub)iteration of the time loop.
161  */
163 
164  /**
165  * Calculate instant quantities at output times.
166  */
168 
169  /**
170  * Communicate parallel concentration vectors into sequential output vector.
171  */
172  void output_vector_gather();
173 
174  /**
175  * @brief Write computed fields.
176  */
177  virtual void output_data() override;
178 
179 
180  /**
181  * Getters.
182  */
183  inline EqData *get_data() { return &data_; }
184 
186 
187  double **get_concentration_matrix();
188  Vec *get_concentration_vector() { return vconc; }
189  void get_par_info(int * &el_4_loc, Distribution * &el_ds);
190  int *get_el_4_loc();
191  int *get_row_4_el();
192 
193 private:
194 
195  /**
196  * Assembly convection term part of the matrix and boundary matrix for application of boundary conditions.
197  *
198  * Discretization of the convection term use explicit time scheme and finite volumes with full upwinding.
199  * We count on with exchange between dimensions and mixing on edges where more then two elements connect (can happen for 2D and 1D elements in
200  * 3D embedding space)
201  *
202  * In order to get multiplication matrix for explicit transport one have to scale the convection part by the acctual time step and
203  * add time term, i. e. unit matrix (see. transport_matrix_step_mpi)
204  *
205  * Updates CFL time step constrain.
206  */
208 
209  void make_transport_partitioning(); //
210  void set_initial_condition();
213 
214  //note: the source of concentration is multiplied by time interval (gives the mass, not the flow like before)
215  void compute_concentration_sources(unsigned int sbi);
216 
217  /**
218  * Finish explicit transport matrix (time step scaling)
219  */
220  void transport_matrix_step_mpi(double time_step); //
221 
224 
225 
226 
227  /**
228  * Parameters of the equation, some are shared with other implementations since EqData is derived from TransportBase::TransportEqData
229  */
231 
232  /**
233  * Indicates if we finished the matrix and add vector by scaling with timestep factor.
234  */
236 
237  double *sources_corr;
239 
240  ///temporary arrays to store constant values of fields over time interval
241  //(avoiding calling "field.value()" too often)
242  double **sources_density,
243  **sources_conc,
244  **sources_sigma;
245 
246  TimeMark::Type target_mark_type; ///< TimeMark type for time marks denoting end of every time interval where transport matrix remains constant.
247  double cfl_max_step;
248  // only local part
249 
250 
251 
252  VecScatter vconc_out_scatter;
253  Mat tm; // PETSc transport matrix
254 
255  /// Time when the transport matrix was created.
256  /// TODO: when we have our own classes for LA objects, we can use lazy dependence to check
257  /// necessity for matrix update
259 
260  /// Concentration vectors for mobile phase.
261  Vec *vconc; // concentration vector
262  /// Concentrations for phase, substance, element
263  double **conc;
264 
265  ///
266  Vec *vpconc; // previous concentration vector
267  Vec *bcvcorr; // boundary condition correction vector
269  double **cumulative_corr;
270 
272 
273  /// Record with output specification.
275 
277 
278 
279  int *row_4_el;
280  int *el_4_loc;
282 
283  /// List of indices used to call balance methods for a set of quantities.
285 
287 };
288 #endif /* TRANSPORT_H_ */
void compute_concentration_sources(unsigned int sbi)
Definition: transport.cc:387
Sorption model in immobile zone in case dual porosity is considered.
Definition: sorption.hh:96
Abstract base class for equation clasess.
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:51
std::vector< VectorSeqDouble > out_conc
Definition: transport.h:271
unsigned long int Type
Definition: time_marks.hh:64
double * sources_corr
Definition: transport.h:237
void update_solution() override
Definition: transport.cc:495
double transport_matrix_time
Definition: transport.h:258
const std::vector< std::string > & names()
Definition: substance.hh:97
void set_balance_object(boost::shared_ptr< Balance > balance)
Definition: transport.h:149
void alloc_transport_vectors()
Definition: transport.cc:241
double ** sources_sigma
Definition: transport.h:242
BCField< 3, FieldValue< 3 >::Vector > bc_conc
Definition: transport.h:97
MultiField< 3, FieldValue< 3 >::Scalar > conc_mobile
Calculated concentrations in the mobile zone.
Definition: transport.h:103
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:52
TimeMark::Type target_mark_type
TimeMark type for time marks denoting end of every time interval where transport matrix remains const...
Definition: transport.h:246
Vec * get_concentration_vector()
Definition: transport.h:188
void set_initial_condition()
Definition: transport.cc:222
void set_boundary_conditions()
Definition: transport.cc:319
Coupling of a transport model with a reaction model by operator splitting.
void transport_matrix_step_mpi(double time_step)
Definition: mesh.h:109
double ** conc
Concentrations for phase, substance, element.
Definition: transport.h:263
void calculate_instant_balance()
Definition: transport.cc:792
virtual ~ConvectionTransport()
Definition: transport.cc:185
void get_par_info(int *&el_4_loc, Distribution *&el_ds)
Definition: transport.cc:748
void zero_time_step() override
Definition: transport.cc:464
void output_vector_gather()
Definition: transport.cc:728
Specification of transport model interface.
OutputTime * output_stream_
Definition: transport.h:276
ConvectionTransport(Mesh &init_mesh, const Input::Record &in_rec)
Definition: transport.cc:97
static Input::Type::Selection sorption_type_selection
Definition: transport.h:83
Input::Record output_rec
Record with output specification.
Definition: transport.h:274
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
boost::shared_ptr< Balance > balance_
(new) object for calculation and writing the mass balance to file.
The class for outputting data during time.
Definition: output_time.hh:32
vector< unsigned int > subst_idx
List of indices used to call balance methods for a set of quantities.
Definition: transport.h:284
Vec * vconc
Concentration vectors for mobile phase.
Definition: transport.h:261
void read_concentration_sources()
FieldSet output_fields
Fields indended for output, i.e. all input fields plus those representing solution.
Definition: transport.h:107
Field< 3, FieldValue< 3 >::Integer > region_id
Definition: transport.h:102
void create_transport_matrix_mpi()
Definition: transport.cc:600
void alloc_transport_structs_mpi()
Definition: transport.cc:276
bool is_convection_matrix_scaled
Definition: transport.h:235
static Input::Type::Selection output_selection
Definition: transport.h:85
SubstanceList substances_
Transported substances.
VecScatter vconc_out_scatter
Definition: transport.h:252
double ** sources_density
temporary arrays to store constant values of fields over time interval
Definition: transport.h:242
virtual void output_data() override
Write computed fields.
Definition: transport.cc:822
void set_target_time(double target_time)
Definition: transport.cc:579
void calculate_cumulative_balance()
Definition: transport.cc:764
OutputTime * output_stream()
Definition: transport.h:185
const vector< unsigned int > & get_subst_idx()
Definition: transport.h:155
double ** cumulative_corr
Definition: transport.h:269
RegionSet read_boundary_list_item(Input::Record rec)
Override generic method in order to allow specification of the boundary conditions through the old bc...
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:45
double ** get_concentration_matrix()
Definition: transport.cc:744
Distribution * el_ds
Definition: transport.h:281
Template for classes storing finite set of named values.
Field< 3, FieldValue< 3 >::Vector > init_conc
Initial concentrations.
Definition: transport.h:100
void make_transport_partitioning()
Definition: transport.cc:161
double ** sources_conc
Definition: transport.h:242
EqData * get_data()
Definition: transport.h:183