OOFEM 3.0
Loading...
Searching...
No Matches
homexportmodule.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 "homexportmodule.h"
36#include "timestep.h"
37#include "element.h"
38#include "gausspoint.h"
39#include "engngm.h"
40#include "material.h"
41#include "classfactory.h"
42#include "crosssection.h"
46
47namespace oofem {
49
50HOMExportModule :: HOMExportModule(int n, EngngModel *e) : ExportModule(n, e) { }
51
52HOMExportModule :: ~HOMExportModule() { }
53
54void
55HOMExportModule :: initializeFrom(InputRecord &ir)
56{
57 ExportModule :: initializeFrom(ir);
58
60 this->reactions = 0;
62 this->scale = 1.;
66
67 lastStress.resize(0);
68 lastStrainStressDep.resize(0);
69}
70
71void
72HOMExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
73{
74 if ( !( testTimeStepOutput(tStep) || forcedOutput ) ) {
75 return;
76 }
77 bool outputVol = false;
78 double volTot;
79 FloatArray answer;
80 this->stream << std::scientific << tStep->giveTargetTime()*this->timeScale << " ";
81
82 //assemble list of eligible elements. Elements can be present more times in a list but averaging goes just once over each element.
83 elements.resize(0);
84 for ( int ireg = 1; ireg <= this->giveNumberOfRegions(); ireg++ ) {
85 elements.followedBy(this->giveRegionSet(ireg)->giveElementList());
86 }
87 //elements.printYourself();
88
89 if (!ists.isEmpty()) {
90 for ( int ist: ists ) {
91 average(answer, volTot, ist, false, tStep);
92
93 if(!outputVol){
94 this->stream << std::scientific << volTot << " ";
95 outputVol = true;
96 }
97
98 if(answer.giveSize() == 0) { //value not defined
99 this->stream << "-";
100 } else if (answer.giveSize() == 1) {
101 this->stream << answer.at(1);
102 } else {
103 this->stream << answer.giveSize() << " ";
104 for ( auto s: answer ) {
105 this->stream << std::scientific << s << " ";
106 }
107 }
108 this->stream << " ";
109 }
110 }
111 if (reactions) {
113 /*
114 TransientTransportProblem *TTP = dynamic_cast< TransientTransportProblem * >(emodel);
115 FieldPtr fld = TTP->giveField(FT_HumidityConcentration, tStep);
116 */
117
118 }
119
120
121 if(strainEnergy){
122 average(answer, volTot, IST_Undefined, true, tStep);
123 strainEnergySumStressDep += answer.at(1);
124 this->stream << answer.at(1) << " " << strainEnergySumStressDep;
125 }
126
127 this->stream << "\n" << std::flush;
128}
129
130
131void
132HOMExportModule :: average(FloatArray &answer, double &volTot, int ist, bool strainEn, TimeStep *tStep)
133{
134 FloatArray ipState, tmp;
135 answer.resize(0);
136 volTot = 0.;
137 double dStrainEnergyStressDep=0;
138 int num = 0;
139 Domain *d = emodel->giveDomain(1);
140 for ( auto &elem : d->giveElements() ) {
141 //printf("%d ", elem -> giveNumber());
142 if ( elements.contains(elem -> giveNumber()) ){
143 for ( GaussPoint *gp: *elem->giveDefaultIntegrationRulePtr() ) {
144 double dV = elem->computeVolumeAround(gp);
145 volTot += dV;
146
147 if(strainEn){
148#ifdef __SM_MODULE
149 FloatArray stress, lastStressIP, strain, strainRed, tmp, strainStressDep, lastStrainStressDepIP, avSig, dEpsStressDep;
150 elem->giveGlobalIPValue(stress, gp, IST_StressTensor, tStep); //returns in giveFullSymVectorForm
151 elem->giveGlobalIPValue(strain, gp, IST_StrainTensor, tStep);
152
153 //Get stress-dependent strain, need FullSymVectorForm of (eps-eps_eig)
154 StructuralMaterial :: giveReducedSymVectorForm(strainRed, strain, gp->giveMaterialMode());
155 dynamic_cast< StructuralMaterial * >(elem->giveCrossSection()->giveMaterial(gp))->giveStressDependentPartOfStrainVector(tmp, gp, strainRed, tStep, VM_Total);
156 StructuralMaterial :: giveFullSymVectorForm(strainStressDep, tmp, gp->giveMaterialMode());
157
158 if(int(lastStress.size()) <= num){
159 lastStressIP.resize(stress.giveSize());
160 lastStressIP.zero();
161 lastStrainStressDepIP.resize(stress.giveSize());
162 lastStrainStressDepIP.zero();
163 } else {
164 lastStressIP = lastStress[num];
165 lastStrainStressDepIP = lastStrainStressDep[num];
166 }
167
168
169 avSig = 0.5*lastStressIP + 0.5*stress;
170 dEpsStressDep.beDifferenceOf(strainStressDep, lastStrainStressDepIP);
171
172 dStrainEnergyStressDep += dV*avSig.dotProduct(dEpsStressDep);
173
174 //memorize current values for the next step
175 if(int(lastStress.size()) <= num){
176 lastStress.push_back(stress);
177 lastStrainStressDep.push_back(strainStressDep);
178 } else {
179 lastStress[num] = stress;
180 lastStrainStressDep[num] = strainStressDep;
181 }
182 num++;
183#else
184 OOFEM_ERROR("Strain energy calculation requires SM module");
185#endif
186 } else {
187 elem->giveGlobalIPValue(ipState, gp, (InternalStateType)ist, tStep);
188 answer.add(dV, ipState);
189 }
190
191 }
192 }
193 }
194
195 if(strainEn){
196 answer.resize(1);
197 answer.at(1) = dStrainEnergyStressDep ;
198 return;
199 } else {
200 answer.times( 1. / volTot * this->scale );
201 return;
202 }
203}
204
205
206void
207HOMExportModule :: initialize()
208{
209 char numStr[32];
210 sprintf(numStr, "%02d", this->number);
211 std::string fileName = emodel->giveOutputBaseFileName() + "." + numStr + ".hom";
212 stream = std::ofstream(fileName);
213 if ( !stream.good() ) {
214 OOFEM_ERROR("failed to open file %s", fileName.c_str() );
215 }
216
217 this->stream << "#Time Volume ";
218 for ( int var: this->ists ) {
219 this->stream << __InternalStateTypeToString( ( InternalStateType ) var) << " ";
220 }
221
222 if(this->strainEnergy){
223 this->stream << "StrainEnergyIncrStressDep StrainEnergySumStressDep ";
224 }
225
226 this->stream << "\n" << std::flush;
227
229
230 ExportModule :: initialize();
231}
232
233void
234HOMExportModule :: terminate()
235{
236
237 if (this->stream){
238 this->stream.close();
239 }
240}
241} // end namespace oofem
#define REGISTER_ExportModule(class)
std ::vector< std ::unique_ptr< Element > > & giveElements()
Definition domain.h:294
double timeScale
Scaling time in output, e.g. conversion from seconds to hours.
virtual void initializeElementSet()
int number
Component number.
Set * giveRegionSet(int i)
Returns element set.
int giveNumberOfRegions()
Returns number of regions (aka regionSets).
EngngModel * emodel
Problem pointer.
bool testTimeStepOutput(TimeStep *tStep)
void resize(Index s)
Definition floatarray.C:94
double & at(Index i)
Definition floatarray.h:202
double dotProduct(const FloatArray &x) const
Definition floatarray.C:524
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
void beDifferenceOf(const FloatArray &a, const FloatArray &b)
Definition floatarray.C:403
void zero()
Zeroes all coefficients of receiver.
Definition floatarray.C:683
void add(const FloatArray &src)
Definition floatarray.C:218
void times(double s)
Definition floatarray.C:834
bool reactions
Reactions to export.
std::vector< FloatArray > lastStress
Last averaged stress.
IntArray ists
Internal states to export.
void average(FloatArray &answer, double &volTot, int ist, bool subtractStressDepStrain, TimeStep *tStep)
double scale
Scale of all homogenized values.
bool strainEnergy
Allow calculation of strain energy, evaluated from mid-point rule (exact for linear elastic problems ...
IntArray elements
List of elements.
std::ofstream stream
Stream for file.
std::vector< FloatArray > lastStrainStressDep
Last averaged stress-dependent strain.
virtual bool hasField(InputFieldType id)=0
Returns true if record contains field identified by idString keyword.
void giveStressDependentPartOfStrainVector(FloatArray &answer, GaussPoint *gp, const FloatArray &reducedStrainVector, TimeStep *tStep, ValueModeType mode) const
double giveTargetTime()
Returns target time.
Definition timestep.h:164
#define OOFEM_ERROR(...)
Definition error.h:79
#define _IFT_HOMExportModule_reactions
#define _IFT_HOMExportModule_ISTs
#define _IFT_HOMExportModule_scale
#define _IFT_HOMExportModule_strain_energy
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
const char * __InternalStateTypeToString(InternalStateType _value)
Definition cltypes.C:309

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