Skip to content

Commit 46c1dcf

Browse files
authoredJun 30, 2020
Merge pull request #131 from precice/refactor-assign-construct
Refactor to reduce assigning fields at creation
2 parents 84a3178 + 0eb0742 commit 46c1dcf

9 files changed

+120
-63
lines changed
 

‎CHT/HeatFlux.C

+13-8
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ void preciceAdapter::CHT::HeatFlux::write(double * buffer, bool meshConnectivity
3333
{
3434
int patchID = patchIDs_.at(j);
3535

36-
scalarField gradientPatch=refCast<fixedValueFvPatchScalarField>
37-
(T_->boundaryFieldRef()[patchID]
38-
).snGrad();
36+
scalarField gradientPatch
37+
(
38+
refCast<fixedValueFvPatchScalarField>
39+
(
40+
T_->boundaryFieldRef()[patchID]
41+
).snGrad()
42+
);
3943

4044
// Extract the effective conductivity on the patch
4145
extractKappaEff(patchID, meshConnectivity);
@@ -94,11 +98,12 @@ void preciceAdapter::CHT::HeatFlux::read(double * buffer, const unsigned int dim
9498

9599
// Get the temperature gradient boundary patch
96100
scalarField & gradientPatch
97-
=
98-
refCast<fixedGradientFvPatchScalarField>
99-
(
100-
T_->boundaryFieldRef()[patchID]
101-
).gradient();
101+
(
102+
refCast<fixedGradientFvPatchScalarField>
103+
(
104+
T_->boundaryFieldRef()[patchID]
105+
).gradient()
106+
);
102107

103108
// For every cell of the patch
104109
forAll(gradientPatch, i)

‎CHT/HeatTransferCoefficient.C

+15-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ void preciceAdapter::CHT::HeatTransferCoefficient::write(double * buffer, bool m
3939
extractKappaEff(patchID, meshConnectivity);
4040

4141
// Get the face-cell distance coefficients on the patch
42-
const scalarField & delta = mesh_.boundary()[patchID].deltaCoeffs();
42+
const scalarField & delta
43+
(
44+
mesh_.boundary()[patchID].deltaCoeffs()
45+
);
4346

4447
//If we use the mesh connectivity, we interpolate from the centres to the nodes
4548
if(meshConnectivity)
@@ -91,11 +94,19 @@ void preciceAdapter::CHT::HeatTransferCoefficient::read(double * buffer, const u
9194
extractKappaEff(patchID,/*meshConnectivity=*/false);
9295

9396
// Get the face-cell distance coefficients on the patch
94-
const scalarField & delta = mesh_.boundary()[patchID].deltaCoeffs();
97+
const scalarField & delta
98+
(
99+
mesh_.boundary()[patchID].deltaCoeffs()
100+
);
95101

96102
// Get a reference to the temperature on the patch
97-
mixedFvPatchScalarField & TPatch =
98-
refCast<mixedFvPatchScalarField>(T_->boundaryFieldRef()[patchID]);
103+
mixedFvPatchScalarField & TPatch
104+
(
105+
refCast<mixedFvPatchScalarField>
106+
(
107+
T_->boundaryFieldRef()[patchID]
108+
)
109+
);
99110

100111
// For every cell on the patch
101112
forAll(TPatch, i)

‎CHT/KappaEffective.C

+12-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ void preciceAdapter::CHT::KappaEff_Incompressible::extract(uint patchID, bool me
125125

126126
// Get the laminar viscosity from the turbulence model
127127
// TODO: Do we really need turbulence at the end?
128-
const scalarField & nu = turbulence_.nu() ().boundaryField()[patchID];
128+
const scalarField & nu
129+
(
130+
turbulence_.nu() ().boundaryField()[patchID]
131+
);
129132

130133
// Compute the effective thermal diffusivity
131134
// (alphaEff = alpha + alphat = nu / Pr + nut / Prt)
@@ -135,8 +138,10 @@ void preciceAdapter::CHT::KappaEff_Incompressible::extract(uint patchID, bool me
135138
// Does the turbulent thermal diffusivity exist in the object registry?
136139
if (mesh_.foundObject<volScalarField>(nameAlphat_))
137140
{
138-
const scalarField & alphat =
139-
mesh_.lookupObject<volScalarField>(nameAlphat_).boundaryField()[patchID];
141+
const scalarField & alphat
142+
(
143+
mesh_.lookupObject<volScalarField>(nameAlphat_).boundaryField()[patchID]
144+
);
140145

141146
alphaEff = nu / Pr_.value() + alphat;
142147
}
@@ -153,7 +158,10 @@ void preciceAdapter::CHT::KappaEff_Incompressible::extract(uint patchID, bool me
153158
}
154159

155160
// Compute the effective thermal conductivity and store it in a temp variable
156-
scalarField kappaEff_temp = alphaEff * rho_.value() * Cp_.value();
161+
scalarField kappaEff_temp
162+
(
163+
alphaEff * rho_.value() * Cp_.value()
164+
);
157165

158166
if(meshConnectivity)
159167
{

‎CHT/SinkTemperature.C

+14-10
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ void preciceAdapter::CHT::SinkTemperature::write(double * buffer, bool meshConne
3131
int patchID = patchIDs_.at(j);
3232

3333
// Get the boundary field of Temperature on the patch
34-
fvPatchScalarField & TPatch =
35-
refCast<fvPatchScalarField>
36-
(
37-
T_->boundaryFieldRef()[patchID]
38-
);
34+
fvPatchScalarField & TPatch
35+
(
36+
refCast<fvPatchScalarField>
37+
(
38+
T_->boundaryFieldRef()[patchID]
39+
)
40+
);
3941

4042
// Get the internal field next to the patch // TODO: Simplify?
4143
tmp<scalarField> patchInternalFieldTmp = TPatch.patchInternalField();
@@ -88,11 +90,13 @@ void preciceAdapter::CHT::SinkTemperature::read(double * buffer, const unsigned
8890
int patchID = patchIDs_.at(j);
8991

9092
// Get the boundary field of the temperature on the patch
91-
mixedFvPatchScalarField & TPatch =
92-
refCast<mixedFvPatchScalarField>
93-
(
94-
T_->boundaryFieldRef()[patchID]
95-
);
93+
mixedFvPatchScalarField & TPatch
94+
(
95+
refCast<mixedFvPatchScalarField>
96+
(
97+
T_->boundaryFieldRef()[patchID]
98+
)
99+
);
96100

97101
// Get a reference to the reference value on the patch
98102
scalarField & Tref = TPatch.refValue();

‎CHT/Temperature.C

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,22 @@ void preciceAdapter::CHT::Temperature::write(double * buffer, bool meshConnectiv
3232
{
3333
int patchID = patchIDs_.at(j);
3434

35-
const scalarField& TPatch=T_->boundaryFieldRef()[patchID];
35+
const scalarField& TPatch
36+
(
37+
T_->boundaryFieldRef()[patchID]
38+
);
3639

3740
//If we use the mesh connectivity, we interpolate from the centres to the nodes
3841
if(meshConnectivity)
3942
{
4043
//Create an Interpolation object at the boundary Field
4144
primitivePatchInterpolation patchInterpolator(mesh_.boundaryMesh()[patchID]);
4245

43-
scalarField TPoints;
44-
4546
//Interpolate from centers to nodes
46-
TPoints= patchInterpolator.faceToPointInterpolate(TPatch);
47+
scalarField TPoints
48+
(
49+
patchInterpolator.faceToPointInterpolate(TPatch)
50+
);
4751

4852
forAll(TPoints, i)
4953
{

‎FSI/Displacement.C

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ void preciceAdapter::FSI::Displacement::read(double * buffer, const unsigned int
4242
int patchID = patchIDs_.at(j);
4343

4444
// Get the displacement on the patch
45-
fixedValuePointPatchVectorField& pointDisplacementFluidPatch =
45+
fixedValuePointPatchVectorField& pointDisplacementFluidPatch
46+
(
4647
refCast<fixedValuePointPatchVectorField>
4748
(
4849
pointDisplacement_->boundaryFieldRef()[patchID]
49-
);
50+
)
51+
);
5052

5153
// For every cell of the patch
5254
forAll(pointDisplacement_->boundaryFieldRef()[patchID], i)

‎FSI/DisplacementDelta.C

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ void preciceAdapter::FSI::DisplacementDelta::read(double * buffer, const unsigne
4242
int patchID = patchIDs_.at(j);
4343

4444
// Get the displacement on the patch
45-
fixedValuePointPatchVectorField& pointDisplacementFluidPatch =
45+
fixedValuePointPatchVectorField& pointDisplacementFluidPatch
46+
(
4647
refCast<fixedValuePointPatchVectorField>
4748
(
4849
pointDisplacement_->boundaryFieldRef()[patchID]
49-
);
50+
)
51+
);
5052

5153
// For every cell of the patch
5254
forAll(pointDisplacement_->boundaryFieldRef()[patchID], i)

‎FSI/Force.C

+35-20
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,31 @@ Foam::tmp<Foam::volSymmTensorField> preciceAdapter::FSI::Force::devRhoReff() con
6464
typedef incompressible::turbulenceModel icoTurbModel;
6565

6666
if (mesh_.foundObject<cmpTurbModel>(cmpTurbModel::propertiesName))
67-
{
68-
const cmpTurbModel& turb =
69-
mesh_.lookupObject<cmpTurbModel>(cmpTurbModel::propertiesName);
70-
67+
{
68+
const cmpTurbModel & turb
69+
(
70+
mesh_.lookupObject<cmpTurbModel>(cmpTurbModel::propertiesName)
71+
);
72+
7173
return turb.devRhoReff();
7274

73-
}
75+
}
7476
else if (mesh_.foundObject<icoTurbModel>(icoTurbModel::propertiesName))
75-
{
76-
const incompressible::turbulenceModel& turb =
77-
mesh_.lookupObject<icoTurbModel>(icoTurbModel::propertiesName);
78-
77+
{
78+
const incompressible::turbulenceModel& turb
79+
(
80+
mesh_.lookupObject<icoTurbModel>(icoTurbModel::propertiesName)
81+
);
82+
7983
return rho()*turb.devReff();
8084
}
8185
else
8286
{
8387
// For laminar flows get the velocity
84-
const volVectorField& U = mesh_.lookupObject<volVectorField>("U");
88+
const volVectorField & U
89+
(
90+
mesh_.lookupObject<volVectorField>("U")
91+
);
8592

8693
return -mu()*dev(twoSymm(fvc::grad(U)));
8794
}
@@ -139,8 +146,10 @@ Foam::tmp<Foam::volScalarField> preciceAdapter::FSI::Force::mu() const
139146
typedef immiscibleIncompressibleTwoPhaseMixture iitpMixture;
140147
if (mesh_.foundObject<iitpMixture>("mixture"))
141148
{
142-
const iitpMixture& mixture =
143-
mesh_.lookupObject<iitpMixture>("mixture");
149+
const iitpMixture& mixture
150+
(
151+
mesh_.lookupObject<iitpMixture>("mixture")
152+
);
144153

145154
return mixture.mu();
146155
}
@@ -181,23 +190,29 @@ void preciceAdapter::FSI::Force::write(double * buffer, bool meshConnectivity, c
181190
// Compute forces. See the Forces function object.
182191

183192
// Normal vectors on the boundary, multiplied with the face areas
184-
const surfaceVectorField::Boundary& Sfb =
185-
mesh_.Sf().boundaryField();
193+
const surfaceVectorField::Boundary& Sfb
194+
(
195+
mesh_.Sf().boundaryField()
196+
);
186197

187198
// Stress tensor boundary field
188-
tmp<volSymmTensorField> tdevRhoReff = devRhoReff();
189-
const volSymmTensorField::Boundary& devRhoReffb =
190-
tdevRhoReff().boundaryField();
199+
tmp<volSymmTensorField> tdevRhoReff(devRhoReff());
200+
const volSymmTensorField::Boundary& devRhoReffb
201+
(
202+
tdevRhoReff().boundaryField()
203+
);
191204

192205
// Density boundary field
193-
tmp<volScalarField> trho = rho();
206+
tmp<volScalarField> trho(rho());
194207
const volScalarField::Boundary& rhob =
195208
trho().boundaryField();
196209

197210
// Pressure boundary field
198211
tmp<volScalarField> tp = mesh_.lookupObject<volScalarField>("p");
199-
const volScalarField::Boundary& pb =
200-
tp().boundaryField();
212+
const volScalarField::Boundary& pb
213+
(
214+
tp().boundaryField()
215+
);
201216

202217
int bufferIndex = 0;
203218
// For every boundary patch of the interface

‎FSI/Stress.C

+15-9
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,25 @@ void preciceAdapter::FSI::Stress::write(double * buffer, bool meshConnectivity,
5252
// Compute stress. See the Forces function object.
5353

5454
// Stress tensor boundary field
55-
tmp<volSymmTensorField> tdevRhoReff = this->devRhoReff();
56-
const volSymmTensorField::Boundary& devRhoReffb =
57-
tdevRhoReff().boundaryField();
55+
tmp<volSymmTensorField> tdevRhoReff(this->devRhoReff());
56+
const volSymmTensorField::Boundary& devRhoReffb
57+
(
58+
tdevRhoReff().boundaryField()
59+
);
5860

5961
// Density boundary field
60-
tmp<volScalarField> trho = this->rho();
61-
const volScalarField::Boundary& rhob =
62-
trho().boundaryField();
62+
tmp<volScalarField> trho(this->rho());
63+
const volScalarField::Boundary& rhob
64+
(
65+
trho().boundaryField()
66+
);
6367

6468
// Pressure boundary field
65-
tmp<volScalarField> tp = mesh_.lookupObject<volScalarField>("p");
66-
const volScalarField::Boundary& pb =
67-
tp().boundaryField();
69+
tmp<volScalarField> tp(mesh_.lookupObject<volScalarField>("p"));
70+
const volScalarField::Boundary& pb
71+
(
72+
tp().boundaryField()
73+
);
6874

6975
int bufferIndex = 0;
7076
// For every boundary patch of the interface

0 commit comments

Comments
 (0)
Please sign in to comment.