MFEM  v4.6.0 Finite element discretization library
material_metrics.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details
11
12 #ifndef MATERIAL_METRICS_HPP
13 #define MATERIAL_METRICS_HPP
14
15 #include <random>
16 #include <vector>
17 #include "mfem.hpp"
18
19 namespace mfem
20 {
21
22 /// Class that implements an edge defined by a start and end point.
23 class Edge
24 {
25 public:
26  Edge(const Vector &start, const Vector &end) : start_(start), end_(end) {}
27
28  /// Compute the distance between a point and the edge.
29  double GetDistanceTo(const Vector &x) const;
30
31 private:
32  const Vector &start_;
33  const Vector &end_;
34 };
35
36 /// Virtual class to define the interface for defining the material topology.
38 {
39 public:
40  virtual ~MaterialTopology() = default;
41
42  /// Compute the metric rho describing the material topology.
43  virtual double ComputeMetric(const Vector &x) = 0;
44 };
45
46 /// Class that implements the particle topology.
48 {
49 public:
50  /// Constructor. The length of the vectors random_positions and
51  /// random_rotations must be 3x and 9x number_of_particles,
52  /// respectively. They implicitly define the number of the particles.
53  /// @param[in] (length_x, length_y, length_z) - particle shape
54  /// @param[in] random_positions - vector with random positions for particles
55  /// @param[in] random_rotations - vector with random rotations for particles
56  ParticleTopology(double length_x, double length_y, double length_z,
57  std::vector<double> &random_positions,
58  std::vector<double> &random_rotations)
59  : particle_shape_({length_x, length_y, length_z}),
60  number_of_particles_(random_positions.size() / 3u)
61  {
62  Initialize(random_positions, random_rotations);
63  }
64
65  /// Compute the metric rho describing the particle topology. For a vector x,
66  /// this function returns the shortest distance to any of the particles. The
67  /// individual is computed as || A_k (x-x_k) ||_2. (A allows do distort the
68  /// particle shape.)
69  double ComputeMetric(const Vector &x) final;
70
71 private:
72  /// Initialize the particle topology with positions x_k and matrices A_k.
73  void Initialize(std::vector<double> &random_positions,
74  std::vector<double> &random_rotations);
75
76  std::vector<Vector> particle_positions_; // A_k * x_k, scaled!
77  std::vector<DenseMatrix> particle_orientations_; // Random rotations of shape
78  Vector particle_shape_; // The shape of the particle.
79  size_t number_of_particles_; // The number of particles.
80 };
81
82 /// Class for the topology of a an octet truss. This class assumes the domain is
83 /// a cube [0,1]^3.
85 {
86 public:
87  OctetTrussTopology() { Initialize(); }
88
89  // Compute the distance, i.e. distance to the closest edge.
90  double ComputeMetric(const Vector &x) final;
91
92 private:
93  /// Initialize the topology, e.g. define the edges.
94  void Initialize();
95
96  /// To account for the periodicity, this function creates ghost points for
97  /// the distance computation, e.g. ( x[0] ± 1, x[1] ± 1, x[2] ± 1).
98  void CreatePeriodicPoints(const Vector &x,
99  std::vector<Vector> &periodic_points) const;
100
101  std::vector<Vector> points_; // The points of the octet truss.
102  std::vector<Edge> edges_; // The edges of the octet truss.
103 };
104
105 } // namespace mfem
106
107 #endif // MATERIAL_METRICS_HPP
Virtual class to define the interface for defining the material topology.
double GetDistanceTo(const Vector &x) const
Compute the distance between a point and the edge.
virtual ~MaterialTopology()=default
Class that implements an edge defined by a start and end point.
Class that implements the particle topology.
virtual double ComputeMetric(const Vector &x)=0
Compute the metric rho describing the material topology.
ParticleTopology(double length_x, double length_y, double length_z, std::vector< double > &random_positions, std::vector< double > &random_rotations)
double ComputeMetric(const Vector &x) final
Compute the metric rho describing the material topology.
Edge(const Vector &start, const Vector &end)
Vector data type.
Definition: vector.hpp:58
double u(const Vector &xvec)
Definition: lor_mms.hpp:22
double ComputeMetric(const Vector &x) final