26 #include <queso/InterpolationSurrogateIOASCII.h>
29 #include <queso/MpiComm.h>
30 #include <queso/StreamUtilities.h>
31 #include <queso/GslVector.h>
32 #include <queso/GslMatrix.h>
40 template<
class V,
class M>
45 template<
class V,
class M>
48 const std::string& vector_space_prefix,
52 unsigned int root = reading_rank;
64 input.open( filename.c_str() );
75 "InterpolationSurrogateIOASCII::read()",
76 "MpiComm::Bcast() failed!" );
80 vector_space_prefix.c_str(),
85 this->m_n_points.resize(dim);
89 for(
unsigned int d = 0; d <
dim; d++ )
98 input >> this->m_n_points[d];
104 "InterpolationSurrogateIOASCII::read()",
105 "MpiComm::Bcast() failed!" );
108 std::vector<double> param_mins(dim);
109 std::vector<double> param_maxs(dim);
113 for(
unsigned int d = 0; d <
dim; d++ )
122 input >> param_mins[d] >> param_maxs[d];
128 "InterpolationSurrogateIOASCII::read()",
129 "MpiComm::Bcast() failed!" );
132 "InterpolationSurrogateIOASCII::read()",
133 "MpiComm::Bcast() failed!" );
141 for(
unsigned int d = 0; d <
dim; d++ )
143 paramMins[d] = param_mins[d];
144 paramMaxs[d] = param_maxs[d];
147 this->m_domain.reset(
new BoxSubset<V,M>(vector_space_prefix.c_str(),
148 *(this->m_vector_space.get()),
159 for(
unsigned int n = 0; n < this->m_data->n_values(); n++ )
171 this->m_data->set_value( n, value );
179 this->m_data->sync_values(root);
184 template<
class V,
class M>
187 int writing_rank )
const
192 std::string error =
"ERROR: No values found in InterpolationSurrogateData.\n";
193 error +=
"Cannot write data without values.\n";
194 error +=
"Use InterpolationSurrogateBuilder or the read method to populate\n";
195 error +=
"data values.\n";
200 std::ofstream output;
205 output.open( filename.c_str() );
208 std::string header =
"# Data for interpolation surrogate\n";
209 header +=
"# Format is as follows:\n";
210 header +=
"# dimension (unsigned int)\n";
211 header +=
"# n_points in each dimension\n";
212 header +=
"# x_min, x_max pairs for each dimension\n";
213 header +=
"# values for each point in parameter space\n";
214 header +=
"# values must be ordered in structured format.\n";
219 output << dim << std::endl;
222 output <<
"# n_points" << std::endl;
223 for(
unsigned int d = 0; d <
dim; d++ )
229 output << std::scientific << std::setprecision(16);
232 output <<
"# domain bounds" << std::endl;
233 for(
unsigned int d = 0; d <
dim; d++ )
235 output << data.
x_min(d) <<
" "
236 << data.
x_max(d) << std::endl;
240 output <<
"# values" << std::endl;
241 for(
unsigned int n = 0; n < data.
n_values(); n++ )
243 output << data.
get_value(n) << std::endl;
InterpolationSurrogateIOASCII()
virtual void write(const std::string &filename, const InterpolationSurrogateData< V, M > &data, int writing_rank=0) const
Write interpolation surrogate data to filename using processor writing_rank.
#define RawValue_MPI_UNSIGNED
#define queso_error_msg(msg)
void Bcast(void *buffer, int count, RawType_MPI_Datatype datatype, int root, const char *whereMsg, const char *whatMsg) const
Broadcast values from the root process to the slave processes.
double get_value(unsigned int n) const
unsigned int n_values() const
const BoxSubset< V, M > & get_paramDomain() const
const std::vector< unsigned int > & get_n_points() const
int fullRank() const
Returns the process full rank.
double x_min(unsigned int dim) const
Lower bound of domain along dimension dim.
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
static void skip_comment_lines(std::istream &in, const char comment_start)
Skips comment lines until a line without a comment character is encountered.
This class sets up the full environment underlying the use of the QUESO library by an executable...
double x_max(unsigned int dim) const
Upper bound of domain along dimension dim.
Class representing a subset of a vector space shaped like a hypercube.
A class representing a vector space.
Class for vector operations using GSL library.
The QUESO MPI Communicator Class.
#define RawValue_MPI_DOUBLE
virtual void read(const std::string &filename, const FullEnvironment &env, const std::string &vector_space_prefix, int reading_rank=0)
Read Interpolation surrogate data from filename using processor reading_rank.