void SetOptimizationPdvsAndAdvs( Optimizer * aOptimizer, Problem * aProblem ) { // UInt modelId = 1; // Model* model = aProblem->GetModelById( 1 ); // Mesh* mesh = model->GetMesh(); // // model->BuildNodeToElementTable(); // // // Vars for creating PDVs // DesignDepObject desDepObj = NOD_PROP; // UInt propId = 11; // int propType = NP_LS; // // UInt myNumNodesInSet = model->GetNumNodes(); // // // ------------------------------------------------------------------------ // std::vector < UInt > &DesVarKeys = aOptimizer->GetMyDesVarKeys(); // // DesVarKeys.assign( myNumNodesInSet, 0 ); // // for ( UInt in = 0; in < myNumNodesInSet; ++in ) // DesVarKeys[in] = model->GetNode( in )->GetIdNum(); // // // Set the number of design variables per processor // aOptimizer->FinalizeDesVarCreation(); // // // ------------------------------------------------------------------------ // // Create PDVs // std::vector < UInt > globalNodesIds( myNumNodesInSet, 0 ); // for ( UInt in = 0; in < myNumNodesInSet; ++in ) // globalNodesIds[in] = model->GetNode( in )->GetIdNum(); // // UInt *ElemIndices = NULL, *ElemIds = NULL; // UInt numLoadElems = 0; // // // Initialize a ParseModelHelper // ParseModelHelper parseModelHelper = ParseModelHelper(); // // // Kill filter in inflow and outflow. // std::vector< UInt > noFilterNodeIds; // // numLoadElems = parseModelHelper.GetSideSetNeighborElemsInfoByID( mesh, sSSetIds[sLoadNSSetIndx], ElemIndices, ElemIds ); // for ( UInt ie = 0; ie < numLoadElems; ++ie ) { // std::vector < UInt > NodeIdsVec( FP_MAX_NODES, 0 ); // Element* elem = model->GetElement( ElemIndices[ie] ); // UInt numNodes = elem->GetNodeIds( &NodeIdsVec[0] ); // // for ( UInt in = 0; in < numNodes; ++in ) { // noFilterNodeIds.push_back( NodeIdsVec[in] ); // } // } // // FemdocAlgorithms::SortUniqueResizeStdVector( noFilterNodeIds ); // // // Read file // std::string line; // std::ifstream myfile ( "disttable" ); // // if ( myfile.is_open() ) // { // std::fprintf( stdout, "\n ... Reading PDVs file\n" ); // while ( myfile.good() ) // { // getline( myfile, line ); // // // char* lineChar = new char[line.size() + 1]; // // lineChar[line.size()] = 0; // // memcpy( lineChar, line.c_str(), line.size() ); // // const char* lineChar = line.c_str(); // // Real test1 = 0.0; // Real test2 = 0.0; // // std::sscanf( lineChar, "%lf %lf", &test1, &test2 ); // UInt glbNodeId = test1; // UInt numNeigb = test2; // // assert( numNeigb > 0 ); // // if ( std::find( &globalNodesIds[0], &globalNodesIds[0] + myNumNodesInSet, glbNodeId ) - &globalNodesIds[0] != myNumNodesInSet ) // { // Node* node = model->GetNodeById( glbNodeId ); // // std::vector < UInt > neigbIdsVec ( ( UInt ) numNeigb , 0.0 ); // std::vector < Real > neigbWgtVec ( ( UInt ) numNeigb , 0.0 ); // // if ( node ) // { // // If found in no filter IDs. // if ( std::find( &noFilterNodeIds[0], &noFilterNodeIds[0] + ( UInt ) noFilterNodeIds.size(), glbNodeId ) - &noFilterNodeIds[0] != ( UInt ) noFilterNodeIds.size() ) { // UInt numEntries[] = {1,0}; // // neigbIdsVec[0] = glbNodeId - 1; // neigbWgtVec[0] = 1.0; // // UInt paramIndex = 0; // UInt propTypeKey = node->GetIndexNum(); // PhysicalDesignVar* pdv = aOptimizer->CreatePhysDesVar( aProblem, modelId, desDepObj, propId, propType, propTypeKey, paramIndex ); // // Function* PDVEvalFunc = new FunctionScalarProduct( numEntries, &neigbWgtVec[0] ); // pdv->CreateEvaluationFunction( PDVEvalFunc, &neigbIdsVec[0] ); // } // else { // Real neighborIds = 0; // Real neighborWgt = 0; // UInt position = 28; // for ( UInt ii = 0; ii < numNeigb; ii++ ) // { // std::sscanf( lineChar + position,"%lf",&neighborIds ); // neigbIdsVec[ii] = neighborIds - 1; // position += 14; // } // for ( UInt ii = 0; ii < numNeigb; ii++ ) // { // std::sscanf( lineChar + position,"%lf",&neighborWgt ); // neigbWgtVec[ii] = neighborWgt; // position += 14; // } // // UInt numEntries[] = {numNeigb, 0}; // UInt paramIndex = 0; // UInt propTypeKey = node->GetIndexNum(); // PhysicalDesignVar* pdv = aOptimizer->CreatePhysDesVar( aProblem, modelId, desDepObj, propId, propType, propTypeKey, paramIndex ); // // Function* PDVEvalFunc = new FunctionScalarProduct( numEntries, &neigbWgtVec[0] ); // pdv->CreateEvaluationFunction( PDVEvalFunc, &neigbIdsVec[0] ); // } // } // } // } // } // else // { // std::fprintf( stdout, " Unable to open file!!!\n" ); // } // Set number of abstract design variables (radius) UInt modelId = 1; UInt numAbsDesVar = 1; UInt AbsDesVarInd[] = {0}; // ------------------------------------------------------------------------ // Set number of abstract design variables aOptimizer->SetNumDesVars(numAbsDesVar); // ------------------------------------------------------------------------ // Create PDV's DesignDepObject desDepObj = NOD_PROP; UInt propId = 11; Int propType = NP_LS; PhysicalDesignVar* pdv = NULL; // Create optimizer sweep function UInt numParameters[] = { 1, 1 }; // number of coefficients and independent variables Real ParameterVals[] = { 0.0 }; // radius and center of circle Real CntrXGlbCoords = sCenterX; Real CntrYGlbCoords = sCenterY; Real CntrZGlbCoords = sCenterZ; Model* model = aProblem->GetModelById(modelId); UInt numNodes = model->GetNumNodes(); model->BuildNodeToElementTable(); Node* node = NULL; Real NodeXGlbCoords = 0.0; Real NodeYGlbCoords = 0.0; Real NodeZGlbCoords = 0.0; for ( UInt in = 0; in < numNodes; ++in ) { node = model->GetNode(in); NodeXGlbCoords = node->GetGlobalXCoord(); NodeYGlbCoords = node->GetGlobalYCoord(); NodeZGlbCoords = node->GetGlobalZCoord(); Real distance = std::sqrt( std::pow((NodeXGlbCoords-CntrXGlbCoords),2) + std::pow((NodeYGlbCoords-CntrYGlbCoords),2) + std::pow((NodeZGlbCoords-CntrZGlbCoords),2)); ParameterVals[0] = distance; // Parameters for moving circle will be [distance, xcoords of node, ycoords of node, zcoords of node] pdv = aOptimizer->CreatePhysDesVar(aProblem,modelId,desDepObj,propId,propType,node->GetIndexNum()); Function* SweepFunc = new FunctionUserDefined(numParameters,ParameterVals,mySweepFunc,mySweepFuncDeriv); pdv->CreateEvaluationFunction(SweepFunc,AbsDesVarInd); } }