OOFEM 3.0
Loading...
Searching...
No Matches
solutionstatusexportmodule.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
36#include "oofemcfg.h"
37#include "engngm.h"
38#include "timestep.h"
39#include "classfactory.h"
40#include "oofemtxtinputrecord.h"
41
42#include <sstream> // std::istringstream
43#include <string> // std::string
44#include <cmath>
45
46namespace oofem {
48
49
50SolutionStatusExportModule :: SolutionStatusExportModule(int n, EngngModel *e, FILE *out) : ExportModule(n, e), outputFile(out)
51{
52}
53
54void
55SolutionStatusExportModule :: initializeFrom(InputRecord &ir)
56{
57 ExportModule :: initializeFrom(ir);
58
59 std::string formatStr("m:s:a:nite:t:dt:st:cr"); //default format
61 // parse format string
62 // use separator to read parts of the line
63 std::istringstream input(formatStr);
64 std::string token;
65 while(std::getline(input, token, ':')) {
66 recs.push_back(token);
67 }
68 this->checkRecs();
69}
70
71void
72SolutionStatusExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
73{
74#if 0
75 if ( !( testTimeStepOutput(tStep) || forcedOutput ) ) {
76 return;
77 }
78#endif
79
80 for (auto rec: this->recs) {
81 if (rec == "m") { // metstep number
82 fprintf(outputFile, "%10d ", tStep->giveMetaStepNumber());
83 } else if (rec == "s") { // solution step number
84 fprintf(outputFile, "%10d ", tStep->giveNumber());
85 } else if (rec == "a") { // attempt number
86 fprintf(outputFile, "%10d ", tStep->numberOfAttempts);
87 } else if (rec == "nite") { // number of iterations
88 fprintf(outputFile, "%10d ", tStep->numberOfIterations);
89 } else if (rec == "t") {
90 fprintf(outputFile, "%10.3e ", tStep->giveTargetTime());
91 } else if (rec == "dt") {
92 fprintf(outputFile, "%10.3e ", tStep->giveTimeIncrement());
93 } else if (rec == "cr") {
95 std::string status;
96 if (r == CR_CONVERGED) {
97 status="Converged";
98 } else if (r==CR_DIVERGED_ITS) {
99 status="Diverged_I";
100 } else if (r==CR_DIVERGED_TOL) {
101 status="Diverged_T";
102 } else if (r==CR_FAILED) {
103 status="Failed";
104 } else {
105 status = "Unknown";
106 }
107 fprintf(outputFile, "%10s ", status.c_str());
108 } else if (rec == "st") {
109 int hours = static_cast<int>(tStep->solutionTime) / 3600;
110 int minutes = (static_cast<int>(tStep->solutionTime) % 3600) / 60;
111 double seconds = fmod(tStep->solutionTime, 60.0); // fractional seconds
112 fprintf(outputFile, "%02d:%02d:%04.1f ", hours, minutes, seconds);
113 } else if (rec == "-") {
114 fprintf(outputFile, "%10s ", "-");
115 }
116 }
117 fprintf(outputFile, "\n");
118}
119
120void
122{
123 if (this->outputFile == nullptr) {
124 char filename [100];
125 sprintf( filename, "%s.m%d", this->emodel->giveOutputBaseFileName().c_str(), this->number);
126 this->outputFile = fopen(filename, "w");
127 }
128
129 fprintf(outputFile,"%s (%s, %s)\nGitHash: %s\n", PRG_VERSION, HOST_TYPE, MODULE_LIST, OOFEM_GIT_HASH);
130 time_t currtime = time(NULL);
131 fprintf(outputFile,"Job: %s\n", this->emodel->giveReferenceFileName().c_str());
132 fprintf(outputFile,"%s\n\n", ctime(& currtime));
133 this->printRecsHeader();
134
135}
136
138{
139 fprintf (outputFile, "\nAnalysis finished\n"); // would be nice to include completion status
140
141 // get overall time consumed
142 int rsec = 0, rmin = 0, rhrs = 0;
143 int usec = 0, umin = 0, uhrs = 0;
144 this->emodel->giveAnalysisTime(rhrs, rmin, rsec, uhrs, umin, usec);
145
146 fprintf(outputFile, "Real time consumed: %03dh:%02dm:%02ds\n", rhrs, rmin, rsec);
147 fprintf(outputFile, "User time consumed: %03dh:%02dm:%02ds\n\n", uhrs, umin, usec);
148
149 int nw, ne;
150 oofem_logger.getNumberOfWarningsAndErrors(nw, ne);
151 fprintf (outputFile, "Total %d error(s) and %d warnings reported\n", ne, nw);
152
153 fclose (this->outputFile);
154}
155
156
157void
158SolutionStatusExportModule :: checkRecs()
159{
160 std::string notrecognized;
161 for (auto rec: this->recs) {
162 if (!(rec == "m" || rec == "s" || rec =="a" || rec=="nite" || rec == "t" ||
163 rec =="dt" || rec == "cr" || rec == "st" || rec=="-")) {
164 notrecognized += " " + rec;
165 }
166 }
167 if (notrecognized.size()) {
168 OOFEM_WARNING ("SolutionStatusExportModule: invalid tokens detected: %s", notrecognized.c_str());
169 }
170}
171
172
173void
174SolutionStatusExportModule :: printRecsHeader()
175{
176 for (auto rec: this->recs) {
177 std::string label;
178
179 if (rec == "m") { // metstep number
180 label = "MetaStep";
181 } else if (rec == "s") { // solution step number
182 label = "Step";
183 } else if (rec == "a") { // attempt number
184 label = "Attempt";
185 } else if (rec == "nite") { // number of iterations
186 label = "Step.nite";
187 } else if (rec == "t") {
188 label = "Step.t";
189 } else if (rec == "dt") {
190 label = "Step.dt";
191 } else if (rec == "cr") {
192 label = "Status";
193 } else if (rec == "st") {
194 label = "Solver.t";
195 } else if (rec == "-") {
196 label = "-";
197 }
198 fprintf (outputFile, "%10s ", label.c_str());
199 }
200 fprintf(outputFile, "\n");
201 std::string dashes (this->recs.size() * 11, '-');
202 fprintf(outputFile, "%s\n", dashes.c_str());
203}
204
205} // end namespace oofem
#define REGISTER_ExportModule(class)
EngngModel * emodel
Problem pointer.
bool testTimeStepOutput(TimeStep *tStep)
int numberOfAttempts
Number of attempts (reduction ot time incerement, etc) needed to reach convergence.
Definition timestep.h:118
int giveMetaStepNumber()
Returns receiver's meta step number.
Definition timestep.h:150
ConvergedReason convergedReason
Status of solution step (Converged,.
Definition timestep.h:120
double giveTimeIncrement()
Returns solution step associated time increment.
Definition timestep.h:168
double giveTargetTime()
Returns target time.
Definition timestep.h:164
int numberOfIterations
Number of itarations needed to achieve convergence.
Definition timestep.h:116
int giveNumber()
Returns receiver's number.
Definition timestep.h:144
double solutionTime
time step solution time in seconds
Definition timestep.h:122
#define OOFEM_WARNING(...)
Definition error.h:80
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
Logger oofem_logger(Logger ::LOG_LEVEL_INFO)
Definition logger.h:131
@ CR_DIVERGED_TOL
@ CR_DIVERGED_ITS
OOFEM_EXPORT const char * OOFEM_GIT_HASH
Definition oofemcfg.C:7
OOFEM_EXPORT const char * HOST_TYPE
Definition oofemcfg.C:33
OOFEM_EXPORT const char * PRG_VERSION
Definition oofemcfg.C:4
OOFEM_EXPORT const char * MODULE_LIST
Definition oofemcfg.C:35
#define _IFT_SolutionStatusExportModule_format
Filename where rules are defined (normally the input file).

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