-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDamageModelInterface.cpp
46 lines (44 loc) · 1.64 KB
/
DamageModelInterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include "DamageModelInterface.h"
void DamageModelInterface::set_parameters(const std::vector <double> & new_parameters)
{
if (new_parameters.size() != ParameterCount())
{
std::cerr << "Error: Incorrect number of parameters to set_parameters(). Expected: " << ParameterCount() << ", actual: " << new_parameters.size() << std::endl;
exit(1);
}
_set_parameters(new_parameters);
}
void DamageModelInterface::print_parameters(std::ostream & out, std::string tag) const
{
out << tag << " Model Parameters:";
if (ParameterCount() == 0)
{
out << " (none)" << std::endl;
return;
}
out << std::endl;
std::vector <Parameter> params = parameters();
unsigned int biggest_param_name = 0;
unsigned int biggest_param_value = 0;
unsigned int lead_space;
std::stringstream ss;
for (unsigned int i = 0; i < params.size(); i++)
{
if (params[i].name.length() > biggest_param_name) biggest_param_name = params[i].name.length();
ss.clear();
ss.str("");
ss << std::setprecision(15) << params[i].value;
if (ss.str().length() > biggest_param_value) biggest_param_value = ss.str().length();
}
if (biggest_param_name > 32) lead_space = 0;
else lead_space = 32 - biggest_param_name;
for (unsigned int i = 0; i < params.size(); i++)
{
out << tag;
for (unsigned int j = 0; j < lead_space; j++) out << " ";
out << std::setw(biggest_param_name) << params[i].name << " = " << std::setw(biggest_param_value) << std::right << std::setprecision(15) << params[i].value << " " << params[i].units << std::endl;
}
}