Flow123d  master-f44eb46
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>
79  DiscreteSpace space_type, unsigned int n_rows, unsigned int n_cols, std::string fe_type, unsigned int n_dofs_per_element)
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_data().get() );
88  size = offset_vec[offset_vec.size()-1];
89  break;
90  }
91  case ELEM_DATA:
92  size = output_mesh_->offsets_->n_values()-1;
93  break;
94  case NATIVE_DATA:
95  size = output_mesh_->offsets_->n_values()-1;
96  break;
97  default:
98  ASSERT_PERMANENT(false).error("Should not happen.");
99  break;
100  }
101 
102  /**
103  * supposing that everything is output at the first step !
104  * - if(current_step == 0) push_back all the non-existing fields shared<ElementDataCache<T>>
105  * - else just set the correct shared<ElementDataCache<T>>
106  * - when clearing output_data_vec, set all to shared<DummyElementCache>
107  * - this can be done in many equations sharing the same OutputTime stream
108  *
109  */
110  auto &od_vec=this->output_data_vec_[space_type];
111  auto it=std::find_if(od_vec.begin(), od_vec.end(),
112  [&field_name](OutputDataPtr ptr) { return (ptr->field_input_name() == field_name); });
113 
114  if(current_step == 0 && it == od_vec.end() ) {
115  // DebugOut() << "OutputTime::prepare_compute_data: PUSH BACK " << field_name << "\n";
116  od_vec.push_back( std::make_shared< ElementDataCache<T> >(field_name, n_rows*n_cols, size, fe_type, n_dofs_per_element) );
117  it=--od_vec.end();
118  }
119  else{
120  ASSERT(it != od_vec.end()).error("Try to add non-existing output field after first step.");
121  *it = std::make_shared< ElementDataCache<T> >(field_name, n_rows*n_cols, size, fe_type, n_dofs_per_element);
122  }
123 
124  return *it;
125 }
126 
127 #endif
#define ASSERT(expr)
Definition: asserts.hh:351
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:348
std::shared_ptr< ElementDataCacheBase > OutputDataPtr
Definition: output_time.hh:144
OutputDataPtr prepare_compute_data(std::string field_name, DiscreteSpace space_type, unsigned int n_rows, unsigned int n_cols, std::string fe_type="", unsigned int n_dofs_per_element=1)
int current_step
Definition: output_time.hh:302
std::shared_ptr< OutputMeshBase > output_mesh_
Output mesh.
Definition: output_time.hh:341
OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES]
Definition: output_time.hh:297
Class OutputElement and its iterator OutputElementIterator on the output mesh.
Classes for auxiliary output mesh.