2929#include < geode/stochastic/sampling/direct/object_set_sampler/segment_set_sampler.hpp>
3030#include < geode/stochastic/sampling/mcmc/helpers/simulation_runner.hpp>
3131#include < geode/stochastic/sampling/mcmc/models/components/density_term.hpp>
32+ #include < geode/stochastic/sampling/mcmc/models/components/intensity_term.hpp>
3233#include < geode/stochastic/sampling/mcmc/models/components/pairwise_term.hpp>
3334#include < geode/stochastic/sampling/mcmc/proposal/classical_proposals.hpp>
3435#include < geode/stochastic/spatial/pairwise_interactions.hpp>
@@ -107,7 +108,8 @@ namespace geode
107108 std::make_unique< ProposalKernel< OwnerSegment2D > >();
108109
109110 // Mapping set names -> UUID
110- std::unordered_map< std::string, uuid > name_to_uuid;
111+ // std::unordered_map< std::string, uuid >
112+ // set_name_to_uuid_;
111113
112114 // Step 1: create object sets and samplers
113115 for ( const auto & set_desc : set_descriptors_ )
@@ -120,7 +122,7 @@ namespace geode
120122 fixed_object[0 ], fixed_object[1 ] },
121123 set_id, true );
122124 }
123- name_to_uuid [set_desc.name ] = set_id;
125+ set_name_to_uuid_ [set_desc.name ] = set_id;
124126
125127 auto length_distribution =
126128 DoubleSampler::create_distribution ( set_desc.length );
@@ -139,63 +141,12 @@ namespace geode
139141 // Step 2: create density energy terms
140142 for ( const auto & set_desc : set_descriptors_ )
141143 {
142- const auto set_id = name_to_uuid.at ( set_desc.name );
143- // p20
144- this ->ordered_energy_terms_ .push_back (
145- this ->energy_terms_collection_ .add_energy_term (
146- std::make_unique< DensityTerm< OwnerSegment2D > >(
147- absl::StrCat ( set_desc.name , " _density" ),
148- set_desc.p20 , std::vector< uuid >{ set_id },
149- this ->domain_ ) ) );
150- // intentisty
151- if ( std::fabs ( set_desc.p21 - 1 . ) > GLOBAL_EPSILON )
152- {
153- this ->ordered_energy_terms_ .push_back (
154- this ->energy_terms_collection_ .add_energy_term (
155- std::make_unique< IntensityTerm >(
156- absl::StrCat ( set_desc.name , " _intensity" ),
157- set_desc.p21 , std::vector< uuid >{ set_id },
158- 0.5 * this ->domain_ .smallest_length (),
159- this ->domain_ ) ) );
160- }
161- // spacing
162- if ( set_desc.minimal_spacing > GLOBAL_EPSILON )
163- {
164- auto interaction = std::make_unique<
165- EuclideanCutoffInteraction< OwnerSegment2D > >(
166- set_desc.minimal_spacing ,
167- PairwiseInteraction<
168- OwnerSegment2D >::SCOPE ::same_set );
169-
170- this ->ordered_energy_terms_ .push_back (
171- this ->energy_terms_collection_ .add_energy_term (
172- std::make_unique< PairwiseTerm< OwnerSegment2D > >(
173- absl::StrCat ( set_desc.name , " _min_spacing" ),
174- 0 ., std::vector< uuid >{ set_id },
175- std::move ( interaction ), this ->domain_ ) ) );
176- }
144+ set_density_term ( set_desc );
145+ set_intensity_term ( set_desc );
146+ set_minimal_spacing_term ( set_desc );
177147 }
178- // x node monitoring
179- if ( std::fabs ( beta_x_node_ - 1 . ) > GLOBAL_EPSILON )
180- {
181- std::vector< uuid > set_uuids;
182- set_uuids.reserve ( name_to_uuid.size () );
183- for ( const auto & [name, id] : name_to_uuid )
184- {
185- set_uuids.push_back ( id );
186- }
187- auto interaction = std::make_unique<
188- EuclideanCutoffInteraction< OwnerSegment2D > >(
189- 0 ., PairwiseInteraction<
190- OwnerSegment2D >::SCOPE ::different_set );
148+ set_x_intersection_term ();
191149
192- this ->ordered_energy_terms_ .push_back (
193- this ->energy_terms_collection_ .add_energy_term (
194- std::make_unique< PairwiseTerm< OwnerSegment2D > >(
195- absl::StrCat ( " inter_set_x_nodes" ), beta_x_node_,
196- set_uuids, std::move ( interaction ),
197- this ->domain_ ) ) );
198- }
199150 this ->mh_sampler_ =
200151 std::make_unique< MetropolisHastings< OwnerSegment2D > >(
201152 this ->energy_terms_collection_ ,
@@ -240,8 +191,80 @@ namespace geode
240191 return message;
241192 }
242193
194+ private:
195+ void set_density_term ( const FractureSetDescription& set_desc )
196+ {
197+ const auto set_id = set_name_to_uuid_.at ( set_desc.name );
198+ this ->ordered_energy_terms_ .push_back (
199+ this ->energy_terms_collection_ .add_energy_term (
200+ std::make_unique< DensityTerm< OwnerSegment2D > >(
201+ absl::StrCat ( set_desc.name , " _density" ), set_desc.p20 ,
202+ std::vector< uuid >{ set_id }, this ->domain_ ) ) );
203+ }
204+
205+ void set_intensity_term ( const FractureSetDescription& set_desc )
206+ {
207+ if ( std::fabs ( set_desc.p21 - 1 . ) < GLOBAL_EPSILON )
208+ {
209+ return ;
210+ }
211+ const auto set_id = set_name_to_uuid_.at ( set_desc.name );
212+ this ->ordered_energy_terms_ .push_back (
213+ this ->energy_terms_collection_ .add_energy_term (
214+ std::make_unique< IntensityTerm >(
215+ absl::StrCat ( set_desc.name , " _intensity" ),
216+ set_desc.p21 , std::vector< uuid >{ set_id },
217+ 0.5 * this ->domain_ .smallest_length (),
218+ this ->domain_ ) ) );
219+ }
220+
221+ void set_minimal_spacing_term ( const FractureSetDescription& set_desc )
222+ {
223+ if ( set_desc.minimal_spacing < GLOBAL_EPSILON )
224+ {
225+ return ;
226+ }
227+ const auto set_id = set_name_to_uuid_.at ( set_desc.name );
228+ auto interaction = std::make_unique<
229+ EuclideanCutoffInteraction< OwnerSegment2D > >(
230+ set_desc.minimal_spacing ,
231+ PairwiseInteraction< OwnerSegment2D >::SCOPE ::same_set );
232+
233+ this ->ordered_energy_terms_ .push_back (
234+ this ->energy_terms_collection_ .add_energy_term (
235+ std::make_unique< PairwiseTerm< OwnerSegment2D > >(
236+ absl::StrCat ( set_desc.name , " _min_spacing" ), 0 .,
237+ std::vector< uuid >{ set_id }, std::move ( interaction ),
238+ this ->domain_ ) ) );
239+ }
240+
241+ void set_x_intersection_term ()
242+ {
243+ if ( std::fabs ( beta_x_node_ - 1 . ) > GLOBAL_EPSILON )
244+ {
245+ std::vector< uuid > set_uuids;
246+ set_uuids.reserve ( set_name_to_uuid_.size () );
247+ for ( const auto & [name, id] : set_name_to_uuid_ )
248+ {
249+ set_uuids.push_back ( id );
250+ }
251+ auto interaction = std::make_unique<
252+ EuclideanCutoffInteraction< OwnerSegment2D > >(
253+ 0 ., PairwiseInteraction<
254+ OwnerSegment2D >::SCOPE ::different_set );
255+
256+ this ->ordered_energy_terms_ .push_back (
257+ this ->energy_terms_collection_ .add_energy_term (
258+ std::make_unique< PairwiseTerm< OwnerSegment2D > >(
259+ absl::StrCat ( " inter_set_x_nodes" ), beta_x_node_,
260+ set_uuids, std::move ( interaction ),
261+ this ->domain_ ) ) );
262+ }
263+ }
264+
243265 private:
244266 std::vector< FractureSetDescription > set_descriptors_;
267+ std::unordered_map< std::string, uuid > set_name_to_uuid_;
245268 // x node monitoring
246269 double beta_x_node_{ 1 . };
247270 };
0 commit comments