Commit 6e894a3f authored by Dennis Gläser's avatar Dennis Gläser
Browse files

Merge branch 'feature/simplify-examples' into 'master'

Feature/cleanup-examples

See merge request tools/frackit!206
parents 95f6ab29 3ed481ef
Pipeline #2846 passed with stages
in 9 minutes and 49 seconds
...@@ -36,11 +36,10 @@ int main(int argc, char** argv) ...@@ -36,11 +36,10 @@ int main(int argc, char** argv)
// These points will be used as the quadrilateral centers. // These points will be used as the quadrilateral centers.
auto pointSampler = makeUniformPointSampler(domain); auto pointSampler = makeUniformPointSampler(domain);
// Sampler class for quadrilaterals. Per default, this uses // Sampler class for quadrilaterals. Per default, this uses uniform distributions
// uniform distributions for all parameters defining the quadrilaterals. // for all parameters defining the quadrilaterals. Quadrilateral samplers require
// Quadrilateral samplers require distributions for strike angle, dip angle, // distributions for strike angle, dip angle, edge length (see class description
// edge length (see class description for more details). Moreover, we define // for more details).
// a minimum edge length.
using QuadSampler = QuadrilateralSampler<worldDimension>; using QuadSampler = QuadrilateralSampler<worldDimension>;
using NormalDistro = std::normal_distribution<ctype>; using NormalDistro = std::normal_distribution<ctype>;
using UniformDistro = std::uniform_real_distribution<ctype>; using UniformDistro = std::uniform_real_distribution<ctype>;
......
import frackit.geometry as geometry import frackit.geometry as geometry
import random
import math
# we use the unit cube as domain # we use the unit cube as domain
box = geometry.Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0) box = geometry.Box(xmin=0.0, ymin=0.0, zmin=0.0,
xmax=1.0, ymax=1.0, zmax=1.0)
# we sample points uniformly within the domain # we sample points uniformly within the domain
from frackit.sampling import makeUniformPointSampler from frackit.sampling import makeUniformPointSampler
# returns a sampler from a gaussian distribution with mean and std deviation # returns a sampler from a gaussian distribution with mean and std deviation
def gaussianSampler(mean, stdDev): def gaussianSampler(mean, stdDev):
import random def sample(): return random.gauss(mean, stdDev)
def sample():
return random.gauss(mean, stdDev)
return sample return sample
# returns a sampler from a uniform distribution between min and max # returns a sampler from a uniform distribution between min and max
def uniformSampler(min, max): def uniformSampler(min, max):
import random def sample(): return random.uniform(min, max)
def sample():
return random.uniform(min, max)
return sample return sample
# we sample quadrialeterals within the box with gaussian distributions for the parameters # we sample quadrilaterals within the box with gaussian distributions for the parameters
from frackit.common import toRadians
from frackit.sampling import QuadrilateralSampler as QuadSampler from frackit.sampling import QuadrilateralSampler as QuadSampler
quadSampler1 = QuadSampler(makeUniformPointSampler(box), quadSampler1 = QuadSampler(pointSampler = makeUniformPointSampler(box),
gaussianSampler(toRadians(45.0), toRadians(5.0)), # strike angle strikeAngleSampler = gaussianSampler(math.radians(45.0), math.radians(5.0)),
gaussianSampler(toRadians(90.0), toRadians(5.0)), # dip angle dipAngleSampler = gaussianSampler(math.radians(90.0), math.radians(5.0)),
uniformSampler(0.4, 0.8), # strike length strikeLengthSampler = uniformSampler(0.4, 0.8),
uniformSampler(0.4, 0.8)) # dip length dipLengthSampler = uniformSampler(0.4, 0.8))
# sampler for quadrilaterals of the secondary orientation # sampler for quadrilaterals of the secondary orientation
quadSampler2 = QuadSampler(makeUniformPointSampler(box), quadSampler2 = QuadSampler(pointSampler = makeUniformPointSampler(box),
gaussianSampler(toRadians(0.0), toRadians(5.0)), # strike angle strikeAngleSampler = gaussianSampler(math.radians(0.0), math.radians(5.0)),
gaussianSampler(toRadians(0.0), toRadians(5.0)), # dip angle dipAngleSampler = gaussianSampler(math.radians(0.0), math.radians(5.0)),
uniformSampler(0.4, 0.8), # strike length strikeLengthSampler = uniformSampler(0.4, 0.8),
uniformSampler(0.4, 0.8)) # dip length dipLengthSampler = uniformSampler(0.4, 0.8))
# We want to enforce some constraints on the set of quadrilaterals. # We want to enforce some constraints on the set of quadrilaterals.
# In particular, for entities of the same set we want a minimum spacing # In particular, for entities of the same set we want a minimum spacing
...@@ -45,14 +43,14 @@ quadSampler2 = QuadSampler(makeUniformPointSampler(box), ...@@ -45,14 +43,14 @@ quadSampler2 = QuadSampler(makeUniformPointSampler(box),
from frackit.entitynetwork import EntityNetworkConstraints from frackit.entitynetwork import EntityNetworkConstraints
constraintsOnSelf = EntityNetworkConstraints() constraintsOnSelf = EntityNetworkConstraints()
constraintsOnSelf.setMinDistance(0.05) constraintsOnSelf.setMinDistance(0.05)
constraintsOnSelf.setMinIntersectingAngle(toRadians(30.0)) constraintsOnSelf.setMinIntersectingAngle(math.radians(30.0))
constraintsOnSelf.setMinIntersectionMagnitude(0.05) constraintsOnSelf.setMinIntersectionMagnitude(0.05)
constraintsOnSelf.setMinIntersectionDistance(0.05) constraintsOnSelf.setMinIntersectionDistance(0.05)
# with respect to entities of the other set, we want to have larger intersection angles # with respect to entities of the other set, we want to have larger intersection angles
constraintsOnOther = EntityNetworkConstraints() constraintsOnOther = EntityNetworkConstraints()
constraintsOnOther.setMinDistance(0.05) constraintsOnOther.setMinDistance(0.05)
constraintsOnOther.setMinIntersectingAngle(toRadians(40.0)); constraintsOnOther.setMinIntersectingAngle(math.radians(40.0))
constraintsOnOther.setMinIntersectionMagnitude(0.05) constraintsOnOther.setMinIntersectionMagnitude(0.05)
constraintsOnOther.setMinIntersectionDistance(0.05) constraintsOnOther.setMinIntersectionDistance(0.05)
...@@ -105,16 +103,16 @@ print("\n --- Finished entity sampling ---\n") ...@@ -105,16 +103,16 @@ print("\n --- Finished entity sampling ---\n")
# We can now create an entity network from the two sets # We can now create an entity network from the two sets
from frackit.entitynetwork import EntityNetworkBuilder from frackit.entitynetwork import EntityNetworkBuilder
builder = EntityNetworkBuilder() builder = EntityNetworkBuilder()
builder.addEntities(entities1); builder.addEntities(entities1)
builder.addEntities(entities2); builder.addEntities(entities2)
# let the builder construct the network and write it to gmsh file format # let the builder construct the network and write it to gmsh file format
print("\n --- Constructing entity network from the raw entities ---\n") print("\n --- Constructing entity network from the raw entities ---\n")
network = builder.build(); network = builder.build()
print("\n --- Writing .geo file ---\n") print("\n --- Writing .geo file ---\n")
from frackit.io import GmshWriter from frackit.io import GmshWriter
writer = GmshWriter(network); writer = GmshWriter(network)
writer.setMeshSize(GmshWriter.GeometryTag.entity, 0.1) writer.setMeshSize(GmshWriter.GeometryTag.entity, 0.1)
writer.write("network") # filename of the .geo files (will add extension .geo automatically) writer.write("network") # filename of the .geo files (will add extension .geo automatically)
......
...@@ -67,7 +67,7 @@ raw entities. This can potentially fail to detect small length scales that appea ...@@ -67,7 +67,7 @@ raw entities. This can potentially fail to detect small length scales that appea
the entities to the domain. A possibilty to address this and make the algorithm more robust the entities to the domain. A possibilty to address this and make the algorithm more robust
(but computationally more demanding) is discussed at the end of this page. (but computationally more demanding) is discussed at the end of this page.
As you can see in the above code snippet, the `Cylinder` class provides functions for obtaining th As you can see in the above code snippet, the `Cylinder` class provides functions for obtaining the
representations of the top, bottom and lateral boundaries. The top and bottom boundaries are representations of the top, bottom and lateral boundaries. The top and bottom boundaries are
represented by instances of the `Disk` class, while the lateral surface is described by the class represented by instances of the `Disk` class, while the lateral surface is described by the class
`CylinderSurface`. Please also note that for the lateral surface, we enforce the constraints `CylinderSurface`. Please also note that for the lateral surface, we enforce the constraints
......
import frackit.geometry as geometry import frackit.geometry as geometry
import random
import math
# we want to use a cylindrical domain with radius=0.5 and height=1.0 domain = geometry.Cylinder(radius=0.5, height=1.0)
domain = geometry.Cylinder(0.5, 1.0)
# we sample points uniformly within the shifted unit cube such # we sample points uniformly within the shifted unit cube such
# that the origin is in the center of the bottom boundary of the domain # that the origin is in the center of the bottom boundary of the domain
from frackit.sampling import makeUniformPointSampler from frackit.sampling import makeUniformPointSampler
box = geometry.Box(-0.5, -0.5, 0.0, 0.5, 0.5, 1.0) box = geometry.Box(xmin=-0.5, ymin=-0.5, zmin=0.0,
xmax=0.5, ymax=0.5, zmax=1.0)
pointSampler = makeUniformPointSampler(box) pointSampler = makeUniformPointSampler(box)
# returns a sampler from a gaussian distribution with mean and std deviation # returns a sampler from a gaussian distribution with mean and std deviation
def gaussianSampler(mean, stdDev): def gaussianSampler(mean, stdDev):
import random def sample(): return random.gauss(mean, stdDev)
def sample():
return random.gauss(mean, stdDev)
return sample return sample
#returns a sampler from a uniform distribution between min and max #returns a sampler from a uniform distribution between min and max
def uniformSampler(min, max): def uniformSampler(min, max):
import random def sample(): return random.uniform(min, max)
def sample():
return random.uniform(min, max)
return sample return sample
# we sample quadrialeterals within the box with gaussian distributions for the parameters # we sample quadrialeterals within the box with gaussian distributions for the parameters
from frackit.common import toRadians
from frackit.sampling import QuadrilateralSampler as QuadSampler from frackit.sampling import QuadrilateralSampler as QuadSampler
quadSampler1 = QuadSampler(pointSampler, quadSampler1 = QuadSampler(pointSampler = pointSampler,
gaussianSampler(toRadians(45.0), toRadians(5.0)), # strike angle strikeAngleSampler = gaussianSampler(math.radians(45.0), math.radians(5.0)),
gaussianSampler(toRadians(90.0), toRadians(5.0)), # dip angle dipAngleSampler = gaussianSampler(math.radians(90.0), math.radians(5.0)),
uniformSampler(0.4, 0.6), # strike length strikeLengthSampler = uniformSampler(0.4, 0.6),
uniformSampler(0.4, 0.6)) # dip length dipLengthSampler = uniformSampler(0.4, 0.6))
# sampler for quadrilaterals of the secondary orientation # sampler for quadrilaterals of the secondary orientation
quadSampler2 = QuadSampler(pointSampler, quadSampler2 = QuadSampler(pointSampler = pointSampler,
gaussianSampler(toRadians(0.0), toRadians(5.0)), # strike angle strikeAngleSampler = gaussianSampler(math.radians(0.0), math.radians(5.0)),
gaussianSampler(toRadians(0.0), toRadians(5.0)), # dip angle dipAngleSampler = gaussianSampler(math.radians(0.0), math.radians(5.0)),
uniformSampler(0.4, 0.6), # strike length strikeLengthSampler = uniformSampler(0.4, 0.6),
uniformSampler(0.4, 0.6)) # dip length dipLengthSampler = uniformSampler(0.4, 0.6))
# constructs a constraints object with default settings for this example # constructs a constraints object with default settings for this example
from frackit.entitynetwork import EntityNetworkConstraints from frackit.entitynetwork import EntityNetworkConstraints
def makeDefaultConstraints(): def makeDefaultConstraints():
c = EntityNetworkConstraints() c = EntityNetworkConstraints()
c.setMinDistance(0.05) c.setMinDistance(0.05)
c.setMinIntersectingAngle(toRadians(30.0)) c.setMinIntersectingAngle(math.radians(30.0))
c.setMinIntersectionMagnitude(0.05) c.setMinIntersectionMagnitude(0.05)
c.setMinIntersectionDistance(0.05) c.setMinIntersectionDistance(0.05)
return c return c
...@@ -59,7 +56,7 @@ constraintsOnSelf = makeDefaultConstraints() ...@@ -59,7 +56,7 @@ constraintsOnSelf = makeDefaultConstraints()
# with respect to entities of the other set, we want to have larger intersection angles # with respect to entities of the other set, we want to have larger intersection angles
constraintsOnOther = makeDefaultConstraints() constraintsOnOther = makeDefaultConstraints()
constraintsOnOther.setMinIntersectingAngle(toRadians(40.0)); constraintsOnOther.setMinIntersectingAngle(math.radians(40.0))
# we use the default constraints w.r.t. to the domain boundary # we use the default constraints w.r.t. to the domain boundary
constraintsOnBoundary = makeDefaultConstraints() constraintsOnBoundary = makeDefaultConstraints()
...@@ -114,7 +111,7 @@ while not status.finished(): ...@@ -114,7 +111,7 @@ while not status.finished():
# reject entities whose contained part is too small # reject entities whose contained part is too small
from frackit.geometry import computeContainedMagnitude from frackit.geometry import computeContainedMagnitude
containedArea = computeContainedMagnitude(quad, domain); containedArea = computeContainedMagnitude(quad, domain)
if (containedArea < 0.01): if (containedArea < 0.01):
status.increaseRejectedCounter() status.increaseRejectedCounter()
continue continue
...@@ -135,19 +132,19 @@ from frackit.entitynetwork import ContainedEntityNetworkBuilder ...@@ -135,19 +132,19 @@ from frackit.entitynetwork import ContainedEntityNetworkBuilder
builder = ContainedEntityNetworkBuilder() builder = ContainedEntityNetworkBuilder()
# our domain confines all entities and receives the id 1 # our domain confines all entities and receives the id 1
builder.addConfiningSubDomain(domain, Id(1)); builder.addConfiningSubDomain(domain, Id(1))
# define all entities to be embedded in this domain # define all entities to be embedded in this domain
builder.addSubDomainEntities(entities1, Id(1)); builder.addSubDomainEntities(entities1, Id(1))
builder.addSubDomainEntities(entities2, Id(1)); builder.addSubDomainEntities(entities2, Id(1))
# let the builder construct the network and write it to gmsh file format # let the builder construct the network and write it to gmsh file format
print("\n --- Constructing entity network from the raw entities ---\n") print("\n --- Constructing entity network from the raw entities ---\n")
network = builder.build(); network = builder.build()
print("\n --- Writing .geo file ---\n") print("\n --- Writing .geo file ---\n")
from frackit.io import GmshWriter from frackit.io import GmshWriter
writer = GmshWriter(network); writer = GmshWriter(network)
writer.setMeshSize(GmshWriter.GeometryTag.entity, 0.1) writer.setMeshSize(GmshWriter.GeometryTag.entity, 0.1)
writer.setMeshSize(GmshWriter.GeometryTag.subDomain, 0.1) writer.setMeshSize(GmshWriter.GeometryTag.subDomain, 0.1)
writer.write("network") # filename of the .geo files (will add extension .geo automatically) writer.write("network") # filename of the .geo files (will add extension .geo automatically)
......
...@@ -17,6 +17,8 @@ realize this example using the Frackit python bindings.__ ...@@ -17,6 +17,8 @@ realize this example using the Frackit python bindings.__
* use the `MultiGeometrySampler` and `MultiGeometryEntitySet` classes to conveniently compose a network out of multiple entity geometries * use the `MultiGeometrySampler` and `MultiGeometryEntitySet` classes to conveniently compose a network out of multiple entity geometries
* use the `ConstraintsMatrix` class to conveniently define several constraints to be fulfilled among different entity sets * use the `ConstraintsMatrix` class to conveniently define several constraints to be fulfilled among different entity sets
* define multiple confining/non-confining sub-domains to place the entities in * define multiple confining/non-confining sub-domains to place the entities in
* register the reasons for entity rejections within the `Status` class and print a summary
* Build and write networks that are confined/unconfined to their embedding domains
### Read in a domain geometry ### Read in a domain geometry
......
...@@ -59,9 +59,9 @@ int main(int argc, char** argv) ...@@ -59,9 +59,9 @@ int main(int argc, char** argv)
// Compute its volume and get the boundary faces for constraint evaluation. // Compute its volume and get the boundary faces for constraint evaluation.
const auto& networkDomain = solids[1]; const auto& networkDomain = solids[1];
const auto domainVolume = computeMagnitude(networkDomain); const auto domainVolume = computeMagnitude(networkDomain);
const auto shells = OCCUtilities::getShells(networkDomain); const auto domainShell = OCCUtilities::getShells(networkDomain);
if (shells.size() != 1) throw std::runtime_error("Expected a single shell bounding the domain"); if (domainShell.size() != 1) throw std::runtime_error("Expected a single shell bounding the domain");
const auto domainBoundaryFaces = OCCUtilities::getFaces(shells[0]); const auto domainBoundaryFaces = OCCUtilities::getFaces(domainShell[0]);
...@@ -157,14 +157,13 @@ int main(int argc, char** argv) ...@@ -157,14 +157,13 @@ int main(int argc, char** argv)
// of entity sets of different geometry types. // of entity sets of different geometry types.
MultiGeometryEntitySet<Disk, Quad> entitySets; MultiGeometryEntitySet<Disk, Quad> entitySets;
// Helper class for terminal output of the creation // Helper class for terminal output of the creation progress
// progress and definition of stop criterion etc // and definition of stop criterion etc. Check if a value has
// Check if a value has been passed via the command line, // been passed via the command line, otherwise use the defaults.
// otherwise use the defaults. This is used in the test suite // This is used in the test suite to speed up testing time.
// to speed up testing time.
SamplingStatus status; SamplingStatus status;
status.setTargetCount(diskSetId, (argc > 1 ? std::stoi(argv[1]) : 12)); // we want 11 entities of orientation 1 status.setTargetCount(diskSetId, (argc > 1 ? std::stoi(argv[1]) : 12)); // desired number of entities of orientation 1
status.setTargetCount(quadSetId, (argc > 1 ? std::stoi(argv[1]) : 16)); // we want 13 entities of orientation 2 status.setTargetCount(quadSetId, (argc > 1 ? std::stoi(argv[1]) : 16)); // desired number of entities of orientation 2
// The actual network generation loop // The actual network generation loop
ctype containedNetworkArea = 0.0; ctype containedNetworkArea = 0.0;
...@@ -179,9 +178,9 @@ int main(int argc, char** argv) ...@@ -179,9 +178,9 @@ int main(int argc, char** argv)
if (status.finished(id)) if (status.finished(id))
{ status.increaseRejectedCounter("set finished"); continue; } { status.increaseRejectedCounter("set finished"); continue; }
// Moreover, we want to avoid small fragments (< 250 m²) // Moreover, we want to avoid small fragments
const auto containedArea = computeContainedMagnitude(geom, networkDomain); const auto containedArea = computeContainedMagnitude(geom, networkDomain);
if (containedArea < 350.0) if (containedArea < 250.0)
{ status.increaseRejectedCounter("minimum contained area violation"); continue; } { status.increaseRejectedCounter("minimum contained area violation"); continue; }
// enforce constraints w.r.t. to the other entities // enforce constraints w.r.t. to the other entities
......
...@@ -9,9 +9,8 @@ print("\n\n" ...@@ -9,9 +9,8 @@ print("\n\n"
#################################################### ####################################################
# 1. Read in the domain geometry from .brep file. ## # 1. Read in the domain geometry from .brep file. ##
# The file name is defined in CMakeLists.txt ##
#################################################### ####################################################
from frackit.occutilities import readShape, getSolids, getShells, getFaces, getBoundingBox from frackit.occutilities import readShape, getSolids, getShells, getFaces
domainShape = readShape("layers.brep") domainShape = readShape("layers.brep")
# obtain the three solids contained in the file # obtain the three solids contained in the file
...@@ -22,12 +21,10 @@ if len(solids) != 3: sys.exit("Expected the .brep file to contain 3 solids") ...@@ -22,12 +21,10 @@ if len(solids) != 3: sys.exit("Expected the .brep file to contain 3 solids")
# Compute its volume and get the boundary faces for constraint evaluation. # Compute its volume and get the boundary faces for constraint evaluation.
from frackit.geometry import computeMagnitude from frackit.geometry import computeMagnitude
networkDomain = solids[1] networkDomain = solids[1]
domainVolume = computeMagnitude(networkDomain); domainVolume = computeMagnitude(networkDomain)
shells = getShells(networkDomain) domainShell = getShells(networkDomain)
if len(shells) != 1: sys.exit("Expected a single shell bounding the domain") if len(domainShell) != 1: sys.exit("Expected a single shell bounding the domain")
domainBoundaryFaces = getFaces(domainShell[0])
domainBoundaryFaces = getFaces(shells[0])
if len(domainBoundaryFaces) != 6: sys.exit("Expected 6 faces to bound the domain")
############################################################################## ##############################################################################
...@@ -36,9 +33,8 @@ if len(domainBoundaryFaces) != 6: sys.exit("Expected 6 faces to bound the domain ...@@ -36,9 +33,8 @@ if len(domainBoundaryFaces) != 6: sys.exit("Expected 6 faces to bound the domain
############################################################################## ##############################################################################
# Bounding box of the domain in which we want to place the entities # Bounding box of the domain in which we want to place the entities
# In order for this to work we parse the solid back into a wrapper around a BRep shape from frackit.geometry import OCCShapeWrapper, getBoundingBox
from frackit.geometry import Box, OCCShapeWrapper domainBBox = getBoundingBox(networkDomain)
domainBBox = getBoundingBox( OCCShapeWrapper(networkDomain) )
# creates a uniform sampler within an interval # creates a uniform sampler within an interval
import random import random
...@@ -51,22 +47,24 @@ def normalSampler(mean, stdDev): ...@@ -51,22 +47,24 @@ def normalSampler(mean, stdDev):
def sample(): return random.gauss(mean, stdDev) def sample(): return random.gauss(mean, stdDev)
return sample return sample
from frackit.common import toRadians, Id import math
from frackit.common import Id
from frackit.sampling import DiskSampler, QuadrilateralSampler, makeUniformPointSampler from frackit.sampling import DiskSampler, QuadrilateralSampler, makeUniformPointSampler
# sampler for disks (orientation 1) # sampler for disks (orientation 1)
diskSampler = DiskSampler(makeUniformPointSampler(domainBBox), # sampler for disk center points diskSampler = DiskSampler(pointSampler = makeUniformPointSampler(domainBBox),
uniformSampler(30.0, 6.5), # major axis length: mean value & standard deviation majAxisSampler = uniformSampler(30.0, 6.5),
uniformSampler(24.0, 4.5), # minor axis length: mean value & standard deviation minAxisSampler = uniformSampler(24.0, 4.5),
normalSampler(toRadians(0.0), toRadians(7.5)), # rotation around x-axis: mean value & standard deviation xAngleSampler = normalSampler(math.radians(0.0), math.radians(7.5)),
normalSampler(toRadians(0.0), toRadians(7.5)), # rotation around y-axis: mean value & standard deviation yAngleSampler = normalSampler(math.radians(0.0), math.radians(7.5)),
normalSampler(toRadians(0.0), toRadians(7.5))) # rotation around z-axis: mean value & standard deviation zAngleSampler = normalSampler(math.radians(0.0), math.radians(7.5)))
# sampler for quadrilaterals (orientation 2) # sampler for quadrilaterals (orientation 2)
quadSampler = QuadrilateralSampler(makeUniformPointSampler(domainBBox), # sampler for quadrilateral center points quadSampler = QuadrilateralSampler(pointSampler = makeUniformPointSampler(domainBBox),
normalSampler(toRadians(45.0), toRadians(5.0)), # strike angle: mean value & standard deviation strikeAngleSampler = normalSampler(math.radians(45.0), math.radians(5.0)),
normalSampler(toRadians(90.0), toRadians(5.0)), # dip angle: mean value & standard deviation dipAngleSampler = normalSampler(math.radians(90.0), math.radians(5.0)),
uniformSampler(30.0, 60.0), # strike length strikeLengthSampler = uniformSampler(30.0, 60.0),
uniformSampler(30.0, 60.0)) # dip length dipLengthSampler = uniformSampler(30.0, 60.0))
# Define ids for the two entity sets # Define ids for the two entity sets
diskSetId = Id(1) # we give the set of orientation one, consisting of disks, the id 1 diskSetId = Id(1) # we give the set of orientation one, consisting of disks, the id 1
...@@ -84,7 +82,7 @@ from frackit.entitynetwork import EntityNetworkConstraints, EntityNetworkConstra ...@@ -84,7 +82,7 @@ from frackit.entitynetwork import EntityNetworkConstraints, EntityNetworkConstra
def makeDefaultConstraints(): def makeDefaultConstraints():
c = EntityNetworkConstraints() c = EntityNetworkConstraints()
c.setMinDistance(2.5) c.setMinDistance(2.5)
c.setMinIntersectingAngle(toRadians(25.0)) c.setMinIntersectingAngle(math.radians(25.0))
c.setMinIntersectionMagnitude(5.0) c.setMinIntersectionMagnitude(5.0)
c.setMinIntersectionDistance(2.5) c.setMinIntersectionDistance(2.5)
return c return c
...@@ -100,7 +98,7 @@ constraints2.setMinDistance(5.0) ...@@ -100,7 +98,7 @@ constraints2.setMinDistance(5.0)
# Define constraints between entities of different sets # Define constraints between entities of different sets
constraintsOnOther = makeDefaultConstraints() constraintsOnOther = makeDefaultConstraints()
constraintsOnOther.setMinDistance(2.5) constraintsOnOther.setMinDistance(2.5)
constraintsOnOther.setMinIntersectingAngle(toRadians(40.0)) constraintsOnOther.setMinIntersectingAngle(math.radians(40.0))
# We can use the constraints matrix to facilitate constraint evaluation # We can use the constraints matrix to facilitate constraint evaluation
constraintsMatrix = EntityNetworkConstraintsMatrix() constraintsMatrix = EntityNetworkConstraintsMatrix()
...@@ -116,7 +114,7 @@ constraintsMatrix.addConstraints(constraintsOnOther, # constraint instance ...@@ -116,7 +114,7 @@ constraintsMatrix.addConstraints(constraintsOnOther, # constraint instance
# Moreover, we define constraints w.r.t. the domain boundary # Moreover, we define constraints w.r.t. the domain boundary
constraintsOnDomain = makeDefaultConstraints() constraintsOnDomain = makeDefaultConstraints()
constraintsOnDomain.setMinIntersectingAngle(toRadians(15.0)) constraintsOnDomain.setMinIntersectingAngle(math.radians(15.0))
########################### ###########################
...@@ -127,15 +125,15 @@ constraintsOnDomain.setMinIntersectingAngle(toRadians(15.0)) ...@@ -127,15 +125,15 @@ constraintsOnDomain.setMinIntersectingAngle(toRadians(15.0))
# progress and definition of stop criterion etc # progress and definition of stop criterion etc
from frackit.sampling import SamplingStatus from frackit.sampling import SamplingStatus
status = SamplingStatus() status = SamplingStatus()
status.setTargetCount(diskSetId, 12) # we want 11 entities of orientation 1 status.setTargetCount(diskSetId, 12) # number of desired entities of orientation 1
status.setTargetCount(quadSetId, 16) # we want 13 entities of orientation 2 status.setTargetCount(quadSetId, 16) # number of desired entities of orientation 2
# store all entity sets in a dictionary # store all entity sets in a dictionary
entitySets = {diskSetId: [], quadSetId: []} entitySets = {diskSetId: [], quadSetId: []}
# Alternate between set 1 & set 2 during sampling phase # Alternate between set 1 & set 2 during sampling phase
sampleIntoSet1 = True sampleIntoSet1 = True
containedNetworkArea = 0.0; containedNetworkArea = 0.0
while not status.finished(): while not status.finished():
id = diskSetId if sampleIntoSet1 else quadSetId id = diskSetId if sampleIntoSet1 else quadSetId
geom = diskSampler() if sampleIntoSet1 else quadSampler() geom = diskSampler() if sampleIntoSet1 else quadSampler()
...@@ -146,10 +144,10 @@ while not status.finished(): ...@@ -146,10 +144,10 @@ while not status.finished():
status.increaseRejectedCounter("set finished") status.increaseRejectedCounter("set finished")
continue continue
# Moreover, we want to avoid small fragments (< 250 m²) # Moreover, we want to avoid small fragments
from frackit.geometry import computeContainedMagnitude from frackit.geometry import computeContainedMagnitude
containedArea = computeContainedMagnitude(geom, networkDomain); containedArea = computeContainedMagnitude(geom, networkDomain)
if containedArea < 350.0: if containedArea < 250.0:
status.increaseRejectedCounter("minimum contained area violation") status.increaseRejectedCounter("minimum contained area violation")
continue continue
...@@ -171,17 +169,17 @@ while not status.finished(): ...@@ -171,17 +169,17 @@ while not status.finished():
status.print() status.print()
# keep track of entity area # keep track of entity area
containedNetworkArea += containedArea; containedNetworkArea += containedArea
# sample from the other set next time # sample from the other set next time
sampleIntoSet1 = not sampleIntoSet1 sampleIntoSet1 = not sampleIntoSet1
# print the final entity density # print the final entity density
density = containedNetworkArea/domainVolume; density