forked from smdogroup/tacs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding constraint classes to pyTACS (smdogroup#202)
* First cut at adjacency constraint class * Minor comment updates * Abstracting constraint class * Adding constraint classes to integration test * Adding constraint section to docs * Updating docstrings * Adding DVConstraint class * Adding DVConstraint to docs * Minor warning update * Minor docstring update * Minor docstring update * Minor bugfix in DVConstraint * Docstring update * Docstring update * Docstring update * Minor bugfix in Adjacency constraint * Minor docstring update * Adding constraints module to conda build test * Adding `getConstraintSizes` method * Adding constraints to mphys wrapper * Adding adjacency constraints to mphys tests * Adding allreduce to mphys constraints forward sens * Moving tacs constraints to mphys post_solve group * Minor speedup for AdjacencyConstraint * Adding EnclosedVolume function to TACS * Adding VolumeConstraint to pyTACS * Adding VolumeConstraint to integration tests * Adding VolumeConstraint to documentation * Adding shell VolumeConstraint integration test * Adding distribute call before sens return for VolumeConstraint * Adding volume closure check to VolumeConstraint class * Docstring update * Minor refactor * Adding volume constraint options to docs * Docstring update * Adding writeVisualization method to VolumeConstraint and AdjacencyConstraint * Switching visualization files to .dat format * Switching visualization files to .dat format * Removing accidental commit * docstring typo * Making volume xpt sens a column vector
- Loading branch information
Showing
40 changed files
with
28,296 additions
and
25,608 deletions.
There are no files selected for viewing
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,19 @@ | ||
AdjacencyConstraint | ||
------------------- | ||
.. automodule:: tacs.constraints.adjacency | ||
|
||
Options | ||
^^^^^^^ | ||
Options can be set for :class:`~tacs.constraints.AdjacencyConstraint` at time of creation for the class in the | ||
:meth:`pyTACS.createAdjacencyConstraint <tacs.pytacs.pyTACS.createAdjacencyConstraint>` method or using the | ||
:meth:`AdjacencyConstraint.setOption <tacs.constraints.AdjacencyConstraint.setOption>` method. Current option values for a class | ||
instance can be printed out using the :meth:`AdjacencyConstraint.printOption <tacs.constraints.AdjacencyConstraint.printOptions>` method. | ||
The following options, their default values and descriptions are listed below: | ||
|
||
.. program-output:: python -c "from tacs.constraints import AdjacencyConstraint; AdjacencyConstraint.printDefaultOptions()" | ||
|
||
API Reference | ||
^^^^^^^^^^^^^ | ||
.. autoclass:: tacs.constraints.AdjacencyConstraint | ||
:members: | ||
:inherited-members: |
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,9 @@ | ||
Constraint classes | ||
================== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
adjacency | ||
dvcon | ||
volume |
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,9 @@ | ||
DVConstraint | ||
------------------- | ||
.. automodule:: tacs.constraints.dv | ||
|
||
API Reference | ||
^^^^^^^^^^^^^ | ||
.. autoclass:: tacs.constraints.DVConstraint | ||
:members: | ||
:inherited-members: |
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,19 @@ | ||
VolumeConstraint | ||
---------------- | ||
.. automodule:: tacs.constraints.volume | ||
|
||
Options | ||
^^^^^^^ | ||
Options can be set for :class:`~tacs.constraints.VolumeConstraint` at time of creation for the class in the | ||
:meth:`pyTACS.createVolumeConstraint <tacs.pytacs.pyTACS.createVolumeConstraint>` method or using the | ||
:meth:`VolumeConstraint.setOption <tacs.constraints.VolumeConstraint.setOption>` method. Current option values for a class | ||
instance can be printed out using the :meth:`VolumeConstraint.printOption <tacs.constraints.VolumeConstraint.printOptions>` method. | ||
The following options, their default values and descriptions are listed below: | ||
|
||
.. program-output:: python -c "from tacs.constraints import VolumeConstraint; VolumeConstraint.printDefaultOptions()" | ||
|
||
API Reference | ||
^^^^^^^^^^^^^ | ||
.. autoclass:: tacs.constraints.VolumeConstraint | ||
:members: | ||
:inherited-members: |
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
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,143 @@ | ||
/* | ||
This file is part of TACS: The Toolkit for the Analysis of Composite | ||
Structures, a parallel finite-element code for structural and | ||
multidisciplinary design optimization. | ||
Copyright (C) 2010 University of Toronto | ||
Copyright (C) 2012 University of Michigan | ||
Copyright (C) 2014 Georgia Tech Research Corporation | ||
Additional copyright (C) 2010 Graeme J. Kennedy and Joaquim | ||
R.R.A. Martins All rights reserved. | ||
TACS is licensed under the Apache License, Version 2.0 (the | ||
"License"); you may not use this software except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
#include "TACSEnclosedVolume.h" | ||
|
||
#include "TACSAssembler.h" | ||
|
||
/* | ||
Allocate the enclosed volume function | ||
*/ | ||
TACSEnclosedVolume::TACSEnclosedVolume(TACSAssembler *_assembler) | ||
: TACSFunction(_assembler) { | ||
totalVol = 0.0; | ||
} | ||
|
||
/* | ||
Destructor for the enclosed volume | ||
*/ | ||
TACSEnclosedVolume::~TACSEnclosedVolume() {} | ||
|
||
const char *TACSEnclosedVolume::funcName = "EnclosedVolume"; | ||
|
||
/* | ||
The enclosed volume function name | ||
*/ | ||
const char *TACSEnclosedVolume::getObjectName() { return funcName; } | ||
|
||
/* | ||
Get the function name | ||
*/ | ||
TacsScalar TACSEnclosedVolume::getFunctionValue() { return totalVol; } | ||
|
||
/* | ||
Initialize the volume to zero | ||
*/ | ||
void TACSEnclosedVolume::initEvaluation(EvaluationType ftype) { | ||
totalVol = 0.0; | ||
} | ||
|
||
/* | ||
Sum the volume across all MPI processes | ||
*/ | ||
void TACSEnclosedVolume::finalEvaluation(EvaluationType ftype) { | ||
TacsScalar temp = totalVol; | ||
MPI_Allreduce(&temp, &totalVol, 1, TACS_MPI_TYPE, MPI_SUM, | ||
assembler->getMPIComm()); | ||
} | ||
|
||
/* | ||
Perform the element-wise evaluation of the TACSKSFailure function. | ||
*/ | ||
void TACSEnclosedVolume::elementWiseEval( | ||
EvaluationType ftype, int elemIndex, TACSElement *element, double time, | ||
TacsScalar scale, const TacsScalar Xpts[], const TacsScalar vars[], | ||
const TacsScalar dvars[], const TacsScalar ddvars[]) { | ||
for (int i = 0; i < element->getNumQuadraturePoints(); i++) { | ||
double pt[3]; | ||
double weight = element->getQuadraturePoint(i, pt); | ||
|
||
// Evaluate the failure index, and check whether it is an | ||
// undefined quantity of interest on this element | ||
TacsScalar density = 0.0, detXd = 0.0; | ||
int count = element->evalPointQuantity( | ||
elemIndex, TACS_ELEMENT_ENCLOSED_VOLUME, time, i, pt, Xpts, vars, dvars, | ||
ddvars, &detXd, &density); | ||
|
||
if (count >= 1) { | ||
totalVol += scale * weight * detXd * density; | ||
} | ||
} | ||
} | ||
|
||
/* | ||
Determine the derivative of the volume w.r.t. the material | ||
design variables | ||
*/ | ||
void TACSEnclosedVolume::addElementDVSens( | ||
int elemIndex, TACSElement *element, double time, TacsScalar scale, | ||
const TacsScalar Xpts[], const TacsScalar vars[], const TacsScalar dvars[], | ||
const TacsScalar ddvars[], int dvLen, TacsScalar dfdx[]) { | ||
for (int i = 0; i < element->getNumQuadraturePoints(); i++) { | ||
double pt[3]; | ||
double weight = element->getQuadraturePoint(i, pt); | ||
|
||
TacsScalar density = 0.0, detXd = 0.0; | ||
int count = element->evalPointQuantity( | ||
elemIndex, TACS_ELEMENT_ENCLOSED_VOLUME, time, i, pt, Xpts, vars, dvars, | ||
ddvars, &detXd, &density); | ||
|
||
if (count >= 1) { | ||
TacsScalar dfdq = scale * weight * detXd; | ||
element->addPointQuantityDVSens(elemIndex, TACS_ELEMENT_ENCLOSED_VOLUME, | ||
time, 1.0, i, pt, Xpts, vars, dvars, | ||
ddvars, &dfdq, dvLen, dfdx); | ||
} | ||
} | ||
} | ||
|
||
/* | ||
Determine the derivative of the volume w.r.t. the element nodal | ||
locations. | ||
*/ | ||
void TACSEnclosedVolume::getElementXptSens( | ||
int elemIndex, TACSElement *element, double time, TacsScalar scale, | ||
const TacsScalar Xpts[], const TacsScalar vars[], const TacsScalar dvars[], | ||
const TacsScalar ddvars[], TacsScalar dfdXpts[]) { | ||
// Zero the derivative of the function w.r.t. the node locations | ||
int numNodes = element->getNumNodes(); | ||
memset(dfdXpts, 0, 3 * numNodes * sizeof(TacsScalar)); | ||
|
||
for (int i = 0; i < element->getNumQuadraturePoints(); i++) { | ||
double pt[3]; | ||
double weight = element->getQuadraturePoint(i, pt); | ||
|
||
TacsScalar density = 0.0, detXd = 0.0; | ||
int count = element->evalPointQuantity( | ||
elemIndex, TACS_ELEMENT_ENCLOSED_VOLUME, time, i, pt, Xpts, vars, dvars, | ||
ddvars, &detXd, &density); | ||
|
||
if (count >= 1) { | ||
TacsScalar dfdq = scale * weight * detXd; | ||
TacsScalar dfddetXd = scale * weight * density; | ||
element->addPointQuantityXptSens(elemIndex, TACS_ELEMENT_ENCLOSED_VOLUME, | ||
time, 1.0, i, pt, Xpts, vars, dvars, | ||
ddvars, dfddetXd, &dfdq, dfdXpts); | ||
} | ||
} | ||
} |
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,77 @@ | ||
/* | ||
This file is part of TACS: The Toolkit for the Analysis of Composite | ||
Structures, a parallel finite-element code for structural and | ||
multidisciplinary design optimization. | ||
Copyright (C) 2010 University of Toronto | ||
Copyright (C) 2012 University of Michigan | ||
Copyright (C) 2014 Georgia Tech Research Corporation | ||
Additional copyright (C) 2010 Graeme J. Kennedy and Joaquim | ||
R.R.A. Martins All rights reserved. | ||
TACS is licensed under the Apache License, Version 2.0 (the | ||
"License"); you may not use this software except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
#ifndef TACS_ENCLOSED_VOLUME_H | ||
#define TACS_ENCLOSED_VOLUME_H | ||
|
||
/* | ||
Compute the enclosed volume | ||
*/ | ||
|
||
#include "TACSFunction.h" | ||
|
||
/* | ||
Evaluate the enclosed volume of the structure | ||
*/ | ||
class TACSEnclosedVolume : public TACSFunction { | ||
public: | ||
TACSEnclosedVolume(TACSAssembler *_assembler); | ||
~TACSEnclosedVolume(); | ||
|
||
const char *getObjectName(); | ||
|
||
/** | ||
Member functions to integrate the function value | ||
*/ | ||
void initEvaluation(EvaluationType ftype); | ||
void elementWiseEval(EvaluationType ftype, int elemIndex, | ||
TACSElement *element, double time, TacsScalar scale, | ||
const TacsScalar Xpts[], const TacsScalar vars[], | ||
const TacsScalar dvars[], const TacsScalar ddvars[]); | ||
void finalEvaluation(EvaluationType ftype); | ||
|
||
/** | ||
Return the value of the function | ||
*/ | ||
TacsScalar getFunctionValue(); | ||
|
||
/** | ||
Add the derivative of the function w.r.t. the design variables | ||
*/ | ||
void addElementDVSens(int elemIndex, TACSElement *element, double time, | ||
TacsScalar scale, const TacsScalar Xpts[], | ||
const TacsScalar vars[], const TacsScalar dvars[], | ||
const TacsScalar ddvars[], int dvLen, | ||
TacsScalar dfdx[]); | ||
|
||
/** | ||
Evaluate the derivative of the function w.r.t. the node locations | ||
*/ | ||
void getElementXptSens(int elemIndex, TACSElement *element, double time, | ||
TacsScalar scale, const TacsScalar Xpts[], | ||
const TacsScalar vars[], const TacsScalar dvars[], | ||
const TacsScalar ddvars[], TacsScalar fXptSens[]); | ||
|
||
private: | ||
// The total volume of enclosed by all elements in the specified domain | ||
TacsScalar totalVol; | ||
|
||
static const char *funcName; | ||
}; | ||
|
||
#endif // TACS_ENCLOSED_VOLUME_H |
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
Oops, something went wrong.