MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
material_metrics.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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
19namespace mfem
20{
21
22/// Class that implements an edge defined by a start and end point.
23class Edge
24{
25public:
26 Edge(const Vector &start, const Vector &end) : start_(start), end_(end) {}
27
28 /// Compute the distance between a point and the edge.
29 real_t GetDistanceTo(const Vector &x) const;
30
31private:
32 const Vector &start_;
33 const Vector &end_;
34};
35
36/// Virtual class to define the interface for defining the material topology.
38{
39public:
40 virtual ~MaterialTopology() = default;
41
42 /// Compute the metric rho describing the material topology.
43 virtual real_t ComputeMetric(const Vector &x) = 0;
44};
45
46/// Class that implements the particle topology.
48{
49public:
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(real_t length_x, real_t length_y, real_t length_z,
57 std::vector<real_t> &random_positions,
58 std::vector<real_t> &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 real_t ComputeMetric(const Vector &x) final;
70
71private:
72 /// Initialize the particle topology with positions x_k and matrices A_k.
73 void Initialize(std::vector<real_t> &random_positions,
74 std::vector<real_t> &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{
86public:
87 OctetTrussTopology() { Initialize(); }
88
89 // Compute the distance, i.e. distance to the closest edge.
90 real_t ComputeMetric(const Vector &x) final;
91
92private:
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
Class that implements an edge defined by a start and end point.
real_t GetDistanceTo(const Vector &x) const
Compute the distance between a point and the edge.
Edge(const Vector &start, const Vector &end)
Virtual class to define the interface for defining the material topology.
virtual ~MaterialTopology()=default
virtual real_t ComputeMetric(const Vector &x)=0
Compute the metric rho describing the material topology.
real_t ComputeMetric(const Vector &x) final
Compute the metric rho describing the material topology.
Class that implements the particle topology.
real_t ComputeMetric(const Vector &x) final
ParticleTopology(real_t length_x, real_t length_y, real_t length_z, std::vector< real_t > &random_positions, std::vector< real_t > &random_rotations)
Vector data type.
Definition: vector.hpp:80
float real_t
Definition: config.hpp:43