Skip to content

Commit

Permalink
v2.2.3 (#88)
Browse files Browse the repository at this point in the history
* Updated version.

* Added the AD calls for the FFD design variable.

* Minor edit to the pyDAFoam.py docs.

* Added an option to depress the print info for the setPrimalBoundaryConditions function.

* Fixed an issue in the pyDict2OFDict function to make it compatible with Python 3.8.

* Implemented the AD for dF/dAlpha.

* Added the AD capability for dF/dBC.

* Reverted the AOA and BC derivative to FD since the AD version does not work in parllel yet.

* Updated tests.

* Updated the test srcript.

* Updated the test srcript.
  • Loading branch information
friedenhe authored Feb 7, 2021
1 parent b9b5687 commit 81fb634
Show file tree
Hide file tree
Showing 16 changed files with 1,629 additions and 73 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/reg_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ jobs:
docker run -i -d -u dafoamuser --name regtest -v $GITHUB_WORKSPACE:${{env.DOCKER_MOUNT_DIR}} dafoam/opt-packages:${{env.DOCKER_TAG}} /bin/bash
docker exec -i regtest /bin/bash -c "rm -rf ${{ env.DOCKER_WORKING_DIR}} && cp -r ${{env.DOCKER_MOUNT_DIR}} ${{env.DOCKER_WORKING_DIR}}"
docker exec -i regtest /bin/bash -c ". /home/dafoamuser/loadDAFoam.sh && cd ${{env.DOCKER_WORKING_DIR}} && ./Allmake ${{matrix.args}}"
if [ "${{matrix.args}}" = "incompressible" ]; then
if [ "${{matrix.args}}" = "solid" ]; then
echo "Skip building the AD version for solid"
else
docker exec -i regtest /bin/bash -c ". /home/dafoamuser/loadDAFoam.sh && . /home/dafoamuser/OpenFOAM/OpenFOAM-v1812-AD/etc/bashrc && cd ${{env.DOCKER_WORKING_DIR}} && ./Allclean && ./Allmake ${{matrix.args}} 2> makeWarnings.txt"
fi
docker exec -i regtest /bin/bash -c ". /home/dafoamuser/loadDAFoam.sh && cd ${{env.DOCKER_WORKING_DIR}} && pip install ."
Expand Down
186 changes: 155 additions & 31 deletions dafoam/pyDAFoam.py

Large diffs are not rendered by default.

106 changes: 81 additions & 25 deletions src/adjoint/DAField/DAField.C
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ void DAField::specialBCTreatment()
// *******************************************************************
}

