예제 #1
0
void FluidGui::soundFontUpClicked()
      {
      int row = soundFonts->currentRow();
      if (row <= 0)
            return;
      QStringList sfonts = fluid()->soundFonts();
      sfonts.swap(row, row-1);
      fluid()->loadSoundFonts(sfonts);
      sfonts = fluid()->soundFonts();
      soundFonts->clear();
      soundFonts->addItems(sfonts);
      soundFonts->setCurrentRow(row-1);
      }
예제 #2
0
void FluidGui::soundFontDownClicked()
      {
      int rows = soundFonts->count();
      int row = soundFonts->currentRow();
      if (row + 1 >= rows)
            return;

      QStringList sfonts = fluid()->soundFonts();
      sfonts.swap(row, row+1);
      fluid()->loadSoundFonts(sfonts);
      sfonts = fluid()->soundFonts();
      soundFonts->clear();
      soundFonts->addItems(sfonts);
      soundFonts->setCurrentRow(row+1);
      }
예제 #3
0
파일: include.c 프로젝트: pdo/aldor
local SrcLineList                     
inclHandleIf(String property)
{
	Scope("inclHandleIf");

	IfState		fluid(ifState);
	SrcLineList   	result = listNil(SrcLine);

	if (INCLUDING(ifState)) {
		SrcLine sl = SysCmdLine(true);

		if (INCL_IsAssert(&localAssertList, property)) {
			ifState = ActiveIf;
			result = addSysCmd(inclFileContents(),sl);
		} 
		else {
			ifState = InactiveIf;
			result = addSysCmd(inclFileContents(),sl);
		}
	} 
	else {
		ifState = FormerlyActiveIf;
		result = inclFileContents();
	}
	Return(result);
}
	boost::shared_ptr<PhysicsFluid> createFluid(int type, int maxParticles, float fluidStaticRestitution, float fluidStaticAdhesion, float fluidDynamicRestitution, float fluidDynamicAdhesion, float fluidDamping, float fluidStiffness, float fluidViscosity, float fluidKernelRadiusMultiplier, float fluidRestParticlesPerMeter, float fluidRestDensity, float fluidMotionLimit, int fluidPacketSizeMultiplier, int collGroup)
	{
		boost::shared_ptr<PhysicsFluid> fluid(new PhysicsFluid());
		fluidActorList.push_back(fluid.get());

		FluidData data;
		data.fluid = fluid;
		data.type = type;
		data.maxParticles = maxParticles;
		data.fluidStaticRestitution = fluidStaticRestitution;
		data.fluidStaticAdhesion = fluidStaticAdhesion;
		data.fluidDynamicRestitution = fluidDynamicRestitution;
		data.fluidDynamicAdhesion = fluidDynamicAdhesion;
		data.fluidDamping = fluidDamping;
		data.fluidStiffness = fluidStiffness;
		data.fluidViscosity = fluidViscosity;
		data.fluidKernelRadiusMultiplier = fluidKernelRadiusMultiplier;
		data.fluidRestParticlesPerMeter = fluidRestParticlesPerMeter;
		data.fluidRestDensity = fluidRestDensity;
		data.fluidMotionLimit = fluidMotionLimit;
		data.fluidPacketSizeMultiplier = fluidPacketSizeMultiplier;
		data.collisionGroup = collGroup;

		fluidList.push_back(data);
		return fluid;
	}
예제 #5
0
Foam::tmp<Foam::volScalarField> Foam::diameterModels::IATEsource::Eo() const
{
    const uniformDimensionedVectorField& g =
        phase().U().db().lookupObject<uniformDimensionedVectorField>("g");

    return
        mag(g)*sqr(phase().d())
       *(otherPhase().rho() - phase().rho())
       /fluid().sigma();
}
예제 #6
0
void FluidGui::soundFontDeleteClicked()
      {
      int row = soundFonts->currentRow();
      if (row >= 0) {
            QString s(soundFonts->item(row)->text());
            fluid()->removeSoundFont(s);
            delete soundFonts->takeItem(row);
            }
      updateUpDownButtons();
      }
예제 #7
0
void FluidGui::soundFontAddClicked()
      {
      QFileInfoList l = fluid()->sfFiles();

      ListDialog ld;
      foreach (const QFileInfo& fi, l)
            ld.add(fi.fileName(), fi.absoluteFilePath());
      if (!ld.exec())
            return;

      QString sfName = ld.name();
      QString sfPath = ld.path();

      int n = soundFonts->count();
      QStringList sl;
      for (int i = 0; i < n; ++i) {
            QListWidgetItem* item = soundFonts->item(i);
            sl.append(item->text());
            }

      if (sl.contains(sfPath)) {
            QMessageBox::warning(this,
            tr("MuseScore"),
            QString(tr("Soundfont %1 already loaded")).arg(sfPath));
            }
      else {
            bool loaded = fluid()->addSoundFont(sfPath);
            if (!loaded) {
                  QMessageBox::warning(this,
                  tr("MuseScore"),
                  QString(tr("cannot load soundfont %1")).arg(sfPath));
                  }
            else {
                  soundFonts->insertItem(0, sfName);
                  emit sfChanged();
                  }
            }
      updateUpDownButtons();
      }
