43 template<
typename,SolverMode>
typename SOLVER
48 static constexpr unsigned dim = SOLVER<T,SolverMode::Primal>::dim;
63 void setPrimalSolver(std::shared_ptr<SOLVER<T,SolverMode::Primal>> primalSolver) {
82 template<
typename,SolverMode>
typename SOLVER,
84 template<
typename...>
typename PRIMAL_DYNAMICS,
89 using DESCRIPTOR = SOLVER<T,SolverMode::Primal>::DESCRIPTOR;
105 this->
_objectiveDomain->getSuperGeometry().getCuboidDecomposition().getDeltaR(),
113 [
this](T* output,
auto cell,
int iC,
const int* coords) {
114 _objective->j(output, cell, iC, coords);
121 [
this](T* output,
int iC,
const int* coords) {
122 const T* control = getControlPointer(iC, coords);
123 _objective->r(output, iC, coords, control);
127 int dummy[
dim+1]{0}; T result{0}; T result2{0};
130 return result + result2;
135 std::shared_ptr<SuperF<dim,T,T>> djdf = std::make_shared<SuperLatticeFfromCallableF<T,DESCRIPTOR>> (
137 [
this](T* output,
auto cell,
int iC,
const int* coords){
138 const int iCglob = this->
_primalSolver->lattice().getLoadBalancer().glob(iC);
140 if constexpr (DESCRIPTOR::d == 3) {
141 isInside = this->
_objectiveDomain->operator()(iCglob,coords[0],coords[1],coords[2]);
150 blockLatticeAD.template defineDynamics<PRIMAL_DYNAMICS>(position);
151 auto adFcell = blockLatticeAD.
get(position);
152 DESCRIPTOR::fields_t::for_each([&](
auto id) {
153 using field =
typename decltype(id)::type;
154 adFcell.template setField<field>(cell.template getField<field>());
157 for (
unsigned iPop=0; iPop<DESCRIPTOR::q; ++iPop){
158 adFcell.template getFieldPointer<descriptors::POPULATION>()[iPop].setDiffVariable(iPop);
162 for (
unsigned iPop=0; iPop<DESCRIPTOR::q; ++iPop){
167 for (
unsigned iPop=0; iPop<DESCRIPTOR::q; ++iPop){
177 std::shared_ptr<SuperF<dim,T,T>> drdc = std::make_shared<SuperLatticeFfromCallableF<T,DESCRIPTOR>> (
179 [
this](T* output,
int iC,
const int* coords){
180 const int iCglob = this->
_primalSolver->lattice().getLoadBalancer().glob(iC);
181 if constexpr (DESCRIPTOR::d == 3) {
182 if (this->
_designDomain->operator()(iCglob,coords[0],coords[1],coords[2])) {
186 for (
unsigned iControl=0; iControl<FieldDim; ++iControl){
187 adFcontrol[iControl].setDiffVariable(iControl);
192 for (
unsigned iControl=0; iControl<FieldDim; ++iControl){
193 output[iControl] =
_cellVolume * result.d(iControl);
197 for (
unsigned iControl=0; iControl<FieldDim; ++iControl){
198 output[iControl] = T(0);
203 if (this->
_designDomain->operator()(iCglob,coords[0],coords[1])) {
207 for (
unsigned iControl=0; iControl<FieldDim; ++iControl){
208 adFcontrol[iControl].setDiffVariable(iControl);
213 for (
unsigned iControl=0; iControl<FieldDim; ++iControl){
214 output[iControl] =
_cellVolume * result.d(iControl);
218 for (
unsigned iControl=0; iControl<FieldDim; ++iControl){
219 output[iControl] = T(0);
233 int latticeR[
dim+1] = {
237 if constexpr (
dim == 3) {
238 latticeR[3] = coords[2];
240 const auto index = this->
_serializer->getSerializedCellIndex(latticeR);
Cell< T, DESCRIPTOR > get(CellID iCell)
Get Cell interface for index iCell.
Implementation of BlockLattice on a concrete PLATFORM.
Generate a SuperLatticeF from an arbitrary function.
constexpr const T * data() const any_platform
const S * getControlPointer(int i) const
Objective in optimization with adjoint LBM.
virtual void initialize(Controller< T > *controller, std::shared_ptr< GeometrySerializer< T, dim > > serializer)
std::shared_ptr< SOLVER< T, SolverMode::Primal > > _primalSolver
Controller< T > * _controller
virtual std::shared_ptr< SuperF< dim, T, T > > derivativeByPopulations()=0
std::shared_ptr< SuperIndicatorF< T, dim > > _objectiveDomain
std::shared_ptr< GeometrySerializer< T, dim > > _serializer
void setPrimalSolver(std::shared_ptr< SOLVER< T, SolverMode::Primal > > primalSolver)
static constexpr unsigned dim
std::shared_ptr< SuperIndicatorF< T, dim > > _designDomain
virtual std::shared_ptr< SuperF< dim, T, T > > derivativeByControl()=0
Objective in optimization with adjoint LBM.
std::shared_ptr< SuperF< dim, T, T > > derivativeByPopulations() override
SOLVER< T, SolverMode::Primal >::DESCRIPTOR DESCRIPTOR
std::shared_ptr< SuperF< dim, T, T > > derivativeByControl() override
GenericObjective()=default
std::shared_ptr< OBJECTIVE > _objective
const T * getControlPointer(int iC, const int *coords) const
Access control at some position.
GenericObjective(std::shared_ptr< OBJECTIVE > objective)
This class serializes the cells inside the geometry.
Definition of a description of a algoritmic differentiation data type using the forward method.
Expr pow(Expr base, Expr exp)
Top level namespace for all of OpenLB.
std::conditional_t< DIM==2, SuperIntegral2D< T, W >, SuperIntegral3D< T, W > > SuperIntegral
Objective functional results, always scalar.