Skip to content

Commit

Permalink
Added new function to API which allows to query defined parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
uphoffc committed Nov 12, 2018
1 parent c0a9f16 commit 5a6e5d8
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ easi_add_test (33_layered_constant)
easi_add_test (101_asagi)
easi_add_test (f_16_scec)
easi_add_test (f_120_sumatra)
easi_add_test (supplied_parameters)
2 changes: 2 additions & 0 deletions examples/supplied_parameters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!Include
../examples/26_function.yaml
2 changes: 2 additions & 0 deletions include/easi/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Component {
return s.str();
}

virtual std::set<std::string> suppliedParameters() { return out(); }

protected:
void setIn(std::set<std::string> const& parameters) { m_in = parameters; }
void setOut(std::set<std::string> const& parameters) { m_out = parameters; }
Expand Down
17 changes: 17 additions & 0 deletions include/easi/component/Composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Composite : public Component {
virtual void evaluate(Query& query, ResultAdapter& result);

std::string addMissingParameters(std::string const& what_arg, std::set<std::string> expected, std::set<std::string> supplied);

virtual std::set<std::string> suppliedParameters();

protected:
virtual Matrix<double> map(Matrix<double>& x) = 0;
Expand Down Expand Up @@ -206,6 +208,21 @@ std::string Composite::addMissingParameters(std::string const& what_arg, std::se
s << "}.";
return s.str();
}

std::set<std::string> Composite::suppliedParameters() {
if (m_components.empty()) {
return Component::suppliedParameters();
}

return std::accumulate(begin(), end(), std::set<std::string>(), [](std::set<std::string>& a, Component*& b) {
std::set<std::string> supplied;
auto c = b->suppliedParameters();
std::set_union( a.begin(), a.end(),
c.begin(), c.end(),
std::inserter(supplied, supplied.begin()) );
return supplied;
});
}
}

#endif
61 changes: 61 additions & 0 deletions tests/supplied_parameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @file
* This file is part of SeisSol.
*
* @author Carsten Uphoff (c.uphoff AT tum.de, http://www5.in.tum.de/wiki/index.php/Carsten_Uphoff,_M.Sc.)
*
* @section LICENSE
* Copyright (c) 2018, SeisSol Group
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @section DESCRIPTION
**/

#include <easi/YAMLParser.h>

int main(int argc, char** argv) {
assert(argc == 2);

easi::YAMLParser parser(3);
easi::Component* model = parser.parse(argv[1]);

std::set<std::string> supplied = model->suppliedParameters();
std::set<std::string> expected = {"rho", "mu", "lambda", "plastCo", "bulkFriction", "s_xx", "s_yy", "s_zz", "s_xy", "s_yz", "s_xz"};

std::set<std::string> missing;
std::set_difference( expected.begin(), expected.end(),
supplied.begin(), supplied.end(),
std::inserter(missing, missing.begin()));

assert(missing.empty());

delete model;

return 0;
}

0 comments on commit 5a6e5d8

Please sign in to comment.