From 8c8ad84b6e854a16bd1d6f85ea9986d3dea1d67f Mon Sep 17 00:00:00 2001 From: davide baroli Date: Sat, 18 Nov 2017 19:46:34 +0100 Subject: [PATCH 1/2] assert on dim of Lines; assert of ringNodes; bug fix on NormFunction if it is modify the type from user or the NormFunction itself --- +mgen/MgGeoArea4LineEllipsoidalVoid.m | 45 ++++++++++++++++++++------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/+mgen/MgGeoArea4LineEllipsoidalVoid.m b/+mgen/MgGeoArea4LineEllipsoidalVoid.m index 5074d41..09c797a 100644 --- a/+mgen/MgGeoArea4LineEllipsoidalVoid.m +++ b/+mgen/MgGeoArea4LineEllipsoidalVoid.m @@ -59,11 +59,22 @@ classdef MgGeoArea4LineEllipsoidalVoid < mgen.MgGeoArea4Line %fig = figure(1); subplot('Position',[0.05 0.05 0.90 0.90]); axis equal; hold on; gnv = gridnodes; - + for kk = 1:4 + if self.geoLines(kk).getNumTargetGridNodes() - 1 ==0 + warning('increase the number of nodes in the %d line',kk) + + end + end dim0 = self.geoLines(1).getNumTargetGridNodes() - 1; + + assert(dim0>0); dim1 = self.geoLines(2).getNumTargetGridNodes() - 1; + assert(dim1>0); + dim2 = self.geoLines(3).getNumTargetGridNodes() - 1; + assert(dim2>0); dim3 = self.geoLines(4).getNumTargetGridNodes() - 1; + assert(dim3>0); dim = self.nrings*(dim0 + dim1 + dim2 + dim3); segments = self.nrings - 1; run_id = 1 + length(gridnodes); @@ -95,18 +106,28 @@ classdef MgGeoArea4LineEllipsoidalVoid < mgen.MgGeoArea4Line % create grid nodes for mm = segments:-1:1 % loop over segments from outer to inner - % set function values - self.normFunction.vals(1) = segments; - if self.normFunction.vals(2) == 0 + % set function values if the normFunction is not set by + % user + if self.normFunction.vals == [0,0] self.normFunction.vals(1) = segments; + if self.normFunction.vals(2) == 0 + self.normFunction.vals(1) = segments; + end + if self.normFunction.vals(1) == 1 + self.normFunction.vals(2) = segments; + end end - if self.normFunction.vals(1) == 1 - self.normFunction.vals(2) = segments; + % some bugs occurs if user sets the type of normFunction. + if self.normFunction.vals(1)>self.normFunction.vals(2) + self.normFunction.vals=sort(self.normFunction.vals) end - + scale = self.normFunction.eval( mm/segments ); - - for gline = self.geoLines % loop over the four GeoLines + if isnan(scale) + warning('normFunction can not eval %d/%d',mm,segments) + end + + for gline = self.geoLines % loop over the four GeoLines for ii = 1:gline.getNumTargetGridNodes - 1 % loop over GridNodes - 1 @@ -135,10 +156,12 @@ classdef MgGeoArea4LineEllipsoidalVoid < mgen.MgGeoArea4Line end end end - + % defensive programming: check if ringNodes is filled. + assert(~isempty(self.ringNodes)) + % make sure the ring nodes represent a closed line in terms of node connectivity self.ringNodes(end+1) = self.ringNodes(1); - + % sort in existing nodes for gline = self.geoLines for ii = 1:gline.getNumTargetGridNodes - 1 -- GitLab From 7b376dec12e9d5fc684ecf746cca73e0a7d403e2 Mon Sep 17 00:00:00 2001 From: davide baroli Date: Sat, 18 Nov 2017 19:50:48 +0100 Subject: [PATCH 2/2] example of use Mesh with Hole circular with custom FunctionNorm type; number of nodes for lines and number of nodes in inner rings are very important for good representation of circle and mesh refinement --- extra/circleGeom/MeshHole.m | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 extra/circleGeom/MeshHole.m diff --git a/extra/circleGeom/MeshHole.m b/extra/circleGeom/MeshHole.m new file mode 100644 index 0000000..2a71e87 --- /dev/null +++ b/extra/circleGeom/MeshHole.m @@ -0,0 +1,33 @@ +%% Describe the goemetry of the problem for the mesh generator +% helfpul parameters (problem specific) +n = 10;% should be >1! % d: length measure; n = number of grid nodes per d +% create all geo points + +gp1 = mgen.MgGeoPoint( [-1, -1] ); +gp2 = mgen.MgGeoPoint( [1, -1] ); +gp3 = mgen.MgGeoPoint( [1, 1] ); +gp4 = mgen.MgGeoPoint( [-1, 1] ); +gcenter = mgen.MgGeoPoint([0.,0.]); +gl1 = mgen.MgGeoLine2Point( [gp1, gp2], n ); +gl2 = mgen.MgGeoLine2Point( [gp2, gp3], n ); +gl3 = mgen.MgGeoLine2Point( [gp3, gp4], n ); +gl4 = mgen.MgGeoLine2Point( [gp4, gp1], n ); + +%number of ring => refine near the circle +a= 0.5% +b= 0.5% +c=0; %ellipse rotation angle in rad +normFunc = mgen.MgNormFunction( mgen.MgNormFunctionType.Quadratic); + +ga1 = mgen.MgGeoArea4LineEllipsoidalVoid([gl1,gl2,gl3,gl4],20,a,b,c,normFunc) + +% create geo object and generate the mesh +geo = mgen.MgGeo( [gp1, gp2, gp3, gp4], ... + [gl1, gl2, gl3, gl4], ... + [ga1] ); +% print geo and mesh data info +fprintf(geo.print()); +% plot mesh +cla; clf; +fig = figure(1); subplot('Position',[0.05 0.05 0.90 0.90]); axis equal; hold on; +geo.plot(); \ No newline at end of file -- GitLab