CalibrationShearCell.cpp File Reference
#include <Logger.h>
#include <Math/Helpers.h>
#include "Calibration.h"

Classes

struct  ShearStageData
 

Functions

template<typename T >
std::pair< T, T > getLinearFit (const std::vector< T > X, const std::vector< T > Y)
 
std::pair< double, doublesolveQuad (double a, double b, double c)
 
double computeFFc (Mdouble preCompressionNormalStress, Mdouble preCompressionShearStress, std::vector< double > normalStress, std::vector< double > maxShearStress)
 
double computeSimpleFFc (Mdouble preCompressionNormalStress, Mdouble preCompressionShearStress, std::vector< double > normalStress, std::vector< double > maxShearStress)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ computeFFc()

double computeFFc ( Mdouble  preCompressionNormalStress,
Mdouble  preCompressionShearStress,
std::vector< double normalStress,
std::vector< double maxShearStress 
)

https://www.dietmar-schulze.de/grdle1.pdf

74  {
75  //This part does the linear fit through the shear points and get the yield locus with slope and intercept
76  //Then we calculate the sigma_1 and sigma_c to compute flow function FFc
77  logger(INFO, "p % % tau % %", preCompressionNormalStress, toString(normalStress), preCompressionShearStress,
78  toString(maxShearStress));
79 
80  double sigmaC;
81  {
82  auto[slope, intercept] = getLinearFit(normalStress, maxShearStress);
83 
84  if (intercept < 0) {
85  logger(WARN, "y-intercept % <0; setting FFc to 100", intercept);
86  return 1000;
87  }
88  if (slope < 0) {
89  logger(WARN, "slope % <0; this does not make sense; setting FFc to 0", slope);
90  return 0;
91  }
92  //see ffc.nb
93  double arclength = sqrt(1+slope*slope);
94  sigmaC = 2*intercept*(arclength+slope);
95  }
96 
97  double sigma1;
98  {
99  auto[slope, intercept] = getLinearFit<double>({preCompressionNormalStress, normalStress[0]}, {preCompressionShearStress, maxShearStress[0]});
100  if (slope < 0) {
101  sigma1 = preCompressionShearStress + preCompressionShearStress;
102  logger(WARN, "slope % <0; setting sigma1 to %", slope, sigma1);
103  } else {
104  //see ffc.nb
105  double arclength = sqrt(1 + slope * slope);
106  sigma1 = preCompressionNormalStress * arclength * arclength
107  + intercept * slope
108  + arclength * (intercept + preCompressionNormalStress * slope);
109  }
110  }
111 
112  double ffc = sigma1/sigmaC;
113  logger(INFO,"p = %, sigmaC = %, sigma1 = %, ffc = %",preCompressionNormalStress, sigmaC, sigma1, ffc);
114  return ffc;
115 }
std::pair< T, T > getLinearFit(const std::vector< T > X, const std::vector< T > Y)
Definition: CalibrationShearCell.cpp:33
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
std::string toString(Mdouble value, unsigned precision)
converts a floating point number into a string with a given precision
Definition: StringHelpers.cc:38

References getLinearFit(), INFO, logger, helpers::toString(), and WARN.

Referenced by main().

◆ computeSimpleFFc()

double computeSimpleFFc ( Mdouble  preCompressionNormalStress,
Mdouble  preCompressionShearStress,
std::vector< double normalStress,
std::vector< double maxShearStress 
)

https://www.dietmar-schulze.de/grdle1.pdf

121  {
122  //This part does the linear fit through the shear points and get the yield locus with slope and intercept
123  //Then we calculate the sigma_1 and sigma_c to compute flow function FFc
124 
125  logger(INFO, "p % % tau % %", preCompressionNormalStress, toString(normalStress), preCompressionShearStress,
126  toString(maxShearStress));
127  auto [slope, intercept] = getLinearFit(normalStress,maxShearStress);
128 
129  if (intercept < 0) {
130  logger(WARN, "y-intercept % <0; setting FFc to 1000", intercept);
131  return 1000;
132  }
133  if (slope < 0) {
134  logger(WARN, "slope % <0; setting FFc to 1000", slope);
135  return 1000;
136  }
137 
138  //see ffc.nb
139  double arclength = sqrt(1+slope*slope);
140  double sigmaC = 2*intercept*(arclength+slope);
141  double sigma1 = preCompressionNormalStress*arclength*arclength
142  +intercept*slope
143  +arclength*(intercept+preCompressionNormalStress*slope);
144  double ffc = sigma1/sigmaC;
145  logger(INFO,"p = %, sigmaC = %, sigma1 = %, ffc = %",preCompressionNormalStress, sigmaC, sigma1, ffc);
146  return ffc;
147 }

References getLinearFit(), INFO, logger, helpers::toString(), and WARN.

◆ getLinearFit()

