NEML2 2.0.0
Loading...
Searching...
No Matches
DiagnosticsInterface.h
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#pragma once
26
27#include "neml2/base/NEML2Object.h"
28
29namespace neml2
30{
31// Forward decl
32class DiagnosticsInterface;
33class VariableBase;
34
37{
38public:
40};
41
43void diagnose(const DiagnosticsInterface &);
44
47{
48public:
51
56 virtual ~DiagnosticsInterface() = default;
57
73 virtual void diagnose(std::vector<Diagnosis> & diagnoses) const = 0;
74
75 template <typename... Args>
76 void diagnostic_assert(std::vector<Diagnosis> & diagnoses, bool assertion, Args &&... args) const;
77
78 void diagnostic_assert_state(std::vector<Diagnosis> & diagnoses, const VariableBase & v) const;
79 void diagnostic_assert_old_state(std::vector<Diagnosis> & diagnoses,
80 const VariableBase & v) const;
81 void diagnostic_assert_force(std::vector<Diagnosis> & diagnoses, const VariableBase & v) const;
82 void diagnostic_assert_old_force(std::vector<Diagnosis> & diagnoses,
83 const VariableBase & v) const;
84 void diagnostic_assert_residual(std::vector<Diagnosis> & diagnoses, const VariableBase & v) const;
85 void diagnostic_check_input_variable(std::vector<Diagnosis> & diagnoses,
86 const VariableBase & v) const;
87 void diagnostic_check_output_variable(std::vector<Diagnosis> & diagnoses,
88 const VariableBase & v) const;
89
90private:
91 NEML2Object * _object;
92};
93
94template <typename... Args>
95void
97 bool assertion,
98 Args &&... args) const
99{
100 if (assertion)
101 return;
102
103 std::ostringstream oss;
104 internal::stream_all(oss,
105 "In object '",
106 _object->name(),
107 "' of type ",
108 _object->type(),
109 ": ",
110 std::forward<Args>(args)...);
111 diagnoses.emplace_back(Diagnosis(oss.str()));
112}
113}
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:54
Exception type reserved for diagnostics, so as to not conceptually clash with other exceptions.
Definition DiagnosticsInterface.h:37
Interface for object making diagnostics about common setup errors.
Definition DiagnosticsInterface.h:47
void diagnostic_check_input_variable(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:106
void diagnostic_assert(std::vector< Diagnosis > &diagnoses, bool assertion, Args &&... args) const
Definition DiagnosticsInterface.h:96
DiagnosticsInterface(DiagnosticsInterface &&)=delete
void diagnostic_check_output_variable(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:130
DiagnosticsInterface & operator=(const DiagnosticsInterface &)=delete
DiagnosticsInterface(const DiagnosticsInterface &)=delete
void diagnostic_assert_old_state(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:59
void diagnostic_assert_residual(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:93
void diagnostic_assert_force(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:72
void diagnostic_assert_old_force(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:80
void diagnostic_assert_state(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:51
virtual void diagnose(std::vector< Diagnosis > &diagnoses) const =0
Check for common problems.
DiagnosticsInterface & operator=(DiagnosticsInterface &&)=delete
virtual ~DiagnosticsInterface()=default
The base class of all "manufacturable" objects in the NEML2 library.
Definition NEML2Object.h:38
const std::string & name() const
A readonly reference to the object's name.
Definition NEML2Object.h:70
const std::string & type() const
A readonly reference to the object's type.
Definition NEML2Object.h:72
Definition error.h:33
Base class of variable.
Definition Variable.h:47
Definition CrossRef.cxx:31
void diagnose(const DiagnosticsInterface &patient)
Raise diagnostics as exception, if any.
Definition DiagnosticsInterface.cxx:31