Skip to content

Commit a7f2a78

Browse files
colemanjsgknapp1
andauthored
add function object for solidification data (#74)
* add function object for solidification data * enable function options through system flags * fix function object file headers and file reconstruction --------- Co-authored-by: Gerry Knapp <knappgl@ornl.gov>
1 parent 99102b7 commit a7f2a78

File tree

21 files changed

+533
-94
lines changed

21 files changed

+533
-94
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.bak
66
*.bak[0-9][0-9]
77
\#*\#
8+
.nfs*
89

910
# File-browser settings - anywhere
1011
.directory
@@ -36,6 +37,7 @@ linux*Icc*/
3637
solaris*Gcc*/
3738
SunOS*Gcc*/
3839
platforms/
40+
gitInfo.H
3941

4042
# Source packages - anywhere
4143
*.tar.bz2

applications/solvers/additiveFoam/Allwclean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cd ${0%/*} || exit 1 # Run from this directory
33

44
rm -rf Make/gitInfo.H
55

6-
wclean libso functionObjects/ExaCA
6+
wclean libso functionObjects
77
wclean libso movingHeatSource
88
wclean
99

applications/solvers/additiveFoam/Allwmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export ADDITIVEFOAM_BUILD_FLAGS="-DGIT_MODULE_ENABLED=1"
2727

2828
#------------------------------------------------------------------------------
2929
# Build libraries and solver
30-
wmake $targetType functionObjects/ExaCA
30+
wmake $targetType functionObjects
3131
wmake $targetType movingHeatSource
3232
wmake $targetType
3333

applications/solvers/additiveFoam/functionObjects/ExaCA/ExaCA.C

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ void Foam::functionObjects::ExaCA::interpolate()
405405
exacaPath + "/" + "data_" + Foam::name(Pstream::myProcNo()) + ".csv"
406406
);
407407

408+
os << "x,y,z,tm,ts,cr" << endl;
409+
408410
for(int i=0; i < data.size(); i++)
409411
{
410412
int n = data[i].size()-1;

applications/solvers/additiveFoam/functionObjects/ExaCA/Make/files

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ExaCA/ExaCA.C
2+
solidificationData/solidificationData.C
3+
4+
LIB = $(FOAM_USER_LIBBIN)/libadditiveFoamFunctionObjects

applications/solvers/additiveFoam/functionObjects/ExaCA/Make/options renamed to applications/solvers/additiveFoam/functionObjects/Make/options

File renamed without changes.
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
/*---------------------------------------------------------------------------*\
2+
========= |
3+
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4+
\\ / O peration | Website: https://openfoam.org
5+
\\ / A nd | Copyright (C) 2024 OpenFOAM Foundation
6+
\\/ M anipulation |
7+
-------------------------------------------------------------------------------
8+
Copyright (C) 2023 Oak Ridge National Laboratory
9+
-------------------------------------------------------------------------------
10+
License
11+
This file is part of OpenFOAM.
12+
13+
OpenFOAM is free software: you can redistribute it and/or modify it
14+
under the terms of the GNU General Public License as published by
15+
the Free Software Foundation, either version 3 of the License, or
16+
(at your option) any later version.
17+
18+
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21+
for more details.
22+
23+
You should have received a copy of the GNU General Public License
24+
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25+
26+
\*---------------------------------------------------------------------------*/
27+
28+
#include "solidificationData.H"
29+
#include "Time.H"
30+
#include "fvMesh.H"
31+
#include "addToRunTimeSelectionTable.H"
32+
#include "volFields.H"
33+
#include "fvc.H"
34+
#include "OFstream.H"
35+
#include "OSspecific.H"
36+
#include "labelVector.H"
37+
38+
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39+
40+
namespace Foam
41+
{
42+
namespace functionObjects
43+
{
44+
defineTypeNameAndDebug(solidificationData, 0);
45+
46+
addToRunTimeSelectionTable
47+
(
48+
functionObject,
49+
solidificationData,
50+
dictionary
51+
);
52+
}
53+
}
54+
55+
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56+
57+
Foam::functionObjects::solidificationData::solidificationData
58+
(
59+
const word& name,
60+
const Time& runTime,
61+
const dictionary& dict
62+
)
63+
:
64+
fvMeshFunctionObject(name, runTime, dict),
65+
T_(mesh_.lookupObject<VolField<scalar>>("T")),
66+
R_
67+
(
68+
IOobject
69+
(
70+
"R",
71+
mesh_.time().timeName(),
72+
mesh_,
73+
IOobject::NO_READ,
74+
IOobject::NO_WRITE
75+
),
76+
fvc::ddt(T_)
77+
),
78+
searchEngine_(mesh_, polyMesh::CELL_TETS)
79+
{
80+
read(dict);
81+
82+
setOverlapCells();
83+
}
84+
85+
86+
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
87+
88+
Foam::functionObjects::solidificationData::~solidificationData()
89+
{}
90+
91+
92+
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93+
94+
bool Foam::functionObjects::solidificationData::read(const dictionary& dict)
95+
{
96+
box_ = dict.lookup("box");
97+
isoValue_ = dict.lookup<scalar>("isoValue");
98+
99+
return true;
100+
}
101+
102+
void Foam::functionObjects::solidificationData::setOverlapCells()
103+
{
104+
// create a compact cell-stencil using the overlap sub-space
105+
const pointField& points = mesh_.points();
106+
107+
boundBox procBb(points);
108+
109+
const vector extend = 1e-10*vector::one;
110+
111+
if (procBb.overlaps(box_))
112+
{
113+
forAll(mesh_.cells(), celli)
114+
{
115+
boundBox cellBb(point::max, point::min);
116+
117+
const labelList& vertices = mesh_.cellPoints()[celli];
118+
119+
forAll(vertices, i)
120+
{
121+
cellBb.min() = min(cellBb.min(), points[vertices[i]] - extend);
122+
cellBb.max() = max(cellBb.max(), points[vertices[i]] + extend);
123+
}
124+
125+
if (cellBb.overlaps(box_))
126+
{
127+
overlapCells.append(celli);
128+
}
129+
}
130+
}
131+
132+
overlapCells.shrink();
133+
}
134+
135+
136+
Foam::wordList Foam::functionObjects::solidificationData::fields() const
137+
{
138+
return wordList::null();
139+
}
140+
141+
142+
bool Foam::functionObjects::solidificationData::execute()
143+
{
144+
//- Get current time
145+
const scalar& time = mesh_.time().value();
146+
147+
//- Get the temperature at the previous time
148+
const volScalarField& T0_ = T_.oldTime();
149+
150+
//- Calculate the thermal gradient
151+
const volScalarField G("G", mag(fvc::grad(T_)));
152+
153+
forAll(overlapCells, i)
154+
{
155+
label celli = overlapCells[i];
156+
157+
// Cooled below specified isotherm
158+
if ((T0_[celli] > isoValue_) && (T_[celli] <= isoValue_))
159+
{
160+
const scalar Ri = mag(R_[celli]);
161+
const scalar Gi = max(G[celli], small);
162+
163+
const vector pt = mesh_.C()[celli];
164+
165+
List<scalar> event(7);
166+
167+
event[0] = pt[0];
168+
event[1] = pt[1];
169+
event[2] = pt[2];
170+
event[3] = time;
171+
event[4] = Ri;
172+
event[5] = Gi;
173+
event[6] = Ri / Gi;
174+
175+
events.append(event);
176+
}
177+
}
178+
179+
//- Update cooling rate
180+
R_ = fvc::ddt(T_);
181+
182+
return true;
183+
}
184+
185+
bool Foam::functionObjects::solidificationData::end()
186+
{
187+
Info<< "Number of solidification events: "
188+
<< returnReduce(events.size(), sumOp<scalar>()) << endl;
189+
190+
const fileName filePath
191+
(
192+
mesh_.time().rootPath()
193+
/mesh_.time().globalCaseName()
194+
/"solidificationData"
195+
);
196+
197+
mkDir(filePath);
198+
199+
OFstream os
200+
(
201+
filePath + "/" + "data_" + Foam::name(Pstream::myProcNo()) + ".csv"
202+
);
203+
204+
os << "x,y,z,ts,cr,g,v" << endl;
205+
206+
for(int i=0; i < events.size(); i++)
207+
{
208+
int n = events[i].size() - 1;
209+
210+
for(int j=0; j < n; j++)
211+
{
212+
os << events[i][j] << ",";
213+
}
214+
os << events[i][n] << "\n";
215+
}
216+
217+
Info<< "Successfully wrote solidification data in: "
218+
<< returnReduce(mesh_.time().cpuTimeIncrement(), maxOp<scalar>()) << " s"
219+
<< endl << endl;
220+
221+
return true;
222+
}
223+
224+
225+
bool Foam::functionObjects::solidificationData::write()
226+
{
227+
return true;
228+
}
229+
230+
231+
// ************************************************************************* //

0 commit comments

Comments
 (0)