diff --git a/dune/tectonic/factories/strikeslipfactory.cc b/dune/tectonic/factories/strikeslipfactory.cc index 9449ff9531e9e39c3e2bd09ae2711059f5af8461..c790ad89cae9acddecaae7fd81f12e9b4bd8424e 100644 --- a/dune/tectonic/factories/strikeslipfactory.cc +++ b/dune/tectonic/factories/strikeslipfactory.cc @@ -2,6 +2,9 @@ #include "config.h" #endif +#include <vector> +#include <regex> + #include <dune/fufem/geometry/convexpolyhedron.hh> #include <dune/contact/projections/normalprojection.hh> @@ -14,6 +17,34 @@ #include "strikeslipfactory.hh" +template <class HostGridType, class VectorTEMPLATE> +std::vector<double> StrikeSlipFactory<HostGridType, VectorTEMPLATE>::parsePatchString(const std::string& patch_str) { + std::vector<double> res; + + std::string str = patch_str; + std::regex my_regex("[0-9]+\\.[0-9]+"); + + double lower = 0.0; + std::smatch match; + while (std::regex_search(str, match, my_regex)) { + double newVal = atof(match[0].str().c_str()); + + if (newVal <= lower) { + DUNE_THROW(Dune::Exception, "Invalid patches object in .cfg file: Interval boundaries are expected in ascending order."); + } + lower = newVal; + + res.push_back(newVal); + str = match.suffix(); + } + + if (res.size() % 2 != 0) { + DUNE_THROW(Dune::Exception, "Invalid patches object in .cfg file: An even number of doubles representing a sequence of intervals is expected."); + } + + return res; +} + template <class HostGridType, class VectorTEMPLATE> void StrikeSlipFactory<HostGridType, VectorTEMPLATE>::setBodies() { // set up cuboid geometries @@ -35,10 +66,24 @@ void StrikeSlipFactory<HostGridType, VectorTEMPLATE>::setBodies() { //triangleGeometries_[1]->addWeakeningPatch(frictionParset, origins[1], {origins[1][0] + lengths[1], origins[1][1], 0}); #elif MY_DIM == 2 triangleGeometries_[0] = std::make_shared<TriangleGeometry>(origin, lengths[0], heights[0]); - triangleGeometries_[0]->addWeakeningPatch(frictionParset, triangleGeometries_[0]->A(), triangleGeometries_[0]->C()); - triangleGeometries_[1] = std::make_shared<TriangleGeometry>(triangleGeometries_[0]->C(), -lengths[1], -heights[1]); - triangleGeometries_[1]->addWeakeningPatch(frictionParset, triangleGeometries_[1]->A(), triangleGeometries_[1]->C()); + + // parse weakening patches + using Patches = std::vector<std::array<double, 2> >; + std::string patches_str = this->parset_.template get<std::string>("boundary.friction.weakening.patches"); + + auto patches = parsePatchString(patches_str); + for (size_t i=0; i<patches.size(); i++) { + auto start1 = triangleGeometries_[1]->C() + patches[i]*(triangleGeometries_[1]->A() - triangleGeometries_[1]->C()); + auto end1 = triangleGeometries_[1]->C() + patches[i+1]*(triangleGeometries_[1]->A() - triangleGeometries_[1]->C()); + triangleGeometries_[1]->addWeakeningPatch(frictionParset, start1, end1); + + auto start0 = triangleGeometries_[0]->A() + patches[i]*(triangleGeometries_[0]->C() - triangleGeometries_[0]->A()); + auto end0 = triangleGeometries_[0]->A() + patches[i+1]*(triangleGeometries_[0]->C() - triangleGeometries_[0]->A()); + triangleGeometries_[0]->addWeakeningPatch(frictionParset, start0, end0); + i++; + } + #else #error CuboidGeometry only supports 2D and 3D!" #endif diff --git a/dune/tectonic/factories/strikeslipfactory.hh b/dune/tectonic/factories/strikeslipfactory.hh index 0c3d551e812c4616ebfaf401c89c573f876ddc36..1201cb0e426e161f830d7fbfd4d9a0d91cbb45d3 100644 --- a/dune/tectonic/factories/strikeslipfactory.hh +++ b/dune/tectonic/factories/strikeslipfactory.hh @@ -81,6 +81,8 @@ template <class HostGridType, class VectorType> class StrikeSlipFactory : public return {0, 0, 1}; #endif } + + std::vector<double> parsePatchString(const std::string& patch_str); }; #endif