PRISMS-PF Manual
Loading...
Searching...
No Matches
solve_group.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#include <deal.II/matrix_free/evaluation_flags.h>
8
11#include <prismspf/core/types.h>
12
13#include <prismspf/config.h>
14
15#include <set>
16#include <string>
17#include <vector>
18
20
51
52// NOLINTBEGIN(misc-non-private-member-variables-in-classes, hicpp-explicit-conversions)
53// readability-simplify-boolean-expr
54
59{
60public:
61 using EvalFlags = dealii::EvaluationFlags::EvaluationFlags;
63
77
82 int id;
83
88
94
98 std::set<Types::Index> field_indices;
99
108
113 std::vector<SolveGroup> aux_solve_container;
114
115 [[nodiscard]] bool
117 {
118 return !aux_solve_container.empty();
119 }
120
121 bool
122 operator<(const SolveGroup &other) const
123 {
124 return id < other.id;
125 }
126
127 void
128 validate() const
129 {
133 dealii::ExcMessage(
134 "A valid solve type must be selected (Constant | Explicit | Linear | Newton)\n"));
135 AssertThrow(!field_indices.empty(),
136 dealii::ExcMessage("This solve group must manage at least 1 field.\n"));
138 {
139 for (unsigned int field_index : field_indices)
140 {
141 const auto &dep_it_rhs = dependencies_rhs.find(field_index);
143 dealii::ExcMessage("Every field in a newton solve should appear "
144 "in the residual (RHS) expression.\n"));
145 AssertThrow(dep_it_rhs->second.flag != EvalFlags::nothing,
146 dealii::ExcMessage("Every field in a newton solve should appear "
147 "in the residual (RHS) expression.\n"));
148 const auto &dep_it_lhs = dependencies_lhs.find(field_index);
150 dealii::ExcMessage(
151 "Every field in a newton solve should appear as a Delta term"
152 "in the residual Jacobian (LHS) expression.\n"));
153 AssertThrow(dep_it_lhs->second.src_flag != EvalFlags::nothing,
154 dealii::ExcMessage(
155 "Every field in a newton solve should appear as a Delta term"
156 "in the residual Jacobian (LHS) expression.\n"));
157 }
158 }
159 else if (solve_type == SolveType::Linear)
160 {
161 for (unsigned int field_index : field_indices)
162 {
163 const auto &dep_it_lhs = dependencies_lhs.find(field_index);
165 dealii::ExcMessage(
166 "Every field in a linear solve should appear "
167 "in the (LHS) expression. Be sure to use the src_flag.\n"));
168 AssertThrow(dep_it_lhs->second.src_flag != EvalFlags::nothing,
169 dealii::ExcMessage(
170 "Every field in a linear solve should appear "
171 "in the (LHS) expression. Be sure to use the src_flag.\n"));
172 }
173 }
175 {
177 dealii::ExcMessage("Explicit solves do not have an LHS, "
178 "and should have no LHS dependencies.\n"));
179 }
181 {
183 dealii::ExcMessage("Constant \"solves\" do not have an RHS or LHS, "
184 "and should have no dependencies.\n"));
185 }
186 for (const auto &[field_index, dependency] : dependencies_rhs)
187 {
188 AssertThrow(dependency.src_flag == EvalFlags::nothing,
189 dealii::ExcMessage(
190 "Trial/Change terms should not appear in RHS expressions.\n"));
191 }
192 for (const SolveGroup &aux : aux_solve_container)
193 {
194 aux.validate();
195 }
196 }
197};
198
199// NOLINTEND(misc-non-private-member-variables-in-classes, hicpp-explicit-conversions)
200
Structure to hold the attributes of a solve-group.
Definition solve_group.h:59
SolveGroup(int _id=-1, SolveType _solve_type=Explicit, SolveTiming _solve_timing=Primary, std::set< Types::Index > _field_indices={}, DependencyMap _dependencies_rhs={}, DependencyMap _dependencies_lhs={})
Definition solve_group.h:64
std::vector< SolveGroup > aux_solve_container
Solves that occur inside the parent solve. This is only really meant for implicit solves with higher ...
Definition solve_group.h:113
std::set< Types::Index > field_indices
Indices of the fields to be solved in this group.
Definition solve_group.h:98
DependencyMap dependencies_rhs
Dependencies for the rhs equation(s)
Definition solve_group.h:103
SolveType solve_type
PDE type (Constant | Explicit | Linear | Newton).
Definition solve_group.h:87
void validate() const
Definition solve_group.h:128
dealii::EvaluationFlags::EvaluationFlags EvalFlags
Definition solve_group.h:61
DependencyMap dependencies_lhs
Dependencies for the lhs equation(s)
Definition solve_group.h:107
bool has_auxiliary_solve() const
Definition solve_group.h:116
bool operator<(const SolveGroup &other) const
Definition solve_group.h:122
SolveTiming solve_timing
This is used to determine whether to initialize the solution vector with the initial conditions or ju...
Definition solve_group.h:93
int id
Unique identifier. Use this in 'if' statements or switch cases in equations lhs and rhs.
Definition solve_group.h:82
std::map< Types::Index, Dependency > DependencyMap
Definition dependencies.h:129
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
Definition conditional_ostreams.cc:20
Definition vectorized_operations.h:17
SolveTiming
Enum describing when each group of fields gets solved.
Definition solve_group.h:25
@ Uninitialized
Definition solve_group.h:39
@ Primary
Definition solve_group.h:31
@ NucleationRate
NucleationRate fields are only solved on nucleation attempt and output increments.
Definition solve_group.h:49
@ PostProcess
Definition solve_group.h:44
@ Initialized
Definition solve_group.h:32
@ Secondary
Definition solve_group.h:38
SolveType
Type of PDE that is being solved.
Definition type_enums.h:17
@ Linear
Definition type_enums.h:20
@ Newton
Definition type_enums.h:21
@ Constant
Definition type_enums.h:18
@ Explicit
Definition type_enums.h:19
TensorRank
Tensor rank of the field.
Definition type_enums.h:30