OGS
SetIPDataInitialConditions.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <string_view>
14
15#include "BaseLib/Error.h"
16#include "MeshLib/Properties.h"
18
19namespace ProcessLib
20{
22inline std::string_view removeIPFieldDataNameSuffix(std::string_view const name)
23{
24 if (!name.ends_with("_ip"))
25 {
27 "The name of integration point data must end with '_ip'. '{}' "
28 "does not.",
29 name);
30 }
31
32 return {name.data(), name.size() - 3};
33}
34
35template <typename LocalAssemblersVector>
37 std::vector<std::unique_ptr<MeshLib::IntegrationPointWriter>> const&
38 _integration_point_writer,
39 MeshLib::Properties const& mesh_properties,
40 LocalAssemblersVector& local_assemblers)
41{
42 for (auto const& ip_writer : _integration_point_writer)
43 {
44 // Find the mesh property with integration point writer's name.
45 auto const& name = ip_writer->name();
46 if (!mesh_properties.existsPropertyVector<double>(name))
47 {
48 continue;
49 }
50 auto const& mesh_property =
51 *mesh_properties.template getPropertyVector<double>(name);
52
53 // The mesh property must be defined on integration points.
54 if (mesh_property.getMeshItemType() !=
56 {
57 continue;
58 }
59
60 auto const ip_meta_data =
61 getIntegrationPointMetaData(mesh_properties, name);
62
63 // Check the number of components.
64 if (ip_meta_data.n_components !=
65 mesh_property.getNumberOfGlobalComponents())
66 {
68 "Different number of components in meta data ({:d}) than in "
69 "the integration point field data for '{:s}': {:d}.",
70 ip_meta_data.n_components, name,
71 mesh_property.getNumberOfGlobalComponents());
72 }
73
74 INFO("Setting initial integration point data for '{}'", name);
75
76 auto const name_transformed = removeIPFieldDataNameSuffix(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
Definition Properties.h:74
std::string_view removeIPFieldDataNameSuffix(std::string_view const name)
Removes the suffix '_ip' from the passed field name.
void setIPDataInitialConditions(std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > const &_integration_point_writer, MeshLib::Properties const &mesh_properties, LocalAssemblersVector &local_assemblers)