NEML2 1.4.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:
50
66 virtual void diagnose(std::vector<Diagnosis> & diagnoses) const = 0;
67
68 template <typename... Args>
69 void diagnostic_assert(std::vector<Diagnosis> & diagnoses, bool assertion, Args &&... args) const;
70
71 void diagnostic_assert_state(std::vector<Diagnosis> & diagnoses, const VariableBase & v) const;
72 void diagnostic_assert_old_state(std::vector<Diagnosis> & diagnoses,
73 const VariableBase & v) const;
74 void diagnostic_assert_force(std::vector<Diagnosis> & diagnoses, const VariableBase & v) const;
75 void diagnostic_assert_old_force(std::vector<Diagnosis> & diagnoses,
76 const VariableBase & v) const;
77 void diagnostic_assert_residual(std::vector<Diagnosis> & diagnoses, const VariableBase & v) const;
78 void diagnostic_check_input_variable(std::vector<Diagnosis> & diagnoses,
79 const VariableBase & v) const;
80 void diagnostic_check_output_variable(std::vector<Diagnosis> & diagnoses,
81 const VariableBase & v) const;
82
83private:
84 NEML2Object * _object;
85};
86
87template <typename... Args>
88void
90 bool assertion,
91 Args &&... args) const
92{
93 if (assertion)
94 return;
95
96 std::ostringstream oss;
97 internal::stream_all(oss,
98 "In object '",
99 _object->name(),
100 "' of type ",
101 _object->type(),
102 ": ",
103 std::forward<Args>(args)...);
104 return diagnoses.push_back(Diagnosis(oss.str().data()));
105}
106}
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:56
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:91
void diagnostic_assert(std::vector< Diagnosis > &diagnoses, bool assertion, Args &&... args) const
Definition DiagnosticsInterface.h:89
void diagnostic_check_output_variable(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:104
DiagnosticsInterface(NEML2Object *object)
Definition DiagnosticsInterface.cxx:45
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:83
void diagnostic_assert_force(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:67
void diagnostic_assert_old_force(std::vector< Diagnosis > &diagnoses, const VariableBase &v) const
Definition DiagnosticsInterface.cxx:75
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.
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:65
const std::string & type() const
A readonly reference to the object's type.
Definition NEML2Object.h:67
Definition error.h:33
Definition Variable.h:42
Definition CrossRef.cxx:30
void diagnose(const DiagnosticsInterface &patient)
Raise diagnostics as exception, if any.
Definition DiagnosticsInterface.cxx:31