https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ThreadedNodeLoop.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "FEProblemBase.h"
13#include "ParallelUniqueId.h"
14
16
17template <typename RangeType, typename IteratorType>
19{
20public:
22
23 // Splitting Constructor
25
26 virtual ~ThreadedNodeLoop() {}
27
28 void operator()(const RangeType & range);
29
33 virtual void pre();
34
38 virtual void post();
39
43 virtual void onNode(IteratorType & node_it);
44
50 virtual void postNode(IteratorType & node_it);
51
57 {
58 Threads::spin_mutex::scoped_lock lock(threaded_node_mutex);
59
60 std::string what(e.what());
62 };
63
69 virtual bool keepGoing() { return !_fe_problem.hasException(); }
70
71protected:
74
76 virtual void printGeneralExecutionInformation() const {}
77
89 template <typename T>
90 void printExecutionOrdering(const std::vector<T *> & objs,
91 const bool print_header = true,
92 const std::string & line_prefix = "[DBG]") const;
93};
94
95template <typename RangeType, typename IteratorType>
97 : _fe_problem(fe_problem)
98{
99}
100
101template <typename RangeType, typename IteratorType>
103 Threads::split /*split*/)
104 : _fe_problem(x._fe_problem)
105{
106}
107
108template <typename RangeType, typename IteratorType>
109void
111{
112 try
113 {
114 ParallelUniqueId puid;
115 _tid = puid.id;
116
117 pre();
118 printGeneralExecutionInformation();
119
120 for (IteratorType nd = range.begin(); nd != range.end(); ++nd)
121 {
122 if (!keepGoing())
123 break;
124
125 onNode(nd);
126
127 postNode(nd);
128 }
129
130 post();
131 }
132 catch (MooseException & e)
133 {
134 caughtMooseException(e);
135 }
136}
137
138template <typename RangeType, typename IteratorType>
139void
143
144template <typename RangeType, typename IteratorType>
145void
149
150template <typename RangeType, typename IteratorType>
151void
153{
154}
155
156template <typename RangeType, typename IteratorType>
157void
159{
160}
161
162template <typename RangeType, typename IteratorType>
163template <typename T>
164void
166 const std::vector<T *> & objs, const bool print_header, const std::string & line_prefix) const
167{
168 if (!objs.size())
169 return;
170
171 auto & console = _fe_problem.console();
172 const auto objects_type = MooseUtils::prettyCppType(objs[0]);
173 std::vector<MooseObject *> moose_objs;
174 moose_objs.reserve(objs.size());
175 for (auto obj_ptr : objs)
176 moose_objs.push_back(cast_ptr<MooseObject *>(obj_ptr));
177 const auto names = ConsoleUtils::mooseObjectVectorToString(moose_objs);
178
179 // Print string with a DBG prefix and with sufficient line breaks
180 std::string message = print_header ? "Executing " + objects_type + " on " +
181 _fe_problem.getCurrentExecuteOnFlag().name() + "\n"
182 : "";
183 message += (print_header ? "Order of execution:\n" : "") + names;
184 console << ConsoleUtils::formatString(message, line_prefix) << std::endl;
185}
unsigned int THREAD_ID
Definition MooseTypes.h:237
static Threads::spin_mutex threaded_node_mutex
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual bool hasException()
Whether or not an exception has occurred.
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class,...
Provides a way for users to bail out of the current solve.
virtual const char * what() const
Get out the error message.
virtual void printGeneralExecutionInformation() const
Print information about the loop, mostly order of execution of objects.
virtual void postNode(IteratorType &node_it)
Called after the node assembly is done (including surface assembling)
virtual void onNode(IteratorType &node_it)
Called for each node.
void printExecutionOrdering(const std::vector< T * > &objs, const bool print_header=true, const std::string &line_prefix="[DBG]") const
Routine to output the ordering of objects within a vector of pointers to these objects.
ThreadedNodeLoop(ThreadedNodeLoop &x, Threads::split split)
ThreadedNodeLoop(FEProblemBase &fe_problem)
virtual bool keepGoing()
Whether or not the loop should continue.
FEProblemBase & _fe_problem
virtual void pre()
Called before the node range loop.
virtual void post()
Called after the node range loop.
virtual ~ThreadedNodeLoop()
void operator()(const RangeType &range)
virtual void caughtMooseException(MooseException &e)
Called if a MooseException is caught anywhere during the computation.
std::string formatString(std::string message, const std::string &prefix)
Add new lines and prefixes to a string for pretty display in output NOTE: This makes a copy of the st...
std::string mooseObjectVectorToString(const std::vector< MooseObject * > &objs, const std::string &sep=" ")
Routine to output the name of MooseObjects in a string.
std::string prettyCppType(const std::string &cpp_type)