Line data Source code
1 : // Copyright 2024, UChicago Argonne, LLC
2 : // All Rights Reserved
3 : // Software Name: NEML2 -- the New Engineering material Model Library, version 2
4 : // By: Argonne National Laboratory
5 : // OPEN SOURCE LICENSE (MIT)
6 : //
7 : // Permission is hereby granted, free of charge, to any person obtaining a copy
8 : // of this software and associated documentation files (the "Software"), to deal
9 : // in the Software without restriction, including without limitation the rights
10 : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 : // copies of the Software, and to permit persons to whom the Software is
12 : // furnished to do so, subject to the following conditions:
13 : //
14 : // The above copyright notice and this permission notice shall be included in
15 : // all copies or substantial portions of the Software.
16 : //
17 : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 : // THE SOFTWARE.
24 :
25 : #include "neml2/base/DiagnosticsInterface.h"
26 : #include "neml2/base/NEML2Object.h"
27 :
28 : namespace neml2
29 : {
30 266 : Diagnosing::Diagnosing(bool ongoing)
31 266 : : prev_state(current_diagnostic_state())
32 : {
33 266 : current_diagnostic_state().ongoing = ongoing;
34 266 : }
35 :
36 266 : Diagnosing::~Diagnosing() { current_diagnostic_state() = prev_state; }
37 :
38 : DiagnosticState &
39 1068 : current_diagnostic_state()
40 : {
41 1068 : static DiagnosticState _diagnostic_state;
42 1068 : return _diagnostic_state;
43 : }
44 :
45 : std::vector<Diagnosis> &
46 443 : current_diagnoses()
47 : {
48 443 : static std::vector<Diagnosis> _diagnoses;
49 443 : return _diagnoses;
50 : }
51 :
52 : std::vector<Diagnosis>
53 266 : diagnose(const DiagnosticsInterface & patient)
54 : {
55 266 : auto & state = current_diagnostic_state();
56 266 : state.patient_name = patient.object().name();
57 266 : state.patient_type = patient.object().type();
58 :
59 : // Run diagnostics
60 : {
61 266 : Diagnosing guard;
62 266 : patient.diagnose();
63 266 : }
64 :
65 : // Get the new diagnoses
66 266 : auto new_diagnoses = current_diagnoses();
67 :
68 : // Reset to a clean state before returning
69 266 : if (!state.ongoing)
70 : {
71 173 : current_diagnoses().clear();
72 173 : state.reset();
73 : }
74 :
75 266 : return new_diagnoses;
76 0 : }
77 :
78 602 : DiagnosticsInterface::DiagnosticsInterface(NEML2Object * object)
79 602 : : _object(object)
80 : {
81 602 : }
82 : } // namespace neml2
|