Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding STL support and changing volume check to relative test #1266

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions proteus/SpatialTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,37 @@ def __init__(self, domain, filename):
self.BC[key] = self.BC_class(shape=self, name=key)
self.BC_list += [self.BC[key]]
# self.BC = BCContainer(self.BC_dict)

def reloadBCList(self):
"""
Allows for easier addition/modification of shape BC's from the input file directly.
Calls to this function should be made after adding a new entry to boundaryTags dict,
and before assignment of boundary conditions.

ex:
tank.boundaryTags["top"]=2 #<-new BC flag
tank.reloadBCList()
"""
self.BC={}
self.BC_list=[]
for key,value in self.boundaryTags.items():
self.BC[key] = self.BC_class(shape=self, name=key)
self.BC_list += [self.BC[key]]

def assignFacetFlagsFromSTL(self,flag,boundary_stl):
"""
Add flags to ShapeSTL facets using a separate STL surface containing only the boundary facets.

ex:
tank.assignFacetFlagsFromSTL(boundaryTags["inflow"],"inflow.stl")
"""

boundary_stl_info=getInfoFromSTL(boundary_stl)
for i in range(len(self.facets)):
if ((self.vertices[self.facets[i][0][0]].tolist() in boundary_stl_info[0].tolist()) and
(self.vertices[self.facets[i][0][1]].tolist() in boundary_stl_info[0].tolist()) and
(self.vertices[self.facets[i][0][2]].tolist() in boundary_stl_info[0].tolist())):
self.facetFlags[i]=flag

def getInfoFromSTL(filename):
"""
Expand Down
6 changes: 2 additions & 4 deletions proteus/mprans/VOF.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from builtins import range
from past.utils import old_div
import numpy as np
from math import fabs
from math import fabs, isclose
import proteus
from proteus import cfemIntegrals, Quadrature, Norms, Comm
from proteus.NonlinearSolvers import NonlinearEquation
Expand Down Expand Up @@ -1082,9 +1082,7 @@ def getMassMatrix(self):
self.ML = np.zeros((self.nFreeDOF_global[0],), 'd')
for i in range(self.nFreeDOF_global[0]):
self.ML[i] = self.MC_a[self.rowptr[i]:self.rowptr[i + 1]].sum()
np.testing.assert_almost_equal(self.ML.sum(),
self.mesh.volume,
err_msg="Trace of lumped mass matrix should be the domain volume", verbose=True)
assert isclose(self.ML.sum(),self.mesh.volume,rel_tol=1e-7), "Trace of lumped mass matrix should be the domain volume"+": "+str(self.ML.sum())+" =/= "+str(self.mesh.volume)

def initVectors(self):
if self.coefficients.porosity_dof is None:
Expand Down