MDStressLab++
Loading...
Searching...
No Matches
Stress.h
Go to the documentation of this file.
1/*
2 * Stress.h
3 *
4 * Created on: Nov 5, 2019
5 * Author: Nikhil
6 */
7
8#ifndef STRESS_H_
9#define STRESS_H_
10
11#include <vector>
12#include "Grid.h"
13#include "typedef.h"
14#include "SpatialHash.h"
15#include "Method.h"
16#include <string>
17#include <fstream>
18#include <iostream>
19
31template<typename TMethod,
32 StressType stressType,
33 typename TGrid = typename std::conditional<stressType==Piola,Grid<Reference>,Grid<Current>>::type>
34class Stress {
35public:
39 std::vector<Matrix3d> field;
40
44 TGrid* pgrid;
45
52
57 std::string name;
58
62 Stress(std::string name,
65 {
66 field.resize(pgrid->ngrid);
67 for(auto& matrix : field)
68 matrix= Matrix3d::Zero();
69 }
70
75 TGrid* pgrid): pgrid(pgrid),method(method)
76 {
77 field.resize(pgrid->ngrid);
78 for(auto& matrix : field)
79 matrix= Matrix3d::Zero();
80 }
81
90 void write()
91 {
92 if (name.empty())
93 MY_ERROR("Stress object created without specifying a name. Use write(filename) instead of write()");
94 std::ofstream file(name+".stress");
95
96 file << field.size() << "\n";
97 //file << "\n";
98 int index= 0;
99 //Eigen::IOFormat fmt(Eigen::FullPrecision, 0, " ", "\n", "", "", "");
100 Eigen::IOFormat fmt(Eigen::FullPrecision, 0, " ", "\n", "", "", "");
101 file << std::fixed << std::setprecision(std::numeric_limits<double>::max_digits10);
102 file << "Properties=pos:R:3:stress:R:6" << std::endl;
103 for (auto& stress : field)
104 {
105 //Eigen::Map<Eigen::Matrix<double,1,DIM*DIM>> stressRow(stress.data(), stress.size());
106 //file << pgrid->coordinates[index].format(fmt) << std::setw(5) << stressRow.format(fmt) << std::endl;
107 file << pgrid->coordinates[index].format(fmt)
108 << std::setw(25) << stress(0,0)
109 << std::setw(25) << stress(1,1)
110 << std::setw(25) << stress(2,2)
111 << std::setw(25) << stress(0,1)
112 << std::setw(25) << stress(0,2)
113 << std::setw(25) << stress(1,2)
114 << std::endl;
115 index++;
116 }
117 }
118
119 void write(const std::string& filename)
120 {
121 if (name.empty())
122 name= filename;
123 else
124 std::cout << "Stress object created with name " << name << ". Ignoring the filename: " << filename << "." << std::endl;
125 write();
126 }
127
129 {
130 // TODO Auto-generated destructor stub
131 }
132
133
134};
135
136#endif /* STRESS_H_ */
Definition Grid.h:31
std::vector< Matrix3d > field
A three-dimensional stress field.
Definition Stress.h:39
std::string name
The prefix of the filename that will be outputted when the stress field is written.
Definition Stress.h:57
void write()
Definition Stress.h:90
Stress(const Method< TMethod > &method, TGrid *pgrid)
Constructs a Stress object.
Definition Stress.h:74
Stress(std::string name, const Method< TMethod > &method, TGrid *pgrid)
Constructs a Stress object.
Definition Stress.h:62
void write(const std::string &filename)
Definition Stress.h:119
TGrid * pgrid
Pointer to the Grid on which the stress field is defined.
Definition Stress.h:44
~Stress()
Definition Stress.h:128
const Method< TMethod > & method
The method used to compute the stress field. The Method object provides details about the weighting f...
Definition Stress.h:51
#define MY_ERROR(message)
Definition typedef.h:17
StressType
Definition typedef.h:63