Allow spatial constraints on element sources within MeshSource (#3431)

This commit is contained in:
Paul Romano 2025-07-01 09:03:28 -05:00 committed by GitHub
parent dab8af5672
commit ecfb666db7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 94 additions and 69 deletions

View file

@ -139,6 +139,9 @@ public:
DomainType domain_type() const { return domain_type_; }
const std::unordered_set<int32_t>& domain_ids() const { return domain_ids_; }
// Setter for spatial distribution
void set_space(UPtrSpace space) { space_ = std::move(space); }
protected:
// Indicates whether derived class already handles constraints
bool constraints_applied() const override { return true; }
@ -205,6 +208,23 @@ typedef unique_ptr<Source> create_compiled_source_t(std::string parameters);
//! Mesh-based source with different distributions for each element
//==============================================================================
// Helper class to sample spatial position on a single mesh element
class MeshElementSpatial : public SpatialDistribution {
public:
MeshElementSpatial(int32_t mesh_index, int elem_index)
: mesh_index_(mesh_index), elem_index_(elem_index)
{}
//! Sample a position from the distribution
//! \param seed Pseudorandom number seed pointer
//! \return Sampled position
Position sample(uint64_t* seed) const override;
private:
int32_t mesh_index_ {C_NONE}; //!< Index in global meshes array
int elem_index_; //! Index of mesh element
};
class MeshSource : public Source {
public:
// Constructors
@ -219,18 +239,15 @@ public:
double strength() const override { return space_->total_strength(); }
// Accessors
const std::unique_ptr<Source>& source(int32_t i) const
const unique_ptr<IndependentSource>& source(int32_t i) const
{
return sources_.size() == 1 ? sources_[0] : sources_[i];
}
protected:
bool constraints_applied() const override { return true; }
private:
// Data members
unique_ptr<MeshSpatial> space_; //!< Mesh spatial
vector<std::unique_ptr<Source>> sources_; //!< Source distributions
unique_ptr<MeshSpatial> space_; //!< Mesh spatial
vector<unique_ptr<IndependentSource>> sources_; //!< Source distributions
};
//==============================================================================