void DataContainer::Allocate() {

	// Check that memory has not been allocated
	if (m_pAllocatedMemory != NULL) {
		_EXCEPTIONT("Attempting Allocate() on attached DataContainer");
	}

	// Allocate memory as one contiguous chunk
	size_t sTotalByteSize = GetTotalByteSize();

	m_pAllocatedMemory =
		reinterpret_cast<unsigned char*>(malloc(sTotalByteSize));

	if (m_pAllocatedMemory == NULL) {
		_EXCEPTIONT("Out of memory");
	}

	// Initialize allocated memory to zero
	memset(m_pAllocatedMemory, 0, sTotalByteSize);

	// Assign memory to DataChunks
	unsigned char * pAccumulated = m_pAllocatedMemory;

	for (size_t i = 0; i < m_vecDataChunks.size(); i++) {
		DataChunk * pDataChunk =
			reinterpret_cast<DataChunk*>(m_vecDataChunks[i]);

		pDataChunk->AttachToData(
			reinterpret_cast<void *>(pAccumulated));

#pragma message "Alignment may be an issue here on 32-bit systems"
		pAccumulated += pDataChunk->GetByteSize();
	}
}
void GridCartesianGLL::ApplyDefaultPatchLayout(
	int nPatchCount
) {

	// Verify patch count is positive
	if (nPatchCount < 1) {
		_EXCEPTIONT("nPatchCount must be a positive integer");
	}

	// Verify no Patches have been previously added
	if (m_nInitializedPatchBoxes != 0) {
		_EXCEPTIONT("ApplyDefaultPatchLayout() must be called on an empty Grid");
	}

	// Determine number of usable processors
	int nProcsPerDirection = nPatchCount;

	int nDistributedPatches = nProcsPerDirection;

	// Determine arrangement of elements on processors
	if (GetABaseResolution() % nProcsPerDirection != 0) {
		_EXCEPTIONT("\n(UNIMPLEMENTED) Currently elements must be "
			"equally divided among processors.");
	}

	int nElementsPerDirection = GetABaseResolution() / nProcsPerDirection;
	DataArray1D<int> iBoxBegin(nProcsPerDirection + 1);

	iBoxBegin[0] = 0;
	for (int n = 1; n < nProcsPerDirection; n++) {
		iBoxBegin[n] = n * nElementsPerDirection;
	}
	iBoxBegin[nProcsPerDirection] = GetABaseResolution();

	// Single panel 0 implementation (Cartesian Grid)
	// Rectangular alpha-wise patches that span all of the beta direction
	// (as many as there are processors available)
	for (int i = 0; i < nProcsPerDirection; i++) {

		// Patch strips that span beta
		m_aPatchBoxes[i] = PatchBox(
			0, 0, m_model.GetHaloElements(),
			m_nHorizontalOrder * iBoxBegin[i],
			m_nHorizontalOrder * iBoxBegin[i+1],
			0,
			m_nHorizontalOrder * GetBBaseResolution());
	}

	m_nInitializedPatchBoxes = nProcsPerDirection;
}
Esempio n. 3
0
void LoadMetaDataFile(
	const std::string & strInputMeta,
	DataMatrix3D<int> & dataGLLNodes,
	DataMatrix3D<double> & dataGLLJacobian
) {
	NcFile ncMeta(strInputMeta.c_str(), NcFile::ReadOnly);

	NcDim * dimNp = ncMeta.get_dim("np");
	if (dimNp == NULL) {
		_EXCEPTIONT("Dimension \"np\" missing from metadata file");
	}

	NcDim * dimNelem = ncMeta.get_dim("nelem");
	if (dimNelem == NULL) {
		_EXCEPTIONT("Dimension \"nelem\" missing from metadata file");
	}

	NcVar * varGLLNodes = ncMeta.get_var("GLLnodes");
	if (dimNelem == NULL) {
		_EXCEPTIONT("Variable \"GLLnodes\" missing from metadata file");
	}

	NcVar * varGLLJacobian = ncMeta.get_var("J");
	if (dimNelem == NULL) {
		_EXCEPTIONT("Variable \"J\" missing from metadata file");
	}

	int nP = dimNp->size();
	int nElem = dimNelem->size();

	DataMatrix3D<int> dataGLLNodes_tmp;
	DataMatrix3D<double> dataGLLJacobian_tmp;
 
	dataGLLNodes.Initialize(nP, nP, nElem);
	dataGLLJacobian.Initialize(nP, nP, nElem);
	dataGLLNodes_tmp.Initialize(nP, nP, nElem);
	dataGLLJacobian_tmp.Initialize(nP, nP, nElem);
 
	varGLLNodes->get(&(dataGLLNodes_tmp[0][0][0]), nP, nP, nElem);
 	varGLLJacobian->get(&(dataGLLJacobian_tmp[0][0][0]), nP, nP, nElem);

	for (int i = 0; i < nP; i++) {
		for (int j = 0; j < nP; j++) {
			for (int k = 0; k < nElem; k++) {
				dataGLLNodes[i][j][k] = dataGLLNodes_tmp[j][i][k];
				dataGLLJacobian[i][j][k] = dataGLLJacobian_tmp[j][i][k];
			}
		}
	}
}
	///	<summary>
	///		Calculate eta at the given point via Newton iteration.  The
	///		geopotential and temperature at this point are also returned via
	///		command-line parameters.
	///	</summary>
	double EtaFromRLL(
		const PhysicalConstants &phys,
		double dZp,
		double dXp,
		double dYp,
		double & dGeopotential,
		double & dTemperature
	) const {
		const int MaxIterations  = 50;
		const double InitialEta  = 1.0e-5;
		const double Convergence = 1.0e-13;

		// Buffer variables
		double dEta = InitialEta;
		double dNewEta;

		double dF;
		double dDiffF;

		// Iterate until convergence is achieved
		int i = 0;
		for (; i < MaxIterations; i++) {

			CalculateGeopotentialTemperature(
				phys, dEta, dXp, dYp, dGeopotential, dTemperature);

			dF     = - phys.GetG() * dZp + dGeopotential;
			dDiffF = - phys.GetR() / dEta * dTemperature;

			dNewEta = dEta - dF / dDiffF;

			if (fabs(dEta - dNewEta) < Convergence) {
				return dNewEta;
			}

			dEta = dNewEta;
		}

		// Check for convergence failure
		if (i == MaxIterations) {
			_EXCEPTIONT("Maximum number of iterations exceeded.");
		}

		if ((dEta > 1.0) || (dEta < 0.0)) {
			_EXCEPTIONT("Invalid Eta value");
		}
		return dEta;
	}
	void KesslerPhysics::Initialize(
		const Time & timeStart
) {
		// Indices of EquationSet variables
		const int UIx = 0;
		const int VIx = 1;
		const int TIx = 2;
		const int WIx = 3;
		const int RIx = 4;


		// Get a copy of the GLL grid
		Grid * pGrid = m_model.GetGrid();

		// Check position of variables
		if (pGrid->GetVarLocation(TIx) == DataLocation_REdge) {
			_EXCEPTIONT("Not implemented for --vstagger CPH, use --vstagger LOR");
		}

		int ndim=pGrid->GetRElements();

		qv.Allocate(ndim);
		qc.Allocate(ndim);
		qr.Allocate(ndim);
		t.Allocate(ndim);
		rho.Allocate(ndim);
		zc.Allocate(ndim);
		pk.Allocate(ndim);
	
}
void GridPatchCartesianGLL::InitializeDataLocal() {

	// Allocate data
	GridPatch::InitializeDataLocal();

	// Physical constants
	const PhysicalConstants & phys = m_grid.GetModel().GetPhysicalConstants();
	
	// Initialize the longitude and latitude at each node
	for (int i = 0; i < m_box.GetATotalWidth(); i++) {
	for (int j = 0; j < m_box.GetBTotalWidth(); j++) {
		// Longitude and latitude directly from box
		m_dataLon[i][j] = m_box.GetANode(i);
		m_dataLat[i][j] = m_box.GetBNode(j);

		//m_dataCoriolisF[i][j] = 0.0;
	}
	}

	// Set the scale height for the decay of topography features
	m_dSL = 10.0 * m_dTopoHeight;

	if (m_dSL >= m_grid.GetZtop()) {
 		_EXCEPTIONT("Coordinate scale height exceeds model top.");
	}

	//std::cout << m_box.GetATotalWidth() << " " << m_box.GetBTotalWidth() << "\n";
}
Esempio n. 7
0
void Grid::SetParameters(
	int nRElements,
	int nMaxPatchCount,
	int nABaseResolution,
	int nBBaseResolution,
	int nRefinementRatio,
	VerticalStaggering eVerticalDiscretization,
	VerticalStaggering eVerticalStaggering
) {
	if (!m_dcGridParameters.IsAttached()) {
		_EXCEPTIONT("DefineParameters() must be called before SetParameters()");
	}

	// Default GridParameters values
	m_nMaxPatchCount = nMaxPatchCount;
	m_nRElements = nRElements;
	m_iGridStamp = 0;
	m_eVerticalDiscretization = eVerticalDiscretization;
	m_eVerticalStaggering = eVerticalStaggering;
	m_nABaseResolution = nABaseResolution;
	m_nBBaseResolution = nBBaseResolution;
	m_nRefinementRatio = nRefinementRatio;
	m_dReferenceLength = 1.0;
	m_dZtop = 1.0;
	m_fHasReferenceState = false;
	m_fHasRayleighFriction = false;

	// Set boundary conditions
	for (int i = 0; i < 4; i++) {
		m_eBoundaryCondition[i] = BoundaryCondition_Default;
	}
}
Esempio n. 8
0
void ExchangeBufferRegistry::Send() {

#ifdef TEMPEST_MPIOMP
	if (m_fActiveAsyncSend) {
		_EXCEPTIONT("Attempting to Send() with active asynchronous sends");
	}

	for (int p = 0; p < m_vecProcessors.size(); p++) {
		MPI_Isend(
			m_vecSendBuffers[p],
			m_vecBufferSize[p],
			MPI_BYTE,
			m_vecProcessors[p],
			0,
			MPI_COMM_WORLD,
			&(m_vecSendRequest[p]));

/*
		int nRank;
		MPI_Comm_rank(MPI_COMM_WORLD, &nRank);
		printf("On %i sending %i bytes to %i\n",
			nRank,
			m_vecBufferSize[p],
			m_vecProcessors[p]);
*/
	}

	// Activate
	m_fActiveAsyncSend = true;
#endif
}
Esempio n. 9
0
void GridPatchCSGLL::ComputeVorticityDivergence(
	int iDataIndex
) {
	// Physical constants
	const PhysicalConstants & phys = m_grid.GetModel().GetPhysicalConstants();

	// Working data
	DataArray4D<double> & dataState =
		GetDataState(iDataIndex, DataLocation_Node);

	if (dataState.GetSize(0) < 2) {
		_EXCEPTIONT(
			"Insufficient components for vorticity calculation");
	}

	// Get the alpha and beta components of vorticity
	DataArray3D<double> dataUa;
	dataUa.SetSize(
		dataState.GetSize(1),
		dataState.GetSize(2),
		dataState.GetSize(3));

	DataArray3D<double> dataUb;
	dataUb.SetSize(
		dataState.GetSize(1),
		dataState.GetSize(2),
		dataState.GetSize(3));

	dataUa.AttachToData(&(dataState[0][0][0][0]));
	dataUb.AttachToData(&(dataState[1][0][0][0]));

	// Compute the radial component of the curl of the velocity field
	ComputeCurlAndDiv(dataUa, dataUb);
}
Esempio n. 10
0
void Grid::DefineParameters() {
	if (m_dcGridParameters.IsAttached()) {
		_EXCEPTIONT("Attempting to recall DefineParameters");
	}
#pragma message "May have to modify DataContainer to incorporate padding for DataChunks"

	// Four lateral boundaries (rectangular mesh)
	m_eBoundaryCondition.SetSize(4);

	// Initialize the GridParameters DataContainer
	m_dcGridParameters.PushDataChunk(&m_nMaxPatchCount);
	m_dcGridParameters.PushDataChunk(&m_nRElements);
	m_dcGridParameters.PushDataChunk(&m_iGridStamp);
	m_dcGridParameters.PushDataChunk(&m_eVerticalDiscretization);
	m_dcGridParameters.PushDataChunk(&m_eVerticalStaggering);
	m_dcGridParameters.PushDataChunk(&m_nABaseResolution);
	m_dcGridParameters.PushDataChunk(&m_nBBaseResolution);
	m_dcGridParameters.PushDataChunk(&m_nRefinementRatio);
	m_dcGridParameters.PushDataChunk(&m_eBoundaryCondition);
	m_dcGridParameters.PushDataChunk(&m_dReferenceLength);
	m_dcGridParameters.PushDataChunk(&m_dZtop);
	m_dcGridParameters.PushDataChunk(&m_fHasReferenceState);
	m_dcGridParameters.PushDataChunk(&m_fHasRayleighFriction);

	m_dcGridParameters.Allocate();
}
Esempio n. 11
0
int Grid::GetTotalNodeCount(
	DataLocation loc
) const {

	// Total number of nodes over all patches of grid
	int nTotalNodes = 0;

	// Loop over all patches and obtain total node count
	for (int n = 0; n < m_aPatchBoxes.GetRows(); n++) {
		const PatchBox & box = GetPatchBox(n);

		int nPatchNodes;
		if (loc == DataLocation_Node) {
			nPatchNodes = box.GetTotalNodes() * GetRElements();
		} else if (loc == DataLocation_REdge) {
			nPatchNodes = box.GetTotalNodes() * (GetRElements() + 1);
		} else {
			_EXCEPTIONT("Invalid location");
		}

		nTotalNodes += nPatchNodes;
	}

	return nTotalNodes;
}
void CubedSphereTrans::XYZFromXYP(
	double dXX,
	double dYY,
	int np,
	double &xx,
	double &yy,
	double &zz
) {
	// X, Y, Z coordinates in the local panel-centric coordinate system
	double sx, sy, sz;

	// Convert to Cartesian coordinates
	sz = 1.0 / sqrt(1.0 + dXX * dXX + dYY * dYY);
	sx = sz * dXX;
	sy = sz * dYY;

	// Rotate panel-centroid Cartesian coordinates to global
	// Cartesian coordinates.
	switch(np) {
		case 0:
			yy = sx;
			zz = sy;
			xx = sz;
			break;

		case 1:
			xx = -sx;
			zz = sy;
			yy = sz;
			break;

		case 2:
			yy = -sx;
			zz = sy;
			xx = -sz;
			break;

		case 3:
			xx = sx;
			zz = sy;
			yy = -sz;
			break;

		case 4:
			yy = sx;
			xx = -sy;
			zz = sz;
			break;

		case 5:
			yy = sx;
			xx = sy;
			zz = -sz;
			break;

		default:
			_EXCEPTIONT("Invalid panel id");
	}
}
Esempio n. 13
0
void Grid::ConvertReferenceToPatchCoord(
	const DataArray1D<double> & dXReference,
	const DataArray1D<double> & dYReference,
	DataArray1D<double> & dAlpha,
	DataArray1D<double> & dBeta,
	DataArray1D<int> & iPatch
) const {
	_EXCEPTIONT("Unimplemented.");
}
Esempio n. 14
0
void GridCartesianGLL::GetOpposingDirection(
	int ixPanelSrc,
	int ixPanelDest,
	Direction dir,
	Direction & dirOpposing,
	bool & fSwitchParallel,
	bool & fSwitchPerpendicular
) const {
	if ((ixPanelSrc < 0) || (ixPanelSrc > 5)) {
		_EXCEPTIONT("Invalid value for ixPanelSrc: Out of range");
	}
	if ((ixPanelDest < 0) || (ixPanelDest > 5)) {
		_EXCEPTIONT("Invalid value for ixPanelDest: Out of range");
	}

	// Get the opposing direction for Cartesian panels Source = Destination
	if (ixPanelDest != ixPanelSrc) {
		_EXCEPTIONT("ERROR: Soure and Destination panels must be equal!");
	}

	if (dir == Direction_Right) {
		dirOpposing = Direction_Left;
	} else if (dir == Direction_Top) {
		dirOpposing = Direction_Bottom;
	} else if (dir == Direction_Left) {
		dirOpposing = Direction_Right;
	} else if (dir == Direction_Bottom) {
		dirOpposing = Direction_Top;
	} else if (dir == Direction_TopRight) {
		dirOpposing = Direction_BottomLeft;
	} else if (dir == Direction_TopLeft) {
		dirOpposing = Direction_BottomRight;
	} else if (dir == Direction_BottomLeft) {
		dirOpposing = Direction_TopRight;
	} else if (dir == Direction_BottomRight) {
		dirOpposing = Direction_TopLeft;
	}

	// Do not switch directions across this edge
	fSwitchParallel = false;
	fSwitchPerpendicular = false;
}
Esempio n. 15
0
void Grid::EvaluateVerticalStretchF(
	double dREta,
	double & dREtaStretch,
	double & dDxREtaStretch
) {
	if (m_pVerticalStretchF == NULL) {
		_EXCEPTIONT("No VerticalStretchFunction defined in Grid");
	}

	(*m_pVerticalStretchF)(dREta, dREtaStretch, dDxREtaStretch);
}
Esempio n. 16
0
void Grid::SetBoundaryCondition(
	Direction eDir,
	BoundaryCondition eBoundaryCondition
) {
	int iDir = static_cast<int>(eDir);

	if ((iDir < 0) || (iDir > 3)) {
		_EXCEPTIONT("Invalid Direction specified");
	}

	m_eBoundaryCondition[iDir] = eBoundaryCondition;
}
Esempio n. 17
0
void Grid::RegisterExchangeBuffer(
	int ixSourcePatch,
	int ixTargetPatch,
	Direction dir
) {
	const PatchBox & box = GetPatchBox(ixSourcePatch);

	// First patch coordinate index
	int ixFirst;
	int ixSecond;

	if ((dir == Direction_Right) ||
		(dir == Direction_Left)
	) {
		ixFirst  = box.GetBInteriorBegin();
		ixSecond = box.GetBInteriorEnd();

	} else if (
		(dir == Direction_Top) ||
		(dir == Direction_Bottom)
	) {
		ixFirst  = box.GetAInteriorBegin();
		ixSecond = box.GetAInteriorEnd();

	} else if (dir == Direction_TopRight) {
		ixFirst  = box.GetAInteriorEnd()-1;
		ixSecond = box.GetBInteriorEnd()-1;

	} else if (dir == Direction_TopLeft) {
		ixFirst  = box.GetAInteriorBegin();
		ixSecond = box.GetBInteriorEnd()-1;

	} else if (dir == Direction_BottomLeft) {
		ixFirst  = box.GetAInteriorBegin();
		ixSecond = box.GetBInteriorBegin();

	} else if (dir == Direction_BottomRight) {
		ixFirst  = box.GetAInteriorEnd()-1;
		ixSecond = box.GetBInteriorBegin();

	} else {
		_EXCEPTIONT("Invalid direction");
	}

	// Exterior connect
	RegisterExchangeBuffer(
		ixSourcePatch,
		ixTargetPatch,
		dir,
		ixFirst,
		ixSecond);
}
int TimestepSchemeStrang::GetSubStepCount() const {

	HorizontalDynamics * pHorizontalDynamics =
		m_model.GetHorizontalDynamics();

	if (pHorizontalDynamics == NULL) {
		_EXCEPTIONT("HorizontalDynamics has not been initialized");
	}

	int nHorizontalDynamicsSubSteps =
		pHorizontalDynamics->GetSubStepAfterSubCycleCount();

	return (m_nExplicitSubSteps + nHorizontalDynamicsSubSteps + 1);
}
bool OutputManagerComposite::OpenFile(
    const std::string & strFileName
) {
#ifdef USE_MPI
    // Determine processor rank
    int nRank;
    MPI_Comm_rank(MPI_COMM_WORLD, &nRank);

    // Open file at root
    if (nRank == 0) {

        // Check for existing file
        if (m_ofsActiveOutput.is_open()) {
            _EXCEPTIONT("Restart file already open");
        }

        // Open new binary output stream
        std::string strRestartFileName = strFileName + ".restart.dat";
        m_ofsActiveOutput.open(
            strRestartFileName.c_str(), std::ios::binary | std::ios::out);

        if (!m_ofsActiveOutput) {
            _EXCEPTION1("Error opening output file \"%s\"",
                        strRestartFileName.c_str());
        }
    }

    // Wait for all processes to complete
    MPI_Barrier(MPI_COMM_WORLD);

    return true;
#else
    _EXCEPTIONT("Not implemented without USE_MPI");
#endif

}
Esempio n. 20
0
void ExchangeBufferRegistry::Register(
	const ExchangeBuffer & exbuf
) {
#ifdef TEMPEST_MPIOMP
	int nRank;
	MPI_Comm_rank(MPI_COMM_WORLD, &nRank);

	if (exbuf.m_ixSourceProcessor != nRank) {
		_EXCEPTIONT("ExchangeBuffer must be local");
	}
#endif

	// Add the ExchangeBuffer to the registry
	m_vecRegistry.push_back(exbuf);
}
void GridCartesianGLL::DefineParameters() {

	if (m_dcGridParameters.IsAttached()) {
		_EXCEPTIONT("Attempting to recall SetParameters");
	}

	// Set the dimension of the Cartesian domain
	m_dGDim.SetSize(6);

	// Add parameters for GridCartesianGLL
	m_dcGridParameters.PushDataChunk(&m_dGDim);
	m_dcGridParameters.PushDataChunk(&m_dRefLat);

	// Call up the stack
	GridGLL::DefineParameters();
}
Esempio n. 22
0
void ExchangeBuffer::Reset() {
	if (m_dSendBuffer.GetByteSize() < sizeof(MessageHeader)) {
		_EXCEPTION1("Invalid ExchangeBuffer send buffer (%i)",
			m_dSendBuffer.GetByteSize());
	}
	if (sizeof(MessageHeader) % sizeof(double) != 0) {
		_EXCEPTIONT("sizeof(MessageHeader) % sizeof(double) != 0");
	}

	// Store ExchangeBuffer::MessageHeader
	GetSendMessageHeader((MessageHeader *)(&(m_dSendBuffer[0])));

	// Set read and write indices to just beyond the MessageHeader
	m_ixRecvBuffer = sizeof(MessageHeader) / sizeof(double);
	m_ixSendBuffer = sizeof(MessageHeader) / sizeof(double);
}
double GridSpacingGaussLobattoRepeated::GetEdge(int ix) const {
	int ixElement    = (ix / m_nOrder);
	int ixSubElement = (ix % m_nOrder);

	if (ix < 0) {
		ixElement = ixElement - 1;
		ixSubElement = m_nOrder + ixSubElement;
	}

	if (ixSubElement >= m_nOrder) {
		_EXCEPTIONT("Logic error");
	}

	return (m_dZeroCoord
		+ m_dDeltaElement * static_cast<double>(ixElement)
		+ m_dG[ixSubElement]);
}
double GridSpacingGaussLobatto::GetNode(int ix) const {
	int ixElement    = (ix / (m_nOrder - 1));
	int ixSubElement = (ix % (m_nOrder - 1));

	// Case of a negative index
	if (ix < 0) {
		ixElement = ixElement - 1;
		ixSubElement = m_nOrder + ixSubElement;
	}

	if (ixSubElement >= m_nOrder) {
		_EXCEPTIONT("Logic error");
	}

	return (m_dZeroCoord
		+ m_dDeltaElement * static_cast<double>(ixElement)
		+ m_dG[ixSubElement]);
}
Esempio n. 25
0
size_t DataContainer::GetTotalByteSize() const {
	
	// Get the accumulated size of all DataChunks
	size_t sAccumulated = 0;

	for (size_t i = 0; i < m_vecDataChunks.size(); i++) {
		DataChunk * pDataChunk =
			reinterpret_cast<DataChunk*>(m_vecDataChunks[i]);

		// Verify byte alignment
		size_t sByteSize = pDataChunk->GetByteSize();
		if (sByteSize % sizeof(size_t) != 0) {
			_EXCEPTIONT("Misaligned array detected in DataContainer");
		}
		sAccumulated += sByteSize;
	}

	return sAccumulated;
}
void CopyNcVarAttributes(
	NcVar * varIn,
	NcVar * varOut
) {
	for (int a = 0; a < varIn->num_atts(); a++) {
		NcAtt * att = varIn->get_att(a);
		long num_vals = att->num_vals();

		NcValues * pValues = att->values();

		if (att->type() == ncByte) {
			varOut->add_att(att->name(), num_vals,
				(const ncbyte*)(pValues->base()));

		} else if (att->type() == ncChar) {
			varOut->add_att(att->name(), num_vals,
				(const char*)(pValues->base()));

		} else if (att->type() == ncShort) {
			varOut->add_att(att->name(), num_vals,
				(const short*)(pValues->base()));

		} else if (att->type() == ncInt) {
			varOut->add_att(att->name(), num_vals,
				(const int*)(pValues->base()));

		} else if (att->type() == ncFloat) {
			varOut->add_att(att->name(), num_vals,
				(const float*)(pValues->base()));

		} else if (att->type() == ncDouble) {
			varOut->add_att(att->name(), num_vals,
				(const double*)(pValues->base()));

		} else {
			_EXCEPTIONT("Invalid attribute type");
		}

		delete pValues;
	}
}
double LegendrePolynomial::DerivativeExtendedRoot(
	int nDegree,
	int nRoot
) {
	if ((nRoot >= (nDegree + 1)) || (nRoot < 0)) {
		_EXCEPTIONT("Invalid root.");
	}

	// First root is -1
	if (nRoot == 0) {
		return -1.0;

	// Last root is 1
	} else if (nRoot == nDegree) {
		return 1.0;

	// Otherwise handle interior roots
	} else {
		return DerivativeRoot(nDegree, nRoot - 1);
	}
}
Esempio n. 28
0
void Grid::InitializeDataLocal() {

	if (m_dcGridPatchData.IsAttached()) {
		_EXCEPTIONT("Attempting to call InitializeDataLocal on"
			" initialized Grid");
	}

	// Number of components
	int nComponents = m_model.GetEquationSet().GetComponents();

	// Set the size of all DataArray objects
	m_aPatchBoxes.SetSize(m_nMaxPatchCount);
	m_dREtaLevels.SetSize(m_nRElements);
	m_dREtaInterfaces.SetSize(m_nRElements+1);
	m_dREtaLevelsNormArea.SetSize(m_nRElements);
	m_dREtaInterfacesNormArea.SetSize(m_nRElements+1);
	m_dREtaStretchLevels.SetSize(m_nRElements);
	m_dREtaStretchInterfaces.SetSize(m_nRElements+1);
	m_vecVarLocation.SetSize(nComponents);
	m_vecVarIndex.SetSize(nComponents);
	m_vecVarsAtLocation.SetSize((size_t)DataLocation_Count);

	// Initialize the GridData DataContainer
	m_dcGridPatchData.PushDataChunk(&m_nInitializedPatchBoxes);
	m_dcGridPatchData.PushDataChunk(&m_aPatchBoxes);
	m_dcGridPatchData.PushDataChunk(&m_dREtaLevels);
	m_dcGridPatchData.PushDataChunk(&m_dREtaInterfaces);
	m_dcGridPatchData.PushDataChunk(&m_dREtaLevelsNormArea);
	m_dcGridPatchData.PushDataChunk(&m_dREtaInterfacesNormArea);
	m_dcGridPatchData.PushDataChunk(&m_dREtaStretchLevels);
	m_dcGridPatchData.PushDataChunk(&m_dREtaStretchInterfaces);
	m_dcGridPatchData.PushDataChunk(&m_vecVarLocation);
	m_dcGridPatchData.PushDataChunk(&m_vecVarIndex);
	m_dcGridPatchData.PushDataChunk(&m_vecVarsAtLocation);

	m_dcGridPatchData.Allocate();

	// Default GridData values
	m_nInitializedPatchBoxes = 0;
}
void ExteriorNeighbor::Send() {

	// Send the data
	const GridPatch & patch = m_pConnect->GetGridPatch();

	const Grid & grid = patch.GetGrid();

	int ixPatch = patch.GetPatchIndex();

	int iProcessor = grid.GetPatch(m_ixNeighbor)->GetProcessor();

	// Tag
	if (m_ixNeighbor >= (2 << 12)) {
		_EXCEPTIONT("Maximum neighbor index exceeded.");
	}

	int nTag = (ixPatch << 16) + (m_ixNeighbor << 4) + (int)(m_dirOpposite);

#pragma message "Move MPI_TAG processing to Connectivity"

	MPI_Isend(
		&(m_vecSendBuffer[0]),
		m_ixSendBuffer,
		MPI_DOUBLE,
		iProcessor,
		nTag,
		MPI_COMM_WORLD,
		&m_reqSend);
/*
	MPI_Send(
		&(m_vecSendBuffer[0]),
		m_ixSendBuffer,
		MPI_DOUBLE,
		iProcessor,
		nTag,
		MPI_COMM_WORLD);
*/
}
Esempio n. 30
0
void DataContainer::AttachTo(
	unsigned char * pAllocatedMemory
) {
	if (m_pAllocatedMemory != NULL) {
		_EXCEPTIONT("Attempting AttachTo() on attached DataContainer");
	}

	m_fOwnsData = false;
	m_pAllocatedMemory = pAllocatedMemory;

	// Assign memory to DataChunks
	unsigned char * pAccumulated = m_pAllocatedMemory;

	for (size_t i = 0; i < m_vecDataChunks.size(); i++) {

		DataChunk * pDataChunk =
			reinterpret_cast<DataChunk *>(m_vecDataChunks[i]);
		pDataChunk->AttachToData(
			reinterpret_cast<void *>(pAccumulated));

		pAccumulated += pDataChunk->GetByteSize();
	}
}