Exemplo n.º 1
0
    //------------------------------------------------------------------------------
    /// 値の表すベクトル (x, y) を指定の大きさに設定します。
    ///
    /// @pre ベクトルがゼロベクトルではないことをあらかじめ確認する必要があります。
    ///
    /// @param[in] aLength ベクトルの長さ。正の数を設定します。
    ///
    /// @return (x, y) を aLength の長さに設定したベクトル。
    Vec2 Vec2::getNormalized(float aLength)const
    {
        HPC_LB_ASSERT_F(aLength, 0.0f);

        Vec2 aVec(*this);
        aVec.normalize(aLength);
        return aVec;
    }
Exemplo n.º 2
0
	DLLEXPORT void vclSubstract(const int n, const ScalarType a[], const int aOffset, ScalarType b[], const int bOffset)
	{
		auto aPtr = &(a[0]) + aOffset;
		auto bPtr = &(b[0]) + bOffset;

		viennacl::vector<ScalarType> aVec((ScalarType*)aPtr, viennacl::MAIN_MEMORY, n);
		viennacl::vector<ScalarType> bVec(bPtr, viennacl::MAIN_MEMORY, n);

		bVec = aVec - bVec;
	};
Exemplo n.º 3
0
	DLLEXPORT void vclAbs(const int n, const ScalarType a[], const int aOffset, ScalarType b[], const int bOffset)
	{
		auto aPtr = &(a[0]) + aOffset;
		auto bPtr = &(b[0]) + bOffset;

		viennacl::vector<ScalarType> aVec((ScalarType*)aPtr, viennacl::MAIN_MEMORY, n);
		viennacl::vector<ScalarType> bVec(bPtr, viennacl::MAIN_MEMORY, n);

		bVec = viennacl::linalg::element_abs(aVec);
	};
