MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
mast_constant_field_function.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 // libMesh includes
24 #include "libmesh/point.h"
25 
26 // MAST includes
27 #include "base/parameter.h"
29 
30 TEST_CASE("constant_field_functions", "[field_function],[constant],[base]")
31 {
37  // Create a parameter
38  const Real initial_value = 4.984;
39  MAST::Parameter parameter1("p1", initial_value);
40 
41  const std::string initial_name = "cf1";
42  MAST::ConstantFieldFunction cfield1(initial_name, parameter1);
43 
50  SECTION("constant field function can return a constant reference to its name")
51  {
52  const std::string& name = cfield1.name();
53  CHECK( name == initial_name );
54  }
55 
56  SECTION("constant field function can return a copy of its name")
57  {
58  std::string name = cfield1.name();
59  CHECK( name == initial_name );
60  name += "_added_string";
61  CHECK( name != initial_name );
62  CHECK ( cfield1.name() == initial_name );
63  }
64 
65  SECTION("constant field function can return the value")
66  {
67  Real cfield_value;
68  cfield1(cfield_value);
69  CHECK( cfield_value == initial_value );
70  }
71 
72  SECTION("constant field function's derivative w.r.t. its own parameter is 1")
73  {
74  Real dvalue_dparam;
75  cfield1.derivative(parameter1, dvalue_dparam);
76  REQUIRE ( dvalue_dparam == 1.0 );
77  }
78 
79  SECTION("constant field function's derivative w.r.t. another parameter is 0")
80  {
81  Real dvalue_dparam;
82  MAST::Parameter parameter2("p2", 3.623);
83  cfield1.derivative(parameter2, dvalue_dparam);
84  CHECK( dvalue_dparam == 0.0 );
85  }
86 
87  SECTION("constant field function can return the value given a point and time")
88  {
89  Real cfield_value;
90  const libMesh::Point point(2.3, 3.1, 5.2);
91  const Real time = 2.34;
92  cfield1(point, time, cfield_value);
93  CHECK( cfield_value == initial_value );
94  }
95 
96  SECTION("constant field function is constant over time and space")
97  {
98  Real cfield_value;
99  const libMesh::Point point(2.3, 3.1, 5.2);
100  const Real time = 2.34;
101  cfield1(point, time, cfield_value);
102  CHECK( cfield_value == initial_value );
103 
104  Real cfield_value2;
105  const libMesh::Point point2(4.3, -16.4, 55.2);
106  const Real time2 = 88.4;
107  cfield1(point2, time2, cfield_value2);
108  CHECK( cfield_value2 == initial_value );
109 
110  Real cfield_value3;
111  const libMesh::Point point3(-18.0, 10.2, -7.5);
112  const Real time3 = 36.7;
113  cfield1(point3, time3, cfield_value3);
114  CHECK( cfield_value3 == initial_value );
115  }
116 
117  SECTION("constant field function can return derivative to its own parameter at a given point and time")
118  {
119  Real dvalue_dparam;
120  const libMesh::Point point(3.5, -2.4, -11.2);
121  const Real time = 6.87;
122  cfield1.derivative(parameter1, point, time, dvalue_dparam);
123  CHECK( dvalue_dparam == 1.0 );
124  }
125 
126  SECTION("constant field function can return derivative to other parameter at a given point and time")
127  {
128  MAST::Parameter parameter2("p2", 5.478);
129  Real dvalue_dparam;
130  const libMesh::Point point(3.5, -2.4, -11.2);
131  const Real time = 6.87;
132  cfield1.derivative(parameter2, point, time, dvalue_dparam);
133  CHECK( dvalue_dparam == 0.0 );
134  }
135 
136 
137  SECTION("constant field function derivative w.r.t. itself is constant 1 over time and space")
138  {
139  Real dvalue_dparam;
140  const libMesh::Point point(-5.0, 8.4, 7.3);
141  const Real time = 3.5;
142  cfield1.derivative(parameter1, point, time, dvalue_dparam);
143  CHECK( dvalue_dparam == 1.0 );
144 
145  Real dvalue_dparam2;
146  const libMesh::Point point2(8.8, -10.5, 200.3);
147  const Real time2 = 107.5;
148  cfield1.derivative(parameter1, point2, time2, dvalue_dparam2);
149  CHECK( dvalue_dparam2 == 1.0 );
150 
151  Real dvalue_dparam3;
152  const libMesh::Point point3(0.0, 57.8,-150.7);
153  const Real time3 = 0.0;
154  cfield1.derivative(parameter1, point3, time3, dvalue_dparam3);
155  CHECK( dvalue_dparam3 == 1.0 );
156  }
157 
158  SECTION("constant field function derivative w.r.t. other parameters is constant 0 over time and space")
159  {
160  MAST::Parameter parameter2("p2", 6.578);
161 
162  Real dvalue_dparam;
163  const libMesh::Point point(-5.0, 8.4, 7.3);
164  const Real time = 3.5;
165  cfield1.derivative(parameter2, point, time, dvalue_dparam);
166  CHECK( dvalue_dparam == 0.0 );
167 
168  Real dvalue_dparam2;
169  const libMesh::Point point2(8.8, -10.5, 200.3);
170  const Real time2 = 107.5;
171  cfield1.derivative(parameter2, point2, time2, dvalue_dparam2);
172  CHECK( dvalue_dparam2 == 0.0 );
173 
174  Real dvalue_dparam3;
175  const libMesh::Point point3(0.0, 57.8,-150.7);
176  const Real time3 = 0.0;
177  cfield1.derivative(parameter2, point3, time3, dvalue_dparam3);
178  CHECK( dvalue_dparam3 == 0.0 );
179  }
180 
181  SECTION("constant field function is NOT a shape parameter by default")
182  {
183  CHECK_FALSE( cfield1.is_shape_parameter() );
184  }
185 
186  SECTION("constant field function can be set as a shape parameter")
187  {
188  cfield1.set_as_shape_parameter(true);
189  CHECK( cfield1.is_shape_parameter() );
190  }
191 
192  SECTION("constant field function is NOT a topology parameter by default")
193  {
194  CHECK_FALSE( cfield1.is_topology_parameter() );
195  }
196 
197  SECTION("constant field function can be set as a topology parameter")
198  {
199  cfield1.set_as_topology_parameter(true);
200  CHECK( cfield1.is_topology_parameter() );
201  }
202 }
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
libMesh::Real Real
virtual bool is_topology_parameter() const
Definition: function_base.h:97
TEST_CASE("constant_field_functions", "[field_function],[constant],[base]")
virtual void derivative(const MAST::FunctionBase &f, Real &v) const
calculates the value of the function at the specified point, p, and time, t, and returns it in v...
virtual void set_as_shape_parameter(bool f)
Definition: function_base.h:90