void DAField::setPrimalBoundaryConditions()
void DAField::setPrimalBoundaryConditions(const label printInfo)
{
/*
Description:
Expand Down Expand Up @@ -608,15 +608,21 @@ void DAField::setPrimalBoundaryConditions()
{
if (!db.foundObject<volScalarField>(variable))
{
Info << variable << " not found, skip it." << endl;
if (printInfo)
{
Info << variable << " not found, skip it." << endl;
}
continue;
}
// it is a scalar
volScalarField& state(const_cast<volScalarField&>(
db.lookupObject<volScalarField>(variable)));

Info << "Setting primal boundary conditions..." << endl;
Info << "Setting " << variable << " = " << value[0] << " at " << patch << endl;
if (printInfo)
{
Info << "Setting primal boundary conditions..." << endl;
Info << "Setting " << variable << " = " << value[0] << " at " << patch << endl;
}

label patchI = mesh_.boundaryMesh().findPatchID(patch);

Expand Down Expand Up @@ -665,18 +671,23 @@ void DAField::setPrimalBoundaryConditions()
{
if (!db.foundObject<volVectorField>(variable))
{
Info << variable << " not found, skip it." << endl;
if (printInfo)
{
Info << variable << " not found, skip it." << endl;
}
continue;
}
// it is a vector
volVectorField& state(const_cast<volVectorField&>(
db.lookupObject<volVectorField>(variable)));

vector valVec = {value[0], value[1], value[2]};

Info << "Setting primal boundary conditions..." << endl;
Info << "Setting " << variable << " = (" << value[0] << " "
<< value[1] << " " << value[2] << ") at " << patch << endl;
if (printInfo)
{
Info << "Setting primal boundary conditions..." << endl;
Info << "Setting " << variable << " = (" << value[0] << " "
<< value[1] << " " << value[2] << ") at " << patch << endl;
}

label patchI = mesh_.boundaryMesh().findPatchID(patch);

Expand Down Expand Up @@ -764,8 +775,11 @@ void DAField::setPrimalBoundaryConditions()
{
if (mesh_.boundaryMesh()[patchI].type() == "wall")
{
Info << "Setting nut wall BC for "
<< mesh_.boundaryMesh()[patchI].name() << ". ";
if (printInfo)
{
Info << "Setting nut wall BC for "
<< mesh_.boundaryMesh()[patchI].name() << ". ";
}

if (useWallFunction)
{
Expand All @@ -778,7 +792,11 @@ void DAField::setPrimalBoundaryConditions()
"nutUSpaldingWallFunction",
mesh_.boundary()[patchI],
nut));
Info << "BCType=nutUSpaldingWallFunction" << endl;

if (printInfo)
{
Info << "BCType=nutUSpaldingWallFunction" << endl;
}
}
else // wall function for kOmega and kEpsilon
{
Expand All @@ -788,7 +806,11 @@ void DAField::setPrimalBoundaryConditions()
"nutkWallFunction",
mesh_.boundary()[patchI],
nut));
Info << "BCType=nutkWallFunction" << endl;

if (printInfo)
{
Info << "BCType=nutkWallFunction" << endl;
}
}

// set boundary values
Expand All @@ -811,7 +833,11 @@ void DAField::setPrimalBoundaryConditions()
"nutLowReWallFunction",
mesh_.boundary()[patchI],
nut));
Info << "BCType=nutLowReWallFunction" << endl;

if (printInfo)
{
Info << "BCType=nutLowReWallFunction" << endl;
}

// set boundary values
// for decomposed domain, don't set BC if the patch is empty
Expand Down Expand Up @@ -839,16 +865,23 @@ void DAField::setPrimalBoundaryConditions()
{
if (mesh_.boundaryMesh()[patchI].type() == "wall")
{
Info << "Setting k wall BC for "
<< mesh_.boundaryMesh()[patchI].name() << ". ";
if (printInfo)
{
Info << "Setting k wall BC for "
<< mesh_.boundaryMesh()[patchI].name() << ". ";
}

if (useWallFunction)
{
// wall function for SA
k.boundaryFieldRef().set(
patchI,
fvPatchField<scalar>::New("kqRWallFunction", mesh_.boundary()[patchI], k));
Info << "BCType=kqRWallFunction" << endl;

if (printInfo)
{
Info << "BCType=kqRWallFunction" << endl;
}

// set boundary values
// for decomposed domain, don't set BC if the patch is empty
Expand All @@ -866,7 +899,11 @@ void DAField::setPrimalBoundaryConditions()
k.boundaryFieldRef().set(
patchI,
fvPatchField<scalar>::New("fixedValue", mesh_.boundary()[patchI], k));
Info << "BCType=fixedValue" << endl;

if (printInfo)
{
Info << "BCType=fixedValue" << endl;
}

// set boundary values
// for decomposed domain, don't set BC if the patch is empty
Expand All @@ -893,14 +930,21 @@ void DAField::setPrimalBoundaryConditions()
{
if (mesh_.boundaryMesh()[patchI].type() == "wall")
{
Info << "Setting omega wall BC for "
<< mesh_.boundaryMesh()[patchI].name() << ". ";
if (printInfo)
{
Info << "Setting omega wall BC for "
<< mesh_.boundaryMesh()[patchI].name() << ". ";
}

// always use omegaWallFunction
omega.boundaryFieldRef().set(
patchI,
fvPatchField<scalar>::New("omegaWallFunction", mesh_.boundary()[patchI], omega));
Info << "BCType=omegaWallFunction" << endl;

if (printInfo)
{
Info << "BCType=omegaWallFunction" << endl;
}

// set boundary values
// for decomposed domain, don't set BC if the patch is empty
Expand All @@ -927,15 +971,23 @@ void DAField::setPrimalBoundaryConditions()
{
if (mesh_.boundaryMesh()[patchI].type() == "wall")
{
Info << "Setting epsilon wall BC for "
<< mesh_.boundaryMesh()[patchI].name() << ". ";

if (printInfo)
{
Info << "Setting epsilon wall BC for "
<< mesh_.boundaryMesh()[patchI].name() << ". ";
}

if (useWallFunction)
{
epsilon.boundaryFieldRef().set(
patchI,
fvPatchField<scalar>::New("epsilonWallFunction", mesh_.boundary()[patchI], epsilon));
Info << "BCType=epsilonWallFunction" << endl;

if (printInfo)
{
Info << "BCType=epsilonWallFunction" << endl;
}

// set boundary values
// for decomposed domain, don't set BC if the patch is empty
Expand All @@ -953,7 +1005,11 @@ void DAField::setPrimalBoundaryConditions()
epsilon.boundaryFieldRef().set(
patchI,
fvPatchField<scalar>::New("fixedValue", mesh_.boundary()[patchI], epsilon));
Info << "BCType=fixedValue" << endl;

if (printInfo)
{
Info << "BCType=fixedValue" << endl;
}

// set boundary values
// for decomposed domain, don't set BC if the patch is empty
Expand Down
3 changes: 1 addition & 2 deletions src/adjoint/DAField/DAField.H
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public:
const scalarList& stateBounaryList) const;

/// set the boundary conditions based on parameters defined in DAOption
void setPrimalBoundaryConditions();
void setPrimalBoundaryConditions(const label printInfo = 1);

/// apply special treatment for boundary conditions
void specialBCTreatment();
Expand All @@ -113,7 +113,6 @@ public:

/// a list that contains the names of detected special boundary conditions
wordList specialBCs;

};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Expand Down
Loading

0 comments on commit 81fb634

Please sign in to comment.