Exemplo n.º 4
0
//----------------------------------------------------------------
// Function: move
// Description: translate the body and its child entities
//
// Author: Jane Hu
//----------------------------------------------------------------
CubitStatus OCCBody::move(double dx, double dy, double dz)
{
  double tol = OCCQueryEngine::instance()->get_sme_resabs_tolerance();
  if(fabs(dx) < tol && fabs(dy) < tol && fabs(dz) < tol)
    return CUBIT_SUCCESS;

  gp_Vec aVec(dx, dy, dz);
  gp_Trsf aTrsf;
  aTrsf.SetTranslation(aVec);

  BRepBuilderAPI_Transform aBRepTrsf(aTrsf);

  return transform(aBRepTrsf);
}
Exemplo n.º 5
0
int main()
{
  typedef int T;
  const unsigned int SIZE = 1;
  const unsigned int NUM_ITERATIONS = 1000000;
  std::vector<T> aVec(SIZE);
  std::vector<T>& vecRef = aVec;

  for(unsigned int ii=1; ii< NUM_ITERATIONS; ++ii) {
    aVec.resize(SIZE*2*ii);
    checkRef(aVec, vecRef);
  }

}
Exemplo n.º 6
0
REAL TestMulMat(INT aNbTime, INT aNbVar)
{
    ElTimer aChrono;
    Im2D_REAL8 aMat(aNbVar,aNbVar,0.0);
    Im1D_REAL8 aVec(aNbVar,0.0);

    REAL8 ** aDM = aMat.data();
    REAL8 *  aDV = aVec.data();

    for (INT aKT=0 ; aKT<aNbTime ; aKT++)
        for (INT aKV=0 ; aKV<aNbVar ; aKV++)
	{
		for (INT aX=0 ; aX<aNbVar ; aX++)
		    for (INT aY=0 ; aY<aNbVar ; aY++)
		        aDM[aY][aX] += aDV[aY] * aDV[aX];
	}

    return aChrono.uval();
}
Exemplo n.º 7
0
Arquivo: alg1.cpp Projeto: Quna/mspdev
// Illustrate the use of the algorithm swap_ranges.
void swap_example ()
{
    std::cout << "Illustrate swap_ranges algorithm\n";
    
    // First make two parallel sequences.
    int data[] = {12, 27, 14, 64}, *datap = data;
    std::vector<int, std::allocator<int> > aVec (4);
    
    std::generate (aVec.begin (), aVec.end (), iotaGen (1));
    
    // Illustrate swap and iter_swap.
    std::swap (data [0], data [2]);
    std::copy (data, data + 4, int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    std::vector<int, std::allocator<int> >::iterator last =
        aVec.end ();

    --last;
    
    std::iter_swap (aVec.begin (),  last);
    std::copy  (aVec.begin (), aVec.end (),
                int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    // Now swap the entire sequence.
    std::swap_ranges (aVec.begin (), aVec.end (), datap);
    std::copy (data, data+4, int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    std::copy (aVec.begin (), aVec.end (),
               int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
}
Exemplo n.º 8
0
void Ground::makeHole(b2Vec2 epicenter, float radius)
{
	std::list<b2Vec2>::iterator first,second, firstToDel, lastToDel, circleStart, circleEnd, itr, leftCircleBorder, rightCircleBorder;
	b2Vec2 leftBorder, rightBorder;
	bool leftFound(false), rightFound(false);

	//find left border
	first = this->edges.begin();
	for (second=++(this->edges.begin()); second!=this->edges.end(); first++,second++)
	{
		if (distance(*second, epicenter) <= radius)
		{
			leftBorder = (*first);
			circleStart = first;
			leftFound = true;
			firstToDel = second;
			break;
		}
	}

	//find right border
	first = --(this->edges.end());
	for (second= --(--this->edges.end()); second!=this->edges.begin(); first--,second--)
	{
		if (distance(*second, epicenter) <= radius)
		{
			rightBorder = (*first);
			circleEnd = first;
			rightFound = true;
			lastToDel = second;
			break;
		}
	}

	if ( !(leftFound && rightFound) )
		return;

	leftBorder = getBorder(*circleStart, *firstToDel, epicenter, radius);
	leftCircleBorder = circleStart;
	leftCircleBorder++;
	this->edges.insert(leftCircleBorder,leftBorder);
	leftCircleBorder--;
	

	rightBorder = getBorder(*circleEnd, *lastToDel, epicenter, radius);
	rightCircleBorder = circleEnd;
	this->edges.insert(rightCircleBorder,rightBorder);
	rightCircleBorder--;

	this->edges.erase(firstToDel, ++lastToDel);

	b2Vec2 aVec(leftBorder.x-epicenter.x, leftBorder.y-epicenter.y), bVec(rightBorder.x-epicenter.x, rightBorder.y-epicenter.y);
	positiveAngle ab = getPositiveAngle(aVec,bVec);

	positiveAngle step = 1/57.296;

	b2Vec2 toInsert = rotateVec(aVec, step);
	positiveAngle rotated(step);
	for (itr = ++leftCircleBorder; rotated < ab; rotated+=step)
	{
		this->edges.insert(itr,epicenter + toInsert);
		toInsert = rotateVec(toInsert,step);
	}
}
Exemplo n.º 9
0
void solveSip(const uqFullEnvironmentClass& env)
{
  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Entering solveSip()..."
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 1 of 5: Instantiate the parameter space
  ////////////////////////////////////////////////////////
  unsigned int p = 2;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> paramSpace(env, "param_", p, NULL);
  uqGslVectorClass aVec(paramSpace.zeroVector());
  aVec[0] = 2.;
  aVec[1] = 5.;
  uqGslVectorClass xGiven(paramSpace.zeroVector());
  xGiven[0] = -1.;
  xGiven[1] =  7.;

  ////////////////////////////////////////////////////////
  // Step 2 of 5: Instantiate the parameter domain
  ////////////////////////////////////////////////////////
  //uqGslVectorClass paramMins    (paramSpace.zeroVector());
  //uqGslVectorClass paramMaxs    (paramSpace.zeroVector());
  //paramMins    [0] = -1.e+16;
  //paramMaxs    [0] =  1.e+16;
  //paramMins    [1] = -1.e+16;
  //paramMaxs    [1] =  1.e+16;
  //uqBoxSubsetClass<uqGslVectorClass,uqGslMatrixClass> paramDomain("param_",paramSpace,paramMins,paramMaxs);
  uqVectorSetClass<uqGslVectorClass,uqGslMatrixClass>* paramDomain = &paramSpace;

  ////////////////////////////////////////////////////////
  // Step 3 of 5: Instantiate the likelihood function object
  ////////////////////////////////////////////////////////
  unsigned int n = 5;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> dataSpace(env, "data_", n, NULL);
  
  uqGslVectorClass yMeanVec(dataSpace.zeroVector());
  double tmp = scalarProduct(aVec,xGiven);
  for (unsigned int i = 0; i < n; ++i) {
    yMeanVec[i] = tmp;
  }

  double sigmaEps = 2.1;
  uqGslMatrixClass yCovMat(dataSpace.zeroVector());
  tmp = sigmaEps*sigmaEps;
  for (unsigned int i = 0; i < n; ++i) {
    yCovMat(i,i) = tmp;
  }

  uqGslVectorClass ySamples(dataSpace.zeroVector());
  uqGaussianVectorRVClass<uqGslVectorClass,uqGslMatrixClass> yRv("y_", dataSpace, yMeanVec, yCovMat);
  yRv.realizer().realization(ySamples);

  double ySampleMean = 0.;
  for (unsigned int i = 0; i < n; ++i) {
    ySampleMean += ySamples[i];
  }
  ySampleMean /= ((double) n);

  struct likelihoodDataStruct likelihoodData;
  likelihoodData.aVec     = &aVec;
  likelihoodData.sigmaEps = sigmaEps;
  likelihoodData.ySamples = &ySamples;

  uqGenericScalarFunctionClass<uqGslVectorClass,uqGslMatrixClass>
    likelihoodFunctionObj("like_",
                          *paramDomain,
                          likelihoodRoutine,
                          (void *) &likelihoodData,
                          true); // routine computes [ln(function)]

  ////////////////////////////////////////////////////////
  // Step 4 of 5: Instantiate the inverse problem
  ////////////////////////////////////////////////////////
  uqGslVectorClass xPriorMeanVec(paramSpace.zeroVector());
  xPriorMeanVec[0] = 0.;
  xPriorMeanVec[1] = 0.;
  uqGslMatrixClass sigma0Mat(paramSpace.zeroVector());
  sigma0Mat(0,0) = 1.e-3;
  sigma0Mat(0,1) = 0.;
  sigma0Mat(1,0) = 0.;
  sigma0Mat(1,1) = 1.e-3;
  uqGslMatrixClass sigma0MatInverse(paramSpace.zeroVector());
  sigma0MatInverse = sigma0Mat.inverse();
  uqGaussianVectorRVClass<uqGslVectorClass,uqGslMatrixClass> priorRv("prior_", *paramDomain, xPriorMeanVec, sigma0MatInverse);

  uqGenericVectorRVClass <uqGslVectorClass,uqGslMatrixClass> postRv ("post_", paramSpace);

  uqStatisticalInverseProblemClass<uqGslVectorClass,uqGslMatrixClass> sip("sip_", NULL, priorRv, likelihoodFunctionObj, postRv);

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "In solveSip():"
                          << "\n  p                = " << p
                          << "\n  xGiven           = " << xGiven
                          << "\n  sigma0Mat        = " << sigma0Mat
                          << "\n  sigma0MatInverse = " << sigma0MatInverse
                          << "\n  aVec             = " << aVec
                          << "\n  n                = " << n
                          << "\n  sigmaEps         = " << sigmaEps
                          << "\n  yMeanVec         = " << yMeanVec
                          << "\n  yCovMat          = " << yCovMat
                          << "\n  ySamples         = " << ySamples
                          << "\n  ySampleMean      = " << ySampleMean
                          << std::endl;
  }

  uqGslMatrixClass sigmaMatInverse(paramSpace.zeroVector());
  sigmaMatInverse = matrixProduct(aVec,aVec);
  sigmaMatInverse *= (((double) n)/sigmaEps/sigmaEps);
  sigmaMatInverse += sigma0Mat;
  uqGslMatrixClass sigmaMat(paramSpace.zeroVector());
  sigmaMat = sigmaMatInverse.inverse();

  uqGslVectorClass muVec(paramSpace.zeroVector());
  muVec = sigmaMat * aVec;
  muVec *= (((double) n) * ySampleMean)/sigmaEps/sigmaEps;

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "In solveSip():"
                          << "\n  muVec            = " << muVec
                          << "\n  sigmaMat         = " << sigmaMat
                          << "\n  sigmaMatInverse  = " << sigmaMatInverse
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 5 of 5: Solve the inverse problem
  ////////////////////////////////////////////////////////
  uqGslVectorClass initialValues(paramSpace.zeroVector());
  initialValues[0] = 25.;
  initialValues[1] = 25.;

  uqGslMatrixClass proposalCovMat(paramSpace.zeroVector());
  proposalCovMat(0,0) = 10.;
  proposalCovMat(0,1) = 0.;
  proposalCovMat(1,0) = 0.;
  proposalCovMat(1,1) = 10.;

  sip.solveWithBayesMetropolisHastings(NULL,initialValues,&proposalCovMat);

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Leaving solveSip()"
                          << std::endl;
  }

  return;
}
Exemplo n.º 10
0
double likelihoodRoutine(
  const uqGslVectorClass& paramValues,
  const uqGslVectorClass* paramDirection,
  const void*             functionDataPtr,
  uqGslVectorClass*       gradVector,
  uqGslMatrixClass*       hessianMatrix,
  uqGslVectorClass*       hessianEffect)
{
  struct timeval timevalBegin;
  gettimeofday(&timevalBegin, NULL);

  likelihoodCounter++;
  const uqBaseEnvironmentClass& env = paramValues.env();
  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 3)) {
    *env.subDisplayFile() << "Entering likelihoodRoutine()..."
                          << ": likelihoodCounter = "       << likelihoodCounter
                          << ", params = "                  << paramValues
                          << ", env.subComm().NumProc() = " << env.subComm().NumProc()
                          << ", my subRank = "              << env.subRank()
                          << std::endl;
  }

  if (env.subRank() == 0) {
#if 0
    std::cout << "Entering likelihoodRoutine()"
              << ", likelihoodCounter = " << likelihoodCounter
              << std::endl;
#endif
  }

  //////////////////////////////////////////////////
  // Begin actual likelihood routine
  //////////////////////////////////////////////////
  double totalLnLikelihood = 0.;

  if (paramDirection  &&
      functionDataPtr &&
      gradVector      &&
      hessianMatrix   &&
      hessianEffect) {
    // Just to eliminate INTEL compiler warnings
  }

  struct likelihoodDataStruct* likelihoodData = (likelihoodDataStruct *) functionDataPtr; 
  uqGslVectorClass aVec(*(likelihoodData->aVec));
  unsigned int p = aVec.sizeLocal();
  double sigmaEps = likelihoodData->sigmaEps;
  uqGslVectorClass ySamples(*(likelihoodData->ySamples));
  unsigned int n = ySamples.sizeLocal();

  UQ_FATAL_TEST_MACRO(paramValues.sizeLocal() != p,
                      env.fullRank(),
                      "likelihoodRoutine()",
                      "invalid parameter vector size");

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 4)) {
    *env.subDisplayFile() << "In likelihoodRoutine()"
                          << ": likelihoodCounter = " << likelihoodCounter
                          << ", params = "            << paramValues
                          << ", p = "                 << p
                          << ", aVec = "              << aVec
                          << ", sigmaEps = "          << sigmaEps
                          << ", n = "                 << n
                          << ", ySamples = "          << ySamples
                          << std::endl;
  }

  //******************************************************************************
  // Compute likelihood
  //******************************************************************************
  for (unsigned int i = 0; i < n; ++i) {
    double diff = (ySamples[i] - scalarProduct(aVec,paramValues))/sigmaEps;
    totalLnLikelihood -= 0.5 * diff * diff;
    if ((env.subDisplayFile()) && (env.displayVerbosity() >= 4)) {
      *env.subDisplayFile() << "In likelihoodRoutine()"
                            << ": likelihoodCounter = " << likelihoodCounter
                            << ", params = "            << paramValues
                            << ", diff = "              << diff
                            << std::endl;
    }
  }

  //******************************************************************************
  // Prepare to return
  //******************************************************************************
  double totalTime = uqMiscGetEllapsedSeconds(&timevalBegin);
  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 3)) {
    *env.subDisplayFile() << "Leaving likelihoodRoutine()"
                          << ": likelihoodCounter = " << likelihoodCounter
                          << ", params = "            << paramValues
                          << ", totalLnLikelihood = " << totalLnLikelihood
                          << " after "                << totalTime
                          << " seconds"
                          << std::endl;
  }

  if (env.subRank() == 0) {
#if 0
    std::cout << "Leaving likelihoodRoutine()"
              << ": likelihoodCounter = " << likelihoodCounter
              << ", params = "            << paramValues
              << ", totalLnLikelihood = " << totalLnLikelihood
              << " after "                << totalTime
              << " seconds"
              << std::endl;
#endif
  }

  env.subComm().Barrier();
  //exit(1);

  return totalLnLikelihood;
}
Exemplo n.º 11
0
bool StGLImageProgram::init(StGLContext&                 theCtx,
                            const StImage::ImgColorModel theColorModel,
                            const StImage::ImgColorScale theColorScale,
                            const FragGetColor           theFilter) {

    // re-configure shader parts when required
    bool isChanged = myActiveProgram.isNull();
    isChanged = setFragmentShaderPart(theCtx, FragSection_Main,    0) || isChanged;
    isChanged = setFragmentShaderPart(theCtx, FragSection_Gamma,
                                      stAreEqual(params.gamma->getValue(), 1.0f, 0.0001f) ? FragGamma_Off : FragGamma_On) || isChanged;
    isChanged = setFragmentShaderPart(theCtx, FragSection_Correct,
                                      params.brightness->isDefaultValue()
                                   && params.saturation->isDefaultValue()
                                   && hasNoColorScale() ? FragCorrect_Off : FragCorrect_On) || isChanged;
    int aToRgb = getColorShader(theColorModel, theColorScale);
    if(aToRgb >= FragToRgb_FromYuvFull
    && theFilter == FragGetColor_Cubemap) {
        aToRgb += FragToRgb_CUBEMAP;
    }

    isChanged = setFragmentShaderPart(theCtx, FragSection_ToRgb,    aToRgb) || isChanged;
    isChanged = setFragmentShaderPart(theCtx, FragSection_GetColor, theFilter) || isChanged;
    isChanged = setVertexShaderPart  (theCtx, 0, theFilter == FragGetColor_Cubemap ? VertMain_Cubemap : VertMain_Normal) || isChanged;
    if(isChanged) {
        if(!initProgram(theCtx)) {
            return false;
        }

        myActiveProgram->uniProjMatLoc  = myActiveProgram->getUniformLocation(theCtx, "uProjMat");
        myActiveProgram->uniModelMatLoc = myActiveProgram->getUniformLocation(theCtx, "uModelMat");
        uniTexMainDataLoc     = myActiveProgram->getUniformLocation(theCtx, "uTexData");
        uniTexUVDataLoc       = myActiveProgram->getUniformLocation(theCtx, "uTexUVData");
        uniTexSizePxLoc       = myActiveProgram->getUniformLocation(theCtx, "uTexSizePx");
        uniTexelSizePxLoc     = myActiveProgram->getUniformLocation(theCtx, "uTexelSize");
        uniColorProcessingLoc = myActiveProgram->getUniformLocation(theCtx, "uColorProcessing");
        uniGammaLoc           = myActiveProgram->getUniformLocation(theCtx, "uGamma");
        myActiveProgram->atrVVertexLoc  = myActiveProgram->getAttribLocation(theCtx, "vVertex");
        myActiveProgram->atrVTCoordLoc  = myActiveProgram->getAttribLocation(theCtx, "vTexCoord");

        StGLVarLocation uniTextureLoc  = myActiveProgram->getUniformLocation(theCtx, "uTexture");
        StGLVarLocation uniTextureULoc = myActiveProgram->getUniformLocation(theCtx, "uTextureU");
        StGLVarLocation uniTextureVLoc = myActiveProgram->getUniformLocation(theCtx, "uTextureV");
        myActiveProgram->use(theCtx);
        theCtx.core20fwd->glUniform1i(uniTextureLoc,  StGLProgram::TEXTURE_SAMPLE_0);
        theCtx.core20fwd->glUniform1i(uniTextureULoc, StGLProgram::TEXTURE_SAMPLE_1);
        theCtx.core20fwd->glUniform1i(uniTextureVLoc, StGLProgram::TEXTURE_SAMPLE_2);
        myActiveProgram->unuse(theCtx);

        /*if (!uniModelMatLoc.isValid()
         || !uniTexMainDataLoc.isValid()
        //|| !uniTexSizePxLoc.isValid()
        //|| !uniTexelSizePxLoc.isValid()
        //|| !uniSmoothFilterLoc.isValid()
        //|| !uniColorProcessingLoc
         || !atrVVertexLoc.isValid()
         || !atrVTCoordLoc.isValid()
         || !uniTextureLoc.isValid()) {
            return false;
        }*/
    }
    if(!isValid()) {
        return false;
    }

    myActiveProgram->use(theCtx);
    if(getFragmentShaderPart(FragSection_Gamma) != FragGamma_Off) {
        GLfloat aReversed = 1.0f / params.gamma->getValue();
        StGLVec4 aVec(aReversed, aReversed, aReversed, 1.0f);
        theCtx.core20fwd->glUniform4fv(uniGammaLoc, 1, aVec);
    }
    setupCorrection(theCtx);
    myActiveProgram->unuse(theCtx);

    const StGLResources aShaders("StGLWidgets");
    return true;
}
bool StdMeshers_Projection_3D::Evaluate(SMESH_Mesh& aMesh,
                                        const TopoDS_Shape& aShape,
                                        MapShapeNbElems& aResMap)
{
  if ( !_sourceHypo )
    return false;

  SMESH_Mesh * srcMesh = _sourceHypo->GetSourceMesh();
  SMESH_Mesh * tgtMesh = & aMesh;
  if ( !srcMesh )
    srcMesh = tgtMesh;

  // get shell from shape3D
  TopoDS_Shell srcShell, tgtShell;
  TopExp_Explorer exp( _sourceHypo->GetSource3DShape(), TopAbs_SHELL );
  int nbShell;
  for ( nbShell = 0; exp.More(); exp.Next(), ++nbShell )
    srcShell = TopoDS::Shell( exp.Current() );
  if ( nbShell != 1 )
    return error(COMPERR_BAD_SHAPE,
                 SMESH_Comment("Source shape must have 1 shell but not ") << nbShell);

  exp.Init( aShape, TopAbs_SHELL );
  for ( nbShell = 0; exp.More(); exp.Next(), ++nbShell )
    tgtShell = TopoDS::Shell( exp.Current() );
  if ( nbShell != 1 )
    return error(COMPERR_BAD_SHAPE,
                 SMESH_Comment("Target shape must have 1 shell but not ") << nbShell);

  // Check that shapes are blocks
  if ( SMESH_MesherHelper::Count( tgtShell, TopAbs_FACE , 1 ) != 6 ||
       SMESH_MesherHelper::Count( tgtShell, TopAbs_EDGE , 1 ) != 12 ||
       SMESH_MesherHelper::Count( tgtShell, TopAbs_WIRE , 1 ) != 6 )
    return error(COMPERR_BAD_SHAPE, "Target shape is not a block");
  if ( SMESH_MesherHelper::Count( srcShell, TopAbs_FACE , 1 ) != 6 ||
       SMESH_MesherHelper::Count( srcShell, TopAbs_EDGE , 1 ) != 12 ||
       SMESH_MesherHelper::Count( srcShell, TopAbs_WIRE , 1 ) != 6 )
    return error(COMPERR_BAD_SHAPE, "Source shape is not a block");

  // Assure that mesh on a source shape is computed

  SMESH_subMesh* srcSubMesh = srcMesh->GetSubMesh( _sourceHypo->GetSource3DShape() );

  if ( !srcSubMesh->IsMeshComputed() )
    return error(COMPERR_BAD_INPUT_MESH,"Source mesh not computed");


  std::vector<int> aVec(SMDSEntity_Last);
  for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;

  aVec[SMDSEntity_Node] = srcSubMesh->GetSubMeshDS()->NbNodes();

  //bool quadratic = false;
  SMDS_ElemIteratorPtr elemIt = srcSubMesh->GetSubMeshDS()->GetElements();
  while ( elemIt->more() ) {
    const SMDS_MeshElement* E  = elemIt->next();
    if( E->NbNodes()==4 ) {
      aVec[SMDSEntity_Tetra]++;
    }
    else if( E->NbNodes()==5 ) {
      aVec[SMDSEntity_Pyramid]++;
    }
    else if( E->NbNodes()==6 ) {
      aVec[SMDSEntity_Penta]++;
    }
    else if( E->NbNodes()==8 ) {
      aVec[SMDSEntity_Hexa]++;
    }
    else if( E->NbNodes()==10 && E->IsQuadratic() ) {
      aVec[SMDSEntity_Quad_Tetra]++;
    }
    else if( E->NbNodes()==13 && E->IsQuadratic() ) {
      aVec[SMDSEntity_Quad_Pyramid]++;
    }
    else if( E->NbNodes()==15 && E->IsQuadratic() ) {
      aVec[SMDSEntity_Quad_Penta]++;
    }
    else if( E->NbNodes()==20 && E->IsQuadratic() ) {
      aVec[SMDSEntity_Quad_Hexa]++;
    }
    else {
      aVec[SMDSEntity_Polyhedra]++;
    }
  }

  SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
  aResMap.insert(std::make_pair(sm,aVec));

  return true;
}
Exemplo n.º 13
0
void solveSip(const uqFullEnvironmentClass& env, bool useML)
{
  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Entering solveSip()..."
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 1 of 5: Instantiate the parameter space
  ////////////////////////////////////////////////////////
  unsigned int p = 1;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> paramSpace(env, "param_", p, NULL);
  uqGslVectorClass aVec(paramSpace.zeroVector());
  aVec[0] = 126831.7;
  uqGslVectorClass bVec(paramSpace.zeroVector());
  bVec[0] = 112136.1;

  ////////////////////////////////////////////////////////
  // Step 2 of 5: Instantiate the parameter domain
  ////////////////////////////////////////////////////////
  //uqGslVectorClass paramMins    (paramSpace.zeroVector());
  //uqGslVectorClass paramMaxs    (paramSpace.zeroVector());
  //paramMins    [0] = -1.e+16;
  //paramMaxs    [0] =  1.e+16;
  //paramMins    [1] = -1.e+16;
  //paramMaxs    [1] =  1.e+16;
  //uqBoxSubsetClass<uqGslVectorClass,uqGslMatrixClass> paramDomain("param_",paramSpace,paramMins,paramMaxs);
  uqVectorSetClass<uqGslVectorClass,uqGslMatrixClass>* paramDomain = &paramSpace;

  ////////////////////////////////////////////////////////
  // Step 3 of 5: Instantiate the likelihood function object
  ////////////////////////////////////////////////////////
  unsigned int n = 400;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> dataSpace(env, "data_", n, NULL);

  double sigmaTotal = 4229.55;

  std::set<unsigned int> tmpSet;
  tmpSet.insert(env.subId());

  uqGslVectorClass ySamples(dataSpace.zeroVector());
  ySamples.subReadContents("input/dataPoints",
                           "m",
                            tmpSet);

  struct likelihoodDataStruct likelihoodData;
  likelihoodData.aVec       = &aVec;
  likelihoodData.bVec       = &bVec;
  likelihoodData.sigmaTotal = sigmaTotal;
  likelihoodData.ySamples   = &ySamples;

  uqGenericScalarFunctionClass<uqGslVectorClass,uqGslMatrixClass>
    likelihoodFunctionObj("like_",
                          *paramDomain,
                          likelihoodRoutine,
                          (void *) &likelihoodData,
                          true); // routine computes [ln(function)]

  ////////////////////////////////////////////////////////
  // Step 4 of 5: Instantiate the inverse problem
  ////////////////////////////////////////////////////////
  uqUniformVectorRVClass<uqGslVectorClass,uqGslMatrixClass> priorRv("prior_", *paramDomain);

  uqGenericVectorRVClass<uqGslVectorClass,uqGslMatrixClass> postRv ("post_", paramSpace);

  uqStatisticalInverseProblemClass<uqGslVectorClass,uqGslMatrixClass> sip("sip_", NULL, priorRv, likelihoodFunctionObj, postRv);

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "In solveSip():"
                          << "\n  p          = " << p
                          << "\n  aVec       = " << aVec
                          << "\n  bVec       = " << bVec
                          << "\n  n          = " << n
                          << "\n  sigmaTotal = " << sigmaTotal
                          << "\n  ySamples   = " << ySamples
                          << "\n  useML      = " << useML
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 5 of 5: Solve the inverse problem
  ////////////////////////////////////////////////////////
  uqGslVectorClass initialValues(paramSpace.zeroVector());
  initialValues[0] = 0.;

  uqGslMatrixClass proposalCovMat(paramSpace.zeroVector());
  proposalCovMat(0,0) = 1.;

  if (useML) {
    sip.solveWithBayesMLSampling();
  }
  else {
    sip.solveWithBayesMetropolisHastings(NULL,initialValues,&proposalCovMat);
  }

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Leaving solveSip()"
                          << std::endl;
  }

  return;
}