예제 #8
0
Foam::tmp<Foam::volScalarField> Foam::diameterModels::IATEsource::Ur() const
{
    const uniformDimensionedVectorField& g =
        phase().U().db().lookupObject<uniformDimensionedVectorField>("g");

    return
        sqrt(2.0)
       *pow025
        (
            fluid().sigma()*mag(g)
           *(otherPhase().rho() - phase().rho())
           /sqr(otherPhase().rho())
        )
       *pow(max(1 - phase(), scalar(0)), 1.75);
}
예제 #9
0
Foam::tmp<Foam::volScalarField> Foam::diameterModels::IATEsource::We() const
{
    return otherPhase().rho()*sqr(Ur())*phase().d()/fluid().sigma();
}
예제 #10
0
파일: gf_gener.c 프로젝트: dokterp/aldor
local Foam
gen0GenerBodyFun(AbSyn iter, TForm tf)
{
	Scope("genBody0");
	FoamList topLines;
	Bool 	 flag;
	GenerGenInfo	fluid(gen0GenInfo);
	GenBoundCalc	calc = NULL;
	AbSyn		body  = iter->abGenerate.body;
	AbSyn		bound = iter->abGenerate.count;
	FoamTag		retType = gen0Type(tf, NULL);
	Foam	fluid(gen0GenVars);

	GenFoamState	saved;
	Foam		foam, clos, stmt;
	Foam		done, step, bnd, value;

	gen0GenInfo = NULL;
#ifdef GenerBetterGuesses 
	if (!bound || abTag(bound) == AB_Nothing) {
		calc = gen0MakeBoundInit(body);
		gen0ComputeGeners();
	}
#endif
	flag = gen0AddImportPlace(&topLines);

	clos = gen0ProgClosEmpty();
	foam = gen0ProgInitEmpty("generBaseFn", body);

	saved = gen0ProgSaveState(PT_Gener);

	gen0GenVars = gen0MakeGenerVars(tf);

	step   = gen0GenerStepFun(body, tf);
 	done   = gen0GenerDoneFun();
	value  = gen0GenerValueFun(retType, tf);
	bnd    = gen0GenerBoundFun(bound, calc);

	stmt = foamNewReturn(foamNew(FOAM_Values, 4, done, step, value, bnd));
	gen0AddStmt(stmt, body);

	gen0UseStackedFormat(int0);
	gen0ProgPushFormat(int0);
	gen0ProgFiniEmpty(foam, FOAM_NOp, int0);
	foam->foamProg.format = gen0MakeGenerRetFormat();

	gen0AddLexLevels(foam, 1);

        foam->foamProg.infoBits = IB_SIDE | IB_INLINEME;
        foamOptInfo(foam) = inlInfoNew(NULL, foam, NULL, false);

	if (gen0GenInfo) stoFree(gen0GenInfo);

	gen0ProgRestoreState(saved);

	if (flag) gen0ResetImportPlace(topLines);

	stmt = foamNewSet(yieldPlaceVar, foamNewSInt(int0));
	gen0AddStmt(stmt, iter);

	foamFree(gen0GenVars);
	gen0GenVars = NULL;

        Return(clos);
}
예제 #11
0
파일: include.c 프로젝트: pdo/aldor
local SrcLineList
inclFile(String fname, Bool reincluding, Bool top, long *pnlines)
{
	Scope("inclFile");

	SrcLineList     sll;
	Hash            fhash;
	FileName        fn;
	FileState	o_fileState; 
	IfState		fluid(ifState);
	String		curdir;

	o_fileState 	     = fileState;     /* no fluid(struct) */
	ifState              = NoIf;
	fileState.lineNumber = 0;

	fn = inclFind(fname, fileState.curDir);

	if (fn != 0) {
		fileState.curDir   = strCopy(fnameDir(fn));
		fileState.curFile  = strCopy(fnameUnparseStatic(fn));
		fileState.curFname = fn;
	}
	curdir = fileState.curDir;

	if (fn == 0) {
		fileState = o_fileState;
		if (top) {
			comsgFatal(NULL, ALDOR_F_CantOpen, fname);
			NotReached(sll = 0);
		}
		else
			sll = inclError(ALDOR_F_CantOpen, fname);
	} 
	else {
		fhash = fileHash(fn);
		fname = strCopy (fnameUnparseStatic(fn));

		if (!reincluding && listMemq(Hash)(includedFileCodes, fhash)) {
			sll = listNil(SrcLine);
		}
		else if (listMemq(Hash)(fileState.fileCodes, fhash)) {
			String s = inclActiveFileChain
				(fileState.fileNames, "->");
			fileState = o_fileState;
			sll = inclError(ALDOR_E_InclInfinite, s);
			strFree(s);
		}
		else {
			includedFileCodes   =
			   listCons(Hash)  (fhash,includedFileCodes);
			fileState.fileCodes =
			   listCons(Hash)  (fhash,fileState.fileCodes);
			fileState.fileNames =
			   listCons(String)(fname,fileState.fileNames);
			fileState.infile    = fileRdOpen(fn);

			sll = inclFileContents();

			listFreeCons(Hash)  (fileState.fileCodes);
			listFreeCons(String)(fileState.fileNames);
			fclose(fileState.infile);
		}
		fnameFree(fn);
		strFree(curdir);
				 /*!! curFile is used in src lines */
		strFree(fname);
	}
	if (pnlines) *pnlines = fileState.lineNumber;
	fileState = o_fileState;
	Return(sll);
}
예제 #12
0
void FluidGui::synthesizerChanged()
      {
      QStringList sfonts = fluid()->soundFonts();
      soundFonts->clear();
      soundFonts->addItems(sfonts);
      }