template<typename T >
std::pair<T,T> getLinearFit ( const std::vector< T >  X,
const std::vector< T >  Y 
)
34 {
35  size_t n = Y.size();
36  logger.assert_always(X.size()==n,"X and Y data sets have to be same size");
37  T xSum = 0, ySum = 0, xxSum = 0, xySum = 0;
38  for (long i = 0; i < n; i++)
39  {
40  xSum += X[i];
41  ySum += Y[i];
42  xxSum += X[i] * X[i];
43  xySum += X[i] * Y[i];
44  }
45  T slope = (n * xySum - xSum * ySum) / (n * xxSum - xSum * xSum);
46  T intercept = (ySum - slope * xSum) / Y.size();
47  logger(INFO,"Fit values: Slope %, intercept %",slope, intercept);
48  return {slope, intercept};
49 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
@ Y
Definition: StatisticsVector.h:42
@ X
Definition: StatisticsVector.h:42
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References constants::i, INFO, logger, n, X, and Y.

Referenced by computeFFc(), and computeSimpleFFc().

◆ main()

int main ( int argc  ,
char argv[] 
)
161 {
162  // read in pre-compression stress and subsequent compression stresses
163  std::vector<double> normalStress =
164  helpers::readVectorFromCommandLine<double>(argc,argv,"-normalStress",4, {});
165  logger.assert_always(normalStress.size()>2,"You need at least one pre-compression stress and two compression stresses to compute an ffc");
166  double preCompressionNormalStress = normalStress[0];
167  normalStress.erase(normalStress.begin());
168 
169  //get the directory name
170  std::string dir = argv[0];
171  dir.resize(dir.size()-std::string("CalibrationShearCell").length());
172 
173  // run pre-compression stage
174  {
175  std::stringstream cmd;
176  cmd << dir << "CalibrationPrecompression";
177  for (int i = 1; i < argc; ++i) cmd << ' ' << argv[i];
178  logger(INFO, "\nRunning %", cmd.str());
179  int status = system(cmd.str().c_str());
180  }
181 
182  // run shear stages
183  for (const double s : normalStress) {
184  std::stringstream cmd;
185  cmd << dir << "CalibrationShearStage -compression " << s;
186  for (int i = 1; i < argc; ++i) cmd << ' ' << argv[i];
187  logger(INFO, "\nRunning %", cmd.str());
188  int status = system(cmd.str().c_str());
189  }
190 
191  //read back output
192  Calibration dpm(argc, argv);
193  dpm.setName("CalibrationShearCell" + dpm.getParam());
194  Mdouble preCompressionShearStress = helpers::readFromFile(dpm.getName()+".out","preCompressionShearStress",0);
195  Mdouble preCompressionBulkDensity = helpers::readFromFile(dpm.getName()+".out","preCompressionBulkDensity", 0);
196 
197  std::vector<Mdouble> maxShearStress;
198  std::vector<Mdouble> bulkDensity;
199  for (const int s : normalStress) {
200  maxShearStress.push_back(
201  helpers::readFromFile(dpm.getName() + "-" + std::to_string(s) + "Pa.out",
202  "maxShearStress", 0));
203  bulkDensity.push_back(
204  helpers::readFromFile(dpm.getName() + "-" + std::to_string(s) + "Pa.out",
205  "bulkDensity", 0));
206  }
207 
208  //Write output file
209  std::stringstream out;
210  if (helpers::readFromCommandLine(argc,argv,"-ffc")) {
211  out << computeFFc(preCompressionNormalStress, preCompressionShearStress, normalStress, maxShearStress) << ' ';
212  //out << computeSimpleFFc(preCompressionNormalStress, preCompressionShearStress, normalStress, maxShearStress) << ' ';
213  } else {
214  for (const auto s : maxShearStress)
215  out << s << ' ';
216  for (const auto b : bulkDensity)
217  out << b << ' ';
218  }
219  helpers::writeToFile(dpm.getName()+".txt", out.str());
220  logger(INFO,"Output to %: %",dpm.getName()+".txt", out.str());
221 
222  return 0;
223 }
double computeFFc(Mdouble preCompressionNormalStress, Mdouble preCompressionShearStress, std::vector< double > normalStress, std::vector< double > maxShearStress)
Definition: CalibrationShearCell.cpp:73
Definition: Calibration.h:19
bool readFromCommandLine(int argc, char *argv[], std::string varName)
Returns true if command line arguments contain varName, false else.
Definition: CommandLineHelpers.cc:103
T readFromFile(const std::string fileName, const std::string varName, const T defaultValue)
Definition: FileIOHelpers.h:121
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: FileIOHelpers.cc:58

References computeFFc(), DPMBase::getName(), Calibration::getParam(), constants::i, INFO, logger, helpers::readFromCommandLine(), helpers::readFromFile(), DPMBase::setName(), and helpers::writeToFile().

◆ solveQuad()

std::pair<double , double > solveQuad ( double  a,
double  b,
double  c 
)
53 {
54  double disc = (b * b) - (4. * a * c); //The discriminant
55  if(disc < 0) //If the discriminant is less than 0
56  {
57  logger(WARN,"Discriminant < 0. Roots are imaginary.");
59  } else {
60  disc = sqrt(disc);
61  return {0.5 * (-b + disc) / a, 0.5 * (-b - disc) / a};
62  }
63 }
const Mdouble NaN
Definition: GeneralDefine.h:43

References logger, constants::NaN, and WARN.