 |
revision: v0.14
|
Go to the documentation of this file.
50 #ifndef MERCURY_SMALLMATRIX_H
51 #define MERCURY_SMALLMATRIX_H
66 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
80 logger.assert_debug(numberOfColumns == 1,
"Trying to construct a matrix with more than 1 columns from a vector");
81 std::copy(other.
data(), other.
data() + numberOfRows,
data_.begin());
94 logger.assert_debug(entries.size() == numberOfColumns,
"expected a matrix with % "
95 "columns, but got a matrix with % columns", numberOfColumns,
97 unsigned int column = 0;
100 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
102 (*this)(
i, column) = entry[
i];
119 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
121 for (
unsigned int j = 0; j < numberOfColumns; ++j)
123 (*this)(
i, j) = entries[j][
i];
137 logger.assert_debug(
n < numberOfRows,
"Requested row number % for a matrix with only % rows",
n, numberOfRows);
138 logger.assert_debug(m < numberOfColumns,
"Requested column number % for a matrix with only % columns", m,
140 return data_[
n + m * numberOfRows];
146 logger.assert_debug(
n < numberOfRows,
"Requested row number % for a matrix with only % rows",
n, numberOfRows);
147 logger.assert_debug(m < numberOfColumns,
"Requested column number % for a matrix with only % columns", m,
149 return data_[
n + m * numberOfRows];
155 logger.assert_debug(
n < numberOfRows * numberOfColumns,
"Requested entry % for a matrix with only % entries",
n,
156 numberOfRows * numberOfColumns);
162 logger.assert_debug(
n < numberOfRows * numberOfColumns,
"Requested entry % for a matrix with only % entries",
n,
163 numberOfRows * numberOfColumns);
177 std::bind(std::multiplies<Mdouble>(), std::placeholders::_1, right));
182 template<
unsigned int K>
185 template<
unsigned int K>
190 std::transform(
data_.begin(),
data_.end(), other.
data_.begin(),
data_.begin(), std::plus<Mdouble>());
196 std::transform(
data_.begin(),
data_.end(), other.
data_.begin(),
data_.begin(), std::minus<Mdouble>());
203 std::transform(
data_.begin(),
data_.end(), other.
data_.begin(), result.
data_.begin(), std::plus<Mdouble>());
210 std::transform(
data_.begin(),
data_.end(), other.
data_.begin(), result.
data_.begin(), std::minus<Mdouble>());
223 std::bind(std::multiplies<Mdouble>(), std::placeholders::_1, scalar));
235 std::bind(std::divides<Mdouble>(), std::placeholders::_1, scalar));
244 std::bind(std::divides<Mdouble>(), std::placeholders::_1, scalar));
258 std::move(right.data_.begin(), right.data_.end(),
data_.begin());
268 for (
unsigned int i = 0;
i < numberOfRows * numberOfColumns; ++
i)
277 return numberOfRows * numberOfColumns;
295 return numberOfColumns;
306 logger.assert_debug(j < numberOfColumns,
"Asked for column %, but there are only % columns", j, numberOfColumns);
313 logger.assert_debug(
i < numberOfRows,
"Asked for row %, but there are only % rows",
i, numberOfRows);
315 for (
unsigned int j = 0; j < numberOfColumns; ++j)
317 result[j] = (*this)(
i, j);
333 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
335 for (
unsigned int j = 0; j < numberOfColumns; ++j)
337 result(j,
i) = (*this)(
i, j);
344 template<
unsigned int numberOfRightHandS
ideColumns>
363 std::array<Mdouble, numberOfRows * numberOfColumns>
data_;
367 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
370 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
372 os <<
A.getRow(
i) << std::endl;
378 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
386 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
392 #endif //MERCURY_SMALLMATRIX_H
void setMax(const Vec3D &max)
Sets the maximum coordinates of the problem domain.
Definition: DPMBase.cc:1073
SmallMatrix & operator*=(const Mdouble &scalar)
Does matrix A_ij=scalar*A_ij.
Definition: SmallMatrix.h:220
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:420
void writeEneTimeStep(std::ostream &os) const override
Write the global kinetic, potential energy, etc. in the system.
Definition: SlidingFrictionUnitTest.cpp:36
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1225
void setMin(const Vec3D &min)
Sets the minimum coordinates of the problem domain.
Definition: DPMBase.cc:1109
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1241
const Mdouble pi
Definition: ExtendedMath.h:45
Definition: SlidingSpheresUnitTest.cpp:33
Mdouble * data()
Definition: SmallMatrix.h:351
SmallMatrix(const SmallVector< numberOfRows > &other)
Definition: SmallMatrix.h:77
const Mdouble & operator[](const unsigned int n) const
Definition: SmallMatrix.h:160
SmallMatrix & operator=(SmallMatrix &&right)
Assigns one matrix to another.
Definition: SmallMatrix.h:256
int main(int argc, char *argv[])
Definition: SlidingSpheresUnitTest.cpp:109
#define assert(e,...)
Definition: Logger.h:769
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Definition: BaseInteractable.h:239
SmallVector< numberOfRows > operator*(SmallVector< numberOfColumns > &right)
Defines Matrix A times vector B and return vector C i.e. C_,j= A_ij B_,j.
Definition: SmallMatrix_impl.h:81
SmallMatrix & operator+=(const SmallMatrix &other)
Definition: SmallMatrix.h:188
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
void writeEneHeader(std::ostream &os) const override
Writes a header with a certain format for ENE file.
Definition: SlidingFrictionUnitTest.cpp:31
SmallMatrix(std::array< SmallVector< numberOfRows >, numberOfColumns > entries)
Glues one or more vectors with the same number of rows together.
Definition: SmallMatrix.h:116
void solve(SmallMatrix< numberOfRows, numberOfRightHandSideColumns > &B) const
solves Ax=B where A is the current matrix and B is passed in. The result is returned in B.
Definition: SmallMatrix_impl.h:329
SmallMatrix< numberOfColumns, numberOfRows > transpose() const
Definition: SmallMatrix.h:330
Mdouble & operator()(unsigned int n, unsigned int m)
defines the operator(n,m) to access the element on row n and column m
Definition: SmallMatrix.h:135
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_.
Definition: File.cc:273
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:37
unsigned int getNumberOfColumns() const
Get the number of columns.
Definition: SmallMatrix.h:293
virtual void setInertia()
Definition: BaseParticle.cc:497
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
std::array< Mdouble, numberOfRows *numberOfColumns > data_
The actually data of the matrix class.
Definition: SmallMatrix.h:363
SmallMatrix(SmallMatrix &&other)
Move Matrix from another Matrix.
Definition: SmallMatrix.h:129
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species)
Definition: BaseParticle.cc:542
SmallMatrix operator/(const Mdouble &scalar) const
this does element by divided by a scalar
Definition: SmallMatrix.h:240
void solve()
The work horse of the code.
Definition: DPMBase.cc:4003
std::ostream & operator<<(std::ostream &os, const SmallMatrix< numberOfRows, numberOfColumns > &A)
Writes nicely formatted entries of the Matrix A to the stream os.
Definition: SmallMatrix.h:368
Mdouble & operator[](const unsigned int n)
Access the n linear element in the matrix.
Definition: SmallMatrix.h:153
void setInertia() override
Compute and set the inertia-tensor for this superquadric. For internal use only.
Definition: SuperQuadricParticle.cc:216
@ A
Definition: StatisticsVector.h:42
SmallMatrix operator-(const SmallMatrix &other) const
Definition: SmallMatrix.h:207
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60
SmallVector< numberOfRows > computeWedgeStuffVector() const
computeWedgeStuffVector.
Definition: SmallMatrix_impl.h:201
unsigned int getNumberOfRows() const
Get the number of rows.
Definition: SmallMatrix.h:281
double Mdouble
Definition: GeneralDefine.h:34
Data type for small dense matrix.
Definition: SmallMatrix.h:68
void axpy(Mdouble a, const SmallMatrix &x)
Applies the matrix y=ax + y, where x is another matrix and a is a scalar.
Definition: SmallMatrix.h:266
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
Definition: BaseInteractable.cc:350
unsigned int getNRows() const
Definition: SmallMatrix.h:287
SmallMatrix LUfactorisation() const
Return the LUfactorisation of the matrix.
Definition: SmallMatrix_impl.h:242
SuperQuadricParticle * copy() const override
Copy method. It calls to copy constructor of this superquadric, useful for polymorphism.
Definition: SuperQuadricParticle.cc:90
void setSpecies(const ParticleSpecies *species)
Definition: BaseParticle.cc:804
SmallVector< numberOfColumns > getRow(unsigned int i) const
get the i^th row
Definition: SmallMatrix.h:311
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:805
SmallMatrix & operator/=(const Mdouble &scalar)
Does matrix A_ij=scalar*A_ij.
Definition: SmallMatrix.h:232
SmallMatrix & operator=(const SmallMatrix &right)
Assigns one matrix to another.
Definition: SmallMatrix.h:249
SmallVector< numberOfRows > getColumn(unsigned int j) const
get the j^th column
Definition: SmallMatrix.h:304
Contains material and contact force properties.
Definition: Species.h:35
SmallMatrix operator-() const
Definition: SmallMatrix.h:214
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1385
const Mdouble * data() const
Definition: SmallVector.h:238
int main(int argc UNUSED, char *argv[] UNUSED)
Definition: SlidingFrictionUnitTest.cpp:44
A spherical particle is the most simple particle used in MercuryDPM.
Definition: SphericalParticle.h:37
void actionsAfterTimeStep() override
A virtual function which allows to define operations to be executed after time step.
Definition: SlidingSpheresUnitTest.cpp:89
Mdouble determinant() const
Definition: SmallMatrix_impl.h:261
void setDimension(unsigned int newDim)
Sets both the system dimensions and the particle dimensionality.
Definition: DPMBase.cc:1394
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition: DPMBase.cc:870
const Mdouble & operator()(unsigned int n, unsigned int m) const
defines the operator(n,m) to access the element on row n and column m
Definition: SmallMatrix.h:144
const Mdouble * data() const
Definition: SmallMatrix.h:356
void setGravity(Vec3D newGravity)
Sets a new value for the gravitational acceleration.
Definition: DPMBase.cc:1374
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Definition: InteractionHandler.cc:149
Contains information about the contact between two interactables, BaseInteraction::P_ and BaseInterac...
Definition: Interaction.h:116
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
SmallMatrix operator*(const Mdouble &right) const
Does matrix A_ij=scalar*B_ij.
Definition: SmallMatrix.h:173
SmallMatrix()
Constructs a matrix of size n-rows by m-columns.
Definition: SmallMatrix.h:72
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:457
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
SmallMatrix operator+(const SmallMatrix &other) const
Definition: SmallMatrix.h:200
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
bool contactHasOccured
Definition: SlidingSpheresUnitTest.cpp:106
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: DPMBase.h:1446
#define UNUSED
Definition: GeneralDefine.h:39
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition: BaseParticle.h:362
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
void test()
Definition: SlidingSpheresUnitTest.cpp:97
SmallMatrix(const SmallMatrix &other)
Construct and copy Matrix from another Matrix i.e. B(A) where B and A are both matrices.
Definition: SmallMatrix.h:109
Definition: SuperQuadricParticle.h:56
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: Helpers.cc:445
Definition: SlidingFrictionUnitTest.cpp:29
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition: SlidingSpheresUnitTest.cpp:35
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1395
SmallMatrix(const std::initializer_list< SmallVector< numberOfRows >> &entries)
Definition: SmallMatrix.h:91
SmallMatrix & operator-=(const SmallMatrix &other)
Definition: SmallMatrix.h:194
void setAxesAndExponents(const Mdouble &a1, const Mdouble &a2, const Mdouble &a3, const Mdouble &eps1, const Mdouble &eps2)
Set the geometrical properties of the superquadrics, namely the axes-lengths a1, a2 and a3,...
Definition: SuperQuadricParticle.cc:133
unsigned int size() const
Get total number of Matrix entries.
Definition: SmallMatrix.h:275
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:406
Species< LinearViscoelasticNormalSpecies, SlidingFrictionSpecies, BondedSpecies > LinearViscoelasticSlidingFrictionBondedSpecies
Definition: LinearViscoelasticSlidingFrictionBondedSpecies.h:35
SmallMatrix inverse() const
return the inverse in the vector result. The size of result matches the matrix.
Definition: SmallMatrix_impl.h:305
SmallMatrix(const Mdouble &c)
Constructs a matrix of size n-rows by m-columns and initialises all entry to a constant.
Definition: SmallMatrix.h:85
bool isEqual(Mdouble v1, Mdouble v2, Mdouble absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
Definition: ExtendedMath.cc:251
Definition: SmallVector.h:62
SmallMatrix< numberOfRows, numberOfColumns > operator*(const Mdouble d, const SmallMatrix< numberOfRows, numberOfColumns > &mat)
Multiplies a matrix with a Mdouble.
Definition: SmallMatrix.h:380
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1425
unsigned int getNCols() const
Definition: SmallMatrix.h:298
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:76