TEST( SDCFsiTest, reuse )
{
    std::vector<int> nbIter;

    for ( int nbReuse = 0; nbReuse < 3; nbReuse++ )
    {
        scalar r0 = 0.2;
        scalar a0 = M_PI * r0 * r0;
        scalar u0 = 0.1;
        scalar p0 = 0;
        scalar dt = 0.01;
        int N = 20;
        scalar L = 1;
        scalar T = 1;
        scalar dx = L / N;
        scalar rho = 1.225;
        scalar E = 490;
        scalar h = 1.0e-3;
        scalar cmk = std::sqrt( E * h / (2 * rho * r0) );
        scalar c0 = std::sqrt( cmk * cmk - p0 / (2 * rho) );
        scalar kappa = c0 / u0;

        bool parallel = false;
        int extrapolation = 0;
        scalar tol = 1.0e-5;
        int maxIter = 50;
        scalar initialRelaxation = 1.0e-3;
        int maxUsedIterations = 50;

        scalar singularityLimit = 1.0e-13;
        int reuseInformationStartingFromTimeIndex = 0;
        bool scaling = false;
        bool updateJacobian = false;
        scalar beta = 0.1;
        int minIter = 5;

        ASSERT_NEAR( kappa, 10, 1.0e-13 );
        ASSERT_TRUE( dx > 0 );

        std::shared_ptr<tubeflow::SDCTubeFlowFluidSolver> fluid( new tubeflow::SDCTubeFlowFluidSolver( a0, u0, p0, dt, cmk, N, L, T, rho ) );
        std::shared_ptr<tubeflow::SDCTubeFlowSolidSolver> solid( new tubeflow::SDCTubeFlowSolidSolver( a0, cmk, p0, rho, L, N ) );

        shared_ptr<RBFFunctionInterface> rbfFunction;
        shared_ptr<RBFInterpolation> rbfInterpolator;
        shared_ptr<RBFCoarsening> rbfInterpToCouplingMesh;
        shared_ptr<RBFCoarsening> rbfInterpToMesh;

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        shared_ptr<MultiLevelSolver> fluidSolver( new MultiLevelSolver( fluid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 0, 0 ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        shared_ptr<MultiLevelSolver> solidSolver( new MultiLevelSolver( solid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 1, 0 ) );

        std::shared_ptr< std::list<std::shared_ptr<ConvergenceMeasure> > > convergenceMeasures;
        convergenceMeasures = std::shared_ptr<std::list<std::shared_ptr<ConvergenceMeasure> > >( new std::list<std::shared_ptr<ConvergenceMeasure> > );

        convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new RelativeConvergenceMeasure( 0, false, tol ) ) );
        convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new MinIterationConvergenceMeasure( 0, false, minIter ) ) );

        shared_ptr<MultiLevelFsiSolver> fsi( new MultiLevelFsiSolver( fluidSolver, solidSolver, convergenceMeasures, parallel, extrapolation ) );

        shared_ptr<PostProcessing> postProcessing( new AndersonPostProcessing( fsi, maxIter, initialRelaxation, maxUsedIterations, nbReuse, singularityLimit, reuseInformationStartingFromTimeIndex, scaling, beta, updateJacobian ) );

        std::shared_ptr<sdc::SDCFsiSolverInterface> sdcFluidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( fluid );
        std::shared_ptr<sdc::SDCFsiSolverInterface> sdcSolidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( solid );

        assert( sdcFluidSolver );
        assert( sdcSolidSolver );

        std::shared_ptr<fsi::SDCFsiSolver> fsiSolver( new fsi::SDCFsiSolver( sdcFluidSolver, sdcSolidSolver, postProcessing, extrapolation ) );

        int nbNodes = 3;

        std::shared_ptr<fsi::quadrature::IQuadrature<scalar> > quadrature;
        quadrature = std::shared_ptr<fsi::quadrature::IQuadrature<scalar> >( new fsi::quadrature::Uniform<scalar>( nbNodes ) );

        std::shared_ptr<sdc::SDC> sdc( new sdc::SDC( fsiSolver, quadrature, 1.0e-10, nbNodes, nbNodes ) );

        sdc->run();

        nbIter.push_back( fsi->nbIter );
    }

    int iprev;
    int index = 0;

    for ( int i : nbIter )
    {
        std::cout << "nbIter = " << i << std::endl;

        if ( index > 0 )
            ASSERT_LE( i, iprev );

        iprev = i;
        index++;
    }
}
TEST( SDIRKFsiSolidTest, linearized )
{
    scalar r0 = 3.0e-3;
    scalar h = 3.0e-4;
    scalar L = 0.126;
    scalar rho_s = 1000;
    scalar E0 = 4.0e5;
    scalar G = 4.0e5;
    scalar nu = 0.5;

    scalar a0 = M_PI * r0 * r0;
    scalar u0 = 0.26;
    scalar p0 = 0;
    int N = 5;
    scalar T = 1;
    scalar rho_f = 1060;
    scalar E = 490;
    scalar cmk = std::sqrt( E * h / (2 * rho_f * r0) );

    bool parallel = false;
    int extrapolation = 0;
    scalar tol = 1.0e-8;
    int maxIter = 50;
    scalar initialRelaxation = 1.0e-3;
    int maxUsedIterations = 50;
    int nbReuse = 0;
    scalar singularityLimit = 1.0e-13;
    int reuseInformationStartingFromTimeIndex = 0;
    bool scaling = false;
    scalar beta = 0.01;
    bool updateJacobian = false;
    int minIter = 5;

    int nbComputations = 3;

    std::deque<std::shared_ptr<tubeflow::SDCTubeFlowFluidSolver> > fluidSolvers;
    std::deque<std::shared_ptr<tubeflow::SDCTubeFlowLinearizedSolidSolver> > solidSolvers;
    std::deque<int> nbTimeStepsList;

    for ( int iComputation = 0; iComputation < nbComputations; iComputation++ )
    {
        int nbTimeSteps = 120 * std::pow( 2, iComputation );
        std::cout << "nbTimeSteps = " << nbTimeSteps << std::endl;
        scalar dt = T / nbTimeSteps;

        std::shared_ptr<tubeflow::SDCTubeFlowFluidSolver> fluid( new tubeflow::SDCTubeFlowFluidSolver( a0, u0, p0, dt, cmk, N, L, T, rho_f ) );
        std::shared_ptr<tubeflow::SDCTubeFlowLinearizedSolidSolver> solid( new tubeflow::SDCTubeFlowLinearizedSolidSolver( N, nu, rho_s, h, L, dt, G, E0, r0, T ) );

        shared_ptr<RBFFunctionInterface> rbfFunction;
        shared_ptr<RBFInterpolation> rbfInterpolator;
        shared_ptr<RBFCoarsening> rbfInterpToCouplingMesh;
        shared_ptr<RBFCoarsening> rbfInterpToMesh;

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        shared_ptr<MultiLevelSolver> fluidSolver( new MultiLevelSolver( fluid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 0, 0 ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        shared_ptr<MultiLevelSolver> solidSolver( new MultiLevelSolver( solid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 1, 0 ) );

        std::shared_ptr< std::list<std::shared_ptr<ConvergenceMeasure> > > convergenceMeasures;
        convergenceMeasures = std::shared_ptr<std::list<std::shared_ptr<ConvergenceMeasure> > >( new std::list<std::shared_ptr<ConvergenceMeasure> >() );

        convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new RelativeConvergenceMeasure( 0, true, tol ) ) );
        convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new MinIterationConvergenceMeasure( 0, false, minIter ) ) );

        shared_ptr<MultiLevelFsiSolver> fsi( new MultiLevelFsiSolver( fluidSolver, solidSolver, convergenceMeasures, parallel, extrapolation ) );

        shared_ptr<PostProcessing> postProcessing( new AndersonPostProcessing( fsi, maxIter, initialRelaxation, maxUsedIterations, nbReuse, singularityLimit, reuseInformationStartingFromTimeIndex, scaling, beta, updateJacobian ) );

        std::shared_ptr<sdc::SDCFsiSolverInterface> sdcFluidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( fluid );
        std::shared_ptr<sdc::SDCFsiSolverInterface> sdcSolidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( solid );

        assert( sdcFluidSolver );
        assert( sdcSolidSolver );

        std::shared_ptr<fsi::SDCFsiSolver> fsiSolver( new fsi::SDCFsiSolver( sdcFluidSolver, sdcSolidSolver, postProcessing, extrapolation ) );

        std::shared_ptr<sdc::AdaptiveTimeStepper> adaptiveTimeStepper( new sdc::AdaptiveTimeStepper( false ) );

        std::string method = "ESDIRK53PR";

        std::shared_ptr<sdc::ESDIRK> esdirk( new sdc::ESDIRK( fsiSolver, method, adaptiveTimeStepper ) );

        esdirk->run();

        fluidSolvers.push_back( fluid );
        solidSolvers.push_back( solid );
        nbTimeStepsList.push_back( nbTimeSteps );
    }

    std::cout << "solid" << std::endl;

    for ( int i = 0; i < 2; i++ )
    {
        fsi::vector ref;

        if ( i == 0 )
            ref = solidSolvers.back()->r;
        else
            ref = solidSolvers.back()->u;

        std::deque<scalar> errors;

        for ( int iComputation = 0; iComputation < nbComputations - 1; iComputation++ )
        {
            fsi::vector data;

            if ( i == 0 )
                data = solidSolvers.at( iComputation )->r;
            else
                data = solidSolvers.at( iComputation )->u;

            scalar error = (ref - data).norm() / ref.norm();
            errors.push_back( error );
        }

        for ( int iComputation = 0; iComputation < nbComputations - 2; iComputation++ )
        {
            scalar order = ( std::log10( errors.at( iComputation ) ) - std::log10( errors.at( iComputation + 1 ) ) ) / ( std::log10( nbTimeStepsList.at( iComputation + 1 ) ) - std::log10( nbTimeStepsList.at( iComputation ) ) );
            std::cout << "order = " << order << std::endl;

            if ( i == 0 )
                ASSERT_NEAR( order, 3, 0.1 );
        }
    }

    std::cout << "fluid" << std::endl;

    for ( int i = 0; i < 3; i++ )
    {
        fsi::vector ref;

        if ( i == 0 )
            ref = fluidSolvers.back()->u;

        if ( i == 1 )
            ref = fluidSolvers.back()->a;

        if ( i == 2 )
            ref = fluidSolvers.back()->p;

        std::deque<scalar> errors;

        for ( int iComputation = 0; iComputation < nbComputations - 1; iComputation++ )
        {
            fsi::vector data;

            if ( i == 0 )
                data = fluidSolvers.at( iComputation )->u;

            if ( i == 1 )
                data = fluidSolvers.at( iComputation )->a;

            if ( i == 2 )
                data = fluidSolvers.at( iComputation )->p;

            scalar error = (ref - data).norm() / ref.norm();
            errors.push_back( error );
        }

        for ( int iComputation = 0; iComputation < nbComputations - 2; iComputation++ )
        {
            scalar order = ( std::log10( errors.at( iComputation ) ) - std::log10( errors.at( iComputation + 1 ) ) ) / ( std::log10( nbTimeStepsList.at( iComputation + 1 ) ) - std::log10( nbTimeStepsList.at( iComputation ) ) );
            std::cout << "order = " << order << std::endl;

            if ( i == 1 || i == 2 )
                ASSERT_NEAR( order, 3, 0.1 );
        }
    }
}
        virtual void SetUp()
        {
            scalar r0 = 3.0e-3;
            scalar h = 3.0e-4;
            scalar L = 0.126;
            scalar rho_s = 1000;
            scalar E0 = 4.0e5;
            scalar G = 4.0e5;
            scalar nu = 0.5;

            scalar a0 = M_PI * r0 * r0;
            scalar u0 = 0.26;
            scalar p0 = 0;
            scalar dt = 1;
            int N = 5;
            scalar T = 1;
            scalar rho_f = 1060;
            scalar E = 490;
            scalar cmk = std::sqrt( E * h / (2 * rho_f * r0) );

            bool parallel = false;
            int extrapolation = 0;
            scalar tol = 1.0e-3;
            int maxIter = 20;
            scalar initialRelaxation = 1.0e-3;
            int maxUsedIterations = 50;
            int nbReuse = 0;

            scalar singularityLimit = 1.0e-13;
            int reuseInformationStartingFromTimeIndex = 0;
            bool scaling = false;
            bool updateJacobian = false;
            scalar beta = 0.5;
            int minIter = 5;

            std::shared_ptr<tubeflow::SDCTubeFlowFluidSolver> fluid( new tubeflow::SDCTubeFlowFluidSolver( a0, u0, p0, dt, cmk, N, L, T, rho_f ) );

            std::shared_ptr<fsi::BaseMultiLevelSolver> solid;
            solid = std::shared_ptr<fsi::BaseMultiLevelSolver>( new tubeflow::SDCTubeFlowLinearizedSolidSolver( N, nu, rho_s, h, L, dt, G, E0, r0, T ) );

            assert( solid );

            shared_ptr<RBFFunctionInterface> rbfFunction;
            shared_ptr<RBFInterpolation> rbfInterpolator;
            shared_ptr<RBFCoarsening> rbfInterpToCouplingMesh;
            shared_ptr<RBFCoarsening> rbfInterpToMesh;

            rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
            rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
            rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

            rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
            rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
            rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

            shared_ptr<MultiLevelSolver> fluidSolver( new MultiLevelSolver( fluid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 0, 0 ) );

            rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
            rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
            rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

            rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
            rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
            rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

            shared_ptr<MultiLevelSolver> solidSolver( new MultiLevelSolver( solid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 1, 0 ) );

            std::shared_ptr< std::list<std::shared_ptr<ConvergenceMeasure> > > convergenceMeasures;
            convergenceMeasures = std::shared_ptr<std::list<std::shared_ptr<ConvergenceMeasure> > >( new std::list<std::shared_ptr<ConvergenceMeasure> >() );

            convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new RelativeConvergenceMeasure( 0, true, tol ) ) );
            convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new MinIterationConvergenceMeasure( 0, false, minIter ) ) );

            shared_ptr<MultiLevelFsiSolver> fsi( new MultiLevelFsiSolver( fluidSolver, solidSolver, convergenceMeasures, parallel, extrapolation ) );

            shared_ptr<PostProcessing> postProcessing( new AndersonPostProcessing( fsi, maxIter, initialRelaxation, maxUsedIterations, nbReuse, singularityLimit, reuseInformationStartingFromTimeIndex, scaling, beta, updateJacobian ) );

            std::shared_ptr<sdc::SDCFsiSolverInterface> sdcFluidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( fluid );
            std::shared_ptr<sdc::SDCFsiSolverInterface> sdcSolidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( solid );

            assert( sdcFluidSolver );
            assert( sdcSolidSolver );

            std::shared_ptr<fsi::SDCFsiSolver> fsiSolver( new fsi::SDCFsiSolver( sdcFluidSolver, sdcSolidSolver, postProcessing, extrapolation ) );

            std::shared_ptr<sdc::AdaptiveTimeStepper> adaptiveTimeStepper( new sdc::AdaptiveTimeStepper( false ) );

            std::string method = "ESDIRK53PR";

            esdirk = std::shared_ptr<sdc::ESDIRK> ( new sdc::ESDIRK( fsiSolver, method, adaptiveTimeStepper ) );
        }
