ReFRACtor
problem_state.cc
Go to the documentation of this file.
1 #include <problem_state.h>
2 #include <fp_exception.h>
3 
4 
5 using namespace FullPhysics;
6 using namespace blitz;
7 
8 
9 bool ProblemState::parameters_different(const Array<double, 1>& x) const
10 {
11  assert_parameter_correct(x);
12 
13  bool different = (X.size() <= 0);
14 
15  // A test is performed on the parameters. If the absolute
16  // relative difference of a single current parameter and
17  // its corresponding element from the input parameters vector
18  // is larger than abs_rel_diff_tol, then the input parameters
19  // are considered to be different (in other words, the new
20  // point in the parameter space is considered to be different
21  // from the current point in the parameter space.)
22  //
23  // Most sensitive when less than or equal to zero.
24  //
25  double abs_rel_diff_tol = 1.0e-17;
26  for(int i=0; (i<X.rows()) && !different; i++) {
27  if( X(i) == 0.0 )
28  different = ( x(i) != 0.0 );
29  else
30  different = abs((X(i)-x(i))/X(i)) > abs_rel_diff_tol;
31  }
32 
33  return different;
34 }
35 
36 void ProblemState::parameters(const blitz::Array<double, 1>& x)
37 {
38  if( parameters_different(x) ) {
39  clear();
40  X.reference(x.copy());
41  }
42 }
43 
44 void ProblemState::assert_parameter_correct(const blitz::Array<double, 1>& x) const
45 {
46  if(x.rows() != expected_parameter_size()) {
47  Exception e;
48  e << "For this problem state, x does not have the expected size:\n"
49  << " Expected size " << expected_parameter_size()
50  << " Got size " << x.rows();
51  throw e;
52  }
53 }
virtual blitz::Array< double, 1 > parameters() const
Returns the current parameters.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
virtual void assert_parameter_correct(const blitz::Array< double, 1 > &x) const
Checks that the new input parameters are correct.
Apply value function to a blitz array.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
virtual bool parameters_different(const blitz::Array< double, 1 > &x) const
Checks whether or not new input parameters are different from the current ones.
Definition: problem_state.cc:9

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:10