10 changed files with 1323 additions and 960 deletions
@ -0,0 +1,268 @@ |
|||
--- |
|||
BasedOnStyle: Google |
|||
AccessModifierOffset: -4 |
|||
AlignAfterOpenBracket: Align |
|||
AlignArrayOfStructures: Left |
|||
AlignConsecutiveAssignments: |
|||
Enabled: true |
|||
AcrossEmptyLines: false |
|||
AcrossComments: true |
|||
AlignCompound: true |
|||
PadOperators: true |
|||
AlignConsecutiveBitFields: |
|||
Enabled: true |
|||
AcrossEmptyLines: false |
|||
AcrossComments: true |
|||
AlignCompound: true |
|||
PadOperators: true |
|||
AlignConsecutiveDeclarations: |
|||
Enabled: true |
|||
AcrossEmptyLines: false |
|||
AcrossComments: true |
|||
AlignCompound: true |
|||
PadOperators: true |
|||
AlignConsecutiveMacros: |
|||
Enabled: true |
|||
AcrossEmptyLines: false |
|||
AcrossComments: true |
|||
AlignCompound: true |
|||
PadOperators: true |
|||
AlignConsecutiveShortCaseStatements: |
|||
Enabled: true |
|||
AcrossEmptyLines: false |
|||
AcrossComments: true |
|||
AlignCaseColons: false |
|||
AlignEscapedNewlines: Left |
|||
AlignOperands: Align |
|||
AlignTrailingComments: |
|||
Kind: Always |
|||
OverEmptyLines: 2 |
|||
AllowAllArgumentsOnNextLine: false |
|||
AllowAllParametersOfDeclarationOnNextLine: false |
|||
AllowShortBlocksOnASingleLine: Always |
|||
AllowShortCaseLabelsOnASingleLine: true |
|||
AllowShortEnumsOnASingleLine: true |
|||
AllowShortFunctionsOnASingleLine: All |
|||
AllowShortIfStatementsOnASingleLine: WithoutElse |
|||
AllowShortLambdasOnASingleLine: All |
|||
AllowShortLoopsOnASingleLine: true |
|||
AlwaysBreakAfterDefinitionReturnType: None |
|||
AlwaysBreakAfterReturnType: None |
|||
AlwaysBreakBeforeMultilineStrings: false |
|||
AlwaysBreakTemplateDeclarations: Yes |
|||
AttributeMacros: |
|||
- __capability |
|||
BinPackArguments: false |
|||
BinPackParameters: false |
|||
BitFieldColonSpacing: Both |
|||
BraceWrapping: |
|||
AfterCaseLabel: false |
|||
AfterClass: false |
|||
AfterControlStatement: Never |
|||
AfterEnum: false |
|||
AfterFunction: false |
|||
AfterNamespace: false |
|||
AfterObjCDeclaration: false |
|||
AfterStruct: false |
|||
AfterUnion: false |
|||
AfterExternBlock: false |
|||
BeforeCatch: false |
|||
BeforeElse: false |
|||
BeforeLambdaBody: false |
|||
BeforeWhile: false |
|||
IndentBraces: false |
|||
SplitEmptyFunction: true |
|||
SplitEmptyRecord: true |
|||
SplitEmptyNamespace: true |
|||
BreakAfterAttributes: Never |
|||
BreakAfterJavaFieldAnnotations: false |
|||
BreakArrays: true |
|||
BreakBeforeBinaryOperators: NonAssignment |
|||
BreakBeforeBraces: Linux |
|||
BreakBeforeConceptDeclarations: Always |
|||
BreakBeforeInlineASMColon: OnlyMultiline |
|||
BreakBeforeTernaryOperators: true |
|||
BreakConstructorInitializers: BeforeColon |
|||
BreakInheritanceList: AfterComma |
|||
BreakStringLiterals: true |
|||
ColumnLimit: 128 |
|||
CommentPragmas: "^(!<)? IWYU pragma:" |
|||
CompactNamespaces: false |
|||
ConstructorInitializerIndentWidth: 4 |
|||
ContinuationIndentWidth: 4 |
|||
Cpp11BracedListStyle: true |
|||
DerivePointerAlignment: true |
|||
DisableFormat: false |
|||
EmptyLineAfterAccessModifier: Never |
|||
EmptyLineBeforeAccessModifier: LogicalBlock |
|||
ExperimentalAutoDetectBinPacking: false |
|||
FixNamespaceComments: true |
|||
ForEachMacros: |
|||
- foreach |
|||
- Q_FOREACH |
|||
- BOOST_FOREACH |
|||
IfMacros: |
|||
- KJ_IF_MAYBE |
|||
IncludeBlocks: Regroup |
|||
IncludeCategories: |
|||
- Regex: ^<ext/.*\.h> |
|||
Priority: 2 |
|||
SortPriority: 0 |
|||
CaseSensitive: false |
|||
- Regex: ^<.*\.h> |
|||
Priority: 1 |
|||
SortPriority: 0 |
|||
CaseSensitive: false |
|||
- Regex: ^<.* |
|||
Priority: 2 |
|||
SortPriority: 0 |
|||
CaseSensitive: false |
|||
- Regex: .* |
|||
Priority: 3 |
|||
SortPriority: 0 |
|||
CaseSensitive: false |
|||
IncludeIsMainRegex: ([-_](test|unittest))?$ |
|||
IncludeIsMainSourceRegex: "" |
|||
IndentAccessModifiers: false |
|||
IndentCaseBlocks: false |
|||
IndentCaseLabels: true |
|||
IndentExternBlock: AfterExternBlock |
|||
IndentGotoLabels: false |
|||
IndentPPDirectives: None |
|||
IndentRequiresClause: true |
|||
IndentWidth: 4 |
|||
IndentWrappedFunctionNames: true |
|||
InsertBraces: false |
|||
InsertNewlineAtEOF: false |
|||
InsertTrailingCommas: None |
|||
IntegerLiteralSeparator: |
|||
Binary: 0 |
|||
BinaryMinDigits: 0 |
|||
Decimal: 0 |
|||
DecimalMinDigits: 0 |
|||
Hex: 0 |
|||
HexMinDigits: 0 |
|||
JavaScriptQuotes: Leave |
|||
JavaScriptWrapImports: true |
|||
KeepEmptyLinesAtEOF: false |
|||
KeepEmptyLinesAtTheStartOfBlocks: false |
|||
LambdaBodyIndentation: Signature |
|||
Language: Cpp |
|||
LineEnding: DeriveLF |
|||
MacroBlockBegin: "" |
|||
MacroBlockEnd: "" |
|||
MaxEmptyLinesToKeep: 2 |
|||
NamespaceIndentation: None |
|||
ObjCBinPackProtocolList: Never |
|||
ObjCBlockIndentWidth: 2 |
|||
ObjCBreakBeforeNestedBlockParam: true |
|||
ObjCSpaceAfterProperty: false |
|||
ObjCSpaceBeforeProtocolList: true |
|||
PPIndentWidth: -1 |
|||
PackConstructorInitializers: NextLine |
|||
PenaltyBreakAssignment: 2 |
|||
PenaltyBreakBeforeFirstCallParameter: 1 |
|||
PenaltyBreakComment: 300 |
|||
PenaltyBreakFirstLessLess: 120 |
|||
PenaltyBreakOpenParenthesis: 0 |
|||
PenaltyBreakString: 1000 |
|||
PenaltyBreakTemplateDeclaration: 10 |
|||
PenaltyExcessCharacter: 1000000 |
|||
PenaltyIndentedWhitespace: 0 |
|||
PenaltyReturnTypeOnItsOwnLine: 200 |
|||
PointerAlignment: Right |
|||
QualifierAlignment: Leave |
|||
RawStringFormats: |
|||
- Language: Cpp |
|||
Delimiters: |
|||
- cc |
|||
- CC |
|||
- cpp |
|||
- Cpp |
|||
- CPP |
|||
- c++ |
|||
- C++ |
|||
CanonicalDelimiter: "" |
|||
BasedOnStyle: google |
|||
- Language: TextProto |
|||
Delimiters: |
|||
- pb |
|||
- PB |
|||
- proto |
|||
- PROTO |
|||
EnclosingFunctions: |
|||
- EqualsProto |
|||
- EquivToProto |
|||
- PARSE_PARTIAL_TEXT_PROTO |
|||
- PARSE_TEST_PROTO |
|||
- PARSE_TEXT_PROTO |
|||
- ParseTextOrDie |
|||
- ParseTextProtoOrDie |
|||
- ParseTestProto |
|||
- ParsePartialTestProto |
|||
CanonicalDelimiter: pb |
|||
BasedOnStyle: google |
|||
ReferenceAlignment: Pointer |
|||
ReflowComments: true |
|||
RemoveBracesLLVM: false |
|||
RemoveParentheses: Leave |
|||
RemoveSemicolon: false |
|||
RequiresClausePosition: OwnLine |
|||
RequiresExpressionIndentation: OuterScope |
|||
SeparateDefinitionBlocks: Always |
|||
ShortNamespaceLines: 0 |
|||
SortIncludes: Never |
|||
SortJavaStaticImport: Before |
|||
SortUsingDeclarations: LexicographicNumeric |
|||
SpaceAfterCStyleCast: false |
|||
SpaceAfterLogicalNot: false |
|||
SpaceAfterTemplateKeyword: true |
|||
SpaceAroundPointerQualifiers: Default |
|||
SpaceBeforeAssignmentOperators: true |
|||
SpaceBeforeCaseColon: false |
|||
SpaceBeforeCpp11BracedList: false |
|||
SpaceBeforeCtorInitializerColon: true |
|||
SpaceBeforeInheritanceColon: true |
|||
SpaceBeforeJsonColon: false |
|||
SpaceBeforeParens: Custom |
|||
SpaceBeforeParensOptions: |
|||
AfterControlStatements: true |
|||
AfterForeachMacros: true |
|||
AfterFunctionDeclarationName: false |
|||
AfterFunctionDefinitionName: false |
|||
AfterIfMacros: true |
|||
AfterOverloadedOperator: false |
|||
AfterRequiresInClause: false |
|||
AfterRequiresInExpression: true |
|||
BeforeNonEmptyParentheses: false |
|||
SpaceBeforeRangeBasedForLoopColon: true |
|||
SpaceBeforeSquareBrackets: false |
|||
SpaceInEmptyBlock: false |
|||
SpacesBeforeTrailingComments: 1 |
|||
SpacesInAngles: Never |
|||
SpacesInContainerLiterals: true |
|||
SpacesInLineCommentPrefix: |
|||
Minimum: 1 |
|||
Maximum: -1 |
|||
SpacesInParens: Never |
|||
SpacesInParensOptions: |
|||
InConditionalStatements: false |
|||
InCStyleCasts: false |
|||
InEmptyParentheses: false |
|||
Other: false |
|||
SpacesInSquareBrackets: false |
|||
Standard: Auto |
|||
StatementAttributeLikeMacros: |
|||
- Q_EMIT |
|||
StatementMacros: |
|||
- Q_UNUSED |
|||
- QT_REQUIRE_VERSION |
|||
TabWidth: 8 |
|||
UseTab: Never |
|||
VerilogBreakBetweenInstancePorts: true |
|||
WhitespaceSensitiveMacros: |
|||
- BOOST_PP_STRINGIZE |
|||
- CF_SWIFT_NAME |
|||
- NS_SWIFT_NAME |
|||
- PP_STRINGIZE |
|||
- STRINGIZE |
File diff suppressed because it is too large
@ -0,0 +1,179 @@ |
|||
#include <bitset> |
|||
#include <iostream> |
|||
#include <booluarray.hpp> |
|||
|
|||
|
|||
#include <cstddef> |
|||
#include <iostream> |
|||
#include <iomanip> |
|||
#include <fstream> |
|||
#include <vector> |
|||
#include "bernstein.hpp" |
|||
#include "quadrature_multipoly.hpp" |
|||
|
|||
#include "real.hpp" |
|||
#include "uvector.hpp" |
|||
#include "vector" |
|||
#include "xarray.hpp" |
|||
|
|||
|
|||
using namespace algoim; |
|||
|
|||
// Driver method which takes a functor phi defining a single polynomial in the reference
|
|||
// rectangle [xmin, xmax]^N, of Bernstein degree P, along with an integrand function,
|
|||
// and performances a q-refinement convergence study, comparing the computed integral
|
|||
// with the given exact answers, for 1 <= q <= qMax.
|
|||
template <int N, typename Phi, typename F> |
|||
void qConv1(const Phi& phi, |
|||
real xmin, |
|||
real xmax, |
|||
uvector<int, N> P, |
|||
const F& integrand, |
|||
int qMax, |
|||
real volume_exact, |
|||
real surf_exact) |
|||
{ |
|||
// Construct Bernstein polynomial by mapping [0,1] onto bounding box [xmin,xmax]
|
|||
xarray<real, N> phipoly(nullptr, P); |
|||
algoim_spark_alloc(real, phipoly); |
|||
bernstein::bernsteinInterpolate<N>([&](const uvector<real, N>& x) { return phi(xmin + x * (xmax - xmin)); }, phipoly); |
|||
|
|||
// Build quadrature hierarchy
|
|||
ImplicitPolyQuadrature<N> ipquad(phipoly); |
|||
|
|||
// Functional to evaluate volume and surface integrals of given integrand
|
|||
real volume, surf; |
|||
auto compute = [&](int q) { |
|||
volume = 0.0; |
|||
surf = 0.0; |
|||
// compute volume integral over {phi < 0} using AutoMixed strategy
|
|||
ipquad.integrate(AutoMixed, q, [&](const uvector<real, N>& x, real w) { |
|||
if (bernstein::evalBernsteinPoly(phipoly, x) < 0) volume += w * integrand(xmin + x * (xmax - xmin)); |
|||
}); |
|||
// compute surface integral over {phi == 0} using AutoMixed strategy
|
|||
ipquad.integrate_surf(AutoMixed, q, [&](const uvector<real, N>& x, real w, const uvector<real, N>& wn) { |
|||
surf += w * integrand(xmin + x * (xmax - xmin)); |
|||
}); |
|||
// scale appropriately
|
|||
volume *= pow(xmax - xmin, N); |
|||
surf *= pow(xmax - xmin, N - 1); |
|||
}; |
|||
|
|||
// Compute results for all q and output in a convergence table
|
|||
for (int q = 1; q <= qMax; ++q) { |
|||
compute(q); |
|||
std::cout << q << ' ' << volume << ' ' << surf << ' ' << std::abs(volume - volume_exact) / volume_exact << ' ' |
|||
<< std::abs(surf - surf_exact) / surf_exact << std::endl; |
|||
} |
|||
} |
|||
|
|||
// Driver method which takes two phi functors defining two polynomials in the reference
|
|||
// rectangle [xmin, xmax]^N, each of of Bernstein degree P, builds a quadrature scheme with the
|
|||
// given q, and outputs it for visualisation in a set of VTP XML files
|
|||
template <int N, typename F1, typename F2, typename F> |
|||
void qConvMultiPloy(const F1& fphi1, |
|||
const F2& fphi2, |
|||
real xmin, |
|||
real xmax, |
|||
const uvector<int, N>& P, |
|||
const F& integrand, |
|||
int q, |
|||
std::string qfile) |
|||
{ |
|||
// Construct phi by mapping [0,1] onto bounding box [xmin,xmax]
|
|||
xarray<real, N> phi1(nullptr, P), phi2(nullptr, P); |
|||
algoim_spark_alloc(real, phi1, phi2); |
|||
bernstein::bernsteinInterpolate<N>([&](const uvector<real, N>& x) { return fphi1(xmin + x * (xmax - xmin)); }, phi1); |
|||
// bernstein::bernsteinInterpolate<N>([&](const uvector<real, N>& x) { return fphi2(xmin + x * (xmax - xmin)); }, phi2);
|
|||
|
|||
// Build quadrature hierarchy
|
|||
// ImplicitPolyQuadrature<N> ipquad(phi1, phi2);
|
|||
ImplicitPolyQuadrature<N> ipquad(phi1); |
|||
|
|||
// Functional to evaluate volume and surface integrals of given integrand
|
|||
real volume, surf; |
|||
auto compute = [&](int q) { |
|||
volume = 0.0; |
|||
surf = 0.0; |
|||
// compute volume integral over {phi < 0} using AutoMixed strategy
|
|||
ipquad.integrate(AutoMixed, q, [&](const uvector<real, N>& x, real w) { |
|||
// if (bernstein::evalBernsteinPoly(phi1, x) < 0 && bernstein::evalBernsteinPoly(phi2, x) < 0)
|
|||
if (bernstein::evalBernsteinPoly(phi1, x) < 0) volume += w * integrand(xmin + x * (xmax - xmin)); |
|||
}); |
|||
// compute surface integral over {phi == 0} using AutoMixed strategy
|
|||
ipquad.integrate_surf(AutoMixed, q, [&](const uvector<real, N>& x, real w, const uvector<real, N>& wn) { |
|||
surf += w * integrand(xmin + x * (xmax - xmin)); |
|||
}); |
|||
// scale appropriately
|
|||
volume *= pow(xmax - xmin, N); |
|||
surf *= pow(xmax - xmin, N - 1); |
|||
}; |
|||
compute(q); |
|||
std::cout << "q volume: " << volume << std::endl; |
|||
} |
|||
|
|||
void testMultiPloys() |
|||
{ |
|||
// Visusalisation of a 2D implicitly-defined domain involving the intersection of two polynomials; this example
|
|||
// corresponds to the top-left example of Figure 15, https://doi.org/10.1016/j.jcp.2021.110720
|
|||
if (true) { |
|||
auto phi0 = [](const uvector<real, 3>& xx) { |
|||
real x = xx(0); |
|||
real y = xx(1); |
|||
real z = xx(2); |
|||
return x * x + y * y + z * z - 1; |
|||
}; |
|||
auto phi1 = [](const uvector<real, 3>& xx) { |
|||
real x = xx(0); |
|||
real y = xx(1); |
|||
real z = xx(2); |
|||
return x * x + y * y + z * z - 1; |
|||
// real x = xx(0);
|
|||
// real y = xx(1);
|
|||
// real z = xx(2);
|
|||
// return x * y * z;
|
|||
}; |
|||
// auto phi0 = [](const uvector<real, 3>& xx) {
|
|||
// real x = xx(0) * 2 - 1;
|
|||
// real y = xx(1) * 2 - 1;
|
|||
// return 0.014836540349115947 + 0.7022484024095262 * y + 0.09974561176434385 * y * y
|
|||
// + x * (0.6863910464417281 + 0.03805619999999999 * y - 0.09440658332756446 * y * y)
|
|||
// + x * x * (0.19266932968830816 - 0.2325190091204104 * y + 0.2957473125000001 * y * y);
|
|||
// };
|
|||
// auto phi1 = [](const uvector<real, 3>& xx) {
|
|||
// real x = xx(0) * 2 - 1;
|
|||
// real y = xx(1) * 2 - 1;
|
|||
// return -0.18792528379702625 + 0.6713882473904913 * y + 0.3778666084723582 * y * y
|
|||
// + x * x * (-0.14480813208127946 + 0.0897755603159206 * y - 0.141199875 * y * y)
|
|||
// + x * (-0.6169311810674598 - 0.19449299999999994 * y - 0.005459163675646665 * y * y);
|
|||
// };
|
|||
auto integrand = [](const uvector<real, 3>& x) { return 1.0; }; |
|||
qConvMultiPloy<3>(phi0, phi1, -1.0, 1.0, 3, integrand, 3, "exampleC"); |
|||
std::cout << "\n\nQuadrature visualisation of a 2D implicitly-defined domain involving the\n"; |
|||
std::cout << "intersection of two polynomials, corresponding to the top-left example of Figure 15,\n"; |
|||
std::cout << "https://doi.org/10.1016/j.jcp.2021.110720, written to exampleC-xxxx.vtp files\n"; |
|||
std::cout << "(XML VTP file format).\n"; |
|||
} |
|||
} |
|||
|
|||
void testBitSet() |
|||
{ |
|||
std::bitset<10> set(128); |
|||
set.set(); |
|||
std::cout << set << std::endl; |
|||
} |
|||
|
|||
void testBooluarray() |
|||
{ |
|||
algoim::booluarray<2, 3> tmp; |
|||
tmp(0) = true; |
|||
tmp(1) = true; |
|||
tmp(2) = true; |
|||
std::cout << tmp.bits << std::endl; |
|||
} |
|||
|
|||
void testMain() |
|||
{ |
|||
testBooluarray(); |
|||
testMultiPloys(); |
|||
} |
Loading…
Reference in new issue