/
TimeMaxEvaluator.cc
68 lines (55 loc) · 1.78 KB
/
TimeMaxEvaluator.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Copyright 2010-202x held jointly by participating institutions.
ATS is released under the three-clause BSD License.
The terms of use and "as is" disclaimer for this license are
provided in the top-level COPYRIGHT file.
Authors: Ethan Coon (coonet@ornl.gov)
*/
#include "TimeMaxEvaluator.hh"
namespace Amanzi {
namespace Relations {
TimeMaxEvaluator::TimeMaxEvaluator(Teuchos::ParameterList& plist)
: EvaluatorSecondaryMonotypeCV(plist), evaluated_once_(false)
{
operator_ = plist.get<std::string>("operator", "max");
if (operator_ != "max" && operator_ != "min") {
Errors::Message msg;
msg << "TimeMaxEvaluator: " << my_keys_.front().first << ": invalid operator \"" << operator_
<< "\"";
Exceptions::amanzi_throw(msg);
}
if (dependencies_.size() == 0) {
Tag tag = my_keys_.front().second;
Key key = my_keys_.front().first;
AMANZI_ASSERT(Keys::starts_with(key, operator_ + "_"));
dependencies_.insert(KeyTag{ key.substr(4, key.size()), tag });
}
}
Teuchos::RCP<Evaluator>
TimeMaxEvaluator::Clone() const
{
return Teuchos::rcp(new TimeMaxEvaluator(*this));
}
void
TimeMaxEvaluator::Evaluate_(const State& S, const std::vector<CompositeVector*>& result)
{
if (!evaluated_once_) {
if (operator_ == "max") {
result[0]->PutScalar(-1.e16);
} else {
result[0]->PutScalar(1.e16);
}
evaluated_once_ = true;
}
Epetra_MultiVector& res = *result[0]->ViewComponent("cell", false);
const Epetra_MultiVector& dep =
*S.Get<CompositeVector>(dependencies_.front().first, dependencies_.front().second)
.ViewComponent("cell", false);
if (operator_ == "max") {
for (int c = 0; c != res.MyLength(); ++c) {
res[0][c] = std::max(res[0][c], dep[0][c]);
}
}
}
} // namespace Relations
} // namespace Amanzi