MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
mast_parameter.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 // Catch2 includes
21 #include "catch.hpp"
22 
23 // MAST includes
24 #include "base/parameter.h"
25 
26 
31 TEST_CASE("parameters", "[parameter],[base]")
32 {
38  // Create a parameter
39  const Real initial_value = 4.984;
40  const std::string initial_name = "p1";
41  MAST::Parameter parameter1(initial_name, initial_value);
42 
43 
49  SECTION("parameter can return a constant reference to its name")
50  {
51  const std::string& name = parameter1.name();
52  CHECK( name == initial_name );
53  }
54 
55  SECTION("parameter can return a copy of its name")
56  {
57  std::string name = parameter1.name();
58  CHECK( name == initial_name );
59  name += "_added_string";
60  CHECK( name != initial_name );
61  CHECK ( parameter1.name() == initial_name );
62  }
63 
64  SECTION("parameter can return a constant reference to its value")
65  {
66  const Real const_param_value = parameter1();
67  CHECK( const_param_value == initial_value );
68  }
69 
70  SECTION("parameter can return a writable reference to its value")
71  {
72  Real& parameter_value = parameter1();
73  CHECK( parameter_value == initial_value );
74  }
75 
76  SECTION("parameter value can be changed through writable reference to its value")
77  {
78  Real& parameter_value = parameter1();
79  parameter_value = 2.4578;
80  CHECK( parameter1() == 2.4578 );
81  }
82 
83  SECTION("parameter value can be set through assignment oeprator '='")
84  {
85  parameter1 = 5.678;
86  CHECK( parameter1() == 5.678 );
87  }
88 
89  SECTION("parameter can return a pointer to its value")
90  {
91  Real* val_ptr = parameter1.ptr();
92  CHECK( *val_ptr == initial_value );
93  }
94 
95  SECTION("parameter depends on itself")
96  {
97  const bool depends_on_itself = parameter1.depends_on(parameter1);
98  CHECK( depends_on_itself );
99  }
100 
101  SECTION("parameter does not depend on other field functions")
102  {
103  MAST::Parameter parameter2("p2", 5.242);
104  const bool depends_on_other = parameter1.depends_on(parameter2);
105  CHECK_FALSE( depends_on_other );
106  }
107 
108  SECTION("parameter is NOT a shape parameter by default")
109  {
110  CHECK_FALSE( parameter1.is_shape_parameter() );
111  }
112 
113  SECTION("parameter can be set as a shape parameter")
114  {
115  parameter1.set_as_shape_parameter(true);
116  CHECK( parameter1.is_shape_parameter() );
117  }
118 
119  SECTION("parameter is NOT a topology parameter by default")
120  {
121  CHECK_FALSE( parameter1.is_topology_parameter() );
122  }
123 
124  SECTION("parameter can be set as a topology parameter")
125  {
126  parameter1.set_as_topology_parameter(true);
127  CHECK( parameter1.is_topology_parameter() );
128  }
129 
130  //TODO: Test that Parameter constructor accepts a field function as well
131 }
virtual bool is_shape_parameter() const
Definition: function_base.h:89
const std::string & name() const
returns the name of this function
Definition: function_base.h:60
virtual void set_as_topology_parameter(bool f)
Definition: function_base.h:98
This is a scalar function whose value can be changed and one that can be used as a design variable in...
Definition: parameter.h:35
TEST_CASE("parameters", "[parameter],[base]")
MAST::Parameter objects are independent of libMesh and thus we do not need to initialize any libMesh ...
libMesh::Real Real
virtual bool is_topology_parameter() const
Definition: function_base.h:97
Real * ptr()
Definition: parameter.h:78
virtual bool depends_on(const MAST::FunctionBase &f) const
Definition: parameter.h:86
virtual void set_as_shape_parameter(bool f)
Definition: function_base.h:90