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

Classes

struct  ShearStageData
 

Functions

template<typename T >
std::pair< T, TgetLinearFit (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

54  {
55  //This part does the linear fit through the shear points and get the yield locus with slope and intercept
56  //Then we calculate the sigma_1 and sigma_c to compute flow function FFc
57  logger(INFO, "p % % tau % %", preCompressionNormalStress, toString(normalStress), preCompressionShearStress,
58  toString(maxShearStress));
59 
60  double sigmaC;
61  {
62  auto[slope, intercept] = getLinearFit(normalStress, maxShearStress);
63 
64  if (intercept < 0) {
65  logger(WARN, "y-intercept % <0; setting FFc to 100", intercept);
66  return 1000;
67  }
68  if (slope < 0) {
69  logger(WARN, "slope % <0; this does not make sense; setting FFc to 0", slope);
70  return 0;
71  }
72  //see ffc.nb
73  double arclength = sqrt(1+slope*slope);
74  sigmaC = 2*intercept*(arclength+slope);
75  }
76 
77  double sigma1;
78  {
79  auto[slope, intercept] = getLinearFit<double>({preCompressionNormalStress, normalStress[0]}, {preCompressionShearStress, maxShearStress[0]});
80  if (slope < 0) {
81  sigma1 = preCompressionShearStress + preCompressionShearStress;
82  logger(WARN, "slope % <0; setting sigma1 to %", slope, sigma1);
83  } else {
84  //see ffc.nb
85  double arclength = sqrt(1 + slope * slope);
86  sigma1 = preCompressionNormalStress * arclength * arclength
87  + intercept * slope
88  + arclength * (intercept + preCompressionNormalStress * slope);
89  }
90  }
91 
92  double ffc = sigma1/sigmaC;
93  logger(INFO,"p = %, sigmaC = %, sigma1 = %, ffc = %",preCompressionNormalStress, sigmaC, sigma1, ffc);
94  return ffc;
95 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
std::pair< T, T > getLinearFit(const std::vector< T > X, const std::vector< T > Y)
Definition: CalibrationShearCell.cpp:13
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:33
#define INFO(i)
Definition: mumps_solver.h:54
std::string toString(Mdouble value, unsigned precision)
converts a floating point number into a string with a given precision
Definition: StringHelpers.cc:17

References getLinearFit(), INFO, logger, sqrt(), 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

101  {
102  //This part does the linear fit through the shear points and get the yield locus with slope and intercept
103  //Then we calculate the sigma_1 and sigma_c to compute flow function FFc
104 
105  logger(INFO, "p % % tau % %", preCompressionNormalStress, toString(normalStress), preCompressionShearStress,
106  toString(maxShearStress));
107  auto [slope, intercept] = getLinearFit(normalStress,maxShearStress);
108 
109  if (intercept < 0) {
110  logger(WARN, "y-intercept % <0; setting FFc to 1000", intercept);
111  return 1000;
112  }
113  if (slope < 0) {
114  logger(WARN, "slope % <0; setting FFc to 1000", slope);
115  return 1000;
116  }
117 
118  //see ffc.nb
119  double arclength = sqrt(1+slope*slope);
120  double sigmaC = 2*intercept*(arclength+slope);
121  double sigma1 = preCompressionNormalStress*arclength*arclength
122  +intercept*slope
123  +arclength*(intercept+preCompressionNormalStress*slope);
124  double ffc = sigma1/sigmaC;
125  logger(INFO,"p = %, sigmaC = %, sigma1 = %, ffc = %",preCompressionNormalStress, sigmaC, sigma1, ffc);
126  return ffc;
127 }

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

◆ getLinearFit()

template<typename T >
std::pair<T,T> getLinearFit ( const std::vector< T X,
const std::vector< T Y 
)
14 {
15  size_t n = Y.size();
16  logger.assert_always(X.size()==n,"X and Y data sets have to be same size");
17  T xSum = 0, ySum = 0, xxSum = 0, xySum = 0;
18  for (long i = 0; i < n; i++)
19  {
20  xSum += X[i];
21  ySum += Y[i];
22  xxSum += X[i] * X[i];
23  xySum += X[i] * Y[i];
24  }
25  T slope = (n * xySum - xSum * ySum) / (n * xxSum - xSum * xSum);
26  T intercept = (ySum - slope * xSum) / Y.size();
27  logger(INFO,"Fit values: Slope %, intercept %",slope, intercept);
28  return {slope, intercept};
29 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
#define X
Definition: icosphere.cpp:20
const char Y
Definition: test/EulerAngles.cpp:32

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

Referenced by computeFFc(), and computeSimpleFFc().

◆ main()

int main ( int argc  ,
char argv[] 
)
141 {
142  // read in pre-compression stress and subsequent compression stresses
143  std::vector<double> normalStress =
144  helpers::readVectorFromCommandLine<double>(argc,argv,"-normalStress",4, {});
145  logger.assert_always(normalStress.size()>2,"You need at least one pre-compression stress and two compression stresses to compute an ffc");
146  double preCompressionNormalStress = normalStress[0];
147  normalStress.erase(normalStress.begin());
148 
149  //get the directory name
150  std::string dir = argv[0];
151  dir.resize(dir.size()-std::string("CalibrationShearCell").length());
152 
153  // run pre-compression stage
154  {
155  std::stringstream cmd;
156  cmd << dir << "CalibrationPrecompression";
157  for (int i = 1; i < argc; ++i) cmd << ' ' << argv[i];
158  logger(INFO, "\nRunning %", cmd.str());
159  int status = system(cmd.str().c_str());
160  }
161 
162  // run shear stages
163  for (const double s : normalStress) {
164  std::stringstream cmd;
165  cmd << dir << "CalibrationShearStage -compression " << s;
166  for (int i = 1; i < argc; ++i) cmd << ' ' << argv[i];
167  logger(INFO, "\nRunning %", cmd.str());
168  int status = system(cmd.str().c_str());
169  }
170 
171  //read back output
172  Calibration dpm(argc, argv);
173  dpm.setName("CalibrationShearCell" + dpm.getParam());
174  Mdouble preCompressionShearStress = helpers::readFromFile(dpm.getName()+".out","preCompressionShearStress",0);
175  Mdouble preCompressionBulkDensity = helpers::readFromFile(dpm.getName()+".out","preCompressionBulkDensity", 0);
176 
177  std::vector<Mdouble> maxShearStress;
178  std::vector<Mdouble> bulkDensity;
179  for (const int s : normalStress) {
180  maxShearStress.push_back(
181  helpers::readFromFile(dpm.getName() + "-" + std::to_string(s) + "Pa.out",
182  "maxShearStress", 0));
183  bulkDensity.push_back(
184  helpers::readFromFile(dpm.getName() + "-" + std::to_string(s) + "Pa.out",
185  "bulkDensity", 0));
186  }
187 
188  //Write output file
189  std::stringstream out;
190  if (helpers::readFromCommandLine(argc,argv,"-ffc")) {
191  out << computeFFc(preCompressionNormalStress, preCompressionShearStress, normalStress, maxShearStress) << ' ';
192  //out << computeSimpleFFc(preCompressionNormalStress, preCompressionShearStress, normalStress, maxShearStress) << ' ';
193  } else {
194  for (const auto s : maxShearStress)
195  out << s << ' ';
196  for (const auto b : bulkDensity)
197  out << b << ' ';
198  }
199  helpers::writeToFile(dpm.getName()+".txt", out.str());
200  logger(INFO,"Output to %: %",dpm.getName()+".txt", out.str());
201 
202  return 0;
203 }
double computeFFc(Mdouble preCompressionNormalStress, Mdouble preCompressionShearStress, std::vector< double > normalStress, std::vector< double > maxShearStress)
Definition: CalibrationShearCell.cpp:53
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: Calibration.h:23
RealScalar s
Definition: level1_cplx_impl.h:130
T readFromFile(const std::string &fileName, const std::string &varName, const T defaultValue)
Definition: FileIOHelpers.h:107
bool readFromCommandLine(int argc, char *argv[], const std::string &varName)
Returns true if command line arguments contain varName, false else.
Definition: CommandLineHelpers.cc:99
bool writeToFile(const std::string &filename, const std::string &filecontent)
Writes a string to a file.
Definition: FileIOHelpers.cc:29
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
std::string to_string(T object, unsigned float_precision=8)
Definition: oomph_utilities.h:189
std::ofstream out("Result.txt")

References b, computeFFc(), DPMBase::getName(), Calibration::getParam(), i, INFO, logger, out(), helpers::readFromCommandLine(), helpers::readFromFile(), s, DPMBase::setName(), oomph::Global_string_for_annotation::string(), oomph::StringConversion::to_string(), and helpers::writeToFile().

◆ solveQuad()

std::pair<double , double > solveQuad ( double  a,
double  b,
double  c 
)
33 {
34  double disc = (b * b) - (4. * a * c); //The discriminant
35  if(disc < 0) //If the discriminant is less than 0
36  {
37  logger(WARN,"Discriminant < 0. Roots are imaginary.");
39  } else {
40  disc = sqrt(disc);
41  return {0.5 * (-b + disc) / a, 0.5 * (-b - disc) / a};
42  }
43 }
const Scalar * a
Definition: level2_cplx_impl.h:32
int c
Definition: calibrate.py:100
const Mdouble NaN
Definition: GeneralDefine.h:22

References a, b, calibrate::c, logger, constants::NaN, sqrt(), and WARN.