Utilities

Book keeping

Needs["ComputationalGeometry`"]

A Saved Mesh

SetDirectory["/home/campus03/struther/Desktop/Link to Courses/4620/SampleGrids"];
DataEle=Take[Import["QuarterCircleThree.1.ele","TABLE"],{2,-2}];
DataNode=Take[Import["QuarterCircleThree.1.node","TABLE"],{2,-2}];
BoundaryNodes=Flatten[Position[DataNode,{n_,x_,y_,1}]]
Nodes=DataNode[[All,{2,3}]];
Elements=DataEle[[All,{2,3,4}]];

I saved the nodes and elements and boundary nodes so that I do not need to carry around the data files.  They are in the hidden initialization cell below.

BoundaryNodes={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,25,28,30,63,66,121,131,141,170,176,191,193,194,204,220,231,244,258,259,265,270,272,284,287,290,291,293};
Nodes={{0,0},{3,0},{2.988584094275237`,0.2614672282429745`},{2.954423259036624`,0.520944533000791`},{2.897777478867205`,0.7764571353075622`},{2.8190778623577253`,1.0260604299770062`},{2.7189233611099497`,1.2678547852220983`},{2.598076211353316`,1.4999999999999998`},{2.4574561328669753`,1.7207293090531381`},{2.298133329356934`,1.9283628290596178`},{2.121320343559643`,2.1213203435596424`},{1.9283628290596182`,2.298133329356934`},{1.7207293090531386`,2.4574561328669753`},{1.5000000000000004`,2.598076211353316`},{1.2678547852220983`,2.7189233611099497`},{1.0260604299770064`,2.819077862357725`},{0.7764571353075622`,2.897777478867205`},{0.5209445330007912`,2.954423259036624`},{0.2614672282429751`,2.988584094275237`},{0,3},{1.5`,0},{1.9587802641631815`,1.7948914191028067`},{1.6899265255855487`,1.5485323571929912`},{1.3602970809686032`,2.1352387085914395`},{0,1.5`},{1.4952151993065323`,2.3470177330383173`},{0.9836535267275764`,2.37474968490184`},{0,2},{2.121564210141363`,1.1044164234294347`},{2,0},{2.102799630688276`,1.9268608543119918`},{1.8753920856275104`,2.046631325883333`},{2.1965444366470206`,1.6799868535298081`},{1.9622166753664985`,1.9357107314517734`},{1.7641243979423582`,1.8700931882992557`},{2.2012707363996573`,1.8230172917070153`},{1.806756646161333`,1.6909153696096109`},{1.6170202648417462`,2.086143065301593`},{1.9941527584634104`,1.4180274078681765`},{1.7376047664177177`,2.0101415913728506`},{1.9761116442911708`,1.6064261056308191`},{1.8488591727939052`,1.499177211840397`},{1.6364370533819173`,1.0957126640048718`},{1.8113062786790528`,1.2612967481298722`},{2.125550129433852`,1.5256732184394262`},{2.1888184507275064`,1.314427320630976`},{2.064186803569169`,1.709555107285475`},{1.5783960775719352`,1.3321378501453216`},{1.880562175339031`,1.0130277635279288`},{1.9926682792622232`,1.2347369419983591`},{1.887448986352978`,1.1487430092105495`},{2.4387145347276253`,1.1186259274036305`},{2.3600734166862427`,1.4808157309346421`},{1.6746928836653616`,1.2304411927091283`},{1.7243890493611533`,1.3938314226343378`},{1.2045258814956086`,1.661770626863066`},{2.2775080616341588`,1.1702509576755933`},{2.4084702931754003`,1.3016915410623484`},{2.5579844121954247`,1.2323616153549053`},{2.6223530175340835`,1.045456420979251`},{2.6140452531463088`,1.3607858274391669`},{2.484876160652442`,1.4184355267400977`},{2.7690006117338375`,1.1469576075995522`},{2.3334254526517366`,0.5873450194532792`},{2.7026106714111244`,0.8521298715073439`},{2.858427670612465`,0.9012587826422843`},{2.7181096625677235`,0.602590404669467`},{2.7678721039513348`,0.7309322263583169`},{2.4722561744881983`,1.5750008858641316`},{2.2311354940253882`,1.4421987163441845`},{1.4329675214122257`,1.5440310465360465`},{1.0133336727697237`,1.0680814433611925`},{1.5626573726705562`,1.4771884662367503`},{1.3221362869097821`,1.1438906468980565`},{1.489268510312477`,1.1849206128417935`},{1.3798733002331347`,1.3517383612010536`},{1.2597266780553`,1.4883885299998938`},{0.8420247211992707`,1.4508803839230853`},{1.046708040672023`,1.5160467562406048`},{0.8103352134543897`,1.9303564203928596`},{1.0047029531092084`,1.2939503374299226`},{1.1943084829487458`,1.3097278293774903`},{1.091964369619064`,1.3924670086606463`},{1.1092410090867175`,1.1848455190730005`},{0.8773366905503804`,1.693999449913208`},{0.9657368187024862`,1.4163404207466384`},{0.9187708921815879`,1.5638573286323703`},{1.0411749512616286`,1.6803587443675991`},{1.1535554746531562`,1.9408983484814675`},{1.1367963445689317`,1.793620417378293`},{1.3884591498839478`,1.8395755647196084`},{0.9834801061149536`,1.8856591593564367`},{0.9980636489533615`,2.130199281875039`},{1.0387044681603292`,2.005070683613494`},{0.4177931288750378`,1.6914051125967569`},{1.1793490192064`,2.1205961468261556`},{1.095765361368782`,2.258656110611888`},{1.2078328591960699`,2.47906007069823`},{0.6867406368586797`,2.2345543459015977`},{0.6472050927675381`,1.7564378485177519`},{1.0916868295724536`,2.6355651498179022`},{0.8346374841988878`,2.6471319067427017`},{1.064504175590899`,2.4940424116871722`},{0.9655286876395639`,2.6939402084763633`},{1.2782411301448802`,2.304566864759379`},{1.3998092838985237`,2.2589323318078356`},{1.3642425958674764`,2.4407201100457696`},{1.3488941491610034`,2.5912015517142644`},{0.8633809053263214`,2.244962866301113`},{0.7817407332756123`,2.441239642706043`},{0.78349299720723`,2.096657509354214`},{0.5110438054901298`,2.0083899007778134`},{0.6667172885044242`,1.9924922431193224`},{0.781034160549201`,1.7943751481943986`},{0.5938414645669657`,1.5075278498221028`},{0.9139001931449682`,2.5170270423265935`},{0.5031941522833039`,2.62254346494593`},{0.49973293744961783`,1.8395086856160876`},{0.25656571867783584`,1.9406142620540594`},{0.3953049531815314`,1.931322161852091`},{0,2.5`},{0.7430795986257481`,1.58937571217845`},{0.5545521460612998`,1.646126350880597`},{0.6730655343622503`,2.578901008397768`},{0.6971474311697233`,2.747292697313436`},{0.53683002740905`,2.4010457904103166`},{0.637359759992975`,2.87494408929232`},{0.4936645394253169`,2.7894677312416634`},{0.38085197432054063`,2.8928579502847387`},{0.3396259350886788`,2.140380907245962`},{0,2.75`},{0.24430858201140523`,2.84487636543991`},{0.1611879912929637`,2.6969256059193745`},{0.3303289201558677`,2.6831485950868266`},{0.048173133740787674`,2.625`},{0.21390031096149728`,2.4893486169604775`},{0.37230957086376015`,2.526054794820759`},{0.3330865705748748`,2.335156899166516`},{0.10352800471976098`,2.372732605291092`},{0.4755949161623939`,2.242443670178059`},{0,2.25`},{0.18188181820222`,2.2325826139405756`},{0.6679465417754838`,2.368368199086929`},{0.14471150894158263`,2.0742421860187625`},{0.5774184539272286`,2.138154112680734`},{1.574255515307437`,2.4710861770757457`},{1.9762651601548866`,2.1567149696440526`},{1.7667673207977925`,2.2008388976640947`},{1.794157072005234`,2.338191019099707`},{1.6433354563867801`,2.2968597656818135`},{1.5331403458627328`,2.2036198701900394`},{1.586186164904394`,0.5456190195257203`},{2.1013695749374324`,0.7942030356519483`},{2.2909394250658837`,0.9346847494394396`},{2.493842585751936`,0.8787841832040493`},{2.5004594497659984`,1.0065615934896597`},{2.1343690836989415`,0.9478188158211024`},{1.9866000299091928`,0.8992099974151919`},{1.7396033013760606`,0.7754002582293439`},{1.8449401184881744`,0.8735368714778807`},{1.6886024176970698`,0.9357439891302732`},{1.4528532200465176`,0.9473566270835732`},{2.2760741247762724`,0.7565981745345665`},{2.44084439235382`,0.7180871700340815`},{2.6045176250040694`,0.720452055651903`},{2.5282137649273655`,0.5332429792369037`},{2.606701479362771`,0.29010213886064273`},{2.3958508070385363`,0.43439276072009136`},{2.3516402338145284`,0.2752175631009077`},{2.5`,0},{2.140789561490294`,0.41950818496035625`},{2.8183712954508047`,0.43967364749265947`},{1.2113196077370556`,0.9284476143972132`},{2.795518436556444`,0.2474537959828488`},{2.9013264444828057`,0.12667464825152017`},{2.75`,0},{2.672512180446578`,0.14216706138995788`},{1.3268128773518555`,1.0052634553199775`},{1.197842999982431`,1.071601240104628`},{1.7341959019578685`,0.3765343602440702`},{1.3514389329491678`,0.6907033953099108`},{0.9307289924719795`,0.740778357006443`},{1.3394532146381815`,0.8438025490200612`},{1.0349486993073052`,0.8885508291423753`},{1.1396913831178772`,0.7040409754951734`},{0.7847525666592969`,0.8027925689756819`},{1.090406434753195`,0.5446446020855007`},{1.2215239953078252`,0.4654383725802026`},{0.5583759903434757`,1.015135772176508`},{0.9817052632005369`,0.4180734154175043`},{0.75`,0},{0.8113285370579645`,0.9526940378967867`},{1.125`,0},{0,0.75`},{0.8190137147187799`,1.1737555882268464`},{0.5898454096531228`,0.7480755286908168`},{0.6444169071300477`,0.9111843755811107`},{0.4258231980626414`,1.0404080786434953`},{0.6766291082059428`,1.0801367901024823`},{0.5031309538215503`,1.3377650068003002`},{1.4083093622365435`,0.5202667544607992`},{1.5341218446462261`,0.27422660952161504`},{0.9272037493344949`,0.5748427712774031`},{1.3125`,0},{1.2405303190737635`,0.617439034207537`},{1.5135059791547116`,0.41887184056785703`},{0.8835070456113873`,1.0608491232012214`},{0.9475788576928912`,1.1786682155795352`},{0.8628039516426016`,1.309637229146856`},{0.6520886590867828`,1.302547014431574`},{1.3876047027207925`,0.3271357212959948`},{0.7064172765183268`,1.4287511484505215`},{1.7795975628211904`,0.13986367505683872`},{1.7906089724037355`,0.5752391747395227`},{1.6750745515909904`,0.6523775873662641`},{1.555532643468674`,0.7935154630423201`},{1.93442472725845`,0.4270489696102972`},{1.8731096925754458`,0.2479994457998382`},{2.0440189936305706`,0.5987484083837817`},{1.75`,0},{2.0892516906440415`,0.20212791976198316`},{2.187437272129726`,0.5604359589491661`},{1.9424695729480679`,0.7346864464198369`},{1.9200945041164927`,0.557022082510328`},{2.0341979179610585`,0.3299800047491466`},{1.472445478469107`,0.14266477639466738`},{1.21875`,0.19371260921411593`},{1.3517802635808251`,0.19891435510080763`},{1.6777316245508016`,0.24016917812448016`},{1.4947686282687869`,0.6601582711609816`},{2.25`,0},{2.206383255080608`,0.28915722970106367`},{2.2663585275723697`,0.15033574547729697`},{2.422048376643903`,0.13557557372287254`},{1.2487673300860678`,0.32928320941878775`},{0.9870421973165682`,0.18630879467402378`},{2.125`,0.06557391378769298`},{1.1048359764990632`,0.12930080307677788`},{1.0922951613972003`,0.3046762538396011`},{0.7092041353555456`,0.2958546676981596`},{0.8060332446680673`,0.44485882892037454`},{0.8702383389178153`,0.2971718103504207`},{0.7908674634180766`,0.15637531545929495`},{0.9375`,0},{1.4667648218207223`,1.9962070187046372`},{1.3073585232534617`,1.984418100869271`},{1.5772463532926368`,1.843083713865294`},{1.4854222609105876`,1.703054309782797`},{1.3418355313431638`,1.7037672608451793`},{1.643419153557193`,1.699569525319757`},{0.39154186835787574`,0.7887997212491623`},{0.7474135964492254`,0.6209731256468404`},{0.43802342982702214`,1.476291954589059`},{0.5222478754829665`,1.1858991177713323`},{0.3605637370013206`,1.188357416634026`},{0.3483918208250514`,1.3496014811029182`},{0.22151607797591794`,1.5344159113659945`},{0,1.125`},{0,1.3125`},{0.20249467534003263`,1.0302667889429005`},{0.42807396237920403`,0.4635155909243362`},{0.21025314171545667`,1.3907263345001644`},{0.617413008452289`,0.46146823912002893`},{0.4626943812256612`,0.6320972429372322`},{0,0.375`},{0.33344419285016047`,0.6679147856280796`},{0.19602184528698605`,0.808363822133413`},{0.6043533683331116`,0.6048415378648139`},{0.3055524329200213`,0.9162147425993031`},{0,0.9375`},{0.3488464455042638`,1.5764131693067371`},{0,1.75`},{0.17975798776693636`,1.2110694380090903`},{0.12990040579409867`,0.9213384493095219`},{0.09401089594953531`,1.625`},{0.17436278157929508`,1.7832838163032436`},{0.11531373032750142`,1.9142762720947277`},{0.32098828278311475`,1.8033437596464896`},{0.09203343622499938`,2.875`},{2.6586709397042116`,0.44111691241289436`},{1.9625553672238076`,0.13730303526877477`},{0.20096481386793133`,0.4824766522063419`},{0.16952274466227912`,0.6449808191619841`},{0,0.5625`},{0.3199083610195958`,0.5375434075829608`},{0.28125`,0.1748983133611042`},{0.375`,0},{0.14798914879423608`,0.3219358189590783`},{0.5095507553716626`,0.18469803369502844`},{0,0.1875`},{0.1875`,0},{0.13872175779561471`,0.13872175779561474`},{0.5625`,0},{0.3149938061381398`,0.339386751115883`},{0.45944129996551064`,0.32136837706008303`},{0.39776216275088827`,0.12477646923397123`},{0.6454968878935834`,0.12373231670112723`},{1.625`,0.09334432232081827`}};
Elements={{108,98,107},{98,103,97},{98,15,101},{146,26,150},{130,119,120},{34,35,22},{38,148,150},{109,97,27},{124,110,102},{75,178,162},{70,33,45},{128,117,125},{55,73,48},{62,59,61},{100,123,122},{172,3,4},{34,11,147},{104,101,16},{34,147,32},{58,53,70},{68,5,66},{59,63,7},{38,40,148},{36,31,47},{45,47,41},{67,166,280},{86,87,78},{31,34,22},{31,36,10},{10,11,31},{144,141,28},{50,29,46},{43,54,75},{26,151,150},{51,29,50},{66,6,65},{247,250,35},{10,36,9},{22,37,41},{45,33,47},{11,34,31},{35,34,32},{32,40,35},{245,38,151},{47,31,22},{9,36,33},{42,41,37},{22,35,37},{147,148,32},{91,245,246},{39,42,44},{39,46,45},{148,40,32},{247,38,245},{42,37,23},{41,39,45},{54,55,48},{39,41,42},{51,54,43},{225,171,217},{55,42,23},{43,49,51},{39,50,46},{69,33,53},{46,29,57},{57,58,46},{36,47,33},{22,41,47},{247,40,38},{77,76,71},{161,43,162},{52,57,154},{39,44,50},{51,50,44},{51,44,54},{29,51,49},{158,157,29},{60,63,59},{53,62,69},{45,46,70},{55,54,44},{75,54,48},{42,55,44},{73,55,23},{92,94,80},{76,77,82},{154,29,157},{57,52,58},{59,58,52},{69,62,8},{59,52,60},{61,59,7},{57,29,154},{6,60,65},{7,8,61},{61,8,62},{53,58,62},{62,58,59},{167,174,280},{60,6,63},{52,156,60},{156,154,155},{68,4,5},{165,155,164},{68,66,65},{67,165,166},{65,155,165},{4,68,67},{8,9,69},{33,69,9},{58,70,46},{33,70,53},{35,40,247},{79,83,77},{227,235,239},{72,184,173},{73,23,250},{76,73,71},{75,48,76},{215,216,230},{48,73,76},{75,74,178},{71,249,77},{74,75,76},{79,77,56},{83,79,86},{88,85,87},{199,192,207},{90,88,56},{79,87,86},{93,109,111},{272,276,277},{209,195,208},{81,84,82},{81,208,84},{74,76,82},{81,82,83},{77,83,82},{179,72,173},{74,82,84},{88,79,56},{122,114,100},{209,86,78},{83,86,81},{88,87,79},{122,87,85},{91,89,90},{88,90,92},{97,93,96},{85,88,92},{90,56,249},{92,90,89},{248,249,71},{248,73,250},{94,92,89},{92,80,114},{93,94,96},{97,109,93},{96,94,89},{80,94,93},{113,100,114},{78,87,122},{246,96,89},{106,107,105},{105,96,24},{15,16,101},{105,98,97},{98,105,107},{103,101,116},{118,95,123},{80,111,113},{118,123,100},{104,17,102},{97,103,27},{128,125,127},{27,110,109},{98,101,103},{101,104,116},{17,104,16},{104,102,116},{96,105,97},{106,105,24},{24,245,151},{107,106,26},{146,107,26},{108,107,14},{14,15,108},{98,108,15},{103,116,27},{111,109,99},{125,124,102},{109,110,143},{113,111,145},{93,111,80},{126,140,143},{278,118,120},{145,111,99},{113,112,118},{92,114,85},{113,114,80},{186,192,197},{251,189,198},{102,110,116},{27,116,110},{132,129,19},{126,143,124},{113,118,100},{120,118,112},{112,130,120},{275,25,257},{145,140,130},{119,276,278},{140,126,138},{126,137,138},{122,85,114},{212,122,115},{123,95,271},{122,123,115},{125,102,17},{124,117,126},{127,125,17},{117,124,125},{134,128,129},{136,137,134},{17,18,127},{127,18,128},{18,129,128},{132,134,129},{18,19,129},{133,135,136},{20,279,19},{138,139,142},{136,134,133},{131,121,135},{279,131,133},{132,133,134},{131,135,133},{133,132,279},{128,134,117},{136,135,121},{142,130,138},{134,137,117},{138,137,136},{126,117,137},{136,121,139},{138,130,140},{142,139,141},{28,277,144},{145,130,112},{143,140,99},{139,138,136},{119,144,277},{141,144,142},{130,144,119},{109,143,99},{124,143,110},{67,280,172},{121,141,139},{113,145,112},{99,140,145},{13,14,146},{107,146,14},{11,12,147},{148,147,12},{12,149,148},{149,13,150},{12,13,149},{13,146,150},{26,106,151},{148,149,150},{24,151,106},{38,150,151},{162,216,161},{218,217,180},{158,153,157},{153,223,219},{153,163,154},{60,155,65},{163,155,154},{155,163,164},{154,156,52},{155,60,156},{158,29,49},{153,154,157},{49,160,158},{160,223,158},{160,49,161},{180,214,152},{161,49,43},{159,214,223},{43,75,162},{159,160,161},{74,84,179},{215,159,216},{222,153,219},{163,64,164},{164,166,165},{165,67,68},{65,165,68},{166,164,64},{198,254,255},{168,166,64},{174,3,172},{172,280,174},{168,171,232},{152,206,180},{168,64,222},{167,168,169},{153,222,163},{221,233,232},{234,167,169},{176,175,177},{167,166,168},{67,172,4},{234,177,167},{178,183,162},{3,174,175},{2,175,176},{2,3,175},{177,174,167},{175,174,177},{170,176,177},{179,178,74},{183,178,173},{72,179,84},{178,179,173},{188,201,205},{181,185,205},{173,184,185},{235,227,228},{195,199,207},{181,183,185},{185,183,173},{216,183,181},{72,207,184},{184,182,185},{285,261,264},{252,182,186},{190,203,241},{152,230,201},{204,226,228},{180,206,202},{292,290,1},{206,201,211},{188,239,235},{226,21,298},{193,227,238},{201,188,211},{182,184,192},{242,241,240},{208,195,207},{190,187,203},{204,21,226},{205,187,188},{199,254,189},{239,187,190},{254,198,189},{210,195,209},{242,243,236},{195,210,199},{251,196,197},{197,199,189},{196,252,186},{254,199,210},{200,253,256},{197,189,251},{240,241,263},{255,273,260},{205,201,181},{205,185,187},{215,214,159},{206,152,201},{202,229,180},{227,193,204},{122,212,78},{182,192,186},{187,185,203},{186,197,196},{203,185,182},{226,202,228},{184,207,192},{208,207,72},{84,208,72},{209,208,81},{86,209,81},{209,212,210},{212,209,78},{198,255,260},{199,197,192},{202,206,211},{220,281,213},{115,210,212},{218,281,225},{180,217,214},{217,224,214},{161,216,159},{152,214,215},{183,216,162},{230,216,181},{180,229,218},{219,217,171},{298,220,213},{229,213,218},{222,219,171},{158,223,153},{281,220,30},{281,221,225},{231,234,233},{168,232,169},{168,222,171},{163,222,64},{159,223,160},{224,223,214},{217,219,224},{223,224,219},{218,225,217},{232,225,221},{213,281,218},{228,202,211},{204,228,227},{235,228,211},{298,202,226},{298,213,229},{201,230,181},{215,230,152},{225,232,171},{281,237,221},{221,237,233},{234,231,170},{169,232,233},{234,170,177},{169,233,234},{211,188,235},{188,187,239},{190,241,242},{193,238,244},{30,231,237},{233,237,231},{239,238,227},{244,238,236},{242,239,190},{239,236,238},{261,268,264},{288,290,292},{203,182,252},{203,252,241},{243,242,240},{242,236,239},{291,286,292},{243,191,244},{246,245,24},{243,244,236},{245,91,247},{96,246,24},{91,246,89},{248,247,91},{247,248,250},{249,248,91},{248,71,73},{90,249,91},{249,56,77},{23,37,250},{35,250,37},{266,267,283},{196,251,264},{200,115,253},{210,200,254},{123,253,115},{262,25,259},{115,200,210},{241,252,263},{253,271,256},{256,255,200},{256,262,273},{123,271,253},{278,95,118},{255,256,273},{254,200,255},{274,194,267},{258,273,259},{260,274,269},{264,251,266},{294,285,282},{256,257,262},{25,262,257},{196,268,252},{283,282,285},{268,261,263},{288,292,286},{266,285,264},{267,266,251},{283,284,282},{269,267,251},{267,269,274},{264,268,196},{263,252,268},{251,198,269},{198,260,269},{95,278,271},{258,270,274},{256,271,257},{259,273,262},{276,119,277},{258,260,273},{258,274,260},{194,274,270},{271,276,257},{272,25,275},{272,275,276},{275,257,276},{144,130,142},{272,277,28},{119,278,120},{271,278,276},{19,279,132},{20,131,279},{166,167,280},{237,281,30},{287,286,291},{267,194,283},{282,284,265},{283,285,266},{283,194,284},{288,294,282},{293,191,297},{263,261,295},{288,282,265},{240,263,295},{296,286,287},{1,291,292},{288,286,294},{296,293,289},{294,261,285},{288,265,290},{191,243,297},{295,294,286},{297,240,289},{286,296,295},{295,289,240},{261,294,295},{293,296,287},{295,296,289},{240,297,243},{289,293,297},{298,229,202},{21,220,298}};

