void TriangularCadInterface::updateBackgroundGridInfo() { getAllCells(m_Cells, m_BGrid); getNodesFromCells(m_Cells, m_Nodes, m_BGrid); setBoundaryCodes(GuiMainWindow::pointer()->getAllBoundaryCodes()); setAllCells(); readVMD(); updatePotentialSnapPoints(); l2l_t c2c = getPartC2C(); g2l_t _cells = getPartLocalCells(); QVector<int> m_LNodes(m_Nodes.size()); for (int i = 0; i < m_LNodes.size(); ++i) { m_LNodes[i] = i; } createNodeToNode(m_Cells, m_Nodes, m_LNodes, m_N2N, m_BGrid); // create m_Triangles m_Triangles.resize(m_BGrid->GetNumberOfCells()); for (vtkIdType id_cell = 0; id_cell < m_BGrid->GetNumberOfCells(); ++id_cell) { m_Triangles[id_cell] = Triangle(m_BGrid, id_cell); for (int i = 0; i < 3; i++) { int i_cell = _cells[id_cell]; if (c2c[i_cell][i] < 0) { m_Triangles[id_cell].setNeighbourFalse(i); } else { m_Triangles[id_cell].setNeighbourTrue(i); } } } // compute node normals m_NodeNormals.resize(m_BGrid->GetNumberOfPoints()); for (vtkIdType id_node = 0; id_node < m_BGrid->GetNumberOfPoints(); ++id_node) { m_NodeNormals[id_node] = vec3_t(0, 0, 0); } foreach(Triangle T, m_Triangles) { double angle_a = GeometryTools::angle(m_BGrid, T.idC(), T.idA(), T.idB()); double angle_b = GeometryTools::angle(m_BGrid, T.idA(), T.idB(), T.idC()); double angle_c = GeometryTools::angle(m_BGrid, T.idB(), T.idC(), T.idA()); if (isnan(angle_a) || isinf(angle_a)) EG_BUG; if (isnan(angle_b) || isinf(angle_b)) EG_BUG; if (isnan(angle_c) || isinf(angle_c)) EG_BUG; if (!checkVector(T.g3())) { qWarning() << "T.g3 = " << T.g3(); EG_BUG; } m_NodeNormals[T.idA()] += angle_a * T.g3(); m_NodeNormals[T.idB()] += angle_b * T.g3(); m_NodeNormals[T.idC()] += angle_c * T.g3(); if (!checkVector(m_NodeNormals[T.idA()])) EG_BUG; if (!checkVector(m_NodeNormals[T.idB()])) EG_BUG; if (!checkVector(m_NodeNormals[T.idC()])) EG_BUG; }
static int luaPrintReverseOrbit(lua_State* luaSt) { mwvector finalPos, finalVel; static real dt = 0.0; static real tstop = 0.0; static real tstopf = 0.0; static Potential* pot = NULL; static const mwvector* pos = NULL; static const mwvector* vel = NULL; //static mwbool SecondDisk = FALSE; static const MWNamedArg argTable[] = { { "potential", LUA_TUSERDATA, POTENTIAL_TYPE, TRUE, &pot }, { "position", LUA_TUSERDATA, MWVECTOR_TYPE, TRUE, &pos }, { "velocity", LUA_TUSERDATA, MWVECTOR_TYPE, TRUE, &vel }, { "tstop", LUA_TNUMBER, NULL, TRUE, &tstop }, { "tstopf", LUA_TNUMBER, NULL, TRUE, &tstopf }, { "dt", LUA_TNUMBER, NULL, TRUE, &dt }, END_MW_NAMED_ARG }; switch (lua_gettop(luaSt)) { case 1: handleNamedArgumentTable(luaSt, argTable, 1); break; case 6: pot = checkPotential(luaSt, 1); pos = checkVector(luaSt, 2); vel = checkVector(luaSt, 3); tstop = luaL_checknumber(luaSt, 4); tstopf = luaL_checknumber(luaSt, 5); dt = luaL_checknumber(luaSt, 6); break; default: return luaL_argerror(luaSt, 1, "Expected 1 or 6 arguments"); } /* Make sure precalculated constants ready for use */ if (checkPotentialConstants(pot)) luaL_error(luaSt, "Error with potential"); nbPrintReverseOrbit(&finalPos, &finalVel, pot, *pos, *vel, tstop, tstopf, dt); pushVector(luaSt, finalPos); pushVector(luaSt, finalVel); return 2; }
vec3_t projectPointOnEdge(const vec3_t& M,const vec3_t& A, const vec3_t& u) { checkVector(u); if(u.abs2()==0) EG_BUG; double k = ((M-A)*u)/u.abs2(); return A + k*u; }
static int luaLbrToCartesian(lua_State* luaSt) { mwbool useRadians = FALSE, useGalacticCoordinates = FALSE; real sunGCDist = DEFAULT_SUN_GC_DISTANCE; const NBodyCtx* ctx = NULL; mwvector v; if (lua_gettop(luaSt) > 4) luaL_argerror(luaSt, 4, "Expected 1, 2, 3 or 4 arguments"); ctx = checkNBodyCtx(luaSt, 1); v = *checkVector(luaSt, 2); /* ctx = toNBodyCtx(luaSt, 2); sunGCDist = ctx != NULL ? ctx->sunGCDist : luaL_optnumber(luaSt, 2, DEFAULT_SUN_GC_DISTANCE); */ sunGCDist = ctx->sunGCDist; useGalacticCoordinates = mw_lua_optboolean(luaSt, 3, FALSE); useRadians = mw_lua_optboolean(luaSt, 4, FALSE); if (!useGalacticCoordinates) v = useRadians ? lbrToCartesian_rad(v, sunGCDist) : lbrToCartesian(v, sunGCDist); pushVector(luaSt, v); return 1; }
void ModifiedPatankarRK(int dim_matrix, double oldvalue[], double dt, double newvalue[], recomb_t *thisRecombRates, cell_t *thisCell){ double intervalue[dim_matrix]; double oldvalue_local[dim_matrix]; double newvalue_local[dim_matrix]; double destr_rate[dim_matrix][dim_matrix]; double inter_destr_rate[dim_matrix][dim_matrix]; double matrix[dim_matrix][dim_matrix]; initializeVector(dim_matrix, oldvalue_local, oldvalue); initializeVector(dim_matrix, newvalue_local, oldvalue); // printf("oldvalue_local[0] = %e\toldvalue_local[1] = %e\n", oldvalue_local[0], oldvalue_local[1]); // First Runge Kutta step initializeVector(dim_matrix, oldvalue_local, newvalue_local); //oldvalue = x create_rate_functions(dim_matrix, destr_rate, oldvalue_local, thisRecombRates, thisCell); //calculate destruction rates calculateMatrix(dim_matrix, dt, matrix, destr_rate, oldvalue_local); //calculate matrix for destr_rate and oldvalue solveSetOfEquations(dim_matrix, matrix, oldvalue_local, intervalue); //Solve set of equations for intervalue checkVector(dim_matrix,intervalue); // Second Runge Kutta step initializeVector(dim_matrix, oldvalue_local, oldvalue); //oldvalue = newvalue create_rate_functions(dim_matrix, inter_destr_rate, intervalue, thisRecombRates, thisCell); //calculate new destruction rates from intervalue add_rate_functions(dim_matrix, inter_destr_rate, destr_rate); //add rate functions destr_rate and interdestr_rate, output on interdestr_rate calculateMatrix(dim_matrix, dt*0.5, matrix, inter_destr_rate, intervalue); //calculate matrix for interdestr_rate and intervalue solveSetOfEquations(dim_matrix, matrix, oldvalue_local, newvalue_local); //solve set of equations for newvalue checkVector(dim_matrix, newvalue_local); initializeVector(dim_matrix, newvalue, newvalue_local); }
void Parser::parse(std::list<tToken> &tokens) { tTI it(tokens.begin()); tTI ie(tokens.end()); size_t line(0); size_t count(0); while (it != ie && (it->first == Lexer::COMMENT || it->first == Lexer::END)) { if (it->first == Lexer::END) line++; it++; } line++; size(*it, line); it++; while (it != ie) { if (it->first == Lexer::VALUE) { values(it, ie, ++line); count++; } else if (it->first != Lexer::COMMENT && it->first != Lexer::END) error(line); it++; } if (count != _size) { error(line); if (count < _size) std::cerr << ": not enough lines" << std::endl; else if (count > _size) std::cerr << ": too much lines" << std::endl; } checkVector(); }
bool BrlCadInterface::brlCadShootRay(vec3_t x, vec3_t v, vec3_t &x_in, vec3_t &x_out, vec3_t &n_in, vec3_t &n_out, double &r_in, double &r_out) { if (!checkVector(x)) { EG_BUG; } if (!checkVector(v)) { EG_BUG; } VSET(m_Ap.a_ray.r_pt, x[0], x[1], x[2]); VSET(m_Ap.a_ray.r_dir, v[0], v[1], v[2]); m_Hit = false; m_Ap.a_hit = BrlCadInterface::hit; m_Ap.a_miss = BrlCadInterface::miss; rt_shootray(&m_Ap); x_in = m_XIn; n_in = m_InNormal; r_in = m_InRadius; x_out = m_XOut; n_out = m_OutNormal; r_out = m_OutRadius; x = x_out; if (!checkVector(x_in)) { EG_BUG; } if (!checkVector(x_out)) { EG_BUG; } if (!checkVector(n_in)) { EG_BUG; } if (!checkVector(n_out)) { EG_BUG; } return m_Hit; }
void UniqueLinSolveAtom::retrieve(const Query& query, Answer& answer) throw (PluginError) { Tuple parms = query.getInputTuple(); std::string matrixPred = ""; std::string constantPred = ""; int argc = 2; char* argv[] = {"-linkname", "math -mathlink"}; //check number and type of arguments if (parms.size()!= 2) { throw PluginError("Wrong number of arguments"); } else { if(parms[0].isSymbol() && parms[1].isSymbol()) { matrixPred = parms[0].getString(); //std::cout << "Matrixpraedikat: " << matrixPred << std::endl; constantPred = parms[1].getString(); //std::cout << "Vektorpraedikat: " << vectorPred << std::endl; } else { throw PluginError("Wrong type of arguments"); } } //get complete Interpretation of given predicates in query AtomSet totalInt = query.getInterpretation(); AtomSet matrixInt; AtomSet constantInt; if (totalInt.empty()) { throw PluginError("Could not find any interpretion"); } else { // separate interpretation into facts of first predicate (matrix) totalInt.matchPredicate(matrixPred, matrixInt); // and into facts of second predicate (vector) totalInt.matchPredicate(constantPred, constantInt); } int mRows = 0; int mColumns = 0; int cRows = 0; int cColumns = 0; evaluateMatrix(matrixInt, mRows, mColumns); evaluateVector(constantInt, cRows, cColumns); if(mRows != cRows) throw PluginError("Coefficient matrix and target vector(s) or matrix do not have the same dimensions."); std::vector <std::vector <std::string> > matrix(mRows); for(int i = 0; i < mRows; i++) matrix[i].resize(mColumns); std::vector <std::vector <std::string> > constants(cRows); for (int i = 0; i < cRows; i++) constants[i].resize(cColumns); //write the values of the Atoms in the Interpretation into std::vectors for further processing convertMatrixToVector(matrixInt, mRows, mColumns, matrix); convertMatrixToVector(constantInt, cRows, cColumns, constants); //check if matrix and target vector or matrix are fully defined checkVector(matrix, mRows, mColumns, matrixPred); checkVector(constants, cRows, cColumns, constantPred); //convert matrix to MatrixRank-expression and calculate rank of coefficient matrix A std::string coeffMRankExpr = toMatrixRankExpr(matrix, mRows, mColumns); //std::cout << "MatrixRank expression: " << coeffMRankExpr << std::endl; int coeffMRank = calculateRank(argc, argv, coeffMRankExpr); //convert matrix A and target b to MatrixRank-expression and calculate rank //of extended coefficient matrix [A,b] std::string extendedMRankExpr = toMatrixRankExpr(matrix, mRows, mColumns, constants, cRows, cColumns); //std::cout << "Extended MatrixRank expression: " << extendedMRankExpr << std::endl; int extCoeffMRank = calculateRank(argc, argv, extendedMRankExpr); //compare calculated ranks and number of matrix colums, iff they are equal, //a unique solution for the matrix equation exists if ((coeffMRank == extCoeffMRank) && (coeffMRank == mColumns)) { std::string linSolExpr = toLinearSolveExpr(matrix, mRows, mColumns, constants, cRows, cColumns); std::vector <std::string> result; result = calculateSolution(argc, argv, linSolExpr); if(result.size() != mColumns*cColumns) throw PluginError("Wrong number of arguments in result vector"); Tuple out; int index = 0; //fill the result values with correct indices into Tuple out //and add all Tuples to Answer for (int r = 1; r <= mColumns; r++) { for(int c = 1; c<= cColumns; c++) { out.push_back(Term(r)); out.push_back(Term(c)); out.push_back(Term(result[index],true)); answer.addTuple(out); out.clear(); index++; } } } }