MFEM
v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
miniapps
spde
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
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
real_t
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.
37
class
MaterialTopology
38
{
39
public
:
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.
47
class
ParticleTopology
:
public
MaterialTopology
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
(
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
71
private
:
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.
84
class
OctetTrussTopology
:
public
MaterialTopology
85
{
86
public
:
87
OctetTrussTopology
() { Initialize(); }
88
89
// Compute the distance, i.e. distance to the closest edge.
90
real_t
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
mfem::Edge
Class that implements an edge defined by a start and end point.
Definition
material_metrics.hpp:24
mfem::Edge::GetDistanceTo
real_t GetDistanceTo(const Vector &x) const
Compute the distance between a point and the edge.
Definition
material_metrics.cpp:72
mfem::Edge::Edge
Edge(const Vector &start, const Vector &end)
Definition
material_metrics.hpp:26
mfem::MaterialTopology
Virtual class to define the interface for defining the material topology.
Definition
material_metrics.hpp:38
mfem::MaterialTopology::~MaterialTopology
virtual ~MaterialTopology()=default
mfem::MaterialTopology::ComputeMetric
virtual real_t ComputeMetric(const Vector &x)=0
Compute the metric rho describing the material topology.
mfem::OctetTrussTopology
Definition
material_metrics.hpp:85
mfem::OctetTrussTopology::ComputeMetric
real_t ComputeMetric(const Vector &x) final
Compute the metric rho describing the material topology.
Definition
material_metrics.cpp:84
mfem::OctetTrussTopology::OctetTrussTopology
OctetTrussTopology()
Definition
material_metrics.hpp:87
mfem::ParticleTopology
Class that implements the particle topology.
Definition
material_metrics.hpp:48
mfem::ParticleTopology::ComputeMetric
real_t ComputeMetric(const Vector &x) final
Definition
material_metrics.cpp:17
mfem::ParticleTopology::ParticleTopology
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)
Definition
material_metrics.hpp:56
mfem::Vector
Vector data type.
Definition
vector.hpp:80
mfem.hpp
mfem
Definition
CodeDocumentation.dox:1
mfem::real_t
float real_t
Definition
config.hpp:43
1.11.0