Just as a check!

nNodes=Length[Nodes];
nElements=Length[Elements];
GraphicsGrid[{{ListPlot[{Nodes,Nodes[[BoundaryNodes]]},
PlotStyle->{Red, Blue},
AspectRatio->Automatic,
Frame->True],
Show[Graphics[{
EdgeForm[{Thick, Black}],
Table[{Hue[i/nElements],Polygon[Nodes[[Elements[[i]]]]]},
{i, nElements}]
}
],
Frame->True
]}}]

Basic Gradient Computations

BasicGradientComputation[{p1_,p2_,p3_}]:= Module[
{Δp2x,Δp2y,Δp3x,Δp3y},
{{Δp2x,Δp2y},{Δp3x,Δp3y}}={p2-p1,p3-p1};
(* Computes the constant gradient of the slab function *)
(* that is 1 at p1 and zero at the other two points *)
{Δp2y-Δp3y,Δp3x-Δp2x}/(-Δp2y Δp3x+Δp2x Δp3y)
(* LinearSolve[{Δp3,Δp2},{1,1}] *)
(* To compute the gradient of the other slab functions *)
(* on the triangle permute the vertices *)
]
BasicAreaComputation[{p1_,p2_,p3_}]:= Module[
{Δp2x,Δp2y,Δp3x,Δp3y},
{{Δp2x,Δp2y},{Δp3x,Δp3y}}={p2-p1,p3-p1};
(* Computes the area of the triangle *)
0.5* Abs[Δp3x Δp2y-Δp2x Δp3y]
(* More efficient to combine the computations *)
]

Testing the things.

{p1,p2,p3}={{0.1,0.2},{0.3, 0.15},{0.24, 0.4}};
Area=BasicAreaComputation[{p1,p2,p3}]
n=BasicGradientComputation[{p1,p2,p3}]

We can visually check the area to see if it looks plausible!

{p1,p2,p3}={{1.1,1.2},{1.3, 1.15},{1.24, 1.4}};
Area=BasicAreaComputation[{p1,p2,p3}]
Show[Graphics[{
{Opacity[0.5],Pink, Polygon[{p1,p2,p3}]},
Circle[(p1+p2+p3)/3,(Sqrt[Area/π])],
Map[Point,{p1,p2,p3,(p1+p2+p3)/3}]
}
],
Frame->True,
PlotRange->All]

We can check if the linear function defined by the gradient and the value 1 at p1 works

{p1,p2,p3}={{0.1,0.2},{0.3, 0.15},{0.24, 0.4}};
n=BasicGradientComputation[{p1,p2,p3}]
Plane[{x_,y_}]:= 1 +n.({x,y}-p1)
Map[Plane,{p1,p2,p3}]

We could check that it works ok for the permuted versions as well.

Basic stiffness matrix and load vector assembley.  Dirichlet Boundary Conditions

AssembleStiffnessMatrix[Elements_List,Nodes_List]:= Module[
{NodeCount,ElementCount,A,n1,n2,n3,p1,p2,p3,i,j,k,
Area,Grad1,Grad2,Grad3,a12,a13,a23},
NodeCount=Length[Nodes];
ElementCount=Length[Elements];
A=SparseArray[{},{NodeCount,NodeCount}];
Do[
(* Grab the triangle data *)
{n1,n2,n3}=Elements[[i]];
{p1,p2,p3}=Nodes[[{n1,n2,n3}]];
(* Compute the geometric stuff *)
Area=BasicAreaComputation[{p1,p2,p3}];
Grad1=BasicGradientComputation[{p1,p2,p3}];
Grad2=BasicGradientComputation[{p2,p3,p1}];
Grad3=BasicGradientComputation[{p3,p1,p2}];
(* Update the stiffness matrix *)
A[[n1,n1]]+=Area*Grad1.Grad1;
A[[n2,n2]]+=Area*Grad2.Grad2;
A[[n3,n3]]+=Area*Grad3.Grad3;
a12=Area*Grad1.Grad2;A[[n1,n2]]+=a12;A[[n2,n1]]+=a12;
a13=Area*Grad1.Grad3;A[[n1,n3]]+=a13;A[[n3,n1]]+=a13;
a23=Area*Grad2.Grad3;A[[n2,n3]]+=a23;A[[n3,n2]]+=a23,
{i,ElementCount}
];
A
]

