Skip to content
Snippets Groups Projects
Commit 9ec7fc19 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add OutputNamedItemValueSet mechanism

This allows to create lists of heterogeneous ItemValue associated to a unique
name. It aims at defining post-processed data.
parent b1cbee37
No related branches found
No related tags found
1 merge request!10Feature/data output
...@@ -120,7 +120,9 @@ int main(int argc, char *argv[]) ...@@ -120,7 +120,9 @@ int main(int argc, char *argv[])
VTKWriter vtk_writer("mesh", 0.01); VTKWriter vtk_writer("mesh", 0.01);
while((t<tmax) and (iteration<itermax)) { while((t<tmax) and (iteration<itermax)) {
vtk_writer.write(mesh, t); vtk_writer.write(mesh, {NamedItemValue{"density", rhoj},
NamedItemValue{"velocity", unknowns.uj()},
NamedItemValue{"coords", mesh.xr()}}, t);
double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj); double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj);
if (t+dt>tmax) { if (t+dt>tmax) {
dt=tmax-t; dt=tmax-t;
...@@ -132,7 +134,9 @@ int main(int argc, char *argv[]) ...@@ -132,7 +134,9 @@ int main(int argc, char *argv[])
t += dt; t += dt;
++iteration; ++iteration;
} }
vtk_writer.write(mesh, t, true); // forces last output vtk_writer.write(mesh, {NamedItemValue{"density", rhoj},
NamedItemValue{"velocity", unknowns.uj()},
NamedItemValue{"coords", mesh.xr()}}, t, true); // forces last output
pout() << "* " << rang::style::underline << "Final time" << rang::style::reset pout() << "* " << rang::style::underline << "Final time" << rang::style::reset
<< ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n"; << ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n";
...@@ -227,7 +231,9 @@ int main(int argc, char *argv[]) ...@@ -227,7 +231,9 @@ int main(int argc, char *argv[])
VTKWriter vtk_writer("mesh", 0.01); VTKWriter vtk_writer("mesh", 0.01);
while((t<tmax) and (iteration<itermax)) { while((t<tmax) and (iteration<itermax)) {
vtk_writer.write(mesh, t); vtk_writer.write(mesh, {NamedItemValue{"density", rhoj},
NamedItemValue{"velocity", unknowns.uj()},
NamedItemValue{"coords", mesh.xr()}}, t);
double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj); double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj);
if (t+dt>tmax) { if (t+dt>tmax) {
dt=tmax-t; dt=tmax-t;
...@@ -239,7 +245,9 @@ int main(int argc, char *argv[]) ...@@ -239,7 +245,9 @@ int main(int argc, char *argv[])
t += dt; t += dt;
++iteration; ++iteration;
} }
vtk_writer.write(mesh, t, true); // forces last output vtk_writer.write(mesh, {NamedItemValue{"density", rhoj},
NamedItemValue{"velocity", unknowns.uj()},
NamedItemValue{"coords", mesh.xr()}}, t, true); // forces last output
pout() << "* " << rang::style::underline << "Final time" << rang::style::reset pout() << "* " << rang::style::underline << "Final time" << rang::style::reset
<< ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n"; << ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n";
...@@ -323,7 +331,9 @@ int main(int argc, char *argv[]) ...@@ -323,7 +331,9 @@ int main(int argc, char *argv[])
VTKWriter vtk_writer("mesh", 0.01); VTKWriter vtk_writer("mesh", 0.01);
while((t<tmax) and (iteration<itermax)) { while((t<tmax) and (iteration<itermax)) {
vtk_writer.write(mesh, t); vtk_writer.write(mesh, {NamedItemValue{"density", rhoj},
NamedItemValue{"velocity", unknowns.uj()},
NamedItemValue{"coords", mesh.xr()}}, t);
double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj); double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj);
if (t+dt>tmax) { if (t+dt>tmax) {
dt=tmax-t; dt=tmax-t;
...@@ -334,7 +344,9 @@ int main(int argc, char *argv[]) ...@@ -334,7 +344,9 @@ int main(int argc, char *argv[])
t += dt; t += dt;
++iteration; ++iteration;
} }
vtk_writer.write(mesh, t, true); // forces last output vtk_writer.write(mesh, {NamedItemValue{"density", rhoj},
NamedItemValue{"velocity", unknowns.uj()},
NamedItemValue{"coords", mesh.xr()}}, t, true); // forces last output
pout() << "* " << rang::style::underline << "Final time" << rang::style::reset pout() << "* " << rang::style::underline << "Final time" << rang::style::reset
<< ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n"; << ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n";
......
#ifndef OUTPUT_NAMED_ITEM_VALUE_SET_HPP
#define OUTPUT_NAMED_ITEM_VALUE_SET_HPP
#include <ItemValue.hpp>
#include <TinyVector.hpp>
#include <TinyMatrix.hpp>
#include <variant>
#include <map>
#include <string>
template <typename DataType,
ItemType item_type>
class NamedItemValue
{
private:
std::string m_name;
ItemValue<const DataType,item_type> m_item_value;
public:
constexpr const std::string& name() const
{
return m_name;
}
constexpr const ItemValue<const DataType,item_type>& itemValue() const
{
return m_item_value;
}
NamedItemValue& operator=(const NamedItemValue&) = default;
NamedItemValue& operator=(NamedItemValue&&) = default;
NamedItemValue(const std::string& name, const ItemValue<DataType,item_type>& item_value)
: m_name(name),
m_item_value(item_value)
{
;
}
NamedItemValue(const std::string& name, const ItemValue<const DataType,item_type>& item_value)
: m_name(name),
m_item_value(item_value)
{
;
}
NamedItemValue(const NamedItemValue&) = default;
NamedItemValue(NamedItemValue&&) = default;
~NamedItemValue() = default;
};
class OutputNamedItemValueSet
{
public:
using ItemValueVariant = std::variant<NodeValue<const int>,
NodeValue<const long int>,
NodeValue<const double>,
NodeValue<const TinyVector<1,double>>,
NodeValue<const TinyVector<2,double>>,
NodeValue<const TinyVector<3,double>>,
CellValue<const int>,
CellValue<const long int>,
CellValue<const double>,
CellValue<const TinyVector<1,double>>,
CellValue<const TinyVector<2,double>>,
CellValue<const TinyVector<3,double>>
>;
private:
std::map<std::string, ItemValueVariant> m_name_itemvariant_map;
template <typename DataType,
ItemType item_type>
PASTIS_FORCEINLINE
constexpr void _doInsert(const NamedItemValue<DataType, item_type>& named_itemvalue)
{
if (m_name_itemvariant_map.find(named_itemvalue.name()) == m_name_itemvariant_map.end()) {
m_name_itemvariant_map[named_itemvalue.name()] = named_itemvalue.itemValue();
}
}
template <typename DataType,
ItemType item_type,
typename... Args>
PASTIS_FORCEINLINE
constexpr void _unpackVariadicInput(const NamedItemValue<DataType, item_type>& named_itemvalue,
Args&&... args)
{
_doInsert(named_itemvalue);
if constexpr (sizeof...(args) > 0) {
this->_unpackVariadicInput(std::forward<Args>(args)...);
}
}
public:
auto begin() const
{
return m_name_itemvariant_map.begin();
}
auto end() const
{
return m_name_itemvariant_map.end();
}
template <typename ...DataType,
ItemType ...item_type>
OutputNamedItemValueSet(NamedItemValue<DataType, item_type>... named_itemvalue)
{
_unpackVariadicInput(named_itemvalue...);
}
OutputNamedItemValueSet(const OutputNamedItemValueSet&) = default;
OutputNamedItemValueSet() = default;
~OutputNamedItemValueSet() = default;
};
#endif // OUTPUT_NAMED_ITEM_VALUE_SET_HPP
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <IConnectivity.hpp> #include <IConnectivity.hpp>
#include <ItemValue.hpp> #include <ItemValue.hpp>
#include <OutputNamedItemValueSet.hpp>
class VTKWriter class VTKWriter
{ {
...@@ -21,6 +22,7 @@ class VTKWriter ...@@ -21,6 +22,7 @@ class VTKWriter
public: public:
template <typename MeshType> template <typename MeshType>
void write(const MeshType& mesh, void write(const MeshType& mesh,
const OutputNamedItemValueSet& output_named_item_value_set,
const double& time, const double& time,
const bool& forced_output = false) const bool& forced_output = false)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment