Example #1
0
/*!
 Destructor for the CG vectors data.

 @param[inout] data the CG vectors data structure whose storage is deallocated
 */
inline void DeleteCGData(CGData & data) {

  DeleteVector (data.r);
  DeleteVector (data.z);
  DeleteVector (data.p);
  DeleteVector (data.Ap);
  return;
}
Example #2
0
	void CText2Scene::DeleteStage()
	{
		if (m_pStage == NULL)
		{
			return;
		}
		DeleteVector(&m_pStage->m_Scenes);
		DeleteVector(&m_pStage->m_Actors);
		delete m_pStage;
		m_pStage = NULL;
	}
double AbstractParameterisedSystem<VECTOR>::GetAnyVariable(unsigned index, double time,
                                                           VECTOR* pDerivedQuantities)
{
    if (index < mNumberOfStateVariables)
    {
        return GetVectorComponent(mStateVariables, index);
    }
    else if (index - mNumberOfStateVariables < GetVectorSize(mParameters))
    {
        return GetVectorComponent(mParameters, index - mNumberOfStateVariables);
    }
    else
    {
        unsigned offset = mNumberOfStateVariables + GetVectorSize(mParameters);
        if (index - offset < GetNumberOfDerivedQuantities())
        {
            VECTOR dqs;
            if (pDerivedQuantities == NULL)
            {
                dqs = ComputeDerivedQuantitiesFromCurrentState(time);
                pDerivedQuantities = &dqs;
            }
            double value = GetVectorComponent(*pDerivedQuantities, index - offset);
            if (pDerivedQuantities == &dqs)
            {
                DeleteVector(dqs);
            }
            return value;
        }
        else
        {
            EXCEPTION("Invalid index passed to GetAnyVariable.");
        }
    }
}
Example #4
0
 void CheckDerivedQuantities(AbstractParameterisedSystem<VECTOR_TYPE>& rCell,
                             const VECTOR_TYPE& rStateVec)
 {
     TS_ASSERT_EQUALS(rCell.GetNumberOfDerivedQuantities(), 2u);
     TS_ASSERT_EQUALS(rCell.GetDerivedQuantityIndex("FonRT"), 0u);
     TS_ASSERT_EQUALS(rCell.GetDerivedQuantityIndex("potassium_currents"), 1u);
     TS_ASSERT_EQUALS(rCell.GetDerivedQuantityUnits(0u), "per_millivolt");
     TS_ASSERT_EQUALS(rCell.GetDerivedQuantityUnits(1u), "microA_per_cm2");
     VECTOR_TYPE derived = rCell.ComputeDerivedQuantitiesFromCurrentState(0.0);
     const double FonRT = 0.037435728309031795;
     const double i_K_total = 1.0007;
     TS_ASSERT_EQUALS(GetVectorSize(derived), 2u);
     TS_ASSERT_DELTA(GetVectorComponent(derived, 0), FonRT, 1e-12);
     TS_ASSERT_DELTA(GetVectorComponent(derived, 1), i_K_total, 1e-4);
     DeleteVector(derived);
     derived = rCell.ComputeDerivedQuantities(0.0, rStateVec);
     TS_ASSERT_EQUALS(GetVectorSize(derived), 2u);
     TS_ASSERT_DELTA(GetVectorComponent(derived, 0), FonRT, 1e-12);
     TS_ASSERT_DELTA(GetVectorComponent(derived, 1), i_K_total, 1e-4);
     DeleteVector(derived);
 }
Example #5
0
// Set the symbol information
// Return false if input is wrong
bool Symbol::SetMultiplier(const char* info)
{	
	// Get cell values
	std::vector<char*>* multipliers = SplitString(info, ';');
	
	// Get config pointer
	Config* config = Config::GetInst();
	
	// The number of cell is wrong => error
	if(config->GetNumOfWheels() != (int)multipliers->size())
	{
		DeleteVector(&multipliers);
	}
	
	// Save multiplier values
	for(int i = 0; i < (int)multipliers->size(); i++)
	{
		m_multipliers[i] = atoi((*multipliers)[i]);
	}
	
	DeleteVector(&multipliers);
	return true;
}
void VehicleController::UnloadComponents()
{
	m_retroStructList.clear();
	m_retroStructList.shrink_to_fit();

	m_bodyStructList.clear();
	m_bodyStructList.shrink_to_fit();

	m_frontWheelStructList.clear();
	m_frontWheelStructList.shrink_to_fit();

	m_backWheelStructList.clear();
	m_backWheelStructList.shrink_to_fit();

	m_spoilerStructList.clear();
	m_spoilerStructList.shrink_to_fit();

	DeleteVector(m_vehicles);
}
Example #7
0
void AbstractCvodeCell::SetStateVariables(const std::vector<double>& rVariables)
{
    N_Vector vars = MakeNVector(rVariables);
    AbstractCvodeSystem::SetStateVariables(vars);
    DeleteVector(vars);
}
Example #8
0
// Load the symbols from file
bool SymbolManager::LoadSymbols()
{
	// Open the file
	std::ifstream symbolsFile;
	symbolsFile.open(SYMBOLS_FILE, std::ios::in);
	
	// If symbolsFile is not OK => exit
	if(!symbolsFile.is_open() || !symbolsFile.good())
	{
		return false;
	}
	
	// Each file line represent a Symbol
	// Load and instanciate each Symbol
	while(symbolsFile.good())
	{
		// Get symbols info
		std::string line;
	 	std::getline(symbolsFile, line);
		
		// Get id and type
		std::vector<char*> * idntype = SplitString(line, '|');

		// Check if result is OK
		if(idntype->size() < 1)
		{
			DeleteVector(&idntype);
			continue;
		}
		
		// Get id and type
		std::vector<char*>* idntypeSplitted = SplitString((*idntype)[0], ';');
		
		// Check if result is OK
		if(idntypeSplitted->size() != 2)
		{
			DeleteVector(&idntypeSplitted);
			DeleteVector(&idntype);
			continue;
		}

		// Get id first
		int id = atoi((*idntypeSplitted)[0]);
		SymbolType type = (SymbolType)atoi((*idntypeSplitted)[1]);
		
		// No more needed
		DeleteVector(&idntypeSplitted);
		
		// Check if symbol is already present and type is correct	
		if(m_symbols.find(id) != m_symbols.end() || type >= NUMOFSYMBOLTYPES)
		{
			DeleteVector(&idntype);
			return false;
		}
		
		// Create new Symbol
		Symbol* newSymbol = new Symbol(id, type);
		
		// If the symbol has multipliers
		if(type != WILD)
		{
			// Check if input is correct	
			if(idntype->size() != 2)
			{
				DeleteVector(&idntype);
				delete newSymbol;
				continue;
			}

			// Set symbol multiplier
			if(newSymbol->SetMultiplier((*idntype)[1]) == false)
			{	
				// Error occured during the line setting
				delete newSymbol;
				DeleteVector(&idntype);
				continue;
			}
		}

		// Save the line in the map
		m_symbols[id] = newSymbol;

		// Clean memory
		DeleteVector(&idntype);	
	}

	// Load is OK
	return true;
}
Example #9
0
int TestSymmetry(SparseMatrix & A, Vector & b, Vector & xexact, TestSymmetryData & testsymmetry_data) {

 local_int_t nrow = A.localNumberOfRows;
 local_int_t ncol = A.localNumberOfColumns;

 Vector x_ncol, y_ncol, z_ncol;
 InitializeVector(x_ncol, ncol);
 InitializeVector(y_ncol, ncol);
 InitializeVector(z_ncol, ncol);

 double t4 = 0.0; // Needed for dot-product call, otherwise unused
 testsymmetry_data.count_fail = 0;

 // Test symmetry of matrix

 // First load vectors with random values
 FillRandomVector(x_ncol);
 FillRandomVector(y_ncol);

 double xNorm2, yNorm2;
 double ANorm = 2 * 26.0;

 // Next, compute x'*A*y
 ComputeDotProduct(nrow, y_ncol, y_ncol, yNorm2, t4, A.isDotProductOptimized);
 int ierr = ComputeSPMV(A, y_ncol, z_ncol); // z_nrow = A*y_overlap
 if (ierr) HPCG_fout << "Error in call to SpMV: " << ierr << ".\n" << endl;
 double xtAy = 0.0;
 ierr = ComputeDotProduct(nrow, x_ncol, z_ncol, xtAy, t4, A.isDotProductOptimized); // x'*A*y
 if (ierr) HPCG_fout << "Error in call to dot: " << ierr << ".\n" << endl;

 // Next, compute y'*A*x
 ComputeDotProduct(nrow, x_ncol, x_ncol, xNorm2, t4, A.isDotProductOptimized);
 ierr = ComputeSPMV(A, x_ncol, z_ncol); // b_computed = A*x_overlap
 if (ierr) HPCG_fout << "Error in call to SpMV: " << ierr << ".\n" << endl;
 double ytAx = 0.0;
 ierr = ComputeDotProduct(nrow, y_ncol, z_ncol, ytAx, t4, A.isDotProductOptimized); // y'*A*x
 if (ierr) HPCG_fout << "Error in call to dot: " << ierr << ".\n" << endl;

 testsymmetry_data.depsym_spmv = std::fabs((long double) (xtAy - ytAx))/((xNorm2*ANorm*yNorm2 + yNorm2*ANorm*xNorm2) * (DBL_EPSILON));
 if (testsymmetry_data.depsym_spmv > 1.0) ++testsymmetry_data.count_fail;  // If the difference is > 1, count it wrong
 if (A.geom->rank==0) HPCG_fout << "Departure from symmetry (scaled) for SpMV abs(x'*A*y - y'*A*x) = " << testsymmetry_data.depsym_spmv << endl;

 // Test symmetry of symmetric Gauss-Seidel

 // Compute x'*Minv*y
 ierr = ComputeMG(A, y_ncol, z_ncol); // z_ncol = Minv*y_ncol
 if (ierr) HPCG_fout << "Error in call to MG: " << ierr << ".\n" << endl;
 double xtMinvy = 0.0;
 ierr = ComputeDotProduct(nrow, x_ncol, z_ncol, xtMinvy, t4, A.isDotProductOptimized); // x'*Minv*y
 if (ierr) HPCG_fout << "Error in call to dot: " << ierr << ".\n" << endl;

 // Next, compute z'*Minv*x
 ierr = ComputeMG(A, x_ncol, z_ncol); // z_ncol = Minv*x_ncol
 if (ierr) HPCG_fout << "Error in call to MG: " << ierr << ".\n" << endl;
 double ytMinvx = 0.0;
 ierr = ComputeDotProduct(nrow, y_ncol, z_ncol, ytMinvx, t4, A.isDotProductOptimized); // y'*Minv*x
 if (ierr) HPCG_fout << "Error in call to dot: " << ierr << ".\n" << endl;

 testsymmetry_data.depsym_mg = std::fabs((long double) (xtMinvy - ytMinvx))/((xNorm2*ANorm*yNorm2 + yNorm2*ANorm*xNorm2) * (DBL_EPSILON));
 if (testsymmetry_data.depsym_mg > 1.0) ++testsymmetry_data.count_fail;  // If the difference is > 1, count it wrong
 if (A.geom->rank==0) HPCG_fout << "Departure from symmetry (scaled) for MG abs(x'*Minv*y - y'*Minv*x) = " << testsymmetry_data.depsym_mg << endl;

 CopyVector(xexact, x_ncol); // Copy exact answer into overlap vector

 int numberOfCalls = 2;
 double residual = 0.0;
 for (int i=0; i< numberOfCalls; ++i) {
   ierr = ComputeSPMV(A, x_ncol, z_ncol); // b_computed = A*x_overlap
   if (ierr) HPCG_fout << "Error in call to SpMV: " << ierr << ".\n" << endl;
   if ((ierr = ComputeResidual(A.localNumberOfRows, b, z_ncol, residual)))
     HPCG_fout << "Error in call to compute_residual: " << ierr << ".\n" << endl;
   if (A.geom->rank==0) HPCG_fout << "SpMV call [" << i << "] Residual [" << residual << "]" << endl;
 }
 DeleteVector(x_ncol);
 DeleteVector(y_ncol);
 DeleteVector(z_ncol);

 return 0;
}
Example #10
0
Aprendizagem_Reforco::~Aprendizagem_Reforco()
{
	DeleteVector(vetorHeuristica);
}
void AbstractParameterisedSystem<VECTOR>::ResetToInitialConditions()
{
    VECTOR inits = GetInitialConditions();
    SetStateVariables(inits);
    DeleteVector(inits);
}