AssembleLoadVector[Elements_List,Nodes_List,f_]:= Module[
{NodeCount,ElementCount,b,
n1,n2,n3,p1,p2,p3,i,
Area,bTemp},
NodeCount=Length[Nodes];
ElementCount=Length[Elements];
b=ConstantArray[0,NodeCount];
Do[
(* Grab the triangle data *)
{n1,n2,n3}=Elements[[i]];
{p1,p2,p3}=Nodes[[{n1,n2,n3}]];
(* Compute the geometric stuff *)
Area=BasicAreaComputation[{p1,p2,p3}];
(* Use midpoint value for f and the shape functions *)
(* Midpoint gives the average value of p *)
(* shape functions are all 1/3 at the midpoint *)
bTemp=Area*f[(p1+p2+p3)/3.0]/3.0;
b[[n1]]+=bTemp; b[[n2]]+=bTemp; b[[n3]]+=bTemp,
{i,ElementCount}
];
b
]

DirichletBoundarySet[A_,b_,BoundaryNodes_,BoundaryNodeValues_]:= Module[
{BoundaryNodeCount,i,n,Huge=1.0 (10^9),ATemp=A, bTemp=b},
BoundaryNodeCount=Length[BoundaryNodes];
Do[
(* Loading the Diagonals to enforce Dirichlet Boundary conditions *)
n=BoundaryNodes[[i]];
ATemp[[n,n]]=Huge;
bTemp[[n]]=Huge*BoundaryNodeValues[[i]],
{i,BoundaryNodeCount}
];
{ATemp,bTemp}
]

Plotting Utilities

we need to plot our triangulated values.

TrianglePlot[u_List,Nodes_,Elements_]:= Module[
{Data,x,y,i},
Data=Table[ 
{x,y}=Nodes[[i]];
{x,y,u[[i]]},
{i, Length[u]}];
Show[
Graphics3D[
Table[
Polygon[Data[[Elements[[i]]]]],
{i, Length[Elements]}]
],
BoxRatios->{1,1,0.5},
Axes->True
]
]

A Saved Mesh

SetDirectory["/home/campus03/struther/Desktop/Link to Courses/4620/SampleGrids"];
DataEle=Take[Import["QuarterCircleThree.1.ele","TABLE"],{2,-2}];
DataNode=Take[Import["QuarterCircleThree.1.node","TABLE"],{2,-2}];
BoundaryNodes=Flatten[Position[DataNode,{n_,x_,y_,1}]]
Nodes=DataNode[[All,{2,3}]];
Elements=DataEle[[All,{2,3,4}]];

I saved the nodes and elements and boundary nodes so that I do not need to carry around the data files.  They are in the hidden initialization cell below.

