Changeset 22299


Ignore:
Timestamp:
12/22/17 08:13:13 (7 years ago)
Author:
bdef
Message:

NEW: implemeting domain orientation in python bamg (holes and subdomain too)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/mesh/bamg.py

    r22271 r22299  
    2222
    2323           - domain :            followed by an ARGUS file that prescribes the domain outline
     24           - holes :             followed by an ARGUS file that prescribes the holes
     25     - subdomains :        followed by an ARGUS file that prescribes the list of
     26                                 subdomains (that need to be inside domain)
     27
    2428           - hmin :              minimum edge length (default is 10^-100)
    2529           - hmax :              maximum edge length (default is 10^100)
     
    7478        bamg_mesh=bamgmesh()
    7579
    76         subdomain_ref = 1
    77         hole_ref = 1
     80        subdomain_ref = 1
     81        hole_ref = 1
    7882
    7983        # Bamg Geometry parameters {{{
    8084        if options.exist('domain'):
    81 
    8285                #Check that file exists
    8386                domainfile=options.getfieldvalue('domain')
     
    9295                count=0
    9396                for i,domaini in enumerate(domain):
    94 
    9597                        #Check that the domain is closed
    9698                        if (domaini['x'][0]!=domaini['x'][-1] or domaini['y'][0]!=domaini['y'][-1]):
    9799                                raise RuntimeError("bamg error message: all contours provided in ''domain'' should be closed")
    98100
    99                         #Checks that all holes are INSIDE the principle domain outline
     101                        #Checks that all holes are INSIDE the principle domain outline princial domain should be index 0
    100102                        if i:
    101103                                flags=ContourToNodes(domaini['x'],domaini['y'],domainfile,0)[0]
     
    103105                                        raise RuntimeError("bamg error message: All holes should be strictly inside the principal domain")
    104106
     107                        #Check orientation
     108                        nods=domaini['nods']-1#the domain are closed 1=end;
     109
     110                        test = np.sum((domaini['x'][1:nods+1] - domaini['x'][0:nods])*(domaini['y'][1:nods+1] + domaini['y'][0:nods]))
     111                        if (i==0 and test>0) or (i>0 and test<0):
     112                                print('At least one contour was not correctly oriented and has been re-oriented')
     113                                domaini['x'] = np.flipud(domaini['x'])
     114                                domaini['y'] = np.flipud(domaini['y'])
     115
     116
    105117                        #Add all points to bamg_geometry
    106118                        nods=domaini['nods']-1    #the domain are closed 0=end
    107119                        bamg_geometry.Vertices=np.vstack((bamg_geometry.Vertices,np.vstack((domaini['x'][0:nods],domaini['y'][0:nods],np.ones((nods)))).T))
    108120                        bamg_geometry.Edges   =np.vstack((bamg_geometry.Edges,np.vstack((np.arange(count+1,count+nods+1),np.hstack((np.arange(count+2,count+nods+1),count+1)),1.*np.ones((nods)))).T))
    109                         if i:
    110                             bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,-subdomain_ref]))
    111                             subdomain_ref = subdomain_ref+1;
    112                         else:
    113                             bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,0]))
    114 
    115                         # bamg_geometry.Vertices=np.hstack((bamg_geometry.Vertices,np.vstack((domaini['x'][0:nods].reshape(-1),domaini['y'][0:nods].reshape(-1),np.ones((nods))))))
    116                         # bamg_geometry.Edges   =np.vstack((bamg_geometry.Edges,np.hstack((np.arange(count+1,count+nods+1).reshape(-1,),np.hstack((np.arange(count+2,count+nods+1),count+1)).reshape(-1,),1.*np.ones((nods,))))))
    117                         # if i:
    118                         #       bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,1]))
    119 
     121                        if i:
     122                                bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,-subdomain_ref]))
     123                                subdomain_ref = subdomain_ref+1;
     124                        else:
     125                                bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,0]))
     126                       
    120127                        #update counter
    121128                        count+=nods
    122129
     130                #Deal with domain holes
     131                if options.exist('holes'):
     132                        holesfile=options.getfieldvalue('holes')
     133                        if type(holesfile) == str:
     134                                if not os.path.exists(holesfile):
     135                                        raise IOError("bamg error message: file '%s' not found" % holesfile)
     136                                holes=expread(holesfile)
     137                        else:
     138                                holes=holesfile
     139
     140                        #Build geometry
     141                        for i,holei in enumerate(holes):
     142                                #Check that the hole is closed
     143                                if (holei['x'][0]!=holei['x'][-1] or holei['y'][0]!=holei['y'][-1]):
     144                                        raise RuntimeError("bamg error message: all contours provided in ''hole'' should be closed")
     145
     146                                #Checks that all holes are INSIDE the principle domain outline princial domain should be index 0
     147                                flags=ContourToNodes(holei['x'],holei['y'],domainfile,0)[0]
     148                                if np.any(np.logical_not(flags)):
     149                                        raise RuntimeError("bamg error message: All holes should be strictly inside the principal domain")
     150
     151                                #Check orientation
     152                                nods=holei['nods']-1#the hole are closed 1=end;
     153                                test = np.sum((holei['x'][1:nods+1] - holei['x'][0:nods])*(holei['y'][1:nods+1] + holei['y'][0:nods]))
     154                                if test<0:
     155                                        print('At least one hole was not correctly oriented and has been re-oriented')
     156                                        holei['x'] = np.flipud(holei['x'])
     157                                        holei['y'] = np.flipud(holei['y'])
     158
     159                                #Add all points to bamg_geometry
     160                                nods=holei['nods']-1    #the hole are closed 0=end
     161                                bamg_geometry.Vertices=np.vstack((bamg_geometry.Vertices,np.vstack((holei['x'][0:nods],holei['y'][0:nods],np.ones((nods)))).T))
     162                                bamg_geometry.Edges   =np.vstack((bamg_geometry.Edges,np.vstack((np.arange(count+1,count+nods+1),np.hstack((np.arange(count+2,count+nods+1),count+1)),1.*np.ones((nods)))).T))
     163                                #update counter
     164                                count+=nods
     165
     166                #And subdomains
     167                if options.exist('subdomains'):
     168                        subdomainfile=options.getfieldvalue('subdomains')
     169                        if type(subdomainfile) == str:
     170                                if not os.path.exists(subdomainfile):
     171                                        raise IOError("bamg error message: file '%s' not found" % subdomainfile)
     172                                subdomains=expread(subdomainfile)
     173                        else:
     174                                subdomains=subdomainfile
     175
     176                        #Build geometry
     177                        for i,subdomaini in enumerate(subdomains):
     178                                #Check that the subdomain is closed
     179                                if (subdomaini['x'][0]!=subdomaini['x'][-1] or subdomaini['y'][0]!=subdomaini['y'][-1]):
     180                                        raise RuntimeError("bamg error message: all contours provided in ''subdomain'' should be closed")
     181
     182                                #Checks that all subdomains are INSIDE the principle subdomain outline princial domain should be index 0
     183                                if i:
     184                                        flags=ContourToNodes(subdomaini['x'],subdomaini['y'],domainfile,0)[0]
     185                                        if np.any(np.logical_not(flags)):
     186                                                raise RuntimeError("bamg error message: All subdomains should be strictly inside the principal subdomain")
     187
     188                                #Check orientation
     189                                nods=subdomaini['nods']-1#the subdomain are closed 1=end;
     190
     191                                test = np.sum((subdomaini['x'][1:nods+1] - subdomaini['x'][0:nods])*(subdomaini['y'][1:nods+1] + subdomaini['y'][0:nods]))
     192                                if test>0:
     193                                        print('At least one subcontour was not correctly oriented and has been re-oriented')
     194                                        subdomaini['x'] = np.flipud(subdomaini['x'])
     195                                        subdomaini['y'] = np.flipud(subdomaini['y'])
     196
     197                                #Add all points to bamg_geometry
     198                                nods=subdomaini['nods']-1    #the subdomain are closed 0=end
     199                                bamg_geometry.Vertices=np.vstack((bamg_geometry.Vertices,np.vstack((subdomaini['x'][0:nods],subdomaini['y'][0:nods],np.ones((nods)))).T))
     200                                bamg_geometry.Edges   =np.vstack((bamg_geometry.Edges,np.vstack((np.arange(count+1,count+nods+1),np.hstack((np.arange(count+2,count+nods+1),count+1)),1.*np.ones((nods)))).T))
     201                                #update counter
     202                                count+=nods
     203                       
    123204                if options.getfieldvalue('vertical',0):
    124205                        if np.size(options.getfieldvalue('Markers',[]))!=np.size(bamg_geometry.Edges,0):
Note: See TracChangeset for help on using the changeset viewer.