PRISMS-PF Manual
Loading...
Searching...
No Matches
field_attributes.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#pragma once
5
6#include <deal.II/base/exceptions.h>
7
10
11#include <prismspf/config.h>
12
13#include <map>
14#include <string>
15#include <vector>
16
18
24{
29 std::string _name = "",
30 TensorRank _field_type = TensorRank::Scalar,
31 bool _is_nucleation_rate_variable = false,
32 std::vector<Types::Index> _nucleating_field_indices = std::vector<Types::Index>())
33 : name(std::move(_name))
34 , field_type(_field_type)
35 , is_nucleation_rate_variable(_is_nucleation_rate_variable)
36 , nucleating_field_indices(std::move(_nucleating_field_indices))
37 {}
38
42 std::string name;
43
48
53
57 std::vector<Types::Index> nucleating_field_indices;
58};
59
63inline std::map<std::string, Types::Index>
64field_index_map(const std::vector<FieldAttributes> &fields)
65{
66 std::map<std::string, Types::Index> map;
67 for (unsigned int i = 0; i < fields.size(); ++i)
68 {
69 AssertThrow(map.find(fields[i].name) == map.end(),
70 dealii::ExcMessage(
71 "The names of the fields are not unique. This is not allowed."));
72 map[fields[i].name] = i;
73 }
74 return map;
75}
76
80inline std::map<std::string, FieldAttributes>
81field_map(const std::vector<FieldAttributes> &fields)
82{
83 std::map<std::string, FieldAttributes> map;
84 for (const FieldAttributes &field : fields)
85 {
86 AssertThrow(map.find(field.name) == map.end(),
87 dealii::ExcMessage(
88 "The names of the fields are not unique. This is not allowed."));
89 map[field.name] = field;
90 }
91 return map;
92}
93
94// TODO: Submit a PR/issue to dealii to make operator| constexpr.
95// constexpr EvalFlags values_and_gradients = EvalFlags::values |
96// EvalFlags::gradients;
97
98PRISMS_PF_END_NAMESPACE
std::map< std::string, Types::Index > field_index_map(const std::vector< FieldAttributes > &fields)
Make a map that maps field names to field indices.
Definition field_attributes.h:64
std::map< std::string, FieldAttributes > field_map(const std::vector< FieldAttributes > &fields)
Make a map that maps field names to field attributes.
Definition field_attributes.h:81
Definition conditional_ostreams.cc:20
Definition vectorized_operations.h:17
Structure to hold the attributes of a field. This includes things like the name, rank,...
Definition field_attributes.h:24
TensorRank field_type
Field type (Scalar/Vector).
Definition field_attributes.h:47
std::vector< Types::Index > nucleating_field_indices
If this is a nucleation rate, the indices of the nucleating fields.
Definition field_attributes.h:57
bool is_nucleation_rate_variable
Is a nucleation rate.
Definition field_attributes.h:52
FieldAttributes(std::string _name="", TensorRank _field_type=TensorRank::Scalar, bool _is_nucleation_rate_variable=false, std::vector< Types::Index > _nucleating_field_indices=std::vector< Types::Index >())
Constructor.
Definition field_attributes.h:28
std::string name
Field name.
Definition field_attributes.h:42
TensorRank
Tensor rank of the field.
Definition type_enums.h:30
@ Scalar
Definition type_enums.h:32