BoundaryNodes={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,25,28,30,63,66,121,131,141,170,176,191,193,194,204,220,231,244,258,259,265,270,272,284,287,290,291,293};
Nodes={{0,0},{3,0},{2.988584094275237`,0.2614672282429745`},{2.954423259036624`,0.520944533000791`},{2.897777478867205`,0.7764571353075622`},{2.8190778623577253`,1.0260604299770062`},{2.7189233611099497`,1.2678547852220983`},{2.598076211353316`,1.4999999999999998`},{2.4574561328669753`,1.7207293090531381`},{2.298133329356934`,1.9283628290596178`},{2.121320343559643`,2.1213203435596424`},{1.9283628290596182`,2.298133329356934`},{1.7207293090531386`,2.4574561328669753`},{1.5000000000000004`,2.598076211353316`},{1.2678547852220983`,2.7189233611099497`},{1.0260604299770064`,2.819077862357725`},{0.7764571353075622`,2.897777478867205`},{0.5209445330007912`,2.954423259036624`},{0.2614672282429751`,2.988584094275237`},{0,3},{1.5`,0},{1.9587802641631815`,1.7948914191028067`},{1.6899265255855487`,1.5485323571929912`},{1.3602970809686032`,2.1352387085914395`},{0,1.5`},{1.4952151993065323`,2.3470177330383173`},{0.9836535267275764`,2.37474968490184`},{0,2},{2.121564210141363`,1.1044164234294347`},{2,0},{2.102799630688276`,1.9268608543119918`},{1.8753920856275104`,2.046631325883333`},{2.1965444366470206`,1.6799868535298081`},{1.9622166753664985`,1.9357107314517734`},{1.7641243979423582`,1.8700931882992557`},{2.2012707363996573`,1.8230172917070153`},{1.806756646161333`,1.6909153696096109`},{1.6170202648417462`,2.086143065301593`},{1.9941527584634104`,1.4180274078681765`},{1.7376047664177177`,2.0101415913728506`},{1.9761116442911708`,1.6064261056308191`},{1.8488591727939052`,1.499177211840397`},{1.6364370533819173`,1.0957126640048718`},{1.8113062786790528`,1.2612967481298722`},{2.125550129433852`,1.5256732184394262`},{2.1888184507275064`,1.314427320630976`},{2.064186803569169`,1.709555107285475`},{1.5783960775719352`,1.3321378501453216`},{1.880562175339031`,1.0130277635279288`},{1.9926682792622232`,1.2347369419983591`},{1.887448986352978`,1.1487430092105495`},{2.4387145347276253`,1.1186259274036305`},{2.3600734166862427`,1.4808157309346421`},{1.6746928836653616`,1.2304411927091283`},{1.7243890493611533`,1.3938314226343378`},{1.2045258814956086`,1.661770626863066`},{2.2775080616341588`,1.1702509576755933`},{2.4084702931754003`,1.3016915410623484`},{2.5579844121954247`,1.2323616153549053`},{2.6223530175340835`,1.045456420979251`},{2.6140452531463088`,1.3607858274391669`},{2.484876160652442`,1.4184355267400977`},{2.7690006117338375`,1.1469576075995522`},{2.3334254526517366`,0.5873450194532792`},{2.7026106714111244`,0.8521298715073439`},{2.858427670612465`,0.9012587826422843`},{2.7181096625677235`,0.602590404669467`},{2.7678721039513348`,0.7309322263583169`},{2.4722561744881983`,1.5750008858641316`},{2.2311354940253882`,1.4421987163441845`},{1.4329675214122257`,1.5440310465360465`},{1.0133336727697237`,1.0680814433611925`},{1.5626573726705562`,1.4771884662367503`},{1.3221362869097821`,1.1438906468980565`},{1.489268510312477`,1.1849206128417935`},{1.3798733002331347`,1.3517383612010536`},{1.2597266780553`,1.4883885299998938`},{0.8420247211992707`,1.4508803839230853`},{1.046708040672023`,1.5160467562406048`},{0.8103352134543897`,1.9303564203928596`},{1.0047029531092084`,1.2939503374299226`},{1.1943084829487458`,1.3097278293774903`},{1.091964369619064`,1.3924670086606463`},{1.1092410090867175`,1.1848455190730005`},{0.8773366905503804`,1.693999449913208`},{0.9657368187024862`,1.4163404207466384`},{0.9187708921815879`,1.5638573286323703`},{1.0411749512616286`,1.6803587443675991`},{1.1535554746531562`,1.9408983484814675`},{1.1367963445689317`,1.793620417378293`},{1.3884591498839478`,1.8395755647196084`},{0.9834801061149536`,1.8856591593564367`},{0.9980636489533615`,2.130199281875039`},{1.0387044681603292`,2.005070683613494`},{0.4177931288750378`,1.6914051125967569`},{1.1793490192064`,2.1205961468261556`},{1.095765361368782`,2.258656110611888`},{1.2078328591960699`,2.47906007069823`},{0.6867406368586797`,2.2345543459015977`},{0.6472050927675381`,1.7564378485177519`},{1.0916868295724536`,2.6355651498179022`},{0.8346374841988878`,2.6471319067427017`},{1.064504175590899`,2.4940424116871722`},{0.9655286876395639`,2.6939402084763633`},{1.2782411301448802`,2.304566864759379`},{1.3998092838985237`,2.2589323318078356`},{1.3642425958674764`,2.4407201100457696`},{1.3488941491610034`,2.5912015517142644`},{0.8633809053263214`,2.244962866301113`},{0.7817407332756123`,2.441239642706043`},{0.78349299720723`,2.096657509354214`},{0.5110438054901298`,2.0083899007778134`},{0.6667172885044242`,1.9924922431193224`},{0.781034160549201`,1.7943751481943986`},{0.5938414645669657`,1.5075278498221028`},{0.9139001931449682`,2.5170270423265935`},{0.5031941522833039`,2.62254346494593`},{0.49973293744961783`,1.8395086856160876`},{0.25656571867783584`,1.9406142620540594`},{0.3953049531815314`,1.931322161852091`},{0,2.5`},{0.7430795986257481`,1.58937571217845`},{0.5545521460612998`,1.646126350880597`},{0.6730655343622503`,2.578901008397768`},{0.6971474311697233`,2.747292697313436`},{0.53683002740905`,2.4010457904103166`},{0.637359759992975`,2.87494408929232`},{0.4936645394253169`,2.7894677312416634`},{0.38085197432054063`,2.8928579502847387`},{0.3396259350886788`,2.140380907245962`},{0,2.75`},{0.24430858201140523`,2.84487636543991`},{0.1611879912929637`,2.6969256059193745`},{0.3303289201558677`,2.6831485950868266`},{0.048173133740787674`,2.625`},{0.21390031096149728`,2.4893486169604775`},{0.37230957086376015`,2.526054794820759`},{0.3330865705748748`,2.335156899166516`},{0.10352800471976098`,2.372732605291092`},{0.4755949161623939`,2.242443670178059`},{0,2.25`},{0.18188181820222`,2.2325826139405756`},{0.6679465417754838`,2.368368199086929`},{0.14471150894158263`,2.0742421860187625`},{0.5774184539272286`,2.138154112680734`},{1.574255515307437`,2.4710861770757457`},{1.9762651601548866`,2.1567149696440526`},{1.7667673207977925`,2.2008388976640947`},{1.794157072005234`,2.338191019099707`},{1.6433354563867801`,2.2968597656818135`},{1.5331403458627328`,2.2036198701900394`},{1.586186164904394`,0.5456190195257203`},{2.1013695749374324`,0.7942030356519483`},{2.2909394250658837`,0.9346847494394396`},{2.493842585751936`,0.8787841832040493`},{2.5004594497659984`,1.0065615934896597`},{2.1343690836989415`,0.9478188158211024`},{1.9866000299091928`,0.8992099974151919`},{1.7396033013760606`,0.7754002582293439`},{1.8449401184881744`,0.8735368714778807`},{1.6886024176970698`,0.9357439891302732`},{1.4528532200465176`,0.9473566270835732`},{2.2760741247762724`,0.7565981745345665`},{2.44084439235382`,0.7180871700340815`},{2.6045176250040694`,0.720452055651903`},{2.5282137649273655`,0.5332429792369037`},{2.606701479362771`,0.29010213886064273`},{2.3958508070385363`,0.43439276072009136`},{2.3516402338145284`,0.2752175631009077`},{2.5`,0},{2.140789561490294`,0.41950818496035625`},{2.8183712954508047`,0.43967364749265947`},{1.2113196077370556`,0.9284476143972132`},{2.795518436556444`,0.2474537959828488`},{2.9013264444828057`,0.12667464825152017`},{2.75`,0},{2.672512180446578`,0.14216706138995788`},{1.3268128773518555`,1.0052634553199775`},{1.197842999982431`,1.071601240104628`},{1.7341959019578685`,0.3765343602440702`},{1.3514389329491678`,0.6907033953099108`},{0.9307289924719795`,0.740778357006443`},{1.3394532146381815`,0.8438025490200612`},{1.0349486993073052`,0.8885508291423753`},{1.1396913831178772`,0.7040409754951734`},{0.7847525666592969`,0.8027925689756819`},{1.090406434753195`,0.5446446020855007`},{1.2215239953078252`,0.4654383725802026`},{0.5583759903434757`,1.015135772176508`},{0.9817052632005369`,0.4180734154175043`},{0.75`,0},{0.8113285370579645`,0.9526940378967867`},{1.125`,0},{0,0.75`},{0.8190137147187799`,1.1737555882268464`},{0.5898454096531228`,0.7480755286908168`},{0.6444169071300477`,0.9111843755811107`},{0.4258231980626414`,1.0404080786434953`},{0.6766291082059428`,1.0801367901024823`},{0.5031309538215503`,1.3377650068003002`},{1.4083093622365435`,0.5202667544607992`},{1.5341218446462261`,0.27422660952161504`},{0.9272037493344949`,0.5748427712774031`},{1.3125`,0},{1.2405303190737635`,0.617439034207537`},{1.5135059791547116`,0.41887184056785703`},{0.8835070456113873`,1.0608491232012214`},{0.9475788576928912`,1.1786682155795352`},{0.8628039516426016`,1.309637229146856`},{0.6520886590867828`,1.302547014431574`},{1.3876047027207925`,0.3271357212959948`},{0.7064172765183268`,1.4287511484505215`},{1.7795975628211904`,0.13986367505683872`},{1.7906089724037355`,0.5752391747395227`},{1.6750745515909904`,0.6523775873662641`},{1.555532643468674`,0.7935154630423201`},{1.93442472725845`,0.4270489696102972`},{1.8731096925754458`,0.2479994457998382`},{2.0440189936305706`,0.5987484083837817`},{1.75`,0},{2.0892516906440415`,0.20212791976198316`},{2.187437272129726`,0.5604359589491661`},{1.9424695729480679`,0.7346864464198369`},{1.9200945041164927`,0.557022082510328`},{2.0341979179610585`,0.3299800047491466`},{1.472445478469107`,0.14266477639466738`},{1.21875`,0.19371260921411593`},{1.3517802635808251`,0.19891435510080763`},{1.6777316245508016`,0.24016917812448016`},{1.4947686282687869`,0.6601582711609816`},{2.25`,0},{2.206383255080608`,0.28915722970106367`},{2.2663585275723697`,0.15033574547729697`},{2.422048376643903`,0.13557557372287254`},{1.2487673300860678`,0.32928320941878775`},{0.9870421973165682`,0.18630879467402378`},{2.125`,0.06557391378769298`},{1.1048359764990632`,0.12930080307677788`},{1.0922951613972003`,0.3046762538396011`},{0.7092041353555456`,0.2958546676981596`},{0.8060332446680673`,0.44485882892037454`},{0.8702383389178153`,0.2971718103504207`},{0.7908674634180766`,0.15637531545929495`},{0.9375`,0},{1.4667648218207223`,1.9962070187046372`},{1.3073585232534617`,1.984418100869271`},{1.5772463532926368`,1.843083713865294`},{1.4854222609105876`,1.703054309782797`},{1.3418355313431638`,1.7037672608451793`},{1.643419153557193`,1.699569525319757`},{0.39154186835787574`,0.7887997212491623`},{0.7474135964492254`,0.6209731256468404`},{0.43802342982702214`,1.476291954589059`},{0.5222478754829665`,1.1858991177713323`},{0.3605637370013206`,1.188357416634026`},{0.3483918208250514`,1.3496014811029182`},{0.22151607797591794`,1.5344159113659945`},{0,1.125`},{0,1.3125`},{0.20249467534003263`,1.0302667889429005`},{0.42807396237920403`,0.4635155909243362`},{0.21025314171545667`,1.3907263345001644`},{0.617413008452289`,0.46146823912002893`},{0.4626943812256612`,0.6320972429372322`},{0,0.375`},{0.33344419285016047`,0.6679147856280796`},{0.19602184528698605`,0.808363822133413`},{0.6043533683331116`,0.6048415378648139`},{0.3055524329200213`,0.9162147425993031`},{0,0.9375`},{0.3488464455042638`,1.5764131693067371`},{0,1.75`},{0.17975798776693636`,1.2110694380090903`},{0.12990040579409867`,0.9213384493095219`},{0.09401089594953531`,1.625`},{0.17436278157929508`,1.7832838163032436`},{0.11531373032750142`,1.9142762720947277`},{0.32098828278311475`,1.8033437596464896`},{0.09203343622499938`,2.875`},{2.6586709397042116`,0.44111691241289436`},{1.9625553672238076`,0.13730303526877477`},{0.20096481386793133`,0.4824766522063419`},{0.16952274466227912`,0.6449808191619841`},{0,0.5625`},{0.3199083610195958`,0.5375434075829608`},{0.28125`,0.1748983133611042`},{0.375`,0},{0.14798914879423608`,0.3219358189590783`},{0.5095507553716626`,0.18469803369502844`},{0,0.1875`},{0.1875`,0},{0.13872175779561471`,0.13872175779561474`},{0.5625`,0},{0.3149938061381398`,0.339386751115883`},{0.45944129996551064`,0.32136837706008303`},{0.39776216275088827`,0.12477646923397123`},{0.6454968878935834`,0.12373231670112723`},{1.625`,0.09334432232081827`}};
Elements={{108,98,107},{98,103,97},{98,15,101},{146,26,150},{130,119,120},{34,35,22},{38,148,150},{109,97,27},{124,110,102},{75,178,162},{70,33,45},{128,117,125},{55,73,48},{62,59,61},{100,123,122},{172,3,4},{34,11,147},{104,101,16},{34,147,32},{58,53,70},{68,5,66},{59,63,7},{38,40,148},{36,31,47},{45,47,41},{67,166,280},{86,87,78},{31,34,22},{31,36,10},{10,11,31},{144,141,28},{50,29,46},{43,54,75},{26,151,150},{51,29,50},{66,6,65},{247,250,35},{10,36,9},{22,37,41},{45,33,47},{11,34,31},{35,34,32},{32,40,35},{245,38,151},{47,31,22},{9,36,33},{42,41,37},{22,35,37},{147,148,32},{91,245,246},{39,42,44},{39,46,45},{148,40,32},{247,38,245},{42,37,23},{41,39,45},{54,55,48},{39,41,42},{51,54,43},{225,171,217},{55,42,23},{43,49,51},{39,50,46},{69,33,53},{46,29,57},{57,58,46},{36,47,33},{22,41,47},{247,40,38},{77,76,71},{161,43,162},{52,57,154},{39,44,50},{51,50,44},{51,44,54},{29,51,49},{158,157,29},{60,63,59},{53,62,69},{45,46,70},{55,54,44},{75,54,48},{42,55,44},{73,55,23},{92,94,80},{76,77,82},{154,29,157},{57,52,58},{59,58,52},{69,62,8},{59,52,60},{61,59,7},{57,29,154},{6,60,65},{7,8,61},{61,8,62},{53,58,62},{62,58,59},{167,174,280},{60,6,63},{52,156,60},{156,154,155},{68,4,5},{165,155,164},{68,66,65},{67,165,166},{65,155,165},{4,68,67},{8,9,69},{33,69,9},{58,70,46},{33,70,53},{35,40,247},{79,83,77},{227,235,239},{72,184,173},{73,23,250},{76,73,71},{75,48,76},{215,216,230},{48,73,76},{75,74,178},{71,249,77},{74,75,76},{79,77,56},{83,79,86},{88,85,87},{199,192,207},{90,88,56},{79,87,86},{93,109,111},{272,276,277},{209,195,208},{81,84,82},{81,208,84},{74,76,82},{81,82,83},{77,83,82},{179,72,173},{74,82,84},{88,79,56},{122,114,100},{209,86,78},{83,86,81},{88,87,79},{122,87,85},{91,89,90},{88,90,92},{97,93,96},{85,88,92},{90,56,249},{92,90,89},{248,249,71},{248,73,250},{94,92,89},{92,80,114},{93,94,96},{97,109,93},{96,94,89},{80,94,93},{113,100,114},{78,87,122},{246,96,89},{106,107,105},{105,96,24},{15,16,101},{105,98,97},{98,105,107},{103,101,116},{118,95,123},{80,111,113},{118,123,100},{104,17,102},{97,103,27},{128,125,127},{27,110,109},{98,101,103},{101,104,116},{17,104,16},{104,102,116},{96,105,97},{106,105,24},{24,245,151},{107,106,26},{146,107,26},{108,107,14},{14,15,108},{98,108,15},{103,116,27},{111,109,99},{125,124,102},{109,110,143},{113,111,145},{93,111,80},{126,140,143},{278,118,120},{145,111,99},{113,112,118},{92,114,85},{113,114,80},{186,192,197},{251,189,198},{102,110,116},{27,116,110},{132,129,19},{126,143,124},{113,118,100},{120,118,112},{112,130,120},{275,25,257},{145,140,130},{119,276,278},{140,126,138},{126,137,138},{122,85,114},{212,122,115},{123,95,271},{122,123,115},{125,102,17},{124,117,126},{127,125,17},{117,124,125},{134,128,129},{136,137,134},{17,18,127},{127,18,128},{18,129,128},{132,134,129},{18,19,129},{133,135,136},{20,279,19},{138,139,142},{136,134,133},{131,121,135},{279,131,133},{132,133,134},{131,135,133},{133,132,279},{128,134,117},{136,135,121},{142,130,138},{134,137,117},{138,137,136},{126,117,137},{136,121,139},{138,130,140},{142,139,141},{28,277,144},{145,130,112},{143,140,99},{139,138,136},{119,144,277},{141,144,142},{130,144,119},{109,143,99},{124,143,110},{67,280,172},{121,141,139},{113,145,112},{99,140,145},{13,14,146},{107,146,14},{11,12,147},{148,147,12},{12,149,148},{149,13,150},{12,13,149},{13,146,150},{26,106,151},{148,149,150},{24,151,106},{38,150,151},{162,216,161},{218,217,180},{158,153,157},{153,223,219},{153,163,154},{60,155,65},{163,155,154},{155,163,164},{154,156,52},{155,60,156},{158,29,49},{153,154,157},{49,160,158},{160,223,158},{160,49,161},{180,214,152},{161,49,43},{159,214,223},{43,75,162},{159,160,161},{74,84,179},{215,159,216},{222,153,219},{163,64,164},{164,166,165},{165,67,68},{65,165,68},{166,164,64},{198,254,255},{168,166,64},{174,3,172},{172,280,174},{168,171,232},{152,206,180},{168,64,222},{167,168,169},{153,222,163},{221,233,232},{234,167,169},{176,175,177},{167,166,168},{67,172,4},{234,177,167},{178,183,162},{3,174,175},{2,175,176},{2,3,175},{177,174,167},{175,174,177},{170,176,177},{179,178,74},{183,178,173},{72,179,84},{178,179,173},{188,201,205},{181,185,205},{173,184,185},{235,227,228},{195,199,207},{181,183,185},{185,183,173},{216,183,181},{72,207,184},{184,182,185},{285,261,264},{252,182,186},{190,203,241},{152,230,201},{204,226,228},{180,206,202},{292,290,1},{206,201,211},{188,239,235},{226,21,298},{193,227,238},{201,188,211},{182,184,192},{242,241,240},{208,195,207},{190,187,203},{204,21,226},{205,187,188},{199,254,189},{239,187,190},{254,198,189},{210,195,209},{242,243,236},{195,210,199},{251,196,197},{197,199,189},{196,252,186},{254,199,210},{200,253,256},{197,189,251},{240,241,263},{255,273,260},{205,201,181},{205,185,187},{215,214,159},{206,152,201},{202,229,180},{227,193,204},{122,212,78},{182,192,186},{187,185,203},{186,197,196},{203,185,182},{226,202,228},{184,207,192},{208,207,72},{84,208,72},{209,208,81},{86,209,81},{209,212,210},{212,209,78},{198,255,260},{199,197,192},{202,206,211},{220,281,213},{115,210,212},{218,281,225},{180,217,214},{217,224,214},{161,216,159},{152,214,215},{183,216,162},{230,216,181},{180,229,218},{219,217,171},{298,220,213},{229,213,218},{222,219,171},{158,223,153},{281,220,30},{281,221,225},{231,234,233},{168,232,169},{168,222,171},{163,222,64},{159,223,160},{224,223,214},{217,219,224},{223,224,219},{218,225,217},{232,225,221},{213,281,218},{228,202,211},{204,228,227},{235,228,211},{298,202,226},{298,213,229},{201,230,181},{215,230,152},{225,232,171},{281,237,221},{221,237,233},{234,231,170},{169,232,233},{234,170,177},{169,233,234},{211,188,235},{188,187,239},{190,241,242},{193,238,244},{30,231,237},{233,237,231},{239,238,227},{244,238,236},{242,239,190},{239,236,238},{261,268,264},{288,290,292},{203,182,252},{203,252,241},{243,242,240},{242,236,239},{291,286,292},{243,191,244},{246,245,24},{243,244,236},{245,91,247},{96,246,24},{91,246,89},{248,247,91},{247,248,250},{249,248,91},{248,71,73},{90,249,91},{249,56,77},{23,37,250},{35,250,37},{266,267,283},{196,251,264},{200,115,253},{210,200,254},{123,253,115},{262,25,259},{115,200,210},{241,252,263},{253,271,256},{256,255,200},{256,262,273},{123,271,253},{278,95,118},{255,256,273},{254,200,255},{274,194,267},{258,273,259},{260,274,269},{264,251,266},{294,285,282},{256,257,262},{25,262,257},{196,268,252},{283,282,285},{268,261,263},{288,292,286},{266,285,264},{267,266,251},{283,284,282},{269,267,251},{267,269,274},{264,268,196},{263,252,268},{251,198,269},{198,260,269},{95,278,271},{258,270,274},{256,271,257},{259,273,262},{276,119,277},{258,260,273},{258,274,260},{194,274,270},{271,276,257},{272,25,275},{272,275,276},{275,257,276},{144,130,142},{272,277,28},{119,278,120},{271,278,276},{19,279,132},{20,131,279},{166,167,280},{237,281,30},{287,286,291},{267,194,283},{282,284,265},{283,285,266},{283,194,284},{288,294,282},{293,191,297},{263,261,295},{288,282,265},{240,263,295},{296,286,287},{1,291,292},{288,286,294},{296,293,289},{294,261,285},{288,265,290},{191,243,297},{295,294,286},{297,240,289},{286,296,295},{295,289,240},{261,294,295},{293,296,287},{295,296,289},{240,297,243},{289,293,297},{298,229,202},{21,220,298}};

