27 auto& ogs_version_field = *MeshLib::getOrCreateMeshProperty<char>(
37 std::vector<GlobalVector*>
const& x,
38 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_tables,
40 std::string
const& output_name,
43 DBUG(
" secondary variable {:s}", output_name);
45 auto& nodal_values_mesh = *MeshLib::getOrCreateMeshProperty<double>(
48 if (nodal_values_mesh.size() !=
52 "Nodal property `{:s}' does not have the right number of "
53 "components. Expected: {:d}, actual: {:d}",
56 nodal_values_mesh.size());
59 std::unique_ptr<GlobalVector> result_cache;
60 auto const& nodal_values =
64 std::size_t
const global_vector_size =
65 nodal_values.getLocalSize() + nodal_values.getGhostSize();
67 std::size_t
const global_vector_size = nodal_values.size();
69 if (nodal_values_mesh.size() != global_vector_size)
72 "Secondary variable `{:s}' did not evaluate to the right number of "
73 "components. Expected: {:d}, actual: {:d}.",
74 var.
name, nodal_values_mesh.size(), global_vector_size);
78 nodal_values.copyValues(nodal_values_mesh);
83 std::vector<GlobalVector*>
const& x,
84 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_table,
86 std::string
const& output_name,
94 DBUG(
" secondary variable {:s} residual", output_name);
95 auto const& property_name_res = output_name +
"_residual";
97 auto& residuals_mesh = *MeshLib::getOrCreateMeshProperty<double>(
100 if (residuals_mesh.size() !=
104 "Cell property `{:s}' does not have the right number of "
105 "components. Expected: {:d}, actual: {:d}",
108 residuals_mesh.size());
111 std::unique_ptr<GlobalVector> result_cache;
112 auto const& residuals =
115 std::size_t
const global_vector_size =
116 residuals.getLocalSize() + residuals.getGhostSize();
118 std::size_t
const global_vector_size = residuals.size();
120 if (residuals_mesh.size() != global_vector_size)
123 "The residual of secondary variable `{:s}' did not evaluate to the "
124 "right number of components. Expected: {:d}, actual: {:d}.",
125 var.
name, residuals_mesh.size(), global_vector_size);
129 residuals.copyValues(residuals_mesh);
134 std::vector<double> x_copy;
146 if (&bulk_mesh_dof_table != &dof_table)
148 auto const bulk_id_string =
150 if (!mesh.getProperties().existsPropertyVector<std::size_t>(
154 "The required bulk node ids map does not exist in "
155 "the boundary mesh '{:s}' or has the wrong data "
156 "type (should be equivalent to C++ data type "
157 "std::size_t which is an unsigned integer of size "
158 "{:d} or UInt64 in vtk terminology).",
159 mesh.getName(),
sizeof(std::size_t));
161 return mesh.getProperties().getPropertyVector<std::size_t>(
170 std::size_t
const mesh_id, std::size_t
const node_id,
171 [[maybe_unused]]
bool const is_ghost_node,
int const global_component_id,
178 if (is_ghost_node && &bulk_mesh_dof_table != &dof_table)
180 auto const bulk_node_id = (*bulk_node_id_map)[node_id];
181 std::size_t
const bulk_mesh_id = 0;
187 return bulk_mesh_dof_table.getLocalIndex(
199 [[maybe_unused]] std::size_t
const node_id)
241 std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
const&
243 std::set<std::string>
const& output_variables,
253 "The d.o.f. table for the passed mesh must have the same number of "
254 "variables and global components as the d.o.f. table for the full "
255 "simulation domain. But the values differ: {} != {} (variables) or "
256 "{} != {} (global components).",
265 if (number_of_dof_variables !=
static_cast<int>(process_variables.size()))
268 "The number of variables in the d.o.f. table differs from the "
269 "number of primary variables of the process {} != {}.",
270 number_of_dof_variables, process_variables.size());
274 std::set<std::string> names_of_already_output_variables;
276 int global_component_offset_next = 0;
279 mesh, dof_table, bulk_mesh_dof_table);
281 for (
int variable_id = 0; variable_id < number_of_dof_variables;
284 auto const& pv = process_variables[variable_id].get();
285 auto const n_components = pv.getNumberOfGlobalComponents();
289 int global_component_offset = global_component_offset_next;
290 global_component_offset_next += n_components;
292 if (!output_variables.empty() &&
293 !output_variables.contains(pv.getName()))
298 names_of_already_output_variables.insert(pv.getName());
300 DBUG(
" process variable {:s}", pv.getName());
302 auto& output_data = *MeshLib::getOrCreateMeshProperty<double>(
306 int const dummy_component_id = 0;
307 auto const& mesh_subset =
309 auto const mesh_id = mesh_subset.
getMeshID();
311 for (
auto const* node : mesh_subset.getNodes())
313 auto const node_id = node->getID();
314 auto const is_ghost_node =
isGhostNode(mesh, node_id);
316 for (
int component_id = 0; component_id < n_components;
319 auto const global_component_id =
320 global_component_offset + component_id;
323 mesh_id, node_id, is_ghost_node, global_component_id, x,
324 dof_table, bulk_mesh_dof_table, bulk_node_id_map);
327 auto const out_index = node_id * n_components + component_id;
329 output_data[out_index] = x_copy[in_index];
334 return names_of_already_output_variables;
339 std::set<std::string>& names_of_already_output_variables,
const double t,
341 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_tables,
342 bool const output_residuals)
344 for (
auto const& external_variable_name : secondary_variables)
346 auto const& name = external_variable_name.first;
347 if (!names_of_already_output_variables.insert(name).second)
354 secondary_variables.
get(name), name, mesh);
356 if (output_residuals)
359 t, xs, dof_tables, secondary_variables.
get(name), name, mesh);
367 std::vector<GlobalVector*>
const& xs,
368 int const process_id,
370 bool const output_secondary_variables,
373 DBUG(
"Process output data.");
375 auto const& pod = process_output_data;
377 auto const& secondary_variables = pod.getSecondaryVariables();
378 auto const*
const integration_point_writers =
379 pod.getIntegrationPointWriters();
380 auto const& bulk_mesh_dof_table = pod.getBulkMeshDofTable(process_id);
381 auto const& output_mesh_dof_table = pod.getOutputMeshDofTable(process_id);
382 auto& output_mesh = pod.getOutputMesh();
389 output_mesh, *xs[process_id], process_variables, output_variables,
390 output_mesh_dof_table, bulk_mesh_dof_table);
392 if (output_secondary_variables)
394 auto const& output_mesh_dof_tables =
395 pod.getOutputMeshDofTablesOfAllProcesses();
398 names_of_already_output_variables, t, xs,
399 output_mesh, output_mesh_dof_tables,
403 if (integration_point_writers)
405 addIntegrationPointDataToMesh(output_mesh, *integration_point_writers);
static std::vector< double > copySolutionVector(GlobalVector const &x)
static void addSecondaryVariableResiduals(double const t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, ProcessLib::SecondaryVariable const &var, std::string const &output_name, MeshLib::Mesh &mesh)
static GlobalIndexType getIndexForComponentInSolutionVector(std::size_t const mesh_id, std::size_t const node_id, bool const is_ghost_node, int const global_component_id, GlobalVector const &x, NumLib::LocalToGlobalIndexMap const &dof_table, NumLib::LocalToGlobalIndexMap const &bulk_mesh_dof_table, MeshLib::PropertyVector< std::size_t > const *const bulk_node_id_map)
MeshLib::PropertyVector< std::size_t > const * getBulkNodeIdMapForPetscIfNecessary(MeshLib::Mesh const &mesh, NumLib::LocalToGlobalIndexMap const &dof_table, NumLib::LocalToGlobalIndexMap const &bulk_mesh_dof_table)
static std::set< std::string > addPrimaryVariablesToMesh(MeshLib::Mesh &mesh, GlobalVector const &x, std::vector< std::reference_wrapper< ProcessLib::ProcessVariable > > const &process_variables, std::set< std::string > const &output_variables, NumLib::LocalToGlobalIndexMap const &dof_table, NumLib::LocalToGlobalIndexMap const &bulk_mesh_dof_table)
static void addSecondaryVariableNodes(double const t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, ProcessLib::SecondaryVariable const &var, std::string const &output_name, MeshLib::Mesh &mesh)
static void addSecondaryVariablesToMesh(ProcessLib::SecondaryVariableCollection const &secondary_variables, std::set< std::string > &names_of_already_output_variables, const double t, std::vector< GlobalVector * > const &xs, MeshLib::Mesh &mesh, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, bool const output_residuals)
static bool isGhostNode(MeshLib::Mesh const &mesh, std::size_t const node_id)
static void addOgsVersion(MeshLib::Mesh &mesh)
GlobalMatrix::IndexType GlobalIndexType
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition of mesh class for partitioned mesh (by node) for parallel computing within the framework o...
Global vector based on Eigen vector.
IndexType getRangeEnd() const
return an end index of the active data range
void copyValues(std::vector< double > &u) const
static constexpr IndexType getRangeBegin()
return a start index of the active data range
std::size_t getMeshID() const
return this mesh ID
const std::string getName() const
Get name of the mesh.
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::size_t getNumberOfElements() const
Get the number of elements.
int getNumberOfVariables() const
MeshLib::MeshSubset const & getMeshSubset(int const variable_id, int const component_id) const
GlobalIndexType getLocalIndex(MeshLib::Location const &l, std::size_t const comp_id, std::size_t const range_begin, std::size_t const range_end) const
int getNumberOfGlobalComponents() const
Holds all data of a process that are needed for output.
std::vector< std::reference_wrapper< ProcessVariable > > const & getProcessVariables(int const process_id) const
Handles configuration of several secondary variables from the project file.
SecondaryVariable const & get(std::string const &external_name) const
Returns the secondary variable with the given external name.
const std::string OGS_VERSION
GITINFOLIB_EXPORT const std::string ogs_version
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)
Holds information about which variables to write to output files.
bool output_residuals
Tells if also to output extrapolation residuals.
std::set< std::string > output_variables
All variables that shall be output.
Function const eval_field
Computes the value of the field at every node of the underlying mesh.
const unsigned num_components
Number of components of the variable.
Function const eval_residuals
Stores information about a specific secondary variable.
SecondaryVariableFunctions fcts
Functions used for computing the secondary variable.
std::string const name
Name of the variable; used, e.g., for output.