OOFEM 3.0
Loading...
Searching...
No Matches
vtkpfemexportmodule.C
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#include "vtkpfemexportmodule.h"
36#include "element.h"
37#include "gausspoint.h"
38#include "timestep.h"
39#include "engngm.h"
40#include "node.h"
41#include "dof.h"
42#include "materialinterface.h"
43#include "mathfem.h"
44#include "cltypes.h"
45#include "material.h"
46#include "classfactory.h"
47#include "crosssection.h"
49
50#ifdef __PFEM_MODULE
51 #include "pfem/pfemparticle.h"
52#endif
53
54#include <string>
55#include <sstream>
56#include <ctime>
57
58namespace oofem {
65
67
68void
73
74std::string
76{
77 return this->giveOutputBaseFileName(tStep) + ".vtu";
78}
79
80
81std::ofstream
83{
84 std::string fileName = giveOutputFileName(tStep);
85 std::ofstream streamF;
86
87 if ( pythonExport ) {
88 streamF = std::ofstream(NULL_DEVICE);//do not write anything
89 } else {
90 streamF = std::ofstream(fileName);
91 }
92
93 if ( !streamF.good() ) {
94 OOFEM_ERROR("failed to open file %s", fileName.c_str() );
95 }
96
97 streamF.fill('0');//zero padding
98 return streamF;
99}
100
101
102void
104{
105 if ( !( testTimeStepOutput(tStep) || forcedOutput ) ) {
106 return;
107 }
108
109 this->fileStream = this->giveOutputStream(tStep);
110 struct tm *current;
111 time_t now;
112 time(& now);
113 current = localtime(& now);
114
115 // Write output: VTK header
116 this->fileStream << "<!-- TimeStep " << tStep->giveTargetTime() * timeScale << " Computed " << current->tm_year + 1900 << "-" << setw(2) << current->tm_mon + 1 << "-" << setw(2) << current->tm_mday << " at " << current->tm_hour << ":" << current->tm_min << ":" << setw(2) << current->tm_sec << " -->\n";
117 this->fileStream << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
118 this->fileStream << "<UnstructuredGrid>\n";
119
120#ifdef __PFEM_MODULE
121 // write out the particles (nodes exported as vertices = VTK_VERTEX)
122 Domain *d = emodel->giveDomain(1);
123 int nnode = d->giveNumberOfDofManagers();
124
125 int nActiveNode = 0;
126 for ( int inode = 1; inode <= nnode; inode++ ) {
127 PFEMParticle *particle = dynamic_cast< PFEMParticle * >( d->giveNode(inode) );
128 if ( particle ) {
129 if ( particle->isActive() ) {
130 nActiveNode++;
131 }
132 }
133 }
134
135 DofManager *node;
136 this->fileStream << "<Piece NumberOfPoints=\"" << nActiveNode << "\" NumberOfCells=\"" << nActiveNode << "\">\n";
137 this->fileStream << "<Points>\n <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\"> ";
138
139 for ( int inode = 1; inode <= nnode; inode++ ) {
140 node = d->giveNode(inode);
141 PFEMParticle *particle = dynamic_cast< PFEMParticle * >( node );
142 if ( particle ) {
143 if ( particle->isActive() ) {
144 const FloatArray &coords = node->giveCoordinates();
146 for ( int i = 1; i <= coords.giveSize(); i++ ) {
147 this->fileStream << scientific << coords.at(i) << " ";
148 }
149
150 for ( int i = coords.giveSize() + 1; i <= 3; i++ ) {
151 this->fileStream << scientific << 0.0 << " ";
152 }
153 }
154 }
155 }
156
157 this->fileStream << "</DataArray>\n</Points>\n";
158
159
160 // output the cells connectivity data
161 this->fileStream << "<Cells>\n";
162 this->fileStream << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\"> ";
163
164 for ( int ielem = 1; ielem <= nActiveNode; ielem++ ) {
165 this->fileStream << ielem - 1 << " ";
166 }
167
168 this->fileStream << "</DataArray>\n";
169
170 // output the offsets (index of individual element data in connectivity array)
171 this->fileStream << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\"> ";
172
173 for ( int ielem = 1; ielem <= nActiveNode; ielem++ ) {
174 this->fileStream << ielem << " ";
175 }
176 this->fileStream << "</DataArray>\n";
177
178
179 // output cell (element) types
180 this->fileStream << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\"> ";
181 for ( int ielem = 1; ielem <= nActiveNode; ielem++ ) {
182 this->fileStream << 1 << " ";
183 }
184
185 this->fileStream << "</DataArray>\n";
186 this->fileStream << "</Cells>\n";
187 this->fileStream << "</Piece>\n";
188#endif //__PFEM_MODULE
189
190 // Finalize the output:
191 this->fileStream << "</UnstructuredGrid>\n</VTKFile>";
192 if(this->fileStream){
193 this->fileStream.close();
194 }
195
196 }
197
198} // end namespace oofem
#define REGISTER_ExportModule(class)
const FloatArray & giveCoordinates() const
Definition dofmanager.h:390
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition domain.h:461
Node * giveNode(int n)
Definition domain.h:398
double timeScale
Scaling time in output, e.g. conversion from seconds to hours.
std::string giveOutputBaseFileName(TimeStep *tStep)
virtual void initializeFrom(InputRecord &ir)
Initializes receiver according to object description stored in input record.
bool pythonExport
Output is carried out as a python list instead of writing files.
EngngModel * emodel
Problem pointer.
bool testTimeStepOutput(TimeStep *tStep)
double & at(Index i)
Definition floatarray.h:202
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
virtual bool isActive()
Returns the activeFlag.
double giveTargetTime()
Returns target time.
Definition timestep.h:164
VTKPFEMXMLExportModule(int n, EngngModel *e)
Constructor. Creates empty Output Manager. By default all components are selected.
std::ofstream giveOutputStream(TimeStep *tStep)
Returns the output stream for given solution step.
void doOutput(TimeStep *tStep, bool forcedOutput=false) override
void initializeFrom(InputRecord &ir) override
Initializes receiver according to object description stored in input record.
std::string giveOutputFileName(TimeStep *tStep)
Returns the filename for the given time step.
virtual ~VTKPFEMXMLExportModule()
Destructor.
#define OOFEM_ERROR(...)
Definition error.h:79
#define NULL_DEVICE

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011