Just as a check!

nNodes=Length[Nodes];
nElements=Length[Elements];
GraphicsGrid[{{ListPlot[{Nodes,Nodes[[BoundaryNodes]]},
PlotStyle->{Red, Blue},
AspectRatio->Automatic,
Frame->True],
Show[Graphics[{
EdgeForm[{Thick, Black}],
Table[{Hue[i/nElements],Polygon[Nodes[[Elements[[i]]]]]},
{i, nElements}]
}
],
Frame->True
]}}]

Testing the things I made

Testing the things.  First lets test the plotting function I made.

Clear[f,x,y]
f[{x_,y_}]:= Sin[x y];
GraphicsGrid[{
{
Plot3D[ f[{x,y}],{x,0,3},{y,0,3},
RegionFunction->Function[{x,y,z},(x^2)+(y^2)<9]
],
TrianglePlot[Map[f,Nodes],Nodes,Elements]
}
}
]

Lets see if the assembly looks plausible.

A=AssembleStiffnessMatrix[Elements,Nodes]
b=AssembleLoadVector[Elements,Nodes,f];
GraphicsGrid[{
{
MatrixPlot[A],TrianglePlot[b,Nodes,Elements]
}
}
]

Lets look and see if the Dirichlet fixing looks plausible.

BoundaryNodeValues=0.0 BoundaryNodes;
{A,b}=DirichletBoundarySet[A,b,BoundaryNodes,BoundaryNodeValues];
GraphicsGrid[{
{
MatrixPlot[A],TrianglePlot[b,Nodes,Elements]
}
}
]

