16#include <range/v3/algorithm/transform.hpp>
17#include <range/v3/range/conversion.hpp>
32 std::string
const& property_name)
34 if (bulk_mesh == sub_mesh)
40 std::string_view(property_name)))
44 auto const& bulk_mesh_property =
46 std::string_view(property_name));
49 std::string_view mesh_item_type_string =
50 [mesh_item_type, &property_name]() -> std::string_view
52 switch (mesh_item_type)
62 "Property '{}' is assigned to edges. But mappings from the "
63 "bulk edges to submesh edges isn't implemented. Mesh item "
64 "type 'Edge' is not supported, only 'Node' and 'Cell' are "
65 "implemented at the moment.",
71 "Property '{}' is assigned to faces. But mappings from the "
72 "bulk faces to submesh faces isn't implemented. Mesh item "
73 "type 'Face' is not supported, only 'Node' and 'Cell' are "
74 "implemented at the moment.",
80 "Property '{}' is assigned to integration points. But "
81 "mappings from the bulk integration points to submesh "
82 "integration points isn't implemented. Mesh item type "
83 "'IntegrationPoint' is not supported, only 'Node' and "
84 "'Cell' are implemented at the moment.",
90 static_cast<int>(mesh_item_type));
95 if (mesh_item_type_string.empty())
100 mesh_item_type_string, mesh_item_type, 1))
103 "The property {} is required for output on the mesh {}, but it "
105 mesh_item_type_string, sub_mesh.
getName());
109 auto const& bulk_ids =
111 mesh_item_type_string);
113 auto const number_of_components =
115 auto& sub_mesh_property = *MeshLib::getOrCreateMeshProperty<double>(
116 sub_mesh, property_name, mesh_item_type, number_of_components);
118 for (std::size_t sub_mesh_node_id = 0;
119 sub_mesh_node_id < bulk_ids.getNumberOfTuples();
122 auto const& bulk_id = bulk_ids[sub_mesh_node_id];
123 for (std::remove_cv_t<
decltype(number_of_components)> c = 0;
124 c < number_of_components;
127 sub_mesh_property.getComponent(sub_mesh_node_id, c) =
128 bulk_mesh_property.getComponent(bulk_id, c);
135 auto const is_last_process =
146 bool const output_nonlinear_iteration_results,
148 std::vector<std::string>&& mesh_names_for_output,
149 std::vector<std::unique_ptr<MeshLib::Mesh>>
const& meshes)
150 : _output_format(std::move(output_format)),
151 _output_nonlinear_iteration_results(output_nonlinear_iteration_results),
152 _output_data_specification(std::move(output_data_specification)),
153 _mesh_names_for_output(std::move(mesh_names_for_output)),
168 std::string
const& property_name,
176 const int timestep,
const double t,
const int iteration,
177 std::vector<std::reference_wrapper<const MeshLib::Mesh>>
const& meshes)
183 for (
auto const& mesh : meshes)
185 for (
auto [name, property] : mesh.get().getProperties())
187 property->is_for_output =
true;
193 for (
auto const& mesh : meshes)
195 for (
auto [name, property] : mesh.get().getProperties())
198 if (name ==
"OGS_VERSION")
200 property->is_for_output =
true;
204 property->is_for_output =
214 std::string
const& submesh_output_name,
Process const& process,
215 const int process_id,
double const t,
216 std::vector<GlobalVector*>
const& xs)
const
220 [&submesh_output_name](
auto const& m)
221 { return m->getName() == submesh_output_name; },
222 "Need mesh '" + submesh_output_name +
"' for the output.");
224 DBUG(
"Found {:d} nodes for output at mesh '{:s}'.",
225 submesh.getNumberOfNodes(), submesh.getName());
227 bool const output_secondary_variables =
false;
232 auto const process_output_data =
236 output_secondary_variables,
239 auto const& bulk_mesh = process.
getMesh();
240 auto const& property_names =
248 auto is_residuum_field = [](std::string
const& name) ->
bool
250 using namespace std::literals::string_view_literals;
251 static constexpr std::string_view endings[] = {
252 "FlowRate"sv,
"heat_flux"sv,
"MaterialForces"sv,
"NodalForces"sv,
253 "NodalForcesJump"sv};
254 auto ends_with = [&](std::string_view
const& ending)
255 {
return name.ends_with(ending); };
256 return std::find_if(std::begin(endings), std::end(endings),
257 ends_with) != std::end(endings);
260 for (
auto const& name : property_names)
263 {name, MeshLib::MeshItemType::Node}))
270 if (bulk_mesh.getDimension() == submesh.getDimension())
275 if (is_residuum_field(name))
292 const int process_id,
296 std::vector<GlobalVector*>
const& xs)
const
301 bool const output_secondary_variables =
true;
302 auto const process_output_data =
307 output_secondary_variables,
315 std::vector<std::reference_wrapper<const MeshLib::Mesh>> output_meshes;
321 output_meshes.emplace_back(process.
getMesh());
326 auto const& submesh =
328 output_meshes.emplace_back(submesh);
332 outputMeshes(timestep, t, iteration, std::move(output_meshes));
334 INFO(
"[time] Output of timestep {:d} took {:g} s.", timestep,
339 const int process_id,
343 std::vector<GlobalVector*>
const& xs)
const
358 const int process_id,
362 std::vector<GlobalVector*>
const& xs)
const
375 Process const& process,
const int process_id,
int const timestep,
376 const double t,
int const iteration,
377 std::vector<GlobalVector*>
const& xs)
const
387 bool const output_secondary_variable =
true;
388 auto const process_output_data =
399 std::string
const output_file_name =
_output_format->constructFilename(
402 std::string
const output_file_path =
405 DBUG(
"output iteration results to {:s}", output_file_path);
415 DBUG(
"non-linear iterations can only written in Vtk/VTU format.");
417 INFO(
"[time] Output took {:g} s.", time_output.
elapsed());
427 auto construct_filename = ranges::views::transform(
428 [&](
auto const& output_name)
429 {
return _output_format->constructFilename(output_name, 0, 0, 0); });
432 ranges::to<std::vector>;
436 std::vector<Output>
const& outputs)
438 std::vector<double> fixed_times;
439 for (
auto const& output : outputs)
441 auto const& output_fixed_times = output.getFixedOutputTimes();
442 fixed_times.insert(fixed_times.end(), output_fixed_times.begin(),
443 output_fixed_times.end());
451 os <<
"Output::_output_data_specification:\t"
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the RunTime class.
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
Properties & getProperties()
const std::string getName() const
Get name of the mesh.
std::vector< std::string > getPropertyVectorNames() const
bool existsPropertyVector(std::string_view name) const
PropertyVector< T > const * getPropertyVector(std::string_view name) const
MeshItemType getMeshItemType() const
int getNumberOfGlobalComponents() const
std::set< std::pair< std::string, MeshLib::MeshItemType > > _do_not_project_from_bulk_mesh_to_submeshes
std::reference_wrapper< std::vector< std::unique_ptr< MeshLib::Mesh > > const > _meshes
void doOutputLastTimestep(Process const &process, const int process_id, int const timestep, const double t, int const iteration, std::vector< GlobalVector * > const &xs) const
std::vector< std::string > _mesh_names_for_output
MeshLib::Mesh const & prepareSubmesh(std::string const &submesh_output_name, Process const &process, const int process_id, double const t, std::vector< GlobalVector * > const &xs) const
void doOutput(Process const &process, const int process_id, int const timestep, const double t, int const iteration, std::vector< GlobalVector * > const &xs) const
void doNotProjectFromBulkMeshToSubmeshes(std::string const &property_name, MeshLib::MeshItemType const mesh_item_type)
OutputDataSpecification _output_data_specification
void doOutputNonlinearIteration(Process const &process, const int process_id, int const timestep, const double t, const int iteration, std::vector< GlobalVector * > const &xs) const
std::vector< std::reference_wrapper< Process const > > _output_processes
Output(std::unique_ptr< OutputFormat > &&output_format, bool const output_nonlinear_iteration_results, OutputDataSpecification &&output_data_specification, std::vector< std::string > &&mesh_names_for_output, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes)
bool isOutputProcess(int const process_id, Process const &process) const
bool isOutputStep(int const timestep, double const t) const
Tells if output will be written at the specified timestep/time.
std::unique_ptr< OutputFormat > _output_format
void outputMeshes(int const timestep, const double t, int const iteration, std::vector< std::reference_wrapper< const MeshLib::Mesh > > const &meshes) const
void addProcess(ProcessLib::Process const &process)
TODO doc. Opens a PVD file for each process.
bool _output_nonlinear_iteration_results
std::vector< std::string > getFileNamesForOutput() const
void doOutputAlways(Process const &process, const int process_id, int const timestep, const double t, int const iteration, std::vector< GlobalVector * > const &xs) const
MeshLib::Mesh & getMesh() const
virtual bool isMonolithicSchemeUsed() const
std::iterator_traits< InputIt >::reference findElementOrError(InputIt begin, InputIt end, Predicate predicate, std::string const &error="")
std::string joinPaths(std::string const &pathA, std::string const &pathB)
void makeVectorUnique(std::vector< T > &v)
void CoProcess(MeshLib::Mesh const &mesh, double const time, unsigned int const timeStep, bool const lastTimeStep, std::string output_directory)
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
void addProcessDataToMesh(const double t, std::vector< GlobalVector * > const &xs, int const process_id, ProcessOutputData const &process_output_data, bool const output_secondary_variables, OutputDataSpecification const &process_output)
ProcessOutputData createProcessOutputData(Process const &process, std::size_t const n_processes, MeshLib::Mesh &output_mesh)
Extracts data necessary for output from the given process.
std::ostream & operator<<(std::ostream &os, Output const &output)
void outputMeshVtk(std::string const &file_name, MeshLib::Mesh const &mesh, bool const compress_output, int const data_mode)
std::vector< double > calculateUniqueFixedTimesForAllOutputs(std::vector< Output > const &outputs)
void addBulkMeshPropertyToSubMesh(MeshLib::Mesh const &bulk_mesh, MeshLib::Mesh &sub_mesh, std::string const &property_name)
Holds information about which variables to write to output files.
std::set< std::string > output_variables
All variables that shall be output.
bool isOutputStep(int timestep, double const time) const