예제 #16
0
void RadioRT::run() {
	Timer timer;
	timer.start();

	Fluid fluid(params.inputfile, params.ndims, params.ncells, params.sideLength);
	if (params.integratingRL) {
		fluid.updateLineData(params.nlevel, params.frequency, params.turb_broad);
		fluid.updateDepartureCoeffs("config/bsubn.txt");
	}

	if (params.theta < -90.0 || params.theta > 90.0)
		throw std::runtime_error("RadioRT::run: theta is out of range (0 <= th <= 180).");
	if (params.phi < 0.0 || params.phi > 360.0)
		throw std::runtime_error("RadioRT::run: phi is out of range (0 <= ph <= 360).");

	if (params.theta < 90.0)
		fluid.flip();

	// Set the number of pixels in the ray-traced image (npixels[0] and npixels[1])
	std::array<int, 2> npixels;
	npixels[0] = params.ncells[0] * params.resolutionScale;
	npixels[1] = params.ncells[1] * params.resolutionScale;
	if (params.geometry == "cylindrical") {
		npixels[0] *= 2;
	}

	//convert theta and phi to radians
	double theta_rad = Converter::DEG_2_RAD(params.theta);
	double phi_rad = Converter::DEG_2_RAD(params.phi);

	// Calculate frequencies.
	std::vector<double> freqs;
	double channelWidth = params.bandwidth / params.nchannels;
	for (int i = 0; i < params.nchannels; ++i)
		freqs.push_back(params.frequency + (i + 0.5) * channelWidth - (params.bandwidth / 2.0));

	// make the image on the plane of the sky and return it in the array image(npixels[0],npixels[1]) (units are erg/s/cm^2/Hz/ster).
	// The opacity is returned in the array tau(npixels[0],npixels[1])
	RayTracer raytracer;
	raytracer.setIntegratingFF(params.integratingFF);
	raytracer.setIntegratingRL(params.integratingRL);
	raytracer.setImageDimensions(npixels[0], npixels[1]);
	raytracer.setSampling(params.sampling);
	raytracer.setFrequencies(freqs);
	raytracer.setDopplerShifted(params.dopplerShifted);
	raytracer.setLineOfSightVelocity(params.vLOS);
	raytracer.setDopplerIntMinPhiInc(params.doppShiftPhiIncr);

	RayTracerData data;
	if (params.geometry == "cylindrical")
		data = raytracer.rayTraceAxiSymm(fluid, std::abs(theta_rad));
	else
		data = raytracer.rayTrace3D(fluid, std::abs(theta_rad), phi_rad);

	if (params.theta < 90.0)
		data.flip();

	// Scale to correct units and work out total flux
	double pixsize = data.fac * fluid.getDeltaX(); // pixel size [cm].
	double pixrad = pixsize / (Units::milli() * params.dist * Converter::PC_2_CM(1)); // pixel size [radians].
	double pixdeg = Converter::RAD_2_DEG(pixrad); // pixel size [degrees].
	double pixarcm = pixdeg * 60.0; // pixel size [arcminutes].
	double pixarcs = pixarcm * 60.0; // pixel size [arcseconds].
	double pixmas = Units::milli() * pixarcs; // pixel size [milliarcseconds].

	data.intensityFF *= Units::milli() * Converter::CGS_2_JY(1) * pixrad * pixrad; //mJy
	data.intensityRL *= Units::milli() * Converter::CGS_2_JY(1) * pixrad * pixrad;
	data.fluxFF.mul(Units::milli() * Converter::CGS_2_JY(1) * pixrad * pixrad);
	data.fluxRL.mul(Units::milli() * Converter::CGS_2_JY(1) * pixrad * pixrad);

	data.emissionMeasureFF.mul(Converter::CM_2_PC(1.0));
	data.emissionMeasureRL.mul(Converter::CM_2_PC(1.0));

	if (params.integratingFF) {
		WriteFITS::wfits(params.outputDirectory + "odepth_ff", "", data.tauFF, params, pixdeg, pixsize, fluid.getDeltaX());
		WriteFITS::wfits(params.outputDirectory + "emeasure_ff", "cm**6/pc", data.emissionMeasureFF, params, pixdeg, pixsize, fluid.getDeltaX());
		WriteFITS::wfits(params.outputDirectory + "intensity_pixel_ff", "mJy/pixel", data.fluxFF, params, pixdeg, pixsize, fluid.getDeltaX(), data.intensityFF);
	}
	if (params.integratingRL) {
		WriteFITS::wfits(params.outputDirectory + "odepth_rl", "", data.tauRL, params, pixdeg, pixsize, fluid.getDeltaX());
		WriteFITS::wfits(params.outputDirectory + "emeasure_rl", "cm**6/pc", data.emissionMeasureRL, params, pixdeg, pixsize, fluid.getDeltaX());
		WriteFITS::wfits(params.outputDirectory + "intensity_pixel_rl", "mJy/pixel", data.fluxRL, params, pixdeg, pixsize, fluid.getDeltaX(), data.intensityRL);
	}
}
예제 #17
0
MStatus 
simpleFluidEmitter::fluidEmitter( 
	const MObject& fluidObject, 
	const MMatrix& worldMatrix, 
	int plugIndex 
)
//==============================================================================
//
//	Description:
//
//		Callback function that gets called once per frame by each fluid
//		into which this emitter is emitting.  Emits values directly into
//		the fluid object.  The MFnFluid object passed to this routine is
//		not pointing to a DAG object, it is pointing to an internal fluid
//		data structure that the fluid node is constructing, eventually to
//		be set into the fluid's output attribute.
//
//	Parameters:
//
//		fluid:			fluid into which we are emitting
//		worldMatrix:	object->world matrix for the fluid
//		plugIndex:		identifies which fluid connected to the emitter
//						we are emitting into
//
//	Returns:
//
//		MS::kSuccess 			if the method wishes to override the default
//								emitter behaviour
//		MS::kUnknownParameter 	if the method wishes to have the default
//								emitter behaviour execute after this routine
//								exits.
//
//	Notes:
//
//		The method first does some work common to all emitter types, then
//		calls one of 4 different methods to actually do the emission.
//		The methods are:
//
//			omniEmitter: 	omni-directional emitter from a point,
//							or from the vertices of an owner object.
//
//			volumeEmitter:	emits from the surface of an exact cube, sphere,
//							cone, cylinder, or torus.
//
//			surfaceEmitter:	emits from the surface of an owner object.
//
//==============================================================================
{

	//	make sure the fluid is valid.  If it isn't, return MS::kSuccess, indicating
	//	that no work needs to be done.  If we return a failure code, then the default
	//	fluid emitter code will try to run, which is pointless if the fluid is not
	//	valid.
	//
	MFnFluid fluid( fluidObject );
	if( fluid.object() != MObject::kNullObj )
	{
		return MS::kSuccess;
	}

	//	get a data block for the emitter, so we can get attribute values
	//
	MDataBlock block = forceCache();

	//	figure out the time interval for emission for the given fluid
	//
	double dTime = getDeltaTime( plugIndex, block ).as(MTime::kSeconds);
	if( dTime == 0.0 )
	{
		// shouldn't happen, but if the time interval is 0, then no fluid should
		// be emitted
		return MS::kSuccess;
	}

	// 	if currentTime <= startTime, return. The startTime is connected to 
	// 	the target fluid object.
	//
	MTime cTime = getCurrentTime( block );
	MTime sTime = getStartTime( plugIndex, block );

	//	if we are at or before the start time, reset the random number
	//	state to the appropriate seed value for the given fluid
	//
	if( cTime < sTime )
	{
		resetRandomState( plugIndex, block );
		return MS::kSuccess;
	}

	//	check to see if we need to emit anything into the target fluid.
	//	if the emission rate is 0, or if the fluid doesn't have a grid
	//	for one of the quantities, then we needn't do any emission
	//
	
	//	emission rates
	double density = fluidDensityEmission( block );	
	double heat = fluidHeatEmission( block );	
	double fuel = fluidFuelEmission( block );	
	bool doColor = fluidEmitColor( block );	

	//	fluid grid settings
	MFnFluid::FluidMethod densityMode, tempMode, fuelMode;
	MFnFluid::ColorMethod colorMode;
	MFnFluid::FluidGradient grad;
	MFnFluid::FalloffMethod falloffMode;
	fluid.getDensityMode( densityMode, grad );
	fluid.getTemperatureMode( tempMode, grad );
	fluid.getFuelMode( fuelMode, grad );
	fluid.getColorMode( colorMode );
	fluid.getFalloffMode( falloffMode );

	//	see if we need to emit density, heat, fuel, or color
	bool densityToEmit = (density != 0.0) && ((densityMode == MFnFluid::kDynamicGrid)||(densityMode == MFnFluid::kStaticGrid));
	bool heatToEmit = (heat != 0.0) && ((tempMode == MFnFluid::kDynamicGrid)||(tempMode == MFnFluid::kStaticGrid));
	bool fuelToEmit = (fuel != 0.0) && ((fuelMode == MFnFluid::kDynamicGrid)||(fuelMode == MFnFluid::kStaticGrid));
	bool colorToEmit = doColor && ((colorMode == MFnFluid::kDynamicColorGrid)||(colorMode == MFnFluid::kStaticColorGrid));
	bool falloffEmit = (falloffMode == MFnFluid::kStaticFalloffGrid);
	

	//	nothing to emit, do nothing
	//
	if( !densityToEmit && !heatToEmit && !fuelToEmit && !colorToEmit && !falloffEmit )
	{
		return MS::kSuccess;
	}

	//	get the dropoff rate for the fluid 
	//	
	double dropoff = fluidDropoff( block );

	//	modify the dropoff rate to account for fluids that have
	//	been scaled in worldspace - larger scales mean slower
	//	falloffs and vice versa
	//
	MTransformationMatrix xform( worldMatrix );
	double xformScale[3];
	xform.getScale( xformScale, MSpace::kWorld );
	double dropoffScale = sqrt( xformScale[0]*xformScale[0] + 
								xformScale[1]*xformScale[1] + 
								xformScale[2]*xformScale[2] );
	if( dropoffScale > 0.1 )
	{
		dropoff /= dropoffScale;
	}
	
	//	retrieve the current random state from the "randState" attribute, and
	//	store it in the member variable "randState".  We will use this member 
	//	value numerous times via the randgen() method.  Once we are done emitting,
	//	we will set the random state back into the attribute via setRandomState().
	//
	getRandomState( plugIndex, block );

	//	conversion value used to map user input emission rates into internal
	//	values.
	//
	double conversion = 0.01;

	MEmitterType emitterType = getEmitterType( block );
	switch( emitterType )
	{
		case kOmni:
			omniFluidEmitter( fluid, worldMatrix, plugIndex, block, dTime,
							  conversion, dropoff );
			break;

		case kVolume:
			volumeFluidEmitter( fluid, worldMatrix, plugIndex, block, dTime,
							    conversion, dropoff );
			break;
			
		case kSurface:
			surfaceFluidEmitter( fluid, worldMatrix, plugIndex, block, dTime,
							     conversion, dropoff );
			break;

		default:
			break;
	}

	//	store the random state back into the datablock
	//	
	setRandomState( plugIndex, block );
	return MS::kSuccess;
}
TEST( SDCFsiTest, order )
{
    int N = 5;
    scalar r0 = 0.2;
    scalar a0 = M_PI * r0 * r0;
    scalar u0 = 0.1;
    scalar p0 = 0;
    scalar L = 1;
    scalar T = 1;
    scalar dx = L / N;
    scalar rho = 1.225;
    scalar E = 490;
    scalar h = 1.0e-3;
    scalar cmk = std::sqrt( E * h / (2 * rho * r0) );
    scalar c0 = std::sqrt( cmk * cmk - p0 / (2 * rho) );
    scalar kappa = c0 / u0;

    bool parallel = false;
    int extrapolation = 0;
    scalar tol = 1.0e-5;
    int maxIter = 20;
    scalar initialRelaxation = 1.0e-3;
    int maxUsedIterations = 50;
    int nbReuse = 0;
    scalar singularityLimit = 1.0e-13;
    int reuseInformationStartingFromTimeIndex = 0;
    bool scaling = false;
    scalar beta = 0.01;
    bool updateJacobian = false;
    int minIter = 5;

    ASSERT_NEAR( kappa, 10, 1.0e-13 );
    ASSERT_TRUE( dx > 0 );

    int nbComputations = 5;

    std::deque<std::shared_ptr<tubeflow::SDCTubeFlowFluidSolver> > fluidSolvers;
    std::deque<int> nbTimeStepsList;

    for ( int iComputation = 0; iComputation < nbComputations; iComputation++ )
    {
        int nbTimeSteps = 4 * std::pow( 2, iComputation );
        std::cout << "nbTimeSteps = " << nbTimeSteps << std::endl;
        scalar dt = T / nbTimeSteps;

        std::shared_ptr<tubeflow::SDCTubeFlowFluidSolver> fluid( new tubeflow::SDCTubeFlowFluidSolver( a0, u0, p0, dt, cmk, N, L, T, rho ) );
        std::shared_ptr<tubeflow::SDCTubeFlowSolidSolver> solid( new tubeflow::SDCTubeFlowSolidSolver( a0, cmk, p0, rho, L, N ) );

        shared_ptr<RBFFunctionInterface> rbfFunction;
        shared_ptr<RBFInterpolation> rbfInterpolator;
        shared_ptr<RBFCoarsening> rbfInterpToCouplingMesh;
        shared_ptr<RBFCoarsening> rbfInterpToMesh;

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        shared_ptr<MultiLevelSolver> fluidSolver( new MultiLevelSolver( fluid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 0, 0 ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() );
        rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) );
        rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) );

        shared_ptr<MultiLevelSolver> solidSolver( new MultiLevelSolver( solid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 1, 0 ) );

        std::shared_ptr< std::list<std::shared_ptr<ConvergenceMeasure> > > convergenceMeasures;
        convergenceMeasures = std::shared_ptr<std::list<std::shared_ptr<ConvergenceMeasure> > >( new std::list<std::shared_ptr<ConvergenceMeasure> > );

        convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new ResidualRelativeConvergenceMeasure( 0, false, tol ) ) );
        convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new MinIterationConvergenceMeasure( 0, false, minIter ) ) );

        shared_ptr<MultiLevelFsiSolver> fsi( new MultiLevelFsiSolver( fluidSolver, solidSolver, convergenceMeasures, parallel, extrapolation ) );

        shared_ptr<PostProcessing> postProcessing( new AndersonPostProcessing( fsi, maxIter, initialRelaxation, maxUsedIterations, nbReuse, singularityLimit, reuseInformationStartingFromTimeIndex, scaling, beta, updateJacobian ) );

        std::shared_ptr<sdc::SDCFsiSolverInterface> sdcFluidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( fluid );
        std::shared_ptr<sdc::SDCFsiSolverInterface> sdcSolidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( solid );

        assert( sdcFluidSolver );
        assert( sdcSolidSolver );

        std::shared_ptr<fsi::SDCFsiSolver> fsiSolver( new fsi::SDCFsiSolver( sdcFluidSolver, sdcSolidSolver, postProcessing, extrapolation ) );

        int nbNodes = 3;

        std::shared_ptr<fsi::quadrature::IQuadrature<scalar> > quadrature;
        quadrature = std::shared_ptr<fsi::quadrature::IQuadrature<scalar> >( new fsi::quadrature::GaussLobatto<scalar>( nbNodes ) );

        std::shared_ptr<sdc::SDC> sdc( new sdc::SDC( fsiSolver, quadrature, 1.0e-13, 10, 200 ) );

        sdc->run();
        ASSERT_TRUE( sdc->isConverged() );

        fluidSolvers.push_back( fluid );
        nbTimeStepsList.push_back( nbTimeSteps );
    }

    for ( int i = 0; i < 2; i++ )
    {
        fsi::vector ref;

        if ( i == 0 )
            ref = fluidSolvers.back()->u;
        else
            ref = fluidSolvers.back()->a;

        std::deque<scalar> errors;

        for ( int iComputation = 0; iComputation < nbComputations - 1; iComputation++ )
        {
            fsi::vector data;

            if ( i == 0 )
                data = fluidSolvers.at( iComputation )->u;
            else
                data = fluidSolvers.at( iComputation )->a;

            scalar error = (ref - data).norm() / data.norm();
            std::cout << "error = " << error << std::endl;
            errors.push_back( error );
        }

        for ( int iComputation = 0; iComputation < nbComputations - 2; iComputation++ )
        {
            scalar order = ( std::log10( errors.at( iComputation ) ) - std::log10( errors.at( iComputation + 1 ) ) ) / ( std::log10( nbTimeStepsList.at( iComputation + 1 ) ) - std::log10( nbTimeStepsList.at( iComputation ) ) );
            std::cout << "order = " << order << std::endl;
            ASSERT_GE( order, 3.8 );
        }
    }
}