forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MockModel.cc
80 lines (69 loc) · 2.4 KB
/
MockModel.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
69
70
71
72
73
74
75
76
77
78
79
80
//----------------------------------*-C++-*----------------------------------//
// Copyright 2021-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/phys/MockModel.cc
//---------------------------------------------------------------------------//
#include "MockModel.hh"
#include <sstream>
#include "celeritas/grid/ValueGridBuilder.hh"
#include "celeritas/mat/MaterialView.hh"
namespace celeritas
{
namespace test
{
//---------------------------------------------------------------------------//
MockModel::MockModel(Input data) : data_(std::move(data))
{
CELER_EXPECT(data_.id);
CELER_EXPECT(data_.materials);
CELER_EXPECT(data_.applic);
CELER_EXPECT(data_.cb);
label_ = "mock-model-";
label_ += std::to_string(data_.id.get() - 4);
std::ostringstream os;
os << "MockModel(" << (data_.id.get() - 4)
<< ", p=" << data_.applic.particle.get()
<< ", emin=" << data_.applic.lower.value()
<< ", emax=" << data_.applic.upper.value() << ")";
description_ = std::move(os).str();
}
auto MockModel::applicability() const -> SetApplicability
{
return {data_.applic};
}
auto MockModel::micro_xs(Applicability range) const -> MicroXsBuilders
{
CELER_EXPECT(range.material);
CELER_EXPECT(range.particle);
MicroXsBuilders builders;
MaterialView mat(data_.materials->host_ref(), range.material);
if (!data_.xs.empty())
{
builders.resize(mat.num_elements());
for (auto elcomp_idx : celeritas::range(mat.num_elements()))
{
std::vector<double> xs_grid;
for (auto xs : data_.xs)
{
xs_grid.push_back(native_value_from(xs));
}
builders[elcomp_idx] = std::make_unique<ValueGridLogBuilder>(
range.lower.value(), range.upper.value(), xs_grid);
}
}
return builders;
}
void MockModel::execute(CoreParams const&, CoreStateHost&) const
{
// Shouldn't be called?
}
void MockModel::execute(CoreParams const&, CoreStateDevice&) const
{
// Inform calling test code that we've been executed
data_.cb(this->action_id());
}
//---------------------------------------------------------------------------//
} // namespace test
} // namespace celeritas