PRISMS-PF Manual
Loading...
Searching...
No Matches
solve_block.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
48
49// NOLINTBEGIN(misc-non-private-member-variables-in-classes, hicpp-explicit-conversions)
50// readability-simplify-boolean-expr
51
56{
57public:
58 using EvalFlags = dealii::EvaluationFlags::EvaluationFlags;
60
61 explicit SolveBlock(int _id = -1,
62 SolveType _solve_type = Explicit,
63 SolveTiming _solve_timing = Primary,
64 std::set<Types::Index> _field_indices = {},
65 DependencyMap _dependencies_rhs = {},
66 DependencyMap _dependencies_lhs = {})
67 : id(_id)
68 , solve_type(_solve_type)
69 , solve_timing(_solve_timing)
70 , field_indices(std::move(_field_indices))
71 , dependencies_rhs(std::move(_dependencies_rhs))
72 , dependencies_lhs(std::move(_dependencies_lhs))
73 {}
74
79 int id;
80
85
91
95 std::set<Types::Index> field_indices;
96
105
110 std::vector<SolveBlock> aux_solve_container;
111
112 [[nodiscard]] bool
114 {
115 return !aux_solve_container.empty();
116 }
117
118 bool
119 operator<(const SolveBlock &other) const
120 {
121 return id < other.id;
122 }
123
124 void
125 validate() const
126 {
127 AssertThrow(
130 dealii::ExcMessage(
131 "A valid solve type must be selected (Constant | Explicit | Linear | Newton)\n"));
132 AssertThrow(!field_indices.empty(),
133 dealii::ExcMessage("This solve block must manage at least 1 field.\n"));
135 {
136 for (unsigned int field_index : field_indices)
137 {
138 const auto &dep_it_rhs = dependencies_rhs.find(field_index);
139 AssertThrow(dep_it_rhs != dependencies_rhs.end(),
140 dealii::ExcMessage("Every field in a newton solve should appear "
141 "in the residual (RHS) expression.\n"));
142 AssertThrow(dep_it_rhs->second.flag != EvalFlags::nothing,
143 dealii::ExcMessage("Every field in a newton solve should appear "
144 "in the residual (RHS) expression.\n"));
145 const auto &dep_it_lhs = dependencies_lhs.find(field_index);
146 AssertThrow(dep_it_lhs != dependencies_lhs.end(),
147 dealii::ExcMessage(
148 "Every field in a newton solve should appear as a Delta term"
149 "in the residual Jacobian (LHS) expression.\n"));
150 AssertThrow(dep_it_lhs->second.src_flag != EvalFlags::nothing,
151 dealii::ExcMessage(
152 "Every field in a newton solve should appear as a Delta term"
153 "in the residual Jacobian (LHS) expression.\n"));
154 }
155 }
156 else if (solve_type == SolveType::Linear)
157 {
158 for (unsigned int field_index : field_indices)
159 {
160 const auto &dep_it_lhs = dependencies_lhs.find(field_index);
161 AssertThrow(dep_it_lhs != dependencies_lhs.end(),
162 dealii::ExcMessage(
163 "Every field in a linear solve should appear "
164 "in the (LHS) expression. Be sure to use the src_flag.\n"));
165 AssertThrow(dep_it_lhs->second.src_flag != EvalFlags::nothing,
166 dealii::ExcMessage(
167 "Every field in a linear solve should appear "
168 "in the (LHS) expression. Be sure to use the src_flag.\n"));
169 }
170 }
172 {
173 AssertThrow(dependencies_lhs.empty(),
174 dealii::ExcMessage("Explicit solves do not have an LHS, "
175 "and should have no LHS dependencies.\n"));
176 }
178 {
179 AssertThrow(dependencies_rhs.empty() && dependencies_lhs.empty(),
180 dealii::ExcMessage("Constant \"solves\" do not have an RHS or LHS, "
181 "and should have no dependencies.\n"));
182 }
183 for (const auto &[field_index, dependency] : dependencies_rhs)
184 {
185 AssertThrow(dependency.src_flag == EvalFlags::nothing,
186 dealii::ExcMessage(
187 "Trial/Change terms should not appear in RHS expressions.\n"));
188 }
189 for (const SolveBlock &aux : aux_solve_container)
190 {
191 aux.validate();
192 }
193 }
194};
195
197
198// NOLINTEND(misc-non-private-member-variables-in-classes, hicpp-explicit-conversions)
199
200PRISMS_PF_END_NAMESPACE
Structure to hold the attributes of a solve-block.
Definition solve_block.h:56
SolveType solve_type
PDE type (Constant | Explicit | Linear | Newton).
Definition solve_block.h:84
bool has_auxiliary_solve() const
Definition solve_block.h:113
SolveTiming solve_timing
This is used to determine whether to initialize the solution vector with the initial conditions or ju...
Definition solve_block.h:90
int id
Unique identifier. Use this in 'if' statements or switch cases in equations lhs and rhs.
Definition solve_block.h:79
SolveBlock(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_block.h:61
TensorRank FieldType
Definition solve_block.h:59
DependencyMap dependencies_rhs
Dependencies for the rhs equation(s)
Definition solve_block.h:100
std::vector< SolveBlock > aux_solve_container
Solves that occur inside the parent solve. This is only really meant for implicit solves with higher ...
Definition solve_block.h:110
dealii::EvaluationFlags::EvaluationFlags EvalFlags
Definition solve_block.h:58
DependencyMap dependencies_lhs
Dependencies for the lhs equation(s)
Definition solve_block.h:104
void validate() const
Definition solve_block.h:125
bool operator<(const SolveBlock &other) const
Definition solve_block.h:119
std::set< Types::Index > field_indices
Indices of the fields to be solved in this block.
Definition solve_block.h:95
std::map< Types::Index, Dependency > DependencyMap
Definition dependencies.h:129
Definition conditional_ostreams.cc:20
SolveBlock SolveGroup
Definition solve_block.h:196
SolveTiming
Enum describing when each block of fields gets solved.
Definition solve_block.h:25
@ Uninitialized
Definition solve_block.h:37
@ Primary
Primary fields are initialized explicitly through initial conditions rather than through the solver o...
Definition solve_block.h:30
@ NucleationRate
NucleationRate fields are only solved on nucleation attempt and output increments.
Definition solve_block.h:46
@ PostProcess
PostProcess fields are only solved on output increments.
Definition solve_block.h:41
@ Initialized
Definition solve_block.h:31
@ Secondary
Secondary fields are only evaluated by the pde solver on every increment, not initialized by a separa...
Definition solve_block.h:36
SolveType
Type of PDE that is being solved.
Definition type_enums.h:17
@ Linear
Definition type_enums.h:33
@ Newton
Definition type_enums.h:43
@ Constant
Definition type_enums.h:21
@ Explicit
Definition type_enums.h:26
TensorRank
Tensor rank of the field.
Definition type_enums.h:52