-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more inputs, changed solverInto to inputInfo, and added aerothe…
…rmal (#745) * Added field input and verifed its totals. * Added tests for vector field. * Added the patchVar input. * Added CHT. * Added the missing files. * Added the missing flag.
- Loading branch information
Showing
34 changed files
with
1,816 additions
and
213 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/*---------------------------------------------------------------------------*\ | ||
DAFoam : Discrete Adjoint with OpenFOAM | ||
Version : v4 | ||
\*---------------------------------------------------------------------------*/ | ||
|
||
#include "DAInputField.H" | ||
|
||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
||
namespace Foam | ||
{ | ||
|
||
defineTypeNameAndDebug(DAInputField, 0); | ||
addToRunTimeSelectionTable(DAInput, DAInputField, dictionary); | ||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // | ||
|
||
DAInputField::DAInputField( | ||
const word inputName, | ||
const word inputType, | ||
fvMesh& mesh, | ||
const DAOption& daOption, | ||
const DAModel& daModel, | ||
const DAIndex& daIndex) | ||
: DAInput( | ||
inputName, | ||
inputType, | ||
mesh, | ||
daOption, | ||
daModel, | ||
daIndex) | ||
{ | ||
fieldName_ = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName).getWord("fieldName"); | ||
fieldType_ = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName).getWord("fieldType"); | ||
} | ||
|
||
void DAInputField::run(const scalarList& input) | ||
{ | ||
/* | ||
Description: | ||
Assign the input array to OF's field variables. Note that we need different treatment for distributed and | ||
non-distributed field inputs | ||
*/ | ||
|
||
if (fieldType_ == "scalar") | ||
{ | ||
volScalarField& field = const_cast<volScalarField&>(mesh_.thisDb().lookupObject<volScalarField>(fieldName_)); | ||
if (this->distributed()) | ||
{ | ||
forAll(field, cellI) | ||
{ | ||
field[cellI] = input[cellI]; | ||
} | ||
} | ||
else | ||
{ | ||
for (label globalCellI = 0; globalCellI < daIndex_.nGlobalCells; globalCellI++) | ||
{ | ||
if (daIndex_.globalCellNumbering.isLocal(globalCellI)) | ||
{ | ||
label localCellI = daIndex_.globalCellNumbering.toLocal(globalCellI); | ||
field[localCellI] = input[globalCellI]; | ||
} | ||
} | ||
} | ||
field.correctBoundaryConditions(); | ||
} | ||
else if (fieldType_ == "vector") | ||
{ | ||
volVectorField& field = const_cast<volVectorField&>(mesh_.thisDb().lookupObject<volVectorField>(fieldName_)); | ||
if (this->distributed()) | ||
{ | ||
label counterI = 0; | ||
forAll(field, cellI) | ||
{ | ||
for (label i = 0; i < 3; i++) | ||
{ | ||
field[cellI][i] = input[counterI]; | ||
counterI++; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
for (label globalCellI = 0; globalCellI < daIndex_.nGlobalCells; globalCellI++) | ||
{ | ||
if (daIndex_.globalCellNumbering.isLocal(globalCellI)) | ||
{ | ||
label localCellI = daIndex_.globalCellNumbering.toLocal(globalCellI); | ||
for (label comp = 0; comp < 3; comp++) | ||
{ | ||
label inputIdx = globalCellI * 3 + comp; | ||
field[localCellI][comp] = input[inputIdx]; | ||
} | ||
} | ||
} | ||
} | ||
field.correctBoundaryConditions(); | ||
} | ||
else | ||
{ | ||
FatalErrorIn("DAInputField::run") << exit(FatalError); | ||
} | ||
} | ||
|
||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
||
} // End namespace Foam | ||
|
||
// ************************************************************************* // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/*---------------------------------------------------------------------------*\ | ||
DAFoam : Discrete Adjoint with OpenFOAM | ||
Version : v4 | ||
Description: | ||
Child class for field variable input | ||
\*---------------------------------------------------------------------------*/ | ||
|
||
#ifndef DAInputField_H | ||
#define DAInputField_H | ||
|
||
#include "DAInput.H" | ||
#include "addToRunTimeSelectionTable.H" | ||
#include "mixedFvPatchFields.H" | ||
#include "DAGlobalVar.H" | ||
|
||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
||
namespace Foam | ||
{ | ||
|
||
/*---------------------------------------------------------------------------*\ | ||
Class DAInputField Declaration | ||
\*---------------------------------------------------------------------------*/ | ||
|
||
class DAInputField | ||
: public DAInput | ||
{ | ||
|
||
protected: | ||
word fieldName_; | ||
word fieldType_; | ||
|
||
public: | ||
TypeName("field"); | ||
// Constructors | ||
|
||
//- Construct from components | ||
DAInputField( | ||
const word inputName, | ||
const word inputType, | ||
fvMesh& mesh, | ||
const DAOption& daOption, | ||
const DAModel& daModel, | ||
const DAIndex& daIndex); | ||
|
||
//- Destructor | ||
virtual ~DAInputField() | ||
{ | ||
} | ||
|
||
virtual void run(const scalarList& input); | ||
|
||
virtual label size() | ||
{ | ||
if (fieldType_ == "scalar") | ||
{ | ||
if (this->distributed()) | ||
{ | ||
return daIndex_.nLocalCells; | ||
} | ||
else | ||
{ | ||
return daIndex_.nGlobalCells; | ||
} | ||
} | ||
else if (fieldType_ == "vector") | ||
{ | ||
if (this->distributed()) | ||
{ | ||
return daIndex_.nLocalCells * 3; | ||
} | ||
else | ||
{ | ||
return daIndex_.nGlobalCells * 3; | ||
} | ||
} | ||
else | ||
{ | ||
FatalErrorIn("DAInputField::size") << "fieldType not valid" << exit(FatalError); | ||
return -1; | ||
} | ||
} | ||
|
||
virtual label distributed() | ||
{ | ||
label distributed = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName_).getLabel("distributed"); | ||
return distributed; | ||
} | ||
}; | ||
|
||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
||
} // End namespace Foam | ||
|
||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
||
#endif | ||
|
||
// ************************************************************************* // |
Oops, something went wrong.