Flow123d  release_3.0.0-684-g928e266
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  size = this->nodes_->n_values();
87  break;
88  case ELEM_DATA:
89  case NATIVE_DATA:
90  size = this->offsets_->n_values();
91  break;
92  default:
93  ASSERT(false).error("Should not happen.");
94  break;
95  }
96 
97  auto &od_vec=this->output_data_vec_[space_type];
98  auto it=std::find_if(od_vec.begin(), od_vec.end(),
99  [&field_name](OutputDataPtr ptr) { return (ptr->field_input_name() == field_name); });
100  if ( it == od_vec.end() ) {
101  od_vec.push_back( std::make_shared< ElementDataCache<T> >(field_name, n_rows, n_cols, size) );
102  it=--od_vec.end();
103  }
104  return dynamic_cast<ElementDataCache<T> &>(*(*it));
105 }
106 
107 #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< ElementDataCache< unsigned int > > offsets_
Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
Definition: output_time.hh:312
std::shared_ptr< ElementDataCacheBase > OutputDataPtr
Definition: output_time.hh:122
std::shared_ptr< ElementDataCache< double > > nodes_
Vector of node coordinates. [spacedim x n_nodes].
Definition: output_time.hh:308
#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:250