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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
/*************************************************************************
* Copyright (C) 2006 by Bruno Chareyre *
* bruno.chareyre@grenoble-inp.fr *
* *
* This program is free software; it is licensed under the terms of the *
* GNU General Public License v2 or later. See file LICENSE for details. *
*************************************************************************/
#include <lib/high-precision/Constants.hpp>
#include <core/Aabb.hpp>
#include <core/Body.hpp>
#include <core/Dispatching.hpp>
#include <core/Interaction.hpp>
#include <core/InteractionLoop.hpp>
#include <core/Scene.hpp>
#include <pkg/common/Box.hpp>
#include <pkg/common/ElastMat.hpp>
#include <pkg/common/Facet.hpp>
#include <pkg/common/ForceResetter.hpp>
#include <pkg/common/GravityEngines.hpp>
#include <pkg/common/InsertionSortCollider.hpp>
#include <pkg/common/Sphere.hpp>
#include <pkg/common/Wall.hpp>
#include <pkg/dem/ElasticContactLaw.hpp>
#include <pkg/dem/FrictPhys.hpp>
#include <pkg/dem/GlobalStiffnessTimeStepper.hpp>
#include <pkg/dem/NewtonIntegrator.hpp>
#include <pkg/dem/TriaxialCompressionEngine.hpp>
#include <pkg/dem/TriaxialStateRecorder.hpp>
#include <pkg/dem/TriaxialStressController.hpp>
#include <preprocessing/dem/Shop.hpp>
#include <pkg/common/Bo1_Aabb.hpp>
#include <pkg/common/Wall.hpp>
#include <pkg/dem/Ig2_Box_Sphere_ScGeom.hpp>
#include <pkg/dem/Ig2_Facet_Sphere_ScGeom.hpp>
#include <pkg/dem/Ig2_Sphere_Sphere_ScGeom.hpp>
#include <boost/limits.hpp>
#include <boost/numeric/conversion/bounds.hpp>
#include <preprocessing/dem/SpherePack.hpp>
//#include<pkg/dem/MicroMacroAnalyser.hpp>
#include "TriaxialTest.hpp"
namespace yade { // Cannot have #include directive inside.
CREATE_LOGGER(TriaxialTest);
YADE_PLUGIN((TriaxialTest));
TriaxialTest::~TriaxialTest() { }
bool TriaxialTest::generate(string& message)
{
message = "";
if (facetWalls && wallWalls) { LOG_WARN("Turning TriaxialTest::facetWalls off, since wallWalls were selected as well."); }
shared_ptr<Body> body;
/* if _mean_radius is not given (i.e. <=0), then calculate it from box size;
* OTOH, if it is specified, scale the box preserving its ratio and lowerCorner so that the radius can be as requested
*/
Real porosity = .8;
SpherePack sphere_pack;
if (importFilename == "") {
Vector3r dimensions = upperCorner - lowerCorner;
Real volume = dimensions.x() * dimensions.y() * dimensions.z();
long num;
if (radiusMean <= 0) num = sphere_pack.makeCloud(lowerCorner, upperCorner, -1, radiusStdDev, numberOfGrains, false /*periodic?*/, porosity);
else {
bool fixedDims[3];
fixedDims[0] = fixedBoxDims.find('x') != string::npos;
fixedDims[1] = fixedBoxDims.find('y') != string::npos;
fixedDims[2] = fixedBoxDims.find('z') != string::npos;
int nScaled = (3 - (int)fixedDims[0] + (int)fixedDims[1] + (int)fixedDims[2]);
if (nScaled == 0)
throw std::invalid_argument(
"At most 2 (not 3) axes can have fixed dimensions in fixedBoxDims if scaling for given radiusMean.");
Real boxScaleFactor = radiusMean * pow((4 / 3.) * Mathr::PI * numberOfGrains / (volume * (1 - porosity)), 1. / nScaled);
LOG_INFO("Mean radius value of " << radiusMean << " requested, scaling " << nScaled << " dimensions by " << boxScaleFactor);
dimensions[0] *= fixedDims[0] ? 1. : boxScaleFactor;
dimensions[1] *= fixedDims[1] ? 1. : boxScaleFactor;
dimensions[2] *= fixedDims[2] ? 1. : boxScaleFactor;
upperCorner = lowerCorner + dimensions;
num = sphere_pack.makeCloud(
lowerCorner, upperCorner, radiusMean, radiusStdDev, numberOfGrains, false, -1, vector<Real>(), vector<Real>(), false, seed);
}
message += "Generated a sample with " + boost::lexical_cast<string>(num) + " spheres inside box of dimensions: ("
+ boost::lexical_cast<string>(upperCorner[0] - lowerCorner[0]) + "," + boost::lexical_cast<string>(upperCorner[1] - lowerCorner[1])
+ "," + boost::lexical_cast<string>(upperCorner[2] - lowerCorner[2]) + ").";
} else {
if (radiusMean > 0) LOG_WARN("radiusMean ignored, since importFilename specified.");
sphere_pack.fromFile(importFilename);
sphere_pack.aabb(lowerCorner, upperCorner);
}
// setup scene here, since radiusMean is now at its true value (if it was negative)
scene = shared_ptr<Scene>(new Scene);
positionRootBody(scene);
createActors(scene);
if (thickness < 0) thickness = radiusMean;
if (facetWalls || wallWalls) thickness = 0;
if (!facetWalls && !wallWalls) {
// bottom box
Vector3r center = Vector3r((lowerCorner[0] + upperCorner[0]) / 2, lowerCorner[1] - thickness / 2.0, (lowerCorner[2] + upperCorner[2]) / 2);
Vector3r halfSize = Vector3r(
wallOversizeFactor * math::abs(lowerCorner[0] - upperCorner[0]) / 2 + thickness,
thickness / 2.0,
wallOversizeFactor * math::abs(lowerCorner[2] - upperCorner[2]) / 2 + thickness);
createBox(body, center, halfSize, true);
scene->bodies->insert(body);
triaxialcompressionEngine->wall_bottom_id = body->getId();
// top box
center = Vector3r((lowerCorner[0] + upperCorner[0]) / 2, upperCorner[1] + thickness / 2.0, (lowerCorner[2] + upperCorner[2]) / 2);
halfSize = Vector3r(
wallOversizeFactor * math::abs(lowerCorner[0] - upperCorner[0]) / 2 + thickness,
thickness / 2.0,
wallOversizeFactor * math::abs(lowerCorner[2] - upperCorner[2]) / 2 + thickness);
createBox(body, center, halfSize, true);
scene->bodies->insert(body);
triaxialcompressionEngine->wall_top_id = body->getId();
// box 1
center = Vector3r(lowerCorner[0] - thickness / 2.0, (lowerCorner[1] + upperCorner[1]) / 2, (lowerCorner[2] + upperCorner[2]) / 2);
halfSize = Vector3r(
thickness / 2.0,
wallOversizeFactor * math::abs(lowerCorner[1] - upperCorner[1]) / 2 + thickness,
wallOversizeFactor * math::abs(lowerCorner[2] - upperCorner[2]) / 2 + thickness);
createBox(body, center, halfSize, true);
scene->bodies->insert(body);
triaxialcompressionEngine->wall_left_id = body->getId();
// box 2
center = Vector3r(upperCorner[0] + thickness / 2.0, (lowerCorner[1] + upperCorner[1]) / 2, (lowerCorner[2] + upperCorner[2]) / 2);
halfSize = Vector3r(
thickness / 2.0,
wallOversizeFactor * math::abs(lowerCorner[1] - upperCorner[1]) / 2 + thickness,
wallOversizeFactor * math::abs(lowerCorner[2] - upperCorner[2]) / 2 + thickness);
createBox(body, center, halfSize, true);
scene->bodies->insert(body);
triaxialcompressionEngine->wall_right_id = body->getId();
// box 3
center = Vector3r((lowerCorner[0] + upperCorner[0]) / 2, (lowerCorner[1] + upperCorner[1]) / 2, lowerCorner[2] - thickness / 2.0);
halfSize = Vector3r(
wallOversizeFactor * math::abs(lowerCorner[0] - upperCorner[0]) / 2 + thickness,
wallOversizeFactor * math::abs(lowerCorner[1] - upperCorner[1]) / 2 + thickness,
thickness / 2.0);
createBox(body, center, halfSize, true);
scene->bodies->insert(body);
triaxialcompressionEngine->wall_back_id = body->getId();
// box 4
center = Vector3r((lowerCorner[0] + upperCorner[0]) / 2, (lowerCorner[1] + upperCorner[1]) / 2, upperCorner[2] + thickness / 2.0);
halfSize = Vector3r(
wallOversizeFactor * math::abs(lowerCorner[0] - upperCorner[0]) / 2 + thickness,
wallOversizeFactor * math::abs(lowerCorner[1] - upperCorner[1]) / 2 + thickness,
thickness / 2.0);
createBox(body, center, halfSize, true);
scene->bodies->insert(body);
triaxialcompressionEngine->wall_front_id = body->getId();
}
size_t imax = sphere_pack.pack.size();
for (size_t i = 0; i < imax; i++) {
const SpherePack::Sph& sp(sphere_pack.pack[i]);
LOG_DEBUG("sphere (" << sp.c << " " << sp.r << ")");
createSphere(body, sp.c, sp.r, false, true);
scene->bodies->insert(body);
}
if (defaultDt < 0) {
defaultDt = Shop::PWaveTimeStep(scene);
scene->dt = defaultDt;
globalStiffnessTimeStepper->defaultDt = defaultDt;
LOG_INFO("Computed default (PWave) timestep " << defaultDt);
}
return true;
}
void TriaxialTest::createSphere(shared_ptr<Body>& body, Vector3r position, Real radius, bool /*big*/, bool /*dynamic*/)
{
body = shared_ptr<Body>(new Body);
body->groupMask = 2;
shared_ptr<Aabb> aabb(new Aabb);
shared_ptr<Sphere> iSphere(new Sphere);
body->state->blockedDOFs = State::DOF_NONE;
body->state->mass = 4.0 / 3.0 * Mathr::PI * radius * radius * radius * density;
body->state->inertia = Vector3r(
2.0 / 5.0 * body->state->mass * radius * radius,
2.0 / 5.0 * body->state->mass * radius * radius,
2.0 / 5.0 * body->state->mass * radius * radius);
body->state->pos = position;
shared_ptr<FrictMat> mat(new FrictMat);
mat->young = sphereYoungModulus;
mat->poisson = sphereKsDivKn;
mat->frictionAngle = compactionFrictionDeg * Mathr::PI / 180.0;
aabb->color = Vector3r(0, 1, 0);
iSphere->radius = radius;
//iSphere->color = Vector3r(0.4,0.1,0.1);
iSphere->color = Vector3r(math::unitRandom(), math::unitRandom(), math::unitRandom());
iSphere->color.normalize();
body->shape = iSphere;
body->bound = aabb;
body->material = mat;
}
void TriaxialTest::createBox(shared_ptr<Body>& body, Vector3r position, Vector3r extents, bool wire)
{
body = shared_ptr<Body>(new Body);
body->groupMask = 2;
body->state->blockedDOFs = State::DOF_ALL;
shared_ptr<Aabb> aabb(new Aabb);
aabb->color = Vector3r(1, 0, 0);
body->bound = aabb;
body->state->pos = position;
shared_ptr<FrictMat> mat(new FrictMat);
mat->young = sphereYoungModulus;
mat->poisson = sphereKsDivKn;
mat->frictionAngle = boxFrictionDeg * Mathr::PI / 180.0;
body->material = mat;
if (!facetWalls && !wallWalls) {
shared_ptr<Box> iBox(new Box);
iBox->extents = extents;
iBox->wire = wire;
iBox->color = Vector3r(1, 1, 1);
body->shape = iBox;
}
// guess the orientation
int ax0 = extents[0] == 0 ? 0 : (extents[1] == 0 ? 1 : 2);
int ax1 = (ax0 + 1) % 3, ax2 = (ax0 + 2) % 3;
if (facetWalls) {
Vector3r corner = position - extents; // "lower right" corner, with 90 degrees
Vector3r side1(Vector3r::Zero());
side1[ax1] = 4 * extents[ax1];
Vector3r side2(Vector3r::Zero());
side2[ax2] = 4 * extents[ax2];
Vector3r v[3];
v[0] = corner;
v[1] = corner + side1;
v[2] = corner + side2;
Vector3r cog = Shop::inscribedCircleCenter(v[0], v[1], v[2]);
shared_ptr<Facet> iFacet(new Facet);
for (int i = 0; i < 3; i++) {
iFacet->vertices[i] = v[i] - cog;
}
iFacet->color = Vector3r(1, 1, 1);
body->shape = iFacet;
}
if (wallWalls) {
shared_ptr<Wall> wall(new Wall);
wall->sense = 0; // interact from both sides, since unspecified here
wall->axis = ax0;
body->shape = wall;
}
}
void TriaxialTest::createActors(shared_ptr<Scene>& scene2)
{
// declaration of ‘scene’ shadows a member of ‘yade::TriaxialTest’ [-Werror=shadow]
shared_ptr<IGeomDispatcher> interactionGeometryDispatcher(new IGeomDispatcher);
interactionGeometryDispatcher->add(new Ig2_Sphere_Sphere_ScGeom);
interactionGeometryDispatcher->add(new Ig2_Facet_Sphere_ScGeom);
interactionGeometryDispatcher->add(new Ig2_Box_Sphere_ScGeom);
shared_ptr<IPhysDispatcher> interactionPhysicsDispatcher(new IPhysDispatcher);
shared_ptr<IPhysFunctor> ss(new Ip2_FrictMat_FrictMat_FrictPhys);
interactionPhysicsDispatcher->add(ss);
shared_ptr<GravityEngine> gravityCondition(new GravityEngine);
gravityCondition->gravity = gravity;
globalStiffnessTimeStepper = shared_ptr<GlobalStiffnessTimeStepper>(new GlobalStiffnessTimeStepper);
globalStiffnessTimeStepper->timeStepUpdateInterval = timeStepUpdateInterval;
globalStiffnessTimeStepper->defaultDt = defaultDt;
// moving walls to regulate the stress applied + compress when the packing is dense an stable
//cerr << "triaxialcompressionEngine = shared_ptr<TriaxialCompressionEngine> (new TriaxialCompressionEngine);" << std::endl;
triaxialcompressionEngine = shared_ptr<TriaxialCompressionEngine>(new TriaxialCompressionEngine);
//This prevent the deprecation warning. In fact this preprocessor in itself is becoming deprecated
triaxialcompressionEngine->warn = 1;
triaxialcompressionEngine->stiffnessUpdateInterval = wallStiffnessUpdateInterval; // = stiffness update interval
triaxialcompressionEngine->radiusControlInterval = radiusControlInterval; // = stiffness update interval
triaxialcompressionEngine->sigmaIsoCompaction = sigmaIsoCompaction;
triaxialcompressionEngine->sigmaLateralConfinement = sigmaLateralConfinement;
triaxialcompressionEngine->max_vel = maxWallVelocity;
triaxialcompressionEngine->thickness = thickness;
triaxialcompressionEngine->strainRate = strainRate;
triaxialcompressionEngine->StabilityCriterion = StabilityCriterion;
triaxialcompressionEngine->autoCompressionActivation = autoCompressionActivation;
triaxialcompressionEngine->autoUnload = autoUnload;
triaxialcompressionEngine->autoStopSimulation = autoStopSimulation;
triaxialcompressionEngine->internalCompaction = internalCompaction;
triaxialcompressionEngine->maxMultiplier = maxMultiplier;
triaxialcompressionEngine->finalMaxMultiplier = finalMaxMultiplier;
triaxialcompressionEngine->Key = Key;
triaxialcompressionEngine->noFiles = noFiles;
triaxialcompressionEngine->frictionAngleDegree = sphereFrictionDeg;
triaxialcompressionEngine->fixedPoroCompaction = false;
triaxialcompressionEngine->fixedPorosity = 1;
// recording global stress
if (recordIntervalIter > 0 && !noFiles) {
triaxialStateRecorder = shared_ptr<TriaxialStateRecorder>(new TriaxialStateRecorder);
triaxialStateRecorder->file = WallStressRecordFile + Key;
triaxialStateRecorder->iterPeriod = recordIntervalIter;
}
scene2->engines.clear();
scene2->engines.push_back(shared_ptr<Engine>(new ForceResetter));
shared_ptr<InsertionSortCollider> collider(new InsertionSortCollider);
scene2->engines.push_back(collider);
collider->verletDist = .5 * radiusMean;
collider->boundDispatcher->add(new Bo1_Sphere_Aabb);
collider->boundDispatcher->add(new Bo1_Box_Aabb);
collider->boundDispatcher->add(new Bo1_Facet_Aabb);
collider->boundDispatcher->add(new Bo1_Wall_Aabb);
shared_ptr<InteractionLoop> ids(new InteractionLoop);
ids->geomDispatcher = interactionGeometryDispatcher;
ids->physDispatcher = interactionPhysicsDispatcher;
ids->lawDispatcher = shared_ptr<LawDispatcher>(new LawDispatcher);
shared_ptr<Law2_ScGeom_FrictPhys_CundallStrack> see(new Law2_ScGeom_FrictPhys_CundallStrack);
ids->lawDispatcher->add(see);
scene2->engines.push_back(ids);
scene2->engines.push_back(globalStiffnessTimeStepper);
scene2->engines.push_back(triaxialcompressionEngine);
if (recordIntervalIter > 0 && !noFiles) scene2->engines.push_back(triaxialStateRecorder);
shared_ptr<NewtonIntegrator> newton(new NewtonIntegrator);
newton->damping = dampingForce;
scene2->engines.push_back(newton);
}
void TriaxialTest::positionRootBody(shared_ptr<Scene>& /*scene*/) { }
} // namespace yade
|