Skip to content

Commit 775427d

Browse files
feat(applications): implement fracture application
1 parent d526b8f commit 775427d

10 files changed

Lines changed: 492 additions & 195 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#pragma once
2+
3+
#include <geode/stochastic/inference/target_statistics.hpp>
4+
#include <geode/stochastic/sampling/direct/object_set_sampler/segment_set_sampler.hpp>
5+
#include <geode/stochastic/sampling/mcmc/helpers/simulation_context.hpp>
6+
#include <geode/stochastic/sampling/mcmc/simulation_runner.hpp>
7+
8+
namespace geode
9+
{
10+
using Fracture = OwnerSegment2D;
11+
using FractureSamplerConfig = ObjectSamplerConfig< Fracture >;
12+
using FractureSimulationContext = SimulationContext< Fracture >;
13+
using FractureSimulationRunner = SimulationRunner< Fracture >;
14+
15+
struct FractureSetDescription
16+
{
17+
std::string fset_name;
18+
19+
FractureSamplerConfig sampler;
20+
double birth_ratio{ 1.0 };
21+
double death_ratio{ 1.0 };
22+
double change_ratio{ 1.0 };
23+
24+
std::string density_name() const
25+
{
26+
return absl::StrCat( fset_name, "_p20" );
27+
}
28+
double p20{ 0. };
29+
std::optional< double > expected_number;
30+
31+
std::string intensity_name() const
32+
{
33+
return absl::StrCat( fset_name, "_p21" );
34+
}
35+
double p21{ 0. };
36+
std::optional< double > expected_total_length;
37+
38+
std::vector< std::array< geode::Point2D, 2 > > observed_fractures;
39+
40+
std::string spacing_name() const
41+
{
42+
return absl::StrCat( fset_name, "_spacing" );
43+
}
44+
double minimal_spacing{ 0. };
45+
46+
std::string string() const
47+
{
48+
auto message =
49+
absl::StrCat( "FractureSetDescription: ", fset_name );
50+
for( const auto& fixed_object : observed_fractures )
51+
{
52+
absl::StrAppend( &message,
53+
"\n\t --> observation (x,y,z)start: ",
54+
fixed_object[0].string(),
55+
" (x,y,z)end: ", fixed_object[1].string() );
56+
}
57+
absl::StrAppend( &message,
58+
"\n\t --> length distribution: ", sampler.length.string() );
59+
absl::StrAppend( &message,
60+
"\n\t --> azimuth distribution: ", sampler.azimuth.string() );
61+
absl::StrAppend( &message, "\n\t --> ", density_name(), ": ", p20 );
62+
absl::StrAppend(
63+
&message, "\n\t --> ", intensity_name(), ": ", p21 );
64+
absl::StrAppend(
65+
&message, "\n\t --> ", spacing_name(), ": ", minimal_spacing );
66+
67+
absl::StrAppend( &message,
68+
"\n\t --> dynamic move ratio - birth/death/change (",
69+
birth_ratio, " / ", death_ratio, " / ", change_ratio, ")" );
70+
return message;
71+
}
72+
};
73+
74+
// struct FractureInterSetDescription
75+
// {
76+
// std::string interaction_name;
77+
//
78+
// std::vector< std::string > set_names;
79+
//
80+
// double gamma{ 1. };
81+
// double distance{ 0. };
82+
//
83+
// bool include_intra_set{ true };
84+
// bool include_inter_set{ false };
85+
//
86+
// std::optional< double > expected_nb_interactions;
87+
// };
88+
89+
struct FractureNetworkDescription
90+
{
91+
std::string fnet_name;
92+
93+
SpatialDomainConfig< 2 > domain;
94+
95+
std::vector< FractureSetDescription > fracture_sets;
96+
97+
FractureSetDescription& add_fracture_set( absl::string_view fset_name )
98+
{
99+
auto& fracture_set = fracture_sets.emplace_back();
100+
fracture_set.fset_name = fset_name;
101+
return fracture_set;
102+
}
103+
104+
std::string string() const
105+
{
106+
auto message =
107+
absl::StrCat( "FractureNetworkDescription: ", fnet_name );
108+
absl::StrAppend( &message, "\n\t --> ", domain.string() );
109+
for( const auto& fset_desc : fracture_sets )
110+
{
111+
absl::StrAppend( &message, "\n\t --> ", fset_desc.string() );
112+
}
113+
return message;
114+
}
115+
// std::vector< StraussInteractionDescription< ObjectType > >
116+
// inter_set_interactions;
117+
//
118+
// void add_x_node_monitoring( double beta_x_node )
119+
// {
120+
// OpenGeodeStochasticStochasticException::check_exception(
121+
// beta_x_node <= 1.0 && beta_x_node >= 0., nullptr,
122+
// OpenGeodeException::TYPE::data,
123+
// "[FractureSimulationRunner] x node should be
124+
// inhibitated, " "please provise a value in [0., 1.]."
125+
// );
126+
// beta_x_node_ = beta_x_node;
127+
// }
128+
};
129+
130+
FractureSimulationContext build_fractures_simulation_context(
131+
const FractureNetworkDescription& description );
132+
133+
std::vector< geode::TargetStatisticConfig > build_fractures_targeted_stat(
134+
const FractureNetworkDescription& description );
135+
136+
} // namespace geode

