Skip to content

Commit 9ee9847

Browse files
Some code refactoring to better manage Tetra (#72)
1 parent b22c417 commit 9ee9847

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1162
-598
lines changed

Code/boundaries/Boundaries.m

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
properties (Access = private)
1010
grid
11+
bcList
12+
% to ensure neumann is applied before dirichlet in case of overlapping
13+
% entity definition
1114
end
1215

1316
methods (Access = public)
@@ -254,6 +257,13 @@ function removeBCentities(obj,bcId,list)
254257
obj.db(bcId) = bc;
255258

256259
end
260+
261+
262+
function bcList = getBCList(obj)
263+
264+
bcList = obj.bcList;
265+
266+
end
257267
end
258268

259269

@@ -276,7 +286,9 @@ function readInputFile(obj,inputStruct)
276286
inputStruct = readstruct(inputStruct.fileName,AttributeSuffix="");
277287
end
278288

279-
for i = 1:numel(inputStruct.BC)
289+
nBC = numel(inputStruct.BC);
290+
291+
for i = 1:nBC
280292
% process each BC
281293
in = inputStruct.BC(i);
282294

@@ -334,6 +346,16 @@ function readInputFile(obj,inputStruct)
334346
obj.db(name) = bc;
335347
end
336348

349+
% set correct order of boundary conditions. Dirichlet last
350+
bcTypeList = [];
351+
for bcId = string(obj.db.keys)
352+
bcTypeList = [bcTypeList, obj.getType(bcId)];
353+
end
354+
idxDir = strcmp(bcTypeList, 'Dirichlet');
355+
bcOrd = [find(~idxDir), find(idxDir)];
356+
bcNames = obj.db.keys;
357+
obj.bcList = string(bcNames(bcOrd));
358+
337359
end
338360

339361
end

Code/boundaries/linkBoundSurf2TPFAFace.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function linkBoundSurf2TPFAFace(solver)
22
% TO DO: call this from within the SinglePhaseFlow solver!
33

4-
bcs = solver.bcs;
4+
bcs = solver.domain.bcs;
55

66
keys = bcs.db.keys;
77
flRenum = false(length(keys),1);

Code/discretizer/Discretizer.m

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef Discretizer < handle
22
% General discretizer class
33

4-
properties (GetAccess=public, SetAccess=private)
4+
properties (GetAccess=public, SetAccess=public)
55
physicsSolvers % physics solvers database
66
solverNames
77
dofm
@@ -52,9 +52,9 @@
5252
end
5353

5454
function applyBC(obj,t)
55-
bcList = obj.bcs.db.keys;
55+
bcList = obj.bcs.getBCList();
5656

57-
for bcId = string(bcList)
57+
for bcId = bcList
5858
% loop over available bcs
5959
bcVar = obj.bcs.getVariable(bcId);
6060

@@ -74,9 +74,9 @@ function applyBC(obj,t)
7474

7575

7676
function applyDirVal(obj,t)
77-
bcList = obj.bcs.db.keys;
77+
bcList = obj.bcs.getBCList;
7878

79-
for bcId = string(bcList)
79+
for bcId = bcList
8080
% discard non-Dirichlet BC
8181
if ~strcmp(obj.bcs.getType(bcId),"Dirichlet")
8282
continue
@@ -458,12 +458,20 @@ function setInput(obj, varargin)
458458
case 'grid'
459459
obj.grid = value;
460460
% check that grid has been defined correctly
461-
isGridCorrect = all([isfield(obj.grid,"topology");...
462-
isfield(obj.grid,"cells");...
463-
isfield(obj.grid,"faces")]);
461+
if ~isfield(obj.grid,"topology")
462+
obj.grid.topology = [];
463+
end
464+
if ~isfield(obj.grid,"cells")
465+
obj.grid.cells = [];
466+
end
467+
if ~isfield(obj.grid,"faces")
468+
obj.grid.faces = [];
469+
end
470+
471+
isGridCorrect = numel(fieldnames(obj.grid))==3;
464472

465473
assert(isGridCorrect,"Error in Discretizer: grid input is not correct. " + ...
466-
"See the default value of the grid property in Discretizer.");
474+
"grid must be a struct with fields: 'topology','cells','faces'.");
467475

468476
case 'materials'
469477
assert(isa(value, 'Materials'),msg)

Code/discretizer/PhysicsSolver.m

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,21 @@
3333
properties (GetAccess=public, SetAccess=protected)
3434
% handle to domain properties
3535
domain
36-
dofm
36+
simparams
3737
mesh
3838
elements
3939
faces
40-
bcs
41-
materials
42-
simparams
4340
end
4441

4542
methods
4643
function obj = PhysicsSolver(domain)
4744

