Flow123d  JS_before_hm-2152-gf87f4aac4
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/fe_values.hh" // for FEValues
33 #include "quadrature/quadrature_lib.hh" // for QGauss
34 #include "fields/equation_output.hh" // for EquationOutput
35 #include "fields/field.hh" // for Field
36 #include "fields/field_set.hh" // for FieldSet
37 #include "fields/field_values.hh" // for FieldValue<>::Scalar, FieldV...
38 #include "fields/field_python.hh"
39 #include "la/vector_mpi.hh" // for VectorMPI
40 #include "input/type_base.hh" // for Array
41 #include "input/type_generic.hh" // for Instance
42 #include "petscvec.h" // for Vec, _p_Vec
43 #include "system/exceptions.hh" // for ExcAssertMsg::~ExcAssertMsg
44 
45 class DOFHandlerMultiDim;
46 class DarcyFlowInterface;
47 class Mesh;
48 class OutputTime;
49 namespace Input {
50  class Record;
51  namespace Type {
52  class Record;
53  }
54 }
55 
56 template<unsigned int spacedim> class FEValues;
57 template <int spacedim, class Value> class FieldFE;
58 
59 /**
60  * Actually this class only collect former code from postprocess.*
61  * This code depends on values stored in mesh and has to be changed to use fields or other data provided by
62  * interface to darcy_flow. We have to relay on the interface in order to allow different implementation of darcy_flow.
63  *
64  * Principal functionalities of current postprocess are:
65  * - move computed values into mesh - this can be removed after we get new output classes,
66  * other dependent code can use directly field interface
67  * - compute interpolation to nodes - this can be external and operate directly on fields
68  * - compute water balances over materials and boundary parts - is feasible through field interface
69  *
70  * Further functionality of this class should be:
71  * - prepare data for general output classes
72  *
73  */
75 public:
76 
77  /// Standard quantities for output in DarcyFlowMH.
78  class OutputFields : public EquationOutput {
79  public:
80 
81  OutputFields();
82 
85  };
86 
87  /// Specific quantities for output in DarcyFlowMH - error estimates etc.
89  public:
91 
95  };
96 
98  virtual ~DarcyFlowMHOutput();
99 
100  static const Input::Type::Instance & get_input_type(FieldSet& eq_data, const std::string &equation_name);
102 
103  /** \brief Calculate values for output. **/
104  void output();
105 
106  //const OutputFields &get_output_fields() { return output_fields; }
107 
108 
109 
110 protected:
112 
113  virtual void prepare_output(Input::Record in_rec);
114  virtual void prepare_specific_output(Input::Record in_rec);
115 
117 
118  /**
119  * Temporary hack.
120  * Calculate approximation of L2 norm for:
121  * 1) difference between regularized pressure and analytical solution (using FunctionPython)
122  * 2) difference between RT velocities and analytical solution
123  * 3) difference of divergence
124  *
125  * TODO:
126  * 1) implement field objects
127  * 2) implement DG_P2 finite elements
128  * 3) implement pressure postprocessing (result is DG_P2 field)
129  * 4) implement calculation of L2 norm for two field (compute the norm and values on individual elements as P0 field)
130  */
131  void compute_l2_difference();
132 
133 
136 
137  /// Specific experimental error computing.
139 
140 
141  /** Pressure head (in [m]) interpolated into nodes. Provides P1 approximation. Indexed by element-node numbering.*/
143  /** Pressure head (in [m]) in barycenters of elements (or equivalently mean pressure over every element). Indexed by element indexes in the mesh.*/
145  /** Piezo-metric head (in [m]) in barycenter of elements (or equivalently mean pressure over every element). Indexed by element indexes in the mesh.*/
147 
148  // integrals of squared differences on individual elements - error indicators, can be written out into VTK files
150 
151  std::shared_ptr<DOFHandlerMultiDim> dh_;
152  std::shared_ptr<DiscreteSpace> ds;
153 
156 
157  std::shared_ptr<OutputTime> output_stream;
158 
159  /// Raw data output file.
160  ofstream raw_output_file;
161 
162  /// Output specific field stuff
164  struct DiffData {
167 
168  // Temporary objects holding pointers to appropriate FieldFE
169  // TODO remove after final fix of equations
170  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> pressure_diff_ptr;
171  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> vel_diff_ptr;
172  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> div_diff_ptr;
173 
174  std::shared_ptr<SubDOFHandlerMultiDim> dh_;
175 
179  } diff_data;
180 
181  //MixedPtr<FE_P_disc> fe_p0;
182 
183  /// Struct containing all dim dependent FE classes needed for output
184  /// (and for computing solution error).
185  struct FEData{
186  FEData();
187 
188  const unsigned int order; // order of Gauss quadrature
191 
192  // following is used for calculation of postprocessed pressure difference
193  // and comparison to analytical solution
196 
197  // FEValues for velocity.
200  };
201 
203 
204  /// Computes L2 error on an element.
205  void l2_diff_local(DHCellAccessor dh_cell,
206  FEValues<3> &fe_values, FEValues<3> &fv_rt,
207  FieldPython<3, FieldValue<3>::Vector > &anal_sol, DiffData &result);
208 };
209 
210 
211 #endif /* DARCY_FLOW_MH_OUTPUT_HH_ */
212 
DarcyFlowMHOutput::OutputSpecificFields::OutputSpecificFields
OutputSpecificFields()
Definition: darcy_flow_mh_output.cc:113
DarcyFlowMHOutput::l2_diff_pressure
std::vector< double > l2_diff_pressure
Definition: darcy_flow_mh_output.hh:149
DarcyFlowMHOutput::prepare_specific_output
virtual void prepare_specific_output(Input::Record in_rec)
Definition: darcy_flow_mh_output.cc:191
DarcyFlowMHOutput::l2_diff_velocity
std::vector< double > l2_diff_velocity
Definition: darcy_flow_mh_output.hh:149
fe_rt.hh
Definitions of Raviart-Thomas finite elements.
DarcyFlowMHOutput::DiffData::eq_data_
DarcyMH::EqData * eq_data_
Definition: darcy_flow_mh_output.hh:178
DarcyFlowMHOutput::output
void output()
Calculate values for output.
Definition: darcy_flow_mh_output.cc:246
DarcyFlowMHOutput::FEData::order
const unsigned int order
Definition: darcy_flow_mh_output.hh:188
vector_mpi.hh
field_python.hh
Input
Abstract linear system class.
Definition: balance.hh:40
DarcyFlowMHOutput::is_output_specific_fields
bool is_output_specific_fields
Output specific field stuff.
Definition: darcy_flow_mh_output.hh:163
DarcyFlowMHOutput::output_specific_fields
OutputSpecificFields output_specific_fields
Definition: darcy_flow_mh_output.hh:155
string.h
DarcyFlowMHOutput::DiffData::eq_fields_
DarcyMH::EqFields * eq_fields_
Definition: darcy_flow_mh_output.hh:177
DarcyFlowMHOutput::compute_l2_difference
void compute_l2_difference()
Definition: darcy_flow_mh_output.cc:507
DarcyFlowMHOutput::FEData::FEData
FEData()
Definition: darcy_flow_mh_output.cc:495
DarcyFlowMHOutput::prepare_output
virtual void prepare_output(Input::Record in_rec)
Definition: darcy_flow_mh_output.cc:177
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:111
field_set.hh
std::vector< unsigned int >
DarcyFlowMHOutput::mesh_
Mesh * mesh_
Definition: darcy_flow_mh_output.hh:135
DarcyFlowMHOutput::corner_pressure
VectorMPI corner_pressure
Definition: darcy_flow_mh_output.hh:142
type_base.hh
DarcyFlowMHOutput::output_stream
std::shared_ptr< OutputTime > output_stream
Definition: darcy_flow_mh_output.hh:157
flow
Definition: output_msh.hh:24
exceptions.hh
DarcyFlowMHOutput::OutputSpecificFields::pressure_diff
Field< 3, FieldValue< 3 >::Scalar > pressure_diff
Definition: darcy_flow_mh_output.hh:93
DarcyFlowMHOutput::OutputFields
Standard quantities for output in DarcyFlowMH.
Definition: darcy_flow_mh_output.hh:78
DarcyFlowMHOutput::dh_
std::shared_ptr< DOFHandlerMultiDim > dh_
Definition: darcy_flow_mh_output.hh:151
DarcyFlowMHOutput::OutputFields::region_id
Field< 3, FieldValue< 3 >::Scalar > region_id
Definition: darcy_flow_mh_output.hh:84
FEValues
Calculates finite element data on the actual cell.
Definition: fe_values.hh:66
fe_p.hh
Definitions of basic Lagrangean finite elements with polynomial shape functions.
DarcyMH::EqData
Definition: darcy_flow_mh.hh:204
DarcyFlowMHOutput::get_input_type
static const Input::Type::Instance & get_input_type(FieldSet &eq_data, const std::string &equation_name)
Definition: darcy_flow_mh_output.cc:62
equation_output.hh
DarcyFlowMHOutput::ds
std::shared_ptr< DiscreteSpace > ds
Definition: darcy_flow_mh_output.hh:152
DarcyFlowMHOutput::DiffData::div_diff_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > div_diff_ptr
Definition: darcy_flow_mh_output.hh:172
DarcyFlowMHOutput::DiffData::velocity_error
double velocity_error[3]
Definition: darcy_flow_mh_output.hh:165
DarcyFlowMHOutput::l2_diff_divergence
std::vector< double > l2_diff_divergence
Definition: darcy_flow_mh_output.hh:149
DarcyFlowMHOutput::output_fields
OutputFields output_fields
Definition: darcy_flow_mh_output.hh:154
DarcyFlowMHOutput::DiffData::mask_vel_error
double mask_vel_error
Definition: darcy_flow_mh_output.hh:166
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:88
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:151
DarcyFlowMHOutput::FEData
Definition: darcy_flow_mh_output.hh:185
DarcyFlowMHOutput::DiffData::vel_diff_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > vel_diff_ptr
Definition: darcy_flow_mh_output.hh:171
DarcyFlowMHOutput::FEData::quad
QGauss::array quad
Definition: darcy_flow_mh_output.hh:189
EquationOutput
Definition: equation_output.hh:44
DarcyMH::EqFields
Definition: darcy_flow_mh.hh:143
DarcyFlowMHOutput::OutputSpecificFields::velocity_diff
Field< 3, FieldValue< 3 >::Scalar > velocity_diff
Definition: darcy_flow_mh_output.hh:92
DarcyFlowMHOutput::OutputSpecificFields::div_diff
Field< 3, FieldValue< 3 >::Scalar > div_diff
Definition: darcy_flow_mh_output.hh:94
DarcyFlowMHOutput::OutputFields::OutputFields
OutputFields()
Definition: darcy_flow_mh_output.cc:86
field_values.hh
OutputTime
The class for outputting data during time.
Definition: output_time.hh:51
DarcyFlowMHOutput::FEData::fv_rt
std::vector< FEValues< 3 > > fv_rt
Definition: darcy_flow_mh_output.hh:199
QGauss::array
std::array< QGauss, 4 > array
Definition: quadrature_lib.hh:36
DarcyFlowMHOutput::DiffData::pressure_diff_ptr
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > pressure_diff_ptr
Definition: darcy_flow_mh_output.hh:170
DarcyFlowMHOutput::ele_pressure
VectorMPI ele_pressure
Definition: darcy_flow_mh_output.hh:144
DarcyFlowMHOutput::DarcyFlowMHOutput
DarcyFlowMHOutput(DarcyFlowInterface *flow, Input::Record in_rec)
Definition: darcy_flow_mh_output.cc:127
Input::Type::Instance
Helper class that stores data of generic types.
Definition: type_generic.hh:89
DarcyFlowMHOutput::fe_data
FEData fe_data
Definition: darcy_flow_mh_output.hh:202
DarcyFlowMHOutput::DiffData::div_error
double div_error[3]
Definition: darcy_flow_mh_output.hh:165
DarcyFlowMHOutput::get_input_type_specific
static const Input::Type::Instance & get_input_type_specific()
Definition: darcy_flow_mh_output.cc:69
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
DarcyFlowMHOutput::output_internal_flow_data
void output_internal_flow_data()
Definition: darcy_flow_mh_output.cc:287
DarcyFlowMHOutput::DiffData
Definition: darcy_flow_mh_output.hh:164
DarcyFlowMHOutput::raw_output_file
ofstream raw_output_file
Raw data output file.
Definition: darcy_flow_mh_output.hh:160
FieldFE
Definition: field.hh:61
FieldPython
Definition: field_python.hh:46
Mesh
Definition: mesh.h:355
DarcyFlowMHOutput::diff_data
struct DarcyFlowMHOutput::DiffData diff_data
DarcyFlowMHOutput::ele_piezo_head
VectorMPI ele_piezo_head
Definition: darcy_flow_mh_output.hh:146
DHCellAccessor
Cell accessor allow iterate over DOF handler cells.
Definition: dh_cell_accessor.hh:43
DarcyFlowMHOutput::DiffData::velocity_mask
std::vector< int > velocity_mask
Definition: darcy_flow_mh_output.hh:176
DarcyFlowMHOutput::FEData::fe_values
std::vector< FEValues< 3 > > fe_values
Definition: darcy_flow_mh_output.hh:195
DarcyFlowMHOutput::darcy_flow
DarcyFlowInterface * darcy_flow
Definition: darcy_flow_mh_output.hh:134
DarcyFlowMHOutput::FEData::fe_p0
MixedPtr< FE_P_disc > fe_p0
Definition: darcy_flow_mh_output.hh:194
DarcyFlowMHOutput::compute_errors_
bool compute_errors_
Specific experimental error computing.
Definition: darcy_flow_mh_output.hh:138
MixedPtr< FE_P_disc >
DarcyFlowMHOutput::DiffData::dh_
std::shared_ptr< SubDOFHandlerMultiDim > dh_
Definition: darcy_flow_mh_output.hh:174
DarcyFlowMHOutput::OutputFields::subdomain
Field< 3, FieldValue< 3 >::Scalar > subdomain
Definition: darcy_flow_mh_output.hh:83
DarcyFlowMHOutput::~DarcyFlowMHOutput
virtual ~DarcyFlowMHOutput()
Definition: darcy_flow_mh_output.cc:234
VectorMPI
Definition: vector_mpi.hh:43
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:93
DarcyFlowMHOutput::DiffData::pressure_error
double pressure_error[3]
Definition: darcy_flow_mh_output.hh:165
DarcyFlowMHOutput
Definition: darcy_flow_mh_output.hh:74
DarcyFlowMHOutput::l2_diff_local
void l2_diff_local(DHCellAccessor dh_cell, FEValues< 3 > &fe_values, FEValues< 3 > &fv_rt, FieldPython< 3, FieldValue< 3 >::Vector > &anal_sol, DiffData &result)
Computes L2 error on an element.
Definition: darcy_flow_mh_output.cc:381
DarcyFlowMHOutput::FEData::fe_p1
MixedPtr< FE_P_disc > fe_p1
Definition: darcy_flow_mh_output.hh:190
DarcyFlowMHOutput::FEData::fe_rt
MixedPtr< FE_RT0 > fe_rt
Definition: darcy_flow_mh_output.hh:198
field.hh
DarcyFlowInterface
Definition: darcy_flow_interface.hh:15
FieldValue
Definition: field_values.hh:645