Flow123d  release_3.0.0-968-gc87a28e79
darcy_flow_mh_output.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file darcy_flow_mh_output.hh
15  * @brief Output class for darcy_flow_mh model.
16  * @author Jan Brezina
17  */
18 
19 #ifndef DARCY_FLOW_MH_OUTPUT_HH_
20 #define DARCY_FLOW_MH_OUTPUT_HH_
21 
22 #include <stdio.h> // for sprintf
23 #include <string.h> // for memcpy
24 
25 #include <cmath> // for pow
26 #include <iosfwd> // for ofstream
27 #include <memory> // for shared_ptr
28 #include <vector> // for vector
29 #include <armadillo>
30 #include "fem/fe_p.hh" // for FE_P_disc
31 #include "fem/fe_rt.hh" // for FE_RT0
32 #include "fem/mapping_p1.hh" // for MappingP1
33 #include "fem/fe_values.hh" // for FEValues
34 #include "quadrature/quadrature_lib.hh" // for QGauss
35 #include "fields/equation_output.hh" // for EquationOutput
36 #include "fields/field.hh" // for Field
37 #include "fields/field_set.hh" // for FieldSet
38 #include "fields/field_values.hh" // for FieldValue<>::Scalar, FieldV...
39 #include "fields/field_python.hh"
40 #include "la/vector_mpi.hh" // for VectorMPI
41 #include "input/type_base.hh" // for Array
42 #include "input/type_generic.hh" // for Instance
43 #include "petscvec.h" // for Vec, _p_Vec
44 #include "system/exceptions.hh" // for ExcAssertMsg::~ExcAssertMsg
45 
46 class DOFHandlerMultiDim;
47 class DarcyMH;
48 class Mesh;
49 class OutputTime;
50 namespace Input {
51  class Record;
52  namespace Type {
53  class Record;
54  }
55 }
56 
57 template<unsigned int dim, unsigned int spacedim> class FEValues;
58 template <int spacedim, class Value> class FieldFE;
59 
60 /**
61  * Actually this class only collect former code from postprocess.*
62  * This code depends on values stored in mesh and has to be changed to use fields or other data provided by
63  * interface to darcy_flow. We have to relay on the interface in order to allow different implementation of darcy_flow.
64  *
65  * Principal functionalities of current postprocess are:
66  * - move computed values into mesh - this can be removed after we get new output classes,
67  * other dependent code can use directly field interface
68  * - compute interpolation to nodes - this can be external and operate directly on fields
69  * - compute water balances over materials and boundary parts - is feasible through field interface
70  *
71  * Further functionality of this class should be:
72  * - prepare data for general output classes
73  *
74  */
76 public:
77 
78  /// Standard quantities for output in DarcyFlowMH.
79  class OutputFields : public EquationOutput {
80  public:
81 
82  OutputFields();
83 
90  };
91 
92  /// Specific quantities for output in DarcyFlowMH - error estimates etc.
94  public:
96 
100  };
101 
103  virtual ~DarcyFlowMHOutput();
104 
105  static const Input::Type::Instance & get_input_type();
107 
108  /** \brief Calculate values for output. **/
109  void output();
110 
111  //const OutputFields &get_output_fields() { return output_fields; }
112 
113 
114 
115 protected:
117 
118  virtual void prepare_output(Input::Record in_rec);
119  virtual void prepare_specific_output(Input::Record in_rec);
120 
121  void make_side_flux();
122  void make_element_scalar(ElementSetRef element_indices);
123 
124  /** Computes fluxes at the barycenters of elements.
125  * TODO:
126  * We use FEValues to get fluxes at the barycenters of elements,
127  * but we still use MHDofHandler. Once we are able to make output routines
128  * parallel, we can use simply FieldFE for velocity here.
129  */
130  void make_element_vector(ElementSetRef element_indices);
131 
132  //void make_sides_scalar();
133  /**
134  * \brief Calculate nodes scalar,
135  * store it in double* node_scalars instead of node->scalar
136  * */
137  void make_node_scalar_param(ElementSetRef element_indices);
138  //void make_node_scalar();
139  void make_corner_scalar(vector<double> &node_scalar);
140  //void make_neighbour_flux();
142 
143  /**
144  * Temporary hack.
145  * Calculate approximation of L2 norm for:
146  * 1) difference between regularized pressure and analytical solution (using FunctionPython)
147  * 2) difference between RT velocities and analytical solution
148  * 3) difference of divergence
149  *
150  * TODO:
151  * 1) implement field objects
152  * 2) implement DG_P2 finite elements
153  * 3) implement pressure postprocessing (result is DG_P2 field)
154  * 4) implement calculation of L2 norm for two field (compute the norm and values on individual elements as P0 field)
155  */
156  void compute_l2_difference();
157 
158 
161 
162  /// Specific experimental error computing.
164 
165 
166  /** Pressure head (in [m]) interpolated into nodes. Provides P1 approximation. Indexed by element-node numbering.*/
168  /** Pressure head (in [m]) in barycenters of elements (or equivalently mean pressure over every element). Indexed by element indexes in the mesh.*/
170  /** Piezo-metric head (in [m]) in barycenter of elements (or equivalently mean pressure over every element). Indexed by element indexes in the mesh.*/
172 
173  /** Average flux in barycenter of every element. Indexed as elements in the mesh. */
174  // TODO: Definitely we need more general (templated) implementation of Output that accept arbitrary containers. So
175  // that we can pass there directly vector< arma:: vec3 >
177 
178  // Temporary objects holding pointers to appropriate FieldFE
179  // TODO remove after final fix of equations
180  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> ele_pressure_ptr; ///< Field of pressure head in barycenters of elements.
181  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> ele_piezo_head_ptr; ///< Field of piezo-metric head in barycenters of elements.
182  std::shared_ptr<FieldFE<3, FieldValue<3>::VectorFixed>> ele_flux_ptr; ///< Field of flux in barycenter of every element.
183 
184  // A vector of all element indexes
186 
187  // integrals of squared differences on individual elements - error indicators, can be written out into VTK files
189 
190  std::shared_ptr<DOFHandlerMultiDim> dh_;
191  FE_P_disc<0> fe0; //TODO temporary solution - add support of FEData<0>
192  std::shared_ptr<DiscreteSpace> ds;
193 
196 
197  std::shared_ptr<OutputTime> output_stream;
198 
199  /// Raw data output file.
200  ofstream raw_output_file;
201 
202  /// Output specific field stuff
204  struct DiffData {
210 
211  // Temporary objects holding pointers to appropriate FieldFE
212  // TODO remove after final fix of equations
213  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> pressure_diff_ptr;
214  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> vel_diff_ptr;
215  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> div_diff_ptr;
216 
217  double * solution;
218  const MH_DofHandler * dh;
219 
223  } diff_data;
224 
225 
226  /// Struct containing all dim dependent FE classes needed for output
227  /// (and for computing solution error).
228  template<int dim> struct FEData{
229  FEData();
230 
231  // we create trivial Dofhandler , for P0 elements, to get access to, FEValues on individual elements
232  // this we use to integrate our own functions - difference of postprocessed pressure and analytical solution
235 
236  const unsigned int order; // order of Gauss quadrature
238 
240 
242 
243  // FEValues for velocity.
246  };
247 
251 
252  /// Computes L2 error on an element.
253  template <int dim>
255  FEValues<dim,3> &fe_values, FEValues<dim,3> &fv_rt,
256  FieldPython<3, FieldValue<3>::Vector > &anal_sol, DiffData &result);
257 };
258 
259 
260 #endif /* DARCY_FLOW_MH_OUTPUT_HH_ */
261 
DarcyFlowMHOutput::OutputSpecificFields::OutputSpecificFields
OutputSpecificFields()
Definition: darcy_flow_mh_output.cc:112
DarcyFlowMHOutput::l2_diff_pressure
std::vector< double > l2_diff_pressure
Definition: darcy_flow_mh_output.hh:188
FE_RT0
Raviart-Thomas element of order 0.
Definition: fe_rt.hh:60
DarcyFlowMHOutput::ele_flux
VectorMPI ele_flux
Definition: darcy_flow_mh_output.hh:176
DarcyFlowMHOutput::prepare_specific_output
virtual void prepare_specific_output(Input::Record in_rec)
Definition: darcy_flow_mh_output.cc:208
DarcyFlowMHOutput::FEData::order
const unsigned int order
Definition: darcy_flow_mh_output.hh:236
DarcyFlowMHOutput::l2_diff_velocity
std::vector< double > l2_diff_velocity
Definition: darcy_flow_mh_output.hh:188
DarcyFlowMHOutput::FEData::fe_p0
FE_P_disc< dim > fe_p0
Definition: darcy_flow_mh_output.hh:233
fe_rt.hh
Definitions of Raviart-Thomas finite elements.
DarcyFlowMHOutput::output
void output()
Calculate values for output.
Definition: darcy_flow_mh_output.cc:250
vector_mpi.hh
DarcyFlowMHOutput::fe_data_1d
FEData< 1 > fe_data_1d
Definition: darcy_flow_mh_output.hh:248
field_python.hh
Input
Abstract linear system class.
Definition: balance.hh:37
DarcyFlowMHOutput::is_output_specific_fields
bool is_output_specific_fields
Output specific field stuff.
Definition: darcy_flow_mh_output.hh:203
DarcyFlowMHOutput::output_specific_fields
OutputSpecificFields output_specific_fields
Definition: darcy_flow_mh_output.hh:195
string.h
DarcyFlowMHOutput::compute_l2_difference
void compute_l2_difference()
Definition: darcy_flow_mh_output.cc:676
DarcyFlowMHOutput::make_element_vector
void make_element_vector(ElementSetRef element_indices)
Definition: darcy_flow_mh_output.cc:344
DarcyFlowMHOutput::prepare_output
virtual void prepare_output(Input::Record in_rec)
Definition: darcy_flow_mh_output.cc:166
fe_values.hh
Class FEValues calculates finite element data on the actual cells such as shape function values,...
DarcyFlowMHOutput::ElementSetRef
const typedef vector< unsigned int > & ElementSetRef
Definition: darcy_flow_mh_output.hh:116
field_set.hh
DarcyFlowMHOutput::make_side_flux
void make_side_flux()
DarcyFlowMHOutput::ele_pressure_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > ele_pressure_ptr
Field of pressure head in barycenters of elements.
Definition: darcy_flow_mh_output.hh:180
DarcyFlowMHOutput::FEData::fe_p1
FE_P_disc< dim > fe_p1
Definition: darcy_flow_mh_output.hh:234
std::vector< unsigned int >
DarcyFlowMHOutput::l2_diff_local
void l2_diff_local(ElementAccessor< 3 > &ele, FEValues< dim, 3 > &fe_values, FEValues< dim, 3 > &fv_rt, FieldPython< 3, FieldValue< 3 >::Vector > &anal_sol, DiffData &result)
Computes L2 error on an element.
ElementAccessor< 3 >
DarcyFlowMHOutput::mesh_
Mesh * mesh_
Definition: darcy_flow_mh_output.hh:160
DarcyFlowMHOutput::FEData::fe_rt
FE_RT0< dim > fe_rt
Definition: darcy_flow_mh_output.hh:244
DarcyFlowMHOutput::corner_pressure
VectorMPI corner_pressure
Definition: darcy_flow_mh_output.hh:167
DarcyFlowMHOutput::make_corner_scalar
void make_corner_scalar(vector< double > &node_scalar)
Definition: darcy_flow_mh_output.cc:362
type_base.hh
DarcyFlowMHOutput::output_stream
std::shared_ptr< OutputTime > output_stream
Definition: darcy_flow_mh_output.hh:197
flow
Definition: output_msh.hh:24
DarcyFlowMHOutput::FEData::fe_values
FEValues< dim, 3 > fe_values
Definition: darcy_flow_mh_output.hh:241
exceptions.hh
DarcyFlowMHOutput::OutputSpecificFields::pressure_diff
Field< 3, FieldValue< 3 >::Scalar > pressure_diff
Definition: darcy_flow_mh_output.hh:98
DarcyFlowMHOutput::OutputFields
Standard quantities for output in DarcyFlowMH.
Definition: darcy_flow_mh_output.hh:79
DarcyFlowMHOutput::dh_
std::shared_ptr< DOFHandlerMultiDim > dh_
Definition: darcy_flow_mh_output.hh:190
DarcyFlowMHOutput::OutputFields::region_id
Field< 3, FieldValue< 3 >::Scalar > region_id
Definition: darcy_flow_mh_output.hh:89
FEValues
Calculates finite element data on the actual cell.
Definition: fe_values.hh:532
fe_p.hh
Definitions of basic Lagrangean finite elements with polynomial shape functions.
DarcyFlowMHOutput::DiffData::data_
DarcyMH::EqData * data_
Definition: darcy_flow_mh_output.hh:222
DarcyMH::EqData
Definition: darcy_flow_mh.hh:149
DarcyFlowMHOutput::fe_data_3d
FEData< 3 > fe_data_3d
Definition: darcy_flow_mh_output.hh:250
equation_output.hh
DarcyFlowMHOutput::ds
std::shared_ptr< DiscreteSpace > ds
Definition: darcy_flow_mh_output.hh:192
DarcyFlowMHOutput::DiffData::div_diff_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > div_diff_ptr
Definition: darcy_flow_mh_output.hh:215
DarcyFlowMHOutput::DiffData::velocity_error
double velocity_error[3]
Definition: darcy_flow_mh_output.hh:205
DarcyFlowMHOutput::l2_diff_divergence
std::vector< double > l2_diff_divergence
Definition: darcy_flow_mh_output.hh:188
DarcyFlowMHOutput::output_fields
OutputFields output_fields
Definition: darcy_flow_mh_output.hh:194
DarcyFlowMHOutput::DiffData::mask_vel_error
double mask_vel_error
Definition: darcy_flow_mh_output.hh:206
DarcyFlowMHOutput::all_element_idx_
std::vector< unsigned int > all_element_idx_
Definition: darcy_flow_mh_output.hh:185
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
DarcyFlowMHOutput::OutputSpecificFields
Specific quantities for output in DarcyFlowMH - error estimates etc.
Definition: darcy_flow_mh_output.hh:93
type_generic.hh
quadrature_lib.hh
Definitions of particular quadrature rules on simplices.
DOFHandlerMultiDim
Provides the numbering of the finite element degrees of freedom on the computational mesh.
Definition: dofhandler.hh:152
DarcyFlowMHOutput::FEData::fv_rt
FEValues< dim, 3 > fv_rt
Definition: darcy_flow_mh_output.hh:245
DarcyFlowMHOutput::FEData
Definition: darcy_flow_mh_output.hh:228
DarcyFlowMHOutput::make_node_scalar_param
void make_node_scalar_param(ElementSetRef element_indices)
Calculate nodes scalar, store it in double* node_scalars instead of node->scalar.
Definition: darcy_flow_mh_output.cc:399
DarcyFlowMHOutput::DiffData::vel_diff_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > vel_diff_ptr
Definition: darcy_flow_mh_output.hh:214
EquationOutput
Definition: equation_output.hh:40
DarcyFlowMHOutput::OutputSpecificFields::velocity_diff
Field< 3, FieldValue< 3 >::Scalar > velocity_diff
Definition: darcy_flow_mh_output.hh:97
DarcyFlowMHOutput::OutputFields::field_ele_flux
Field< 3, FieldValue< 3 >::VectorFixed > field_ele_flux
Definition: darcy_flow_mh_output.hh:87
DarcyFlowMHOutput::OutputSpecificFields::div_diff
Field< 3, FieldValue< 3 >::Scalar > div_diff
Definition: darcy_flow_mh_output.hh:99
DarcyFlowMHOutput::OutputFields::OutputFields
OutputFields()
Definition: darcy_flow_mh_output.cc:85
DarcyFlowMHOutput::FEData::quad
QGauss< dim > quad
Definition: darcy_flow_mh_output.hh:237
field_values.hh
OutputTime
The class for outputting data during time.
Definition: output_time.hh:50
DarcyFlowMHOutput::get_input_type
static const Input::Type::Instance & get_input_type()
Definition: darcy_flow_mh_output.cc:60
DarcyFlowMHOutput::DiffData::pressure_diff_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > pressure_diff_ptr
Definition: darcy_flow_mh_output.hh:213
DarcyFlowMHOutput::ele_pressure
VectorMPI ele_pressure
Definition: darcy_flow_mh_output.hh:169
Input::Type::Instance
Helper class that stores data of generic types.
Definition: type_generic.hh:89
DarcyFlowMHOutput::DiffData::div_diff
VectorMPI div_diff
Definition: darcy_flow_mh_output.hh:209
DarcyFlowMHOutput::DiffData::div_error
double div_error[3]
Definition: darcy_flow_mh_output.hh:205
DarcyFlowMHOutput::FEData::mapp
MappingP1< dim, 3 > mapp
Definition: darcy_flow_mh_output.hh:239
DarcyFlowMHOutput::get_input_type_specific
static const Input::Type::Instance & get_input_type_specific()
Definition: darcy_flow_mh_output.cc:68
DarcyFlowMHOutput::fe_data_2d
FEData< 2 > fe_data_2d
Definition: darcy_flow_mh_output.hh:249
DarcyFlowMHOutput::output_internal_flow_data
void output_internal_flow_data()
Definition: darcy_flow_mh_output.cc:521
DarcyFlowMHOutput::OutputFields::field_ele_piezo_head
Field< 3, FieldValue< 3 >::Scalar > field_ele_piezo_head
Definition: darcy_flow_mh_output.hh:86
FieldValue_
Definition: field_values.hh:247
DarcyFlowMHOutput::DiffData
Definition: darcy_flow_mh_output.hh:204
DarcyFlowMHOutput::DiffData::dh
const MH_DofHandler * dh
Definition: darcy_flow_mh_output.hh:218
DarcyFlowMHOutput::DiffData::darcy
DarcyMH * darcy
Definition: darcy_flow_mh_output.hh:221
QGauss
Symmetric Gauss-Legendre quadrature formulae on simplices.
Definition: quadrature_lib.hh:33
DarcyFlowMHOutput::raw_output_file
ofstream raw_output_file
Raw data output file.
Definition: darcy_flow_mh_output.hh:200
FieldFE
Definition: field.hh:56
DarcyFlowMHOutput::OutputFields::field_node_pressure
Field< 3, FieldValue< 3 >::Scalar > field_node_pressure
Definition: darcy_flow_mh_output.hh:85
FieldPython
Definition: field_python.hh:46
Mesh
Definition: mesh.h:80
DarcyFlowMHOutput::diff_data
struct DarcyFlowMHOutput::DiffData diff_data
DarcyFlowMHOutput::DiffData::solution
double * solution
Definition: darcy_flow_mh_output.hh:217
DarcyFlowMHOutput::ele_piezo_head
VectorMPI ele_piezo_head
Definition: darcy_flow_mh_output.hh:171
DarcyFlowMHOutput::DiffData::velocity_mask
std::vector< int > velocity_mask
Definition: darcy_flow_mh_output.hh:220
DarcyFlowMHOutput::ele_flux_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::VectorFixed > > ele_flux_ptr
Field of flux in barycenter of every element.
Definition: darcy_flow_mh_output.hh:182
MappingP1< dim, 3 >
DarcyFlowMHOutput::compute_errors_
bool compute_errors_
Specific experimental error computing.
Definition: darcy_flow_mh_output.hh:163
DarcyFlowMHOutput::ele_piezo_head_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > ele_piezo_head_ptr
Field of piezo-metric head in barycenters of elements.
Definition: darcy_flow_mh_output.hh:181
DarcyFlowMHOutput::DarcyFlowMHOutput
DarcyFlowMHOutput(DarcyMH *flow, Input::Record in_rec)
Definition: darcy_flow_mh_output.cc:126
mapping_p1.hh
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell.
DarcyFlowMHOutput::OutputFields::subdomain
Field< 3, FieldValue< 3 >::Scalar > subdomain
Definition: darcy_flow_mh_output.hh:88
DarcyFlowMHOutput::~DarcyFlowMHOutput
virtual ~DarcyFlowMHOutput()
Definition: darcy_flow_mh_output.cc:238
DarcyFlowMHOutput::darcy_flow
DarcyMH * darcy_flow
Definition: darcy_flow_mh_output.hh:159
VectorMPI
Definition: vector_mpi.hh:42
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:83
DarcyFlowMHOutput::DiffData::pressure_error
double pressure_error[3]
Definition: darcy_flow_mh_output.hh:205
DarcyFlowMHOutput::FEData::FEData
FEData()
Definition: darcy_flow_mh_output.cc:669
DarcyFlowMHOutput
Definition: darcy_flow_mh_output.hh:75
DarcyMH
Mixed-hybrid model of linear Darcy flow, possibly unsteady.
Definition: darcy_flow_mh.hh:126
DarcyFlowMHOutput::OutputFields::field_ele_pressure
Field< 3, FieldValue< 3 >::Scalar > field_ele_pressure
Definition: darcy_flow_mh_output.hh:84
DarcyFlowMHOutput::make_element_scalar
void make_element_scalar(ElementSetRef element_indices)
Definition: darcy_flow_mh_output.cc:322
DarcyFlowMHOutput::DiffData::velocity_diff
VectorMPI velocity_diff
Definition: darcy_flow_mh_output.hh:208
FE_P_disc< 0 >
MH_DofHandler
Definition: mh_dofhandler.hh:43
field.hh
DarcyFlowMHOutput::fe0
FE_P_disc< 0 > fe0
Definition: darcy_flow_mh_output.hh:191
DarcyFlowMHOutput::DiffData::pressure_diff
VectorMPI pressure_diff
Definition: darcy_flow_mh_output.hh:207