Lets look and see if the solve looks plausible.

u=LinearSolve[A,b];
TrianglePlot[u,Nodes,Elements]

Plausible but is it correct.  To check this I need to have a problem that I l know the answer to and possibly a finer mesh.

A test problem

If I pick a function that satisfies Dirichlet BC on my domain and use the Laplacian as a forcinf function f I get a test problem to which I know the analytical answer.

Clear[f,uSol,x,y]
uSol[{x_,y_}]:= x y (9-((x^2)+(y^2)))
f[{x_,y_}] = -(D[uSol[{x,y}],{x,2}]+  D[uSol[{x,y}],{y,2}]);
GraphicsGrid[{
{
Plot3D[uSol[{x,y}],
{x,0,3},
{y,0,3},
RegionFunction->Function[{x,y,z},(x^2)+(y^2)<9]
],
Plot3D[f[{x,y}],
{x,0,3},
{y,0,3},
RegionFunction->Function[{x,y,z},(x^2)+(y^2)<9]
]
}
}
]

A=AssembleStiffnessMatrix[Elements,Nodes]
b=AssembleLoadVector[Elements,Nodes,f];
BoundaryNodeValues=0.0 BoundaryNodes;
{A,b}=DirichletBoundarySet[A,b,BoundaryNodes,BoundaryNodeValues];
u=LinearSolve[A,b];
TrianglePlot[u,Nodes,Elements]

