arma::Mat<ResultType>
ElementaryPotentialOperator<BasisFunctionType, KernelType, ResultType>::
    evaluateAtPoints(
        const GridFunction<BasisFunctionType, ResultType> &argument,
        const arma::Mat<CoordinateType> &evaluationPoints,
        const QuadratureStrategy &quadStrategy,
        const EvaluationOptions &options) const {
  if (evaluationPoints.n_rows != argument.grid()->dimWorld())
    throw std::invalid_argument(
        "ElementaryPotentialOperator::evaluateAtPoints(): "
        "the number of coordinates of each evaluation point must be "
        "equal to the dimension of the space containing the surface "
        "on which the grid function 'argument' is defined");

  if (options.evaluationMode() == EvaluationOptions::DENSE) {
    std::unique_ptr<Evaluator> evaluator =
        makeEvaluator(argument, quadStrategy, options);

    // right now we don't bother about far and near field
    // (this might depend on evaluation options)
    arma::Mat<ResultType> result;
    evaluator->evaluate(Evaluator::FAR_FIELD, evaluationPoints, result);
    return result;
  } else if (options.evaluationMode() == EvaluationOptions::ACA) {
    AssembledPotentialOperator<BasisFunctionType, ResultType> assembledOp =
        assemble(argument.space(), make_shared_from_ref(evaluationPoints),
                 quadStrategy, options);
    return assembledOp.apply(argument);
  } else
    throw std::invalid_argument(
        "ElementaryPotentialOperator::evaluateAtPoints(): "
        "Invalid evaluation mode");
}
예제 #2
0
파일: pgridfunc.cpp 프로젝트: LLNL/mfem
void ParGridFunction::ComputeFlux(
   BilinearFormIntegrator &blfi,
   GridFunction &flux, int wcoef, int subdomain)
{
   ParFiniteElementSpace *ffes =
      dynamic_cast<ParFiniteElementSpace*>(flux.FESpace());
   MFEM_VERIFY(ffes, "the flux FE space must be ParFiniteElementSpace");

   Array<int> count(flux.Size());
   SumFluxAndCount(blfi, flux, count, wcoef, subdomain);

   // Accumulate flux and counts in parallel
   ffes->GroupComm().Reduce<double>(flux, GroupCommunicator::Sum);
   ffes->GroupComm().Bcast<double>(flux);

   ffes->GroupComm().Reduce<int>(count, GroupCommunicator::Sum);
   ffes->GroupComm().Bcast<int>(count);

   // complete averaging
   for (int i = 0; i < count.Size(); i++)
   {
      if (count[i] != 0) { flux(i) /= count[i]; }
   }

   if (ffes->Nonconforming())
   {
      // On a partially conforming flux space, project on the conforming space.
      // Using this code may lead to worse refinements in ex6, so we do not use
      // it by default.

      // Vector conf_flux;
      // flux.ConformingProject(conf_flux);
      // flux.ConformingProlongate(conf_flux);
   }
}
예제 #3
0
VisualizationSceneVector3d::VisualizationSceneVector3d(GridFunction &vgf)
{
   FiniteElementSpace *fes = vgf.FESpace();
   if (fes == NULL || fes->GetVDim() != 3)
   {
      cout << "VisualizationSceneVector3d::VisualizationSceneVector3d" << endl;
      exit(1);
   }

   VecGridF = &vgf;

   mesh = fes->GetMesh();

   sfes = new FiniteElementSpace(mesh, fes->FEColl(), 1, fes->GetOrdering());
   GridF = new GridFunction(sfes);

   solx = new Vector(mesh->GetNV());
   soly = new Vector(mesh->GetNV());
   solz = new Vector(mesh->GetNV());

   vgf.GetNodalValues(*solx, 1);
   vgf.GetNodalValues(*soly, 2);
   vgf.GetNodalValues(*solz, 3);

   sol = new Vector(mesh->GetNV());

   Init();
}
예제 #4
0
void Computation::computeNewVelocities(GridFunction& u, GridFunction& v,
		GridFunction& f, GridFunction& g, GridFunction& p, RealType deltaT) {
	GridFunction branch_1(p.griddimension);
	MultiIndexType begin, end;
	begin[0] = 1;
	end[0] = u.griddimension[0] - 3;
	begin[1] = 1;
	end[1] = u.griddimension[1] - 2;
	// u Update
	PointType delta;
	delta[0] = SimIO.para.deltaX;
	delta[1] = SimIO.para.deltaY;
	Px(branch_1, p, delta);
	f.AddToGridFunction(begin, end, -1.0 * deltaT, branch_1);
	u.SetGridFunction(begin, end, 1.0, f);
	// v Update
	begin[0] = 1;
	end[0] = v.griddimension[0] - 2;
	begin[1] = 1;
	end[1] = v.griddimension[1] - 3;
	GridFunction branch_2(p.griddimension);
	Py(branch_2, p, delta);
	g.AddToGridFunction(begin, end, -1.0 * deltaT, branch_2);
	v.SetGridFunction(begin, end, 1.0, g);

}
예제 #5
0
파일: derivatives.cpp 프로젝트: jp90/src
void VVy(GridFunction& output, GridFunction& v, const RealType alpha,
		const PointType& h) {

	MultiIndexType begin, end;

	begin[0] = 1;
	end[0] = v.griddimension[0] - 2;
	begin[1] = 1;
	end[1] = v.griddimension[1] - 3;

	Stencil stencil_1(3, h);
	stencil_1.setVVy_1Stencil();
	stencil_1.ApplyStencilOperator(begin, end, begin, end, v, output);
	output.MultiplyGridFunctions(begin, end, output);

	GridFunction branch_2(v.griddimension);
	Stencil stencil_2(3, h);
	stencil_2.setVVy_2Stencil();
	stencil_2.ApplyStencilOperator(begin, end, begin, end, v, branch_2);
	branch_2.MultiplyGridFunctions(begin, end, branch_2);

	output.AddToGridFunction(begin, end, -1.0, branch_2);
	output.ScaleGridFunction(begin, end, 1.0 / h[1]);

	GridFunction branch_3(v.griddimension);
	Stencil stencil_3(3, h);
	stencil_3.setVVy_3Stencil();
	stencil_3.ApplyStencilOperator(begin, end, begin, end, v, branch_3);
	branch_3.MultiplyGridFunctions(begin, end, branch_3);

	GridFunction branch_4(v.griddimension);
	Stencil stencil_4(3, h);
	stencil_4.setVVy_4Stencil();
	stencil_4.ApplyStencilOperator(begin, end, begin, end, v, branch_4);
	branch_4.MultiplyGridFunctions(begin, end, branch_4);

	branch_3.MultiplyGridFunctions(begin, end, branch_4);

	GridFunction branch_5(v.griddimension);
	Stencil stencil_5(3, h);
	stencil_5.setVVy_5Stencil();
	stencil_5.ApplyStencilOperator(begin, end, begin, end, v, branch_5);
	branch_5.MultiplyGridFunctions(begin, end, branch_5);

	GridFunction branch_6(v.griddimension);
	Stencil stencil_6(3, h);
	stencil_6.setVVy_6Stencil();
	stencil_6.ApplyStencilOperator(begin, end, begin, end, v, branch_6);
	branch_6.MultiplyGridFunctions(begin, end, branch_6);

	branch_5.MultiplyGridFunctions(begin, end, branch_6);

	branch_3.AddToGridFunction(begin, end, -1.0, branch_5);

	branch_3.ScaleGridFunction(begin, end, alpha / h[1]);

	output.AddToGridFunction(begin, end, 1.0, branch_3);

}
예제 #6
0
파일: derivatives.cpp 프로젝트: jp90/src
void UVx(GridFunction& output, GridFunction& u, GridFunction& v,
		const RealType alpha, const PointType& h) {
	MultiIndexType begin, end;

	begin[0] = 1;
	end[0] = u.griddimension[0] - 2;
	begin[1] = 1;
	end[1] = u.griddimension[1] - 3;

	Stencil stencil_1(3, h);
	stencil_1.setUVx_1Stencil();
	stencil_1.ApplyStencilOperator(begin, end, begin, end, u, output);

	GridFunction branch_2(u.griddimension);
	Stencil stencil_2(3, h);
	stencil_2.setUVx_2Stencil();
	stencil_2.ApplyStencilOperator(begin, end, begin, end, v, branch_2);
	output.MultiplyGridFunctions(begin, end, branch_2);

	GridFunction branch_3(u.griddimension);
	Stencil stencil_3(3, h);
	stencil_3.setUVx_3Stencil();
	stencil_3.ApplyStencilOperator(begin, end, begin, end, u, branch_3);

	GridFunction branch_4(u.griddimension);
	Stencil stencil_4(3, h);
	stencil_4.setUVx_4Stencil();
	stencil_4.ApplyStencilOperator(begin, end, begin, end, v, branch_4);
	branch_3.MultiplyGridFunctions(begin, end, branch_4);
	output.AddToGridFunction(begin, end, -1.0, branch_3);
	output.ScaleGridFunction(begin, end, 1.0 / h[0]);
//bis hier 1. Zeile
	GridFunction branch_5(u.griddimension);
	Stencil stencil_5(3, h);
	stencil_5.setUVx_5Stencil();
	stencil_5.ApplyStencilOperator(begin, end, begin, end, u, branch_5);

	GridFunction branch_6(u.griddimension);
	Stencil stencil_6(3, h);
	stencil_6.setUVx_6Stencil();
	stencil_6.ApplyStencilOperator(begin, end, begin, end, v, branch_6);
	branch_5.MultiplyGridFunctions(begin, end, branch_6);

	GridFunction branch_7(u.griddimension);
	Stencil stencil_7(3, h);
	stencil_7.setUVx_7Stencil();
	stencil_7.ApplyStencilOperator(begin, end, begin, end, u, branch_7);

	GridFunction branch_8(u.griddimension);
	Stencil stencil_8(3, h);
	stencil_8.setUVx_8Stencil();
	stencil_8.ApplyStencilOperator(begin, end, begin, end, v, branch_8);
	branch_7.MultiplyGridFunctions(begin, end, branch_8);
	branch_5.AddToGridFunction(begin, end, -1.0, branch_7);
	branch_5.ScaleGridFunction(begin, end, alpha * 1.0 / h[0]);
//bis hier 2. Zeile
	output.AddToGridFunction(begin, end, 1.0, branch_5);
}
예제 #7
0
void Computation::ComputeHeatfunction(GridFunction& h, GridFunction& t, GridFunction& u, RealType deltaT) {
	for (int i = 0; i <= h.griddimension[0]-2; i++){
		for (int j = 1; j <= h.griddimension[1]-2; j++){
			h.getGridFunction()[i][j] = h.getGridFunction()[i][j-1]
			                + deltaT * (SimIO.para.re * SimIO.para.Pr * u.getGridFunction()[i][j]
			                  * (t.getGridFunction()[i+1][j] + t.getGridFunction()[i][j])/2.0
			                  - (t.getGridFunction()[i+1][j] - t.getGridFunction()[i][j])/ SimIO.para.deltaX);
		}
	}

}
예제 #8
0
파일: energydiff.cpp 프로젝트: imago/mfes
void NumProcEnergyCalc :: Do(LocalHeap & lh)
{
	  
	double result = 0;
	double potential = 0;
	double conversion = 1.602176565e-19 * 6.02214129e23 * 0.5 / 1000.0;

	const BilinearFormIntegrator & bfi = (bfa) ? *bfa->GetIntegrator(0) : *gfu->GetFESpace().GetIntegrator();
	const BilinearFormIntegrator & bfi2 =  (bfa) ? *bfa->GetIntegrator(0) : *gfu->GetFESpace().GetIntegrator();
	
	cout.precision(dbl::digits10);

	for(unsigned int kk=0; kk<molecule.size(); kk++)	
	{
		Atom currentAtom = molecule.at(kk);
		point(0) = currentAtom.x;
		point(1) = currentAtom.y;
		point(2) = currentAtom.z;
		
		FlatVector<double> pflux(bfi.DimFlux(), lh);
		CalcPointFlux (ma, *gfu, point, domains,
				pflux, bfi, applyd, lh, component);
	      
		result = pflux(0);

		if (showsteps)
			cout << "(" << pflux(0)*conversion;
	      
		CalcPointFlux (ma, *gfu0, point, domains,
				pflux, bfi2, applyd, lh, component);

		result -= pflux(0); 
		if (showsteps)
			cout << " - " << pflux(0)*conversion << ")*" << currentAtom.charge << " = " << currentAtom.charge * result*conversion << endl;

	      
		potential += currentAtom.charge * result;

	}

	double energy;
	energy = (1.602176565e-19 * 6.02214129e23 * 0.5 * potential)/1000;

	if (MyMPI_GetNTasks() == 1 || MyMPI_GetId() != 0){
		ofstream resultFile;
		resultFile.open("result.out");
		resultFile << "The energy difference is " << energy << " [kJ/mol].\n";
		resultFile.close();
		cout << "The energy difference is " << setprecision(12) << energy << " [kJ/mol].\n";
	}
        
	pde.GetVariable(variablename,true) = result;
}
std::auto_ptr<typename ElementaryPotentialOperator<
BasisFunctionType, KernelType, ResultType>::Evaluator>
ElementaryPotentialOperator<BasisFunctionType, KernelType, ResultType>::
makeEvaluator(
        const GridFunction<BasisFunctionType, ResultType>& argument,
        const QuadratureStrategy& quadStrategy,
        const EvaluationOptions& options) const
{
    // Collect the standard set of data necessary for construction of
    // evaluators and assemblers
    typedef Fiber::RawGridGeometry<CoordinateType> RawGridGeometry;
    typedef std::vector<const Fiber::Shapeset<BasisFunctionType>*> ShapesetPtrVector;
    typedef std::vector<std::vector<ResultType> > CoefficientsVector;
    typedef LocalAssemblerConstructionHelper Helper;

    shared_ptr<RawGridGeometry> rawGeometry;
    shared_ptr<GeometryFactory> geometryFactory;
    shared_ptr<Fiber::OpenClHandler> openClHandler;
    shared_ptr<ShapesetPtrVector> shapesets;

    const Space<BasisFunctionType>& space = *argument.space();
    shared_ptr<const Grid> grid = space.grid();
    Helper::collectGridData(space,
                            rawGeometry, geometryFactory);
    Helper::makeOpenClHandler(options.parallelizationOptions().openClOptions(),
                              rawGeometry, openClHandler);
    Helper::collectShapesets(space, shapesets);

    // In addition, get coefficients of argument's expansion in each element
    const GridView& view = space.gridView();
    const int elementCount = view.entityCount(0);

    shared_ptr<CoefficientsVector> localCoefficients =
            boost::make_shared<CoefficientsVector>(elementCount);

    std::auto_ptr<EntityIterator<0> > it = view.entityIterator<0>();
    for (int i = 0; i < elementCount; ++i) {
        const Entity<0>& element = it->entity();
        argument.getLocalCoefficients(element, (*localCoefficients)[i]);
        it->next();
    }

    // Now create the evaluator
    return quadStrategy.makeEvaluatorForIntegralOperators(
                geometryFactory, rawGeometry,
                shapesets,
                make_shared_from_ref(kernels()),
                make_shared_from_ref(trialTransformations()),
                make_shared_from_ref(integral()),
                localCoefficients,
                openClHandler,
                options.parallelizationOptions());
}
예제 #10
0
void Computation::setBoundaryG(GridFunction& g, GridFunction& v) {

	MultiIndexType begin, end;
	begin[0] = 1;
	end[0] = g.griddimension[0] - 2;
	begin[1] = 0;
	end[1] = 0;
	g.SetGridFunction(begin, end, 1.0, v);

	begin[0] = 1;
	end[0] = g.griddimension[0] - 2;
	begin[1] = g.griddimension[1] - 2;
	end[1] = g.griddimension[1] - 2;
	g.SetGridFunction(begin, end, 1.0, v);
}
예제 #11
0
void Computation::setBoundaryF(GridFunction& f, GridFunction& u) {
	MultiIndexType begin, end;
	begin[0] = 0;
	end[0] = 0;
	begin[1] = 1;
	end[1] = f.griddimension[1] - 2;
	f.SetGridFunction(begin, end, 1.0, u);

// F_iMax,j=u_iMax+1,j
	begin[0] = f.griddimension[0] - 2;
	end[0] = f.griddimension[0] - 2;
	begin[1] = 1;
	end[1] = f.griddimension[1] - 2;
	f.SetGridFunction(begin, end, 1.0, u);
}
예제 #12
0
파일: stencil.cpp 프로젝트: feelX46/NumSim
void Stencil::ApplyUVxStencilOperator(const MultiIndexType& gridreadbegin,
		const MultiIndexType& gridreadend,
		const MultiIndexType& gridwritebegin,
		const MultiIndexType& gridwriteend,
		const GridFunctionType& sourcegridfunctionU,
		const GridFunctionType& sourcegridfunctionV,
		GridFunction& imagegridfunction,
		RealType alpha){
	RealType tmp;
	for (IndexType i=gridwritebegin[0]; i<=gridwriteend[0]; i++){
		for (IndexType j=gridwritebegin[1]; j<=gridwriteend[1]; j++){
			tmp = 0.25*((sourcegridfunctionU[i][j]+sourcegridfunctionU[i][j+1])*
						(sourcegridfunctionV[i][j]+sourcegridfunctionV[i+1][j])-
						(sourcegridfunctionU[i-1][j]+sourcegridfunctionU[i-1][j+1])*
						(sourcegridfunctionV[i-1][j]+sourcegridfunctionV[i][j])
			)+
							  alpha*0.25*(abs(sourcegridfunctionU[i][j]+sourcegridfunctionU[i][j+1])*
									  (sourcegridfunctionV[i][j]-sourcegridfunctionV[i+1][j])-
									      abs(sourcegridfunctionU[i-1][j]+sourcegridfunctionU[i-1][j+1])*
									      (sourcegridfunctionV[i-1][j]-sourcegridfunctionV[i][j])
									  );

			imagegridfunction.SetGridFunction(i,j,tmp/h[0]);
		}
	}
}
예제 #13
0
void Computation::ComputeTemperature(GridFunction& T, GridFunction& u,
		GridFunction& v, RealType deltaT) {
	GridFunction branch_1(T.griddimension);
	GridFunction branch_2(T.griddimension);
	MultiIndexType begin, end;
//missing w�rmequelle
	begin[0] = 1;
	end[0] = T.griddimension[0] - 2;
	begin[1] = 1;
	end[1] = T.griddimension[1] - 2;
	PointType delta;
	delta[0] = SimIO.para.deltaX;
	delta[1] = SimIO.para.deltaY;

	TXX(branch_1, T, delta);
	TYY(branch_2, T, delta);
	branch_1.AddToGridFunction(begin, end, 1.0, branch_2);
	branch_1.ScaleGridFunction(begin, end,
			1.0 / (SimIO.para.Pr * SimIO.para.re));

	GridFunction branch_3(T.griddimension);
	GridFunction branch_4(T.griddimension);
	UTX(branch_3, u, T, SimIO.para.gamma, delta);
	VTY(branch_4, v, T, SimIO.para.gamma, delta);
	branch_3.AddToGridFunction(begin, end, 1.0, branch_4);

	branch_1.AddToGridFunction(begin, end, -1.0, branch_3);
	branch_1.ScaleGridFunction(begin, end, deltaT);
	T.AddToGridFunction(begin, end, 1.0, branch_1);
}
예제 #14
0
void Computation::setBoundaryP(GridFunction& p) {
	MultiIndexType begin, end;

	if (SimIO.para.world_rank == 0) {
		// p_0,j = p_1,j
		begin[0] = 0;
		end[0] = 0;
		begin[1] = 1;
		end[1] = p.griddimension[1] - 2;
		MultiIndexType Offset;
		Offset[0] = 1;
		Offset[1] = 0;
		p.SetGridFunction(begin, end, 1.0, Offset);
	}

	if (SimIO.para.world_rank == 1) {
		// p_iMax+1,j = p_iMax,j
		begin[0] = p.griddimension[0] - 1;
		end[0] = p.griddimension[0] - 1;
		begin[1] = 1;
		end[1] = p.griddimension[1] - 2;
		MultiIndexType Offset;
		Offset[0] = -1;
		Offset[1] = 0;
		p.SetGridFunction(begin, end, 1.0, Offset);
	}
	// p_i,0 = p_i,1
	begin[0] = 1;
	end[0] = p.griddimension[0] - 2;
	begin[1] = 0;
	end[1] = 0;
	MultiIndexType Offset;
	Offset[0] = 0;
	Offset[1] = 1;
	p.SetGridFunction(begin, end, 1.0, Offset);

	// p_i,jMax+1 = p_i,jMax
	begin[0] = 1;
	end[0] = p.griddimension[0] - 2;
	begin[1] = p.griddimension[1] - 1;
	end[1] = p.griddimension[1] - 1;
	Offset[0] = 0;
	Offset[1] = -1;
	p.SetGridFunction(begin, end, 1.0, Offset);

}
std::auto_ptr<InterpolatedFunction<ResultType> >
ElementaryPotentialOperator<BasisFunctionType, KernelType, ResultType>::
evaluateOnGrid(
        const GridFunction<BasisFunctionType, ResultType>& argument,
        const Grid& evaluationGrid,
        const QuadratureStrategy& quadStrategy,
        const EvaluationOptions& options) const
{
    if (evaluationGrid.dimWorld() != argument.grid()->dimWorld())
        throw std::invalid_argument(
                "ElementaryPotentialOperator::evaluateOnGrid(): "
                "the evaluation grid and the surface on which the grid "
                "function 'argument' is defined must be embedded in a space "
                "of the same dimension");

    // Get coordinates of interpolation points, i.e. the evaluationGrid's vertices

    std::auto_ptr<GridView> evalView = evaluationGrid.leafView();
    const int evalGridDim = evaluationGrid.dim();
    const int evalPointCount = evalView->entityCount(evalGridDim);
    arma::Mat<CoordinateType> evalPoints(evalGridDim, evalPointCount);

    const IndexSet& evalIndexSet = evalView->indexSet();
    // TODO: extract into template function, perhaps add case evalGridDim == 1
    if (evalGridDim == 2) {
        const int vertexCodim = 2;
        std::auto_ptr<EntityIterator<vertexCodim> > it =
                evalView->entityIterator<vertexCodim>();
        while (!it->finished()) {
            const Entity<vertexCodim>& vertex = it->entity();
            const Geometry& geo = vertex.geometry();
            const int vertexIndex = evalIndexSet.entityIndex(vertex);
            arma::Col<CoordinateType> activeCol(evalPoints.unsafe_col(vertexIndex));
            geo.getCenter(activeCol);
            it->next();
        }
    } else if (evalGridDim == 3) {
        const int vertexCodim = 3;
        std::auto_ptr<EntityIterator<vertexCodim> > it =
                evalView->entityIterator<vertexCodim>();
        while (!it->finished()) {
            const Entity<vertexCodim>& vertex = it->entity();
            const Geometry& geo = vertex.geometry();
            const int vertexIndex = evalIndexSet.entityIndex(vertex);
            arma::Col<CoordinateType> activeCol(evalPoints.unsafe_col(vertexIndex));
            geo.getCenter(activeCol);
            it->next();
        }
    }

    arma::Mat<ResultType> result;
    result = evaluateAtPoints(argument, evalPoints, quadStrategy, options);

    return std::auto_ptr<InterpolatedFunction<ResultType> >(
                new InterpolatedFunction<ResultType>(evaluationGrid, result));
}
예제 #16
0
void Computation::computeRighthandSide(GridFunction& rhs, GridFunction& f,
		GridFunction& g, RealType deltaT) {

	GridFunction branch_1(g.griddimension);

	MultiIndexType begin, end;

	begin[0] = 1;
	end[0] = f.griddimension[0] - 2;
	begin[1] = 1;
	end[1] = f.griddimension[1] - 2;
	PointType delta;
	delta[0] = SimIO.para.deltaX;
	delta[1] = SimIO.para.deltaY;
	Fx(rhs, f, delta);
	Gy(branch_1, g, delta);

	rhs.AddToGridFunction(begin, end, 1.0, branch_1);
	rhs.ScaleGridFunction(begin, end, 1.0 / deltaT);

}
예제 #17
0
void Computation::setBoundaryTN(GridFunction& T, RealType (*TO)(RealType),
		RealType (*TU)(RealType), RealType (*TL)(RealType),
		RealType (*TR)(RealType)) {
	MultiIndexType begin, end;
	// T_i,0

	begin[0] = 1;
	end[0] = T.griddimension[0] - 2;
	begin[1] = 0;
	end[1] = 0;
	MultiIndexType Offset;
	Offset[0] = 0;
	Offset[1] = 1;
	T.SetGridFunction(begin, end, TU, false, SimIO.para.deltaX);
	T.ScaleGridFunction(begin, end, SimIO.para.deltaY);
	T.AddToGridFunction(begin, end, 1.0, T, Offset);

	// T_i,jmax+1

	begin[0] = 1;
	end[0] = T.griddimension[0] - 2;
	begin[1] = T.griddimension[1] - 1;
	end[1] = T.griddimension[1] - 1;
	//MultiIndexType Offset;
	Offset[0] = 0;
	Offset[1] = -1;
	T.SetGridFunction(begin, end, TO, false, SimIO.para.deltaX);
	T.ScaleGridFunction(begin, end, SimIO.para.deltaY);
	T.AddToGridFunction(begin, end, 1.0, T, Offset);
}
예제 #18
0
void Computation::setBoundaryV(GridFunction& v) {
	MultiIndexType begin, end;

	// v_i,0 = 0
	begin[0] = 1;
	end[0] = v.griddimension[0] - 2;
	begin[1] = 0;
	end[1] = 0;
	v.SetGridFunction(begin, end, 0.0);

	// v_i,jMax =0
	begin[0] = 1;
	end[0] = v.griddimension[0] - 2;
	begin[1] = v.griddimension[1] - 2;
	end[1] = v.griddimension[1] - 2;
	v.SetGridFunction(begin, end, 0.0);
	if (SimIO.para.world_rank == 0) {
		// v_0,j = -v_1,j
		begin[0] = 0;
		end[0] = 0;
		begin[1] = 1;
		end[1] = v.griddimension[1] - 2;
		MultiIndexType Offset;
		Offset[0] = 1;
		Offset[1] = 0;
		v.SetGridFunction(begin, end, -1.0, Offset);
	}
	if (SimIO.para.world_rank == 1) {
		// v_iMax+1,j = -v_iMax,j
		begin[0] = v.griddimension[0] - 1;
		end[0] = v.griddimension[0] - 1;
		begin[1] = 1;
		end[1] = v.griddimension[1] - 2;
		MultiIndexType Offset;
		Offset[0] = -1;
		Offset[1] = 0;
		v.SetGridFunction(begin, end, -1.0, Offset);
	}
}
예제 #19
0
파일: IO.cpp 프로젝트: feelX46/NumSim
int IO::getAmountOfFluidcells(GridFunction& geo)
{
	int aof = 0;
	for (int i = geo.beginwrite[0]; i <= geo.endwrite[0]; i++)
	{
		for  (int j = geo.beginwrite[1]; j <= geo.endwrite[1]; j++ )
		{
			if(geo.GetGridFunction(i,j) >= 16)
			    aof++;
		}
	}
	return aof;
}
예제 #20
0
void Computation::setBoundaryU(GridFunction& u) {
	MultiIndexType begin, end;
	if (SimIO.para.world_rank == 0) {
		// u_0,j = 0
		begin[0] = 0;
		end[0] = 0;
		begin[1] = 1;
		end[1] = u.griddimension[1] - 2;
		u.SetGridFunction(begin, end, 0.0);
	}
	if (SimIO.para.world_rank == 1) {
		//u_iMax,j = 0
		begin[0] = u.griddimension[0] - 2;
		end[0] = u.griddimension[0] - 2;
		begin[1] = 1;
		end[1] = u.griddimension[1] - 2;
		u.SetGridFunction(begin, end, 0.0);
	}
	// u_i,0
	begin[0] = 1;
	end[0] = u.griddimension[0] - 2;
	begin[1] = 0;
	end[1] = 0;
	MultiIndexType Offset;
	Offset[0] = 0;
	Offset[1] = 1;
	u.SetGridFunction(begin, end, -1.0, Offset);

	// u_i,jMax+1
	begin[0] = 1;
	end[0] = u.griddimension[0] - 2;
	begin[1] = u.griddimension[1] - 1;
	end[1] = u.griddimension[1] - 1;
	Offset[0] = 0;
	Offset[1] = -1;
	u.SetGridFunction(begin, end, -1.0, Offset);
	//u.SetGridFunction(begin, end, -1.0, u, Offset, 2.0);

}
예제 #21
0
파일: solver.cpp 프로젝트: feelX46/NumSim
RealType Solver::computeResidual(GridFunction& sourcegridfunction,
    				     GridFunctionType& rhs,
    					 const PointType& h){
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    // The pre-value to be returned (return sqrt(doubleSum)):
    RealType doubleSum = 0.0;

    /* We need to compute the derivatives p_xx and p_yy, therefore the stencil has to be applied.
     */

    MultiIndexType dim = sourcegridfunction.GetGridDimension();
    MultiIndexType bread  (0,0);
    MultiIndexType eread  (dim[0]-1,dim[1]-1);
    MultiIndexType bwrite (1,1);
    MultiIndexType ewrite (dim[0]-2,dim[1]-2);

    //Compute the needed derivations for the whole (inner?) area
    Stencil stencil(3,h); 					// bzw. Kann man einfach const weitergeben? /Wie?
    //Get the values for derivative in x-direction:
    GridFunction Fxx(dim);
    stencil.ApplyFxxStencilOperator(bread, eread, bwrite, ewrite, sourcegridfunction.GetGridFunction(), Fxx);
    //Get the values for derivative in y-direction:
    GridFunction Fyy(dim);
    stencil.ApplyFyyStencilOperator(bread, eread, bwrite, ewrite, sourcegridfunction.GetGridFunction(), Fyy);

    // Compute the residual: res = sqrt(Sum_i^I(Sum_j^J((p_xx+p_yy-rightHandSide)²/(I*J))))
    RealType derivator;
    for (IndexType i = 1; i <= dim[0]-2; i++)
    {
    	for (IndexType j = 1; j <= dim[1]-2; j++)
    	{
    		derivator = Fxx.GetGridFunction()[i][j]+ Fyy.GetGridFunction()[i][j] - rhs[i][j];
            doubleSum +=  derivator*derivator / (dim[0]-2) / (dim[1]-2);
    	}
    }
    //std::cout<<doubleSum<<std::endl;
    return sqrt(doubleSum);
}
예제 #22
0
파일: solver.cpp 프로젝트: jp90/srcParallel
//one cycle of the solver, starts with (1,1)
void Solver::SORCycle_White(GridFunction& p, GridFunction& rhs) {


	for (int i = 1; i<=SimIO.para.iMax;i++){
		for(int j=1+i%2; j<=SimIO.para.jMax;j+=2){

			p.getGridFunction()[i][j] =(1-SimIO.para.omg)*p.getGridFunction()[i][j] +
						(SimIO.para.omg)/(2.0*(1.0/(SimIO.para.deltaX*SimIO.para.deltaX) + 1.0/(SimIO.para.deltaY*SimIO.para.deltaY)))*
						((p.getGridFunction()[i+1][j]+p.getGridFunction()[i-1][j])/(SimIO.para.deltaX*SimIO.para.deltaX) +
						(p.getGridFunction()[i][j+1]+p.getGridFunction()[i][j-1])/(SimIO.para.deltaY*SimIO.para.deltaY)
						- rhs.getGridFunction()[i][j]);

		}
	}
}
예제 #23
0
파일: ex17p.cpp 프로젝트: LLNL/mfem
double StressCoefficient::Eval(ElementTransformation &T,
                               const IntegrationPoint &ip)
{
   MFEM_ASSERT(u != NULL, "displacement field is not set");

   double L = lambda.Eval(T, ip);
   double M = mu.Eval(T, ip);
   u->GetVectorGradient(T, grad);
   if (si == sj)
   {
      double div_u = grad.Trace();
      return L*div_u + 2*M*grad(si,si);
   }
   else
   {
      return M*(grad(si,sj) + grad(sj,si));
   }
}
예제 #24
0
파일: ex15.cpp 프로젝트: LLNL/mfem
void UpdateProblem(Mesh &mesh, FiniteElementSpace &fespace,
                   GridFunction &x, BilinearForm &a, LinearForm &b)
{
   // Update the space: recalculate the number of DOFs and construct a matrix
   // that will adjust any GridFunctions to the new mesh state.
   fespace.Update();

   // Interpolate the solution on the new mesh by applying the transformation
   // matrix computed in the finite element space. Multiple GridFunctions could
   // be updated here.
   x.Update();

   // Free any transformation matrices to save memory.
   fespace.UpdatesFinished();

   // Inform the linear and bilinear forms that the space has changed.
   a.Update();
   b.Update();
}
예제 #25
0
파일: stencil.cpp 프로젝트: feelX46/NumSim
void Stencil::ApplyStencilOperator(const MultiIndexType& gridreadbegin,
		const MultiIndexType& gridreadend,
		const MultiIndexType& gridwritebegin,
		const MultiIndexType& gridwriteend,
		const GridFunctionType& sourcegridfunction,
		GridFunction& imagegridfunction){
	// Berechne die Ableitungen
	// (0,0) ist bei allen allen drei Matrtzen (Stencil, sourcegrid, imagegrid) oben links
	RealType tmp;
	for (IndexType i=gridwritebegin[0]; i<=gridwriteend[0]; i++){
		for (IndexType j=gridwritebegin[1]; j<=gridwriteend[1]; j++){
			tmp = 0.0;
			for(IndexType k=0; k<3; k++){
				for(IndexType l=0; l<3; l++){
					tmp = tmp + sourcegridfunction[i+k-1][j+l-1]*stencil[k][l];
				}
			}
			imagegridfunction.SetGridFunction(i,j,tmp);
	 	}
	}

}
예제 #26
0
Solution<BasisFunctionType, ResultType>
DefaultIterativeSolver<BasisFunctionType, ResultType>::solveImplNonblocked(
        const GridFunction<BasisFunctionType, ResultType>& rhs) const
{
    typedef BoundaryOperator<BasisFunctionType, ResultType> BoundaryOp;
    typedef typename ScalarTraits<ResultType>::RealType MagnitudeType;
    typedef Thyra::MultiVectorBase<ResultType> TrilinosVector;

    const BoundaryOp* boundaryOp = boost::get<BoundaryOp>(&m_impl->op);
    if (!boundaryOp)
        throw std::logic_error(
            "DefaultIterativeSolver::solve(): for solvers constructed "
            "from a BlockedBoundaryOperator the other solve() overload "
            "must be used");
    Solver<BasisFunctionType, ResultType>::checkConsistency(
        *boundaryOp, rhs, m_impl->mode);

    // Construct rhs vector
    Vector<ResultType> projectionsVector(
                rhs.projections(*boundaryOp->dualToRange()));
    Teuchos::RCP<TrilinosVector> rhsVector;
    if (m_impl->mode == ConvergenceTestMode::TEST_CONVERGENCE_IN_DUAL_TO_RANGE)
        rhsVector = Teuchos::rcpFromRef(projectionsVector);
    else {
        const size_t size = boundaryOp->range()->globalDofCount();
        rhsVector.reset(new Vector<ResultType>(size));
        boost::get<BoundaryOp>(m_impl->pinvId).weakForm()->apply(
            Thyra::NOTRANS, projectionsVector, rhsVector.ptr(), 1., 0.);
    }

    // Construct solution vector
    arma::Col<ResultType> armaSolution(rhsVector->range()->dim());
    armaSolution.fill(static_cast<ResultType>(0.));
    Teuchos::RCP<TrilinosVector> solutionVector = wrapInTrilinosVector(armaSolution);

    // Get number of threads
    Fiber::ParallelizationOptions parallelOptions =
        boundaryOp->context()->assemblyOptions().parallelizationOptions();
    int maxThreadCount = 1;
    if (!parallelOptions.isOpenClEnabled()) {
        if (parallelOptions.maxThreadCount() ==
            ParallelizationOptions::AUTO)
            maxThreadCount = tbb::task_scheduler_init::automatic;
        else
            maxThreadCount = parallelOptions.maxThreadCount();
    }

    // Solve
    Thyra::SolveStatus<MagnitudeType> status;
    {
        // Initialize TBB threads here (to prevent their construction and
        // destruction on every matrix-vector multiplication)
        tbb::task_scheduler_init scheduler(maxThreadCount);
        status = m_impl->solverWrapper->solve(
            Thyra::NOTRANS, *rhsVector, solutionVector.ptr());
    }

    // Construct grid function and return
    return Solution<BasisFunctionType, ResultType>(
        GridFunction<BasisFunctionType, ResultType>(
            boundaryOp->context(), boundaryOp->domain(), armaSolution),
        status);
}
예제 #27
0
void Computation::setBoundaryTD(GridFunction& T, RealType (*TO)(RealType),
		RealType (*TU)(RealType), RealType (*TL)(RealType),
		RealType (*TR)(RealType)) {
	MultiIndexType begin, end;
	if (SimIO.para.world_rank == 0) {
		// p_0,j = p_1,j
		begin[0] = 0;
		end[0] = 0;
		begin[1] = 1;
		end[1] = T.griddimension[1] - 2;

		T.SetGridFunction(begin, end, TL, true, SimIO.para.deltaY);
		T.ScaleGridFunction(begin, end, 2.0);
		MultiIndexType Offset;
		Offset[0] = 1;
		Offset[1] = 0;
		T.AddToGridFunction(begin, end, -1.0, T, Offset);

	}

	if (SimIO.para.world_rank == 1) {
		// T_imax+1,j
		begin[0] = T.griddimension[0] - 1;
		end[0] = T.griddimension[0] - 1;
		begin[1] = 1;
		end[1] = T.griddimension[1] - 2;
		MultiIndexType Offset;
		Offset[0] = -1;
		Offset[1] = 0;
		T.SetGridFunction(begin, end, TR, true, SimIO.para.deltaY);
		T.ScaleGridFunction(begin, end, 2.0);
		T.AddToGridFunction(begin, end, -1.0, T, Offset);
	}
/*
	// T_i,0

	begin[0] = 1;
	end[0] = T.griddimension[0] - 2;
	begin[1] = 0;
	end[1] = 0;
	MultiIndexType Offset;
	Offset[0] = 0;
	Offset[1] = 1;
	T.SetGridFunction(begin, end, TU, false, SimIO.para.deltaX);
	T.ScaleGridFunction(begin, end, 2.0);
	T.AddToGridFunction(begin, end, -1.0, T, Offset);

	// T_i,jmax+1

	begin[0] = 1;
	end[0] = T.griddimension[0] - 2;
	begin[1] = T.griddimension[1] - 1;
	end[1] = T.griddimension[1] - 1;
	MultiIndexType Offset;
	Offset[0] = 0;
	Offset[1] = -1;
	T.SetGridFunction(begin, end, TO, false, SimIO.para.deltaX);
	T.ScaleGridFunction(begin, end, 2.0);
	T.AddToGridFunction(begin, end, -1.0, T, Offset);*/

}
예제 #28
0
파일: IO.cpp 프로젝트: feelX46/NumSim
void IO::writeVTKSlavefile(GridFunction& u_gridfunction,
		  GridFunction& v_gridfunction, GridFunction& p_gridfunction,
		  GridFunction& T_gridfunction, GridFunction& Geo_gridfunction,
		  const PointType& delta, int mpiSizeH, int mpiSizeV, int step,
		  int rank){

	double deltaX =delta[0];
	double deltaY =delta[1];
	int ibegin = p_gridfunction.beginwrite[0];
	int iend   = p_gridfunction.endwrite[0];
	int jbegin = p_gridfunction.beginwrite[1];
	int jend   = p_gridfunction.endwrite[1];
	GridFunctionType p = p_gridfunction.GetGridFunction();
	GridFunctionType u = u_gridfunction.GetGridFunction();
	GridFunctionType v = v_gridfunction.GetGridFunction();
	GridFunctionType T = T_gridfunction.GetGridFunction();
	GridFunctionType geo = Geo_gridfunction.GetGridFunction();
	int localgriddimensionX = iend-ibegin+1;
	int localgriddimensionY = jend-jbegin+1;

	int processorgridcoordX = rank % mpiSizeH;
	int processorgridcoordY = floor(rank / mpiSizeH);

	int x1=processorgridcoordX    *localgriddimensionX-processorgridcoordX;
	int x2=(processorgridcoordX+1)*localgriddimensionX-processorgridcoordX-1;
	int x3=processorgridcoordY    *localgriddimensionY-processorgridcoordY;
	int x4=(processorgridcoordY+1)*localgriddimensionY-processorgridcoordY-1;

	  char numstr[21];
	  sprintf (numstr, "%d", step);
	  std::string filename;
	  filename.append ("./");
	  filename.append (output);
	  filename.append ("/");
	  filename.append ("sol_");
	  filename.append (numstr);
	  filename.append ("_rank");
	  sprintf (numstr, "%d", rank);
	  filename.append (numstr);
	  filename.append (".vtr");

	  std::filebuf fb;
	  fb.open (const_cast < char *>(filename.c_str ()), std::ios::out);
	  std::ostream os (&fb);
	  os << "<?xml version=\"1.0\"?>" << std::endl
	  //  << "<VTKFile type=\"RectilinearGrid\">" << std::endl
		<< "<VTKFile type=\"RectilinearGrid\">" << std::endl
	    << "<RectilinearGrid WholeExtent=\""
	    << x1 << " " << x2 << " "
	    << x3 << " " << x4 << " "
	    << "0" << " " << "0" << " "
	    << "\" GhostLevel=\"" << "0" << "\">" << std::endl
	    << "<Piece Extent=\""<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" 0 0 \">" <<std::endl
	    << "<Coordinates>"<<std::endl
	        <<
	        "<DataArray type=\"Float64\" format=\"ascii\"> "
	        << std::endl;
	      //coordinates
	      for (int i = ibegin; i <= iend; ++i)
	      {
	    	  os << std::scientific <<(processorgridcoordX*localgriddimensionX)*deltaX-processorgridcoordX*deltaX+ i * deltaX << " ";
	      }
	      os << std::endl;
	      os << "</DataArray>" << std::endl
	      << "<DataArray type=\"Float64\" format=\"ascii\"> " << std::endl;
	      for (int j = jbegin; j <= jend; ++j)
	      {
	    	  os << std::scientific << (processorgridcoordY*localgriddimensionY)*deltaY-processorgridcoordY*deltaY + j * deltaY << " ";
	      }
	      os << std::endl
	      << "</DataArray>" << std::endl
	      << "<DataArray type=\"Float64\" format=\"ascii\"> " << std::endl
	      << "0 0" << std::endl
	      << "</DataArray>" << std::endl

	        << "</Coordinates>" << std::endl
	        << "<PointData>"
	        << std::endl <<
	        "<DataArray Name=\"field\" NumberOfComponents=\"3\" type=\"Float64\" >" <<
	        std::endl;
	      //velocities
	      for (int j = jbegin; j <= jend; ++j)
	      	    	{
	      	    	  RealType y = j * deltaY;

	      for (int i = ibegin; i <= iend; ++i)
	        {
	          RealType x = i * deltaX;



	    	  os << std::scientific << interpolateVelocityU (x, y, u,
	    							 delta) << " " <<
	    	    interpolateVelocityV (x, y, v, delta) << " " << 0. << std::endl;
	    	}

	        }
	      os << "</DataArray>" << std::endl
	        << "<DataArray type=\"Float64\" Name=\"P\" format=\"ascii\">" <<
	        std::endl;
	      //pressure
          for (int j = jbegin; j <= jend; ++j)
          {
        	  for (int i = ibegin; i <= iend; ++i)
        	  {
	    	  os << std::scientific << p[i][j] << " ";

	    	}
	          os << std::endl;

	        }

	      os << "</DataArray>" << std::endl;

	      os << "<DataArray type=\"Float64\" Name=\"T\" format=\"ascii\">" <<
	    		 	        std::endl;
	    	//temperature
	    	for (int j = jbegin; j <= jend; ++j)
	    	{
	    	  	  for (int i = ibegin; i <= iend; ++i)
	    	     	  {
	    		 	  os << std::scientific << T[i][j] << " ";
	    		 	    	}
	    		 	        os << std::endl;

	    		 	        }

	    		 	      os << "</DataArray>" << std::endl;


	        os << "<DataArray type=\"Float64\" Name=\"Geometry\" format=\"ascii\">" <<
	        	    		 	        std::endl;
	        	    	//Geometry
	        	    	for (int j = jbegin; j <= jend; ++j)
	        	    	{
	        	    	  	  for (int i = ibegin; i <= iend; ++i)
	        	    	     	  {
	        	    		 	  os << std::scientific << geo[i][j] << " ";
	        	    		 	    	}
	        	    		 	        os << std::endl;

	        	    		 	        }

	        	    		 	      os << "</DataArray>" << std::endl
	       << "</PointData>" << std::endl

	        << "</Piece>" << std::endl
	        << "</RectilinearGrid>" << std::endl << "</VTKFile>" << std::endl;
	      fb.close ();

}
예제 #29
0
void Computation::computeMomentumEquations(GridFunction& f, GridFunction& g,
		GridFunction& u, GridFunction& v, GridFunction& t, RealType& deltaT) {
	PointType h;
	h[0] = SimIO.para.deltaX;
	h[1] = SimIO.para.deltaY;
	RealType alpha = SimIO.para.alpha;

	MultiIndexType begin, end;
	begin[0] = 1;
	end[0] = u.griddimension[0] - 3;
	begin[1] = 1;
	end[1] = u.griddimension[1] - 2;

	// Term F

	Uxx(f, u, h);

	GridFunction branch_2(u.griddimension);
	Uyy(branch_2, u, h);
	f.AddToGridFunction(begin, end, 1.0, branch_2);
	f.ScaleGridFunction(begin, end, 1.0 / SimIO.para.re);
	GridFunction branch_3(u.griddimension);
	UUx(branch_3, u, alpha, h);
	GridFunction branch_4(u.griddimension);
	UVy(branch_4, u, v, alpha, h);
	branch_3.AddToGridFunction(begin, end, 1.0, branch_4);

	f.AddToGridFunction(begin, end, -1.0, branch_3);
	// KILL branch 2-4

	f.ScaleGridFunction(begin, end, deltaT);
	f.AddToGridFunction(begin, end, 1.0, u);

	// - beta deltaT (tx stencil) gx
	GridFunction branch_5(u.griddimension);

	Stencil stencil_1(3, h);
	stencil_1.setTxStencil();
	stencil_1.ApplyStencilOperator(begin, end, begin, end, t, branch_5);

	branch_5.ScaleGridFunction(begin, end,
			deltaT * SimIO.para.beta * SimIO.para.gx);

	f.AddToGridFunction(begin, end, -1.0, branch_5);

	//Term G
	begin[0] = 1;
	end[0] = v.griddimension[0] - 2;
	begin[1] = 1;
	end[1] = v.griddimension[1] - 3;

	Vxx(g, v, h);
	GridFunction branch_6(v.griddimension);
	Vyy(branch_6, v, h);
	g.AddToGridFunction(begin, end, 1.0, branch_6);
	g.ScaleGridFunction(begin, end, 1.0 / SimIO.para.re);

	GridFunction branch_7(v.griddimension);
	UVx(branch_7, u, v, alpha, h);
	GridFunction branch_8(v.griddimension);
	VVy(branch_8, v, alpha, h);
	branch_7.AddToGridFunction(begin, end, 1.0, branch_8);

	g.AddToGridFunction(begin, end, -1.0, branch_7);

	g.ScaleGridFunction(begin, end, deltaT);
	g.AddToGridFunction(begin, end, 1.0, v);

	// - beta deltaT (ty stencil) gy
	GridFunction branch_9(u.griddimension);

	Stencil stencil_2(3, h);
	stencil_2.setTyStencil();
	stencil_2.ApplyStencilOperator(begin, end, begin, end, t, branch_9);

	branch_9.ScaleGridFunction(begin, end,
			deltaT * SimIO.para.beta * SimIO.para.gy);

	g.AddToGridFunction(begin, end, -1.0, branch_9);
}
예제 #30
0
 /// Check if the mesh of the solution was modified.
 bool MeshIsModified()
 {
    long mesh_sequence = solution->FESpace()->GetMesh()->GetSequence();
    MFEM_ASSERT(mesh_sequence >= current_sequence, "");
    return (mesh_sequence > current_sequence);
 }