include/geode/stochastic/sampling/direct/double_sampler.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ namespace geode
4848

4949
struct DistributionDescription
5050
{
51+
DistributionDescription( absl::string_view name_in )
52+
: name{ name_in }
53+
{
54+
}
55+
56+
DistributionDescription() = default;
57+
5158
std::string name{ "default_distribution" };
5259
DistributionType distribution_type;
5360

include/geode/stochastic/sampling/direct/object_set_sampler/segment_set_sampler.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ namespace geode
3737
double move_ratio{ 0.1 };
3838
// NOLINTEND(*-magic-numbers)
3939

40-
DoubleSampler::DistributionDescription length;
41-
DoubleSampler::DistributionDescription azimuth;
40+
DoubleSampler::DistributionDescription length{ "length" };
41+
42+
DoubleSampler::DistributionDescription azimuth{ "azimuth" };
4243
};
4344

4445
class UniformSegmentSetSampler : public ObjectSetSampler< OwnerSegment2D >

include/geode/stochastic/sampling/mcmc/helpers/simulation_context.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ namespace geode
116116
for( const auto& set_def : config.sets )
117117
{
118118
auto set_id = context.object_sets->add_set( set_def.name );
119+
for( auto fixed_object : set_def.fixed_objects )
120+
{
121+
context.object_sets->add_object(
122+
std::move( fixed_object ), set_id, true );
123+
}
119124
auto sampler =
120125
build_objectset_sampler( *context.domain, set_def.sampler );
121126
geode::add_birth_death_change_moves( *sampler, *proposal_kernel,

include/geode/stochastic/spatial/spatial_domain.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ namespace geode
152152
Point< dimension > min_point;
153153
Point< dimension > max_point;
154154
double buffer_size{ 0.0 };
155+
std::string string() const
156+
{
157+
std::string message = "Domain: ";
158+
absl::StrAppend(
159+
&message, "\n\t --> Min point: ", min_point.string() );
160+
absl::StrAppend(
161+
&message, "\n\t --> Max point: ", max_point.string() );
162+
absl::StrAppend( &message, "\n\t --> Buffer size: ", buffer_size );
163+
return message;
164+
}
155165
};
156166

157167
template < index_t dimension >

src/geode/stochastic/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_geode_library(
2222
NAME stochastic
2323
FOLDER "geode/stochastic"
2424
SOURCES
25+
"applications/fractures.cpp"
2526
"applications/poisson_process.cpp"
2627
"applications/strauss_process.cpp"
2728
"spatial/object_set.cpp"
@@ -41,6 +42,7 @@ add_geode_library(
4142
"sampling/random_engine.cpp"
4243
"common.cpp"
4344
PUBLIC_HEADERS
45+
"applications/fractures.hpp"
4446
"applications/poisson_process.hpp"
4547
"applications/strauss_process.hpp"
4648
#"inference/abc_shadow.hpp"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2019 - 2026 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#include <geode/stochastic/applications/fractures.hpp>
25+
#include <geode/stochastic/sampling/direct/object_set_sampler/segment_set_sampler.hpp>
26+
namespace
27+
{
28+
std::vector< geode::Fracture > build_observed_fractures(
29+
const std::vector< std::array< geode::Point2D, 2 > >&
30+
fracture_extremities )
31+
{
32+
std::vector< geode::Fracture > fractures;
33+
for( const auto& extremities : fracture_extremities )
34+
{
35+
fractures.emplace_back(
36+
geode::OwnerSegment2D{ extremities[0], extremities[1] } );
37+
}
38+
return fractures;
39+
}
40+
} // namespace
41+
42+
namespace geode
43+
{
44+
using FractureDensityDescription = SingleObjectTermConfig;
45+
using FractureIntensityDescription = SingleObjectTermConfig;
46+
using FractureSpacingDescription = PairwiseTermConfig;
47+
48+
using FractureSimulationConfig = SimulationContextConfig< Fracture >;
49+
50+
FractureSimulationContext build_fractures_simulation_context(
51+
const FractureNetworkDescription& fnet_desc )
52+
{
53+
FractureSimulationConfig simulation_config;
54+
simulation_config.domain = fnet_desc.domain;
55+
56+
for( const auto& fset_desc : fnet_desc.fracture_sets )
57+
{
58+
auto& fset = simulation_config.add_set( fset_desc.fset_name );
59+
60+
fset.sampler = fset_desc.sampler;
61+
fset.dynamics.birth_ratio = fset_desc.birth_ratio;
62+
fset.dynamics.death_ratio = fset_desc.death_ratio;
63+
fset.dynamics.change_ratio = fset_desc.change_ratio;
64+
fset.fixed_objects =
65+
build_observed_fractures( fset_desc.observed_fractures );
66+
67+
FractureDensityDescription density;
68+
density.term_name = fset_desc.density_name();
69+
density.object_set_names = { fset_desc.fset_name };
70+
density.lambda = fset_desc.p20;
71+
density.object_feature = ObjectInDomainFeatureConfig{};
72+
simulation_config.model.terms.emplace_back( std::move( density ) );
73+
74+
FractureIntensityDescription intensity;
75+
intensity.term_name = fset_desc.intensity_name();
76+
intensity.object_set_names = { fset_desc.fset_name };
77+
intensity.lambda = fset_desc.p21;
78+
constexpr double caracteristic_length = 1.0;
79+
intensity.object_feature =
80+
SegmentLengthInsideBoxFeatureConfig{ caracteristic_length };
81+
simulation_config.model.terms.emplace_back(
82+
std::move( intensity ) );
83+
84+
FractureSpacingDescription spacing;
85+
spacing.term_name = fset_desc.spacing_name();
86+
spacing.object_set_names_interactions = { { fset_desc.fset_name,
87+
fset_desc.fset_name } };
88+
spacing.gamma = 0.;
89+
spacing.interaction_config =
90+
geode::MinimalDistanceCutoffConfig{ fset_desc.minimal_spacing };
91+
simulation_config.model.terms.emplace_back( std::move( spacing ) );
92+
}
93+
94+
return build_simulation_context( simulation_config );
95+
}
96+
97+
std::vector< geode::TargetStatisticConfig > build_fractures_targeted_stat(
98+
const FractureNetworkDescription& description )
99+
{
100+
std::vector< geode::TargetStatisticConfig > targets;
101+
102+
for( const auto& set_desc : description.fracture_sets )
103+
{
104+
if( set_desc.expected_number )
105+
{
106+
targets.push_back( geode::TargetStatisticConfig{
107+
set_desc.density_name(), *set_desc.expected_number } );
108+
}
109+
}
110+
111+
return targets;
112+
}
113+
114+
} // namespace geode

tests/stochastic/applications/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
#add_geode_test(
22-
# SOURCE "sampling/mcmc/test-mh-fractures.cpp"
23-
# DEPENDENCIES
24-
# OpenGeode::basic
25-
# OpenGeode::geometry
26-
# ${PROJECT_NAME}::stochastic
27-
#)
21+
add_geode_test(
22+
SOURCE "test-fractures.cpp"
23+
DEPENDENCIES
24+
OpenGeode::basic
25+
OpenGeode::geometry
26+
${PROJECT_NAME}::stochastic
27+
)
2828

2929
add_geode_test(
3030
SOURCE "test-poisson-process.cpp"

0 commit comments

Comments
 (0)