4845
% inputStruct: struct with additional solver-specific parameters
4946
obj.domain = domain;
50-
obj.dofm = domain.dofm;
47+
obj.simparams = domain.simparams;
5148
obj.mesh = domain.grid.topology;
52-
obj.elements = domain.grid.cells;
5349
obj.faces = domain.grid.faces;
54-
obj.materials = domain.materials;
55-
obj.bcs = domain.bcs;
56-
obj.simparams = domain.simparams;
50+
obj.elements = domain.grid.cells;
5751

5852
end
5953
end
@@ -165,8 +159,8 @@ function applyNeuBC(obj,bcId,bcDofs,bcVals)
165159

166160
% Base application of Neumann boundary condition to the rhs.
167161
% bc values are subtracted since we solve du = J\(-rhs)
168-
bcVar = obj.bcs.getVariable(bcId);
169-
bcId = obj.dofm.getVariableId(bcVar);
162+
bcVar = obj.domain.bcs.getVariable(bcId);
163+
bcId = obj.domain.dofm.getVariableId(bcVar);
170164

171165
% remove inactive dofs
172166
id = bcDofs == 0;
@@ -197,10 +191,10 @@ function applyDirBC(obj,bcId,bcDofs,bcVals)
197191
% sort bcDofs to improve sparse access performance
198192
[bcDofs,sortId] = sort(bcDofs);
199193

200-
bcVar = obj.bcs.getVariable(bcId);
201-
bcVarId = obj.dofm.getVariableId(bcVar);
194+
bcVar = obj.domain.bcs.getVariable(bcId);
195+
bcVarId = obj.domain.dofm.getVariableId(bcVar);
202196

203-
nV = getNumberOfVariables(obj.dofm);
197+
nV = getNumberOfVariables(obj.domain.dofm);
204198

205199
% zero out rows (use transpose trick)
206200
for j = 1:nV
@@ -265,7 +259,7 @@ function applyDirBC(obj,bcId,bcDofs,bcVals)
265259

266260
function out = BCapplies(obj,bcId)
267261

268-
bcVar = obj.bcs.getVariable(bcId);
262+
bcVar = obj.domain.bcs.getVariable(bcId);
269263
out = any(strcmp(obj.getField(),bcVar));
270264

271265
end

Code/discretizer/PhysicsSolvers/Coupling/BiotFullySaturated.m

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030

3131
function registerSolver(obj,input)
3232

33+
dofm = obj.domain.dofm;
34+
3335
% Register mechanics
3436
obj.mechSolver = Poromechanics(obj.domain);
3537
registerSolver(obj.mechSolver,input.(class(obj.mechSolver)));
36-
obj.fldMech = obj.dofm.getVariableId(obj.mechSolver.getField());
38+
obj.fldMech = dofm.getVariableId(obj.mechSolver.getField());
3739

3840
% setup the solver with custom input
3941
if isfield(input,"SinglePhaseFlowFEM")
@@ -46,7 +48,7 @@ function registerSolver(obj,input)
4648
% Register fluids
4749
obj.flowScheme = obj.flowSolver.typeDiscretization();
4850
registerSolver(obj.flowSolver,input.(class(obj.flowSolver)));
49-
obj.fldFlow = obj.dofm.getVariableId(obj.flowSolver.getField());
51+
obj.fldFlow = dofm.getVariableId(obj.flowSolver.getField());
5052

5153
end
5254

@@ -85,8 +87,10 @@ function computeMatBiot(obj)
8587
% compute coupling matrix only where mechanics and flow are
8688
% active
8789

88-
cellTagFlow = obj.dofm.getTargetRegions(obj.fldFlow);
89-
cellTagMech = obj.dofm.getTargetRegions(obj.fldMech);
90+
dofm = obj.domain.dofm;
91+
92+
cellTagFlow = dofm.getTargetRegions(obj.fldFlow);
93+
cellTagMech = dofm.getTargetRegions(obj.fldMech);
9094

9195
% find cell tag where both flow and mechanics are active
9296
cellTags = intersect(cellTagMech,cellTagFlow);
@@ -103,14 +107,14 @@ function computeMatBiot(obj)
103107
end
104108

105109
[iiVec,jjVec,Qvec] = deal(zeros(nEntries,1));
106-
nDoF1 = obj.dofm.getNumbDoF(obj.fldMech);
107-
nDoF2 = obj.dofm.getNumbDoF(obj.fldFlow);
110+
nDoF1 = dofm.getNumbDoF(obj.fldMech);
111+
nDoF2 = dofm.getNumbDoF(obj.fldFlow);
108112
% consider replacing the string field with an integer
109113