So we are fairly confident it is correct!  To be sure it is completely correct we need to make sure it converges correctly as we refine our mesh.

Basic mas matrix assembley.

This is copied over from the Stiffness matrix but not modified yet.  We need to go back and think about integrating quadratic functions on triangles.

Integrate[ y y,
{x,0,1},
{y,0,1-x}]

AssembleMassMatrix[Elements_List,Nodes_List]:= Module[
{NodeCount,ElementCount,A,n1,n2,n3,p1,p2,p3,i,j,k,
Area,Grad1,Grad2,Grad3,a12,a13,a23},
NodeCount=Length[Nodes];
ElementCount=Length[Elements];
A=SparseArray[{},{NodeCount,NodeCount}];
Do[
(* Grab the triangle data *)
{n1,n2,n3}=Elements[[i]];
{p1,p2,p3}=Nodes[[{n1,n2,n3}]];
(* Compute the geometric stuff *)
Area=BasicAreaComputation[{p1,p2,p3}];
Grad1=BasicGradientComputation[{p1,p2,p3}];
Grad2=BasicGradientComputation[{p2,p3,p1}];
Grad3=BasicGradientComputation[{p3,p1,p2}];
(* Update the stiffness matrix *)
A[[n1,n1]]+=Area*Grad1.Grad1;
A[[n2,n2]]+=Area*Grad2.Grad2;
A[[n3,n3]]+=Area*Grad3.Grad3;
a12=Area*Grad1.Grad2;A[[n1,n2]]+=a12;A[[n2,n1]]+=a12;
a13=Area*Grad1.Grad3;A[[n1,n3]]+=a13;A[[n3,n1]]+=a13;
a23=Area*Grad2.Grad3;A[[n2,n3]]+=a23;A[[n3,n2]]+=a23,
{i,ElementCount}
];
A
]

AssembleLoadVector[Elements_List,Nodes_List,f_]:= Module[
{NodeCount,ElementCount,b,
n1,n2,n3,p1,p2,p3,i,
Area,bTemp},
NodeCount=Length[Nodes];
ElementCount=Length[Elements];
b=ConstantArray[0,NodeCount];
Do[
(* Grab the triangle data *)
{n1,n2,n3}=Elements[[i]];
{p1,p2,p3}=Nodes[[{n1,n2,n3}]];
(* Compute the geometric stuff *)
Area=BasicAreaComputation[{p1,p2,p3}];
(* Use midpoint value for f and the shape functions *)
(* Midpoint gives the average value of p *)
(* shape functions are all 1/3 at the midpoint *)
bTemp=Area*f[(p1+p2+p3)/3.0]/3.0;
b[[n1]]+=bTemp; b[[n2]]+=bTemp; b[[n3]]+=bTemp,
{i,ElementCount}
];
b
]

DirichletBoundarySet[A_,b_,BoundaryNodes_,BoundaryNodeValues_]:= Module[
{BoundaryNodeCount,i,n,Huge=1.0 (10^9),ATemp=A, bTemp=b},
BoundaryNodeCount=Length[BoundaryNodes];
Do[
(* Loading the Diagonals to enforce Dirichlet Boundary conditions *)
n=BoundaryNodes[[i]];
ATemp[[n,n]]=Huge;
bTemp[[n]]=Huge*BoundaryNodeValues[[i]],
{i,BoundaryNodeCount}
];
{ATemp,bTemp}
]

Shallow Water Wave

The Shallow-Water Wave Equations (over a flat topgraphy) in vector divergence form are
	({{(Subscript[η, t]), +, Div(η (OverVector[u])), =, 0}, {(Subscript[(η (OverVector[u])), t]), +, Div((1/2)(OverVector[u])⊗(OverVector[u])+g (η^2)(Subscript[Id, 2])), =, (OverVector[0])}})
where η is the wave height,  (OverVector[u]) is the fluid velocity and g is the acceleration due to gravity.   The weak form is 
	({{(∫_Ω)μ (Subscript[η, t])dA, -, (∫_Ω) η (OverVector[u]). ∇μdA, =, 0}, {(∫_Ω)(OverVector[v]).(Subscript[(η (OverVector[u])), t])dA, -, (∫_Ω) ((η/2)(OverVector[u])⊗(OverVector[u])+g (η^2)(Subscript[Id, 2])). ∇(OverVector[v])dA, =, 0}})
for all smooth scalar fields η and smooth vector fields (OverVector[v]) satisfying suitable boundary conditions.

Possible boundary conditions for η are η=0 (an infinity edge pool) or ∂η/∂(OverVector[n])=0 which is a vertical reflecting edge pool, or periodic conditions for suitable domains.  The reflecting edge conditions are natural.  The Dirichlet conditions need to be enforced.

Possible boundary conditions for (OverVector[u]) are (OverVector[u])=0 (no flow through or along the edge) or a periodic condition for suitable domains.

A straight forward implementation of the reflecting edge pool with the homogeneous Dirichlet conditions for the velocity follows on a general domain with (Subscript[μ, i])(x,y) and (Subscript[(OverVector[v]), i])(x,y)=(Subscript[v, i,1])(x,y)(Subscript[(OverVector[e]), 1])+(Subscript[v, i,2])(x,y)(Subscript[(OverVector[e]), 2]) being piecewise linear shape functions  on the same underlying triangulation for the elevation and two components of the fluid velocity respectively.  Substitute
	({{η(x,y,t), =, (∑_(i=1)^n)(Subscript[α, i])(t)(Subscript[μ, i])(x,y),  ,  }, {(OverVector[u])(x,y,t), =, (∑_(j=1)^n)(Subscript[β, j])(t)(Subscript[v, j,1])(x,y) (Subscript[(OverVector[e]), 1]), +, (∑_(k=1)^n)(Subscript[γ, k])(t)(Subscript[v, k,2])(x,y)(Subscript[(OverVector[e]), 2])}})
into the weak form to get for the first weak equation
	({{(∑_(i=1)^n)(Subscript[α, i])'(t)(∫_Ω)μ (Subscript[μ, i])  dA, -, (∑_(i=1)^n)(∑_(j=1)^n)(Subscript[α, i])(t)(Subscript[β, j])(t)(∫_Ω) (Subscript[μ, i]) (Subscript[e, 1]). ∇μdA, -(∑_(i=1)^n)(∑_(k=1)^n)(Subscript[α, i])(t)(Subscript[γ, k])(t)(∫_Ω) (Subscript[μ, i]) (Subscript[e, 2]). ∇μdA=, 0}})
and for the second weak equation