41 const std::vector<std::string> &tags) {
43 if (
model->d_x.size() == 0)
47 auto points = vtkSmartPointer<vtkPoints>::New();
50 for (
const auto &x :
model->d_x)
51 points->InsertNextPoint(x.d_x, x.d_y, x.d_z);
54 d_grid_p = vtkSmartPointer<vtkUnstructuredGrid>::New();
55 d_grid_p->SetPoints(points);
68 auto array = vtkSmartPointer<vtkDoubleArray>::New();
69 array->SetNumberOfComponents(3);
70 array->SetName(
"Displacement");
72 array->SetComponentName(0,
"x");
73 array->SetComponentName(1,
"y");
74 array->SetComponentName(2,
"z");
76 for (
const auto &ui :
model->d_u) {
80 array->InsertNextTuple(value);
84 d_grid_p->GetPointData()->AddArray(array);
90 auto array = vtkSmartPointer<vtkDoubleArray>::New();
91 array->SetNumberOfComponents(3);
92 array->SetName(
"Velocity");
94 array->SetComponentName(0,
"x");
95 array->SetComponentName(1,
"y");
96 array->SetComponentName(2,
"z");
98 for (
const auto &ui :
model->d_v) {
102 array->InsertNextTuple(value);
106 d_grid_p->GetPointData()->AddArray(array);
112 auto array = vtkSmartPointer<vtkDoubleArray>::New();
113 array->SetNumberOfComponents(3);
114 array->SetName(
"Force_Density");
116 array->SetComponentName(0,
"x");
117 array->SetComponentName(1,
"y");
118 array->SetComponentName(2,
"z");
120 for (
const auto &ui :
model->d_f) {
124 array->InsertNextTuple(value);
128 d_grid_p->GetPointData()->AddArray(array);
134 auto array = vtkSmartPointer<vtkDoubleArray>::New();
135 array->SetNumberOfComponents(3);
136 array->SetName(
"Force");
138 array->SetComponentName(0,
"x");
139 array->SetComponentName(1,
"y");
140 array->SetComponentName(2,
"z");
143 for (
const auto &ui :
model->d_f) {
144 const auto &voli =
model->d_vol[i_count];
145 value[0] = ui.d_x * voli;
146 value[1] = ui.d_y * voli;
147 value[2] = ui.d_z * voli;
148 array->InsertNextTuple(value);
154 d_grid_p->GetPointData()->AddArray(array);
160 auto array = vtkSmartPointer<vtkDoubleArray>::New();
161 array->SetNumberOfComponents(1);
162 array->SetName(
"Fixity");
164 for (
const auto &n :
model->d_fix) {
165 p_tag[0] = double(n);
166 array->InsertNextTuple(p_tag);
170 d_grid_p->GetPointData()->AddArray(array);
176 auto array = vtkSmartPointer<vtkDoubleArray>::New();
177 array->SetNumberOfComponents(1);
178 array->SetName(
"Particle_ID");
180 for (
size_t i = 0; i<
model->d_x.size(); i++) {
181 auto pi =
model->getPtId(i);
182 p_tag[0] = double(
model->getParticleFromAllList(pi)->getId());
183 array->InsertNextTuple(p_tag);
187 d_grid_p->GetPointData()->AddArray(array);
193 auto array = vtkSmartPointer<vtkDoubleArray>::New();
194 array->SetNumberOfComponents(1);
195 array->SetName(
"Zone_ID");
197 for (
size_t i = 0; i<
model->d_x.size(); i++) {
198 auto pi =
model->getPtId(i);
199 p_tag[0] = double(
model->getParticleFromAllList(pi)->d_zoneId);
200 array->InsertNextTuple(p_tag);
204 d_grid_p->GetPointData()->AddArray(array);
210 auto array = vtkSmartPointer<vtkDoubleArray>::New();
211 array->SetNumberOfComponents(1);
212 array->SetName(
"Force_Fixity");
214 for (
const auto &n :
model->d_forceFixity) {
215 p_tag[0] = double(n);
216 array->InsertNextTuple(p_tag);
220 d_grid_p->GetPointData()->AddArray(array);
226 auto array = vtkSmartPointer<vtkDoubleArray>::New();
227 array->SetNumberOfComponents(1);
228 array->SetName(
"Nodal_Volume");
230 for (
const auto &n :
model->d_vol) {
231 p_tag[0] = double(n);
232 array->InsertNextTuple(p_tag);
236 d_grid_p->GetPointData()->AddArray(array);
242 auto array = vtkSmartPointer<vtkDoubleArray>::New();
243 array->SetNumberOfComponents(1);
244 array->SetName(
"Damage_Z");
246 for (
const auto &n :
model->d_Z) {
247 p_tag[0] = double(n);
248 array->InsertNextTuple(p_tag);
252 d_grid_p->GetPointData()->AddArray(array);
258 if (
model->getParticleFromAllList(0)->d_material_p->isStateActive()) {
260 auto array = vtkSmartPointer<vtkDoubleArray>::New();
261 array->SetNumberOfComponents(1);
262 array->SetName(
"Theta");
264 for (
const auto &n :
model->d_thetaX) {
265 p_tag[0] = double(n);
266 array->InsertNextTuple(p_tag);
270 d_grid_p->GetPointData()->AddArray(array);
277 const std::vector<std::string> &tags) {
279 if (
model->d_x.size() == 0)
283 appendNodes(
model, tags);
290 size_t num_elems = 0;
291 size_t num_vertex = 0;
294 for (
const auto &p :
model->d_particlesListTypeAll) {
296 num_elems += p->getMeshP()->getNumElements();
304 auto cells = vtkSmartPointer<vtkCellArray>::New();
305 cells->Allocate(num_vertex, num_elems);
308 int cell_types[num_elems];
311 size_t global_elem_counter = 0;
312 for (
const auto &p :
model->d_particlesListTypeAll) {
314 const auto &mesh = p->getMeshP();
317 size_t element_type = mesh->getElementType();
321 vtkIdType ids[num_vertex_p];
322 for (
size_t e =0; e < mesh->getNumElements(); e++) {
323 auto elem = mesh->getElementConnectivity(e);
326 for (
size_t n=0; n<elem.size(); n++)
327 ids[n] = elem[n] + p->d_globStart;
329 cells->InsertNextCell(num_vertex_p, ids);
330 cell_types[global_elem_counter] = element_type;
333 global_elem_counter++;
338 d_grid_p->SetCells(cell_types, cells);
363 const std::vector<size_t> *processed_nodes,
365 std::pair<size_t, size_t>> *processed_elems) {
367 if (processed_nodes->size() == 0)
371 auto points = vtkSmartPointer<vtkPoints>::New();
374 const size_t num_nodes = processed_nodes->size();
375 const size_t num_elems = processed_elems->size();
378 for (
const auto &i : *processed_nodes) {
379 const auto &x =
model->d_x[i];
380 points->InsertNextPoint(x.d_x, x.d_y, x.d_z);
384 d_grid_p = vtkSmartPointer<vtkUnstructuredGrid>::New();
385 d_grid_p->SetPoints(points);
388 const size_t vtk_element_type = 3;
389 const size_t num_vertex = 2;
391 auto cells = vtkSmartPointer<vtkCellArray>::New();
392 cells->Allocate(num_vertex, num_elems);
395 int cell_types[num_elems];
397 vtkIdType ids[num_vertex];
398 for (
size_t i = 0; i < num_elems; i++) {
400 ids[0] = (*processed_elems)[i].first;
401 ids[1] = (*processed_elems)[i].second;
403 cells->InsertNextCell(num_vertex, ids);
404 cell_types[i] = vtk_element_type;
408 d_grid_p->SetCells(cell_types, cells);
412 auto array = vtkSmartPointer < vtkDoubleArray > ::New();
413 array->SetNumberOfComponents(3);
414 array->SetName(
"Normal");
415 array->SetComponentName(0,
"x");
416 array->SetComponentName(1,
"y");
417 array->SetComponentName(2,
"z");
420 for (
size_t i = 0; i < num_elems; i++) {
422 ids[0] = (*processed_elems)[i].first;
423 ids[1] = (*processed_elems)[i].second;
425 auto glob_id1 = (*processed_nodes)[ids[0]];
426 auto glob_id2 = (*processed_nodes)[ids[1]];
428 const auto &x1 =
model->d_x[glob_id1];
429 const auto &x2 =
model->d_x[glob_id2];
431 auto xd = (x1 - x2)/((x2 - x1).length());
436 array->InsertNextTuple(value);
439 d_grid_p->GetCellData()->AddArray(array);
447 if (
model->d_xQuadCur.size() == 0) {
448 std::cout <<
"VtkParticleWriter::appendStrainStress: Nothing to write.\n";
453 auto points = vtkSmartPointer<vtkPoints>::New();
456 for (
const auto &x :
model->d_xQuadCur)
457 points->InsertNextPoint(x.d_x, x.d_y, x.d_z);
460 d_grid_p = vtkSmartPointer<vtkUnstructuredGrid>::New();
461 d_grid_p->SetPoints(points);
464 double value[3] = {0., 0., 0.};
465 double value_s[6] = {0., 0., 0., 0., 0., 0.};
466 double p_tag[1] = {0.};
468 auto array_strain = vtkSmartPointer<vtkDoubleArray>::New();
469 array_strain->SetNumberOfComponents(6);
470 array_strain->SetName(
"Strain");
472 auto array_stress = vtkSmartPointer<vtkDoubleArray>::New();
473 array_stress->SetNumberOfComponents(6);
474 array_stress->SetName(
"Stress");
476 std::vector<std::string> coord_strings = {
"xx",
"yy",
"zz",
"yz",
"xz",
"xy"};
477 for (
size_t i =0; i<6; i++) {
478 array_strain->SetComponentName(i, coord_strings[i].c_str());
479 array_stress->SetComponentName(i, coord_strings[i].c_str());
482 for (
size_t i=0; i<
model->d_strain.size(); i++) {
484 model->d_strain[i].copy(value_s);
485 array_strain->InsertNextTuple(value_s);
487 model->d_stress[i].copy(value_s);
488 array_stress->InsertNextTuple(value_s);
493 d_grid_p->GetPointData()->AddArray(array_strain);
494 d_grid_p->GetPointData()->AddArray(array_stress);
VtkParticleWriter(const std::string &filename, const std::string &compress_type="")
Constructor.
void appendNodes(const model::ModelData *model, const std::vector< std::string > &tags)
Writes the nodes to the file.
vtkSmartPointer< vtkXMLUnstructuredGridWriter > d_writer_p
XML unstructured grid writer.
void appendStrainStress(const model::ModelData *model)
Writes strain/stress.
void appendMesh(const model::ModelData *model, const std::vector< std::string > &tags)
Writes the nodes to the file.
void addTimeStep(const double ×tep)
Writes the time step to the file.
void appendContactData(const model::ModelData *model, const std::vector< size_t > *processed_nodes, const std::vector< std::pair< size_t, size_t > > *processed_elems)
Prepares contact data that is set of nodes in contact and line-element connecting two contacting node...
void close()
Closes the file and store it to the hard disk.