110114
l1 = 0;
111115
for el=subCells'
112-
113-
biot = obj.materials.getMaterial(obj.mesh.cellTag(el)).PorousRock.getBiotCoefficient();
116+
mat = obj.domain.materials.getMaterial(obj.mesh.cellTag(el));
117+
biot = mat.PorousRock.getBiotCoefficient();
114118
elem = getElement(obj.elements,obj.mesh.cellVTKType(el));
115119
nG = elem.GaussPts.nNode;
116120
nodes = obj.mesh.cells(el,1:obj.mesh.cellNumVerts(el));
@@ -121,7 +125,7 @@ function computeMatBiot(obj)
121125
B = zeros(6,elem.nNode*obj.mesh.nDim,nG);
122126
B(elem.indB(:,2)) = N(elem.indB(:,1));
123127
Nref = getBasisFinGPoints(elem);
124-
dofrow = getLocalDoF(obj.dofm,obj.fldMech,nodes);
128+
dofrow = getLocalDoF(dofm,obj.fldMech,nodes);
125129

126130
% kronecker delta in tensor form
127131
kron = [1;1;1;0;0;0];
@@ -130,10 +134,10 @@ function computeMatBiot(obj)
130134
Np = reshape(Nref',1,elem.nNode,nG);
131135
kron = repmat(kron,1,1,nG);
132136
iN = pagemtimes(kron,Np);
133-
dofcol = getLocalDoF(obj.dofm,obj.fldFlow,nodes);
137+
dofcol = getLocalDoF(dofm,obj.fldFlow,nodes);
134138
case "FVTPFA"
135139
iN = repmat(kron,1,1,nG);
136-
dofcol = getLocalDoF(obj.dofm,obj.fldFlow,el);
140+
dofcol = getLocalDoF(dofm,obj.fldFlow,el);
137141
end
138142

139143
% compute local coupling matrix
@@ -163,8 +167,8 @@ function computeMatBiot(obj)
163167
uOld = getStateOld(obj,"displacements");
164168

165169
% select active coefficients of solution vectors
166-
entsPoro = obj.dofm.getActiveEntities(obj.fldMech,1);
167-
entsFlow = obj.dofm.getActiveEntities(obj.fldFlow,1);
170+
entsPoro = obj.domain.dofm.getActiveEntities(obj.fldMech,1);
171+
entsFlow = obj.domain.dofm.getActiveEntities(obj.fldFlow,1);
168172

169173
% get coupling blocks
170174
Qmech = getJacobian(obj,obj.fldMech,obj.fldFlow);

Code/discretizer/PhysicsSolvers/Flow/SinglePhaseFlow.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ function assembleSystem(obj,dt)
3535
end
3636

3737
function updateState(obj,dSol)
38+
dofm = obj.domain.dofm;
3839
if nargin > 1
39-
ents = obj.dofm.getActiveEntities(obj.fieldId);
40+
ents = dofm.getActiveEntities(obj.fieldId);
4041
state = getState(obj);
41-
state.data.pressure(ents) = state.data.pressure(ents) + dSol(obj.dofm.getDoF(obj.fieldId));
42+
state.data.pressure(ents) = state.data.pressure(ents) + dSol(dofm.getDoF(obj.fieldId));
4243
end
4344
end
4445

@@ -73,12 +74,14 @@ function writeMatFile(obj,fac,tID)
7374
end
7475

7576
function alpha = getRockCompressibility(obj,el)
76-
if ismember(obj.mesh.cellTag(el),getTargetRegions(obj.dofm,["pressure","displacements"]))
77+
mat = obj.domain.materials;
78+
targetRegions = getTargetRegions(obj.domain.dofm,["pressure","displacements"]);
79+
if ismember(obj.mesh.cellTag(el),targetRegions)
7780
alpha = 0; %this term is not needed in a coupled formulation
7881
else
79-
if isfield(obj.materials.getMaterial(obj.mesh.cellTag(el)),"ConstLaw")
82+
if isfield(mat.getMaterial(obj.mesh.cellTag(el)),"ConstLaw")
8083
%solid skeleton contribution to storage term as oedometric compressibility .
81-
alpha = obj.materials.getMaterial(obj.mesh.cellTag(el)).ConstLaw.getRockCompressibility();
84+
alpha = mat.getMaterial(obj.mesh.cellTag(el)).ConstLaw.getRockCompressibility();
8285
else
8386
alpha = 0;
8487
end
@@ -89,7 +92,7 @@ function writeMatFile(obj,fac,tID)
8992
% printPermeab - print the permeability for the cell or element.
9093
perm = zeros(obj.mesh.nCells,6);
9194
for el=1:obj.mesh.nCells
92-
ktmp = obj.materials.getMaterial(obj.mesh.cellTag(el)).PorousRock.getPermMatrix();
95+
ktmp = obj.domain.materials.getMaterial(obj.mesh.cellTag(el)).PorousRock.getPermMatrix();
9396
perm(el,1)=ktmp(1,1);
9497
perm(el,2)=ktmp(2,2);
9598
perm(el,3)=ktmp(3,3);

0 commit comments

Comments
 (0)