OGS
SetIPDataInitialConditions.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "BaseLib/Error.h"
14#include "MeshLib/Properties.h"
16
17namespace ProcessLib
18{
20inline std::string removeIPFieldDataNameSuffix(std::string const& name)
21{
22 if (!name.ends_with("_ip"))
23 {
25 "The name of integration point data must end with '_ip'. '{}' "
26 "does not.",
27 name);
28 }
29
30 return name.substr(0, name.size() - 3);
31}
32
33template <typename LocalAssemblersVector>
35 std::vector<std::unique_ptr<MeshLib::IntegrationPointWriter>> const&
36 _integration_point_writer,
37 MeshLib::Properties const& mesh_properties,
38 LocalAssemblersVector& local_assemblers,
39 bool const remove_name_suffix = false)
40{
41 for (auto const& ip_writer : _integration_point_writer)
42 {
43 // Find the mesh property with integration point writer's name.
44 auto const& name = ip_writer->name();
45 if (!mesh_properties.existsPropertyVector<double>(name))
46 {
47 continue;
48 }
49 auto const& mesh_property =
50 *mesh_properties.template getPropertyVector<double>(name);
51
52 // The mesh property must be defined on integration points.
53 if (mesh_property.getMeshItemType() !=
55 {
56 continue;
57 }
58
59 auto const ip_meta_data =
60 getIntegrationPointMetaData(mesh_properties, name);
61
62 // Check the number of components.
63 if (ip_meta_data.n_components !=
64 mesh_property.getNumberOfGlobalComponents())
65 {
67 "Different number of components in meta data ({:d}) than in "
68 "the integration point field data for '{:s}': {:d}.",
69 ip_meta_data.n_components, name,
70 mesh_property.getNumberOfGlobalComponents());
71 }
72
73 INFO("Setting initial integration point data for '{}'", name);
74
75 auto const& name_transformed =
76 remove_name_suffix ? removeIPFieldDataNameSuffix(name) : name;
77
78 // Now we have a properly named vtk's field data array and the
79 // corresponding meta data.
80 std::size_t position = 0;
81 for (auto& local_asm : local_assemblers)
82 {
83 std::size_t const integration_points_read =
84 local_asm->setIPDataInitialConditions(
85 name_transformed, &mesh_property[position],
86 ip_meta_data.integration_order);
87 // The number of read integration points could be zero in case there
88 // are e.g. multiple materials with different sets of internal state
89 // variables.
90
91 position += integration_points_read * ip_meta_data.n_components;
92 }
93 }
94}
95} // namespace ProcessLib
#define OGS_FATAL(...)
Definition: Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:35
Definition of the class Properties that implements a container of properties.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition: Properties.h:36
bool existsPropertyVector(std::string_view name) const
void setIPDataInitialConditions(std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > const &_integration_point_writer, MeshLib::Properties const &mesh_properties, LocalAssemblersVector &local_assemblers, bool const remove_name_suffix=false)
std::string removeIPFieldDataNameSuffix(std::string const &name)
Removes the suffix '_ip' from the passed field name.