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