void Integrate1DLine(int maxOrder, int numNodes1D, NuTo::eIntegrationMethod method) { NuTo::IntegrationTypeTensorProduct<1> intType(numNodes1D, method); for (int i = 0; i <= maxOrder; i++) { auto f = [i](Eigen::VectorXd x) { return (std::pow(x[0], i)); }; double computedResult = integrate(f, intType); double expectedResult = 1. / (i + 1) * (1. - std::pow(-1, i + 1)); BOOST_CHECK_SMALL(computedResult - expectedResult, 1.e-13); } }
void Integrate2DQuad(int maxOrder, int numNodes1D, NuTo::eIntegrationMethod method) { NuTo::IntegrationTypeTensorProduct<2> intType(numNodes1D, method); for (int n = 0; n <= maxOrder; n++) { for (int i = 0; i < n + 1; i++) { auto f = [n, i](Eigen::VectorXd x) { return (std::pow(x[0], i) * std::pow(x[1], n - i)); }; double computedResult = integrate(f, intType); double expectedResult = 1. / (i + 1) / (n - i + 1) * ((1. - std::pow(-1, i + 1)) * (1. - std::pow(-1, n - i + 1))); BOOST_CHECK_SMALL(computedResult - expectedResult, 1.e-13); } } }
TypePtr integerType(int bits, bool isSigned) { if (isSigned) return intType(bits); else return uintType(bits); }
void HDFAtom<int>::Read(int &value) { H5::DataType intType(H5::PredType::NATIVE_INT); attribute.read(intType, &value); }
void HDFAtom<uint64_t>::Read(uint64_t &value) { H5::DataType intType(H5::PredType::STD_I64LE); attribute.read(intType, &value); }
int genbf_primary_expr(struct primary_expr *a, int lval, struct type **t) { int i, v; struct var *sv; switch (a->type) { case _IDENTIFIER: /* where is this variable? */ v = getVar(a->v._identifier->v, &sv); /* there's a special case: if !lval but it's an array, we actually * want to treat it as an lval (get the data's location). If lval * and it's an array, we die (that's not allowed) */ if (sv->type->basic_type == TYPE_PTR && sv->type->array) { if (!lval) { lval = 1; } else { ERROR("primary_expr", "Changing array pointer values is not currently possible."); } } if (!lval) { BF_PUSH; pushTempVar(1); curvar->type = dupType(sv->type); /* FIXME: this needs to support a whole range of other idents */ if (v == -1) ERROR("primary_expr", "Undefined identifier."); v++; /* now go and get it */ printf("[-]"); for (i = 0; i < v; i++) printf("<<<<<"); /* dup */ printf("[>>>+>+<<<<-]>>>[<<<+>>>-]>["); /* carry it up */ for (i = 0; i < v; i++) printf(">>>>>"); printf("+"); for (i = 0; i < v; i++) printf("<<<<<"); printf("-]"); /* and put it in place */ for (i = 0; i < v; i++) printf(">>>>>"); printf("[<<<<+>>>>-]<<<<"); fflush(stdout); } else { /* lval - turn the identifier into a location */ if (v == -1) ERROR("primary_expr", "Undefined identifier."); if (t) *t = sv->type; /* now we must turn this depth into a location */ BF_PUSH; pushTempVar(1); curvar->type = dupType(sv->type); /* this is now a pointer at the array */ curvar->type->array = 0; curvar->type->size = 1; printf("[-]"); v++; for (i = 0; i < v; i++) printf("<<<<<"); STACK_POS_TO_PTR; return -1; } break; case _CONSTANT: if (lval) ERROR("primary_expr", "Invalid l-value."); /* FIXME: this is a ridiculous way to generate a constant ... */ BF_PUSH; pushTempVar(1); curvar->type = intType(); printf("[-]"); /* constants can be either numbers or 'characters' */ if (a->v._token[0] == '\'') { v = *genbf_parse_string(a->v._token); } else { v = atoi(a->v._token); } if (v >= 0) for (i = 0; i < v; i++) printf("+"); else for (i = 0; i > v; i--) printf("-"); fflush(stdout); break; case _EXPR: return genbf_expr(a->v._expr, lval, t); break; /*case _IDENTIFIER: genbf_identifier(a->v._identifier); break; case _CONSTANT: SPC; printf("CONSTANT: %s\n", a->v._token); break; case _STRING: SPC; printf("STRING: %s\n", a->v._token); break; case _EXPR: genbf_expr(a->v._expr); break;*/ default: UNIMPL("primary_expr"); } }