Flow123d  release_3.0.0-859-g84487d0
output_time.impl.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 output.h
15  * @brief Header: The functions for all outputs.
16  * @todo
17  * - remove Output, keep OutputTime only (done)
18  * - remove parameter mesh from static method OutputTime::output_stream (done)
19  * - move initialization of streams from hc_expolicit_sequantial to
20  * Aplication::Aplication() constructor (done)
21  * - OutputTime::register_XXX_data - should accept iterator to output record of particular equation, ask for presence of the key
22  * that has same name as the name of the quantity to output, extract the string with stream name from this key, find the stream
23  * and perform output.
24  *
25  * on input:
26  *
27  * { // darcy flow
28  * output = {
29  * pressure_nodes="nodal_data",
30  * pressure_elements="el_data"
31  * }
32  * }
33  *
34  * output_streams=[
35  * {name="nodal_data", ... },
36  * {name="el_data", ... }
37  * ]
38  *
39  * in code:
40  *
41  * Input::Record out_rec = in_rec.val<Input::Record>("output");
42  * OutputTime::register_node_data(mesh_, "pressure_nodes", "L", out_rec, node_pressure);
43  * OutputTime::register_elem_data(mesh_, "pressure_elements", "L", out_rec, ele_pressure);
44  * ...
45  *
46  * - use exceptions instead of returning result, see declaration of exceptions through DECLARE_EXCEPTION macro
47  * - move write_data from equations into coupling, write all streams
48  *
49  * =======================
50  * - Is it still necessary to split output into registration and write the data?
51  * Could we perform it at once? ... No, it doesn't make any sense.
52  * - Support for output of corner data into GMSH format (ElementNodeData section)
53  *
54  */
55 
56 #ifndef OUTPUT_H
57 #define OUTPUT_H
58 
59 #include <vector>
60 #include <string>
61 
62 #include "system/system.hh"
63 
64 #include "system/exceptions.hh"
65 #include "io/output_time.hh"
66 #include "io/output_mesh.hh"
67 #include "io/element_data_cache.hh"
68 #include "io/output_element.hh"
69 
70 
71 
72 
73 /**************************************************************************************************************
74  * OutputTime implementation
75  */
76 
77 template <typename T>
78 ElementDataCache<T> & OutputTime::prepare_compute_data(std::string field_name, DiscreteSpace space_type, unsigned int n_rows,
79  unsigned int n_cols)
80 {
81  // get possibly existing data for the same field, check both name and type
82  unsigned int size;
83  switch (space_type) {
84  case NODE_DATA:
85  case CORNER_DATA:
86  {
87  auto &offset_vec = *( output_mesh_->offsets_->get_component_data(0).get() );
88  size = offset_vec[offset_vec.size()-1];
89  break;
90  }
91  case ELEM_DATA:
92  case NATIVE_DATA:
93  size = output_mesh_->offsets_->n_values();
94  break;
95  default:
96  ASSERT(false).error("Should not happen.");
97  break;
98  }
99 
100  auto &od_vec=this->output_data_vec_[space_type];
101  auto it=std::find_if(od_vec.begin(), od_vec.end(),
102  [&field_name](OutputDataPtr ptr) { return (ptr->field_input_name() == field_name); });
103  if ( it == od_vec.end() ) {
104  od_vec.push_back( std::make_shared< ElementDataCache<T> >(field_name, n_rows*n_cols, size) );
105  it=--od_vec.end();
106  }
107  return dynamic_cast<ElementDataCache<T> &>(*(*it));
108 }
109 
110 #endif
ElementDataCache< T > & prepare_compute_data(std::string field_name, DiscreteSpace space_type, unsigned int n_rows, unsigned int n_cols)
Classes for auxiliary output mesh.
std::shared_ptr< OutputMeshBase > output_mesh_
Output mesh.
Definition: output_time.hh:312
std::shared_ptr< ElementDataCacheBase > OutputDataPtr
Definition: output_time.hh:122
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:346
Class OutputElement and its iterator OutputElementIterator on the output mesh.
OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES]
Definition: output_time.hh:268